spree-api-client 0.0.1 → 0.0.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (40) hide show
  1. data/.ruby-version +1 -0
  2. data/.travis.yml +7 -5
  3. data/Gemfile +6 -0
  4. data/LICENSE +1 -1
  5. data/README.md +1 -1
  6. data/fixtures/cassette_library/addresss.yml +46 -0
  7. data/fixtures/cassette_library/countries.yml +52 -0
  8. data/fixtures/cassette_library/orders.yml +48 -0
  9. data/fixtures/cassette_library/payments.yml +48 -0
  10. data/fixtures/cassette_library/products.yml +66 -0
  11. data/fixtures/cassette_library/properties.yml +48 -0
  12. data/fixtures/cassette_library/request.yml +46 -0
  13. data/fixtures/cassette_library/return_authorizations.yml +48 -0
  14. data/fixtures/cassette_library/shipment_ready.yml +46 -0
  15. data/fixtures/cassette_library/taxonomies.yml +48 -0
  16. data/fixtures/cassette_library/taxons.yml +48 -0
  17. data/fixtures/cassette_library/variants.yml +63 -0
  18. data/fixtures/cassette_library/zones.yml +49 -0
  19. data/lib/spree-api-client/connection.rb +2 -1
  20. data/lib/spree-api-client/error.rb +47 -0
  21. data/lib/spree-api-client/orders.rb +2 -1
  22. data/lib/spree-api-client/request.rb +25 -18
  23. data/lib/spree-api-client/version.rb +1 -1
  24. data/spec/addresses_spec.rb +1 -0
  25. data/spec/client_spec.rb +1 -0
  26. data/spec/countries_spec.rb +1 -0
  27. data/spec/orders_spec.rb +1 -0
  28. data/spec/payments_spec.rb +1 -0
  29. data/spec/products_spec.rb +1 -0
  30. data/spec/properties_spec.rb +1 -0
  31. data/spec/return_authorizations_spec.rb +1 -0
  32. data/spec/shipments_spec.rb +1 -0
  33. data/spec/spec_helper.rb +6 -1
  34. data/spec/support/vcr.rb +9 -0
  35. data/spec/taxonomies_spec.rb +1 -0
  36. data/spec/taxons_spec.rb +1 -0
  37. data/spec/variants_spec.rb +1 -0
  38. data/spec/zones_spec.rb +1 -0
  39. data/spree-api-client.gemspec +3 -1
  40. metadata +96 -16
