nexmo 1.1.0 → 1.2.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.
- data/README.md +17 -13
- data/lib/nexmo.rb +20 -6
- data/nexmo.gemspec +2 -2
- data/spec/nexmo_spec.rb +41 -6
- metadata +10 -9
data/README.md
CHANGED
@@ -1,5 +1,8 @@
|
|
1
|
-
|
2
|
-
|
1
|
+
nexmo
|
2
|
+
=====
|
3
|
+
|
4
|
+
|
5
|
+
A Ruby wrapper for the [Nexmo API](https://www.nexmo.com/documentation/api/index.html).
|
3
6
|
|
4
7
|
|
5
8
|
Installation
|
@@ -84,22 +87,23 @@ OAuth::Consumer.new(consumer_key, consumer_secret, {
|
|
84
87
|
Using the `:body` or `:query_string` authorization mechanisms is not supported.
|
85
88
|
|
86
89
|
|
87
|
-
|
88
|
-
|
90
|
+
Custom response behaviour
|
91
|
+
-------------------------
|
89
92
|
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
constructing a client object. For example, to use [multi_json](https://rubygems.org/gems/multi_json):
|
93
|
+
You can customise the response handling by passing a block when constructing
|
94
|
+
a Nexmo::Client object. For example, if you want to use an alternative JSON
|
95
|
+
implementation to decode response bodies, you could do this:
|
94
96
|
|
95
97
|
```ruby
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
98
|
+
nexmo = Nexmo::Client.new do |response|
|
99
|
+
response.object = MultiJson.load(response.body) if response.ok? && response.json?
|
100
|
+
response
|
101
|
+
end
|
100
102
|
```
|
101
103
|
|
102
|
-
|
104
|
+
This might also be useful if you prefer a different style of error handling
|
105
|
+
(e.g. raising exceptions on error and returning the response object directly
|
106
|
+
for 200 OK responses), if you need to log responses etc.
|
103
107
|
|
104
108
|
|
105
109
|
Troubleshooting
|
data/lib/nexmo.rb
CHANGED
@@ -5,10 +5,16 @@ require 'cgi'
|
|
5
5
|
|
6
6
|
module Nexmo
|
7
7
|
class Client
|
8
|
-
def initialize(key = ENV['NEXMO_API_KEY'], secret = ENV['NEXMO_API_SECRET'], options = {})
|
9
|
-
@key, @secret = key, secret
|
8
|
+
def initialize(key = ENV['NEXMO_API_KEY'], secret = ENV['NEXMO_API_SECRET'], options = {}, &block)
|
9
|
+
@key, @secret, @block = key, secret, block
|
10
10
|
|
11
|
-
|
11
|
+
if options.has_key?(:json)
|
12
|
+
Kernel.warn '[nexmo] :json option is deprecated'
|
13
|
+
|
14
|
+
@json = options[:json]
|
15
|
+
else
|
16
|
+
@json = JSON
|
17
|
+
end
|
12
18
|
|
13
19
|
@http = Net::HTTP.new('rest.nexmo.com', Net::HTTP.https_default_port)
|
14
20
|
|
@@ -80,7 +86,7 @@ module Nexmo
|
|
80
86
|
@http.get(request_uri(path, params.merge(:api_key => @key, :api_secret => @secret)))
|
81
87
|
end
|
82
88
|
|
83
|
-
|
89
|
+
decode(http_response)
|
84
90
|
end
|
85
91
|
|
86
92
|
def post(path, params)
|
@@ -90,7 +96,13 @@ module Nexmo
|
|
90
96
|
@http.post(path, @json.dump(params.merge(:api_key => @key, :api_secret => @secret)), {'Content-Type' => 'application/json'})
|
91
97
|
end
|
92
98
|
|
93
|
-
|
99
|
+
decode(http_response)
|
100
|
+
end
|
101
|
+
|
102
|
+
def decode(http_response)
|
103
|
+
response = Response.new(http_response, :json => @json)
|
104
|
+
|
105
|
+
@block ? @block.call(response) : response
|
94
106
|
end
|
95
107
|
|
96
108
|
def request_uri(path, hash = {})
|
@@ -111,6 +123,8 @@ module Nexmo
|
|
111
123
|
end
|
112
124
|
|
113
125
|
class Response
|
126
|
+
attr_writer :object
|
127
|
+
|
114
128
|
def initialize(http_response, options = {})
|
115
129
|
@http_response = http_response
|
116
130
|
|
@@ -134,7 +148,7 @@ module Nexmo
|
|
134
148
|
end
|
135
149
|
|
136
150
|
def object
|
137
|
-
@object ||= @json.
|
151
|
+
@object ||= @json.parse(body)
|
138
152
|
end
|
139
153
|
end
|
140
154
|
|
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.2.0'
|
4
4
|
s.platform = Gem::Platform::RUBY
|
5
5
|
s.authors = ['Tim Craft']
|
6
6
|
s.email = ['mail@timcraft.com']
|
@@ -10,8 +10,8 @@ Gem::Specification.new do |s|
|
|
10
10
|
s.files = Dir.glob('{lib,spec}/**/*') + %w(README.md nexmo.gemspec)
|
11
11
|
s.add_development_dependency('rake', '>= 0.9.3')
|
12
12
|
s.add_development_dependency('mocha', '~> 0.13.2')
|
13
|
-
s.add_development_dependency('multi_json', '~> 1.3.6')
|
14
13
|
s.add_development_dependency('oauth', '~> 0.4.7')
|
14
|
+
s.add_development_dependency('faux', '~> 1.1.0')
|
15
15
|
s.require_path = 'lib'
|
16
16
|
|
17
17
|
if RUBY_VERSION == '1.8.7'
|
data/spec/nexmo_spec.rb
CHANGED
@@ -1,8 +1,9 @@
|
|
1
1
|
require 'minitest/autorun'
|
2
2
|
require 'mocha/setup'
|
3
|
-
require '
|
3
|
+
require 'faux'
|
4
4
|
require 'nexmo'
|
5
5
|
require 'oauth'
|
6
|
+
require 'json'
|
6
7
|
|
7
8
|
describe 'Nexmo::Client' do
|
8
9
|
before do
|
@@ -162,13 +163,21 @@ describe 'Nexmo::Client' do
|
|
162
163
|
end
|
163
164
|
|
164
165
|
describe 'when initialized with a different json implementation' do
|
165
|
-
|
166
|
-
|
166
|
+
it 'emits a deprecation warning' do
|
167
|
+
Kernel.expects(:warn).with(regexp_matches(/:json option is deprecated/))
|
168
|
+
|
169
|
+
@client = Nexmo::Client.new('key', 'secret', :json => stub)
|
167
170
|
end
|
168
171
|
|
169
172
|
describe 'send_message method' do
|
170
173
|
it 'encodes the request body using the alternative json implementation' do
|
171
|
-
|
174
|
+
Kernel.stubs(:warn)
|
175
|
+
|
176
|
+
@json = faux(JSON)
|
177
|
+
|
178
|
+
@json.expects(:dump).with(instance_of(Hash))
|
179
|
+
|
180
|
+
@client = Nexmo::Client.new('key', 'secret', :json => @json)
|
172
181
|
|
173
182
|
@client.http.stubs(:post)
|
174
183
|
|
@@ -176,6 +185,20 @@ describe 'Nexmo::Client' do
|
|
176
185
|
end
|
177
186
|
end
|
178
187
|
end
|
188
|
+
|
189
|
+
describe 'when initialized with a block' do
|
190
|
+
it 'calls the block for each response and returns the return value of the block' do
|
191
|
+
@client = Nexmo::Client.new('key', 'secret') do |response|
|
192
|
+
response.must_be_instance_of(Nexmo::Response)
|
193
|
+
|
194
|
+
:return_value
|
195
|
+
end
|
196
|
+
|
197
|
+
@client.http.stubs(:get).returns(stub)
|
198
|
+
|
199
|
+
@client.get_balance.must_equal(:return_value)
|
200
|
+
end
|
201
|
+
end
|
179
202
|
end
|
180
203
|
|
181
204
|
describe 'Nexmo::Response' do
|
@@ -228,14 +251,26 @@ describe 'Nexmo::Response' do
|
|
228
251
|
end
|
229
252
|
end
|
230
253
|
|
254
|
+
describe 'object equals method' do
|
255
|
+
it 'sets the object to be returned by the object method' do
|
256
|
+
@object = stub
|
257
|
+
|
258
|
+
@response.object = @object
|
259
|
+
|
260
|
+
@response.object.must_equal(@object)
|
261
|
+
end
|
262
|
+
end
|
263
|
+
|
231
264
|
describe 'when initialized with a different json implementation' do
|
232
265
|
before do
|
233
|
-
@
|
266
|
+
@json = faux(JSON)
|
267
|
+
|
268
|
+
@response = Nexmo::Response.new(@http_response, :json => @json)
|
234
269
|
end
|
235
270
|
|
236
271
|
describe 'object method' do
|
237
272
|
it 'decodes the response body using the alternative json implementation' do
|
238
|
-
|
273
|
+
@json.expects(:parse).with('{"value":0.0}')
|
239
274
|
|
240
275
|
@http_response.stubs(:body).returns('{"value":0.0}')
|
241
276
|
|
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: 1.
|
4
|
+
version: 1.2.0
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2013-02
|
12
|
+
date: 2013-09-02 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: rake
|
@@ -44,13 +44,13 @@ dependencies:
|
|
44
44
|
- !ruby/object:Gem::Version
|
45
45
|
version: 0.13.2
|
46
46
|
- !ruby/object:Gem::Dependency
|
47
|
-
name:
|
47
|
+
name: oauth
|
48
48
|
requirement: !ruby/object:Gem::Requirement
|
49
49
|
none: false
|
50
50
|
requirements:
|
51
51
|
- - ~>
|
52
52
|
- !ruby/object:Gem::Version
|
53
|
-
version:
|
53
|
+
version: 0.4.7
|
54
54
|
type: :development
|
55
55
|
prerelease: false
|
56
56
|
version_requirements: !ruby/object:Gem::Requirement
|
@@ -58,15 +58,15 @@ dependencies:
|
|
58
58
|
requirements:
|
59
59
|
- - ~>
|
60
60
|
- !ruby/object:Gem::Version
|
61
|
-
version:
|
61
|
+
version: 0.4.7
|
62
62
|
- !ruby/object:Gem::Dependency
|
63
|
-
name:
|
63
|
+
name: faux
|
64
64
|
requirement: !ruby/object:Gem::Requirement
|
65
65
|
none: false
|
66
66
|
requirements:
|
67
67
|
- - ~>
|
68
68
|
- !ruby/object:Gem::Version
|
69
|
-
version:
|
69
|
+
version: 1.1.0
|
70
70
|
type: :development
|
71
71
|
prerelease: false
|
72
72
|
version_requirements: !ruby/object:Gem::Requirement
|
@@ -74,7 +74,7 @@ dependencies:
|
|
74
74
|
requirements:
|
75
75
|
- - ~>
|
76
76
|
- !ruby/object:Gem::Version
|
77
|
-
version:
|
77
|
+
version: 1.1.0
|
78
78
|
description: A Ruby wrapper for the Nexmo API
|
79
79
|
email:
|
80
80
|
- mail@timcraft.com
|
@@ -106,8 +106,9 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
106
106
|
version: '0'
|
107
107
|
requirements: []
|
108
108
|
rubyforge_project:
|
109
|
-
rubygems_version: 1.8.
|
109
|
+
rubygems_version: 1.8.23
|
110
110
|
signing_key:
|
111
111
|
specification_version: 3
|
112
112
|
summary: See description
|
113
113
|
test_files: []
|
114
|
+
has_rdoc:
|