/
phoneNumbersClientContext.ts
83 lines (71 loc) · 3.05 KB
/
phoneNumbersClientContext.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
/*
* Copyright (c) Microsoft Corporation.
* Licensed under the MIT License.
*
* Code generated by Microsoft (R) AutoRest Code Generator.
* Changes may cause incorrect behavior and will be lost if the code is regenerated.
*/
import * as coreHttp from "@azure/core-http";
import { PhoneNumbersClientOptionalParams } from "./models";
import { lroPolicy } from "./lro";
const packageName = "azure-communication-phone-numbers";
const packageVersion = "1.2.0-beta.1";
export class PhoneNumbersClientContext extends coreHttp.ServiceClient {
endpoint: string;
apiVersion: string;
/**
* Initializes a new instance of the PhoneNumbersClientContext class.
* @param endpoint The communication resource, for example
* https://resourcename.communication.azure.com.
* @param options The parameter options
*/
constructor(endpoint: string, options?: PhoneNumbersClientOptionalParams) {
if (endpoint === undefined) {
throw new Error("'endpoint' cannot be null");
}
// Initializing default values for options
if (!options) {
options = {};
}
if (!options.userAgent) {
const defaultUserAgent = coreHttp.getDefaultUserAgentValue();
options.userAgent = `${packageName}/${packageVersion} ${defaultUserAgent}`;
}
// Building the request policy fatories based on the passed factories and the
// any required factories needed by the client.
if (Array.isArray(options.requestPolicyFactories)) {
// When an array of factories is passed in, we'll just add the required factories,
// in this case lroPolicy(). It is important to note that passing an array of factories
// to a new client, bypasses core-http default factories. Just the pipelines provided will be run.
options.requestPolicyFactories = [
lroPolicy(),
...options.requestPolicyFactories
];
} else if (options.requestPolicyFactories) {
// When we were passed a requestPolicyFactories as a function, we'll create a new one that adds the factories provided
// in the options plus the required policies. When using this path, the pipelines passed to the client will be added to the
// default policies added by core-http
const optionsPolicies = options.requestPolicyFactories([lroPolicy()]) || [
lroPolicy()
];
options.requestPolicyFactories = (defaultFactories) => [
...optionsPolicies,
...defaultFactories
];
} else {
// In case no request policy factories were provided, we'll just need to create a function that will add
// the lroPolicy to the default pipelines added by core-http
options.requestPolicyFactories = (defaultFactories) => [
lroPolicy(),
...defaultFactories
];
}
super(undefined, options);
this.requestContentType = "application/json; charset=utf-8";
this.baseUri = options.endpoint || "{endpoint}";
// Parameter assignments
this.endpoint = endpoint;
// Assigning values to Constant parameters
this.apiVersion = options.apiVersion || "2022-01-11-preview2";
}
}