ruby-vibe 1.0.1 → 2.0.2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: bf9b514d655e13e3501fbb1695fd4a9a4f7260e9e6181aa8bb8a6d9bc6dbb07c
4
- data.tar.gz: ea095d5ac68aa99ebcc621169ebd678361c60aff722d108250f2aa9e42dd71e1
3
+ metadata.gz: 57519dce750fc99dbd7a7db5f33af4c72eabd43720519f755a6aae333c20d105
4
+ data.tar.gz: 8838f746a0985c795d55f07d014f454da069edd0bf373b5efd97e7c920db3012
5
5
  SHA512:
6
- metadata.gz: 63ba09c61c1af86d97adcb44823f355466cc2225b525defbbf6c4173fafbb28dc2f125e6962e192bb14cd0c48ec90a7e126999fe864f96d5159d87e0ab4c95cc
7
- data.tar.gz: ea98f6228c8787a349da508bb0553830a8a0ee9cee76b2ece6ae94344c12709c9e55876437282088f9e346d8fc13dc876ffd282d10134d255384226a18fab3cc
6
+ metadata.gz: 997f2ab4a4d741945dd20455c8dc6b702b63f4a5d6af8a2577994db90ed25378cfbc5a1b815cdf75e42bffc1cb21f24059762f032c1965037fea7e161ec1f240
7
+ data.tar.gz: f7c10572bb27cc2fffab50ca7f9883158451adac3065510741193af137d3d09d586269f8ae5c90dcadb2746267c0ee180bd451405364d9cb3b5f1693dc77af89
@@ -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
@@ -1,33 +1,129 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'rest-client'
2
4
  require 'json'
3
5
 
4
- class RubyVibe
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
- attr_accessor :token
13
+ attr_accessor :token, :name, :avatar
14
+
15
+ attr_reader :response, :payload_hash
16
+
17
+ alias sender name
8
18
 
9
- def initialize(auth_token:)
10
- RubyVibe.configure
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
- @token = auth_token || RubyVibe.config.auth_token
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
- def action(url, payload: {}, http_method: :post)
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: http_method,
23
- url: url,
24
- payload: payload.to_json,
25
- headers: headers,
26
- timeout: 5,
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
- RubyVibe::Response.parse(response)
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
@@ -1,3 +1,9 @@
1
- class RubyVibe
2
- VERSION='1.0.1'.freeze
3
- end
1
+ # frozen_string_literal: true
2
+
3
+ ##
4
+ # Gem version
5
+ #
6
+ module RubyVibe
7
+ # version number to change with new update
8
+ VERSION = '2.0.2'
9
+ end
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,43 +1,72 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ruby-vibe
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.1
4
+ version: 2.0.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Adem Dinarevic
8
8
  autorequire:
9
- bindir: bin
9
+ bindir:
10
+ - bin
10
11
  cert_chain: []
11
- date: 2021-07-15 00:00:00.000000000 Z
12
+ date: 2022-07-01 00:00:00.000000000 Z
12
13
  dependencies:
13
14
  - !ruby/object:Gem::Dependency
14
- name: rspec
15
+ name: rest-client
15
16
  requirement: !ruby/object:Gem::Requirement
16
17
  requirements:
17
18
  - - "~>"
18
19
  - !ruby/object:Gem::Version
19
- version: '3.0'
20
+ version: 2.1.0
21
+ type: :runtime
22
+ prerelease: false
23
+ version_requirements: !ruby/object:Gem::Requirement
24
+ requirements:
25
+ - - "~>"
26
+ - !ruby/object:Gem::Version
27
+ version: 2.1.0
28
+ - !ruby/object:Gem::Dependency
29
+ name: pry
30
+ requirement: !ruby/object:Gem::Requirement
31
+ requirements:
32
+ - - "~>"
33
+ - !ruby/object:Gem::Version
34
+ version: 0.14.1
20
35
  type: :development
21
36
  prerelease: false
22
37
  version_requirements: !ruby/object:Gem::Requirement
23
38
  requirements:
24
39
  - - "~>"
25
40
  - !ruby/object:Gem::Version
26
- version: '3.0'
41
+ version: 0.14.1
27
42
  - !ruby/object:Gem::Dependency
28
- name: rest-client
43
+ name: rake
29
44
  requirement: !ruby/object:Gem::Requirement
30
45
  requirements:
31
46
  - - "~>"
32
47
  - !ruby/object:Gem::Version
33
- version: '2.0'
34
- type: :runtime
48
+ version: 13.0.3
49
+ type: :development
50
+ prerelease: false
51
+ version_requirements: !ruby/object:Gem::Requirement
52
+ requirements:
53
+ - - "~>"
54
+ - !ruby/object:Gem::Version
55
+ version: 13.0.3
56
+ - !ruby/object:Gem::Dependency
57
+ name: rspec
58
+ requirement: !ruby/object:Gem::Requirement
59
+ requirements:
60
+ - - "~>"
61
+ - !ruby/object:Gem::Version
62
+ version: '3.0'
63
+ type: :development
35
64
  prerelease: false
36
65
  version_requirements: !ruby/object:Gem::Requirement
37
66
  requirements:
38
67
  - - "~>"
39
68
  - !ruby/object:Gem::Version
40
- version: '2.0'
69
+ version: '3.0'
41
70
  description: Ruby client for Viber API
42
71
  email:
43
72
  - ademdinarevic@gmail.com
@@ -45,15 +74,12 @@ executables: []
45
74
  extensions: []
46
75
  extra_rdoc_files: []
47
76
  files:
48
- - lib/ruby-vibe.rb
49
- - lib/ruby-vibe/calls.rb
50
- - lib/ruby-vibe/calls/info.rb
51
- - lib/ruby-vibe/calls/messaging.rb
77
+ - lib/ruby-vibe/bot.rb
52
78
  - lib/ruby-vibe/client.rb
53
- - lib/ruby-vibe/configuration.rb
54
- - lib/ruby-vibe/response.rb
55
- - lib/ruby-vibe/urls.rb
79
+ - lib/ruby-vibe/shortcuts.rb
80
+ - lib/ruby-vibe/url.rb
56
81
  - lib/ruby-vibe/version.rb
82
+ - lib/ruby_vibe.rb
57
83
  homepage: https://github.com/ademdc/ruby-vibe
58
84
  licenses:
59
85
  - MIT
@@ -66,14 +92,14 @@ required_ruby_version: !ruby/object:Gem::Requirement
66
92
  requirements:
67
93
  - - ">="
68
94
  - !ruby/object:Gem::Version
69
- version: '2.3'
95
+ version: 2.2.0
70
96
  required_rubygems_version: !ruby/object:Gem::Requirement
71
97
  requirements:
72
98
  - - ">="
73
99
  - !ruby/object:Gem::Version
74
100
  version: '0'
75
101
  requirements: []
76
- rubygems_version: 3.0.9
102
+ rubygems_version: 3.1.2
77
103
  signing_key:
78
104
  specification_version: 4
79
105
  summary: Ruby client for Viber API
@@ -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
@@ -1,9 +0,0 @@
1
- require 'ruby-vibe/calls/info'
2
- require 'ruby-vibe/calls/messaging'
3
-
4
- class RubyVibe
5
- module Calls
6
- include Info
7
- include Messaging
8
- end
9
- end
@@ -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
@@ -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?, :hash, :error_message).new(success, hash, error_message)
28
- end
29
- end
30
- end
@@ -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