Sha256: 09ce62fa7cd03e0627f323e13c89b8d158652ddf7d8ad703abcf24ab1894a726

Contents?: true

Size: 847 Bytes

Versions: 15

Compression:

Stored size: 847 Bytes

Contents

require 'telegram/bot/client/api_helper'
require 'active_support/core_ext/string/inflections'

module Telegram
  module Bot
    class Client
      # Actions with type-casted results. Install `telegram-bot-types` gem first.
      module TypedResponse
        # First we define methods for every available api method to return `result`
        # field instead of object.
        ApiHelper.methods_list.each do |method|
          define_method(method.to_s.underscore) do |*args|
            super(*args)['result']
          end
        end

        # And then override some of them which has castable results.
        Types::Response::WRAPPED_METHODS.each do |method, type|
          define_method(method.to_s.underscore) do |*args|
            Types::Response.wrap(super(*args)['result'], type)
          end
        end
      end
    end
  end
end

Version data entries

15 entries across 15 versions & 1 rubygems

Version Path
telegram-bot-0.16.1 lib/telegram/bot/client/typed_response.rb
telegram-bot-0.16.0 lib/telegram/bot/client/typed_response.rb
telegram-bot-0.15.7 lib/telegram/bot/client/typed_response.rb
telegram-bot-0.15.6 lib/telegram/bot/client/typed_response.rb
telegram-bot-0.15.4 lib/telegram/bot/client/typed_response.rb
telegram-bot-0.15.3 lib/telegram/bot/client/typed_response.rb
telegram-bot-0.15.2 lib/telegram/bot/client/typed_response.rb
telegram-bot-0.15.1 lib/telegram/bot/client/typed_response.rb
telegram-bot-0.15.0 lib/telegram/bot/client/typed_response.rb
telegram-bot-0.14.4 lib/telegram/bot/client/typed_response.rb
telegram-bot-0.14.3 lib/telegram/bot/client/typed_response.rb
telegram-bot-0.14.2 lib/telegram/bot/client/typed_response.rb
telegram-bot-0.14.1 lib/telegram/bot/client/typed_response.rb
telegram-bot-0.14.0 lib/telegram/bot/client/typed_response.rb
telegram-bot-0.13.1 lib/telegram/bot/client/typed_response.rb