ruby-vibe 1.0.0 → 2.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/ruby-vibe/bot.rb +106 -0
- data/lib/ruby-vibe/client.rb +112 -16
- data/lib/ruby-vibe/shortcuts.rb +95 -0
- data/lib/ruby-vibe/url.rb +29 -0
- data/lib/ruby-vibe/version.rb +9 -3
- data/lib/ruby_vibe.rb +32 -0
- metadata +26 -28
- data/lib/ruby-vibe/calls/info.rb +0 -37
- data/lib/ruby-vibe/calls/messaging.rb +0 -40
- data/lib/ruby-vibe/calls.rb +0 -9
- data/lib/ruby-vibe/configuration.rb +0 -21
- data/lib/ruby-vibe/response.rb +0 -30
- data/lib/ruby-vibe/urls.rb +0 -11
- data/lib/ruby-vibe.rb +0 -17
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 30acb26bd491e4aebe669f700fab799753548402d735143904e8350d44082f43
|
4
|
+
data.tar.gz: b07b9d5e5486dcb2c58c819880f6743b79b3203274b68df0937af5620391e44e
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: e9037553e0158052cf54f3ece05fe0857913904ff1cb8ce180af7390827e312ab3d0cb4b43aa6c5a49169a20fe78c4f53704e9a102feba1f1c791eea9aab5676
|
7
|
+
data.tar.gz: e4f1335e2254e32f74e239ad48a5237aca3791bb7918e245462866978cba381aa155b04f234403863d7a3988ce21b71128c2eaf101ec00f5b98e893541846320
|
@@ -0,0 +1,106 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require_relative 'client'
|
4
|
+
|
5
|
+
module RubyVibe
|
6
|
+
##
|
7
|
+
# Set of predefined viber api requests. This class is used directly by user.
|
8
|
+
# Define constants for configuration settings, or add them on initialization.
|
9
|
+
#
|
10
|
+
# @example Set default configuration
|
11
|
+
# RubyVibe::TOKEN = 'my_viber_auth_token'
|
12
|
+
# RubyVibe::NAME = 'my_viber_nickname'
|
13
|
+
# RubyVibe::AVATAR = 'avatar_url'
|
14
|
+
#
|
15
|
+
class Bot < RubyVibe::Client
|
16
|
+
##
|
17
|
+
# @example Initialize new bot with user-defined configuration
|
18
|
+
# @bot = RubyVibe::Bot.new(token: 'auth_token',
|
19
|
+
# name: 'sender_name',
|
20
|
+
# avatar: 'https_avatar_url' )
|
21
|
+
#
|
22
|
+
# @param [String] token **Optional**. Auth token provided by Viber.
|
23
|
+
# @param [String] name **Optional**. Sender name provided by user.
|
24
|
+
# @param [String] avatar **Optional**. SSL link to user photo.
|
25
|
+
#
|
26
|
+
# @return [Bot] Bot object to work with.
|
27
|
+
#
|
28
|
+
def initialize(token: nil, name: nil, avatar: nil)
|
29
|
+
token ||= RubyVibe::TOKEN
|
30
|
+
name ||= RubyVibe::NAME
|
31
|
+
avatar ||= RubyVibe::AVATAR
|
32
|
+
|
33
|
+
super(token: token, name: name, avatar: avatar)
|
34
|
+
end
|
35
|
+
|
36
|
+
##
|
37
|
+
# Send message to user.
|
38
|
+
# @see https://developers.viber.com/docs/api/rest-bot-api/#send-message
|
39
|
+
#
|
40
|
+
# @param [Hash] opts
|
41
|
+
#
|
42
|
+
# @option opts [String] message **Required**. Message text
|
43
|
+
# @option opts [String] receiver **Required**. Message receiver
|
44
|
+
# @option opts [String] sender_name **Optional**. Sender name || RubyVibe::NAME
|
45
|
+
# @option opts [String] avatar **Optional**. Avatar url || RubyVibe::AVATAR
|
46
|
+
# @option opts [String] keyboard **Optional**. Add keyboard to message
|
47
|
+
# @option opts [String] rich_media **Optional**. Send rich_media message
|
48
|
+
#
|
49
|
+
# @return [Hash] Response hash defined in RubyVibe::Client
|
50
|
+
#
|
51
|
+
def send_message(opts = {})
|
52
|
+
opts.merge!(type: 'text') unless opts[:type]
|
53
|
+
|
54
|
+
viberize(URL::SEND_MESSAGE, opts)
|
55
|
+
end
|
56
|
+
|
57
|
+
##
|
58
|
+
# Broadcast message to multiple users.
|
59
|
+
# @see https://developers.viber.com/docs/api/rest-bot-api/#broadcast-message
|
60
|
+
#
|
61
|
+
# @param [Hash] opts Viber API options for broadcast_message request
|
62
|
+
#
|
63
|
+
# @option opts [String] message **Required**. Message text
|
64
|
+
# @option opts [Array] receivers **Required**. Message receivers
|
65
|
+
# @option opts [String] sender_name **Optional**. Sender name || RubyVibe::NAME
|
66
|
+
# @option opts [String] avatar **Optional**. Avatar url || RubyVibe::AVATAR
|
67
|
+
# @option opts [String] keyboard **Optional**. Add keyboard to message
|
68
|
+
# @option opts [String] rich_media **Optional**. Send rich_media message
|
69
|
+
#
|
70
|
+
# @return [Hash] Response hash defined in RubyVibe::Client
|
71
|
+
#
|
72
|
+
def broadcast_message(opts = {})
|
73
|
+
opts.merge!(type: 'text') unless opts[:type]
|
74
|
+
|
75
|
+
viberize(URL::BROADCAST_MESSAGE, opts)
|
76
|
+
end
|
77
|
+
|
78
|
+
##
|
79
|
+
# @see https://developers.viber.com/docs/api/rest-bot-api/#set-webhook
|
80
|
+
#
|
81
|
+
def set_webhook(opts = {})
|
82
|
+
viberize(URL::SET_WEBHOOK, opts)
|
83
|
+
end
|
84
|
+
|
85
|
+
##
|
86
|
+
# @see https://developers.viber.com/docs/api/rest-bot-api/#get-account-info
|
87
|
+
#
|
88
|
+
def get_account_info
|
89
|
+
viberize(URL::GET_ACCOUNT_INFO, info: true)
|
90
|
+
end
|
91
|
+
|
92
|
+
##
|
93
|
+
# @see https://developers.viber.com/docs/api/rest-bot-api/#get-user-details
|
94
|
+
#
|
95
|
+
def get_user_details(user_id)
|
96
|
+
viberize(URL::GET_USER_DETAILS, id: user_id, info: true)
|
97
|
+
end
|
98
|
+
|
99
|
+
##
|
100
|
+
# @see https://developers.viber.com/docs/api/rest-bot-api/#get-online
|
101
|
+
#
|
102
|
+
def get_online(*user_ids)
|
103
|
+
viberize(URL::GET_ONLINE, ids: Array(user_ids), info: true)
|
104
|
+
end
|
105
|
+
end
|
106
|
+
end
|
data/lib/ruby-vibe/client.rb
CHANGED
@@ -1,33 +1,129 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
require 'rest-client'
|
2
4
|
require 'json'
|
3
5
|
|
4
|
-
|
6
|
+
module RubyVibe
|
7
|
+
##
|
8
|
+
# This class is almost never used directly by user.
|
9
|
+
# Send actual request to viber api and perform type validation
|
10
|
+
# for token, name and avatar (must be strings).
|
11
|
+
#
|
5
12
|
class Client
|
6
|
-
|
7
|
-
|
13
|
+
attr_accessor :token, :name, :avatar
|
14
|
+
|
15
|
+
attr_reader :response, :payload_hash
|
16
|
+
|
17
|
+
alias sender name
|
8
18
|
|
9
|
-
|
10
|
-
|
19
|
+
##
|
20
|
+
# @example Initialize new client
|
21
|
+
#
|
22
|
+
# @client = Client.new(token: 'token', name: 'name', avatar: 'https_url')
|
23
|
+
#
|
24
|
+
# @param [String] token **Required**. Viber auth token.
|
25
|
+
# @param [String] name **Required**. Sender name.
|
26
|
+
# @param [String] avatar **Optional**. Avatar url.
|
27
|
+
#
|
28
|
+
# @raise [Token must be string] Token must be string.
|
29
|
+
# @raise [Name must be string] Name must be string.
|
30
|
+
# @raise [Avatar must use SSL] If defined, avatar must use https connection.
|
31
|
+
#
|
32
|
+
# @return [Object]
|
33
|
+
#
|
34
|
+
def initialize(token: nil, name: nil, avatar: nil)
|
35
|
+
raise 'Token must be string!' unless token.is_a? String
|
36
|
+
raise 'Sender name must be string' unless name.is_a? String
|
11
37
|
|
12
|
-
|
38
|
+
raise 'Avatar URL must use SSL' if !avatar.empty? && !(avatar.start_with? 'https://')
|
39
|
+
|
40
|
+
@token = token
|
41
|
+
@name = name
|
42
|
+
@avatar = avatar
|
13
43
|
end
|
14
44
|
|
15
|
-
|
45
|
+
private
|
46
|
+
|
47
|
+
##
|
48
|
+
# Send payload to Viber API.
|
49
|
+
#
|
50
|
+
# @param [String] url **Required**. API url to send payload.
|
51
|
+
# @param [Hash] payload **Optional**. Payload to send with request.
|
52
|
+
# @return [Hash] Bot#response hash with all data.
|
53
|
+
#
|
54
|
+
def action(url, payload: {})
|
16
55
|
headers = {
|
17
56
|
'User-Agent': "RubyVibe client v#{RubyVibe::VERSION})",
|
18
|
-
'X-Viber-Auth-Token': token
|
57
|
+
'X-Viber-Auth-Token': @token
|
19
58
|
}
|
20
59
|
|
21
60
|
response = ::RestClient::Request.execute(
|
22
|
-
method:
|
23
|
-
url:
|
24
|
-
payload:
|
25
|
-
headers:
|
26
|
-
timeout:
|
61
|
+
method: :post,
|
62
|
+
url: url,
|
63
|
+
payload: payload.to_json,
|
64
|
+
headers: headers,
|
65
|
+
timeout: 5,
|
27
66
|
verify_ssl: ::OpenSSL::SSL::VERIFY_NONE
|
28
67
|
)
|
29
|
-
|
30
|
-
|
68
|
+
|
69
|
+
@response = parse(response)
|
70
|
+
end
|
71
|
+
|
72
|
+
##
|
73
|
+
# Method used by bot to construct viber api request.
|
74
|
+
# Prepare payload and send it to api url.
|
75
|
+
#
|
76
|
+
# @param [String] api_url **Required**. URL corresponding to method name.
|
77
|
+
# @param [Hash] opts **Optional**. Payload corresponding to method options.
|
78
|
+
#
|
79
|
+
def viberize(api_url, opts = {})
|
80
|
+
payload = load_payload(opts)
|
81
|
+
action(api_url, payload: payload)
|
82
|
+
end
|
83
|
+
|
84
|
+
##
|
85
|
+
# Construct payload to send with request.
|
86
|
+
# If payload contain `info: true`, do not add sender name and avatar url.
|
87
|
+
# Otherwise, add them together with _options hash_ to payload.
|
88
|
+
# Nil values are not imported.
|
89
|
+
#
|
90
|
+
# @param [Hash] opts **Optional**. Data to create payload.
|
91
|
+
# @return [Hash] Client#payload_hash to send with request.
|
92
|
+
#
|
93
|
+
def load_payload(opts = {})
|
94
|
+
@payload_hash = {}
|
95
|
+
|
96
|
+
if opts[:info].nil?
|
97
|
+
@payload_hash[:sender] = {
|
98
|
+
name: opts[:sender_name] || @name,
|
99
|
+
avatar: opts[:sender_avatar] || @avatar
|
100
|
+
}
|
101
|
+
end
|
102
|
+
|
103
|
+
opts.map do |key, value|
|
104
|
+
next if value.nil?
|
105
|
+
next if key == :info
|
106
|
+
|
107
|
+
@payload_hash[key] = value
|
108
|
+
end
|
109
|
+
@payload_hash
|
110
|
+
end
|
111
|
+
|
112
|
+
##
|
113
|
+
# Construct response hash. Parse viber response and check status code.
|
114
|
+
# If code is not zero (**0**), add `error_message` to response.
|
115
|
+
#
|
116
|
+
def parse(response)
|
117
|
+
success = true
|
118
|
+
error_message = nil
|
119
|
+
hash = JSON.parse(response.body)
|
120
|
+
|
121
|
+
unless hash['status'].to_i.zero?
|
122
|
+
success = false
|
123
|
+
error_message = hash['status_message']
|
124
|
+
end
|
125
|
+
|
126
|
+
Struct.new(:success?, :data, :error_message).new(success, hash, error_message)
|
31
127
|
end
|
32
128
|
end
|
33
|
-
end
|
129
|
+
end
|
@@ -0,0 +1,95 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module RubyVibe
|
4
|
+
##
|
5
|
+
# Shortcut to initialize Bot and send message.
|
6
|
+
# @see https://developers.viber.com/docs/api/rest-bot-api/#send-message
|
7
|
+
#
|
8
|
+
# @note Configuration constants must be defined to use this class.
|
9
|
+
#
|
10
|
+
# @example Configure constants
|
11
|
+
# RubyVibe::TOKEN = 'my_api_token'
|
12
|
+
# RubyVibe::NAME = 'my_nickname'
|
13
|
+
# RubyVibe::AVATAR = 'https_avatar_url'
|
14
|
+
#
|
15
|
+
# @example Send text message
|
16
|
+
# msg = RubyVibe::SendMessage[text: 'text', sender_name: 'my_nickname']
|
17
|
+
# pp msg.error_message unless msg.success?
|
18
|
+
#
|
19
|
+
class SendMessage
|
20
|
+
##
|
21
|
+
# Send message to user.
|
22
|
+
#
|
23
|
+
# @param [Hash] opts
|
24
|
+
# @return [Data#response]
|
25
|
+
# @see Bot#send_message
|
26
|
+
#
|
27
|
+
def self.[](opts = {})
|
28
|
+
Bot.new.send_message(opts)
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
32
|
+
##
|
33
|
+
# Shortcut to initialize Bot and broadcast message.
|
34
|
+
# @see https://developers.viber.com/docs/api/rest-bot-api/#broadcast-message
|
35
|
+
#
|
36
|
+
# @note Configuration constants must be defined to use shortcut classes
|
37
|
+
#
|
38
|
+
# @example Configure constants
|
39
|
+
# RubyVibe::TOKEN = 'my_api_token'
|
40
|
+
# RubyVibe::NAME = 'my_nickname'
|
41
|
+
# RubyVibe::AVATAR = 'https_avatar_url'
|
42
|
+
#
|
43
|
+
class BroadcastMessage
|
44
|
+
##
|
45
|
+
# @example Broadcast message to multiple users
|
46
|
+
# msg = RubyVibe::BroadcastMessage[text: 'text',
|
47
|
+
# receivers: %w[user_1 user_2]
|
48
|
+
# ]
|
49
|
+
# pp msg.error_message unless msg.success?
|
50
|
+
#
|
51
|
+
def self.[](opts = {})
|
52
|
+
Bot.new.broadcast_message(opts)
|
53
|
+
end
|
54
|
+
end
|
55
|
+
|
56
|
+
##
|
57
|
+
# @see https://developers.viber.com/docs/api/rest-bot-api/#set-webhook
|
58
|
+
#
|
59
|
+
class SetWebhook
|
60
|
+
# @note Configuration constants must be defined to use shortcut classes
|
61
|
+
def self.[](opts = {})
|
62
|
+
Bot.new.set_webhook(opts)
|
63
|
+
end
|
64
|
+
end
|
65
|
+
|
66
|
+
##
|
67
|
+
# @see https://developers.viber.com/docs/api/rest-bot-api/#get-account-info
|
68
|
+
#
|
69
|
+
class GetAccountInfo
|
70
|
+
# @note Configuration constants must be defined to use shortcut classes
|
71
|
+
def self.[]
|
72
|
+
Bot.new.get_account_info
|
73
|
+
end
|
74
|
+
end
|
75
|
+
|
76
|
+
##
|
77
|
+
# @see https://developers.viber.com/docs/api/rest-bot-api/#get-user-details
|
78
|
+
#
|
79
|
+
class GetUserDetails
|
80
|
+
# @note Configuration constants must be defined to use shortcut classes
|
81
|
+
def self.[](user_id)
|
82
|
+
Bot.new.get_user_details(user_id)
|
83
|
+
end
|
84
|
+
end
|
85
|
+
|
86
|
+
##
|
87
|
+
# @see https://developers.viber.com/docs/api/rest-bot-api/#get-online
|
88
|
+
#
|
89
|
+
class GetOnline
|
90
|
+
# @note Configuration constants must be defined to use shortcut classes
|
91
|
+
def self.[](*user_ids)
|
92
|
+
Bot.new.get_online(*user_ids)
|
93
|
+
end
|
94
|
+
end
|
95
|
+
end
|
@@ -0,0 +1,29 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
##
|
4
|
+
# Viber API urls as constant for corresponding method.
|
5
|
+
#
|
6
|
+
# @see https://developers.viber.com/docs/api/rest-bot-api
|
7
|
+
#
|
8
|
+
module URL
|
9
|
+
# viber api url
|
10
|
+
API = 'https://chatapi.viber.com/pa'
|
11
|
+
|
12
|
+
# api url to set webhook
|
13
|
+
SET_WEBHOOK = "#{API}/set_webhook".freeze
|
14
|
+
|
15
|
+
# api url to send message to user
|
16
|
+
SEND_MESSAGE = "#{API}/send_message".freeze
|
17
|
+
|
18
|
+
# api url to get info about your account
|
19
|
+
GET_ACCOUNT_INFO = "#{API}/get_account_info".freeze
|
20
|
+
|
21
|
+
# api url to get info about user (twice per 12h for each ID)
|
22
|
+
GET_USER_DETAILS = "#{API}/get_user_details".freeze
|
23
|
+
|
24
|
+
# api url to broadcast message to multiple users (must be subscribed to bot)
|
25
|
+
BROADCAST_MESSAGE = "#{API}/broadcast_message".freeze
|
26
|
+
|
27
|
+
# api url to check if user(s) is online
|
28
|
+
GET_ONLINE = "#{API}/get_online".freeze
|
29
|
+
end
|
data/lib/ruby-vibe/version.rb
CHANGED
data/lib/ruby_vibe.rb
ADDED
@@ -0,0 +1,32 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require_relative 'ruby-vibe/url'
|
4
|
+
require_relative 'ruby-vibe/bot'
|
5
|
+
require_relative 'ruby-vibe/shortcuts'
|
6
|
+
require_relative 'ruby-vibe/version'
|
7
|
+
|
8
|
+
##
|
9
|
+
# RubyVibe represent a main module for Viber Bot.
|
10
|
+
# Multiple classes are used as shortcut classes,
|
11
|
+
# calling methods from RubyVibe::Bot class.
|
12
|
+
# Actual request to viber api is done by RubyVibe::Client class.
|
13
|
+
# Urls for viber API are defined in URL module.
|
14
|
+
#
|
15
|
+
# @see RubyVibe::Bot
|
16
|
+
# @see RubyVibe::Client
|
17
|
+
# @see URL
|
18
|
+
# @see [File] lib/ruby-vibe/shortcuts.rb
|
19
|
+
#
|
20
|
+
|
21
|
+
require 'byebug'
|
22
|
+
|
23
|
+
module RubyVibe
|
24
|
+
# viber api auth_token to be used if not given by user
|
25
|
+
TOKEN = ''
|
26
|
+
|
27
|
+
# sender name to be used if not given by user
|
28
|
+
NAME = ''
|
29
|
+
|
30
|
+
# avatar url to be used if not given by user (require https)
|
31
|
+
AVATAR = ''
|
32
|
+
end
|
metadata
CHANGED
@@ -1,71 +1,72 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: ruby-vibe
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version:
|
4
|
+
version: 2.0.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Adem Dinarevic
|
8
8
|
autorequire:
|
9
|
-
bindir:
|
9
|
+
bindir:
|
10
|
+
- bin
|
10
11
|
cert_chain: []
|
11
|
-
date:
|
12
|
+
date: 2022-06-30 00:00:00.000000000 Z
|
12
13
|
dependencies:
|
13
14
|
- !ruby/object:Gem::Dependency
|
14
|
-
name:
|
15
|
+
name: rest-client
|
15
16
|
requirement: !ruby/object:Gem::Requirement
|
16
17
|
requirements:
|
17
|
-
- -
|
18
|
+
- - "~>"
|
18
19
|
- !ruby/object:Gem::Version
|
19
|
-
version: 2.1.
|
20
|
-
type: :
|
20
|
+
version: 2.1.0
|
21
|
+
type: :runtime
|
21
22
|
prerelease: false
|
22
23
|
version_requirements: !ruby/object:Gem::Requirement
|
23
24
|
requirements:
|
24
|
-
- -
|
25
|
+
- - "~>"
|
25
26
|
- !ruby/object:Gem::Version
|
26
|
-
version: 2.1.
|
27
|
+
version: 2.1.0
|
27
28
|
- !ruby/object:Gem::Dependency
|
28
|
-
name:
|
29
|
+
name: pry
|
29
30
|
requirement: !ruby/object:Gem::Requirement
|
30
31
|
requirements:
|
31
32
|
- - "~>"
|
32
33
|
- !ruby/object:Gem::Version
|
33
|
-
version:
|
34
|
+
version: 0.14.1
|
34
35
|
type: :development
|
35
36
|
prerelease: false
|
36
37
|
version_requirements: !ruby/object:Gem::Requirement
|
37
38
|
requirements:
|
38
39
|
- - "~>"
|
39
40
|
- !ruby/object:Gem::Version
|
40
|
-
version:
|
41
|
+
version: 0.14.1
|
41
42
|
- !ruby/object:Gem::Dependency
|
42
|
-
name:
|
43
|
+
name: rake
|
43
44
|
requirement: !ruby/object:Gem::Requirement
|
44
45
|
requirements:
|
45
46
|
- - "~>"
|
46
47
|
- !ruby/object:Gem::Version
|
47
|
-
version:
|
48
|
+
version: 13.0.3
|
48
49
|
type: :development
|
49
50
|
prerelease: false
|
50
51
|
version_requirements: !ruby/object:Gem::Requirement
|
51
52
|
requirements:
|
52
53
|
- - "~>"
|
53
54
|
- !ruby/object:Gem::Version
|
54
|
-
version:
|
55
|
+
version: 13.0.3
|
55
56
|
- !ruby/object:Gem::Dependency
|
56
|
-
name:
|
57
|
+
name: rspec
|
57
58
|
requirement: !ruby/object:Gem::Requirement
|
58
59
|
requirements:
|
59
60
|
- - "~>"
|
60
61
|
- !ruby/object:Gem::Version
|
61
|
-
version: '
|
62
|
-
type: :
|
62
|
+
version: '3.0'
|
63
|
+
type: :development
|
63
64
|
prerelease: false
|
64
65
|
version_requirements: !ruby/object:Gem::Requirement
|
65
66
|
requirements:
|
66
67
|
- - "~>"
|
67
68
|
- !ruby/object:Gem::Version
|
68
|
-
version: '
|
69
|
+
version: '3.0'
|
69
70
|
description: Ruby client for Viber API
|
70
71
|
email:
|
71
72
|
- ademdinarevic@gmail.com
|
@@ -73,15 +74,12 @@ executables: []
|
|
73
74
|
extensions: []
|
74
75
|
extra_rdoc_files: []
|
75
76
|
files:
|
76
|
-
- lib/ruby-vibe.rb
|
77
|
-
- lib/ruby-vibe/calls.rb
|
78
|
-
- lib/ruby-vibe/calls/info.rb
|
79
|
-
- lib/ruby-vibe/calls/messaging.rb
|
77
|
+
- lib/ruby-vibe/bot.rb
|
80
78
|
- lib/ruby-vibe/client.rb
|
81
|
-
- lib/ruby-vibe/
|
82
|
-
- lib/ruby-vibe/
|
83
|
-
- lib/ruby-vibe/urls.rb
|
79
|
+
- lib/ruby-vibe/shortcuts.rb
|
80
|
+
- lib/ruby-vibe/url.rb
|
84
81
|
- lib/ruby-vibe/version.rb
|
82
|
+
- lib/ruby_vibe.rb
|
85
83
|
homepage: https://github.com/ademdc/ruby-vibe
|
86
84
|
licenses:
|
87
85
|
- MIT
|
@@ -94,14 +92,14 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
94
92
|
requirements:
|
95
93
|
- - ">="
|
96
94
|
- !ruby/object:Gem::Version
|
97
|
-
version:
|
95
|
+
version: 3.0.1
|
98
96
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
99
97
|
requirements:
|
100
98
|
- - ">="
|
101
99
|
- !ruby/object:Gem::Version
|
102
100
|
version: '0'
|
103
101
|
requirements: []
|
104
|
-
rubygems_version: 3.
|
102
|
+
rubygems_version: 3.1.2
|
105
103
|
signing_key:
|
106
104
|
specification_version: 4
|
107
105
|
summary: Ruby client for Viber API
|
data/lib/ruby-vibe/calls/info.rb
DELETED
@@ -1,37 +0,0 @@
|
|
1
|
-
class RubyVibe
|
2
|
-
module Calls
|
3
|
-
module Info
|
4
|
-
|
5
|
-
def get_account_data
|
6
|
-
client.action(RubyVibe::URLS::GET_ACCOUNT_INFO)
|
7
|
-
end
|
8
|
-
|
9
|
-
def set_webhook(url, events: [], send_name: true, send_photo: true)
|
10
|
-
payload = {
|
11
|
-
url: url,
|
12
|
-
event_types: events,
|
13
|
-
send_name: send_name,
|
14
|
-
send_photo: send_photo
|
15
|
-
}
|
16
|
-
|
17
|
-
client.action(RubyVibe::URLS::SET_WEBHOOK, payload: payload)
|
18
|
-
end
|
19
|
-
|
20
|
-
def get_user_details(user_id)
|
21
|
-
payload = {
|
22
|
-
id: user_id
|
23
|
-
}
|
24
|
-
|
25
|
-
client.action(RubyVibe::URLS::GET_USER_DETAILS, payload: payload)
|
26
|
-
end
|
27
|
-
|
28
|
-
def get_online(ids=[])
|
29
|
-
payload = {
|
30
|
-
ids: ids
|
31
|
-
}
|
32
|
-
|
33
|
-
client.action(RubyVibe::URLS::GET_ONLINE, payload: payload)
|
34
|
-
end
|
35
|
-
end
|
36
|
-
end
|
37
|
-
end
|
@@ -1,40 +0,0 @@
|
|
1
|
-
class RubyVibe
|
2
|
-
module Calls
|
3
|
-
module Messaging
|
4
|
-
|
5
|
-
def send_message(receiver:, text:, sender_name: nil, sender_avatar: nil, tracking_data: nil, type: 'text', keyboard: nil)
|
6
|
-
payload = {
|
7
|
-
receiver:receiver,
|
8
|
-
sender:{
|
9
|
-
name:sender_name || RubyVibe.config.sender_name,
|
10
|
-
avatar:sender_avatar || RubyVibe.config.sender_avatar
|
11
|
-
},
|
12
|
-
tracking_data:tracking_data,
|
13
|
-
type:type,
|
14
|
-
text:text
|
15
|
-
}.compact
|
16
|
-
|
17
|
-
payload.merge!({ keyboard: keyboard }) unless keyboard.nil?
|
18
|
-
|
19
|
-
client.action(RubyVibe::URLS::MESSAGE, payload: payload)
|
20
|
-
end
|
21
|
-
|
22
|
-
def broadcast_message(broadcast_list:[], text:, sender_name: nil, sender_avatar: nil, type: 'text', rich_media: nil, keyboard: nil)
|
23
|
-
payload = {
|
24
|
-
sender:{
|
25
|
-
name: sender_name || RubyVibe.config.sender_name,
|
26
|
-
avatar: sender_avatar || RubyVibe.config.sender_avatar
|
27
|
-
},
|
28
|
-
type: type,
|
29
|
-
text: text,
|
30
|
-
broadcast_list: broadcast_list,
|
31
|
-
}
|
32
|
-
|
33
|
-
payload.merge!({ rich_media: rich_media }) unless rich_media.nil?
|
34
|
-
payload.merge!({ keyboard: keyboard }) unless keyboard.nil?
|
35
|
-
|
36
|
-
client.action(RubyVibe::URLS::BROADCAST_MESSAGE, payload: payload)
|
37
|
-
end
|
38
|
-
end
|
39
|
-
end
|
40
|
-
end
|
data/lib/ruby-vibe/calls.rb
DELETED
@@ -1,21 +0,0 @@
|
|
1
|
-
class RubyVibe
|
2
|
-
class << self
|
3
|
-
# Accessor for global configuration.
|
4
|
-
attr_accessor :config
|
5
|
-
end
|
6
|
-
|
7
|
-
def self.configure
|
8
|
-
self.config ||= Configuration.new
|
9
|
-
yield(config) if block_given?
|
10
|
-
end
|
11
|
-
|
12
|
-
class Configuration
|
13
|
-
attr_accessor :auth_token, :sender_name, :sender_avatar
|
14
|
-
|
15
|
-
def initialize
|
16
|
-
@auth_token = nil
|
17
|
-
@sender_name = nil
|
18
|
-
@sender_avatar = 'http://avatar.example.com'
|
19
|
-
end
|
20
|
-
end
|
21
|
-
end
|
data/lib/ruby-vibe/response.rb
DELETED
@@ -1,30 +0,0 @@
|
|
1
|
-
class RubyVibe
|
2
|
-
class Response
|
3
|
-
|
4
|
-
attr_accessor :response
|
5
|
-
|
6
|
-
def initialize(response)
|
7
|
-
@response = response
|
8
|
-
end
|
9
|
-
|
10
|
-
class << self
|
11
|
-
def parse(response)
|
12
|
-
response = new(response)
|
13
|
-
response.parse
|
14
|
-
end
|
15
|
-
end
|
16
|
-
|
17
|
-
def parse
|
18
|
-
success = true
|
19
|
-
error_message = nil
|
20
|
-
hash = JSON.parse(response.body)
|
21
|
-
|
22
|
-
unless hash.dig('status').to_i == 0
|
23
|
-
success = false
|
24
|
-
error_message = hash.dig('status_message')
|
25
|
-
end
|
26
|
-
|
27
|
-
Struct.new(:success?, :se, :error_message).new(success, hash, error_message)
|
28
|
-
end
|
29
|
-
end
|
30
|
-
end
|
data/lib/ruby-vibe/urls.rb
DELETED
@@ -1,11 +0,0 @@
|
|
1
|
-
class RubyVibe
|
2
|
-
module URLS
|
3
|
-
API = 'https://chatapi.viber.com/pa'.freeze
|
4
|
-
SET_WEBHOOK = "#{API}/set_webhook".freeze
|
5
|
-
MESSAGE = "#{API}/send_message".freeze
|
6
|
-
GET_ACCOUNT_INFO = "#{API}/get_account_info".freeze
|
7
|
-
GET_USER_DETAILS = "#{API}/get_user_details".freeze
|
8
|
-
BROADCAST_MESSAGE = "#{API}/broadcast_message".freeze
|
9
|
-
GET_ONLINE = "#{API}/get_online".freeze
|
10
|
-
end
|
11
|
-
end
|
data/lib/ruby-vibe.rb
DELETED
@@ -1,17 +0,0 @@
|
|
1
|
-
require 'ruby-vibe/client'
|
2
|
-
require 'ruby-vibe/calls'
|
3
|
-
require 'ruby-vibe/version'
|
4
|
-
require 'ruby-vibe/configuration'
|
5
|
-
require 'ruby-vibe/urls'
|
6
|
-
require 'ruby-vibe/response'
|
7
|
-
|
8
|
-
class RubyVibe
|
9
|
-
|
10
|
-
attr_accessor :client
|
11
|
-
|
12
|
-
include Calls
|
13
|
-
|
14
|
-
def initialize(auth_token: nil)
|
15
|
-
@client = Client.new(auth_token: auth_token)
|
16
|
-
end
|
17
|
-
end
|