@@ -0,0 +1,46 @@
1
+ ---
2
+ http_interactions:
3
+ - request:
4
+ method: put
5
+ uri: http://localhost:4000/store/api/orders/1/shipments/1/ready
6
+ body:
7
+ encoding: US-ASCII
8
+ string: ''
9
+ headers:
10
+ Accept:
11
+ - application/json
12
+ X-Spree-Token:
13
+ - b56019f04b61a50553ee323f5ab68c6b435871971e79c987
14
+ Content-Length:
15
+ - '0'
16
+ User-Agent:
17
+ - Ruby
18
+ response:
19
+ status:
20
+ code: 404
21
+ message: ! 'Not Found '
22
+ headers:
23
+ Content-Type:
24
+ - application/json
25
+ X-Ua-Compatible:
26
+ - IE=Edge
27
+ Cache-Control:
28
+ - no-cache
29
+ X-Request-Id:
30
+ - 10a1c5aac78cf46d9e1e115f95cdf0b2
31
+ X-Runtime:
32
+ - '0.036787'
33
+ Content-Length:
34
+ - '67'
35
+ Server:
36
+ - WEBrick/1.3.1 (Ruby/1.9.3/2012-02-16)
37
+ Date:
38
+ - Fri, 07 Dec 2012 17:37:15 GMT
39
+ Connection:
40
+ - Keep-Alive
41
+ body:
42
+ encoding: US-ASCII
43
+ string: ! '{"error":"translation missing: en-GB.spree.api.resource_not_found"}'
44
+ http_version:
45
+ recorded_at: Fri, 07 Dec 2012 17:37:15 GMT
46
+ recorded_with: VCR 2.3.0
@@ -0,0 +1,48 @@
1
+ ---
2
+ http_interactions:
3
+ - request:
4
+ method: get
5
+ uri: http://localhost:4000/store/api/taxonomies?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
+ - ! '"6d4a78870b076c5a43e1017631e3a2a5"'
29
+ Cache-Control:
30
+ - max-age=0, private, must-revalidate
31
+ X-Request-Id:
32
+ - 818109a0d62f745696fad81744dbfd74
33
+ X-Runtime:
34
+ - '0.141291'
35
+ Content-Length:
36
+ - '522'
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":3,"current_page":1,"pages":1,"taxonomies":[{"taxonomy":{"id":3,"name":"ridebmx","root":{"id":3,"name":"ridebmx","permalink":"ridebmx","position":0,"parent_id":null,"taxonomy_id":3,"taxons":[]}}},{"taxonomy":{"id":1,"name":"rideukbmx","root":{"id":1,"name":"rideukbmx","permalink":"ridebmx","position":0,"parent_id":null,"taxonomy_id":1,"taxons":[]}}},{"taxonomy":{"id":2,"name":"whitelines","root":{"id":2,"name":"whitelines","permalink":"whitelines","position":0,"parent_id":null,"taxonomy_id":2,"taxons":[]}}}]}'
46
+ http_version:
47
+ recorded_at: Fri, 07 Dec 2012 17:37:16 GMT
48
+ recorded_with: VCR 2.3.0
@@ -0,0 +1,48 @@
1
+ ---
2
+ http_interactions:
3
+ - request:
4
+ method: get
5
+ uri: http://localhost:4000/store/api/taxonomies/1/taxons?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
+ - ! '"d751713988987e9331980363e24189ce"'
29
+ Cache-Control:
30
+ - max-age=0, private, must-revalidate
31
+ X-Request-Id:
32
+ - 92ea82cb431abd35b20ab737cd348ecd
33
+ X-Runtime:
34
+ - '0.033542'
35
+ Content-Length:
36
+ - '2'
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: ! '[]'
46
+ http_version:
47
+ recorded_at: Fri, 07 Dec 2012 17:37:16 GMT
48
+ recorded_with: VCR 2.3.0
@@ -0,0 +1,63 @@
1
+ ---
2
+ http_interactions:
3
+ - request:
4
+ method: get
5
+ uri: http://localhost:4000/store/api/products/1/variants?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
+ - ! '"7ebbeb3d86e3857a26aead46fd50dc24"'
29
+ Cache-Control:
30
+ - max-age=0, private, must-revalidate
31
+ X-Request-Id:
32
+ - 3ea623d6001a50456a17647ca427e6f5
33
+ X-Runtime:
34
+ - '0.100396'
35
+ Content-Length:
36
+ - '9097'
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":30,"total_count":30,"current_page":1,"pages":1,"variants":[{"variant":{"id":1,"name":"Bomb","count_on_hand":0,"sku":"","price":"12.99","weight":null,"height":null,"width":null,"depth":null,"is_master":true,"cost_price":"12.99","permalink":"bomb","option_values":[]}},{"variant":{"id":2,"name":"Bomb","count_on_hand":8,"sku":"","price":"12.99","weight":null,"height":null,"width":null,"depth":null,"is_master":false,"cost_price":null,"permalink":"bomb","option_values":[{"option_value":{"id":1,"name":"Small","presentation":"Small","option_type_name":"Size","option_type_id":1}}]}},{"variant":{"id":3,"name":"Bomb","count_on_hand":20,"sku":"","price":"12.99","weight":null,"height":null,"width":null,"depth":null,"is_master":false,"cost_price":null,"permalink":"bomb","option_values":[{"option_value":{"id":2,"name":"Medium","presentation":"Medium","option_type_name":"Size","option_type_id":1}}]}},{"variant":{"id":4,"name":"Bomb","count_on_hand":14,"sku":"","price":"12.99","weight":null,"height":null,"width":null,"depth":null,"is_master":false,"cost_price":null,"permalink":"bomb","option_values":[{"option_value":{"id":3,"name":"Large","presentation":"Large","option_type_name":"Size","option_type_id":1}}]}},{"variant":{"id":5,"name":"Disobey","count_on_hand":0,"sku":"","price":"12.99","weight":null,"height":null,"width":null,"depth":null,"is_master":true,"cost_price":"12.99","permalink":"disobey","option_values":[]}},{"variant":{"id":6,"name":"Disobey","count_on_hand":10,"sku":"","price":"12.99","weight":null,"height":null,"width":null,"depth":null,"is_master":false,"cost_price":null,"permalink":"disobey","option_values":[{"option_value":{"id":1,"name":"Small","presentation":"Small","option_type_name":"Size","option_type_id":1}}]}},{"variant":{"id":7,"name":"Disobey","count_on_hand":19,"sku":"","price":"12.99","weight":null,"height":null,"width":null,"depth":null,"is_master":false,"cost_price":null,"permalink":"disobey","option_values":[{"option_value":{"id":2,"name":"Medium","presentation":"Medium","option_type_name":"Size","option_type_id":1}}]}},{"variant":{"id":8,"name":"Disobey","count_on_hand":15,"sku":"","price":"12.99","weight":null,"height":null,"width":null,"depth":null,"is_master":false,"cost_price":null,"permalink":"disobey","option_values":[{"option_value":{"id":3,"name":"Large","presentation":"Large","option_type_name":"Size","option_type_id":1}}]}},{"variant":{"id":9,"name":"POV","count_on_hand":0,"sku":"","price":"12.99","weight":null,"height":null,"width":null,"depth":null,"is_master":true,"cost_price":"12.99","permalink":"pov","option_values":[]}},{"variant":{"id":10,"name":"POV","count_on_hand":10,"sku":"","price":"12.99","weight":null,"height":null,"width":null,"depth":null,"is_master":false,"cost_price":null,"permalink":"pov","option_values":[{"option_value":{"id":1,"name":"Small","presentation":"Small","option_type_name":"Size","option_type_id":1}}]}},{"variant":{"id":11,"name":"POV","count_on_hand":19,"sku":"","price":"12.99","weight":null,"height":null,"width":null,"depth":null,"is_master":false,"cost_price":null,"permalink":"pov","option_values":[{"option_value":{"id":2,"name":"Medium","presentation":"Medium","option_type_name":"Size","option_type_id":1}}]}},{"variant":{"id":12,"name":"POV","count_on_hand":15,"sku":"","price":"12.99","weight":null,"height":null,"width":null,"depth":null,"is_master":false,"cost_price":null,"permalink":"pov","option_values":[{"option_value":{"id":3,"name":"Large","presentation":"Large","option_type_name":"Size","option_type_id":1}}]}},{"variant":{"id":13,"name":"Bomb","count_on_hand":5,"sku":"","price":"12.99","weight":null,"height":null,"width":null,"depth":null,"is_master":false,"cost_price":"12.99","permalink":"bomb","option_values":[{"option_value":{"id":4,"name":"XL","presentation":"XL","option_type_name":"Size","option_type_id":1}}]}},{"variant":{"id":14,"name":"Disobey","count_on_hand":5,"sku":"","price":"12.99","weight":null,"height":null,"width":null,"depth":null,"is_master":false,"cost_price":null,"permalink":"disobey","option_values":[{"option_value":{"id":4,"name":"XL","presentation":"XL","option_type_name":"Size","option_type_id":1}}]}},{"variant":{"id":15,"name":"POV","count_on_hand":5,"sku":"","price":"12.99","weight":null,"height":null,"width":null,"depth":null,"is_master":false,"cost_price":null,"permalink":"pov","option_values":[{"option_value":{"id":4,"name":"XL","presentation":"XL","option_type_name":"Size","option_type_id":1}}]}},{"variant":{"id":16,"name":"Whitelines
46
+ 1","count_on_hand":0,"sku":"","price":"14.0","weight":null,"height":null,"width":null,"depth":null,"is_master":true,"cost_price":null,"permalink":"whitelines-1","option_values":[]}},{"variant":{"id":17,"name":"Whitelines
47
+ 1","count_on_hand":0,"sku":"","price":"14.0","weight":null,"height":null,"width":null,"depth":null,"is_master":false,"cost_price":null,"permalink":"whitelines-1","option_values":[{"option_value":{"id":1,"name":"Small","presentation":"Small","option_type_name":"Size","option_type_id":1}}]}},{"variant":{"id":18,"name":"Whitelines
48
+ 1","count_on_hand":0,"sku":"","price":"14.0","weight":null,"height":null,"width":null,"depth":null,"is_master":false,"cost_price":null,"permalink":"whitelines-1","option_values":[{"option_value":{"id":2,"name":"Medium","presentation":"Medium","option_type_name":"Size","option_type_id":1}}]}},{"variant":{"id":19,"name":"Whitelines
49
+ 1","count_on_hand":0,"sku":"","price":"14.0","weight":null,"height":null,"width":null,"depth":null,"is_master":false,"cost_price":null,"permalink":"whitelines-1","option_values":[{"option_value":{"id":3,"name":"Large","presentation":"Large","option_type_name":"Size","option_type_id":1}}]}},{"variant":{"id":20,"name":"Whitelines
50
+ 1","count_on_hand":0,"sku":"","price":"14.0","weight":null,"height":null,"width":null,"depth":null,"is_master":false,"cost_price":null,"permalink":"whitelines-1","option_values":[{"option_value":{"id":4,"name":"XL","presentation":"XL","option_type_name":"Size","option_type_id":1}}]}},{"variant":{"id":21,"name":"Whitelines
51
+ 2","count_on_hand":0,"sku":"","price":"14.0","weight":null,"height":null,"width":null,"depth":null,"is_master":true,"cost_price":null,"permalink":"whitelines-2","option_values":[]}},{"variant":{"id":22,"name":"Whitelines
52
+ 3","count_on_hand":0,"sku":"","price":"14.0","weight":null,"height":null,"width":null,"depth":null,"is_master":true,"cost_price":null,"permalink":"whitelines-3","option_values":[]}},{"variant":{"id":23,"name":"Whitelines
53
+ 2","count_on_hand":0,"sku":"","price":"14.0","weight":null,"height":null,"width":null,"depth":null,"is_master":false,"cost_price":null,"permalink":"whitelines-2","option_values":[{"option_value":{"id":1,"name":"Small","presentation":"Small","option_type_name":"Size","option_type_id":1}}]}},{"variant":{"id":24,"name":"Whitelines
54
+ 2","count_on_hand":0,"sku":"","price":"14.0","weight":null,"height":null,"width":null,"depth":null,"is_master":false,"cost_price":null,"permalink":"whitelines-2","option_values":[{"option_value":{"id":2,"name":"Medium","presentation":"Medium","option_type_name":"Size","option_type_id":1}}]}},{"variant":{"id":25,"name":"Whitelines
55
+ 2","count_on_hand":0,"sku":"","price":"14.0","weight":null,"height":null,"width":null,"depth":null,"is_master":false,"cost_price":null,"permalink":"whitelines-2","option_values":[{"option_value":{"id":3,"name":"Large","presentation":"Large","option_type_name":"Size","option_type_id":1}}]}},{"variant":{"id":26,"name":"Whitelines
56
+ 2","count_on_hand":0,"sku":"","price":"14.0","weight":null,"height":null,"width":null,"depth":null,"is_master":false,"cost_price":null,"permalink":"whitelines-2","option_values":[{"option_value":{"id":4,"name":"XL","presentation":"XL","option_type_name":"Size","option_type_id":1}}]}},{"variant":{"id":27,"name":"Whitelines
57
+ 3","count_on_hand":0,"sku":"","price":"14.0","weight":null,"height":null,"width":null,"depth":null,"is_master":false,"cost_price":null,"permalink":"whitelines-3","option_values":[{"option_value":{"id":1,"name":"Small","presentation":"Small","option_type_name":"Size","option_type_id":1}}]}},{"variant":{"id":28,"name":"Whitelines
58
+ 3","count_on_hand":0,"sku":"","price":"14.0","weight":null,"height":null,"width":null,"depth":null,"is_master":false,"cost_price":null,"permalink":"whitelines-3","option_values":[{"option_value":{"id":2,"name":"Medium","presentation":"Medium","option_type_name":"Size","option_type_id":1}}]}},{"variant":{"id":29,"name":"Whitelines
59
+ 3","count_on_hand":0,"sku":"","price":"14.0","weight":null,"height":null,"width":null,"depth":null,"is_master":false,"cost_price":null,"permalink":"whitelines-3","option_values":[{"option_value":{"id":3,"name":"Large","presentation":"Large","option_type_name":"Size","option_type_id":1}}]}},{"variant":{"id":30,"name":"Whitelines
60
+ 3","count_on_hand":0,"sku":"","price":"14.0","weight":null,"height":null,"width":null,"depth":null,"is_master":false,"cost_price":null,"permalink":"whitelines-3","option_values":[{"option_value":{"id":4,"name":"XL","presentation":"XL","option_type_name":"Size","option_type_id":1}}]}}]}'
61
+ http_version:
62
+ recorded_at: Fri, 07 Dec 2012 17:37:16 GMT
63
+ recorded_with: VCR 2.3.0
@@ -0,0 +1,49 @@
1
+ ---
2
+ http_interactions:
3
+ - request:
4
+ method: get
5
+ uri: http://localhost:4000/store/api/zones?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
@@ -8,7 +8,7 @@ module Spree
8
8
  :force_urlencoded => false,
