Module: Telegram::Bot::Client::ApiHelper

Included in:
Telegram::Bot::Client
Defined in:
lib/telegram/bot/client/api_helper.rb

Constant Summary collapse

METHODS_LIST_FILE =
File.expand_path('api_methods.txt', __dir__)

Class Method Summary collapse

Class Method Details

.define_helpers(*list) ⇒ Object

Defines method with underscored name to post to specific endpoint:

define_method :getMe
# defines #get_me


22
23
24
25
26
# File 'lib/telegram/bot/client/api_helper.rb', line 22

def define_helpers(*list)
  list.map(&:to_s).each do |method|
    define_method(method.underscore) { |*args| request(method, *args) }
  end
end

.methods_list(file = METHODS_LIST_FILE) ⇒ Object



12
13
14
15
16
# File 'lib/telegram/bot/client/api_helper.rb', line 12

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