Sha256: f3cc349c1f25479f84ba2f3a03cd258e8a15a1afbd64b2175e34c3427b6a730f

Contents?: true

Size: 845 Bytes

Versions: 18

Compression:

Stored size: 845 Bytes

Contents

require 'active_support/core_ext/string/inflections'

module Telegram
  module Bot
    class Client
      module ApiHelper
        METHODS_LIST_FILE = File.expand_path('../api_methods.txt', __FILE__)

        class << self
          def methods_list(file = METHODS_LIST_FILE)
            File.read(file).lines.
              map(&:strip).
              reject { |x| x.empty? || x.start_with?('#') }
          end

          # Defines method with underscored name to post to specific endpoint:
          #
          #   define_method :getMe
          #   # defines #get_me
          def define_helpers(*list)
            list.map(&:to_s).each do |method|
              define_method(method.underscore) { |*args| request(method, *args) }
            end
          end
        end

        define_helpers(*methods_list)
      end
    end
  end
end

Version data entries

18 entries across 18 versions & 1 rubygems

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