bookingsync-api 0.0.18 → 0.0.19

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: 1c4e6cd8678c43838cd16404afda232617573958
4
- data.tar.gz: 4bef59232d6e3937eb82633008fe4c659e58a5a8
3
+ metadata.gz: d3d23970ddeff09666633feb1b63444bdcbfcf0d
4
+ data.tar.gz: fe419d0219da0c64ef63646603eb485574b88c9a
5
5
  SHA512:
6
- metadata.gz: 1997f3fcebc513384f814f11971d263e7e502bcd109960ec430687f39203e1d79c1c7e21130a861dee06b29508d4e74340850408fe6d0636bd0e2f0ca927f4ba
7
- data.tar.gz: 78a07d18490c529546f4e43c03bf7092599a19838fa47482e524e5043105f3a33b3238718fc305339d159bd3ef97bdaf6e481ccafea377c621f3e87a3a8af456
6
+ metadata.gz: 3037d88848cf496cf6890bba67386110e518b6cbdc579e078c3280b2b6433befe36b099b0a09a727087eb7b660eee784a181e78688e0bf74f3d19bcad415c6fa
7
+ data.tar.gz: 0113e5eeccf400446ef71c0722cd6cf40e7b3385963d743c04f61eac6e94f7826eb57f7c16b950174fd05ee62e866ee9fce364a0127e556141a25efb5819a340
@@ -287,9 +287,9 @@ module BookingSync::API
287
287
  case response.status
288
288
  when 204; nil # destroy/cancel
289
289
  when 200..299; response
290
- when 401; raise Unauthorized.new
291
- when 404; raise NotFound.new
292
- when 422; raise UnprocessableEntity.new
290
+ when 401; raise Unauthorized.new(response)
291
+ when 404; raise NotFound.new(response)
292
+ when 422; raise UnprocessableEntity.new(response)
293
293
  else raise UnsupportedResponse.new(response)
294
294
  end
295
295
  end
@@ -1,11 +1,6 @@
1
1
  module BookingSync::API
2
2
  # Class for rescuing all BS API errors
3
- class Error < StandardError; end
4
- class Unauthorized < Error; end
5
- class UnprocessableEntity < Error; end
6
- class NotFound < Error; end
7
-
8
- class UnsupportedResponse < Error
3
+ class Error < StandardError
9
4
  attr_reader :status, :headers, :body
10
5
 
11
6
  def initialize(response)
@@ -14,11 +9,20 @@ module BookingSync::API
14
9
  @body = response.body
15
10
  end
16
11
 
17
- def message
18
- %Q{Received unsupported response from BookingSync API
12
+ def message(message = self.class)
13
+ %Q{#{message}
19
14
  HTTP status code : #{status}
20
15
  Headers : #{headers}
21
16
  Body : #{body}}
22
17
  end
23
18
  end
19
+
20
+ class Unauthorized < Error; end
21
+ class UnprocessableEntity < Error; end
22
+ class NotFound < Error; end
23
+ class UnsupportedResponse < Error
24
+ def message
25
+ super("Received unsupported response from BookingSync API")
26
+ end
27
+ end
24
28
  end
@@ -1,5 +1,5 @@
1
1
  module BookingSync
2
2
  module API
3
- VERSION = "0.0.18"
3
+ VERSION = "0.0.19"
4
4
  end
5
5
  end
@@ -35,10 +35,13 @@ describe BookingSync::API::Client do
35
35
 
36
36
  context "on 422 response" do
37
37
  it "raises UnprocessableEntity exception" do
38
- stub_post("resource", status: 422)
38
+ stub_post("resource", status: 422, body: { errors: { country_code:
39
+ ["is required"] } }.to_json)
39
40
  expect {
40
- client.post("resource", {key: :value})
41
- }.to raise_error(BookingSync::API::UnprocessableEntity)
41
+ client.post("resource", { key: :value })
42
+ }.to raise_error(BookingSync::API::UnprocessableEntity) { |error|
43
+ expect(error.message).to include '{"errors":{"country_code":["is required"]}}'
44
+ }
42
45
  end
43
46
  end
44
47
  end
@@ -134,13 +137,14 @@ describe BookingSync::API::Client do
134
137
  context "API returns unsupported status code outside 200..299 range" do
135
138
  it "raises UnsupportedResponse exception" do
136
139
  stub_get("resource", status: 405, body: "Whoops!",
137
- headers: {"content-type"=>"application/vnd.api+json"})
140
+ headers: { "content-type" => "application/vnd.api+json" })
138
141
  expect {
139
142
  client.get("resource")
140
143
  }.to raise_error(BookingSync::API::UnsupportedResponse) { |error|
141
144
  expect(error.status).to eql(405)
142
- expect(error.headers).to eq({"content-type"=>"application/vnd.api+json"})
145
+ expect(error.headers).to eq({ "content-type" => "application/vnd.api+json" })
143
146
  expect(error.body).to eq("Whoops!")
147
+ expect(error.message).to include("Received unsupported response from BookingSync API")
144
148
  }
