Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

DEVEXP-408: Add support for Country Permissions #79

Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions examples/simple-examples/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -303,3 +303,6 @@ yarn run numbers:regions:list
| | [./src/elastic-sip-trunking/access-control-list/addToTrunk.ts](./src/elastic-sip-trunking/access-control-list/addToTrunk.ts) | SIP_TRUNK_ID, ACL_ID |
| | [./src/elastic-sip-trunking/access-control-list/listForTrunk.ts](./src/elastic-sip-trunking/access-control-list/listForTrunk.ts) | SIP_TRUNK_ID |
| | [./src/elastic-sip-trunking/access-control-list/deleteFromTrunk.ts](./src/elastic-sip-trunking/access-control-list/deleteFromTrunk.ts) | SIP_TRUNK_ID, ACL_ID |
| Country Permissions | [./src/elastic-sip-trunking/country-permissions/get.ts](./src/elastic-sip-trunking/country-permissions/get.ts) | |
| | [./src/elastic-sip-trunking/country-permissions/list.ts](./src/elastic-sip-trunking/country-permissions/list.ts) | |
| | [./src/elastic-sip-trunking/country-permissions/update.ts](./src/elastic-sip-trunking/country-permissions/update.ts) | |
3 changes: 3 additions & 0 deletions examples/simple-examples/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,9 @@
"elasticSipTrunks:accessControlList:addToTrunk": "ts-node src/elastic-sip-trunking/access-control-list/addToTrunk.ts",
"elasticSipTrunks:accessControlList:listForTrunk": "ts-node src/elastic-sip-trunking/access-control-list/listForTrunk.ts",
"elasticSipTrunks:accessControlList:deleteFromTrunk": "ts-node src/elastic-sip-trunking/access-control-list/deleteFromTrunk.ts",
"elasticSipTrunks:countryPermissions:get": "ts-node src/elastic-sip-trunking/country-permissions/get.ts",
"elasticSipTrunks:countryPermissions:list": "ts-node src/elastic-sip-trunking/country-permissions/list.ts",
"elasticSipTrunks:countryPermissions:update": "ts-node src/elastic-sip-trunking/country-permissions/update.ts",
"fax:services:create": "ts-node src/fax/services/create.ts",
"fax:services:get": "ts-node src/fax/services/get.ts",
"fax:services:list": "ts-node src/fax/services/list.ts",
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
import { ElasticSipTrunking } from '@sinch/sdk-core';
import {
getPrintFormat,
initElasticSipTrunkingService,
printFullResponse,
} from '../../config';

(async () => {
console.log('************************');
console.log('* getCountryPermission *');
console.log('************************');

const requestData: ElasticSipTrunking.GetCountryPermissionRequestData = {
isoCode: 'US',
};

const elasticSipTrunkingService = initElasticSipTrunkingService();
const response = await elasticSipTrunkingService.countryPermissions.get(requestData);

const printFormat = getPrintFormat(process.argv);

if (printFormat === 'pretty') {
console.log(`The country permission for the country '${response.name}' is ${response.enabled ? '' : 'not '}enabled`);
} else {
printFullResponse(response);
}

})();
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
import { ElasticSipTrunking } from '@sinch/sdk-core';
import {
getPrintFormat,
initElasticSipTrunkingService,
printFullResponse,
} from '../../config';

(async () => {
console.log('*************************');
console.log('* getCountryPermissions *');
console.log('*************************');

const requestData: ElasticSipTrunking.ListCountryPermissionsRequestData = {};

const elasticSipTrunkingService = initElasticSipTrunkingService();
const response = await elasticSipTrunkingService.countryPermissions.list(requestData);

const printFormat = getPrintFormat(process.argv);

if (printFormat === 'pretty') {
console.log(`Here is the status for all the countries:\n${response.countryPermissions?.map((permission) => formatPermission(permission)).join('\n')}`);
} else {
printFullResponse(response);
}

})();

