nexmo 1.2.0 → 1.3.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 +7 -0
- data/README.md +1 -1
- data/lib/nexmo.rb +15 -1
- data/nexmo.gemspec +4 -3
- data/spec/nexmo_spec.rb +58 -29
- metadata +31 -28
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: ae52a9612e17e4e82d62b525f27b1d02523f6d34
|
4
|
+
data.tar.gz: e0fb13b7e0989a6f591102ff5583120006df6270
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: a9bbfbdf2791eff805283d71bad2812a0900b8e6afee3104e6387136112fe5d303f0557f2a35e09165e57a9e1ab7b693ccea95b7b07c8c79bafaed070be50fc1
|
7
|
+
data.tar.gz: dc9656dd961d47e4a908077f0fb1b80f1b7fac12f4d410c75b7495f3a10b3ce1f7ee215e1f02c971f80dd6bf5ba529e7ca2fa4e40fc4f4e84ef443144c0cf645
|
data/README.md
CHANGED
@@ -111,7 +111,7 @@ Troubleshooting
|
|
111
111
|
|
112
112
|
Remember that phone numbers should be specified in international format.
|
113
113
|
|
114
|
-
The Nexmo documentation contains a [list of error codes](
|
114
|
+
The Nexmo documentation contains a [list of error codes](https://docs.nexmo.com/index.php/sms-api/send-message#response_code)
|
115
115
|
which may be useful if you have problems sending a message.
|
116
116
|
|
117
117
|
Please report all bugs/issues via the GitHub issue tracker.
|
data/lib/nexmo.rb
CHANGED
@@ -16,7 +16,9 @@ module Nexmo
|
|
16
16
|
@json = JSON
|
17
17
|
end
|
18
18
|
|
19
|
-
@
|
19
|
+
@host = options.fetch(:host) { 'rest.nexmo.com' }
|
20
|
+
|
21
|
+
@http = Net::HTTP.new(@host, Net::HTTP.https_default_port)
|
20
22
|
|
21
23
|
@http.use_ssl = true
|
22
24
|
end
|
@@ -65,6 +67,18 @@ module Nexmo
|
|
65
67
|
get('/number/search', {:country => country_code}.merge(params))
|
66
68
|
end
|
67
69
|
|
70
|
+
def buy_number(params)
|
71
|
+
post('/number/buy', params)
|
72
|
+
end
|
73
|
+
|
74
|
+
def cancel_number(params)
|
75
|
+
post('/number/cancel', params)
|
76
|
+
end
|
77
|
+
|
78
|
+
def update_number(params)
|
79
|
+
post('/number/update', params)
|
80
|
+
end
|
81
|
+
|
68
82
|
def get_message(id)
|
69
83
|
get('/search/message', {:id => id})
|
70
84
|
end
|
data/nexmo.gemspec
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
Gem::Specification.new do |s|
|
2
2
|
s.name = 'nexmo'
|
3
|
-
s.version = '1.
|
3
|
+
s.version = '1.3.0'
|
4
4
|
s.platform = Gem::Platform::RUBY
|
5
5
|
s.authors = ['Tim Craft']
|
6
6
|
s.email = ['mail@timcraft.com']
|
@@ -12,10 +12,11 @@ Gem::Specification.new do |s|
|
|
12
12
|
s.add_development_dependency('mocha', '~> 0.13.2')
|
13
13
|
s.add_development_dependency('oauth', '~> 0.4.7')
|
14
14
|
s.add_development_dependency('faux', '~> 1.1.0')
|
15
|
+
s.add_development_dependency('webmock', '~> 1.17.0')
|
15
16
|
s.require_path = 'lib'
|
16
17
|
|
17
18
|
if RUBY_VERSION == '1.8.7'
|
18
|
-
s.add_development_dependency('minitest', '
|
19
|
-
s.add_development_dependency('json', '
|
19
|
+
s.add_development_dependency('minitest', '~> 4.2.0')
|
20
|
+
s.add_development_dependency('json', '~> 1.8.0')
|
20
21
|
end
|
21
22
|
end
|
data/spec/nexmo_spec.rb
CHANGED
@@ -1,4 +1,5 @@
|
|
1
1
|
require 'minitest/autorun'
|
2
|
+
require 'webmock/minitest'
|
2
3
|
require 'mocha/setup'
|
3
4
|
require 'faux'
|
4
5
|
require 'nexmo'
|
@@ -7,19 +8,17 @@ require 'json'
|
|
7
8
|
|
8
9
|
describe 'Nexmo::Client' do
|
9
10
|
before do
|
10
|
-
@
|
11
|
+
@base_url = 'https://rest.nexmo.com'
|
11
12
|
|
12
|
-
@
|
13
|
+
@json_object = {:body => /\{".+?":".+?"(,".+?":".+?")+\}/, :headers => {'Content-Type' => 'application/json'}}
|
14
|
+
|
15
|
+
@oauth_header = {'Authorization' => /\AOAuth .+\z/}
|
13
16
|
|
14
17
|
@example_message_hash = {:from => 'ruby', :to => 'number', :text => 'Hey!'}
|
15
18
|
|
16
19
|
@client = Nexmo::Client.new('key', 'secret')
|
17
20
|
end
|
18
21
|
|
19
|
-
def expects_http_get(request_uri)
|
20
|
-
@client.http.expects(:get).with(has_equivalent_query_string(request_uri)).returns(stub)
|
21
|
-
end
|
22
|
-
|
23
22
|
describe 'http method' do
|
24
23
|
it 'returns a net http object that uses ssl' do
|
25
24
|
@client.http.must_be_instance_of(Net::HTTP)
|
@@ -30,7 +29,7 @@ describe 'Nexmo::Client' do
|
|
30
29
|
|
31
30
|
describe 'send_message method' do
|
32
31
|
it 'posts to the sms json resource and returns a response object' do
|
33
|
-
|
32
|
+
stub_request(:post, "#@base_url/sms/json").with(@json_object)
|
34
33
|
|
35
34
|
@client.send_message(@example_message_hash).must_be_instance_of(Nexmo::Response)
|
36
35
|
end
|
@@ -42,25 +41,25 @@ describe 'Nexmo::Client' do
|
|
42
41
|
end
|
43
42
|
|
44
43
|
it 'posts to the sms json resource and returns the message id' do
|
45
|
-
|
46
|
-
|
47
|
-
|
44
|
+
stub_request(:post, "#@base_url/sms/json").with(@json_object).to_return({
|
45
|
+
:headers => {'Content-Type' => 'application/json'},
|
46
|
+
:body => '{"messages":[{"status":0,"message-id":"id"}]}'
|
47
|
+
})
|
48
48
|
|
49
49
|
@client.send_message!(@example_message_hash).must_equal('id')
|
50
50
|
end
|
51
51
|
|
52
52
|
it 'raises an exception if the response code is not expected' do
|
53
|
-
|
54
|
-
|
55
|
-
@client.http.stubs(:post).returns(@http_response)
|
53
|
+
stub_request(:post, "#@base_url/sms/json").with(@json_object).to_return(:status => 500)
|
56
54
|
|
57
55
|
proc { @client.send_message!(@example_message_hash) }.must_raise(Nexmo::Error)
|
58
56
|
end
|
59
57
|
|
60
58
|
it 'raises an exception if the response body contains an error' do
|
61
|
-
|
62
|
-
|
63
|
-
|
59
|
+
stub_request(:post, "#@base_url/sms/json").with(@json_object).to_return({
|
60
|
+
:headers => {'Content-Type' => 'application/json'},
|
61
|
+
:body => '{"messages":[{"status":2,"error-text":"Missing from param"}]}'
|
62
|
+
})
|
64
63
|
|
65
64
|
proc { @client.send_message!(@example_message_hash) }.must_raise(Nexmo::Error)
|
66
65
|
end
|
@@ -68,7 +67,7 @@ describe 'Nexmo::Client' do
|
|
68
67
|
|
69
68
|
describe 'get_balance method' do
|
70
69
|
it 'fetches the account balance resource and returns a response object' do
|
71
|
-
|
70
|
+
stub_request(:get, "#@base_url/account/get-balance?api_key=key&api_secret=secret")
|
72
71
|
|
73
72
|
@client.get_balance.must_be_instance_of(Nexmo::Response)
|
74
73
|
end
|
@@ -76,7 +75,7 @@ describe 'Nexmo::Client' do
|
|
76
75
|
|
77
76
|
describe 'get_country_pricing method' do
|
78
77
|
it 'fetches the outbound pricing resource for the given country and returns a response object' do
|
79
|
-
|
78
|
+
stub_request(:get, "#@base_url/account/get-pricing/outbound?api_key=key&api_secret=secret&country=CA")
|
80
79
|
|
81
80
|
@client.get_country_pricing(:CA).must_be_instance_of(Nexmo::Response)
|
82
81
|
end
|
@@ -84,7 +83,7 @@ describe 'Nexmo::Client' do
|
|
84
83
|
|
85
84
|
describe 'get_prefix_pricing method' do
|
86
85
|
it 'fetches the outbound pricing resource for the given prefix and returns a response object' do
|
87
|
-
|
86
|
+
stub_request(:get, "#@base_url/account/get-prefix-pricing/outbound?api_key=key&api_secret=secret&prefix=44")
|
88
87
|
|
89
88
|
@client.get_prefix_pricing(44).must_be_instance_of(Nexmo::Response)
|
90
89
|
end
|
@@ -92,7 +91,7 @@ describe 'Nexmo::Client' do
|
|
92
91
|
|
93
92
|
describe 'get_account_numbers method' do
|
94
93
|
it 'fetches the account numbers resource with the given parameters and returns a response object' do
|
95
|
-
|
94
|
+
stub_request(:get, "#@base_url/account/numbers?api_key=key&api_secret=secret&size=25&pattern=33")
|
96
95
|
|
97
96
|
@client.get_account_numbers(:size => 25, :pattern => 33).must_be_instance_of(Nexmo::Response)
|
98
97
|
end
|
@@ -100,15 +99,39 @@ describe 'Nexmo::Client' do
|
|
100
99
|
|
101
100
|
describe 'number_search method' do
|
102
101
|
it 'fetches the number search resource for the given country with the given parameters and returns a response object' do
|
103
|
-
|
102
|
+
stub_request(:get, "#@base_url/number/search?api_key=key&api_secret=secret&country=CA&size=25")
|
104
103
|
|
105
104
|
@client.number_search(:CA, :size => 25).must_be_instance_of(Nexmo::Response)
|
106
105
|
end
|
107
106
|
end
|
108
107
|
|
108
|
+
describe 'buy_number method' do
|
109
|
+
it 'purchases the number requested with the given parameters and returns a response object' do
|
110
|
+
stub_request(:post, "#@base_url/number/buy").with(@json_object)
|
111
|
+
|
112
|
+
@client.buy_number(:country => 'US', :msisdn => 'number').must_be_instance_of(Nexmo::Response)
|
113
|
+
end
|
114
|
+
end
|
115
|
+
|
116
|
+
describe 'cancel_number method' do
|
117
|
+
it 'cancels the number requested with the given parameters and returns a response object' do
|
118
|
+
stub_request(:post, "#@base_url/number/cancel").with(@json_object)
|
119
|
+
|
120
|
+
@client.cancel_number(:country => 'US', :msisdn => 'number').must_be_instance_of(Nexmo::Response)
|
121
|
+
end
|
122
|
+
end
|
123
|
+
|
124
|
+
describe 'update_number method' do
|
125
|
+
it 'updates the number requested with the given parameters and returns a response object' do
|
126
|
+
stub_request(:post, "#@base_url/number/update").with(@json_object)
|
127
|
+
|
128
|
+
@client.update_number(:country => 'US', :msisdn => 'number', :moHttpUrl => 'callback').must_be_instance_of(Nexmo::Response)
|
129
|
+
end
|
130
|
+
end
|
131
|
+
|
109
132
|
describe 'get_message method' do
|
110
133
|
it 'fetches the message search resource for the given message id and returns a response object' do
|
111
|
-
|
134
|
+
stub_request(:get, "#@base_url/search/message?api_key=key&api_secret=secret&id=00A0B0C0")
|
112
135
|
|
113
136
|
@client.get_message('00A0B0C0').must_be_instance_of(Nexmo::Response)
|
114
137
|
end
|
@@ -116,7 +139,7 @@ describe 'Nexmo::Client' do
|
|
116
139
|
|
117
140
|
describe 'get_message_rejections method' do
|
118
141
|
it 'fetches the message rejections resource with the given parameters and returns a response object' do
|
119
|
-
|
142
|
+
stub_request(:get, "#@base_url/search/rejections?api_key=key&api_secret=secret&date=YYYY-MM-DD")
|
120
143
|
|
121
144
|
@client.get_message_rejections(:date => 'YYYY-MM-DD').must_be_instance_of(Nexmo::Response)
|
122
145
|
end
|
@@ -124,13 +147,13 @@ describe 'Nexmo::Client' do
|
|
124
147
|
|
125
148
|
describe 'search_messages method' do
|
126
149
|
it 'fetches the search messages resource with the given parameters and returns a response object' do
|
127
|
-
|
150
|
+
stub_request(:get, "#@base_url/search/messages?api_key=key&api_secret=secret&date=YYYY-MM-DD&to=1234567890")
|
128
151
|
|
129
152
|
@client.search_messages(:date => 'YYYY-MM-DD', :to => 1234567890).must_be_instance_of(Nexmo::Response)
|
130
153
|
end
|
131
154
|
|
132
155
|
it 'should encode a non hash argument as a list of ids' do
|
133
|
-
|
156
|
+
stub_request(:get, "#@base_url/search/messages?api_key=key&api_secret=secret&ids=id1&ids=id2")
|
134
157
|
|
135
158
|
@client.search_messages(%w(id1 id2))
|
136
159
|
end
|
@@ -145,18 +168,18 @@ describe 'Nexmo::Client' do
|
|
145
168
|
@client = Nexmo::Client.new
|
146
169
|
|
147
170
|
@client.oauth_access_token = @oauth_access_token
|
148
|
-
|
149
|
-
@client.http = mock()
|
150
171
|
end
|
151
172
|
|
152
173
|
it 'makes get requests through the access token and returns a response object' do
|
153
|
-
|
174
|
+
stub_request(:get, "#@base_url/account/get-pricing/outbound?country=CA").with(:headers => @oauth_header)
|
154
175
|
|
155
176
|
@client.get_country_pricing(:CA).must_be_instance_of(Nexmo::Response)
|
156
177
|
end
|
157
178
|
|
158
179
|
it 'makes post requests through the access token and returns a response object' do
|
159
|
-
@
|
180
|
+
@json_object[:headers].merge!(@oauth_header)
|
181
|
+
|
182
|
+
stub_request(:post, "#@base_url/sms/json").with(@json_object)
|
160
183
|
|
161
184
|
@client.send_message(@example_message_hash).must_be_instance_of(Nexmo::Response)
|
162
185
|
end
|
@@ -199,6 +222,12 @@ describe 'Nexmo::Client' do
|
|
199
222
|
@client.get_balance.must_equal(:return_value)
|
200
223
|
end
|
201
224
|
end
|
225
|
+
|
226
|
+
it 'provides an option for specifying a different hostname to connect to' do
|
227
|
+
@client = Nexmo::Client.new('key', 'secret', host: 'rest-sandbox.nexmo.com')
|
228
|
+
|
229
|
+
@client.http.address.must_equal('rest-sandbox.nexmo.com')
|
230
|
+
end
|
202
231
|
end
|
203
232
|
|
204
233
|
describe 'Nexmo::Response' do
|
metadata
CHANGED
@@ -1,80 +1,85 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: nexmo
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
5
|
-
prerelease:
|
4
|
+
version: 1.3.0
|
6
5
|
platform: ruby
|
7
6
|
authors:
|
8
7
|
- Tim Craft
|
9
8
|
autorequire:
|
10
9
|
bindir: bin
|
11
10
|
cert_chain: []
|
12
|
-
date:
|
11
|
+
date: 2014-04-22 00:00:00.000000000 Z
|
13
12
|
dependencies:
|
14
13
|
- !ruby/object:Gem::Dependency
|
15
14
|
name: rake
|
16
15
|
requirement: !ruby/object:Gem::Requirement
|
17
|
-
none: false
|
18
16
|
requirements:
|
19
|
-
- -
|
17
|
+
- - ">="
|
20
18
|
- !ruby/object:Gem::Version
|
21
19
|
version: 0.9.3
|
22
20
|
type: :development
|
23
21
|
prerelease: false
|
24
22
|
version_requirements: !ruby/object:Gem::Requirement
|
25
|
-
none: false
|
26
23
|
requirements:
|
27
|
-
- -
|
24
|
+
- - ">="
|
28
25
|
- !ruby/object:Gem::Version
|
29
26
|
version: 0.9.3
|
30
27
|
- !ruby/object:Gem::Dependency
|
31
28
|
name: mocha
|
32
29
|
requirement: !ruby/object:Gem::Requirement
|
33
|
-
none: false
|
34
30
|
requirements:
|
35
|
-
- - ~>
|
31
|
+
- - "~>"
|
36
32
|
- !ruby/object:Gem::Version
|
37
33
|
version: 0.13.2
|
38
34
|
type: :development
|
39
35
|
prerelease: false
|
40
36
|
version_requirements: !ruby/object:Gem::Requirement
|
41
|
-
none: false
|
42
37
|
requirements:
|
43
|
-
- - ~>
|
38
|
+
- - "~>"
|
44
39
|
- !ruby/object:Gem::Version
|
45
40
|
version: 0.13.2
|
46
41
|
- !ruby/object:Gem::Dependency
|
47
42
|
name: oauth
|
48
43
|
requirement: !ruby/object:Gem::Requirement
|
49
|
-
none: false
|
50
44
|
requirements:
|
51
|
-
- - ~>
|
45
|
+
- - "~>"
|
52
46
|
- !ruby/object:Gem::Version
|
53
47
|
version: 0.4.7
|
54
48
|
type: :development
|
55
49
|
prerelease: false
|
56
50
|
version_requirements: !ruby/object:Gem::Requirement
|
57
|
-
none: false
|
58
51
|
requirements:
|
59
|
-
- - ~>
|
52
|
+
- - "~>"
|
60
53
|
- !ruby/object:Gem::Version
|
61
54
|
version: 0.4.7
|
62
55
|
- !ruby/object:Gem::Dependency
|
63
56
|
name: faux
|
64
57
|
requirement: !ruby/object:Gem::Requirement
|
65
|
-
none: false
|
66
58
|
requirements:
|
67
|
-
- - ~>
|
59
|
+
- - "~>"
|
68
60
|
- !ruby/object:Gem::Version
|
69
61
|
version: 1.1.0
|
70
62
|
type: :development
|
71
63
|
prerelease: false
|
72
64
|
version_requirements: !ruby/object:Gem::Requirement
|
73
|
-
none: false
|
74
65
|
requirements:
|
75
|
-
- - ~>
|
66
|
+
- - "~>"
|
76
67
|
- !ruby/object:Gem::Version
|
77
68
|
version: 1.1.0
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: webmock
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - "~>"
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: 1.17.0
|
76
|
+
type: :development
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - "~>"
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: 1.17.0
|
78
83
|
description: A Ruby wrapper for the Nexmo API
|
79
84
|
email:
|
80
85
|
- mail@timcraft.com
|
@@ -82,33 +87,31 @@ executables: []
|
|
82
87
|
extensions: []
|
83
88
|
extra_rdoc_files: []
|
84
89
|
files:
|
85
|
-
- lib/nexmo.rb
|
86
|
-
- spec/nexmo_spec.rb
|
87
90
|
- README.md
|
91
|
+
- lib/nexmo.rb
|
88
92
|
- nexmo.gemspec
|
93
|
+
- spec/nexmo_spec.rb
|
89
94
|
homepage: http://github.com/timcraft/nexmo
|
90
95
|
licenses: []
|
96
|
+
metadata: {}
|
91
97
|
post_install_message:
|
92
98
|
rdoc_options: []
|
93
99
|
require_paths:
|
94
100
|
- lib
|
95
101
|
required_ruby_version: !ruby/object:Gem::Requirement
|
96
|
-
none: false
|
97
102
|
requirements:
|
98
|
-
- -
|
103
|
+
- - ">="
|
99
104
|
- !ruby/object:Gem::Version
|
100
105
|
version: '0'
|
101
106
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
102
|
-
none: false
|
103
107
|
requirements:
|
104
|
-
- -
|
108
|
+
- - ">="
|
105
109
|
- !ruby/object:Gem::Version
|
106
110
|
version: '0'
|
107
111
|
requirements: []
|
108
112
|
rubyforge_project:
|
109
|
-
rubygems_version:
|
113
|
+
rubygems_version: 2.2.2
|
110
114
|
signing_key:
|
111
|
-
specification_version:
|
115
|
+
specification_version: 4
|
112
116
|
summary: See description
|
113
117
|
test_files: []
|
114
|
-
has_rdoc:
|