api-client 0.5.0 → 0.6.0

Sign up to get free protection for your applications and to get access to all the features.
data/README.md CHANGED
@@ -1,4 +1,4 @@
1
- # ApiClient [![Build Status](https://secure.travis-ci.org/plribeiro3000/api_client.png)](http://travis-ci.org/plribeiro3000/api_client)
1
+ # ApiClient [![Build Status](https://secure.travis-ci.org/plribeiro3000/api-client.png)](http://travis-ci.org/plribeiro3000/api-client)
2
2
 
3
3
  Client to make Api calls
4
4
 
data/lib/api-client.rb CHANGED
@@ -26,6 +26,7 @@ module ApiClient
26
26
 
27
27
  def self.raise_exception(code)
28
28
  case code
29
+ when '400' then raise ApiClient::Exceptions::BadRequest
29
30
  when '401' then raise ApiClient::Exceptions::Unauthorized
30
31
  when '403' then raise ApiClient::Exceptions::Forbidden
31
32
  when '404' then raise ApiClient::Exceptions::NotFound
@@ -7,4 +7,5 @@ module ApiClient::Exceptions
7
7
  autoload :BadGateway, 'api-client/exceptions/bad_gateway'
8
8
  autoload :ServiceUnavailable, 'api-client/exceptions/service_unavailable'
9
9
  autoload :ConnectionRefused, 'api-client/exceptions/connection_refused'
10
+ autoload :BadRequest, 'api-client/exceptions/bad_request'
10
11
  end
@@ -0,0 +1,5 @@
1
+ class ApiClient::Exceptions::BadRequest < ApiClient::Exceptions::Generic
2
+ def self.initialize
3
+ super("Bad Request!")
4
+ end
5
+ end
@@ -1,3 +1,3 @@
1
1
  module ApiClient
2
- VERSION = "0.5.0"
2
+ VERSION = "0.6.0"
3
3
  end
@@ -12,6 +12,16 @@ describe ApiClient do
12
12
  end
13
13
  end
14
14
 
15
+ context "when response code is 400" do
16
+ before :each do
17
+ FakeWeb.register_uri(:get, "http://api.example.com/user/5", :status => "400")
18
+ end
19
+
20
+ it "should return a BadRequest exception" do
21
+ lambda { ApiClient.get('http://api.example.com/user/5') }.should raise_error(ApiClient::Exceptions::BadRequest)
22
+ end
23
+ end
24
+
15
25
  context "when response code is 401" do
16
26
  before :each do
17
27
  FakeWeb.register_uri(:get, "http://api.example.com/user/5", :status => "401")
@@ -94,6 +104,16 @@ describe ApiClient do
94
104
  end
95
105
  end
96
106
 
107
+ context "when response code is 400" do
108
+ before :each do
109
+ FakeWeb.register_uri(:post, "http://api.example.com/user/5", :status => "400")
110
+ end
111
+
112
+ it "should return a BadRequest exception" do
113
+ lambda { ApiClient.post('http://api.example.com/user/5', {}) }.should raise_error(ApiClient::Exceptions::BadRequest)
114
+ end
115
+ end
116
+
97
117
  context "when response code is 401" do
98
118
  before :each do
99
119
  FakeWeb.register_uri(:post, "http://api.example.com/user/5", :status => "401")
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: api-client
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.5.0
4
+ version: 0.6.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: 2012-06-01 00:00:00.000000000 Z
12
+ date: 2012-06-04 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rake
@@ -77,6 +77,7 @@ files:
77
77
  - lib/api-client.rb
78
78
  - lib/api-client/exceptions.rb
79
79
  - lib/api-client/exceptions/bad_gateway.rb
80
+ - lib/api-client/exceptions/bad_request.rb
80
81
  - lib/api-client/exceptions/connection_refused.rb
81
82
  - lib/api-client/exceptions/forbidden.rb
82
83
  - lib/api-client/exceptions/generic.rb
@@ -99,18 +100,12 @@ required_ruby_version: !ruby/object:Gem::Requirement
99
100
  - - ! '>='
100
101
  - !ruby/object:Gem::Version
101
102
  version: '0'
102
- segments:
103
- - 0
104
- hash: 3031241521538613176
105
103
  required_rubygems_version: !ruby/object:Gem::Requirement
106
104
  none: false
107
105
  requirements:
108
106
  - - ! '>='
109
107
  - !ruby/object:Gem::Version
110
108
  version: '0'
111
- segments:
112
- - 0
113
- hash: 3031241521538613176
114
109
  requirements: []
115
110
  rubyforge_project:
116
111
  rubygems_version: 1.8.24