Sha256: 8fca60fd9029367bba21c393d0d08a593f08153288b1e85360e99e1890e918a5

Contents?: true

Size: 872 Bytes

Versions: 3

Compression:

Stored size: 872 Bytes

Contents

# frozen_string_literal: true

require 'active_support/core_ext/string/inflections'

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

        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

3 entries across 3 versions & 1 rubygems

Version Path
telegram-bot-0.16.5 lib/telegram/bot/client/api_helper.rb
telegram-bot-0.16.4 lib/telegram/bot/client/api_helper.rb
telegram-bot-0.16.3 lib/telegram/bot/client/api_helper.rb