api-client 1.9.0 → 1.9.1

Sign up to get free protection for your applications and to get access to all the features.
data/CHANGELOG.md CHANGED
@@ -1,5 +1,9 @@
1
1
  # CHANGELOG
2
2
 
3
+ ## v1.9.1
4
+
5
+ * Fix for Net::Http on NotFound Exception
6
+
3
7
  ## v1.9.0
4
8
 
5
9
  * Added Requested Url to NotFound Exception message
@@ -108,7 +108,7 @@ module ApiClient
108
108
  protected
109
109
 
110
110
  def self.method_missing(method, *args)
111
- @response = Parser.response(Dispatcher.send(method, *args))
111
+ @response = Parser.response(Dispatcher.send(method, *args), *args[0])
112
112
  case true
113
113
  when @response.instance_of?(Array) then return @response.map { |a| new(a.merge(:response => @response)) }
114
114
  when @response.key?(remote_object) then return new(@response[remote_object].merge(:response => @response))
@@ -7,4 +7,4 @@ class ApiClient::Exceptions::NotFound < ApiClient::Exceptions::Generic
7
7
  def self.initialize(url)
8
8
  super("The requested url (#{url}) could not be found!")
9
9
  end
10
- end
10
+ end
@@ -6,8 +6,8 @@ module ApiClient::Parser
6
6
  #
7
7
  # @param [HTTP] response HTTP object for the request.
8
8
  # @return [Hash] the body parsed.
9
- def self.response(response)
10
- raise_exception(response)
9
+ def self.response(response, url)
10
+ raise_exception(response, url)
11
11
  begin
12
12
  object = ::JSON.parse(response.body)
13
13
  rescue ::JSON::ParserError, TypeError
@@ -18,11 +18,11 @@ module ApiClient::Parser
18
18
 
19
19
  protected
20
20
 
21
- def self.raise_exception(response)
21
+ def self.raise_exception(response, url)
22
22
  case response.code.to_i
23
23
  when 401 then raise ApiClient::Exceptions::Unauthorized
24
24
  when 403 then raise ApiClient::Exceptions::Forbidden
25
- when 404 then raise ApiClient::Exceptions::NotFound.new(response.request.url)
25
+ when 404 then raise ApiClient::Exceptions::NotFound.new(url)
26
26
  when 500 then raise ApiClient::Exceptions::InternalServerError
27
27
  when 502 then raise ApiClient::Exceptions::BadGateway
28
28
  when 503 then raise ApiClient::Exceptions::ServiceUnavailable
@@ -1,5 +1,5 @@
1
1
  # High Level Namespace of the library ApiClient.
2
2
  module ApiClient
3
3
  # Version of the library.
4
- VERSION = "1.9.0"
4
+ VERSION = "1.9.1"
5
5
  end
@@ -9,7 +9,7 @@ describe ApiClient::Parser do
9
9
  end
10
10
 
11
11
  it "should return the response code and the body parsed" do
12
- ApiClient::Parser.response(@response).should == { "base" => { "a" => "b" } }
12
+ ApiClient::Parser.response(@response, 'http://api.example.com/user/5').should == { "base" => { "a" => "b" } }
13
13
  end
14
14
  end
15
15
 
@@ -20,7 +20,7 @@ describe ApiClient::Parser do
20
20
  end
21
21
 
22
22
  it "should return the response code and an empty hash" do
23
- ApiClient::Parser.response(@response).should == {}
23
+ ApiClient::Parser.response(@response, 'http://api.example.com/user/5').should == {}
24
24
  end
25
25
  end
26
26
 
@@ -32,7 +32,7 @@ describe ApiClient::Parser do
32
32
  end
33
33
 
34
34
  it "should return a Unauthorized exception" do
35
- lambda { ApiClient::Parser.response(@response) }.should raise_error(ApiClient::Exceptions::Unauthorized)
35
+ lambda { ApiClient::Parser.response(@response, 'http://api.example.com/user/5') }.should raise_error(ApiClient::Exceptions::Unauthorized)
36
36
  end
37
37
  end
38
38
 
@@ -43,7 +43,7 @@ describe ApiClient::Parser do
43
43
  end
44
44
 
45
45
  it "should return a Forbidden exception" do
46
- lambda { ApiClient::Parser.response(@response) }.should raise_error(ApiClient::Exceptions::Forbidden)
46
+ lambda { ApiClient::Parser.response(@response, 'http://api.example.com/user/5') }.should raise_error(ApiClient::Exceptions::Forbidden)
47
47
  end
48
48
  end
49
49
 
@@ -54,7 +54,7 @@ describe ApiClient::Parser do
54
54
  end
55
55
 
56
56
  it "should return a NotFound exception" do
57
- lambda { ApiClient::Parser.response(@response) }.should raise_error(ApiClient::Exceptions::NotFound, "http://api.example.com/user/5")
57
+ lambda { ApiClient::Parser.response(@response, 'http://api.example.com/user/5') }.should raise_error(ApiClient::Exceptions::NotFound, "http://api.example.com/user/5")
58
58
  end
59
59
  end
60
60
 
@@ -65,7 +65,7 @@ describe ApiClient::Parser do
65
65
  end
66
66
 
67
67
  it "should return a InternalServerError exception" do
68
- lambda { ApiClient::Parser.response(@response) }.should raise_error(ApiClient::Exceptions::InternalServerError)
68
+ lambda { ApiClient::Parser.response(@response, 'http://api.example.com/user/5') }.should raise_error(ApiClient::Exceptions::InternalServerError)
69
69
  end
70
70
  end
71
71
 
@@ -76,7 +76,7 @@ describe ApiClient::Parser do
76
76
  end
77
77
 
78
78
  it "should return a BadGateway exception" do
79
- lambda { ApiClient::Parser.response(@response) }.should raise_error(ApiClient::Exceptions::BadGateway)
79
+ lambda { ApiClient::Parser.response(@response, 'http://api.example.com/user/5') }.should raise_error(ApiClient::Exceptions::BadGateway)
80
80
  end
81
81
  end
82
82
 
@@ -87,7 +87,7 @@ describe ApiClient::Parser do
87
87
  end
88
88
 
89
89
  it "should return a ServiceUnavailable exception" do
90
- lambda { ApiClient::Parser.response(@response) }.should raise_error(ApiClient::Exceptions::ServiceUnavailable)
90
+ lambda { ApiClient::Parser.response(@response, 'http://api.example.com/user/5') }.should raise_error(ApiClient::Exceptions::ServiceUnavailable)
91
91
  end
92
92
  end
93
93
  end
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: 1.9.0
4
+ version: 1.9.1
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -167,7 +167,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
167
167
  version: '0'
168
168
  segments:
169
169
  - 0
170
- hash: 612713952861449012
170
+ hash: -1190097789751108706
171
171
  required_rubygems_version: !ruby/object:Gem::Requirement
172
172
  none: false
173
173
  requirements:
@@ -176,7 +176,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
176
176
  version: '0'
177
177
  segments:
178
178
  - 0
179
- hash: 612713952861449012
179
+ hash: -1190097789751108706
180
180
  requirements: []
181
181
  rubyforge_project:
182
182
  rubygems_version: 1.8.24