Class: Telegram::Bot::Api
- Inherits:
-
Object
- Object
- Telegram::Bot::Api
- 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
-
#token ⇒ Object
readonly
Returns the value of attribute token.
Instance Method Summary collapse
- #call(endpoint, params = {}) ⇒ Object
-
#initialize(token) ⇒ Api
constructor
A new instance of Api.
- #method_missing(method_name, *args, &block) ⇒ Object
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
#token ⇒ Object (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 |