Class: Telegram::Bot::Api
- Inherits:
-
Object
- Object
- Telegram::Bot::Api
show all
- Defined in:
- lib/telegram/bot/api.rb
Constant Summary
collapse
- ENDPOINTS =
%w(
getUpdates setWebhook deleteWebhook getWebhookInfo getMe sendMessage
forwardMessage sendPhoto sendAudio sendDocument sendVideo sendVoice
sendVideoNote sendMediaGroup sendLocation editMessageLiveLocation
stopMessageLiveLocation sendVenue sendContact sendChatAction
getUserProfilePhotos getFile kickChatMember unbanChatMember
restrictChatMember promoteChatMember leaveChat getChat
getChatAdministrators exportChatInviteLink setChatPhoto deleteChatPhoto
setChatTitle setChatDescription pinChatMessage unpinChatMessage
getChatMembersCount getChatMember setChatStickerSet deleteChatStickerSet
answerCallbackQuery editMessageText editMessageCaption
editMessageReplyMarkup deleteMessage sendSticker getStickerSet
uploadStickerFile createNewStickerSet addStickerToSet
setStickerPositionInSet deleteStickerFromSet answerInlineQuery
sendInvoice answerShippingQuery answerPreCheckoutQuery
sendGame setGameScore getGameHighScores sendInvoice
).freeze
- REPLY_MARKUP_TYPES =
[
Telegram::Bot::Types::ReplyKeyboardMarkup,
Telegram::Bot::Types::ReplyKeyboardRemove,
Telegram::Bot::Types::ForceReply,
Telegram::Bot::Types::InlineKeyboardMarkup
].freeze
- INLINE_QUERY_RESULT_TYPES =
[
Telegram::Bot::Types::InlineQueryResultArticle,
Telegram::Bot::Types::InlineQueryResultPhoto,
Telegram::Bot::Types::InlineQueryResultGif,
Telegram::Bot::Types::InlineQueryResultMpeg4Gif,
Telegram::Bot::Types::InlineQueryResultVideo,
Telegram::Bot::Types::InlineQueryResultAudio,
Telegram::Bot::Types::InlineQueryResultVoice,
Telegram::Bot::Types::InlineQueryResultDocument,
Telegram::Bot::Types::InlineQueryResultLocation,
Telegram::Bot::Types::InlineQueryResultVenue,
Telegram::Bot::Types::InlineQueryResultContact,
Telegram::Bot::Types::InlineQueryResultGame,
Telegram::Bot::Types::InlineQueryResultCachedPhoto,
Telegram::Bot::Types::InlineQueryResultCachedGif,
Telegram::Bot::Types::InlineQueryResultCachedMpeg4Gif,
Telegram::Bot::Types::InlineQueryResultCachedSticker,
Telegram::Bot::Types::InlineQueryResultCachedDocument,
Telegram::Bot::Types::InlineQueryResultCachedVideo,
Telegram::Bot::Types::InlineQueryResultCachedVoice,
Telegram::Bot::Types::InlineQueryResultCachedAudio
].freeze
Instance Attribute Summary collapse
Instance Method Summary
collapse
Constructor Details
#initialize(token) ⇒ Api
Returns a new instance of Api.
52
53
54
|
# File 'lib/telegram/bot/api.rb', line 52
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
56
57
58
59
60
61
|
# File 'lib/telegram/bot/api.rb', line 56
def method_missing(method_name, *args, &block)
endpoint = method_name.to_s
endpoint = camelize(endpoint) if endpoint.include?('_')
ENDPOINTS.include?(endpoint) ? call(endpoint, *args) : super
end
|
Instance Attribute Details
#token ⇒ Object
Returns the value of attribute token.
50
51
52
|
# File 'lib/telegram/bot/api.rb', line 50
def token
@token
end
|
Instance Method Details
#call(endpoint, raw_params = {}, force = false) ⇒ Object
70
71
72
73
74
75
76
77
78
79
80
81
|
# File 'lib/telegram/bot/api.rb', line 70
def call(endpoint, raw_params = {}, force = false)
params = force ? raw_params : build_params(raw_params)
response = conn.post("/bot#{token}/#{endpoint}", params.to_json)
if response.status == 200
JSON.parse(response.body)
elsif response.finished?
raise Exceptions::ResponseError.new(response),
'Telegram API has returned the error.'
else
response
end
end
|
#in_parallel(&block) ⇒ Object
83
84
85
|
# File 'lib/telegram/bot/api.rb', line 83
def in_parallel(&block)
conn.in_parallel(&block)
end
|
#respond_to_missing?(*args) ⇒ Boolean
63
64
65
66
67
68
|
# File 'lib/telegram/bot/api.rb', line 63
def respond_to_missing?(*args)
method_name = args[0].to_s
method_name = camelize(method_name) if method_name.include?('_')
ENDPOINTS.include?(method_name) || super
end
|