Class: TARS::API

Inherits:
Object
  • Object
show all
Includes:
HTTParty
Defined in:
lib/tars/api.rb

Class Method Summary collapse

Class Method Details

.meObject



14
15
16
# File 'lib/tars/api.rb', line 14

def self.me
  request 'getMe'
end

.reply_to(chat_id, text) ⇒ Object



26
27
28
# File 'lib/tars/api.rb', line 26

def self.reply_to(chat_id, text)
  request 'sendMessage', chat_id: chat_id, text: text
end

.reply_with_photo(chat_id, photo) ⇒ Object



30
31
32
33
34
35
36
37
# File 'lib/tars/api.rb', line 30

def self.reply_with_photo(chat_id, photo)
  uri = "https://#{BASE_URI}/bot#{TARS.config.token}/sendPhoto"
  random = "/tmp/#{Digest::MD5.hexdigest(photo)}#{File.extname(photo)}"

  IO.copy_stream(open(photo), random)
  RestClient.post(uri, chat_id: chat_id, photo: open(random))
  File.delete(random)
end

.updatesObject



18
19
20
# File 'lib/tars/api.rb', line 18

def self.updates
  request 'getUpdates'
end

.webhookObject



22
23
24
# File 'lib/tars/api.rb', line 22

def self.webhook
  request 'setWebhook', url: URI(TARS.config.webhook)
end