nexmo 4.8.0 → 5.0.0.pre1
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 +48 -42
- data/lib/nexmo.rb +20 -0
- data/lib/nexmo/account.rb +23 -0
- data/lib/nexmo/alerts.rb +25 -0
- data/lib/nexmo/applications.rb +25 -0
- data/lib/nexmo/call_dtmf.rb +15 -0
- data/lib/nexmo/call_stream.rb +19 -0
- data/lib/nexmo/call_talk.rb +19 -0
- data/lib/nexmo/calls.rb +68 -0
- data/lib/nexmo/client.rb +75 -324
- data/lib/nexmo/conversions.rb +15 -0
- data/lib/nexmo/entity.rb +53 -0
- data/lib/nexmo/files.rb +25 -0
- data/lib/nexmo/jwt.rb +2 -1
- data/lib/nexmo/keys.rb +31 -0
- data/lib/nexmo/messages.rb +23 -0
- data/lib/nexmo/namespace.rb +83 -0
- data/lib/nexmo/number_insight.rb +21 -0
- data/lib/nexmo/numbers.rb +33 -0
- data/lib/nexmo/pricing.rb +31 -0
- data/lib/nexmo/pricing_types.rb +17 -0
- data/lib/nexmo/signature.rb +9 -1
- data/lib/nexmo/sms.rb +17 -0
- data/lib/nexmo/user_agent.rb +13 -0
- data/lib/nexmo/verify.rb +31 -0
- data/lib/nexmo/version.rb +1 -1
- data/nexmo.gemspec +3 -11
- metadata +39 -23
- data/spec/nexmo/client_spec.rb +0 -651
- data/spec/nexmo/jwt_spec.rb +0 -53
- data/spec/nexmo/params_spec.rb +0 -18
- data/spec/nexmo/signature_spec.rb +0 -20
data/lib/nexmo/version.rb
CHANGED
data/nexmo.gemspec
CHANGED
@@ -11,18 +11,10 @@ Gem::Specification.new do |s|
|
|
11
11
|
s.description = 'Nexmo Client Library for Ruby'
|
12
12
|
s.summary = 'This is the Ruby client library for Nexmo\'s API. To use it you\'ll need a Nexmo account. Sign up for free at https://www.nexmo.com'
|
13
13
|
s.files = Dir.glob('{lib,spec}/**/*') + %w(LICENSE.txt README.md nexmo.gemspec)
|
14
|
-
s.required_ruby_version = '>=
|
14
|
+
s.required_ruby_version = '>= 2.0.0'
|
15
|
+
s.add_dependency('jwt')
|
15
16
|
s.add_development_dependency('rake')
|
16
17
|
s.add_development_dependency('minitest', '~> 5.0')
|
17
|
-
|
18
|
-
if RUBY_VERSION == '1.9.3'
|
19
|
-
s.add_dependency('jwt', '< 2.0.0')
|
20
|
-
s.add_development_dependency('addressable', '< 2.5.0')
|
21
|
-
s.add_development_dependency('webmock', '~> 1.0')
|
22
|
-
else
|
23
|
-
s.add_dependency('jwt')
|
24
|
-
s.add_development_dependency('webmock', '~> 2.0')
|
25
|
-
end
|
26
|
-
|
18
|
+
s.add_development_dependency('webmock', '~> 3.0')
|
27
19
|
s.require_path = 'lib'
|
28
20
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: nexmo
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version:
|
4
|
+
version: 5.0.0.pre1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Tim Craft
|
@@ -11,13 +11,13 @@ cert_chain: []
|
|
11
11
|
date: 2017-11-15 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
|
-
name:
|
14
|
+
name: jwt
|
15
15
|
requirement: !ruby/object:Gem::Requirement
|
16
16
|
requirements:
|
17
17
|
- - ">="
|
18
18
|
- !ruby/object:Gem::Version
|
19
19
|
version: '0'
|
20
|
-
type: :
|
20
|
+
type: :runtime
|
21
21
|
prerelease: false
|
22
22
|
version_requirements: !ruby/object:Gem::Requirement
|
23
23
|
requirements:
|
@@ -25,47 +25,47 @@ dependencies:
|
|
25
25
|
- !ruby/object:Gem::Version
|
26
26
|
version: '0'
|
27
27
|
- !ruby/object:Gem::Dependency
|
28
|
-
name:
|
28
|
+
name: rake
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
30
30
|
requirements:
|
31
|
-
- - "
|
31
|
+
- - ">="
|
32
32
|
- !ruby/object:Gem::Version
|
33
|
-
version: '
|
33
|
+
version: '0'
|
34
34
|
type: :development
|
35
35
|
prerelease: false
|
36
36
|
version_requirements: !ruby/object:Gem::Requirement
|
37
37
|
requirements:
|
38
|
-
- - "
|
38
|
+
- - ">="
|
39
39
|
- !ruby/object:Gem::Version
|
40
|
-
version: '
|
40
|
+
version: '0'
|
41
41
|
- !ruby/object:Gem::Dependency
|
42
|
-
name:
|
42
|
+
name: minitest
|
43
43
|
requirement: !ruby/object:Gem::Requirement
|
44
44
|
requirements:
|
45
|
-
- - "
|
45
|
+
- - "~>"
|
46
46
|
- !ruby/object:Gem::Version
|
47
|
-
version: '0'
|
48
|
-
type: :
|
47
|
+
version: '5.0'
|
48
|
+
type: :development
|
49
49
|
prerelease: false
|
50
50
|
version_requirements: !ruby/object:Gem::Requirement
|
51
51
|
requirements:
|
52
|
-
- - "
|
52
|
+
- - "~>"
|
53
53
|
- !ruby/object:Gem::Version
|
54
|
-
version: '0'
|
54
|
+
version: '5.0'
|
55
55
|
- !ruby/object:Gem::Dependency
|
56
56
|
name: webmock
|
57
57
|
requirement: !ruby/object:Gem::Requirement
|
58
58
|
requirements:
|
59
59
|
- - "~>"
|
60
60
|
- !ruby/object:Gem::Version
|
61
|
-
version: '
|
61
|
+
version: '3.0'
|
62
62
|
type: :development
|
63
63
|
prerelease: false
|
64
64
|
version_requirements: !ruby/object:Gem::Requirement
|
65
65
|
requirements:
|
66
66
|
- - "~>"
|
67
67
|
- !ruby/object:Gem::Version
|
68
|
-
version: '
|
68
|
+
version: '3.0'
|
69
69
|
description: Nexmo Client Library for Ruby
|
70
70
|
email:
|
71
71
|
- mail@timcraft.com
|
@@ -76,20 +76,36 @@ files:
|
|
76
76
|
- LICENSE.txt
|
77
77
|
- README.md
|
78
78
|
- lib/nexmo.rb
|
79
|
+
- lib/nexmo/account.rb
|
80
|
+
- lib/nexmo/alerts.rb
|
81
|
+
- lib/nexmo/applications.rb
|
82
|
+
- lib/nexmo/call_dtmf.rb
|
83
|
+
- lib/nexmo/call_stream.rb
|
84
|
+
- lib/nexmo/call_talk.rb
|
85
|
+
- lib/nexmo/calls.rb
|
79
86
|
- lib/nexmo/client.rb
|
87
|
+
- lib/nexmo/conversions.rb
|
88
|
+
- lib/nexmo/entity.rb
|
80
89
|
- lib/nexmo/errors/authentication_error.rb
|
81
90
|
- lib/nexmo/errors/client_error.rb
|
82
91
|
- lib/nexmo/errors/error.rb
|
83
92
|
- lib/nexmo/errors/server_error.rb
|
93
|
+
- lib/nexmo/files.rb
|
84
94
|
- lib/nexmo/jwt.rb
|
95
|
+
- lib/nexmo/keys.rb
|
96
|
+
- lib/nexmo/messages.rb
|
97
|
+
- lib/nexmo/namespace.rb
|
98
|
+
- lib/nexmo/number_insight.rb
|
99
|
+
- lib/nexmo/numbers.rb
|
85
100
|
- lib/nexmo/params.rb
|
101
|
+
- lib/nexmo/pricing.rb
|
102
|
+
- lib/nexmo/pricing_types.rb
|
86
103
|
- lib/nexmo/signature.rb
|
104
|
+
- lib/nexmo/sms.rb
|
105
|
+
- lib/nexmo/user_agent.rb
|
106
|
+
- lib/nexmo/verify.rb
|
87
107
|
- lib/nexmo/version.rb
|
88
108
|
- nexmo.gemspec
|
89
|
-
- spec/nexmo/client_spec.rb
|
90
|
-
- spec/nexmo/jwt_spec.rb
|
91
|
-
- spec/nexmo/params_spec.rb
|
92
|
-
- spec/nexmo/signature_spec.rb
|
93
109
|
homepage: https://github.com/Nexmo/nexmo-ruby
|
94
110
|
licenses:
|
95
111
|
- MIT
|
@@ -102,12 +118,12 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
102
118
|
requirements:
|
103
119
|
- - ">="
|
104
120
|
- !ruby/object:Gem::Version
|
105
|
-
version:
|
121
|
+
version: 2.0.0
|
106
122
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
107
123
|
requirements:
|
108
|
-
- - "
|
124
|
+
- - ">"
|
109
125
|
- !ruby/object:Gem::Version
|
110
|
-
version:
|
126
|
+
version: 1.3.1
|
111
127
|
requirements: []
|
112
128
|
rubyforge_project:
|
113
129
|
rubygems_version: 2.6.13
|
data/spec/nexmo/client_spec.rb
DELETED
@@ -1,651 +0,0 @@
|
|
1
|
-
require 'minitest/autorun'
|
2
|
-
require 'webmock/minitest'
|
3
|
-
require 'nexmo'
|
4
|
-
|
5
|
-
describe 'Nexmo::Client' do
|
6
|
-
before do
|
7
|
-
@api_key = 'api_key_xxx'
|
8
|
-
|
9
|
-
@api_secret = 'api_secret_xxx'
|
10
|
-
|
11
|
-
@application_id = 'nexmo-application-id'
|
12
|
-
|
13
|
-
@private_key = File.read('test/private_key.txt')
|
14
|
-
|
15
|
-
@base_url = 'https://rest.nexmo.com'
|
16
|
-
|
17
|
-
@api_base_url = 'https://api.nexmo.com'
|
18
|
-
|
19
|
-
@response_body = {body: '{"key":"value"}', headers: {'Content-Type' => 'application/json;charset=utf-8'}}
|
20
|
-
|
21
|
-
@response_object = {'key' => 'value'}
|
22
|
-
|
23
|
-
@client = Nexmo::Client.new(key: @api_key, secret: @api_secret, application_id: @application_id, private_key: @private_key)
|
24
|
-
end
|
25
|
-
|
26
|
-
let(:authorization_header) { {'Authorization' => /\ABearer (.+)\.(.+)\.(.+)\z/} }
|
27
|
-
|
28
|
-
let(:recording_id) { 'xx-xx-xx-xx' }
|
29
|
-
|
30
|
-
let(:recording_url) { "#@api_base_url/v1/files/xx-xx-xx-xx" }
|
31
|
-
|
32
|
-
let(:recording_content) { 'BODY' }
|
33
|
-
|
34
|
-
let(:recording_response) { {body: recording_content, headers: {'Content-Type' => 'application/octet-stream'}} }
|
35
|
-
|
36
|
-
let(:recording_filename) { 'test/file.mp3' }
|
37
|
-
|
38
|
-
describe 'send_message method' do
|
39
|
-
it 'posts to the sms resource and returns the response object' do
|
40
|
-
expect_post "#@base_url/sms/json", "from=ruby&to=number&text=Hey!&api_key=#@api_key&api_secret=#@api_secret"
|
41
|
-
|
42
|
-
@client.send_message(from: 'ruby', to: 'number', text: 'Hey!').must_equal(@response_object)
|
43
|
-
end
|
44
|
-
end
|
45
|
-
|
46
|
-
describe 'track_message_conversion method' do
|
47
|
-
it 'posts to the sms conversions resource and returns the response object' do
|
48
|
-
expect_post "#@api_base_url/conversions/sms", "message-id=12345&delivered=true&api_key=#@api_key&api_secret=#@api_secret"
|
49
|
-
|
50
|
-
@client.track_message_conversion('12345', delivered: true).must_equal(@response_object)
|
51
|
-
end
|
52
|
-
end
|
53
|
-
|
54
|
-
describe 'track_voice_conversion method' do
|
55
|
-
it 'posts to the voice conversions resource and returns the response object' do
|
56
|
-
expect_post "#@api_base_url/conversions/voice", "message-id=12345&delivered=true&api_key=#@api_key&api_secret=#@api_secret"
|
57
|
-
|
58
|
-
@client.track_voice_conversion('12345', delivered: true).must_equal(@response_object)
|
59
|
-
end
|
60
|
-
end
|
61
|
-
|
62
|
-
describe 'get_balance method' do
|
63
|
-
it 'fetches the account balance resource and returns the response object' do
|
64
|
-
expect_get "#@base_url/account/get-balance?api_key=#@api_key&api_secret=#@api_secret"
|
65
|
-
|
66
|
-
@client.get_balance.must_equal(@response_object)
|
67
|
-
end
|
68
|
-
end
|
69
|
-
|
70
|
-
describe 'get_country_pricing method' do
|
71
|
-
it 'fetches the outbound pricing resource for the given country and returns the response object' do
|
72
|
-
expect_get "#@base_url/account/get-pricing/outbound?api_key=#@api_key&api_secret=#@api_secret&country=CA"
|
73
|
-
|
74
|
-
@client.get_country_pricing(:CA).must_equal(@response_object)
|
75
|
-
end
|
76
|
-
end
|
77
|
-
|
78
|
-
describe 'get_prefix_pricing method' do
|
79
|
-
it 'fetches the outbound pricing resource for the given prefix and returns the response object' do
|
80
|
-
expect_get "#@base_url/account/get-prefix-pricing/outbound?api_key=#@api_key&api_secret=#@api_secret&prefix=44"
|
81
|
-
|
82
|
-
@client.get_prefix_pricing(44).must_equal(@response_object)
|
83
|
-
end
|
84
|
-
end
|
85
|
-
|
86
|
-
describe 'get_sms_pricing method' do
|
87
|
-
it 'fetches the outbound sms pricing resource for the given phone number and returns the response object' do
|
88
|
-
expect_get "#@base_url/account/get-phone-pricing/outbound/sms?api_key=#@api_key&api_secret=#@api_secret&phone=447525856424"
|
89
|
-
|
90
|
-
@client.get_sms_pricing('447525856424').must_equal(@response_object)
|
91
|
-
end
|
92
|
-
end
|
93
|
-
|
94
|
-
describe 'get_voice_pricing method' do
|
95
|
-
it 'fetches the outbound voice pricing resource for the given phone number and returns the response object' do
|
96
|
-
expect_get "#@base_url/account/get-phone-pricing/outbound/voice?api_key=#@api_key&api_secret=#@api_secret&phone=447525856424"
|
97
|
-
|
98
|
-
@client.get_voice_pricing('447525856424').must_equal(@response_object)
|
99
|
-
end
|
100
|
-
end
|
101
|
-
|
102
|
-
describe 'update_settings method' do
|
103
|
-
it 'updates the account settings resource with the given parameters and returns the response object' do
|
104
|
-
expect_post "#@base_url/account/settings", "api_key=#@api_key&api_secret=#@api_secret&moCallBackUrl=http://example.com/callback"
|
105
|
-
|
106
|
-
@client.update_settings(moCallBackUrl: 'http://example.com/callback').must_equal(@response_object)
|
107
|
-
end
|
108
|
-
end
|
109
|
-
|
110
|
-
describe 'topup method' do
|
111
|
-
it 'updates the account top-up resource with the given parameters and returns the response object' do
|
112
|
-
expect_post "#@base_url/account/top-up", "api_key=#@api_key&api_secret=#@api_secret&trx=00X123456Y7890123Z"
|
113
|
-
|
114
|
-
@client.topup(trx: '00X123456Y7890123Z').must_equal(@response_object)
|
115
|
-
end
|
116
|
-
end
|
117
|
-
|
118
|
-
describe 'get_account_numbers method' do
|
119
|
-
it 'fetches the account numbers resource with the given parameters and returns the response object' do
|
120
|
-
expect_get "#@base_url/account/numbers?api_key=#@api_key&api_secret=#@api_secret&size=25&pattern=33"
|
121
|
-
|
122
|
-
@client.get_account_numbers(size: 25, pattern: 33).must_equal(@response_object)
|
123
|
-
end
|
124
|
-
end
|
125
|
-
|
126
|
-
describe 'get_available_numbers method' do
|
127
|
-
it 'fetches the number search resource with the given parameters and returns the response object' do
|
128
|
-
expect_get "#@base_url/number/search?api_key=#@api_key&api_secret=#@api_secret&country=CA&size=25"
|
129
|
-
|
130
|
-
@client.get_available_numbers('CA', size: 25).must_equal(@response_object)
|
131
|
-
end
|
132
|
-
end
|
133
|
-
|
134
|
-
describe 'buy_number method' do
|
135
|
-
it 'purchases the number requested with the given parameters and returns the response object' do
|
136
|
-
expect_post "#@base_url/number/buy", "api_key=#@api_key&api_secret=#@api_secret&country=US&msisdn=number"
|
137
|
-
|
138
|
-
@client.buy_number(country: 'US', msisdn: 'number').must_equal(@response_object)
|
139
|
-
end
|
140
|
-
end
|
141
|
-
|
142
|
-
describe 'cancel_number method' do
|
143
|
-
it 'cancels the number requested with the given parameters and returns the response object' do
|
144
|
-
expect_post "#@base_url/number/cancel", "api_key=#@api_key&api_secret=#@api_secret&country=US&msisdn=number"
|
145
|
-
|
146
|
-
@client.cancel_number(country: 'US', msisdn: 'number').must_equal(@response_object)
|
147
|
-
end
|
148
|
-
end
|
149
|
-
|
150
|
-
describe 'update_number method' do
|
151
|
-
it 'updates the number requested with the given parameters and returns the response object' do
|
152
|
-
expect_post "#@base_url/number/update", "api_key=#@api_key&api_secret=#@api_secret&country=US&msisdn=number&moHttpUrl=callback"
|
153
|
-
|
154
|
-
@client.update_number(country: 'US', msisdn: 'number', moHttpUrl: 'callback').must_equal(@response_object)
|
155
|
-
end
|
156
|
-
end
|
157
|
-
|
158
|
-
describe 'get_message method' do
|
159
|
-
it 'fetches the message search resource for the given message id and returns the response object' do
|
160
|
-
expect_get "#@base_url/search/message?api_key=#@api_key&api_secret=#@api_secret&id=00A0B0C0"
|
161
|
-
|
162
|
-
@client.get_message('00A0B0C0').must_equal(@response_object)
|
163
|
-
end
|
164
|
-
end
|
165
|
-
|
166
|
-
describe 'get_message_rejections method' do
|
167
|
-
it 'fetches the message rejections resource with the given parameters and returns the response object' do
|
168
|
-
expect_get "#@base_url/search/rejections?api_key=#@api_key&api_secret=#@api_secret&date=YYYY-MM-DD"
|
169
|
-
|
170
|
-
@client.get_message_rejections(date: 'YYYY-MM-DD').must_equal(@response_object)
|
171
|
-
end
|
172
|
-
end
|
173
|
-
|
174
|
-
describe 'search_messages method' do
|
175
|
-
it 'fetches the search messages resource with the given parameters and returns the response object' do
|
176
|
-
expect_get "#@base_url/search/messages?api_key=#@api_key&api_secret=#@api_secret&date=YYYY-MM-DD&to=1234567890"
|
177
|
-
|
178
|
-
@client.search_messages(date: 'YYYY-MM-DD', to: 1234567890).must_equal(@response_object)
|
179
|
-
end
|
180
|
-
|
181
|
-
it 'should encode a non hash argument as a list of ids' do
|
182
|
-
expect_get "#@base_url/search/messages?api_key=#@api_key&api_secret=#@api_secret&ids=id1&ids=id2"
|
183
|
-
|
184
|
-
@client.search_messages(%w(id1 id2))
|
185
|
-
end
|
186
|
-
end
|
187
|
-
|
188
|
-
describe 'send_2fa_message method' do
|
189
|
-
it 'posts to the short code two factor authentication resource and returns the response object' do
|
190
|
-
expect_post "#@base_url/sc/us/2fa/json", "api_key=#@api_key&api_secret=#@api_secret&to=16365553226&pin=1234"
|
191
|
-
|
192
|
-
@client.send_2fa_message(to: '16365553226', pin: 1234).must_equal(@response_object)
|
193
|
-
end
|
194
|
-
end
|
195
|
-
|
196
|
-
describe 'send_event_alert_message method' do
|
197
|
-
it 'posts to the short code alert resource and returns the response object' do
|
198
|
-
expect_post "#@base_url/sc/us/alert/json", "api_key=#@api_key&api_secret=#@api_secret&to=16365553226&server=host&link=http://example.com/"
|
199
|
-
|
200
|
-
@client.send_event_alert_message(to: '16365553226', server: 'host', link: 'http://example.com/').must_equal(@response_object)
|
201
|
-
end
|
202
|
-
end
|
203
|
-
|
204
|
-
describe 'send_marketing_message method' do
|
205
|
-
it 'posts to the short code marketing resource and returns the response object' do
|
206
|
-
expect_post "#@base_url/sc/us/marketing/json", "api_key=#@api_key&api_secret=#@api_secret&from=666&to=16365553226&keyword=NEXMO&text=Hello"
|
207
|
-
|
208
|
-
@client.send_marketing_message(from: '666', to: '16365553226', keyword: 'NEXMO', text: 'Hello').must_equal(@response_object)
|
209
|
-
end
|
210
|
-
end
|
211
|
-
|
212
|
-
describe 'get_event_alert_numbers method' do
|
213
|
-
it 'fetches the short code alert opt-in query resource and returns the response object' do
|
214
|
-
expect_get "#@base_url/sc/us/alert/opt-in/query/json?api_key=#@api_key&api_secret=#@api_secret"
|
215
|
-
|
216
|
-
@client.get_event_alert_numbers.must_equal(@response_object)
|
217
|
-
end
|
218
|
-
end
|
219
|
-
|
220
|
-
describe 'resubscribe_event_alert_number method' do
|
221
|
-
it 'posts to the short code alert opt-in manage resource and returns the response object' do
|
222
|
-
expect_post "#@base_url/sc/us/alert/opt-in/manage/json", "api_key=#@api_key&api_secret=#@api_secret&msisdn=441632960960"
|
223
|
-
|
224
|
-
@client.resubscribe_event_alert_number(msisdn: '441632960960').must_equal(@response_object)
|
225
|
-
end
|
226
|
-
end
|
227
|
-
|
228
|
-
describe 'initiate_call method' do
|
229
|
-
it 'posts to the call resource and returns the response object' do
|
230
|
-
expect_post "#@base_url/call/json", "api_key=#@api_key&api_secret=#@api_secret&to=16365553226&answer_url=http://example.com/answer"
|
231
|
-
|
232
|
-
Kernel.stub :warn, proc { |message| message.must_match(/initiate_call is deprecated/) } do
|
233
|
-
@client.initiate_call(to: '16365553226', answer_url: 'http://example.com/answer').must_equal(@response_object)
|
234
|
-
end
|
235
|
-
end
|
236
|
-
end
|
237
|
-
|
238
|
-
describe 'initiate_tts_call method' do
|
239
|
-
it 'posts to the tts resource and returns the response object' do
|
240
|
-
expect_post "#@api_base_url/tts/json", "api_key=#@api_key&api_secret=#@api_secret&to=16365553226&text=Hello"
|
241
|
-
|
242
|
-
Kernel.stub :warn, proc { |message| message.must_match(/initiate_tts_call is deprecated/) } do
|
243
|
-
@client.initiate_tts_call(to: '16365553226', text: 'Hello').must_equal(@response_object)
|
244
|
-
end
|
245
|
-
end
|
246
|
-
end
|
247
|
-
|
248
|
-
describe 'initiate_tts_prompt_call method' do
|
249
|
-
it 'posts to the tts prompt resource and returns the response object' do
|
250
|
-
expect_post "#@api_base_url/tts-prompt/json", "api_key=#@api_key&api_secret=#@api_secret&to=16365553226&text=Hello&max_digits=4&bye_text=Goodbye"
|
251
|
-
|
252
|
-
Kernel.stub :warn, proc { |message| message.must_match(/initiate_tts_prompt_call is deprecated/) } do
|
253
|
-
@client.initiate_tts_prompt_call(to: '16365553226', text: 'Hello', max_digits: 4, bye_text: 'Goodbye').must_equal(@response_object)
|
254
|
-
end
|
255
|
-
end
|
256
|
-
end
|
257
|
-
|
258
|
-
describe 'start_verification method' do
|
259
|
-
it 'posts to the verify json resource and returns the response object' do
|
260
|
-
expect_post "#@api_base_url/verify/json", "api_key=#@api_key&api_secret=#@api_secret&number=447525856424&brand=MyApp"
|
261
|
-
|
262
|
-
@client.start_verification(number: '447525856424', brand: 'MyApp').must_equal(@response_object)
|
263
|
-
end
|
264
|
-
end
|
265
|
-
|
266
|
-
describe 'check_verification method' do
|
267
|
-
it 'posts to the verify check resource and returns the response object' do
|
268
|
-
expect_post "#@api_base_url/verify/check/json", "api_key=#@api_key&api_secret=#@api_secret&request_id=8g88g88eg8g8gg9g90&code=123445"
|
269
|
-
|
270
|
-
@client.check_verification('8g88g88eg8g8gg9g90', code: '123445').must_equal(@response_object)
|
271
|
-
end
|
272
|
-
end
|
273
|
-
|
274
|
-
describe 'get_verification method' do
|
275
|
-
it 'fetches the verify search resource with the given request id and returns the response object' do
|
276
|
-
expect_get "#@api_base_url/verify/search/json?api_key=#@api_key&api_secret=#@api_secret&request_id=8g88g88eg8g8gg9g90"
|
277
|
-
|
278
|
-
@client.get_verification('8g88g88eg8g8gg9g90').must_equal(@response_object)
|
279
|
-
end
|
280
|
-
end
|
281
|
-
|
282
|
-
describe 'cancel_verification method' do
|
283
|
-
it 'posts to the verify control resource and returns the response object' do
|
284
|
-
expect_post "#@api_base_url/verify/control/json", "api_key=#@api_key&api_secret=#@api_secret&request_id=8g88g88eg8g8gg9g90&cmd=cancel"
|
285
|
-
|
286
|
-
@client.cancel_verification('8g88g88eg8g8gg9g90').must_equal(@response_object)
|
287
|
-
end
|
288
|
-
end
|
289
|
-
|
290
|
-
describe 'trigger_next_verification_event method' do
|
291
|
-
it 'posts to the verify control resource and returns the response object' do
|
292
|
-
expect_post "#@api_base_url/verify/control/json", "api_key=#@api_key&api_secret=#@api_secret&request_id=8g88g88eg8g8gg9g90&cmd=trigger_next_event"
|
293
|
-
|
294
|
-
@client.trigger_next_verification_event('8g88g88eg8g8gg9g90').must_equal(@response_object)
|
295
|
-
end
|
296
|
-
end
|
297
|
-
|
298
|
-
describe 'get_basic_number_insight method' do
|
299
|
-
it 'fetches the number format resource and returns the response object' do
|
300
|
-
expect_get "#@api_base_url/ni/basic/json?api_key=#@api_key&api_secret=#@api_secret&number=447525856424"
|
301
|
-
|
302
|
-
@client.get_basic_number_insight(number: '447525856424').must_equal(@response_object)
|
303
|
-
end
|
304
|
-
end
|
305
|
-
|
306
|
-
describe 'get_standard_number_insight method' do
|
307
|
-
it 'fetches the number lookup resource and returns the response object' do
|
308
|
-
expect_get "#@api_base_url/ni/standard/json?api_key=#@api_key&api_secret=#@api_secret&number=447525856424"
|
309
|
-
|
310
|
-
@client.get_standard_number_insight(number: '447525856424').must_equal(@response_object)
|
311
|
-
end
|
312
|
-
end
|
313
|
-
|
314
|
-
describe 'get_advanced_number_insight method' do
|
315
|
-
it 'fetches the ni advanced resource and returns the response object' do
|
316
|
-
expect_get "#@api_base_url/ni/advanced/json?api_key=#@api_key&api_secret=#@api_secret&number=447525856424"
|
317
|
-
|
318
|
-
@client.get_advanced_number_insight(number: '447525856424').must_equal(@response_object)
|
319
|
-
end
|
320
|
-
end
|
321
|
-
|
322
|
-
describe 'get_advanced_async_number_insight method' do
|
323
|
-
it 'fetches the ni advanced async resource and returns the response object' do
|
324
|
-
expect_get "#@api_base_url/ni/advanced/async/json?api_key=#@api_key&api_secret=#@api_secret&number=447525856424"
|
325
|
-
|
326
|
-
@client.get_advanced_async_number_insight(number: '447525856424').must_equal(@response_object)
|
327
|
-
end
|
328
|
-
end
|
329
|
-
|
330
|
-
describe 'request_number_insight method' do
|
331
|
-
it 'posts to the number insight resource and returns the response object' do
|
332
|
-
expect_post "#@base_url/ni/json", "api_key=#@api_key&api_secret=#@api_secret&number=447525856424&callback=https://example.com"
|
333
|
-
|
334
|
-
@client.request_number_insight(number: '447525856424', callback: 'https://example.com').must_equal(@response_object)
|
335
|
-
end
|
336
|
-
end
|
337
|
-
|
338
|
-
describe 'get_applications method' do
|
339
|
-
it 'fetches the applications resource and returns the response object' do
|
340
|
-
expect_get "#@api_base_url/v1/applications?api_key=#@api_key&api_secret=#@api_secret"
|
341
|
-
|
342
|
-
@client.get_applications.must_equal(@response_object)
|
343
|
-
end
|
344
|
-
end
|
345
|
-
|
346
|
-
describe 'get_application method' do
|
347
|
-
it 'fetches the application resource with the given id and returns the response object' do
|
348
|
-
expect_get "#@api_base_url/v1/applications/xx-xx-xx-xx?api_key=#@api_key&api_secret=#@api_secret"
|
349
|
-
|
350
|
-
@client.get_application('xx-xx-xx-xx').must_equal(@response_object)
|
351
|
-
end
|
352
|
-
end
|
353
|
-
|
354
|
-
describe 'create_application method' do
|
355
|
-
it 'posts to the applications resource and returns the response object' do
|
356
|
-
expect_post "#@api_base_url/v1/applications", "api_key=#@api_key&api_secret=#@api_secret&name=Example+App&type=voice"
|
357
|
-
|
358
|
-
@client.create_application(name: 'Example App', type: 'voice')
|
359
|
-
end
|
360
|
-
end
|
361
|
-
|
362
|
-
describe 'update_application method' do
|
363
|
-
it 'puts to the application resource with the given id and returns the response object' do
|
364
|
-
expect_put "#@api_base_url/v1/applications/xx-xx-xx-xx", "api_key=#@api_key&api_secret=#@api_secret&answer_url=https%3A%2F%2Fexample.com%2Fncco"
|
365
|
-
|
366
|
-
@client.update_application('xx-xx-xx-xx', answer_url: 'https://example.com/ncco')
|
367
|
-
end
|
368
|
-
end
|
369
|
-
|
370
|
-
describe 'delete_application method' do
|
371
|
-
it 'deletes the application resource with the given id' do
|
372
|
-
expect_delete "#@api_base_url/v1/applications/xx-xx-xx-xx?api_key=#@api_key&api_secret=#@api_secret"
|
373
|
-
|
374
|
-
@client.delete_application('xx-xx-xx-xx')
|
375
|
-
end
|
376
|
-
end
|
377
|
-
|
378
|
-
describe 'create_call method' do
|
379
|
-
it 'posts to the calls resource and returns the response object' do
|
380
|
-
params = {
|
381
|
-
to: [{type: 'phone', number: '14843331234'}],
|
382
|
-
from: {type: 'phone', number: '14843335555'},
|
383
|
-
answer_url: ['https://example.com/answer']
|
384
|
-
}
|
385
|
-
|
386
|
-
expect :post, "#@api_base_url/v1/calls", params
|
387
|
-
|
388
|
-
@client.create_call(params).must_equal(@response_object)
|
389
|
-
end
|
390
|
-
end
|
391
|
-
|
392
|
-
describe 'get_calls method' do
|
393
|
-
it 'fetches the calls resource and returns the response object' do
|
394
|
-
expect :get, "#@api_base_url/v1/calls?status=completed"
|
395
|
-
|
396
|
-
@client.get_calls(status: 'completed').must_equal(@response_object)
|
397
|
-
end
|
398
|
-
end
|
399
|
-
|
400
|
-
describe 'get_call method' do
|
401
|
-
it 'fetches the call resource with the given uuid and returns the response object' do
|
402
|
-
expect :get, "#@api_base_url/v1/calls/xx-xx-xx-xx"
|
403
|
-
|
404
|
-
@client.get_call('xx-xx-xx-xx').must_equal(@response_object)
|
405
|
-
end
|
406
|
-
end
|
407
|
-
|
408
|
-
describe 'update_call method' do
|
409
|
-
it 'puts to the call resource with the given uuid and returns the response object' do
|
410
|
-
expect :put, "#@api_base_url/v1/calls/xx-xx-xx-xx", {action: 'hangup'}
|
411
|
-
|
412
|
-
@client.update_call('xx-xx-xx-xx', action: 'hangup').must_equal(@response_object)
|
413
|
-
end
|
414
|
-
end
|
415
|
-
|
416
|
-
describe 'send_audio method' do
|
417
|
-
it 'puts to the call stream resource with the given uuid and returns the response object' do
|
418
|
-
expect :put, "#@api_base_url/v1/calls/xx-xx-xx-xx/stream", {stream_url: 'http://example.com/audio.mp3'}
|
419
|
-
|
420
|
-
@client.send_audio('xx-xx-xx-xx', stream_url: 'http://example.com/audio.mp3').must_equal(@response_object)
|
421
|
-
end
|
422
|
-
end
|
423
|
-
|
424
|
-
describe 'stop_audio method' do
|
425
|
-
it 'deletes the call stream resource with the given uuid' do
|
426
|
-
expect :delete, "#@api_base_url/v1/calls/xx-xx-xx-xx/stream"
|
427
|
-
|
428
|
-
@client.stop_audio('xx-xx-xx-xx')
|
429
|
-
end
|
430
|
-
end
|
431
|
-
|
432
|
-
describe 'send_speech method' do
|
433
|
-
it 'puts to the call talk resource with the given uuid and returns the response object' do
|
434
|
-
expect :put, "#@api_base_url/v1/calls/xx-xx-xx-xx/talk", {text: 'Hello'}
|
435
|
-
|
436
|
-
@client.send_speech('xx-xx-xx-xx', text: 'Hello').must_equal(@response_object)
|
437
|
-
end
|
438
|
-
end
|
439
|
-
|
440
|
-
describe 'stop_speech method' do
|
441
|
-
it 'deletes the call talk resource with the given uuid' do
|
442
|
-
expect :delete, "#@api_base_url/v1/calls/xx-xx-xx-xx/talk"
|
443
|
-
|
444
|
-
@client.stop_speech('xx-xx-xx-xx')
|
445
|
-
end
|
446
|
-
end
|
447
|
-
|
448
|
-
describe 'send_dtmf method' do
|
449
|
-
it 'puts to the call dtmf resource with the given uuid and returns the response object' do
|
450
|
-
expect :put, "#@api_base_url/v1/calls/xx-xx-xx-xx/dtmf", {digits: '1234'}
|
451
|
-
|
452
|
-
@client.send_dtmf('xx-xx-xx-xx', digits: '1234').must_equal(@response_object)
|
453
|
-
end
|
454
|
-
end
|
455
|
-
|
456
|
-
describe 'get_file method' do
|
457
|
-
it 'fetches the file resource with the given id and returns the response body' do
|
458
|
-
@request = stub_request(:get, recording_url).with(headers: authorization_header).to_return(recording_response)
|
459
|
-
|
460
|
-
@client.get_file(recording_id).must_equal(recording_content)
|
461
|
-
end
|
462
|
-
|
463
|
-
it 'fetches the file resource with the given url and returns the response body' do
|
464
|
-
@request = stub_request(:get, recording_url).with(headers: authorization_header).to_return(recording_response)
|
465
|
-
|
466
|
-
@client.get_file(recording_url).must_equal(recording_content)
|
467
|
-
end
|
468
|
-
end
|
469
|
-
|
470
|
-
describe 'save_file method' do
|
471
|
-
after { File.unlink(recording_filename) if File.exist?(recording_filename) }
|
472
|
-
|
473
|
-
it 'fetches the file resource with the given id and streams the response body to the given filename' do
|
474
|
-
@request = stub_request(:get, recording_url).with(headers: authorization_header).to_return(recording_response)
|
475
|
-
|
476
|
-
@client.save_file(recording_id, recording_filename)
|
477
|
-
|
478
|
-
File.read(recording_filename).must_equal(recording_content)
|
479
|
-
end
|
480
|
-
|
481
|
-
it 'fetches the file resource with the given url and streams the response body to the given filename' do
|
482
|
-
@request = stub_request(:get, recording_url).with(headers: authorization_header).to_return(recording_response)
|
483
|
-
|
484
|
-
@client.save_file(recording_url, recording_filename)
|
485
|
-
|
486
|
-
File.read(recording_filename).must_equal(recording_content)
|
487
|
-
end
|
488
|
-
end
|
489
|
-
|
490
|
-
describe 'check_signature method' do
|
491
|
-
it 'returns true if the signature in the given params is correct' do
|
492
|
-
params = {'a' => '1', 'b' => '2', 'timestamp' => '1461605396', 'sig' => '6af838ef94998832dbfc29020b564830'}
|
493
|
-
|
494
|
-
client = Nexmo::Client.new(key: @api_key, secret: @api_secret, signature_secret: 'secret')
|
495
|
-
|
496
|
-
client.check_signature(params).must_equal(true)
|
497
|
-
end
|
498
|
-
|
499
|
-
it 'raises an authentication error exception if the signature secret was not provided' do
|
500
|
-
client = Nexmo::Client.new(key: @api_key, secret: @api_secret)
|
501
|
-
|
502
|
-
exception = proc { client.check_signature({}) }.must_raise(Nexmo::AuthenticationError)
|
503
|
-
|
504
|
-
exception.message.must_include('No signature_secret provided.')
|
505
|
-
end
|
506
|
-
end
|
507
|
-
|
508
|
-
it 'raises an authentication error exception if the api key was not provided' do
|
509
|
-
client = Nexmo::Client.new(secret: @api_secret)
|
510
|
-
|
511
|
-
exception = proc { client.get_balance }.must_raise(Nexmo::AuthenticationError)
|
512
|
-
|
513
|
-
exception.message.must_include('No API key provided.')
|
514
|
-
end
|
515
|
-
|
516
|
-
it 'raises an authentication error exception if the api secret was not provided' do
|
517
|
-
client = Nexmo::Client.new(key: @api_key)
|
518
|
-
|
519
|
-
exception = proc { client.get_balance }.must_raise(Nexmo::AuthenticationError)
|
520
|
-
|
521
|
-
exception.message.must_include('No API secret provided.')
|
522
|
-
end
|
523
|
-
|
524
|
-
it 'raises an authentication error exception if the application id was not provided' do
|
525
|
-
client = Nexmo::Client.new(private_key: @private_key)
|
526
|
-
|
527
|
-
exception = proc { client.get_calls }.must_raise(Nexmo::AuthenticationError)
|
528
|
-
|
529
|
-
exception.message.must_include('No application_id provided.')
|
530
|
-
end
|
531
|
-
|
532
|
-
it 'raises an authentication error exception if the private key was not provided' do
|
533
|
-
client = Nexmo::Client.new(application_id: @application_id)
|
534
|
-
|
535
|
-
exception = proc { client.get_calls }.must_raise(Nexmo::AuthenticationError)
|
536
|
-
|
537
|
-
exception.message.must_include('No private_key provided.')
|
538
|
-
end
|
539
|
-
|
540
|
-
it 'raises an authentication error exception if the response code is 401' do
|
541
|
-
stub_request(:get, /#{@base_url}/).to_return(status: 401)
|
542
|
-
|
543
|
-
proc { @client.get_balance }.must_raise(Nexmo::AuthenticationError)
|
544
|
-
end
|
545
|
-
|
546
|
-
it 'raises a client error exception if the response code is 4xx' do
|
547
|
-
stub_request(:get, /#{@base_url}/).to_return(status: 400)
|
548
|
-
|
549
|
-
proc { @client.get_balance }.must_raise(Nexmo::ClientError)
|
550
|
-
end
|
551
|
-
|
552
|
-
it 'raises a server error exception if the response code is 5xx' do
|
553
|
-
stub_request(:get, /#{@base_url}/).to_return(status: 500)
|
554
|
-
|
555
|
-
proc { @client.get_balance }.must_raise(Nexmo::ServerError)
|
556
|
-
end
|
557
|
-
|
558
|
-
it 'provides an accessor to set the authorization token' do
|
559
|
-
auth_token = 'auth_token_xxx'
|
560
|
-
|
561
|
-
headers = {'Authorization' => "Bearer #{auth_token}"}
|
562
|
-
|
563
|
-
@request = stub_request(:get, "#@api_base_url/v1/calls").with(headers: headers).to_return(@response_body)
|
564
|
-
|
565
|
-
@client.auth_token = auth_token
|
566
|
-
|
567
|
-
@client.get_calls
|
568
|
-
end
|
569
|
-
|
570
|
-
it 'includes a user-agent header with the library version number and ruby version number' do
|
571
|
-
headers = {'User-Agent' => "nexmo-ruby/#{Nexmo::VERSION} ruby/#{RUBY_VERSION}"}
|
572
|
-
|
573
|
-
stub_request(:get, /#{@base_url}/).with(headers: headers).to_return(@response_body)
|
574
|
-
|
575
|
-
@client.get_balance
|
576
|
-
end
|
577
|
-
|
578
|
-
it 'provides options for application name and version to be included in the user-agent header' do
|
579
|
-
app_name, app_version = 'ExampleApp', 'X.Y.Z'
|
580
|
-
|
581
|
-
headers = {'User-Agent' => "nexmo-ruby/#{Nexmo::VERSION} ruby/#{RUBY_VERSION} #{app_name}/#{app_version}"}
|
582
|
-
|
583
|
-
stub_request(:get, /#{@base_url}/).with(headers: headers).to_return(@response_body)
|
584
|
-
|
585
|
-
@client = Nexmo::Client.new(key: @api_key, secret: @api_secret, app_name: app_name, app_version: app_version)
|
586
|
-
|
587
|
-
@client.get_balance
|
588
|
-
end
|
589
|
-
|
590
|
-
it 'provides an option for specifying a different hostname to connect to' do
|
591
|
-
expect_get "https://rest-sandbox.nexmo.com/account/get-balance?api_key=#@api_key&api_secret=#@api_secret"
|
592
|
-
|
593
|
-
@client = Nexmo::Client.new(key: @api_key, secret: @api_secret, host: 'rest-sandbox.nexmo.com')
|
594
|
-
|
595
|
-
@client.get_balance
|
596
|
-
end
|
597
|
-
|
598
|
-
it 'provides an option for specifying a different api hostname to connect to' do
|
599
|
-
expect_get "https://debug.example.com/ni/basic/json?api_key=#@api_key&api_secret=#@api_secret&number=447525856424"
|
600
|
-
|
601
|
-
@client = Nexmo::Client.new(key: @api_key, secret: @api_secret, api_host: 'debug.example.com')
|
602
|
-
|
603
|
-
@client.get_basic_number_insight(number: '447525856424')
|
604
|
-
end
|
605
|
-
|
606
|
-
private
|
607
|
-
|
608
|
-
def expect(method_symbol, url, body = nil)
|
609
|
-
headers = {'Authorization' => /\ABearer (.+)\.(.+)\.(.+)\z/}
|
610
|
-
|
611
|
-
@request = stub_request(method_symbol, url)
|
612
|
-
|
613
|
-
if method_symbol == :delete
|
614
|
-
@request.with(headers: headers).to_return(status: 204)
|
615
|
-
elsif body.nil?
|
616
|
-
@request.with(headers: headers).to_return(@response_body)
|
617
|
-
else
|
618
|
-
headers['Content-Type'] = 'application/json'
|
619
|
-
|
620
|
-
@request.with(headers: headers, body: body).to_return(@response_body)
|
621
|
-
end
|
622
|
-
end
|
623
|
-
|
624
|
-
def expect_get(url)
|
625
|
-
@request = stub_request(:get, url).to_return(@response_body)
|
626
|
-
end
|
627
|
-
|
628
|
-
def expect_post(url, data)
|
629
|
-
body = WebMock::Util::QueryMapper.query_to_values(data)
|
630
|
-
|
631
|
-
headers = {'Content-Type' => 'application/x-www-form-urlencoded'}
|
632
|
-
|
633
|
-
@request = stub_request(:post, url).with(body: body, headers: headers).to_return(@response_body)
|
634
|
-
end
|
635
|
-
|
636
|
-
def expect_put(url, data)
|
637
|
-
body = WebMock::Util::QueryMapper.query_to_values(data)
|
638
|
-
|
639
|
-
headers = {'Content-Type' => 'application/json'}
|
640
|
-
|
641
|
-
@request = stub_request(:put, url).with(body: body, headers: headers).to_return(@response_body)
|
642
|
-
end
|
643
|
-
|
644
|
-
def expect_delete(url)
|
645
|
-
@request = stub_request(:delete, url).to_return(status: 204)
|
646
|
-
end
|
647
|
-
|
648
|
-
after do
|
649
|
-
assert_requested(@request) if defined?(@request)
|
650
|
-
end
|
651
|
-
end
|