-
Notifications
You must be signed in to change notification settings - Fork 181
/
pricing.ts
118 lines (114 loc) · 3.68 KB
/
pricing.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
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
import { AuthenticationType, Client } from '@vonage/server-client';
import { ServiceType } from './enums';
import {
OutboundAllCountriesPricingResponse,
OutboundCountryPricingResponse,
} from './types';
/**
* The Pricing API allows you to retrieve pricing information for all countries
* and a specific service type, for a specific country and service type, or for
* a specific prefix and service type.
*
* @example
* Create a standalone Pricing client
*
* ```ts
* import { Pricing } from '@vonage/pricing';
*
* const pricingClient = new Pricing({
* apiKey: VONAGE_API_KEY,
* apiSecret: VONAGE_API_SECRET
* });
* ```
*
* @example
* Create an Pricing client from the Vonage client
*
* ```ts
* import { Vonage } from '@vonage/server-client';
*
* const vonage = new Vonage({
* apiKey: VONAGE_API_KEY,
* apiSecret: VONAGE_API_SECRET
* });
*
* const pricingClient = vonage.pricing;
* ```
*/
export class Pricing extends Client {
/**
* @see {@link Client.authType}
*/
protected authType = AuthenticationType.BASIC;
/**
* Retrieves pricing information for a specific country and service type.
*
* @param {ServiceType} type - The service type.
* @param {string} country - The country for which pricing information is requested.
* @return {Promise<OutboundCountryPricingResponse>} - Pricing information for the specified country.
* @example
*
* ```ts
* import { ServiceType } from '@vonage/pricing';
*
* const pricing = await pricingClient.listCountryPricing(ServiceType.SMS, 'GB');
* console.log(`The current price for Great Britian is ${pricing.defaultPrice}`);
* ```
*/
async listCountryPricing(
type: ServiceType,
country: string,
): Promise<OutboundCountryPricingResponse> {
const resp = await this.sendGetRequest<OutboundCountryPricingResponse>(
`${this.config.restHost}/account/get-pricing/outbound/${type}`,
{ country },
);
return resp.data;
}
/**
* Retrieves pricing information for all countries and a specific service type.
* @param {ServiceType} type - The service type.
* @return {Promise<OutboundAllCountriesPricingResponse>} - Pricing information for all countries.
* @example
* ```ts
* import { ServiceType } from '@vonage/pricing';
*
* const pricing = await pricingClient.listAllCountriesPricing(ServiceType.SMS);
* for (const country in pricing.countries) {
* console.log(`The current price for ${country.countryName} is ${country.defaultPrice}`);
* }
* ```
*/
async listAllCountriesPricing(
type: ServiceType,
): Promise<OutboundAllCountriesPricingResponse> {
const resp = await this.sendGetRequest<OutboundAllCountriesPricingResponse>(
`${this.config.restHost}/account/get-full-pricing/outbound/${type}`,
);
return resp.data;
}
/**
* Retrieves pricing information for a specific prefix and service type.
* @param {ServiceType} type - The service type.
* @param {string} prefix - The prefix for which pricing information is requested.
* @return {Promise<OutboundAllCountriesPricingResponse>} - Pricing information for the specified prefix.
*
* @example
* ```ts
* import { ServiceType } from '@vonage/pricing';
*
* const pricing = await pricingClient.listPrefixPricing(ServiceType.SMS, '44');
* console.log(`The current price for Great Britian is ${pricing.defaultPrice}`);
* ```
*/
async listPrefixPricing(
type: ServiceType,
prefix: string,
): Promise<OutboundAllCountriesPricingResponse> {
const resp = await this.sendGetRequest<OutboundAllCountriesPricingResponse>(
`${this.config.restHost}/account/get-prefix-pricing/outbound/${type}`,
{ prefix },
);
return resp.data;
}
}