Sha256: 9f3979944b2482e85813ec616cd2270175c230cd339271f7524e0a2cfd5ddf0a

Contents?: true

Size: 1.24 KB

Versions: 24

Compression:

Stored size: 1.24 KB

Contents

module Telegram
  module Bot
    class Client
      # Actions with type-casted results. Install `telegram-bot-types` gem first.
      module TypedResponse
        {
          getFile:              :File,
          getMe:                :User,
          getUpdates:           [:Update],
          getUserProfilePhotos: :UserProfilePhotos,

          forwardMessage:       :Message,
          sendAudio:            :Message,
          sendDocument:         :Message,
          sendLocation:         :Message,
          sendMessage:          :Message,
          sendPhoto:            :Message,
          sendSticker:          :Message,
          sendVideo:            :Message,
          sendVoice:            :Message,
        }.each do |method, type|
          next unless type
          if type.is_a?(Array)
            type_class = Types.const_get(type.first)
            define_method(method.to_s.underscore) do |*args|
              request(method, *args)['result'].map { |x| type_class.new(x) }
            end
          else
            type_class = Types.const_get(type)
            define_method(method.to_s.underscore) do |*args|
              type_class.new request(method, *args)['result']
            end
          end
        end
      end
    end
  end
end

Version data entries

24 entries across 24 versions & 1 rubygems

Version Path
telegram-bot-0.13.0 lib/telegram/bot/client/typed_response.rb
telegram-bot-0.12.4 lib/telegram/bot/client/typed_response.rb
telegram-bot-0.12.3 lib/telegram/bot/client/typed_response.rb
telegram-bot-0.12.1 lib/telegram/bot/client/typed_response.rb
telegram-bot-0.12.0 lib/telegram/bot/client/typed_response.rb
telegram-bot-0.11.3 lib/telegram/bot/client/typed_response.rb
telegram-bot-0.11.2 lib/telegram/bot/client/typed_response.rb
telegram-bot-0.11.1 lib/telegram/bot/client/typed_response.rb
telegram-bot-0.11.0 lib/telegram/bot/client/typed_response.rb
telegram-bot-0.10.2 lib/telegram/bot/client/typed_response.rb
telegram-bot-0.10.1 lib/telegram/bot/client/typed_response.rb
telegram-bot-0.10.0 lib/telegram/bot/client/typed_response.rb
telegram-bot-0.9.0 lib/telegram/bot/client/typed_response.rb
telegram-bot-0.9.0.alpha2 lib/telegram/bot/client/typed_response.rb
telegram-bot-0.9.0.alpha1 lib/telegram/bot/client/typed_response.rb
telegram-bot-0.8.0 lib/telegram/bot/client/typed_response.rb
telegram-bot-0.7.4 lib/telegram/bot/client/typed_response.rb
telegram-bot-0.7.3 lib/telegram/bot/client/typed_response.rb
telegram-bot-0.7.2 lib/telegram/bot/client/typed_response.rb
telegram-bot-0.6.0 lib/telegram/bot/client/typed_response.rb