Module: TelegramBot::Request

Included in:
TelegramBot
Defined in:
lib/telegram_bot/request.rb

Defined Under Namespace

Modules: PrependMethods

Constant Summary collapse

API_BASE =
'https://api.telegram.org/bot'

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.included(clazz) ⇒ Object



18
19
20
# File 'lib/telegram_bot/request.rb', line 18

def self.included(clazz)
  clazz.prepend PrependMethods
end

Instance Method Details

#request(method, params) ⇒ Object

Raises:

  • (Exception)


22
23
24
25
26
27
28
29
# 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