9
9
  :raw => false,
10
10
  :ssl => { :verify => false },
11
- :url => 'http://localhost:4000/store/api', #api_endpoint
11
+ :url => api_endpoint,
12
12
  :path_prefix => '/api'
13
13
  }.merge(options)
14
14
 
@@ -17,6 +17,7 @@ module Spree
17
17
 
18
18
  builder.use FaradayMiddleware::FollowRedirects
19
19
  builder.use FaradayMiddleware::Mashify
20
+ builder.use Faraday::Response::RaiseError
20
21
 
21
22
  builder.use FaradayMiddleware::ParseJson, :content_type => /\bjson$/
22
23
 
@@ -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
@@ -19,7 +19,8 @@ module Spree
19
19
  end
20
20
 
21
21
  def set_order_shipping_method(order_number, shipping_method_id, options={})
22
- put("orders/#{order_number}", options.merge(:shipping_method_id => shipping_method_id))
22
+ order_options = (options[:order] || {}).merge(:shipping_method_id => shipping_method_id)
23
+ put("orders/#{order_number}", options.merge(order: order_options))
23
24
  end
24
25
 
25
26
  def empty_order(order_number, options={})
@@ -1,3 +1,5 @@
1
+ require 'spree-api-client/error'
2
+
1
3
  module Spree
