MCPcopy Create free account
hub / github.com/OneSignal/onesignal-node-api / ServerConfiguration

Class ServerConfiguration

servers.ts:13–49  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

11 *
12 */
13export class ServerConfiguration<T extends { [key: string]: string }> implements BaseServerConfiguration {
14 public constructor(private url: string, private variableConfiguration: T) {}
15
16 /**
17 * Sets the value of the variables of this server.
18 *
19 * @param variableConfiguration a partial variable configuration for the variables contained in the url
20 */
21 public setVariables(variableConfiguration: Partial<T>) {
22 Object.assign(this.variableConfiguration, variableConfiguration);
23 }
24
25 public getConfiguration(): T {
26 return this.variableConfiguration
27 }
28
29 private getUrl() {
30 let replacedUrl = this.url;
31 for (const key in this.variableConfiguration) {
32 var re = new RegExp("{" + key + "}","g");
33 replacedUrl = replacedUrl.replace(re, this.variableConfiguration[key]);
34 }
35 return replacedUrl
36 }
37
38 /**
39 * Creates a new request context for this server using the url with variables
40 * replaced with their respective values and the endpoint of the request appended.
41 *
42 * @param endpoint the endpoint to be queried on the server
43 * @param httpMethod httpMethod to be used
44 *
45 */
46 public makeRequestContext(endpoint: string, httpMethod: HttpMethod): RequestContext {
47 return new RequestContext(this.getUrl() + endpoint, httpMethod);
48 }
49}
50
51export const server1 = new ServerConfiguration<{ }>("https://api.onesignal.com", { })
52

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected