api_client 0.5.9 → 0.5.11

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 43c461e0ff353c1755880974f8704c1bee7176b0
4
- data.tar.gz: f271d02470638507b7e5ddcd1b3e1c537d6d19fc
3
+ metadata.gz: fa72f20faca901deb66fb6f1b73599829a0ef633
4
+ data.tar.gz: 38f72c8e3f27ec6c708bba8aa6cc22a2729f0e40
5
5
  SHA512:
6
- metadata.gz: 3dc40c025d6ebfd1e6e7e35be9b36f4a57feb5bbfc8c0c491bc2e73094964d881136cc79bf42dac693a02916fb4e057081bb5618ad490fe1421e193342cccac7
7
- data.tar.gz: f5b8195b7f425819af8662333a62534c62251fa023c371499530cd90517cdee74b5b1e178321d1ad66411df5565c4ff446db83d81a727bf0edace6c0baf96d82
6
+ metadata.gz: dc9414f6a69354c668012ce321773f83d45e845cf109dbe0a3e4b77146ba986bac7b866ba13cd187dc4c3bac3b05d4c4f6dd8a2939562cf31a4a93f1ca13f6de
7
+ data.tar.gz: e4195081871e961a05ec586042de5b9aad01c0e92143a5abc4b5c5298e8842a2d8759976c96d46c53a21ecebbda92c47031203837b03c7a90ccf7bf36118d532
data/CHANGELOG.md CHANGED
@@ -1,3 +1,11 @@
1
+ # 0.5.11
2
+
3
+ * fix handling errors
4
+
5
+ # 0.5.10
6
+
7
+ * add TooManyRequests error
8
+
1
9
  # 0.5.9
2
10
 
3
11
  * fix compatibility with ruby 1.8.x
@@ -83,26 +83,28 @@ module ApiClient
83
83
  end
84
84
 
85
85
  def handle_response(request, response)
86
- raise ApiClient::Errors::ConnectionFailed.new(request, response) unless response
86
+ raise ApiClient::Errors::ConnectionFailed.new(nil, request, response) unless response
87
87
  case response.status
88
88
  when 401
89
- raise ApiClient::Errors::Unauthorized.new(request, response)
89
+ raise ApiClient::Errors::Unauthorized.new(nil, request, response)
90
90
  when 403
91
- raise ApiClient::Errors::Forbidden.new(request, response)
91
+ raise ApiClient::Errors::Forbidden.new(nil, request, response)
92
92
  when 404
93
- raise ApiClient::Errors::NotFound.new(request, response)
93
+ raise ApiClient::Errors::NotFound.new(nil, request, response)
94
94
  when 400
95
- raise ApiClient::Errors::BadRequest.new(request, response)
95
+ raise ApiClient::Errors::BadRequest.new(nil, request, response)
96
96
  when 406
97
- raise ApiClient::Errors::Unsupported.new(request, response)
97
+ raise ApiClient::Errors::Unsupported.new(nil, request, response)
98
98
  when 409
99
- raise ApiClient::Errors::Conflict.new(request, response)
99
+ raise ApiClient::Errors::Conflict.new(nil, request, response)
100
100
  when 422
101
101
  raise ApiClient::Errors::UnprocessableEntity.new(response.body, request, response)
102
+ when 429
103
+ raise ApiClient::Errors::TooManyRequests.new(response.body, request, response)
102
104
  when 300..399
103
105
  raise ApiClient::Errors::Redirect.new(response['Location'], request, response)
104
106
  when 500..599
105
- raise ApiClient::Errors::ServerError.new(request, response)
107
+ raise ApiClient::Errors::ServerError.new(nil, request, response)
106
108
  else
107
109
  response
108
110
  end
@@ -22,6 +22,7 @@ module ApiClient
22
22
  class Conflict < ApiClientError; end
23
23
  class ServerError < ApiClientError; end
24
24
  class UnprocessableEntity < ApiClientError; end
25
+ class TooManyRequests < ApiClientError; end
25
26
  end
26
27
 
27
28
  end
@@ -1,3 +1,3 @@
1
1
  module ApiClient
2
- VERSION = "0.5.9"
2
+ VERSION = "0.5.11"
3
3
  end
@@ -89,71 +89,79 @@ describe ApiClient::Connection::Basic do
89
89
  it "raises an ApiClient::Errors::ConnectionFailed if there is no response" do
90
90
  lambda {
91
91
  @instance.send :handle_response, request, nil
92
- }.should raise_error(ApiClient::Errors::ConnectionFailed)
92
+ }.should raise_error(ApiClient::Errors::ConnectionFailed, "ApiClient::Errors::ConnectionFailed")
93
93
  end
