1
0
mirror of synced 2024-11-24 21:36:02 +03:00
mg-bot-api-client-js/index.js

49 lines
959 B
JavaScript
Raw Normal View History

2019-02-06 14:54:15 +03:00
'use strict';
2019-02-08 13:31:38 +03:00
var v1 = require('./lib/v1/client');
var request = require('./lib/request');
2019-02-06 14:54:15 +03:00
module.exports = RetailcrmBotApiClient;
/**
* @param {Object} options
* @throws {Error}
* @constructor
*/
function RetailcrmBotApiClient(options) {
if (!options.host) {
throw new Error('Url is required');
}
if (options.host.indexOf('https') !== 0) {
throw new Error('HTTPS required');
}
if (!(options.token)) {
throw new Error('Token is required');
}
2019-02-08 13:31:38 +03:00
var currentVersion;
var lastApiVersion = 'v1';
2019-02-06 14:54:15 +03:00
2019-02-08 13:31:38 +03:00
var clients = {
'v1': v1.Client
2019-02-06 14:54:15 +03:00
};
2019-02-08 13:31:38 +03:00
if (options.apiVersion) {
currentVersion = options.apiVersion;
} else {
currentVersion = lastApiVersion;
2019-02-06 14:54:15 +03:00
}
2019-02-08 13:31:38 +03:00
this._client = new clients[currentVersion](new request.Request(options));
}
2019-02-06 14:54:15 +03:00
/**
2019-02-08 13:31:38 +03:00
* Get API client
* @returns {Client}
2019-02-06 14:54:15 +03:00
*/
2019-02-08 13:31:38 +03:00
RetailcrmBotApiClient.prototype.getClient = function () {
return this._client;
2019-02-06 14:54:15 +03:00
};