module TelegramBot::Request

Constants

API_BASE

Public Class Methods

included(clazz) click to toggle source
# File lib/telegram_bot/request.rb, line 18
def self.included(clazz)
  clazz.prepend PrependMethods
end

Public Instance Methods

request(method, params) click to toggle source
# File lib/telegram_bot/request.rb, line 22
def request(method, params)
  url    = construct_url(method)
  resp   = RestClient.post(url, params)
  json   = JSON.parse(resp.body)
  result = json['result']
  return result if resp.code.to_s =~ /^2\d\d$/
  raise Exception.new(resp)
end

Private Instance Methods

construct_url(method) click to toggle source
# File lib/telegram_bot/request.rb, line 33
def construct_url(method)
  method_camelized = method.to_s.camelize(:lower)
  "#{API_BASE}#{@token}/#{method_camelized}"
end