Class: Telegrambot::Api
- Inherits:
-
Object
- Object
- Telegrambot::Api
- Defined in:
- lib/telegrambot/api.rb
Constant Summary collapse
- REPLY_MARKUP_TYPES =
[ Telegrambot::Types::ReplyKeyboardMarkup, Telegrambot::Types::ReplyKeyboardHide, Telegrambot::Types::ForceReply, Telegrambot::Types::InlineKeyboardMarkup ].freeze
Instance Attribute Summary collapse
-
#token ⇒ Object
readonly
Returns the value of attribute token.
Class Method Summary collapse
-
.snakecase(endpoint) ⇒ Object
Convierte un camelCase a snake_case.
Instance Method Summary collapse
-
#endpoint ⇒ Hash
Endpoints de Telegram Bot API (Metaprogramming).
-
#initialize(token) ⇒ Api
constructor
A new instance of Api.
Constructor Details
#initialize(token) ⇒ Api
Returns a new instance of Api.
13 14 15 |
# File 'lib/telegrambot/api.rb', line 13 def initialize(token) @token = token end |
Instance Attribute Details
#token ⇒ Object (readonly)
Returns the value of attribute token.
4 5 6 |
# File 'lib/telegrambot/api.rb', line 4 def token @token end |
Class Method Details
.snakecase(endpoint) ⇒ Object
Convierte un camelCase a snake_case
20 21 22 23 24 25 26 |
# File 'lib/telegrambot/api.rb', line 20 def self.snakecase(endpoint) endpoint.to_s.gsub(/::/, '/'). gsub(/([A-Z]+)([A-Z][a-z])/,'\1_\2'). gsub(/([a-z\d])([A-Z])/,'\1_\2'). tr("-", "_"). downcase end |
Instance Method Details
#endpoint ⇒ Hash
Endpoints de Telegram Bot API (Metaprogramming)
34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 |
# File 'lib/telegrambot/api.rb', line 34 %w( getUpdates setWebhook getMe sendMessage forwardMessage sendPhoto sendAudio sendDocument sendSticker sendVideo sendVoice sendLocation sendVenue sendContact sendChatAction getUserProfilePhotos getFile kickChatMember unbanChatMember answerCallbackQuery editMessageText editMessageCaption editMessageReplyMarkup answerInlineQuery getChat leaveChat getChatAdministrators getChatMember getChatMembersCount ).map{ |e| snakecase(e) }.each do | endpoint | define_method endpoint do | raw_params = {} | params = build_params(raw_params) response = rest_client.post("/bot#{token}/#{camelcase(endpoint)}", params) raise Telegrambot::Exceptions::ResponseError.new(response) unless response.status == 200 JSON.parse(response.body) end end |