cq-spree-api-client 0.0.5

Sign up to get free protection for your applications and to get access to all the features.
Files changed (71) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +19 -0
  3. data/.rspec +2 -0
  4. data/.ruby-version +1 -0
  5. data/.travis.yml +11 -0
  6. data/CONTRIBUTING.md +8 -0
  7. data/Gemfile +3 -0
  8. data/LICENSE +22 -0
  9. data/README.md +61 -0
  10. data/Rakefile +7 -0
  11. data/fixtures/cassette_library/Spree_API_Client_Addresses/address/should_load_address.yml +59 -0
  12. data/fixtures/cassette_library/Spree_API_Client_Addresses/update_address/should_update_address.yml +61 -0
  13. data/fixtures/cassette_library/Spree_API_Client_Shipments/shipment_ready/should_set_a_shipment_to_ready.yml +55 -0
  14. data/fixtures/cassette_library/Spree_API_Client_Shipments/shipment_ready/should_set_a_shipment_to_ship.yml +56 -0
  15. data/fixtures/cassette_library/countries.yml +62 -0
  16. data/fixtures/cassette_library/orders.yml +55 -0
  17. data/fixtures/cassette_library/payments.yml +48 -0
  18. data/fixtures/cassette_library/products.yml +241 -0
  19. data/fixtures/cassette_library/properties.yml +56 -0
  20. data/fixtures/cassette_library/request.yml +241 -0
  21. data/fixtures/cassette_library/return_authorizations.yml +48 -0
  22. data/fixtures/cassette_library/stock_items.yml +1950 -0
  23. data/fixtures/cassette_library/taxonomies.yml +62 -0
  24. data/fixtures/cassette_library/taxons.yml +60 -0
  25. data/fixtures/cassette_library/variants.yml +58 -0
  26. data/fixtures/cassette_library/zones.yml +49 -0
  27. data/lib/spree-api-client.rb +65 -0
  28. data/lib/spree-api-client/addresses.rb +20 -0
  29. data/lib/spree-api-client/adjustments.rb +23 -0
  30. data/lib/spree-api-client/checkouts.rb +27 -0
  31. data/lib/spree-api-client/connection.rb +27 -0
  32. data/lib/spree-api-client/countries.rb +15 -0
  33. data/lib/spree-api-client/credit_cards.rb +20 -0
  34. data/lib/spree-api-client/error.rb +47 -0
  35. data/lib/spree-api-client/line_items.rb +19 -0
  36. data/lib/spree-api-client/option_types.rb +31 -0
  37. data/lib/spree-api-client/option_values.rb +31 -0
  38. data/lib/spree-api-client/orders.rb +56 -0
  39. data/lib/spree-api-client/payments.rb +44 -0
  40. data/lib/spree-api-client/products.rb +31 -0
  41. data/lib/spree-api-client/promotions.rb +15 -0
  42. data/lib/spree-api-client/properties.rb +31 -0
  43. data/lib/spree-api-client/request.rb +59 -0
  44. data/lib/spree-api-client/return_authorizations.rb +31 -0
  45. data/lib/spree-api-client/shipments.rb +15 -0
  46. data/lib/spree-api-client/stock_items.rb +31 -0
  47. data/lib/spree-api-client/stock_locations.rb +31 -0
  48. data/lib/spree-api-client/taxonomies.rb +31 -0
  49. data/lib/spree-api-client/taxons.rb +36 -0
  50. data/lib/spree-api-client/users.rb +31 -0
  51. data/lib/spree-api-client/variants.rb +31 -0
  52. data/lib/spree-api-client/version.rb +7 -0
  53. data/lib/spree-api-client/zones.rb +31 -0
  54. data/spec/addresses_spec.rb +21 -0
  55. data/spec/client_spec.rb +32 -0
  56. data/spec/countries_spec.rb +12 -0
  57. data/spec/orders_spec.rb +12 -0
  58. data/spec/payments_spec.rb +12 -0
  59. data/spec/products_spec.rb +12 -0
  60. data/spec/properties_spec.rb +12 -0
  61. data/spec/return_authorizations_spec.rb +12 -0
  62. data/spec/shipments_spec.rb +19 -0
  63. data/spec/spec_helper.rb +80 -0
  64. data/spec/stock_items_spec.rb +12 -0
  65. data/spec/support/vcr.rb +9 -0
  66. data/spec/taxonomies_spec.rb +12 -0
  67. data/spec/taxons_spec.rb +12 -0
  68. data/spec/variants_spec.rb +12 -0
  69. data/spec/zones_spec.rb +12 -0
  70. data/spree-api-client.gemspec +33 -0
  71. metadata +268 -0
