node-telegram-api/build/functions/api.js
Ali Movahedi e5c25bd9c1 refactor: remove grunt and babel
remove grunt from dependencies, and use transformed code instead using babel/register.
change API a litte
2016-03-28 12:26:07 +04:30

51 lines
1.4 KiB
JavaScript

'use strict';
Object.defineProperty(exports, "__esModule", {
value: true
});
var _fetch = require('./fetch');
var _fetch2 = _interopRequireDefault(_fetch);
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } } // API methods
/**
* API class, has a function for each method of the Telegram API which take
* an object argument, and send request to the API server
*
* Methods: getMe, sendMessage, forwardMessage, sendPhoto, sendAudio,
* sendDocument, sendSticker, sendVideo, sendLocation, sendChatAction,
* getUserProfilePhotos, getUpdates
*/
var API =
/**
* Create a new api object with the given token
* @param {string} token
*/
function API(token) {
_classCallCheck(this, API);
this.token = token;
};
exports.default = API;
API.prototype.request = function request(method, data) {
return (0, _fetch2.default)(this.token + '/' + method, data);
};
var methods = ['getMe', 'sendMessage', 'forwardMessage', 'sendPhoto', 'sendAudio', 'sendDocument', 'sendSticker', 'sendVideo', 'sendLocation', 'sendChatAction', 'getUserProfilePhotos', 'getUpdates', 'setWebhook'];
methods.forEach(function (method) {
API.prototype[method] = function (data) {
return this.request(method, data);
};
});
module.exports = exports['default'];