94
94
 
95
95
  it "raises an ApiClient::Errors::Unauthorized if status is 401" do
96
96
  @response.env[:status] = 401
97
97
  lambda {
98
98
  @instance.send :handle_response, request, @response
99
- }.should raise_error(ApiClient::Errors::Unauthorized)
99
+ }.should raise_error(ApiClient::Errors::Unauthorized, "ApiClient::Errors::Unauthorized")
100
100
  end
101
101
 
102
102
  it "raises an ApiClient::Errors::Forbidden if status is 403" do
103
103
  @response.env[:status] = 403
104
104
  lambda {
105
105
  @instance.send :handle_response, request, @response
106
- }.should raise_error(ApiClient::Errors::Forbidden)
106
+ }.should raise_error(ApiClient::Errors::Forbidden, "ApiClient::Errors::Forbidden")
107
107
  end
108
108
 
109
109
  it "raises an ApiClient::Errors::NotFound if status is 404" do
110
110
  @response.env[:status] = 404
111
111
  lambda {
112
112
  @instance.send :handle_response, request, @response
113
- }.should raise_error(ApiClient::Errors::NotFound)
113
+ }.should raise_error(ApiClient::Errors::NotFound, "ApiClient::Errors::NotFound")
114
114
  end
115
115
 
116
116
  it "raises an ApiClient::Errors::BadRequest if status is 400" do
117
117
  @response.env[:status] = 400
118
118
  lambda {
119
119
  @instance.send :handle_response, request, @response
120
- }.should raise_error(ApiClient::Errors::BadRequest)
120
+ }.should raise_error(ApiClient::Errors::BadRequest, "ApiClient::Errors::BadRequest")
121
121
  end
122
122
 
123
123
  it "raises an ApiClient::Errors::Unsupported if status is 406" do
124
124
  @response.env[:status] = 406
125
125
  lambda {
126
126
  @instance.send :handle_response, request, @response
127
- }.should raise_error(ApiClient::Errors::Unsupported)
127
+ }.should raise_error(ApiClient::Errors::Unsupported, "ApiClient::Errors::Unsupported")
128
128
  end
129
129
 
130
130
  it "raises an ApiClient::Errors::Conflict if status is 409" do
131
131
  @response.env[:status] = 409
132
132
  lambda {
133
133
  @instance.send :handle_response, request, @response
134
- }.should raise_error(ApiClient::Errors::Conflict)
134
+ }.should raise_error(ApiClient::Errors::Conflict, "ApiClient::Errors::Conflict")
135
135
  end
136
136
 
137
137
  it "raises an ApiClient::Errors::Unsupported if status is 422" do
138
138
  @response.env[:status] = 422
139
139
  lambda {
140
140
  @instance.send :handle_response, request, @response
141
- }.should raise_error(ApiClient::Errors::UnprocessableEntity)
141
+ }.should raise_error(ApiClient::Errors::UnprocessableEntity, @response.body)
142
+ end
143
+
144
+ it "raises an ApiClient::Errors::TooManyRequests if status is 429" do
145
+ @response.env[:status] = 429
146
+ lambda {
147
+ @instance.send :handle_response, request, @response
148
+ }.should raise_error(ApiClient::Errors::TooManyRequests, @response.body)
142
149
  end
143
150
 
144
151
  it "raises an ApiClient::Errors::Unsupported if status is 300..399" do
152
+ location = "https://google.com"
145
153
  @response.env[:status] = 302
146
- @response.env[:response_headers] = { 'Location' => "https://google.com" }
154
+ @response.env[:response_headers] = { 'Location' => location }
147
155
  lambda {
148
156
  @instance.send :handle_response, request, @response
149
- }.should raise_error(ApiClient::Errors::Redirect)
157
+ }.should raise_error(ApiClient::Errors::Redirect, location)
150
158
  end
151
159
 
152
160
  it "raises an ApiClient::Errors::ServerError if status is 500..599" do
153
161
  @response.env[:status] = 502
154
162
  lambda {
155
163
  @instance.send :handle_response, request, @response
156
- }.should raise_error(ApiClient::Errors::ServerError)
164
+ }.should raise_error(ApiClient::Errors::ServerError, "ApiClient::Errors::ServerError")
157
165
  end
158
166
 
159
167
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: api_client
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.5.9
4
+ version: 0.5.11
5
5
  platform: ruby
6
6
  authors:
7
7
  - Marcin Bunsch
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-02-18 00:00:00.000000000 Z
11
+ date: 2015-05-06 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: yajl-ruby