2
4
  module API
3
5
  class Client
@@ -5,31 +7,36 @@ module Spree
5
7
  def request(method, path, options = {})
6
8
  token = options.delete(:api_token) || api_token
7
9
 
8
- response = connection.send(method) do |request|
9
-
10
- request.headers['Accept'] = options.delete(:accept) || 'application/json'
11
-
12
- if token
13
- request.headers['X-Spree-Token'] = token
10
+ begin
11
+ response = connection.send(method) do |request|
12
+
13
+ request.headers['Accept'] = options.delete(:accept) || 'application/json'
14
+
15
+ if token
16
+ request.headers['X-Spree-Token'] = token
17
+ end
18
+
19
+ case method
20
+ when :get
21
+ options.merge(:per_page => per_page)
22
+ request.url(path, options)
23
+ when :delete, :head
24
+ request.url(path, options)
25
+ when :patch, :post, :put
26
+ request.path = path
27
+ request.body = MultiJson.dump(options) unless options.empty?
28
+ end
14
29
  end
15
30
 
16
- case method
17
- when :get
18
- options.merge!(:per_page => per_page) if per_page
19
- request.url(path, options)
20
- when :delete, :head
21
- request.url(path, options)
22
- when :patch, :post, :put
23
- request.path = path
24
- request.body = MultiJson.dump(options) unless options.empty?
25
- end
31
+ rescue Faraday::Error::ClientError => error
32
+ raise Spree::API::Client::Error::ClientError.new(error)
26
33
  end