145
149
  end
146
150
  end
@@ -0,0 +1,46 @@
1
+ require "spec_helper"
2
+
3
+ describe BookingSync::API::Error do
4
+ let(:client) { BookingSync::API::Client.new(test_access_token) }
5
+ before do
6
+ stub_get("resource", status: 422, body:
7
+ { errors: { name: ["can't be blank"] } }.to_json)
8
+ end
9
+ let(:request) { client.get("resource") }
10
+
11
+ describe "#status" do
12
+ it "returns HTTP status of the response" do
13
+ expect { request }.to raise_error(BookingSync::API::Error) { |exception|
14
+ expect(exception.status).to eq 422
15
+ }
16
+ end
17
+ end
18
+
19
+ describe "#body" do
20
+ it "returns response body" do
21
+ expect { request }.to raise_error(BookingSync::API::Error) { |exception|
22
+ expect(exception.body).to eq '{"errors":{"name":["can\'t be blank"]}}'
23
+ }
24
+ end
25
+ end
26
+
27
+ describe "#headers" do
28
+ it "returns response headers" do
29
+ expect { request }.to raise_error(BookingSync::API::Error) { |exception|
30
+ expect(exception.headers).to eq({"content-type" =>
31
+ "application/vnd.api+json"})
32
+ }
33
+ end
34
+ end
35
+
36
+ describe "#message" do
37
+ it "returns standard exception message" do
38
+ expect { request }.to raise_error(BookingSync::API::Error) { |exception|
39
+ expect(exception.message).to eq(%Q{BookingSync::API::UnprocessableEntity
40
+ HTTP status code : 422
41
+ Headers : {"content-type"=>"application/vnd.api+json"}
42
+ Body : {"errors":{"name":["can't be blank"]}}})
43
+ }
44
+ end
45
+ end
46
+ end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: bookingsync-api
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.18
4
+ version: 0.0.19
5
5
  platform: ruby
6
6
  authors:
7
7
  - Sébastien Grosjean
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-06-23 00:00:00.000000000 Z
11
+ date: 2014-07-25 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: faraday
@@ -148,6 +148,7 @@ files:
148
148
  - spec/bookingsync/api/client/seasons_spec.rb
149
149
  - spec/bookingsync/api/client/special_offers_spec.rb
150
150
  - spec/bookingsync/api/client_spec.rb
151
+ - spec/bookingsync/api/error_spec.rb
151
152
  - spec/bookingsync/api/relation_spec.rb
152
153
  - spec/bookingsync/api/resource_spec.rb
153
154
  - spec/bookingsync/api/response_spec.rb
@@ -271,6 +272,7 @@ test_files:
271
272
  - spec/bookingsync/api/client/seasons_spec.rb
272
273
  - spec/bookingsync/api/client/special_offers_spec.rb
273
274
  - spec/bookingsync/api/client_spec.rb
275
+ - spec/bookingsync/api/error_spec.rb
274
276
  - spec/bookingsync/api/relation_spec.rb
275
277
  - spec/bookingsync/api/resource_spec.rb
276
278
  - spec/bookingsync/api/response_spec.rb