vonage 7.27.0 → 8.0.0.beta
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/README.md +89 -388
- data/lib/vonage/applications.rb +4 -12
- data/lib/vonage/basic.rb +1 -1
- data/lib/vonage/bearer_token.rb +1 -1
- data/lib/vonage/client.rb +0 -65
- data/lib/vonage/client_error.rb +1 -1
- data/lib/vonage/config.rb +1 -9
- data/lib/vonage/conversations/events.rb +0 -12
- data/lib/vonage/conversations/legs.rb +0 -6
- data/lib/vonage/conversations/members.rb +0 -15
- data/lib/vonage/conversations/users.rb +0 -15
- data/lib/vonage/conversations.rb +0 -30
- data/lib/vonage/errors.rb +20 -37
- data/lib/vonage/gsm7.rb +1 -1
- data/lib/vonage/jwt.rb +0 -17
- data/lib/vonage/key_secret_params.rb +2 -3
- data/lib/vonage/keys.rb +1 -11
- data/lib/vonage/logger.rb +3 -5
- data/lib/vonage/messaging/channels/viber.rb +1 -8
- data/lib/vonage/messaging/channels/whats_app.rb +1 -3
- data/lib/vonage/messaging/message.rb +0 -1
- data/lib/vonage/messaging.rb +4 -34
- data/lib/vonage/namespace.rb +68 -137
- data/lib/vonage/numbers.rb +17 -40
- data/lib/vonage/server_error.rb +1 -1
- data/lib/vonage/signature.rb +5 -5
- data/lib/vonage/sms.rb +20 -20
- data/lib/vonage/version.rb +1 -1
- data/lib/vonage/video/archives.rb +53 -18
- data/lib/vonage/video/list_response.rb +11 -0
- data/lib/vonage/video/moderation.rb +22 -7
- data/lib/vonage/video/signals.rb +9 -4
- data/lib/vonage/video/streams.rb +12 -6
- data/lib/vonage/video.rb +13 -50
- data/lib/vonage/voice/actions/connect.rb +5 -34
- data/lib/vonage/voice/actions/conversation.rb +4 -10
- data/lib/vonage/voice/actions/input.rb +3 -19
- data/lib/vonage/voice/actions/notify.rb +3 -8
- data/lib/vonage/voice/actions/pay.rb +107 -0
- data/lib/vonage/voice/actions/record.rb +4 -52
- data/lib/vonage/voice/actions/stream.rb +4 -48
- data/lib/vonage/voice/actions/talk.rb +4 -54
- data/lib/vonage/voice/talk.rb +1 -11
- data/lib/vonage/voice.rb +0 -24
- data/lib/vonage.rb +0 -4
- data/vonage.gemspec +1 -3
- metadata +9 -104
- data/lib/vonage/api_error.rb +0 -33
- data/lib/vonage/conversation/event/list_response.rb +0 -11
- data/lib/vonage/conversation/event.rb +0 -108
- data/lib/vonage/conversation/list_response.rb +0 -11
- data/lib/vonage/conversation/member/list_response.rb +0 -11
- data/lib/vonage/conversation/member.rb +0 -134
- data/lib/vonage/conversation/user/conversations_list_response.rb +0 -11
- data/lib/vonage/conversation/user/sessions_list_response.rb +0 -11
- data/lib/vonage/conversation/user.rb +0 -67
- data/lib/vonage/conversation.rb +0 -164
- data/lib/vonage/meetings/applications.rb +0 -28
- data/lib/vonage/meetings/dial_in_numbers/list_response.rb +0 -11
- data/lib/vonage/meetings/dial_in_numbers.rb +0 -26
- data/lib/vonage/meetings/recordings.rb +0 -42
- data/lib/vonage/meetings/rooms/list_response.rb +0 -11
- data/lib/vonage/meetings/rooms.rb +0 -167
- data/lib/vonage/meetings/sessions/list_response.rb +0 -11
- data/lib/vonage/meetings/sessions.rb +0 -31
- data/lib/vonage/meetings/themes/list_response.rb +0 -11
- data/lib/vonage/meetings/themes.rb +0 -239
- data/lib/vonage/meetings.rb +0 -50
- data/lib/vonage/messaging/channels/rcs.rb +0 -42
- data/lib/vonage/network_authentication/client_authentication.rb +0 -39
- data/lib/vonage/network_authentication/server_authentication.rb +0 -47
- data/lib/vonage/network_authentication.rb +0 -22
- data/lib/vonage/network_number_verification.rb +0 -92
- data/lib/vonage/network_sim_swap.rb +0 -84
- data/lib/vonage/number_insight_2.rb +0 -36
- data/lib/vonage/proactive_connect/events/list_response.rb +0 -11
- data/lib/vonage/proactive_connect/events.rb +0 -71
- data/lib/vonage/proactive_connect/item.rb +0 -116
- data/lib/vonage/proactive_connect/items/file_response.rb +0 -32
- data/lib/vonage/proactive_connect/items/list_response.rb +0 -11
- data/lib/vonage/proactive_connect/items.rb +0 -116
- data/lib/vonage/proactive_connect/list.rb +0 -186
- data/lib/vonage/proactive_connect/lists/list_response.rb +0 -11
- data/lib/vonage/proactive_connect/lists.rb +0 -38
- data/lib/vonage/proactive_connect.rb +0 -43
- data/lib/vonage/subaccounts/balance_transfers/list_response.rb +0 -11
- data/lib/vonage/subaccounts/credit_transfers/list_response.rb +0 -11
- data/lib/vonage/subaccounts/list_response.rb +0 -15
- data/lib/vonage/subaccounts.rb +0 -203
- data/lib/vonage/users/list_response.rb +0 -11
- data/lib/vonage/users.rb +0 -156
- data/lib/vonage/verify2/channels/email.rb +0 -36
- data/lib/vonage/verify2/channels/silent_auth.rb +0 -45
- data/lib/vonage/verify2/channels/sms.rb +0 -63
- data/lib/vonage/verify2/channels/voice.rb +0 -32
- data/lib/vonage/verify2/channels/whats_app.rb +0 -39
- data/lib/vonage/verify2/channels/whats_app_interactive.rb +0 -32
- data/lib/vonage/verify2/start_verification_options.rb +0 -63
- data/lib/vonage/verify2/workflow.rb +0 -39
- data/lib/vonage/verify2/workflow_builder.rb +0 -25
- data/lib/vonage/verify2.rb +0 -100
- data/lib/vonage/video/archives/list_response.rb +0 -11
- data/lib/vonage/video/broadcasts/list_response.rb +0 -11
- data/lib/vonage/video/broadcasts.rb +0 -75
- data/lib/vonage/video/captions.rb +0 -67
- data/lib/vonage/video/renders/list_response.rb +0 -11
- data/lib/vonage/video/renders.rb +0 -107
- data/lib/vonage/video/sip.rb +0 -48
- data/lib/vonage/video/streams/list_response.rb +0 -11
- data/lib/vonage/video/web_socket.rb +0 -61
data/lib/vonage/keys.rb
CHANGED
@@ -27,17 +27,7 @@ module Vonage
|
|
27
27
|
'has_video',
|
28
28
|
'remove_stream',
|
29
29
|
'screenshare_type',
|
30
|
-
'
|
31
|
-
'stream_mode',
|
32
|
-
'archive_mode',
|
33
|
-
'language_code',
|
34
|
-
'max_duration',
|
35
|
-
'partial_captions',
|
36
|
-
'status_callback_url',
|
37
|
-
'audio_rate',
|
38
|
-
'phone_number',
|
39
|
-
'hashed_phone_number',
|
40
|
-
'max_age'
|
30
|
+
'archive_mode'
|
41
31
|
]
|
42
32
|
hash.transform_keys do |k|
|
43
33
|
if exceptions.include?(k.to_s)
|
data/lib/vonage/logger.rb
CHANGED
@@ -7,11 +7,7 @@ module Vonage
|
|
7
7
|
class Logger
|
8
8
|
extend T::Sig
|
9
9
|
|
10
|
-
sig { params(logger: T.nilable(
|
11
|
-
defined?(ActiveSupport::BroadcastLogger) ?
|
12
|
-
T.any(::Logger, Vonage::Logger, ActiveSupport::BroadcastLogger)
|
13
|
-
: T.any(::Logger, Vonage::Logger)
|
14
|
-
)).void }
|
10
|
+
sig { params(logger: T.nilable(T.any(::Logger, Vonage::Logger))).void }
|
15
11
|
def initialize(logger)
|
16
12
|
@logger = logger || ::Logger.new(nil)
|
17
13
|
end
|
@@ -24,6 +20,8 @@ module Vonage
|
|
24
20
|
|
25
21
|
sig { params(request: T.any(Net::HTTP::Post, Net::HTTP::Get, Net::HTTP::Delete, Net::HTTP::Put, Net::HTTP::Patch)).void }
|
26
22
|
def log_request_info(request)
|
23
|
+
@logger = T.let(@logger, T.nilable(T.any(::Logger, Vonage::Logger)))
|
24
|
+
|
27
25
|
T.must(@logger).info do
|
28
26
|
format('Vonage API request', {
|
29
27
|
method: request.method,
|
@@ -2,7 +2,7 @@
|
|
2
2
|
|
3
3
|
module Vonage
|
4
4
|
class Messaging::Channels::Viber < Messaging::Message
|
5
|
-
MESSAGE_TYPES = ['text', 'image'
|
5
|
+
MESSAGE_TYPES = ['text', 'image']
|
6
6
|
|
7
7
|
attr_reader :data
|
8
8
|
|
@@ -33,13 +33,6 @@ module Vonage
|
|
33
33
|
when 'image'
|
34
34
|
raise Vonage::ClientError.new(":message must be a Hash") unless message.is_a? Hash
|
35
35
|
raise Vonage::ClientError.new(":url is required in :message") unless message[:url]
|
36
|
-
when 'video'
|
37
|
-
raise Vonage::ClientError.new(":message must be a Hash") unless message.is_a? Hash
|
38
|
-
raise Vonage::ClientError.new(":url is required in :message") unless message[:url]
|
39
|
-
raise Vonage::ClientError.new(":thumb_url is required in :message") unless message[:thumb_url]
|
40
|
-
when 'file'
|
41
|
-
raise Vonage::ClientError.new(":message must be a Hash") unless message.is_a? Hash
|
42
|
-
raise Vonage::ClientError.new(":url is required in :message") unless message[:url]
|
43
36
|
end
|
44
37
|
end
|
45
38
|
end
|
@@ -2,7 +2,7 @@
|
|
2
2
|
|
3
3
|
module Vonage
|
4
4
|
class Messaging::Channels::WhatsApp < Messaging::Message
|
5
|
-
MESSAGE_TYPES = ['text', 'image', 'audio', 'video', 'file', 'template', '
|
5
|
+
MESSAGE_TYPES = ['text', 'image', 'audio', 'video', 'file', 'template', 'custom']
|
6
6
|
|
7
7
|
attr_reader :data
|
8
8
|
|
@@ -35,8 +35,6 @@ module Vonage
|
|
35
35
|
raise Vonage::ClientError.new(":name is required in :template") unless message[:name]
|
36
36
|
raise Vonage::ClientError.new(":whatsapp is required in :opts") unless opts[:whatsapp]
|
37
37
|
raise Vonage::ClientError.new(":locale is required in :whatsapp") unless opts[:whatsapp][:locale]
|
38
|
-
when 'sticker'
|
39
|
-
raise Vonage::ClientError.new(":message must contain either :id or :url") unless message.has_key?(:id) ^ message.has_key?(:url)
|
40
38
|
when 'custom'
|
41
39
|
raise Vonage::ClientError.new(":message must be a Hash") unless message.is_a? Hash
|
42
40
|
else
|
@@ -5,7 +5,6 @@ module Vonage
|
|
5
5
|
CHANNELS = {
|
6
6
|
sms: Vonage::Messaging::Channels::SMS,
|
7
7
|
mms: Vonage::Messaging::Channels::MMS,
|
8
|
-
rcs: Vonage::Messaging::Channels::RCS,
|
9
8
|
whatsapp: Vonage::Messaging::Channels::WhatsApp,
|
10
9
|
messenger: Vonage::Messaging::Channels::Messenger,
|
11
10
|
viber: Vonage::Messaging::Channels::Viber
|
data/lib/vonage/messaging.rb
CHANGED
@@ -1,21 +1,16 @@
|
|
1
1
|
# typed: true
|
2
2
|
# frozen_string_literal: true
|
3
|
-
require 'forwardable'
|
4
3
|
|
5
4
|
module Vonage
|
6
5
|
class Messaging < Namespace
|
7
|
-
extend Forwardable
|
8
|
-
|
9
6
|
self.authentication = BearerToken
|
10
7
|
|
11
8
|
self.request_body = JSON
|
12
9
|
|
13
|
-
def_delegators Message, *Message::CHANNELS.keys
|
14
|
-
|
15
10
|
# Send a Message.
|
16
11
|
#
|
17
12
|
# @example
|
18
|
-
# message =
|
13
|
+
# message = Vonage::Messaging::Message.sms(message: "Hello world!")
|
19
14
|
# response = client.messaging.send(to: "447700900000", from: "447700900001", **message)
|
20
15
|
#
|
21
16
|
# @option params [required, String] :to
|
@@ -25,35 +20,10 @@ module Vonage
|
|
25
20
|
# @option params [required, Hash] **message
|
26
21
|
# The Vonage Message object to use for this message.
|
27
22
|
#
|
28
|
-
# @see https://developer.vonage.com/api/messages#SendMessage
|
29
|
-
#
|
30
|
-
def send(to:, from:, **message)
|
31
|
-
request('/v1/messages', params: {to: to, from: from, **message}, type: Post)
|
32
|
-
end
|
33
|
-
|
34
|
-
# Update a Message Object.
|
35
|
-
#
|
36
|
-
# @example
|
37
|
-
# message = client.messaging.update(message_uuid: "aaaaaaaa-bbbb-4ccc-8ddd-0123456789ab", status: "read")
|
38
|
-
#
|
39
|
-
# @option params [required, String] :message_uuid. the UUID of the message to update.
|
40
|
-
#
|
41
|
-
# `:message_uuid` is always required. Other parameters will depend on the message channel and the specific action being performed.
|
42
|
-
# @see https://developer.vonage.com/api/messages#UpdateMessage
|
43
|
-
#
|
44
|
-
def update(message_uuid:, **params)
|
45
|
-
request("/v1/messages/#{message_uuid}", params: params, type: Patch)
|
46
|
-
end
|
47
|
-
|
48
|
-
# Validate a JSON Web Token from a Messages API Webhook.
|
49
|
-
#
|
50
|
-
# @param [String, required] :token The JWT from the Webhook's Authorization header
|
51
|
-
# @param [String, optional] :signature_secret The account signature secret. Required, unless `signature_secret`
|
52
|
-
# is set in `Config`
|
23
|
+
# @see https://developer.vonage.com/api/messages-olympus#SendMessage
|
53
24
|
#
|
54
|
-
|
55
|
-
|
56
|
-
JWT.verify_hs256_signature(token: token, signature_secret: signature_secret)
|
25
|
+
def send(params)
|
26
|
+
request('/v1/messages', params: params, type: Post)
|
57
27
|
end
|
58
28
|
end
|
59
29
|
end
|
data/lib/vonage/namespace.rb
CHANGED
@@ -1,9 +1,6 @@
|
|
1
1
|
# typed: true
|
2
2
|
# frozen_string_literal: true
|
3
|
-
|
4
3
|
require 'net/http'
|
5
|
-
require 'net/http/persistent'
|
6
|
-
require 'net/http/post/multipart'
|
7
4
|
require 'json'
|
8
5
|
|
9
6
|
module Vonage
|
@@ -13,7 +10,8 @@ module Vonage
|
|
13
10
|
|
14
11
|
@host = set_host
|
15
12
|
|
16
|
-
@http = Net::HTTP::
|
13
|
+
@http = Net::HTTP.new(@host, Net::HTTP.https_default_port, p_addr = nil)
|
14
|
+
@http.use_ssl = true
|
17
15
|
|
18
16
|
@config.http.set(@http) unless @config.http.nil?
|
19
17
|
end
|
@@ -23,7 +21,8 @@ module Vonage
|
|
23
21
|
end
|
24
22
|
|
25
23
|
def self.host=(host)
|
26
|
-
raise ArgumentError unless
|
24
|
+
raise ArgumentError unless host == :rest_host || host == :video_host
|
25
|
+
|
27
26
|
@host = host
|
28
27
|
end
|
29
28
|
|
@@ -48,7 +47,6 @@ module Vonage
|
|
48
47
|
end
|
49
48
|
|
50
49
|
protected
|
51
|
-
|
52
50
|
# :nocov:
|
53
51
|
|
54
52
|
Get = Net::HTTP::Get
|
@@ -57,33 +55,33 @@ module Vonage
|
|
57
55
|
Post = Net::HTTP::Post
|
58
56
|
Delete = Net::HTTP::Delete
|
59
57
|
|
60
|
-
def build_request(path:, type: Get, params: {}
|
58
|
+
def build_request(path:, type: Get, params: {})
|
61
59
|
authentication = self.class.authentication.new(@config)
|
62
|
-
authentication.update(params
|
60
|
+
authentication.update(params)
|
63
61
|
|
64
|
-
uri = URI(
|
62
|
+
uri = URI('https://' + @host + path)
|
65
63
|
unless type.const_get(:REQUEST_HAS_BODY) || params.empty?
|
66
64
|
uri.query = Params.encode(params)
|
67
65
|
end
|
68
66
|
|
67
|
+
# Set BasicAuth if neeeded
|
68
|
+
authentication.update(uri)
|
69
|
+
|
69
70
|
# instantiate request
|
70
71
|
request = type.new(uri)
|
71
72
|
|
72
73
|
# set headers
|
73
|
-
request[
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
self.class.request_headers.each { |key, value| request[key] = value }
|
74
|
+
request['User-Agent'] = UserAgent.string(@config.app_name, @config.app_version)
|
75
|
+
request['Accept'] = 'application/json'
|
76
|
+
self.class.request_headers.each do |key, value|
|
77
|
+
request[key] = value
|
78
|
+
end
|
79
79
|
|
80
|
-
# Set
|
81
|
-
authentication.update(request
|
80
|
+
# Set BearerToken if needed
|
81
|
+
authentication.update(request)
|
82
82
|
|
83
83
|
# set body
|
84
|
-
if type.const_get(:REQUEST_HAS_BODY)
|
85
|
-
self.class.request_body.update(request, params)
|
86
|
-
end
|
84
|
+
self.class.request_body.update(request, params) if type.const_get(:REQUEST_HAS_BODY)
|
87
85
|
|
88
86
|
request
|
89
87
|
end
|
@@ -91,8 +89,7 @@ module Vonage
|
|
91
89
|
def make_request!(request, &block)
|
92
90
|
logger.log_request_info(request)
|
93
91
|
|
94
|
-
|
95
|
-
response = @http.request(uri, request, &block)
|
92
|
+
response = @http.request(request, &block)
|
96
93
|
|
97
94
|
logger.log_response_info(response, @host)
|
98
95
|
|
@@ -103,32 +100,17 @@ module Vonage
|
|
103
100
|
response
|
104
101
|
end
|
105
102
|
|
106
|
-
def request(path, params: nil, type: Get, response_class: Response,
|
107
|
-
auto_advance =
|
108
|
-
(
|
109
|
-
if !params.nil? && params.key?(:auto_advance)
|
110
|
-
params[:auto_advance]
|
111
|
-
else
|
112
|
-
false
|
113
|
-
end
|
114
|
-
)
|
103
|
+
def request(path, params: nil, type: Get, response_class: Response, &block)
|
104
|
+
auto_advance = !params.nil? && params.key?(:auto_advance) ? params[:auto_advance] : false
|
115
105
|
|
116
|
-
params =
|
117
|
-
params.tap { |params| params.delete(:auto_advance) } if !params.nil? &&
|
118
|
-
params.key?(:auto_advance)
|
106
|
+
params = params.tap { |params| params.delete(:auto_advance) } if !params.nil? && params.key?(:auto_advance)
|
119
107
|
|
120
|
-
request = build_request(path: path, params: params || {}, type: type
|
108
|
+
request = build_request(path: path, params: params || {}, type: type)
|
121
109
|
|
122
110
|
response = make_request!(request, &block)
|
123
111
|
|
124
112
|
if auto_advance
|
125
|
-
iterable_request(
|
126
|
-
path,
|
127
|
-
response: response,
|
128
|
-
response_class: response_class,
|
129
|
-
params: params,
|
130
|
-
&block
|
131
|
-
)
|
113
|
+
iterable_request(path, response: response, response_class: response_class, params: params, &block)
|
132
114
|
else
|
133
115
|
return if block
|
134
116
|
|
@@ -136,59 +118,22 @@ module Vonage
|
|
136
118
|
end
|
137
119
|
end
|
138
120
|
|
139
|
-
def multipart_post_request(path, filepath:, file_name:, mime_type:, params: {}, override_uri: nil, no_auth: false, response_class: Response, auth_data: nil, &block)
|
140
|
-
authentication = self.class.authentication.new(@config) unless no_auth
|
141
|
-
|
142
|
-
uri = override_uri ? URI(override_uri) : URI('https://' + @host + path)
|
143
|
-
|
144
|
-
http = Net::HTTP.new(uri.host, Net::HTTP.https_default_port, p_addr = nil)
|
145
|
-
http.use_ssl = true
|
146
|
-
http.set_debug_output($stdout)
|
147
|
-
|
148
|
-
response = File.open(filepath) do |file|
|
149
|
-
request = Net::HTTP::Post::Multipart.new(
|
150
|
-
uri,
|
151
|
-
params.merge(file: Multipart::Post::UploadIO.new(file, mime_type, file_name))
|
152
|
-
)
|
153
|
-
|
154
|
-
request['User-Agent'] = UserAgent.string(@config.app_name, @config.app_version)
|
155
|
-
|
156
|
-
# Set Authorization header if needed
|
157
|
-
authentication.update(request, auth_data) unless no_auth
|
158
|
-
|
159
|
-
logger.log_request_info(request)
|
160
|
-
|
161
|
-
http.request(request, &block)
|
162
|
-
end
|
163
|
-
|
164
|
-
logger.log_response_info(response, @host)
|
165
|
-
|
166
|
-
return if block
|
167
|
-
|
168
|
-
logger.debug(response.body) if response.body
|
169
|
-
|
170
|
-
parse(response, response_class)
|
171
|
-
end
|
172
|
-
|
173
121
|
def iterable_request(path, response: nil, response_class: nil, params: {}, &block)
|
174
122
|
json_response = ::JSON.parse(response.body)
|
175
123
|
response = parse(response, response_class)
|
176
124
|
remainder = remaining_count(json_response)
|
177
125
|
|
178
126
|
while remainder > 0
|
179
|
-
params = { page_size: json_response[
|
180
|
-
|
181
|
-
if json_response[
|
182
|
-
params[:record_index] = json_response[
|
183
|
-
elsif json_response[
|
184
|
-
|
185
|
-
params[:record_index] = (
|
186
|
-
json_response["record_index"] + json_response["page_size"]
|
187
|
-
)
|
127
|
+
params = { page_size: json_response['page_size'] }
|
128
|
+
|
129
|
+
if json_response['record_index'] && json_response['record_index'] == 0
|
130
|
+
params[:record_index] = json_response['page_size']
|
131
|
+
elsif json_response['record_index'] && json_response['record_index'] != 0
|
132
|
+
params[:record_index] = (json_response['record_index'] + json_response['page_size'])
|
188
133
|
end
|
189
134
|
|
190
|
-
if json_response[
|
191
|
-
params[:page] = json_response[
|
135
|
+
if json_response['total_pages']
|
136
|
+
params[:page] = json_response['page'] + 1
|
192
137
|
end
|
193
138
|
|
194
139
|
request = build_request(path: path, type: Get, params: params)
|
@@ -199,15 +144,11 @@ module Vonage
|
|
199
144
|
json_response = ::JSON.parse(paginated_response.body)
|
200
145
|
remainder = remaining_count(json_response)
|
201
146
|
|
202
|
-
if response.respond_to?(
|
203
|
-
collection_name = collection_name(response[
|
204
|
-
response[
|
205
|
-
*next_response["_embedded"][collection_name]
|
206
|
-
)
|
147
|
+
if response.respond_to?('_embedded')
|
148
|
+
collection_name = collection_name(response['_embedded'])
|
149
|
+
response['_embedded'][collection_name].push(*next_response['_embedded'][collection_name])
|
207
150
|
else
|
208
|
-
response[collection_name(response)].push(
|
209
|
-
*next_response[collection_name(next_response)]
|
210
|
-
)
|
151
|
+
response[collection_name(response)].push(*next_response[collection_name(next_response)])
|
211
152
|
end
|
212
153
|
end
|
213
154
|
|
@@ -215,51 +156,43 @@ module Vonage
|
|
215
156
|
end
|
216
157
|
|
217
158
|
def remaining_count(params)
|
218
|
-
if params.key?(
|
219
|
-
params[
|
220
|
-
elsif params.key?(
|
221
|
-
params[
|
222
|
-
(
|
223
|
-
if params["record_index"] == 0
|
224
|
-
params["page_size"]
|
225
|
-
else
|
226
|
-
(params["record_index"] + params["page_size"])
|
227
|
-
end
|
228
|
-
)
|
159
|
+
if params.key?('total_pages')
|
160
|
+
params['total_pages'] - params['page']
|
161
|
+
elsif params.key?('count')
|
162
|
+
params['count'] - (params['record_index'] == 0 ? params['page_size'] : (params['record_index'] + params['page_size']))
|
229
163
|
else
|
230
164
|
0
|
231
165
|
end
|
232
166
|
end
|
233
167
|
|
234
168
|
def collection_name(params)
|
235
|
-
@collection_name ||=
|
236
|
-
|
237
|
-
|
238
|
-
|
239
|
-
|
240
|
-
|
241
|
-
|
242
|
-
|
243
|
-
|
244
|
-
|
245
|
-
|
246
|
-
|
247
|
-
|
248
|
-
|
249
|
-
|
250
|
-
|
251
|
-
|
252
|
-
|
253
|
-
|
254
|
-
|
255
|
-
|
256
|
-
|
257
|
-
|
258
|
-
|
259
|
-
|
260
|
-
|
261
|
-
|
262
|
-
"events"
|
169
|
+
@collection_name ||= case
|
170
|
+
when params.respond_to?('calls')
|
171
|
+
'calls'
|
172
|
+
when params.respond_to?('users')
|
173
|
+
'users'
|
174
|
+
when params.respond_to?('legs')
|
175
|
+
'legs'
|
176
|
+
when params.respond_to?('data')
|
177
|
+
'data'
|
178
|
+
when params.respond_to?('conversations')
|
179
|
+
'conversations'
|
180
|
+
when params.respond_to?('applications')
|
181
|
+
'applications'
|
182
|
+
when params.respond_to?('records')
|
183
|
+
'records'
|
184
|
+
when params.respond_to?('reports')
|
185
|
+
'reports'
|
186
|
+
when params.respond_to?('networks')
|
187
|
+
'networks'
|
188
|
+
when params.respond_to?('countries')
|
189
|
+
'countries'
|
190
|
+
when params.respond_to?('media')
|
191
|
+
'media'
|
192
|
+
when params.respond_to?('numbers')
|
193
|
+
'numbers'
|
194
|
+
when params.respond_to?('events')
|
195
|
+
'events'
|
263
196
|
else
|
264
197
|
params.entity.attributes.keys[0].to_s
|
265
198
|
end
|
@@ -270,7 +203,7 @@ module Vonage
|
|
270
203
|
when Net::HTTPNoContent
|
271
204
|
response_class.new(nil, response)
|
272
205
|
when Net::HTTPSuccess
|
273
|
-
if response['Content-Type']
|
206
|
+
if response['Content-Type'].split(';').first == 'application/json'
|
274
207
|
entity = ::JSON.parse(response.body, object_class: Vonage::Entity)
|
275
208
|
|
276
209
|
response_class.new(entity, response)
|
@@ -294,8 +227,6 @@ module Vonage
|
|
294
227
|
@config.rest_host
|
295
228
|
when :video_host
|
296
229
|
@config.video_host
|
297
|
-
when :vonage_host
|
298
|
-
@config.vonage_host
|
299
230
|
else
|
300
231
|
@config.api_host
|
301
232
|
end
|
data/lib/vonage/numbers.rb
CHANGED
@@ -5,8 +5,6 @@ module Vonage
|
|
5
5
|
class Numbers < Namespace
|
6
6
|
include Keys
|
7
7
|
|
8
|
-
self.authentication = Basic
|
9
|
-
|
10
8
|
self.host = :rest_host
|
11
9
|
|
12
10
|
# Retrieve all the inbound numbers associated with your Vonage account.
|
@@ -17,8 +15,6 @@ module Vonage
|
|
17
15
|
# puts "#{item.msisdn} #{item.country} #{item.type}"
|
18
16
|
# end
|
19
17
|
#
|
20
|
-
# @param [Hash] params
|
21
|
-
#
|
22
18
|
# @option params [String] :application_id
|
23
19
|
# The application that you want to return the numbers for.
|
24
20
|
#
|
@@ -49,12 +45,14 @@ module Vonage
|
|
49
45
|
# Set this to `true` to auto-advance through all the pages in the record
|
50
46
|
# and collect all the data. The default is `false`.
|
51
47
|
#
|
48
|
+
# @param [Hash] params
|
49
|
+
#
|
52
50
|
# @return [ListResponse]
|
53
51
|
#
|
54
52
|
# @see https://developer.nexmo.com/api/developer/numbers#getOwnedNumbers
|
55
53
|
#
|
56
54
|
def list(params = nil)
|
57
|
-
request(
|
55
|
+
request('/account/numbers', params: params, response_class: ListResponse)
|
58
56
|
end
|
59
57
|
|
60
58
|
# Retrieve inbound numbers that are available for the specified country.
|
@@ -65,8 +63,6 @@ module Vonage
|
|
65
63
|
# puts "#{item.msisdn} #{item.type} #{item.cost}"
|
66
64
|
# end
|
67
65
|
#
|
68
|
-
# @param [Hash] params
|
69
|
-
#
|
70
66
|
# @option params [required, String] :country
|
71
67
|
# The two character country code in ISO 3166-1 alpha-2 format.
|
72
68
|
#
|
@@ -84,7 +80,7 @@ module Vonage
|
|
84
80
|
# - `2` - Search for numbers that end with **:pattern**
|
85
81
|
#
|
86
82
|
# @option params [String] :features
|
87
|
-
# Available features are `SMS
|
83
|
+
# Available features are `SMS` and `VOICE`.
|
88
84
|
# To look for numbers that support both, use a comma-separated value: `SMS,VOICE`.
|
89
85
|
#
|
90
86
|
# @option params [Integer] :size
|
@@ -97,12 +93,14 @@ module Vonage
|
|
97
93
|
# Set this to `true` to auto-advance through all the pages in the record
|
98
94
|
# and collect all the data. The default is `false`.
|
99
95
|
#
|
96
|
+
# @param [Hash] params
|
97
|
+
#
|
100
98
|
# @return [ListResponse]
|
101
99
|
#
|
102
100
|
# @see https://developer.nexmo.com/api/developer/numbers#getAvailableNumbers
|
103
101
|
#
|
104
102
|
def search(params)
|
105
|
-
request(
|
103
|
+
request('/number/search', params: params, response_class: ListResponse)
|
106
104
|
end
|
107
105
|
|
108
106
|
# Request to purchase a specific inbound number.
|
@@ -110,8 +108,6 @@ module Vonage
|
|
110
108
|
# @example
|
111
109
|
# response = client.numbers.buy(country: 'GB', msisdn: '447700900000')
|
112
110
|
#
|
113
|
-
# @param [Hash] params
|
114
|
-
#
|
115
111
|
# @option params [required, String] :country
|
116
112
|
# The two character country code in ISO 3166-1 alpha-2 format.
|
117
113
|
#
|
@@ -122,17 +118,14 @@ module Vonage
|
|
122
118
|
# If you'd like to perform an action on a subaccount, provide the `api_key` of that account here.
|
123
119
|
# If you'd like to perform an action on your own account, you do not need to provide this field.
|
124
120
|
#
|
121
|
+
# @param [Hash] params
|
122
|
+
#
|
125
123
|
# @return [Response]
|
126
124
|
#
|
127
125
|
# @see https://developer.nexmo.com/api/developer/numbers#buyANumber
|
128
126
|
#
|
129
127
|
def buy(params)
|
130
|
-
request(
|
131
|
-
"/number/buy",
|
132
|
-
params: params,
|
133
|
-
type: Post,
|
134
|
-
response_class: Response
|
135
|
-
)
|
128
|
+
request('/number/buy', params: params, type: Post, response_class: Response)
|
136
129
|
end
|
137
130
|
|
138
131
|
# Cancel your subscription for a specific inbound number.
|
@@ -140,8 +133,6 @@ module Vonage
|
|
140
133
|
# @example
|
141
134
|
# response = client.numbers.cancel(country: 'GB', msisdn: '447700900000')
|
142
135
|
#
|
143
|
-
# @param [Hash] params
|
144
|
-
#
|
145
136
|
# @option params [required, String] :country
|
146
137
|
# The two character country code in ISO 3166-1 alpha-2 format.
|
147
138
|
#
|
@@ -152,17 +143,14 @@ module Vonage
|
|
152
143
|
# If you'd like to perform an action on a subaccount, provide the `api_key` of that account here.
|
153
144
|
# If you'd like to perform an action on your own account, you do not need to provide this field.
|
154
145
|
#
|
146
|
+
# @param [Hash] params
|
147
|
+
#
|
155
148
|
# @return [Response]
|
156
149
|
#
|
157
150
|
# @see https://developer.nexmo.com/api/developer/numbers#cancelANumber
|
158
151
|
#
|
159
152
|
def cancel(params)
|
160
|
-
request(
|
161
|
-
"/number/cancel",
|
162
|
-
params: params,
|
163
|
-
type: Post,
|
164
|
-
response_class: Response
|
165
|
-
)
|
153
|
+
request('/number/cancel', params: params, type: Post, response_class: Response)
|
166
154
|
end
|
167
155
|
|
168
156
|
# Change the behaviour of a number that you own.
|
@@ -177,8 +165,6 @@ module Vonage
|
|
177
165
|
#
|
178
166
|
# response = client.numbers.update(params)
|
179
167
|
#
|
180
|
-
# @param [Hash] params
|
181
|
-
#
|
182
168
|
# @option params [required, String] :country
|
183
169
|
# The two character country code in ISO 3166-1 alpha-2 format.
|
184
170
|
#
|
@@ -205,30 +191,21 @@ module Vonage
|
|
205
191
|
# @option params [String] :voice_status_callback
|
206
192
|
# A webhook URI for Vonage to send a request to when a call ends.
|
207
193
|
#
|
194
|
+
# @param [Hash] params
|
195
|
+
#
|
208
196
|
# @return [Response]
|
209
197
|
#
|
210
198
|
# @see https://developer.nexmo.com/api/developer/numbers#updateANumber
|
211
199
|
#
|
212
200
|
def update(params)
|
213
|
-
request(
|
214
|
-
"/number/update",
|
215
|
-
params: camelcase(params),
|
216
|
-
type: Post,
|
217
|
-
response_class: Response
|
218
|
-
)
|
201
|
+
request('/number/update', params: camelcase(params), type: Post, response_class: Response)
|
219
202
|
end
|
220
203
|
|
221
204
|
private
|
222
205
|
|
223
206
|
# A specific implementation of iterable_request for Numbers, because the Numbers API
|
224
207
|
# handles pagination differently to other Vonage APIs
|
225
|
-
def iterable_request(
|
226
|
-
path,
|
227
|
-
response: nil,
|
228
|
-
response_class: nil,
|
229
|
-
params: {},
|
230
|
-
&block
|
231
|
-
)
|
208
|
+
def iterable_request(path, response: nil, response_class: nil, params: {}, &block)
|
232
209
|
response = parse(response, response_class)
|
233
210
|
params[:index] = 1 unless params.has_key?(:index)
|
234
211
|
size = params.fetch(:size, 10)
|