UNPKG

channelape-sdk

Version:
36 lines 1.27 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); const Resource_1 = require("../../model/Resource"); const Version_1 = require("../../model/Version"); const Q = require("q"); class ChannelsService { constructor(client) { this.client = client; } get(channelId) { const deferred = Q.defer(); const requestUrl = `/${Version_1.default.V1}${Resource_1.default.CHANNELS}/${channelId}`; this.client.get(requestUrl, (error, response, body) => { this.mapPromise(deferred, error, response, body); }); return deferred.promise; } mapPromise(deferred, error, response, body) { if (error) { deferred.reject(error); } else if (response.statusCode === 200) { const channel = body; channel.createdAt = new Date(body.createdAt); channel.updatedAt = new Date(body.updatedAt); deferred.resolve(channel); } else { const channelApeErrorResponse = body; channelApeErrorResponse.statusCode = response.statusCode; deferred.reject(channelApeErrorResponse); } } } exports.default = ChannelsService; //# sourceMappingURL=ChannelsService.js.map