27
34
 
28
35
  response
29
36
  end
30
-
37
+
31
38
  def get(path, options = {})
32
- request(:get, path, options = {}).body
39
+ request(:get, path, options).body
33
40
  end
34
41
 
35
42
  def post(path, options={})
@@ -1,7 +1,7 @@
1
1
  module Spree
2
2
  module API
3
3
  class Client
4
- VERSION = "0.0.1"
4
+ VERSION = "0.0.2"
5
5
  end
6
6
  end
7
7
  end
@@ -1,6 +1,7 @@
1
1
  require 'spec_helper'
2
2
 
3
3
  describe Spree::API::Client::Addresses do
4
+ use_vcr_cassette "addresss", :record => :new_episodes
4
5
  describe 'address' do
5
6
  it 'should load address' do
6
7
  client = Spree::API::Client.new('http://localhost:4000/store/api', 'b56019f04b61a50553ee323f5ab68c6b435871971e79c987')
@@ -22,6 +22,7 @@ describe Spree::API::Client do
22
22
  end
23
23
 
24
24
  describe 'request' do
25
+ use_vcr_cassette "request", :record => :new_episodes
25
26
  it 'should load stuff from the api' do
26
27
  client = Spree::API::Client.new('http://localhost:4000/store/api', 'randomtokenstring')