@@ -0,0 +1,62 @@
1
+ ---
2
+ http_interactions:
3
+ - request:
4
+ method: get
5
+ uri: http://localhost:4000/store/api/taxonomies?locale=en-US&per_page=30
6
+ body:
7
+ encoding: US-ASCII
8
+ string: ''
9
+ headers:
10
+ User-Agent:
11
+ - Faraday v0.9.1
12
+ Accept:
13
+ - application/json
14
+ X-Spree-Token:
15
+ - b56019f04b61a50553ee323f5ab68c6b435871971e79c987
16
+ Accept-Encoding:
17
+ - gzip;q=1.0,deflate;q=0.6,identity;q=0.3
18
+ response:
19
+ status:
20
+ code: 200
21
+ message: 'OK '
22
+ headers:
23
+ X-Frame-Options:
24
+ - SAMEORIGIN
25
+ X-Xss-Protection:
26
+ - 1; mode=block
27
+ X-Content-Type-Options:
28
+ - nosniff
29
+ Content-Type:
30
+ - application/json; charset=utf-8
31
+ Etag:
32
+ - W/"d77fba7f7ff0964ee7fc0ed59a7af1dd"
33
+ Cache-Control:
34
+ - max-age=0, private, must-revalidate
35
+ X-Request-Id:
36
+ - db183f4f-4ff8-4ad1-89ad-e8ca3d835558
37
+ X-Runtime:
38
+ - '0.172052'
39
+ Server:
40
+ - WEBrick/1.3.1 (Ruby/2.2.2/2015-04-13)
41
+ Date:
42
+ - Wed, 08 Jul 2015 15:48:52 GMT
43
+ Content-Length:
44
+ - '1202'
45
+ Connection:
46
+ - Keep-Alive
47
+ Set-Cookie:
48
+ - guest_token=ImNKWFd1cVJwYW5LbDdzZ2ZPcUlQYVEi--8488b9fe70b8c8788da14f8d3d7967c875e824cf;
49
+ path=/; expires=Sun, 08 Jul 2035 15:48:52 -0000
50
+ body:
51
+ encoding: UTF-8
52
+ string: '{"count":2,"current_page":1,"pages":1,"taxonomies":[{"id":1,"name":"Categories","root":{"id":1,"name":"Categories","pretty_name":"Categories","permalink":"categories","parent_id":null,"taxonomy_id":1,"taxons":[{"id":3,"name":"Bags","pretty_name":"Categories
53
+ -\u003e Bags","permalink":"categories/bags","parent_id":1,"taxonomy_id":1},{"id":4,"name":"Mugs","pretty_name":"Categories
54
+ -\u003e Mugs","permalink":"categories/mugs","parent_id":1,"taxonomy_id":1},{"id":5,"name":"Clothing","pretty_name":"Categories
55
+ -\u003e Clothing","permalink":"categories/clothing","parent_id":1,"taxonomy_id":1}]}},{"id":2,"name":"Brand","root":{"id":2,"name":"Brand","pretty_name":"Brand","permalink":"brand","parent_id":null,"taxonomy_id":2,"taxons":[{"id":8,"name":"Ruby","pretty_name":"Brand
56
+ -\u003e Ruby","permalink":"brand/ruby","parent_id":2,"taxonomy_id":2},{"id":9,"name":"Apache","pretty_name":"Brand
57
+ -\u003e Apache","permalink":"brand/apache","parent_id":2,"taxonomy_id":2},{"id":10,"name":"Spree","pretty_name":"Brand
58
+ -\u003e Spree","permalink":"brand/spree","parent_id":2,"taxonomy_id":2},{"id":11,"name":"Rails","pretty_name":"Brand
59
+ -\u003e Rails","permalink":"brand/rails","parent_id":2,"taxonomy_id":2}]}}]}'
60
+ http_version:
61
+ recorded_at: Wed, 08 Jul 2015 15:48:52 GMT
62
+ recorded_with: VCR 2.9.3
@@ -0,0 +1,60 @@
1
+ ---
2
+ http_interactions:
3
+ - request:
4
+ method: get
5
+ uri: http://localhost:4000/store/api/taxonomies/1/taxons?locale=en-US&per_page=30
6
+ body:
7
+ encoding: US-ASCII
8
+ string: ''
9
+ headers:
10
+ User-Agent:
11
+ - Faraday v0.9.1
12
+ Accept:
13
+ - application/json
14
+ X-Spree-Token:
15
+ - b56019f04b61a50553ee323f5ab68c6b435871971e79c987
16
+ Accept-Encoding:
17
+ - gzip;q=1.0,deflate;q=0.6,identity;q=0.3
18
+ response:
19
+ status:
20
+ code: 200
21
+ message: 'OK '
22
+ headers:
23
+ X-Frame-Options:
24
+ - SAMEORIGIN
25
+ X-Xss-Protection:
26
+ - 1; mode=block
27
+ X-Content-Type-Options:
28
+ - nosniff
29
+ Content-Type:
30
+ - application/json; charset=utf-8
31
+ Etag:
32
+ - W/"bcc0eb61da4cbd983ff4d4659f6acff8"
33
+ Cache-Control:
34
+ - max-age=0, private, must-revalidate
35
+ X-Request-Id:
36
+ - 9be9be1b-e157-4102-b6a7-4ff9e580c6b3
37
+ X-Runtime:
38
+ - '0.114618'
39
+ Server:
40
+ - WEBrick/1.3.1 (Ruby/2.2.2/2015-04-13)
41
+ Date:
42
+ - Wed, 08 Jul 2015 15:53:11 GMT
43
+ Content-Length:
44
+ - '837'
45
+ Connection:
46
+ - Keep-Alive
47
+ Set-Cookie:
48
+ - guest_token=IlZJNUR1OXJrMlFFejJLazQwd0NxWVEi--595ea9ba2e4093912d061e9ce62870e553739d32;
49
+ path=/; expires=Sun, 08 Jul 2035 15:53:10 -0000
50
+ body:
51
+ encoding: UTF-8
52
+ string: '{"count":3,"total_count":3,"current_page":1,"per_page":"30","pages":1,"taxons":[{"taxons":[],"id":3,"name":"Bags","pretty_name":"Categories
53
+ -\u003e Bags","permalink":"categories/bags","parent_id":1,"taxonomy_id":1},{"taxons":[],"id":4,"name":"Mugs","pretty_name":"Categories
54
+ -\u003e Mugs","permalink":"categories/mugs","parent_id":1,"taxonomy_id":1},{"taxons":[{"taxons":[],"id":6,"name":"Shirts","pretty_name":"Categories
55
+ -\u003e Clothing -\u003e Shirts","permalink":"categories/clothing/shirts","parent_id":5,"taxonomy_id":1},{"taxons":[],"id":7,"name":"T-Shirts","pretty_name":"Categories
56
+ -\u003e Clothing -\u003e T-Shirts","permalink":"categories/clothing/t-shirts","parent_id":5,"taxonomy_id":1}],"id":5,"name":"Clothing","pretty_name":"Categories
57
+ -\u003e Clothing","permalink":"categories/clothing","parent_id":1,"taxonomy_id":1}]}'
58
+ http_version:
59
+ recorded_at: Wed, 08 Jul 2015 15:53:11 GMT
60
+ recorded_with: VCR 2.9.3
@@ -0,0 +1,58 @@
1
+ ---
2
+ http_interactions:
3
+ - request:
4
+ method: get
5
+ uri: http://localhost:4000/store/api/products/1/variants?locale=en-US&per_page=30
6
+ body:
7
+ encoding: US-ASCII
8
+ string: ''
9
+ headers:
10
+ User-Agent:
11
+ - Faraday v0.9.1
12
+ Accept:
13
+ - application/json
14
+ X-Spree-Token:
15
+ - b56019f04b61a50553ee323f5ab68c6b435871971e79c987
16
+ Accept-Encoding:
17
+ - gzip;q=1.0,deflate;q=0.6,identity;q=0.3
18
+ response:
19
+ status:
20
+ code: 200
21
+ message: 'OK '
22
+ headers:
23
+ X-Frame-Options:
24
+ - SAMEORIGIN
25
+ X-Xss-Protection:
26
+ - 1; mode=block
27
+ X-Content-Type-Options:
28
+ - nosniff
29
+ Content-Type:
30
+ - application/json; charset=utf-8
31
+ Etag:
32
+ - W/"65c4b631b5b31b1e55671aeafc996aac"
33
+ Cache-Control:
34
+ - max-age=0, private, must-revalidate
35
+ X-Request-Id:
36
+ - ced98e62-f925-425a-90bc-934e54501432
37
+ X-Runtime:
38
+ - '0.120245'
39
+ Server:
40
+ - WEBrick/1.3.1 (Ruby/2.2.2/2015-04-13)
41
+ Date:
42
+ - Wed, 08 Jul 2015 15:48:54 GMT
43
+ Content-Length:
44
+ - '1816'
45
+ Connection:
46
+ - Keep-Alive
47
+ Set-Cookie:
48
+ - guest_token=IkxweWVkUHh6enZUaWkwOC1yNExnclEi--13ffd38a679ba65089afc19c6d46c82cc93660aa;
49
+ path=/; expires=Sun, 08 Jul 2035 15:48:54 -0000
50
+ body:
51
+ encoding: UTF-8
52
+ string: '{"count":1,"total_count":1,"current_page":1,"pages":1,"variants":[{"id":1,"name":"Ruby
53
+ on Rails Tote","sku":"ROR-00011","price":"15.99","weight":"0.0","height":null,"width":null,"depth":null,"is_master":true,"slug":"ruby-on-rails-tote","description":"Recusandae
54
+ explicabo possimus est dignissimos. Natus earum ut deserunt corporis ipsa.
55
+ Sunt magni voluptate quia repudiandae.","track_inventory":true,"cost_price":"17.0","display_price":"$15.99","options_text":"","in_stock":true,"is_backorderable":false,"total_on_hand":10,"is_destroyed":false,"option_values":[],"images":[{"id":21,"position":1,"attachment_content_type":"image/jpeg","attachment_file_name":"ror_tote.jpeg","type":"Spree::Image","attachment_updated_at":"2015-07-08T15:40:40.606Z","attachment_width":360,"attachment_height":360,"alt":null,"viewable_type":"Spree::Variant","viewable_id":1,"mini_url":"/spree/products/21/mini/ror_tote.jpeg?1436370040","small_url":"/spree/products/21/small/ror_tote.jpeg?1436370040","product_url":"/spree/products/21/product/ror_tote.jpeg?1436370040","large_url":"/spree/products/21/large/ror_tote.jpeg?1436370040"},{"id":22,"position":2,"attachment_content_type":"image/jpeg","attachment_file_name":"ror_tote_back.jpeg","type":"Spree::Image","attachment_updated_at":"2015-07-08T15:40:40.868Z","attachment_width":360,"attachment_height":360,"alt":null,"viewable_type":"Spree::Variant","viewable_id":1,"mini_url":"/spree/products/22/mini/ror_tote_back.jpeg?1436370040","small_url":"/spree/products/22/small/ror_tote_back.jpeg?1436370040","product_url":"/spree/products/22/product/ror_tote_back.jpeg?1436370040","large_url":"/spree/products/22/large/ror_tote_back.jpeg?1436370040"}],"stock_items":[{"id":1,"count_on_hand":10,"stock_location_id":1,"backorderable":false,"available":true,"stock_location_name":"default"}]}]}'
56
+ http_version:
57
+ recorded_at: Wed, 08 Jul 2015 15:48:54 GMT
58
+ recorded_with: VCR 2.9.3
@@ -0,0 +1,49 @@
1
+ ---
2
+ http_interactions:
3
+ - request:
4
+ method: get
5
+ uri: http://localhost:4000/store/api/zones?locale=en-US&per_page=30
6
+ body:
7
+ encoding: US-ASCII
8
+ string: ''
9
+ headers:
10
+ Accept:
11
+ - application/json
12
+ X-Spree-Token:
13
+ - b56019f04b61a50553ee323f5ab68c6b435871971e79c987
14
+ Accept-Encoding:
15
+ - gzip;q=1.0,deflate;q=0.6,identity;q=0.3
16
+ User-Agent:
17
+ - Ruby
18
+ response:
19
+ status:
20
+ code: 200
21
+ message: ! 'OK '
22
+ headers:
23
+ Content-Type:
24
+ - application/json
25
+ X-Ua-Compatible:
26
+ - IE=Edge
27
+ Etag:
28
+ - ! '"c92d758de9ce28cbf25aff60593d11ae"'
29
+ Cache-Control:
30
+ - max-age=0, private, must-revalidate
31
+ X-Request-Id:
32
+ - 10ac41a5c0639706a64786e46caa8352
33
+ X-Runtime:
34
+ - '0.199412'
35
+ Content-Length:
36
+ - '293'
37
+ Server:
38
+ - WEBrick/1.3.1 (Ruby/1.9.3/2012-02-16)
39
+ Date:
40
+ - Fri, 07 Dec 2012 17:37:16 GMT
41
+ Connection:
42
+ - Keep-Alive
43
+ body:
44
+ encoding: US-ASCII
45
+ string: ! '{"count":2,"current_page":1,"pages":1,"zones":[{"zone":{"id":4,"name":"England","description":"","zone_members":[]}},{"zone":{"id":3,"name":"UK","description":"UK","zone_members":[{"zone_member":{"id":1017582645,"name":"United
46
+ Kingdom","zoneable_type":"Spree::Country","zoneable_id":213}}]}}]}'
47
+ http_version:
48
+ recorded_at: Fri, 07 Dec 2012 17:37:16 GMT
49
+ recorded_with: VCR 2.3.0
@@ -0,0 +1,65 @@
1
+ require "spree-api-client/version"
2
+
3
+ require 'faraday_middleware'
4
+ require 'spree-api-client/connection'
5
+ require 'spree-api-client/request'
6
+
7
+ require 'spree-api-client/users'
8
+ require 'spree-api-client/checkouts'
9
+ require 'spree-api-client/credit_cards'
10
+ require 'spree-api-client/adjustments'
11
+ require 'spree-api-client/products'
12
+ require 'spree-api-client/variants'
13
+ require 'spree-api-client/orders'
14
+ require 'spree-api-client/taxonomies'
15
+ require 'spree-api-client/addresses'
16
+ require 'spree-api-client/countries'
17
+ require 'spree-api-client/zones'
18
+ require 'spree-api-client/properties'
19
+ require 'spree-api-client/line_items'
20
+ require 'spree-api-client/stock_items'
21
+ require 'spree-api-client/stock_locations'
22
+ require 'spree-api-client/return_authorizations'
23
+ require 'spree-api-client/taxons'
24
+ require 'spree-api-client/payments'
25
+ require 'spree-api-client/shipments'
26
+ require 'spree-api-client/promotions'
27
+
28
+ module Spree
29
+ module API
30
+ class Client
31
+ include Spree::API::Client::Connection
32
+ include Spree::API::Client::Request
33
+
34
+ include Spree::API::Client::Users
35
+ include Spree::API::Client::Checkouts
36
+ include Spree::API::Client::Products
37
+ include Spree::API::Client::Variants
38
+ include Spree::API::Client::Orders
39
+ include Spree::API::Client::Taxonomies
40
+ include Spree::API::Client::Addresses
41
+ include Spree::API::Client::Countries
42
+ include Spree::API::Client::Zones
43
+ include Spree::API::Client::Properties
44
+ include Spree::API::Client::LineItems
45
+ include Spree::API::Client::StockLocations
46
+ include Spree::API::Client::StockItems
47
+ include Spree::API::Client::ReturnAuthorizations
48
+ include Spree::API::Client::Taxons
49
+ include Spree::API::Client::Payments
50
+ include Spree::API::Client::Shipments
51
+ include Spree::API::Client::CreditCards
52
+ include Spree::API::Client::Adjustments
53
+ include Spree::API::Client::Promotions
54
+ include Spree::API::Client::Checkouts
55
+
56
+ attr_accessor :api_endpoint, :api_token, :per_page, :locale
57
+ def initialize(api_endpoint, api_token, locale="en-US", options={})
58
+ @api_endpoint = api_endpoint
59
+ @api_token = api_token
60
+ @locale = locale
61
+ @per_page = options.fetch(:per_page, 30)
62
+ end
63
+ end
64
+ end
65
+ end
@@ -0,0 +1,20 @@
1
+ module Spree
2
+ module API
3
+ class Client
4
+ module Addresses
5
+ def address(order_number, id, options={})
6
+ get("orders/#{order_number}/addresses/#{id}", options)
7
+ end
8
+
9
+ # #get addresses by user
10
+ # def addresses(order_number, options={})
11
+ # get("orders/#{order_number}/addresses",options)["addresses"]
12
+ # end
13
+
14
+ def update_address(order_number, id, options={})
15
+ put("orders/#{order_number}/addresses/#{id}", options)
16
+ end
17
+ end
18
+ end
19
+ end
20
+ end
@@ -0,0 +1,23 @@
1
+ module Spree
2
+ module API
3
+ class Client
4
+ module Adjustments
5
+ def adjustment(id, options={})
6
+ get("adjustments/#{id}", options)
7
+ end
8
+
9
+ def adjustments(options={})
10
+ get('adjustments', options)
11
+ end
12
+
13
+ def create_adjustment(options={})
14
+ post("adjustments", options)
15
+ end
16
+
17
+ def update_adjustment(id, options={})
18
+ post("adjustments", options)
19
+ end
20
+ end
21
+ end
22
+ end
23
+ end
@@ -0,0 +1,27 @@
1
+ module Spree
2
+ module API
3
+ class Client
4
+ module Checkouts
5
+ def checkouts(options={})
6
+ get('checkouts', options)['checkouts']
7
+ end
8
+
9
+ def checkout(order_number, options={})
10
+ get("checkouts/#{order_number}", options)
11
+ end
12
+
13
+ def create_checkout(options={})
14
+ post("checkouts", options)
15
+ end
16
+
17
+ def update_checkout(order_number, options={})
18
+ put("checkouts/#{order_number}", options)
19
+ end
20
+
21
+ def next(order_number)
22
+ put("checkouts/#{order_number}/next")
23
+ end
24
+ end
25
+ end
26
+ end
27
+ end
@@ -0,0 +1,27 @@
1
+ module Spree
2
+ module API
3
+ class Client
4
+ module Connection
5
+ def connection(options={})
6
+ options = {
7
+ :ssl => { :verify => false },
8
+ :url => api_endpoint,
9
+ }.merge(options)
10
+
11
+ connection = Faraday.new(options) do |builder|
12
+ builder.request :json
13
+
14
+ builder.use FaradayMiddleware::FollowRedirects
15
+ builder.use FaradayMiddleware::Mashify
16
+ builder.use Faraday::Response::RaiseError
17
+
18
+ builder.use FaradayMiddleware::ParseJson, :content_type => /\bjson$/
19
+
20
+ builder.adapter Faraday.default_adapter
21
+ end
22
+ connection
23
+ end
24
+ end
25
+ end
26
+ end
27
+ end
@@ -0,0 +1,15 @@
1
+ module Spree
2
+ module API
3
+ class Client
4
+ module Countries
5
+ def countries(options={})
6
+ get("countries", options)['countries']
7
+ end
8
+
9
+ def country(id, options={})
10
+ get("countries/#{id}", options)
11
+ end
12
+ end
13
+ end
14
+ end
15
+ end
@@ -0,0 +1,20 @@
1
+ module Spree
2
+ module API
3
+ class Client
4
+ module CreditCards
5
+ def credit_card(id, options={})
6
+ get("credit_cards/#{id}", options)
7
+ end
8
+
9
+ def credit_cards(options={})
10
+ get('credit_cards', options)["credit_cards"]
11
+ end
12
+
13
+ #NOTE- requires ID of already existing Spree::CreditCard
14
+ def authorize_credit_card(options={})
15
+ post('credit_cards/authorize', options)
16
+ end
17
+ end
18
+ end
19
+ end
20
+ end
@@ -0,0 +1,47 @@
1
+ module Spree
2
+ module API
3
+ class Client
4
+ class Error < StandardError
5
+
6
+ # Raised when Spree returns a 4xx or 500 HTTP status code
7
+ class ClientError < Error
8
+
9
+ # Creates a new error from an HTTP environement
10
+ #
11
+ # @param error [Exception]
12
+ # @return [Spree::API::Client::Error::ClientError]
13
+ def initialize(error=nil)
14
+ if error.respond_to?(:response) && !error.response.nil?
15
+ http_error = error.response[:status].to_i
16
+
17
+ if ERROR_MAP.has_key?(http_error)
18
+ raise ERROR_MAP[http_error].new(
19
+ message: error.response[:body]["error"],
20
+ validation_errors: error.response[:body]["errors"] || error.response[:body]["exception"])
21
+ else
22
+ super
23
+ end
24
+ else
25
+ super
26
+ end
27
+ end
28
+ end # ClientError
29
+
30
+ # Raised when Spree returns a 401 HTTP status code
31
+ class Unauthorized < Error; end
32
+
33
+ # Raised when Spree returns a 404 HTTP status code
34
+ class NotFound < Error; end
35
+
36
+ # Raised when Spree returns a 422 HTTP status code
37
+ class UnprocessableEntity < Error; end
38
+
39
+ ERROR_MAP = {
40
+ 401 => Spree::API::Client::Error::Unauthorized,
41
+ 404 => Spree::API::Client::Error::NotFound,
42
+ 422 => Spree::API::Client::Error::UnprocessableEntity
43
+ }
44
+ end # Error
45
+ end
46
+ end
47
+ end