Class: Viberroo::Bot

Inherits:
Object
  • Object
show all
Defined in:
lib/viberroo/bot.rb

Instance Method Summary collapse

Constructor Details

#initialize(token:, callback: nil) ⇒ Bot

Returns a new instance of Bot.



3
4
5
6
# File 'lib/viberroo/bot.rb', line 3

def initialize(token:, callback: nil)
  @headers = { 'X-Viber-Auth-Token': token, 'Content-Type': 'application/json' }
  @callback = callback
end

Instance Method Details

#broadcast(message:, to:) ⇒ Object



37
38
39
# File 'lib/viberroo/bot.rb', line 37

def broadcast(message:, to:)
  request(URL::BROADCAST_MESSAGE, message.merge(broadcast_list: to))
end

#broadcast!(message:, to:) ⇒ Object



41
42
43
# File 'lib/viberroo/bot.rb', line 41

def broadcast!(message:, to:)
  parse broadcast(message: message, to: to)
end

#get_account_infoObject



45
46
47
# File 'lib/viberroo/bot.rb', line 45

def 
  request(URL::GET_ACCOUNT_INFO)
end

#get_account_info!Object



49
50
51
# File 'lib/viberroo/bot.rb', line 49

def 
  parse 
end

#get_online(ids:) ⇒ Object



61
62
63
# File 'lib/viberroo/bot.rb', line 61

def get_online(ids:)
  request(URL::GET_ONLINE, ids: ids)
end

#get_online!(ids:) ⇒ Object



65
66
67
# File 'lib/viberroo/bot.rb', line 65

def get_online!(ids:)
  parse get_online(ids: ids)
end

#get_user_details(id:) ⇒ Object



53
54
55
# File 'lib/viberroo/bot.rb', line 53

def get_user_details(id:)
  request(URL::GET_USER_DETAILS, id: id)
end

#get_user_details!(id:) ⇒ Object



57
58
59
# File 'lib/viberroo/bot.rb', line 57

def get_user_details!(id:)
  parse get_user_details(id: id)
end

#remove_webhookObject



20
21
22
# File 'lib/viberroo/bot.rb', line 20

def remove_webhook
  request(URL::WEBHOOK, url: '')
end

#remove_webhook!Object



24
25
26
# File 'lib/viberroo/bot.rb', line 24

def remove_webhook!
  parse remove_webhook
end

#send(message:, keyboard: {}) ⇒ Object



28
29
30
31
# File 'lib/viberroo/bot.rb', line 28

def send(message:, keyboard: {})
  request(URL::MESSAGE,
          { receiver: @callback&.user_id }.merge(message).merge(keyboard))
end

#send!(message:, keyboard: {}) ⇒ Object



33
34
35
# File 'lib/viberroo/bot.rb', line 33

def send!(message:, keyboard: {})
  parse self.send(message: message, keyboard: keyboard)
end

#set_webhook(url:, event_types: nil, send_name: nil, send_photo: nil) ⇒ Object



8
9
10
11
12
# File 'lib/viberroo/bot.rb', line 8

def set_webhook(url:, event_types: nil, send_name: nil, send_photo: nil)
  request(URL::WEBHOOK, url: url, event_types: event_types,
          send_name: send_name,
          send_photo: send_photo)
end

#set_webhook!(url:, event_types: nil, send_name: nil, send_photo: nil) ⇒ Object



14
15
16
17
18
# File 'lib/viberroo/bot.rb', line 14

def set_webhook!(url:, event_types: nil, send_name: nil, send_photo: nil)
  parse set_webhook(url: url, event_types: event_types,
                    send_name: send_name,
                    send_photo: send_photo)
end