2015-07-05 13:36:27 +00:00
'use strict' ;
2016-03-27 20:29:00 +00:00
Object . defineProperty ( exports , "__esModule" , {
2015-07-05 13:36:27 +00:00
value : true
} ) ;
var _fetch = require ( './fetch' ) ;
var _fetch2 = _interopRequireDefault ( _fetch ) ;
2016-03-27 20:29:00 +00:00
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
2015-07-05 13:36:27 +00:00
/ * *
* 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 ;
} ;
2016-03-27 20:29:00 +00:00
exports . default = API ;
2015-07-05 13:36:27 +00:00
API . prototype . request = function request ( method , data ) {
2016-03-27 20:29:00 +00:00
return ( 0 , _fetch2 . default ) ( this . token + '/' + method , data ) ;
2015-07-05 13:36:27 +00:00
} ;
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' ] ;