const formatPermission = (countryPermission: ElasticSipTrunking.CountryPermission): string => {
return ` - ${countryPermission.name}: ${countryPermission.enabled ? '' : 'NOT '} enabled`;
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
import { ElasticSipTrunking } from '@sinch/sdk-core';
import {
getPrintFormat,
initElasticSipTrunkingService,
printFullResponse,
} from '../../config';

(async () => {
console.log('***************************');
console.log('* updateCountryPermission *');
console.log('***************************');

const requestData: ElasticSipTrunking.UpdateCountryPermissionRequestData = {
isoCode: 'US',
updateCountryPermissionRequestBody: {
enabled: false,
},
};

const elasticSipTrunkingService = initElasticSipTrunkingService();
const response = await elasticSipTrunkingService.countryPermissions.update(requestData);

const printFormat = getPrintFormat(process.argv);

if (printFormat === 'pretty') {
console.log(`The Permission for the country '${response.name}' is ${response.enabled ? '' : 'NOT '}enabled`);
} else {
printFullResponse(response);
}

})();
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
/**
* With country permissions you can control which countries can be dialed from your account. For beta only, countries supported are US,CA and * if you would like to allow international dialing.
*/
export interface CountryPermission {
/** The [ISO code](https://en.wikipedia.org/wiki/ISO_3166-1_alpha-2) of the country */
isoCode?: string;
/** Country name in english */
name?: string;
/** Continent of the country */
continent?: string;
/** The country calling codes as an array, most countries have only one but some have multiple like the San Marino, China, and a few others. */
countryDialingCodes?: string[];
/** If the country is enabled or not. When this is enabled regular numbers can be dialed from the account. */
enabled: boolean;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export type { CountryPermission } from './country-permission';
3 changes: 3 additions & 0 deletions packages/elastic-sip-trunking/src/models/v1/index.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
export * from './access-control-list';
export * from './add-access-control-list-to-trunk';
export * from './country-permission';
export * from './ip-range';
export * from './list-country-permissions-response';
export * from './sip-endpoint';
export * from './sip-trunk';
export * from './update-access-control-list-request';
export * from './update-country-permission-request';
export * from './requests';
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export type { ListCountryPermissionsResponse } from './list-country-permissions-response';
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import { CountryPermission } from '../country-permission';

export interface ListCountryPermissionsResponse {

/** List of CountryPermissions */
countryPermissions?: CountryPermission[];
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import { UpdateCountryPermissionRequest } from '../../update-country-permission-request';

export interface GetCountryPermissionRequestData {
/** The ISO code of the country. */
'isoCode': string;
}
export interface ListCountryPermissionsRequestData {
}
export interface UpdateCountryPermissionRequestData {
/** The ISO code of the country. */
'isoCode': string;
/** The body containing the Country Permission details to update */
'updateCountryPermissionRequestBody': UpdateCountryPermissionRequest;
}
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
export * from './access-control-list/access-control-list-request-data';
export * from './country-permissions/country-permissions-request-data';
export * from './sip-endpoints/sip-endpoints-request-data';
export * from './sip-trunks/sip-trunks-request-data';
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export type { UpdateCountryPermissionRequest } from './update-country-permission-request';
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
export interface UpdateCountryPermissionRequest {
/** If the country is enabled or not. When this is enabled regular numbers can be dialed from the account. */
enabled: boolean;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
import { CountryPermissionsApi } from './country-permissions-api';
import {
CountryPermission,
GetCountryPermissionRequestData,
ListCountryPermissionsRequestData,
ListCountryPermissionsResponse,
UpdateCountryPermissionRequestData,
} from '../../../models';

export class CountryPermissionsApiFixture implements Partial<Readonly<CountryPermissionsApi>> {

/**
* Fixture associated to function getCountryPermission
*/
public get: jest.Mock<Promise<CountryPermission>, [GetCountryPermissionRequestData]> = jest.fn();
/**
* Fixture associated to function getCountryPermissions
*/
public list: jest.Mock<
Promise<ListCountryPermissionsResponse>,
[ListCountryPermissionsRequestData]
> = jest.fn();
/**
* Fixture associated to function updateCountryPermission
*/
public update: jest.Mock<
Promise<CountryPermission>,
[UpdateCountryPermissionRequestData]
> = jest.fn();
}

Original file line number Diff line number Diff line change
@@ -0,0 +1,109 @@
import {
CountryPermission,
ListCountryPermissionsResponse,
GetCountryPermissionRequestData,
ListCountryPermissionsRequestData,
UpdateCountryPermissionRequestData,
} from '../../../models';
import {
RequestBody,
SinchClientParameters,
} from '@sinch/sdk-client';
import { ElasticSipTrunkingDomainApi } from '../elastic-sip-trunking-domain-api';

export class CountryPermissionsApi extends ElasticSipTrunkingDomainApi {

/**
* Initialize your interface
*
* @param {SinchClientParameters} sinchClientParameters - The parameters used to initialize the API Client.
*/
constructor(sinchClientParameters: SinchClientParameters) {
super(sinchClientParameters, 'CountryPermissionsApi');
}

/**
* Fetch country permission
* Fetches the requested country permission.
* @param { GetCountryPermissionRequestData } data - The data to provide to the API call.
*/
public async get(data: GetCountryPermissionRequestData): Promise<CountryPermission> {
this.client = this.getSinchClient();
const getParams = this.client.extractQueryParams<GetCountryPermissionRequestData>(data, [] as never[]);
const headers: { [key: string]: string | undefined } = {
'Content-Type': 'application/json',
'Accept': 'application/json',
};

const body: RequestBody = '';
const basePathUrl = `${this.client.apiClientOptions.hostname}/v1/projects/${this.client.apiClientOptions.projectId}/countryPermissions/${data['isoCode']}`;

const requestOptions = await this.client.prepareOptions(basePathUrl, 'GET', getParams, headers, body || undefined);
const url = this.client.prepareUrl(requestOptions.hostname, requestOptions.queryParams);

return this.client.processCall<CountryPermission>({
url,
requestOptions,
apiName: this.apiName,
operationId: 'GetCountryPermission',
});
}

/**
* Fetch all country permissions
* Fetches the list of country permissions.
* @param { ListCountryPermissionsRequestData } data - The data to provide to the API call.
*/
public async list(data: ListCountryPermissionsRequestData): Promise<ListCountryPermissionsResponse> {
this.client = this.getSinchClient();
const getParams = this.client.extractQueryParams<ListCountryPermissionsRequestData>(data, [] as never[]);
const headers: { [key: string]: string | undefined } = {
'Content-Type': 'application/json',
'Accept': 'application/json',
};

const body: RequestBody = '';
const basePathUrl = `${this.client.apiClientOptions.hostname}/v1/projects/${this.client.apiClientOptions.projectId}/countryPermissions`;

const requestOptions = await this.client.prepareOptions(basePathUrl, 'GET', getParams, headers, body || undefined);
const url = this.client.prepareUrl(requestOptions.hostname, requestOptions.queryParams);

return this.client.processCall<ListCountryPermissionsResponse>({
url,
requestOptions,
apiName: this.apiName,
operationId: 'GetCountryPermissions',
});
}

/**
* Update country permission
* Update the requested country permission.
* @param { UpdateCountryPermissionRequestData } data - The data to provide to the API call.
*/
public async update(data: UpdateCountryPermissionRequestData): Promise<CountryPermission> {
this.client = this.getSinchClient();
const getParams = this.client.extractQueryParams<UpdateCountryPermissionRequestData>(data, [] as never[]);
const headers: { [key: string]: string | undefined } = {
'Content-Type': 'application/json',
'Accept': 'application/json',
};

const body: RequestBody = data['updateCountryPermissionRequestBody']
? JSON.stringify(data['updateCountryPermissionRequestBody'])
: '{}';
const basePathUrl = `${this.client.apiClientOptions.hostname}/v1/projects/${this.client.apiClientOptions.projectId}/countryPermissions/${data['isoCode']}`;

const requestOptions = await this.client.prepareOptions(basePathUrl, 'PUT', getParams, headers, body || undefined);
const url = this.client.prepareUrl(requestOptions.hostname, requestOptions.queryParams);

return this.client.processCall<CountryPermission>({
url,
requestOptions,
apiName: this.apiName,
operationId: 'UpdateCountryPermission',
});
}


}
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
export * from './country-permissions-api';
export * from './country-permissions-api.jest.fixture';
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,20 @@ import { SinchClientParameters } from '@sinch/sdk-client';
import { SipTrunksApi } from './sip-trunks';
import { AccessControlListApi } from './access-control-list';
import { SipEndpointsApi } from './sip-endpoints';
import { CountryPermissionsApi } from './country-permissions';

export class ElasticSipTrunkingService {

public readonly sipTrunks: SipTrunksApi;
public readonly sipEndpoints: SipEndpointsApi;
public readonly accessControlList: AccessControlListApi;
public readonly countryPermissions: CountryPermissionsApi;

constructor(params: SinchClientParameters) {
this.sipTrunks = new SipTrunksApi(params);
this.sipEndpoints = new SipEndpointsApi(params);
this.accessControlList = new AccessControlListApi(params);
this.countryPermissions = new CountryPermissionsApi(params);
}

/**
Expand All @@ -24,5 +27,6 @@ export class ElasticSipTrunkingService {
this.sipTrunks.setHostname(hostname);
this.sipEndpoints.setHostname(hostname);
this.accessControlList.setHostname(hostname);
this.countryPermissions.setHostname(hostname);
}
}
1 change: 1 addition & 0 deletions packages/elastic-sip-trunking/src/rest/v1/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
export * from './access-control-list';
export * from './country-permissions';
export * from './sip-endpoints';
export * from './sip-trunks';
export * from './elastic-sip-trunking-service';
Loading
Loading