nexmo 0.2.1 → 0.2.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (4) hide show
  1. data/lib/nexmo.rb +1 -1
  2. data/nexmo.gemspec +1 -1
  3. data/spec/nexmo_spec.rb +33 -10
  4. metadata +6 -6
data/lib/nexmo.rb CHANGED
@@ -27,7 +27,7 @@ module Nexmo
27
27
  if status == 0
28
28
  Success.new(object['message-id'])
29
29
  else
30
- Failure.new(Error.new(object['error-text']))
30
+ Failure.new(Error.new("#{object['error-text']} (status=#{status})"))
31
31
  end
32
32
  end
33
33
 
data/nexmo.gemspec CHANGED
@@ -1,6 +1,6 @@
1
1
  Gem::Specification.new do |s|
2
2
  s.name = 'nexmo'
3
- s.version = '0.2.1'
3
+ s.version = '0.2.2'
4
4
  s.platform = Gem::Platform::RUBY
5
5
  s.authors = ['Tim Craft']
6
6
  s.email = ['mail@timcraft.com']
data/spec/nexmo_spec.rb CHANGED
@@ -8,27 +8,50 @@ describe Nexmo::Client do
8
8
  @client = Nexmo::Client.new('key', 'secret')
9
9
  end
10
10
 
11
- it 'uses ssl by default' do
12
- assert @client.http.use_ssl?
11
+ describe 'http method' do
12
+ it 'should return a Net::HTTP object that uses SSL' do
13
+ @client.http.must_be_instance_of(Net::HTTP)
14
+ @client.http.use_ssl?.must_equal(true)
15
+ end
13
16
  end
14
17
 
15
- it 'allows access to headers' do
16
- @client.headers.must_be_kind_of(Hash)
18
+ describe 'headers method' do
19
+ it 'should return a hash' do
20
+ @client.headers.must_be_kind_of(Hash)
21
+ end
17
22
  end
18
23
 
19
- describe '#send_message' do
20
- it 'makes the correct http call' do
24
+ describe 'send_message method' do
25
+ before do
26
+ @headers = {'Content-Type' => 'application/x-www-form-urlencoded'}
27
+ end
28
+
29
+ it 'should make the correct http call return a successful response if the first message status equals 0' do
21
30
  http_response = stub(:body => '{"messages":[{"status":0,"message-id":"id"}]}')
22
31
 
23
32
  data = 'from=ruby&to=number&text=Hey%21&username=key&password=secret'
24
33
 
25
- headers = {'Content-Type' => 'application/x-www-form-urlencoded'}
26
-
27
- @client.http.expects(:post).with('/sms/json', data, headers).returns(http_response)
34
+ @client.http.expects(:post).with('/sms/json', data, @headers).returns(http_response)
28
35
 
29
36
  response = @client.send_message({from: 'ruby', to: 'number', text: 'Hey!'})
30
37
 
31
- assert response.success?
38
+ response.success?.must_equal(true)
39
+ response.failure?.must_equal(false)
40
+ response.message_id.must_equal('id')
41
+ end
42
+
43
+ it 'should return a failure response if the first message status does not equal 0' do
44
+ http_response = stub(:body => '{"messages":[{"status":2,"error-text":"Missing from param"}]}')
45
+
46
+ data = 'to=number&text=Hey%21&username=key&password=secret'
47
+
48
+ @client.http.expects(:post).with('/sms/json', data, @headers).returns(http_response)
49
+
50
+ response = @client.send_message({to: 'number', text: 'Hey!'})
51
+
52
+ response.success?.must_equal(false)
53
+ response.failure?.must_equal(true)
54
+ response.error.to_s.must_equal('Missing from param (status=2)')
32
55
  end
33
56
  end
34
57
  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: 0.2.1
4
+ version: 0.2.2
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,11 +9,11 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2011-11-25 00:00:00.000000000Z
12
+ date: 2012-01-21 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: json
16
- requirement: &11028540 !ruby/object:Gem::Requirement
16
+ requirement: &3707430 !ruby/object:Gem::Requirement
17
17
  none: false
18
18
  requirements:
19
19
  - - ~>
@@ -21,10 +21,10 @@ dependencies:
21
21
  version: '1.5'
22
22
  type: :runtime
23
23
  prerelease: false
24
- version_requirements: *11028540
24
+ version_requirements: *3707430
25
25
  - !ruby/object:Gem::Dependency
26
26
  name: mocha
27
- requirement: &11027930 !ruby/object:Gem::Requirement
27
+ requirement: &3707100 !ruby/object:Gem::Requirement
28
28
  none: false
29
29
  requirements:
30
30
  - - ! '>='
@@ -32,7 +32,7 @@ dependencies:
32
32
  version: '0'
33
33
  type: :development
34
34
  prerelease: false
35
- version_requirements: *11027930
35
+ version_requirements: *3707100
36
36
  description: A simple wrapper for the Nexmo API
37
37
  email:
38
38
  - mail@timcraft.com