nexmo 2.0.0 → 3.0.0
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/LICENSE.txt +9 -0
- data/README.md +11 -15
- data/lib/nexmo.rb +41 -25
- data/nexmo.gemspec +7 -4
- data/spec/nexmo_spec.rb +53 -13
- metadata +26 -10
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 3ef6856f5c4e7fb5d1aaf2dc94c0487501afa661
|
4
|
+
data.tar.gz: d5483a19e91810334838fcc842da883d0536673c
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: b5643454f0546a2301fff3543a96ff321d190263f37cbb202abee9fd494fb9474ae1b278aa5ff8ffaafada94e0c5b9f8850dcdb16f02c96c8ed1fc667a397f31
|
7
|
+
data.tar.gz: 40f9abaa788cc4c177e109f738f3142ac28047e0154e44f44459a55ce608f2f7077a4b7fd4c999e06b9cbb1b202581eb35f9e0a53e68c32059318ae81e734d35
|
data/LICENSE.txt
ADDED
@@ -0,0 +1,9 @@
|
|
1
|
+
Copyright (c) TIMCRAFT <http://timcraft.com>
|
2
|
+
|
3
|
+
This is an Open Source project licensed under the terms of the LGPLv3 license.
|
4
|
+
Please see <http://www.gnu.org/licenses/lgpl-3.0.html> for license text.
|
5
|
+
|
6
|
+
This code is distributed in the hope that it will be useful,
|
7
|
+
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
8
|
+
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
9
|
+
GNU Lesser General Public License for more details.
|
data/README.md
CHANGED
@@ -2,7 +2,7 @@ nexmo
|
|
2
2
|
=====
|
3
3
|
|
4
4
|
|
5
|
-
A Ruby wrapper for the [Nexmo API](https://
|
5
|
+
A Ruby wrapper for the [Nexmo API](https://docs.nexmo.com/).
|
6
6
|
|
7
7
|
|
8
8
|
Installation
|
@@ -14,8 +14,8 @@ Installation
|
|
14
14
|
Sending a message
|
15
15
|
-----------------
|
16
16
|
|
17
|
-
Construct a Nexmo::Client object
|
18
|
-
send a message. For example:
|
17
|
+
Construct a Nexmo::Client object with your API credentials and call
|
18
|
+
the #send_message method to send a message. For example:
|
19
19
|
|
20
20
|
```ruby
|
21
21
|
require 'nexmo'
|
@@ -25,10 +25,14 @@ nexmo = Nexmo::Client.new(key: 'YOUR API KEY', secret: 'YOUR API SECRET')
|
|
25
25
|
nexmo.send_message(from: 'Ruby', to: 'YOUR NUMBER', text: 'Hello world')
|
26
26
|
```
|
27
27
|
|
28
|
-
This method call returns the message id if the message
|
29
|
-
or raises an exception if there was an error.
|
30
|
-
|
31
|
-
|
28
|
+
This method call returns the message id and other details if the message
|
29
|
+
was sent successfully, or raises an exception if there was an error.
|
30
|
+
|
31
|
+
The Nexmo documentation contains a [list of error codes](https://docs.nexmo.com/index.php/sms-api/send-message#response_code)
|
32
|
+
which may be useful for debugging exceptions. Remember that phone numbers
|
33
|
+
should be specified in international format, and other country specific
|
34
|
+
restrictions may apply (e.g. US messages must originate from either a
|
35
|
+
pre-approved long number or short code).
|
32
36
|
|
33
37
|
|
34
38
|
Production environment variables
|
@@ -39,11 +43,3 @@ to use environment variables, as described by [12factor.net/config](http://12fac
|
|
39
43
|
Nexmo::Client defaults to extracting the api key/secret it needs from the
|
40
44
|
NEXMO_API_KEY and NEXMO_API_SECRET environment variables if the key/secret
|
41
45
|
options were not specified explicitly.
|
42
|
-
|
43
|
-
|
44
|
-
Troubleshooting
|
45
|
-
---------------
|
46
|
-
|
47
|
-
Remember that phone numbers should be specified in international format.
|
48
|
-
|
49
|
-
Please report all bugs/issues via the GitHub issue tracker.
|
data/lib/nexmo.rb
CHANGED
@@ -8,7 +8,7 @@ module Nexmo
|
|
8
8
|
class AuthenticationError < Error; end
|
9
9
|
|
10
10
|
class Client
|
11
|
-
attr_accessor :key, :secret
|
11
|
+
attr_accessor :key, :secret
|
12
12
|
|
13
13
|
def initialize(options = {})
|
14
14
|
@key = options.fetch(:key) { ENV.fetch('NEXMO_API_KEY') }
|
@@ -16,10 +16,6 @@ module Nexmo
|
|
16
16
|
@secret = options.fetch(:secret) { ENV.fetch('NEXMO_API_SECRET') }
|
17
17
|
|
18
18
|
@host = options.fetch(:host) { 'rest.nexmo.com' }
|
19
|
-
|
20
|
-
@http = Net::HTTP.new(@host, Net::HTTP.https_default_port)
|
21
|
-
|
22
|
-
@http.use_ssl = true
|
23
19
|
end
|
24
20
|
|
25
21
|
def send_message(params)
|
@@ -29,11 +25,9 @@ module Nexmo
|
|
29
25
|
|
30
26
|
status = item['status'].to_i
|
31
27
|
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
raise Error, "#{item['error-text']} (status=#{status})"
|
36
|
-
end
|
28
|
+
raise Error, "#{item['error-text']} (status=#{status})" unless status.zero?
|
29
|
+
|
30
|
+
return item
|
37
31
|
end
|
38
32
|
|
39
33
|
def get_balance
|
@@ -105,23 +99,53 @@ module Nexmo
|
|
105
99
|
end
|
106
100
|
|
107
101
|
def initiate_tts_call(params)
|
108
|
-
post('/tts/json', params)
|
102
|
+
post('https://api.nexmo.com/tts/json', params)
|
109
103
|
end
|
110
104
|
|
111
105
|
def initiate_tts_prompt_call(params)
|
112
|
-
post('/tts-prompt/json', params)
|
106
|
+
post('https://api.nexmo.com/tts-prompt/json', params)
|
107
|
+
end
|
108
|
+
|
109
|
+
def send_verification_request(params)
|
110
|
+
post('https://api.nexmo.com/verify/json', params)
|
111
|
+
end
|
112
|
+
|
113
|
+
def check_verification_request(params)
|
114
|
+
post('https://api.nexmo.com/verify/check/json', params)
|
115
|
+
end
|
116
|
+
|
117
|
+
def get_verification_request(id)
|
118
|
+
get('https://api.nexmo.com/verify/search/json', :request_id => id)
|
119
|
+
end
|
120
|
+
|
121
|
+
def request_number_insight(params)
|
122
|
+
post('/ni/json', params)
|
113
123
|
end
|
114
124
|
|
115
125
|
private
|
116
126
|
|
117
127
|
def get(path, params = {})
|
118
|
-
|
128
|
+
uri = URI.join("https://#{@host}", path)
|
129
|
+
uri.query = query_string(params.merge(:api_key => @key, :api_secret => @secret))
|
130
|
+
|
131
|
+
get_request = Net::HTTP::Get.new(uri.request_uri)
|
132
|
+
|
133
|
+
http = Net::HTTP.new(uri.host, Net::HTTP.https_default_port)
|
134
|
+
http.use_ssl = true
|
135
|
+
|
136
|
+
parse http.request(get_request)
|
119
137
|
end
|
120
138
|
|
121
139
|
def post(path, params)
|
122
|
-
|
140
|
+
uri = URI.join("https://#{@host}", path)
|
141
|
+
|
142
|
+
post_request = Net::HTTP::Post.new(uri.request_uri)
|
143
|
+
post_request.form_data = params.merge(:api_key => @key, :api_secret => @secret)
|
123
144
|
|
124
|
-
|
145
|
+
http = Net::HTTP.new(uri.host, Net::HTTP.https_default_port)
|
146
|
+
http.use_ssl = true
|
147
|
+
|
148
|
+
parse http.request(post_request)
|
125
149
|
end
|
126
150
|
|
127
151
|
def parse(http_response)
|
@@ -139,16 +163,8 @@ module Nexmo
|
|
139
163
|
end
|
140
164
|
end
|
141
165
|
|
142
|
-
def
|
143
|
-
|
144
|
-
path
|
145
|
-
else
|
146
|
-
query_params = hash.map do |key, values|
|
147
|
-
Array(values).map { |value| "#{escape(key)}=#{escape(value)}" }
|
148
|
-
end
|
149
|
-
|
150
|
-
path + '?' + query_params.flatten.join('&')
|
151
|
-
end
|
166
|
+
def query_string(params)
|
167
|
+
params.flat_map { |k, vs| Array(vs).map { |v| "#{escape(k)}=#{escape(v)}" } }.join('&')
|
152
168
|
end
|
153
169
|
|
154
170
|
def escape(component)
|
data/nexmo.gemspec
CHANGED
@@ -1,14 +1,17 @@
|
|
1
1
|
Gem::Specification.new do |s|
|
2
2
|
s.name = 'nexmo'
|
3
|
-
s.version = '
|
3
|
+
s.version = '3.0.0'
|
4
|
+
s.license = 'LGPL-3.0'
|
4
5
|
s.platform = Gem::Platform::RUBY
|
5
6
|
s.authors = ['Tim Craft']
|
6
7
|
s.email = ['mail@timcraft.com']
|
7
8
|
s.homepage = 'http://github.com/timcraft/nexmo'
|
8
9
|
s.description = 'A Ruby wrapper for the Nexmo API'
|
9
10
|
s.summary = 'See description'
|
10
|
-
s.files = Dir.glob('{lib,spec}/**/*') + %w(README.md nexmo.gemspec)
|
11
|
-
s.
|
12
|
-
s.add_development_dependency('
|
11
|
+
s.files = Dir.glob('{lib,spec}/**/*') + %w(LICENSE.txt README.md nexmo.gemspec)
|
12
|
+
s.required_ruby_version = '>= 1.9.3'
|
13
|
+
s.add_development_dependency('rake', '~> 10.1')
|
14
|
+
s.add_development_dependency('webmock', '~> 1.18')
|
15
|
+
s.add_development_dependency('minitest', '~> 5.0')
|
13
16
|
s.require_path = 'lib'
|
14
17
|
end
|
data/spec/nexmo_spec.rb
CHANGED
@@ -10,6 +10,8 @@ describe 'Nexmo::Client' do
|
|
10
10
|
before do
|
11
11
|
@base_url = 'https://rest.nexmo.com'
|
12
12
|
|
13
|
+
@api_base_url = 'https://api.nexmo.com'
|
14
|
+
|
13
15
|
@form_urlencoded_data = {body: /(.+?)=(.+?)(&(.+?)=(.+?))+/, headers: {'Content-Type' => 'application/x-www-form-urlencoded'}}
|
14
16
|
|
15
17
|
@json_response_body = json_response_body('{"key":"value"}')
|
@@ -21,21 +23,13 @@ describe 'Nexmo::Client' do
|
|
21
23
|
@client = Nexmo::Client.new(key: 'key', secret: 'secret')
|
22
24
|
end
|
23
25
|
|
24
|
-
describe 'http method' do
|
25
|
-
it 'returns a net http object that uses ssl' do
|
26
|
-
@client.http.must_be_instance_of(Net::HTTP)
|
27
|
-
|
28
|
-
@client.http.use_ssl?.must_equal(true)
|
29
|
-
end
|
30
|
-
end
|
31
|
-
|
32
26
|
describe 'send_message method' do
|
33
|
-
it 'posts to the sms json resource and returns the message
|
27
|
+
it 'posts to the sms json resource and returns the response message object' do
|
34
28
|
response_body = json_response_body('{"messages":[{"status":0,"message-id":"id"}]}')
|
35
29
|
|
36
30
|
stub_request(:post, "#@base_url/sms/json").with(@form_urlencoded_data).to_return(response_body)
|
37
31
|
|
38
|
-
@client.send_message(@example_message_hash).must_equal('id')
|
32
|
+
@client.send_message(@example_message_hash).must_equal({'status' => 0, 'message-id' => 'id'})
|
39
33
|
end
|
40
34
|
|
41
35
|
it 'raises an exception if the response body contains an error' do
|
@@ -229,7 +223,7 @@ describe 'Nexmo::Client' do
|
|
229
223
|
|
230
224
|
describe 'initiate_tts_call method' do
|
231
225
|
it 'posts to the tts json resource and returns the response object' do
|
232
|
-
url = "#@
|
226
|
+
url = "#@api_base_url/tts/json"
|
233
227
|
|
234
228
|
stub_request(:post, url).with(@form_urlencoded_data).to_return(@json_response_body)
|
235
229
|
|
@@ -239,7 +233,7 @@ describe 'Nexmo::Client' do
|
|
239
233
|
|
240
234
|
describe 'initiate_tts_prompt_call method' do
|
241
235
|
it 'posts to the tts prompt json resource and returns the response object' do
|
242
|
-
url = "#@
|
236
|
+
url = "#@api_base_url/tts-prompt/json"
|
243
237
|
|
244
238
|
stub_request(:post, url).with(@form_urlencoded_data).to_return(@json_response_body)
|
245
239
|
|
@@ -247,6 +241,46 @@ describe 'Nexmo::Client' do
|
|
247
241
|
end
|
248
242
|
end
|
249
243
|
|
244
|
+
describe 'send_verification_request method' do
|
245
|
+
it 'posts to the verify json resource and returns the response object' do
|
246
|
+
url = "#@api_base_url/verify/json"
|
247
|
+
|
248
|
+
stub_request(:post, url).with(@form_urlencoded_data).to_return(@json_response_body)
|
249
|
+
|
250
|
+
@client.send_verification_request(number: '447525856424', brand: 'MyApp')
|
251
|
+
end
|
252
|
+
end
|
253
|
+
|
254
|
+
describe 'check_verification_request method' do
|
255
|
+
it 'posts to the verify json resource and returns the response object' do
|
256
|
+
url = "#@api_base_url/verify/check/json"
|
257
|
+
|
258
|
+
stub_request(:post, url).with(@form_urlencoded_data).to_return(@json_response_body)
|
259
|
+
|
260
|
+
@client.check_verification_request(request_id: '8g88g88eg8g8gg9g90', code: '123445')
|
261
|
+
end
|
262
|
+
end
|
263
|
+
|
264
|
+
describe 'get_verification_request method' do
|
265
|
+
it 'fetches the verify search resource with the given request id and returns the response object' do
|
266
|
+
url = "#@api_base_url/verify/search/json?api_key=key&api_secret=secret&request_id=8g88g88eg8g8gg9g90"
|
267
|
+
|
268
|
+
stub_request(:get, url).to_return(@json_response_body)
|
269
|
+
|
270
|
+
@client.get_verification_request('8g88g88eg8g8gg9g90')
|
271
|
+
end
|
272
|
+
end
|
273
|
+
|
274
|
+
describe 'request_number_insight method' do
|
275
|
+
it 'posts to the number insight resource and returns the response object' do
|
276
|
+
url = "#@base_url/ni/json"
|
277
|
+
|
278
|
+
stub_request(:post, url).with(@form_urlencoded_data).to_return(@json_response_body)
|
279
|
+
|
280
|
+
@client.request_number_insight(number: '447525856424', callback: 'https://example.com')
|
281
|
+
end
|
282
|
+
end
|
283
|
+
|
250
284
|
it 'raises an exception if the response code is not 2xx' do
|
251
285
|
stub_request(:post, "#@base_url/sms/json").with(@form_urlencoded_data).to_return(status: 500)
|
252
286
|
|
@@ -260,8 +294,14 @@ describe 'Nexmo::Client' do
|
|
260
294
|
end
|
261
295
|
|
262
296
|
it 'provides an option for specifying a different hostname to connect to' do
|
297
|
+
url = "https://rest-sandbox.nexmo.com/number/search?api_key=key&api_secret=secret&country=CA&size=25"
|
298
|
+
|
299
|
+
request = stub_request(:get, url).to_return(@json_response_body)
|
300
|
+
|
263
301
|
@client = Nexmo::Client.new(key: 'key', secret: 'secret', host: 'rest-sandbox.nexmo.com')
|
264
302
|
|
265
|
-
@client.
|
303
|
+
@client.number_search(:CA, :size => 25)
|
304
|
+
|
305
|
+
assert_requested(request)
|
266
306
|
end
|
267
307
|
end
|
metadata
CHANGED
@@ -1,43 +1,57 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: nexmo
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version:
|
4
|
+
version: 3.0.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Tim Craft
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2015-03-21 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rake
|
15
15
|
requirement: !ruby/object:Gem::Requirement
|
16
16
|
requirements:
|
17
|
-
- - "
|
17
|
+
- - "~>"
|
18
18
|
- !ruby/object:Gem::Version
|
19
|
-
version:
|
19
|
+
version: '10.1'
|
20
20
|
type: :development
|
21
21
|
prerelease: false
|
22
22
|
version_requirements: !ruby/object:Gem::Requirement
|
23
23
|
requirements:
|
24
|
-
- - "
|
24
|
+
- - "~>"
|
25
25
|
- !ruby/object:Gem::Version
|
26
|
-
version:
|
26
|
+
version: '10.1'
|
27
27
|
- !ruby/object:Gem::Dependency
|
28
28
|
name: webmock
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
30
30
|
requirements:
|
31
31
|
- - "~>"
|
32
32
|
- !ruby/object:Gem::Version
|
33
|
-
version: 1.18
|
33
|
+
version: '1.18'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '1.18'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: minitest
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '5.0'
|
34
48
|
type: :development
|
35
49
|
prerelease: false
|
36
50
|
version_requirements: !ruby/object:Gem::Requirement
|
37
51
|
requirements:
|
38
52
|
- - "~>"
|
39
53
|
- !ruby/object:Gem::Version
|
40
|
-
version:
|
54
|
+
version: '5.0'
|
41
55
|
description: A Ruby wrapper for the Nexmo API
|
42
56
|
email:
|
43
57
|
- mail@timcraft.com
|
@@ -45,12 +59,14 @@ executables: []
|
|
45
59
|
extensions: []
|
46
60
|
extra_rdoc_files: []
|
47
61
|
files:
|
62
|
+
- LICENSE.txt
|
48
63
|
- README.md
|
49
64
|
- lib/nexmo.rb
|
50
65
|
- nexmo.gemspec
|
51
66
|
- spec/nexmo_spec.rb
|
52
67
|
homepage: http://github.com/timcraft/nexmo
|
53
|
-
licenses:
|
68
|
+
licenses:
|
69
|
+
- LGPL-3.0
|
54
70
|
metadata: {}
|
55
71
|
post_install_message:
|
56
72
|
rdoc_options: []
|
@@ -60,7 +76,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
60
76
|
requirements:
|
61
77
|
- - ">="
|
62
78
|
- !ruby/object:Gem::Version
|
63
|
-
version:
|
79
|
+
version: 1.9.3
|
64
80
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
65
81
|
requirements:
|
66
82
|
- - ">="
|