27
28
  response = client.request(:get, 'products')
@@ -1,6 +1,7 @@
1
1
  require 'spec_helper'
2
2
 
3
3
  describe Spree::API::Client::Countries do
4
+ use_vcr_cassette "countries", :record => :new_episodes
4
5
  describe 'countries' do
5
6
  it 'should load countries' do
6
7
  client = Spree::API::Client.new('http://localhost:4000/store/api', 'b56019f04b61a50553ee323f5ab68c6b435871971e79c987')
@@ -1,6 +1,7 @@
1
1
  require 'spec_helper'
2
2
 
3
3
  describe Spree::API::Client::Orders do
4
+ use_vcr_cassette "orders", :record => :new_episodes
4
5
  describe 'orders' do
5
6
  it 'should load orders' do
6
7
  client = Spree::API::Client.new('http://localhost:4000/store/api', 'b56019f04b61a50553ee323f5ab68c6b435871971e79c987')
@@ -1,6 +1,7 @@
1
1
  require 'spec_helper'
2
2
 
3
3
  describe Spree::API::Client::Payments do
4
+ use_vcr_cassette "payments", :record => :new_episodes
4
5
  describe 'payments' do
5
6
  it 'should load payments' do
6
7
  client = Spree::API::Client.new('http://localhost:4000/store/api', 'b56019f04b61a50553ee323f5ab68c6b435871971e79c987')