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

49 lines
959 B
JavaScript

'use strict';
var v1 = require('./lib/v1/client');
var request = require('./lib/request');
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');
}
var currentVersion;
var lastApiVersion = 'v1';
var clients = {
'v1': v1.Client
};
if (options.apiVersion) {
currentVersion = options.apiVersion;
} else {
currentVersion = lastApiVersion;
}
this._client = new clients[currentVersion](new request.Request(options));
}
/**
* Get API client
* @returns {Client}
*/
RetailcrmBotApiClient.prototype.getClient = function () {
return this._client;
};