Class: Telegram::Bot::Api

Inherits:
Object
  • Object
show all
Includes:
HTTParty
Defined in:
lib/telegram/bot/api.rb

Constant Summary collapse

ENDPOINTS =
%w(
  getMe sendMessage forwardMessage sendPhoto sendAudio sendDocument
  sendSticker sendVideo sendLocation sendChatAction getUserProfilePhotos
  getUpdates setWebhook
).freeze

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(token) ⇒ Api

Returns a new instance of Api.



17
18
19
# File 'lib/telegram/bot/api.rb', line 17

def initialize(token)
  @token = token
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(method_name, *args, &block) ⇒ Object



21
22
23
# File 'lib/telegram/bot/api.rb', line 21

def method_missing(method_name, *args, &block)
  ENDPOINTS.include?(method_name.to_s) ? call(method_name, *args) : super
end

Instance Attribute Details

#tokenObject (readonly)

Returns the value of attribute token.



12
13
14
# File 'lib/telegram/bot/api.rb', line 12

def token
  @token
end

Instance Method Details

#call(endpoint, params = {}) ⇒ Object



25
26
27
# File 'lib/telegram/bot/api.rb', line 25

def call(endpoint, params = {})
  self.class.get("/bot#{token}/#{endpoint}", query: params).to_h
end