Skip to content

Commit 1bc9aec

Browse files
committed
Added support for optional endpoint and api version params when initializing Qencode API client object
1 parent 1c2a630 commit 1bc9aec

1 file changed

Lines changed: 26 additions & 3 deletions

File tree

QencodeApiClient.js

Lines changed: 26 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,16 +6,39 @@ const TranscodingTask = require('./Classes/TranscodingTask');
66

77
class QencodeApiClient {
88

9-
constructor(key){
9+
constructor(options){
10+
let key = null;
11+
let endpoint = "https://api.qencode.com/";
12+
this.version = "v1";
13+
let optionsType = Object.prototype.toString.call(options);
14+
if (optionsType === '[object String]') {
15+
key = options;
16+
}
17+
else {
18+
if (!('key' in options)) {
19+
throw new Error("You should provide API Key value when initializing API client!\nExample: const qencodeApiClient = new QencodeApiClient({key: 'your API key'});");
20+
}
21+
else {
22+
key = options.key;
23+
if ('endpoint' in options) {
24+
endpoint = options.endpoint.trim();
25+
if (! endpoint.endsWith('/')) {
26+
endpoint += '/';
27+
}
28+
}
29+
if ('version' in options) {
30+
this.version = options.version.trim();
31+
}
32+
}
33+
}
1034

1135
if(key.length < 12) {
1236
throw new Error("Missing or invalid Qencode project api key!");
1337
}
1438

1539
this.Key = key;
1640
this.AccessToken = null;
17-
this.url = "https://api.qencode.com/";
18-
this.version = "v1";
41+
this.url = endpoint;
1942
this.USER_AGENT = "Qencode NODE API SDK 1.0";
2043
this.ConnectTimeout = 20;
2144
this.lastResponseRaw = null;

0 commit comments

Comments
 (0)