twilio-mcs-client
Advanced tools
Comparing version 0.4.2 to 0.4.3
@@ -48,12 +48,8 @@ "use strict"; | ||
/** | ||
* Base URLs must be full URLs with host. If host is not provided it will be generated from a default configuration | ||
* template using options.region. | ||
* | ||
* @param {String} token - Access token | ||
* @param {String} baseUrl - Base URL for Media Content Service Media resource, i.e. /v1/Services/{serviceSid}/Media | ||
* @param {String} baseSetUrl - Base URL for Media Content Service MediaSet resource, i.e. /v1/Services/{serviceSid}/MediaSet | ||
* @param {String} baseUrl - Base URL for Media Content Service, i.e. /v1/Services/{serviceSid}/Media | ||
* @param {Client#ClientOptions} [options] - Options to customize the Client | ||
*/ | ||
function Client(token, baseUrl, baseSetUrl) { | ||
var options = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : {}; | ||
function Client(token, baseUrl) { | ||
var options = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {}; | ||
(0, _classCallCheck3.default)(this, Client); | ||
@@ -63,3 +59,3 @@ | ||
this.options.logLevel = this.options.logLevel || 'silent'; | ||
this.config = new configuration_1.Configuration(token, baseUrl, baseSetUrl, this.options); | ||
this.config = new configuration_1.Configuration(token, baseUrl, this.options); | ||
if (!token) { | ||
@@ -113,3 +109,3 @@ throw new Error(MSG_NO_TOKEN); | ||
_context.next = 2; | ||
return this.network.get(this.config.mediaUrl + "/" + sid); | ||
return this.network.get(this.config.baseUrl + "/" + sid); | ||
@@ -152,3 +148,3 @@ case 2: | ||
_context2.next = 2; | ||
return this.network.post(this.config.mediaUrl, media, contentType); | ||
return this.network.post(this.config.baseUrl, media, contentType); | ||
@@ -192,3 +188,3 @@ case 2: | ||
_context3.next = 2; | ||
return this.network.post(this.config.mediaUrl, formData); | ||
return this.network.post(this.config.baseUrl, formData); | ||
@@ -236,3 +232,3 @@ case 2: | ||
_context4.next = 3; | ||
return this.network.post("" + this.config.mediaSetUrl, (0, _stringify2.default)(query), 'application/json'); | ||
return this.network.post(this.config.baseUrl + "Set", (0, _stringify2.default)(query), 'application/json'); | ||
@@ -239,0 +235,0 @@ case 3: |
@@ -19,14 +19,5 @@ "use strict"; | ||
var RETRY_WHEN_THROTTLED = true; | ||
var regionalMcsHost = function regionalMcsHost(region) { | ||
return "https://mcs." + (region ? region + "." : '') + "twilio.com"; | ||
}; | ||
var isFullUrl = function isFullUrl(url) { | ||
return url.startsWith('http'); | ||
}; | ||
var fullUrl = function fullUrl(partUrl, region) { | ||
return "" + (!isFullUrl(partUrl) ? regionalMcsHost(region) : '') + partUrl; | ||
}; | ||
var Configuration = function () { | ||
function Configuration(token, baseUrl, baseSetUrl, options) { | ||
function Configuration(token, baseUrl, options) { | ||
(0, _classCallCheck3.default)(this, Configuration); | ||
@@ -36,4 +27,3 @@ | ||
this.region = constructorOptions.region || options.region; | ||
this.mediaUrl = fullUrl(baseUrl, this.region); | ||
this.mediaSetUrl = baseSetUrl ? fullUrl(baseSetUrl) : this.mediaUrl + "Set"; | ||
this.baseUrl = baseUrl; | ||
this.token = token; | ||
@@ -40,0 +30,0 @@ this.retryWhenThrottledOverride = constructorOptions.retryWhenThrottledOverride; |
@@ -69,3 +69,3 @@ "use strict"; | ||
_context.next = 2; | ||
return this.network.get(this.config.mediaUrl + "/" + this.sid); | ||
return this.network.get(this.config.baseUrl + "/" + this.sid); | ||
@@ -72,0 +72,0 @@ case 2: |
@@ -20,11 +20,7 @@ /// <reference types="node" /> | ||
/** | ||
* Base URLs must be full URLs with host. If host is not provided it will be generated from a default configuration | ||
* template using options.region. | ||
* | ||
* @param {String} token - Access token | ||
* @param {String} baseUrl - Base URL for Media Content Service Media resource, i.e. /v1/Services/{serviceSid}/Media | ||
* @param {String} baseSetUrl - Base URL for Media Content Service MediaSet resource, i.e. /v1/Services/{serviceSid}/MediaSet | ||
* @param {String} baseUrl - Base URL for Media Content Service, i.e. /v1/Services/{serviceSid}/Media | ||
* @param {Client#ClientOptions} [options] - Options to customize the Client | ||
*/ | ||
constructor(token: string, baseUrl: string, baseSetUrl: string, options?: Options); | ||
constructor(token: string, baseUrl: string, options?: Options); | ||
/** | ||
@@ -31,0 +27,0 @@ * These options can be passed to Client constructor |
@@ -20,14 +20,10 @@ "use strict"; | ||
/** | ||
* Base URLs must be full URLs with host. If host is not provided it will be generated from a default configuration | ||
* template using options.region. | ||
* | ||
* @param {String} token - Access token | ||
* @param {String} baseUrl - Base URL for Media Content Service Media resource, i.e. /v1/Services/{serviceSid}/Media | ||
* @param {String} baseSetUrl - Base URL for Media Content Service MediaSet resource, i.e. /v1/Services/{serviceSid}/MediaSet | ||
* @param {String} baseUrl - Base URL for Media Content Service, i.e. /v1/Services/{serviceSid}/Media | ||
* @param {Client#ClientOptions} [options] - Options to customize the Client | ||
*/ | ||
constructor(token, baseUrl, baseSetUrl, options = {}) { | ||
constructor(token, baseUrl, options = {}) { | ||
this.options = options; | ||
this.options.logLevel = this.options.logLevel || 'silent'; | ||
this.config = new configuration_1.Configuration(token, baseUrl, baseSetUrl, this.options); | ||
this.config = new configuration_1.Configuration(token, baseUrl, this.options); | ||
if (!token) { | ||
@@ -67,3 +63,3 @@ throw new Error(MSG_NO_TOKEN); | ||
async get(sid) { | ||
const response = await this.network.get(`${this.config.mediaUrl}/${sid}`); | ||
const response = await this.network.get(`${this.config.baseUrl}/${sid}`); | ||
return new media_1.Media(this.config, this.network, response.body); | ||
@@ -79,3 +75,3 @@ } | ||
async post(contentType, media) { | ||
const response = await this.network.post(this.config.mediaUrl, media, contentType); | ||
const response = await this.network.post(this.config.baseUrl, media, contentType); | ||
return new media_1.Media(this.config, this.network, response.body); | ||
@@ -92,3 +88,3 @@ } | ||
async postFormData(formData) { | ||
const response = await this.network.post(this.config.mediaUrl, formData); | ||
const response = await this.network.post(this.config.baseUrl, formData); | ||
return new media_1.Media(this.config, this.network, response.body); | ||
@@ -105,3 +101,3 @@ } | ||
}; | ||
const response = (await this.network.post(`${this.config.mediaSetUrl}`, JSON.stringify(query), 'application/json')); | ||
const response = (await this.network.post(`${this.config.baseUrl}Set`, JSON.stringify(query), 'application/json')); | ||
return response.map((item) => { | ||
@@ -108,0 +104,0 @@ if (item.code !== 200) { |
@@ -5,6 +5,5 @@ declare class Configuration { | ||
readonly backoffConfigOverride: any; | ||
readonly mediaUrl: string; | ||
readonly mediaSetUrl: string; | ||
private readonly region; | ||
constructor(token: string, baseUrl: string, baseSetUrl: string, options: any); | ||
readonly baseUrl: string; | ||
private region; | ||
constructor(token: string, baseUrl: string, options: any); | ||
static get backoffConfigDefault(): any; | ||
@@ -11,0 +10,0 @@ static get retryWhenThrottledDefault(): boolean; |
@@ -8,11 +8,7 @@ "use strict"; | ||
const RETRY_WHEN_THROTTLED = true; | ||
const regionalMcsHost = (region) => `https://mcs.${region ? `${region}.` : ''}twilio.com`; | ||
const isFullUrl = (url) => url.startsWith('http'); | ||
const fullUrl = (partUrl, region) => `${!isFullUrl(partUrl) ? regionalMcsHost(region) : ''}${partUrl}`; | ||
class Configuration { | ||
constructor(token, baseUrl, baseSetUrl, options) { | ||
constructor(token, baseUrl, options) { | ||
let constructorOptions = options.MCS || options || {}; | ||
this.region = constructorOptions.region || options.region; | ||
this.mediaUrl = fullUrl(baseUrl, this.region); | ||
this.mediaSetUrl = baseSetUrl ? fullUrl(baseSetUrl) : `${this.mediaUrl}Set`; | ||
this.baseUrl = baseUrl; | ||
this.token = token; | ||
@@ -19,0 +15,0 @@ this.retryWhenThrottledOverride = constructorOptions.retryWhenThrottledOverride; |
@@ -42,3 +42,3 @@ "use strict"; | ||
async getContentUrl() { | ||
let response = await this.network.get(`${this.config.mediaUrl}/${this.sid}`); | ||
let response = await this.network.get(`${this.config.baseUrl}/${this.sid}`); | ||
this._update(response.body); | ||
@@ -45,0 +45,0 @@ return Promise.resolve(this.state.contentDirectUrl); |
{ | ||
"name": "twilio-mcs-client", | ||
"version": "0.4.2", | ||
"version": "0.4.3", | ||
"description": "Twilio Media Content Service client library", | ||
@@ -5,0 +5,0 @@ "main": "lib/index.js", |
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is too big to display
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
377954
6741