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,19 @@
1
+ module Spree
2
+ module API
3
+ class Client
4
+ module LineItems
5
+ def create_line_item(order_number, options={})
6
+ post("orders/#{order_number}/line_items/", options)
7
+ end
8
+
9
+ def update_line_item(order_number, line_item_id, options={})
10
+ put("orders/#{order_number}/line_items/#{line_item_id}", options)
11
+ end
12
+
13
+ def delete_line_item(order_number, line_item_id, options={})
14
+ delete("orders/#{order_number}/line_items/#{line_item_id}", options)
15
+ end
16
+ end
17
+ end
18
+ end
19
+ end
@@ -0,0 +1,31 @@
1
+ module Spree
2
+ module API
3
+ class Client
4
+ module OptionTypes
5
+ def option_types(options={})
6
+ get('option_types', options)['option_types']
7
+ end
8
+
9
+ def option_type(permalink_or_id, options={})
10
+ get("option_types/#{permalink_or_id}", options)
11
+ end
12
+
13
+ def new_option_type(options={})
14
+ get("option_types/#{permalink_or_id}/new", options)
15
+ end
16
+
17
+ def create_option_type(options={})
18
+ post("option_types", options)
19
+ end
20
+
21
+ def update_option_type(permalink_or_id, options={})
22
+ put("option_types/#{permalink_or_id}", options)
23
+ end
24
+
25
+ def delete_option_type(permalink_or_id, options={})
26
+ delete("option_types/#{permalink_or_id}", options)
27
+ end
28
+ end
29
+ end
30
+ end
31
+ end
@@ -0,0 +1,31 @@
1
+ module Spree
2
+ module API
3
+ class Client
4
+ module OptionValues
5
+ def option_values(options={})
6
+ get('option_values', options)['option_values']
7
+ end
8
+
9
+ def option_value(permalink_or_id, options={})
10
+ get("option_values/#{permalink_or_id}", options)
11
+ end
12
+
13
+ def new_option_value(options={})
14
+ get("option_values/#{permalink_or_id}/new", options)
15
+ end
16
+
17
+ def create_option_value(options={})
18
+ post("option_values", options)
19
+ end
20
+
21
+ def update_option_value(permalink_or_id, options={})
22
+ put("option_values/#{permalink_or_id}", options)
23
+ end
24
+
25
+ def delete_option_value(permalink_or_id, options={})
26
+ delete("option_values/#{permalink_or_id}", options)
27
+ end
28
+ end
29
+ end
30
+ end
31
+ end
@@ -0,0 +1,56 @@
1
+ module Spree
2
+ module API
3
+ class Client
4
+ module Orders
5
+ def orders(options={})
6
+ get('orders', options)['orders']
7
+ end
8
+
9
+ def order(order_number, options={})
10
+ get("orders/#{order_number}", options)
11
+ end
12
+
13
+ def order_completed?(order_number, options={})
14
+ get("orders/#{order_number}/completed", options)
15
+ end
16
+
17
+ def create_order(options={})
18
+ post("orders", options)
19
+ end
20
+
21
+ def cancel_order(order_number, options={})
22
+ put("orders/#{order_number}/cancel", options)
23
+ end
24
+
25
+ def update_order(order_number, options={})
26
+ put("orders/#{order_number}", options)
27
+ end
28
+
29
+ def prepare_order_for_checkout(order_number, options={})
30
+ post("orders/#{order_number}/prepare_order", options)
31
+ end
32
+
33
+ def set_order_owner(order_number, options={})
34
+ put("orders/#{order_number}/owner", options)
35
+ end
36
+
37
+ def prepare_order_for_checkout(order_number, options={})
38
+ post("orders/#{order_number}/prepare_order", options)
39
+ end
40
+
41
+ def update_order_address(order_number, options={})
42
+ put("orders/#{order_number}/address", options)
43
+ end
44
+
45
+ def set_order_shipping_method(order_number, shipping_method_id, options={})
46
+ order_options = (options[:order] || {}).merge(:shipping_method_id => shipping_method_id)
47
+ put("orders/#{order_number}", options.merge(order: order_options))
48
+ end
49
+
50
+ def empty_order(order_number, options={})
51
+ put("orders/#{order_number}/empty", options)
52
+ end
53
+ end
54
+ end
55
+ end
56
+ end
@@ -0,0 +1,44 @@
1
+ module Spree
2
+ module API
3
+ class Client
4
+ module Payments
5
+ def payments(order_number, options={})
6
+
7
+ get("orders/#{order_number}/payments", options)['payments']
8
+ end
9
+
10
+ def payment(order_number, payment_id, options={})
11
+ get("orders/#{order_number}/payments/#{payment_id}", options)
12
+ end
13
+
14
+ def new_payment(order_number, options={})
15
+ get("orders/#{order_number}/payments/new", options)
16
+ end
17
+
18
+ def create_payment(order_number, options={})
19
+ post("orders/#{order_number}/payments/", options)
20
+ end
21
+
22
+ def authorize_payment(order_number, payment_id, options={})
23
+ put("orders/#{order_number}/payments/#{payment_id}/authorize", options)
24
+ end
25
+
26
+ def capture_payment(order_number, payment_id, options={})
27
+ put("orders/#{order_number}/payments/#{payment_id}/capture", options)
28
+ end
29
+
30
+ def purchase_payment(order_number, payment_id, options={})
31
+ put("orders/#{order_number}/payments/#{payment_id}/purchase", options)
32
+ end
33
+
34
+ def void_payment(order_number, payment_id, options={})
35
+ put("orders/#{order_number}/payments/#{payment_id}/void", options)
36
+ end
37
+
38
+ def credit_payment(order_number, payment_id, options={})
39
+ put("orders/#{order_number}/payments/#{payment_id}/credit", options)
40
+ end
41
+ end
42
+ end
43
+ end
44
+ end
@@ -0,0 +1,31 @@
1
+ module Spree
2
+ module API
3
+ class Client
4
+ module Products
5
+ def products(options={})
6
+ get('products', options)['products']
7
+ end
8
+
9
+ def product(permalink_or_id, options={})
10
+ get("products/#{permalink_or_id}", options)
11
+ end
12
+
13
+ def new_product(options={})
14
+ get("products/#{permalink_or_id}/new", options)
15
+ end
16
+
17
+ def create_product(options={})
18
+ post("products", options)
19
+ end
20
+
21
+ def update_product(permalink_or_id, options={})
22
+ put("products/#{permalink_or_id}", options)
23
+ end
24
+
25
+ def delete_product(permalink_or_id, options={})
26
+ delete("products/#{permalink_or_id}", options)
27
+ end
28
+ end
29
+ end
30
+ end
31
+ end
@@ -0,0 +1,15 @@
1
+ module Spree
2
+ module API
3
+ class Client
4
+ module Promotions
5
+ def promotions(options={})
6
+ get('promotions', options)
7
+ end
8
+
9
+ def promotion(permalink_or_id, options={})
10
+ get("promotions/#{permalink_or_id}", options)
11
+ end
12
+ end
13
+ end
14
+ end
15
+ end
@@ -0,0 +1,31 @@
1
+ module Spree
2
+ module API
3
+ class Client
4
+ module Properties
5
+ def properties(product_id, options={})
6
+ get("products/#{product_id}/product_properties", options)['product_properties']
7
+ end
8
+
9
+ def property(product_id, property_id, options={})
10
+ get("products/#{product_id}/product_properties/#{property_id}", options)
11
+ end
12
+
13
+ def new_property(product_id, options={})
14
+ get("products/#{product_id}/product_properties/new", options)
15
+ end
16
+
17
+ def create_property(product_id, options={})
18
+ post("products/#{product_id}/product_properties/", options)
19
+ end
20
+
21
+ def update_property(product_id, property_id, options={})
22
+ put("products/#{product_id}/product_properties/#{property_id}", options)
23
+ end
24
+
25
+ def delete_property(product_id, property_id, options={})
26
+ delete("products/#{product_id}/product_properties/#{property_id}", options)
27
+ end
28
+ end
29
+ end
30
+ end
31
+ end
@@ -0,0 +1,59 @@
1
+ require 'spree-api-client/error'
2
+ require 'multi_json'
3
+
4
+ module Spree
5
+ module API
6
+ class Client
7
+ module Request
8
+ def request(method, path, options = {})
9
+ token = options.delete(:api_token) || api_token
10
+
11
+ begin
12
+ response = connection.send(method) do |request|
13
+
14
+ request.headers['Accept'] = options.delete(:accept) || 'application/json'
15
+
16
+ if token
17
+ request.headers['X-Spree-Token'] = token
18
+ end
19
+
20
+ options.merge!(:locale => locale)
21
+
22
+ case method
23
+ when :get
24
+ options[:per_page] = per_page unless options[:per_page]
25
+ request.url(path, options)
26
+ when :delete, :head
27
+ request.url(path, options)
28
+ when :patch, :post, :put
29
+ request.path = path
30
+ request.body = MultiJson.dump(options) unless options.empty?
31
+ end
32
+ end
33
+
34
+ rescue Faraday::Error::ClientError => error
35
+ raise Spree::API::Client::Error::ClientError.new(error)
36
+ end
37
+
38
+ response
39
+ end
40
+
41
+ def get(path, options = {})
42
+ request(:get, path, options).body
43
+ end
44
+
45
+ def post(path, options={})
46
+ request(:post, path, options).body
47
+ end
48
+
49
+ def put(path, options={})
50
+ request(:put, path, options).body
51
+ end
52
+
53
+ def delete(path, options={})
54
+ request(:delete, path, options).body
55
+ end
56
+ end
57
+ end
58
+ end
59
+ end
@@ -0,0 +1,31 @@
1
+ module Spree
2
+ module API
3
+ class Client
4
+ module ReturnAuthorizations
5
+ def return_authorizations(order_number, options={})
6
+ get("orders/#{order_number}/return_authorizations", options)['return_authorizations']
7
+ end
8
+
9
+ def return_authorization(order_number, return_authorization_id, options={})
10
+ get("orders/#{order_number}/return_authorizations/#{return_authorization_id}", options)
11
+ end
12
+
13
+ def new_return_authorization(order_number, options={})
14
+ get("orders/#{order_number}/return_authorizations/new", options)
15
+ end
16
+
17
+ def create_return_authorization(order_number, options={})
18
+ post("orders/#{order_number}/return_authorizations/", options)
19
+ end
20
+
21
+ def update_return_authorization(product_id, return_authorization_id, options={})
22
+ put("orders/#{order_number}/return_authorizations/#{return_authorization_id}", options)
23
+ end
24
+
25
+ def delete_return_authorization(product_id, return_authorization_id, options={})
26
+ delete("orders/#{order_number}/return_authorizations/#{return_authorization_id}", options)
27
+ end
28
+ end
29
+ end
30
+ end
31
+ end
@@ -0,0 +1,15 @@
1
+ module Spree
2
+ module API
3
+ class Client
4
+ module Shipments
5
+ def shipment_ready(shipment_id, options={})
6
+ put("shipments/#{shipment_id}/ready", options)
7
+ end
8
+
9
+ def ship_shipment(shipment_id, options={})
10
+ put("shipments/#{shipment_id}/ship", options)
11
+ end
12
+ end
13
+ end
14
+ end
15
+ end
@@ -0,0 +1,31 @@
1
+ module Spree
2
+ module API
3
+ class Client
4
+ module StockItems
5
+ def stock_items(location=1, options={})
6
+ get("stock_locations/#{location}/stock_items/", options)
7
+ end
8
+
9
+ def stock_item(stock_item, location=1, options={})
10
+ get("stock_locations/#{location}/stock_items/#{stock_item}", options)
11
+ end
12
+
13
+ def new_stock_item(options={})
14
+ get("stock_items/#{permalink_or_id}/new", options)
15
+ end
16
+
17
+ def create_stock_item(location, options={})
18
+ post("stock_locations/#{location}/stock_items", options)
19
+ end
20
+
21
+ def update_stock_item(stock_item, location=1, options={})
22
+ put("stock_locations/#{location}/stock_items/#{stock_item}", options)
23
+ end
24
+
25
+ def delete_stock_item(stock_item, location=1, options={})
26
+ delete("stock_locations/#{location}/stock_items/#{stock_item}", options)
27
+ end
28
+ end
29
+ end
30
+ end
31
+ end
@@ -0,0 +1,31 @@
1
+ module Spree
2
+ module API
3
+ class Client
4
+ module StockLocations
5
+ def stock_locations(options={})
6
+ get('stock_locations', options)['stock_locations']
7
+ end
8
+
9
+ def stock_location(stock_location, options={})
10
+ get("stock_locations/#{stock_location}", options)
11
+ end
12
+
13
+ def new_stock_location(options={})
14
+ get("stock_locations/#{permalink_or_id}/new", options)
15
+ end
16
+
17
+ def create_stock_location(options={})
18
+ post("stock_locations", options)
19
+ end
20
+
21
+ def update_stock_location(stock_location, options={})
22
+ put("stock_locations/#{stock_location}", options)
23
+ end
24
+
25
+ def delete_stock_location(stock_location, options={})
26
+ delete("stock_locations/#{stock_location}", options)
27
+ end
28
+ end
29
+ end
30
+ end
31
+ end