Module: Igni::API

Included in:
Bot
Defined in:
lib/igni/api.rb

Instance Method Summary collapse

Instance Method Details

#getMeObject



29
30
31
# File 'lib/igni/api.rb', line 29

def getMe
  self.request('getMe', {})
end

#getUpdates(offset, limit, timeout) ⇒ Object



21
22
23
# File 'lib/igni/api.rb', line 21

def getUpdates(offset, limit, timeout)
  self.request('getUpdades', { :offset => offset, :limit => limit, :timeout => timeout })
end

#request(method, payload) ⇒ Object



6
7
8
9
10
11
12
13
14
15
# File 'lib/igni/api.rb', line 6

def request(method, payload)
  req = Unirest.post("https://api.telegram.org/bot#{@token}/#{method}",
        parameters: payload)

  if req.body['ok'] != true
    raise 'Error: ' + req.body['description'] + ' ' + req.raw_body
  end

  return req.body
end

#sendMessage(chat_id, text) ⇒ Object



25
26
27
# File 'lib/igni/api.rb', line 25

def sendMessage(chat_id, text)
  self.request('sendMessage', { :chat_id => chat_id, :text => text })
end

#setWebhook(url) ⇒ Object



17
18
19
# File 'lib/igni/api.rb', line 17

def setWebhook(url)
  self.request('setWebhook', { :url => "https://#{url}/webhook/#{@token}" })
end