viberroo 0.3.0 → 0.3.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/viberroo/bot.rb +10 -0
- data/lib/viberroo/configuration.rb +13 -0
- data/lib/viberroo/response.rb +0 -22
- data/lib/viberroo/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: cfdd2b9cf561f8fe620e7e8fd58c646aded156836519095de599f794022c5771
|
4
|
+
data.tar.gz: 394fcb5010e801f8595c2fe33cb5f28d72e95d961a7cf13cb33b8d006dc59a86
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 155014f7f40d8730f9ad41c9193dd739caa33b906587e0ff4ba6ed2fe7e3890841c12eff617ec7951cceaecca1923cbb59f5a6eecb24a9bf7ff3a664a4f582ac
|
7
|
+
data.tar.gz: 7baf397be2823482dc211c0c3392f3c8bedf981da346e06dc9dae91d41e27db0ce7feb5afdf4d151a65e67bdf9d3a003389cc7ee077123d9dc7f371efa0ee4df
|
data/lib/viberroo/bot.rb
CHANGED
@@ -1,7 +1,10 @@
|
|
1
1
|
require 'net/http'
|
2
2
|
require 'uri'
|
3
3
|
|
4
|
+
# Namespace for all Viberroo code.
|
4
5
|
module Viberroo
|
6
|
+
|
7
|
+
# Used for sending requests to Viber API. Each request sends a http POST request to a particular endpoint, each returns http response.
|
5
8
|
class Bot
|
6
9
|
def initialize(token: nil, response: nil)
|
7
10
|
Viberroo.configure
|
@@ -13,32 +16,39 @@ module Viberroo
|
|
13
16
|
@response = response
|
14
17
|
end
|
15
18
|
|
19
|
+
# Used to set bot webhook.
|
16
20
|
def set_webhook(url:, event_types: nil, send_name: nil, send_photo: nil)
|
17
21
|
request(URL::WEBHOOK, url: url, event_types: event_types,
|
18
22
|
send_name: send_name, send_photo: send_photo)
|
19
23
|
end
|
20
24
|
|
25
|
+
# Used to remove bot webhook.
|
21
26
|
def remove_webhook
|
22
27
|
request(URL::WEBHOOK, url: '')
|
23
28
|
end
|
24
29
|
|
30
|
+
# Used to send messages.
|
25
31
|
def send(message:, keyboard: {})
|
26
32
|
request(URL::MESSAGE,
|
27
33
|
{ receiver: @response&.user_id }.merge(message).merge(keyboard))
|
28
34
|
end
|
29
35
|
|
36
|
+
# Used to broadcast messages.
|
30
37
|
def broadcast(message:, to:)
|
31
38
|
request(URL::BROADCAST_MESSAGE, message.merge(broadcast_list: to))
|
32
39
|
end
|
33
40
|
|
41
|
+
# Used to retrieve account info. These settings can be set in you Viber admin panel.
|
34
42
|
def get_account_info
|
35
43
|
request(URL::GET_ACCOUNT_INFO)
|
36
44
|
end
|
37
45
|
|
46
|
+
# Used to retrieve details of a particular user.
|
38
47
|
def get_user_details(id:)
|
39
48
|
request(URL::GET_USER_DETAILS, id: id)
|
40
49
|
end
|
41
50
|
|
51
|
+
# Used to get online of a list of subscribed users.
|
42
52
|
def get_online(ids:)
|
43
53
|
request(URL::GET_ONLINE, ids: ids)
|
44
54
|
end
|
@@ -1,24 +1,37 @@
|
|
1
1
|
module Viberroo
|
2
2
|
class << self
|
3
|
+
# Accessor for global configuration.
|
3
4
|
attr_accessor :config
|
4
5
|
end
|
5
6
|
|
7
|
+
# Yields the global configuration to a block. Returns existing configuration if one was defined earlier.
|
8
|
+
# @yield [Configuration] global configuration
|
9
|
+
#
|
10
|
+
# @example
|
11
|
+
# RSpec.configure do |config|
|
12
|
+
# config.auth_token = 'syEsp8e0'
|
13
|
+
# end
|
14
|
+
# @see Viberroo::Configuration
|
6
15
|
def self.configure
|
7
16
|
self.config ||= Configuration.new
|
8
17
|
yield(config) if block_given?
|
9
18
|
end
|
10
19
|
|
20
|
+
# Stores runtime configuration information.
|
11
21
|
class Configuration
|
12
22
|
attr_accessor :logger, :auth_token, :parse_response_body
|
13
23
|
|
14
24
|
def initialize
|
25
|
+
# Stores Viber API authentication token. Necessary for the bot to send API requests.
|
15
26
|
@auth_token = nil
|
16
27
|
|
28
|
+
# Specifies logger.
|
17
29
|
@logger = Logger.new(STDOUT)
|
18
30
|
@logger.formatter = proc do |severity, datetime, _, msg|
|
19
31
|
"[#{datetime}] #{severity} Viberroo::Bot #{msg}\n"
|
20
32
|
end
|
21
33
|
|
34
|
+
# Specifies whether to parse request response body.
|
22
35
|
@parse_response_body = true
|
23
36
|
end
|
24
37
|
end
|
data/lib/viberroo/response.rb
CHANGED
@@ -1,28 +1,6 @@
|
|
1
1
|
require 'recursive-open-struct'
|
2
2
|
|
3
3
|
module Viberroo
|
4
|
-
class Response
|
5
|
-
attr_reader :params
|
6
|
-
|
7
|
-
def initialize(params)
|
8
|
-
warn 'DEPRECATION WARNING: Callback class will be renamed to Response in next minor release.'
|
9
|
-
@params = RecursiveOpenStruct.new params.to_h
|
10
|
-
end
|
11
|
-
|
12
|
-
def user_id
|
13
|
-
case @params.event
|
14
|
-
when 'conversation_started', 'subscribed'
|
15
|
-
@params.user.id
|
16
|
-
when 'unsubscribed', 'delivered', 'seen', 'failed'
|
17
|
-
@params.user_id
|
18
|
-
when 'message'
|
19
|
-
@params.sender.id
|
20
|
-
else
|
21
|
-
@params.dig(:user, :id)
|
22
|
-
end
|
23
|
-
end
|
24
|
-
end
|
25
|
-
|
26
4
|
class Response
|
27
5
|
attr_reader :params
|
28
6
|
|
data/lib/viberroo/version.rb
CHANGED