spree_api_v1 4.5.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (158) hide show
  1. checksums.yaml +7 -0
  2. data/.circleci/config.yml +189 -0
  3. data/.gitignore +23 -0
  4. data/.rspec +3 -0
  5. data/.rubocop.yml +24 -0
  6. data/CHANGELOG.md +3 -0
  7. data/CODE_OF_CONDUCT.md +22 -0
  8. data/Gemfile +59 -0
  9. data/LICENSE +26 -0
  10. data/README.md +62 -0
  11. data/Rakefile +15 -0
  12. data/app/controllers/spree/api/v1/addresses_controller.rb +46 -0
  13. data/app/controllers/spree/api/v1/base_controller.rb +174 -0
  14. data/app/controllers/spree/api/v1/checkouts_controller.rb +106 -0
  15. data/app/controllers/spree/api/v1/classifications_controller.rb +21 -0
  16. data/app/controllers/spree/api/v1/countries_controller.rb +22 -0
  17. data/app/controllers/spree/api/v1/credit_cards_controller.rb +26 -0
  18. data/app/controllers/spree/api/v1/customer_returns_controller.rb +25 -0
  19. data/app/controllers/spree/api/v1/images_controller.rb +58 -0
  20. data/app/controllers/spree/api/v1/inventory_units_controller.rb +54 -0
  21. data/app/controllers/spree/api/v1/line_items_controller.rb +70 -0
  22. data/app/controllers/spree/api/v1/option_types_controller.rb +60 -0
  23. data/app/controllers/spree/api/v1/option_values_controller.rb +62 -0
  24. data/app/controllers/spree/api/v1/orders_controller.rb +160 -0
  25. data/app/controllers/spree/api/v1/payments_controller.rb +82 -0
  26. data/app/controllers/spree/api/v1/product_properties_controller.rb +73 -0
  27. data/app/controllers/spree/api/v1/products_controller.rb +131 -0
  28. data/app/controllers/spree/api/v1/promotions_controller.rb +30 -0
  29. data/app/controllers/spree/api/v1/properties_controller.rb +70 -0
  30. data/app/controllers/spree/api/v1/reimbursements_controller.rb +25 -0
  31. data/app/controllers/spree/api/v1/return_authorizations_controller.rb +70 -0
  32. data/app/controllers/spree/api/v1/shipments_controller.rb +196 -0
  33. data/app/controllers/spree/api/v1/states_controller.rb +36 -0
  34. data/app/controllers/spree/api/v1/stock_items_controller.rb +82 -0
  35. data/app/controllers/spree/api/v1/stock_locations_controller.rb +53 -0
  36. data/app/controllers/spree/api/v1/stock_movements_controller.rb +45 -0
  37. data/app/controllers/spree/api/v1/stores_controller.rb +56 -0
  38. data/app/controllers/spree/api/v1/taxonomies_controller.rb +67 -0
  39. data/app/controllers/spree/api/v1/taxons_controller.rb +100 -0
  40. data/app/controllers/spree/api/v1/users_controller.rb +97 -0
  41. data/app/controllers/spree/api/v1/variants_controller.rb +81 -0
  42. data/app/controllers/spree/api/v1/zones_controller.rb +55 -0
  43. data/app/helpers/spree/api/api_helpers.rb +190 -0
  44. data/app/models/spree/api_v1_configuration.rb +5 -0
  45. data/app/views/spree/api/errors/gateway_error.rabl +2 -0
  46. data/app/views/spree/api/errors/invalid_api_key.rabl +2 -0
  47. data/app/views/spree/api/errors/invalid_resource.rabl +3 -0
  48. data/app/views/spree/api/errors/must_specify_api_key.rabl +2 -0
  49. data/app/views/spree/api/errors/not_found.rabl +2 -0
  50. data/app/views/spree/api/errors/unauthorized.rabl +2 -0
  51. data/app/views/spree/api/v1/addresses/show.rabl +10 -0
  52. data/app/views/spree/api/v1/adjustments/show.rabl +4 -0
  53. data/app/views/spree/api/v1/countries/index.rabl +7 -0
  54. data/app/views/spree/api/v1/countries/show.rabl +5 -0
  55. data/app/views/spree/api/v1/credit_cards/index.rabl +7 -0
  56. data/app/views/spree/api/v1/credit_cards/show.rabl +3 -0
  57. data/app/views/spree/api/v1/customer_returns/index.rabl +7 -0
  58. data/app/views/spree/api/v1/images/index.rabl +4 -0
  59. data/app/views/spree/api/v1/images/new.rabl +3 -0
  60. data/app/views/spree/api/v1/images/show.rabl +6 -0
  61. data/app/views/spree/api/v1/inventory_units/show.rabl +2 -0
  62. data/app/views/spree/api/v1/line_items/new.rabl +3 -0
  63. data/app/views/spree/api/v1/line_items/show.rabl +14 -0
  64. data/app/views/spree/api/v1/option_types/index.rabl +3 -0
  65. data/app/views/spree/api/v1/option_types/new.rabl +3 -0
  66. data/app/views/spree/api/v1/option_types/show.rabl +5 -0
  67. data/app/views/spree/api/v1/option_values/index.rabl +3 -0
  68. data/app/views/spree/api/v1/option_values/new.rabl +3 -0
  69. data/app/views/spree/api/v1/option_values/show.rabl +2 -0
  70. data/app/views/spree/api/v1/orders/address.rabl +0 -0
  71. data/app/views/spree/api/v1/orders/canceled.rabl +0 -0
  72. data/app/views/spree/api/v1/orders/cart.rabl +0 -0
  73. data/app/views/spree/api/v1/orders/complete.rabl +0 -0
  74. data/app/views/spree/api/v1/orders/could_not_apply_coupon.rabl +2 -0
  75. data/app/views/spree/api/v1/orders/could_not_transition.rabl +3 -0
  76. data/app/views/spree/api/v1/orders/index.rabl +7 -0
  77. data/app/views/spree/api/v1/orders/insufficient_quantity.rabl +2 -0
  78. data/app/views/spree/api/v1/orders/invalid_shipping_method.rabl +2 -0
  79. data/app/views/spree/api/v1/orders/mine.rabl +9 -0
  80. data/app/views/spree/api/v1/orders/order.rabl +10 -0
  81. data/app/views/spree/api/v1/orders/payment.rabl +3 -0
  82. data/app/views/spree/api/v1/orders/show.rabl +51 -0
  83. data/app/views/spree/api/v1/payments/credit_over_limit.rabl +2 -0
  84. data/app/views/spree/api/v1/payments/index.rabl +7 -0
  85. data/app/views/spree/api/v1/payments/new.rabl +5 -0
  86. data/app/views/spree/api/v1/payments/show.rabl +2 -0
  87. data/app/views/spree/api/v1/payments/update_forbidden.rabl +2 -0
  88. data/app/views/spree/api/v1/product_properties/index.rabl +7 -0
  89. data/app/views/spree/api/v1/product_properties/new.rabl +2 -0
  90. data/app/views/spree/api/v1/product_properties/show.rabl +2 -0
  91. data/app/views/spree/api/v1/products/index.rabl +9 -0
  92. data/app/views/spree/api/v1/products/new.rabl +3 -0
  93. data/app/views/spree/api/v1/products/product.rabl +1 -0
  94. data/app/views/spree/api/v1/products/show.rabl +36 -0
  95. data/app/views/spree/api/v1/promotions/handler.rabl +5 -0
  96. data/app/views/spree/api/v1/promotions/show.rabl +2 -0
  97. data/app/views/spree/api/v1/properties/index.rabl +7 -0
  98. data/app/views/spree/api/v1/properties/new.rabl +2 -0
  99. data/app/views/spree/api/v1/properties/show.rabl +2 -0
  100. data/app/views/spree/api/v1/reimbursements/index.rabl +7 -0
  101. data/app/views/spree/api/v1/return_authorizations/index.rabl +7 -0
  102. data/app/views/spree/api/v1/return_authorizations/new.rabl +3 -0
  103. data/app/views/spree/api/v1/return_authorizations/show.rabl +2 -0
  104. data/app/views/spree/api/v1/shared/stock_location_required.rabl +2 -0
  105. data/app/views/spree/api/v1/shipments/big.rabl +48 -0
  106. data/app/views/spree/api/v1/shipments/cannot_ready_shipment.rabl +2 -0
  107. data/app/views/spree/api/v1/shipments/mine.rabl +9 -0
  108. data/app/views/spree/api/v1/shipments/show.rabl +32 -0
  109. data/app/views/spree/api/v1/shipments/small.rabl +37 -0
  110. data/app/views/spree/api/v1/shipping_rates/show.rabl +2 -0
  111. data/app/views/spree/api/v1/states/index.rabl +12 -0
  112. data/app/views/spree/api/v1/states/show.rabl +2 -0
  113. data/app/views/spree/api/v1/stock_items/index.rabl +7 -0
  114. data/app/views/spree/api/v1/stock_items/show.rabl +5 -0
  115. data/app/views/spree/api/v1/stock_locations/index.rabl +7 -0
  116. data/app/views/spree/api/v1/stock_locations/show.rabl +8 -0
  117. data/app/views/spree/api/v1/stock_movements/index.rabl +7 -0
  118. data/app/views/spree/api/v1/stock_movements/show.rabl +5 -0
  119. data/app/views/spree/api/v1/stores/index.rabl +4 -0
  120. data/app/views/spree/api/v1/stores/show.rabl +2 -0
  121. data/app/views/spree/api/v1/tags/index.rabl +9 -0
  122. data/app/views/spree/api/v1/taxonomies/index.rabl +7 -0
  123. data/app/views/spree/api/v1/taxonomies/jstree.rabl +7 -0
  124. data/app/views/spree/api/v1/taxonomies/nested.rabl +11 -0
  125. data/app/views/spree/api/v1/taxonomies/new.rabl +3 -0
  126. data/app/views/spree/api/v1/taxonomies/show.rabl +15 -0
  127. data/app/views/spree/api/v1/taxons/index.rabl +10 -0
  128. data/app/views/spree/api/v1/taxons/jstree.rabl +7 -0
  129. data/app/views/spree/api/v1/taxons/new.rabl +3 -0
  130. data/app/views/spree/api/v1/taxons/show.rabl +6 -0
  131. data/app/views/spree/api/v1/taxons/taxons.rabl +5 -0
  132. data/app/views/spree/api/v1/users/index.rabl +7 -0
  133. data/app/views/spree/api/v1/users/new.rabl +3 -0
  134. data/app/views/spree/api/v1/users/show.rabl +11 -0
  135. data/app/views/spree/api/v1/variants/big.rabl +14 -0
  136. data/app/views/spree/api/v1/variants/index.rabl +9 -0
  137. data/app/views/spree/api/v1/variants/new.rabl +2 -0
  138. data/app/views/spree/api/v1/variants/show.rabl +3 -0
  139. data/app/views/spree/api/v1/variants/small.rabl +18 -0
  140. data/app/views/spree/api/v1/zones/index.rabl +7 -0
  141. data/app/views/spree/api/v1/zones/show.rabl +6 -0
  142. data/config/initializers/rabl.rb +9 -0
  143. data/config/routes.rb +123 -0
  144. data/lib/spree/api_v1/controller_setup.rb +19 -0
  145. data/lib/spree/api_v1/engine.rb +27 -0
  146. data/lib/spree/api_v1/factories.rb +6 -0
  147. data/lib/spree/api_v1/responders/rabl_template.rb +28 -0
  148. data/lib/spree/api_v1/responders.rb +11 -0
  149. data/lib/spree/api_v1/testing_support/helpers.rb +44 -0
  150. data/lib/spree/api_v1/testing_support/setup.rb +16 -0
  151. data/lib/spree/api_v1/version.rb +9 -0
  152. data/lib/spree/api_v1.rb +9 -0
  153. data/lib/spree_api_v1.rb +3 -0
  154. data/script/rails +9 -0
  155. data/spec/fixtures/files/icon_256x256.jpg +0 -0
  156. data/spec/fixtures/thinking-cat.jpg +0 -0
  157. data/spree_api_v1.gemspec +26 -0
  158. metadata +261 -0
@@ -0,0 +1,190 @@
1
+ module Spree
2
+ module Api
3
+ module ApiHelpers
4
+ ATTRIBUTES = [
5
+ :product_attributes,
6
+ :product_property_attributes,
7
+ :variant_attributes,
8
+ :image_attributes,
9
+ :option_value_attributes,
10
+ :order_attributes,
11
+ :line_item_attributes,
12
+ :option_type_attributes,
13
+ :payment_attributes,
14
+ :payment_method_attributes,
15
+ :shipment_attributes,
16
+ :taxonomy_attributes,
17
+ :taxon_attributes,
18
+ :address_attributes,
19
+ :country_attributes,
20
+ :state_attributes,
21
+ :adjustment_attributes,
22
+ :inventory_unit_attributes,
23
+ :return_authorization_attributes,
24
+ :creditcard_attributes,
25
+ :payment_source_attributes,
26
+ :user_attributes,
27
+ :property_attributes,
28
+ :stock_location_attributes,
29
+ :stock_movement_attributes,
30
+ :stock_item_attributes,
31
+ :promotion_attributes,
32
+ :store_attributes,
33
+ :tag_attributes,
34
+ :customer_return_attributes,
35
+ :reimbursement_attributes
36
+ ]
37
+
38
+ mattr_reader *ATTRIBUTES
39
+
40
+ def required_fields_for(model)
41
+ required_fields = model._validators.select do |_field, validations|
42
+ validations.any? { |v| v.is_a?(ActiveModel::Validations::PresenceValidator) }
43
+ end.map(&:first) # get fields that are invalid
44
+ # Permalinks presence is validated, but are really automatically generated
45
+ # Therefore we shouldn't tell API clients that they MUST send one through
46
+ required_fields.map!(&:to_s).delete('permalink')
47
+ # Do not require slugs, either
48
+ required_fields.delete('slug')
49
+ required_fields
50
+ end
51
+
52
+ @@product_attributes = [
53
+ :id, :name, :description, :price, :display_price, :available_on,
54
+ :slug, :meta_description, :meta_keywords, :shipping_category_id,
55
+ :taxon_ids, :total_on_hand
56
+ ]
57
+
58
+ @@product_property_attributes = [
59
+ :id, :product_id, :property_id, :value, :property_name
60
+ ]
61
+
62
+ @@variant_attributes = [
63
+ :id, :name, :sku, :price, :weight, :height, :width, :depth, :is_master,
64
+ :slug, :description, :track_inventory
65
+ ]
66
+
67
+ @@image_attributes = [
68
+ :id, :position, :attachment_content_type, :attachment_file_name, :type,
69
+ :attachment_updated_at, :attachment_width, :attachment_height, :alt
70
+ ]
71
+
72
+ @@option_value_attributes = [
73
+ :id, :name, :presentation, :option_type_name, :option_type_id,
74
+ :option_type_presentation
75
+ ]
76
+
77
+ @@order_attributes = [
78
+ :id, :number, :item_total, :total, :ship_total, :state, :adjustment_total,
79
+ :user_id, :created_at, :updated_at, :completed_at, :payment_total,
80
+ :shipment_state, :payment_state, :email, :special_instructions, :channel,
81
+ :included_tax_total, :additional_tax_total, :display_included_tax_total,
82
+ :display_additional_tax_total, :tax_total, :currency, :considered_risky,
83
+ :canceler_id
84
+ ]
85
+
86
+ @@line_item_attributes = [:id, :quantity, :price, :variant_id]
87
+
88
+ @@option_type_attributes = [:id, :name, :presentation, :position]
89
+
90
+ @@payment_attributes = [
91
+ :id, :source_type, :source_id, :amount, :display_amount,
92
+ :payment_method_id, :state, :avs_response, :created_at,
93
+ :updated_at, :number
94
+ ]
95
+
96
+ @@payment_method_attributes = [:id, :name, :description]
97
+
98
+ @@shipment_attributes = [:id, :tracking, :number, :cost, :shipped_at, :state]
99
+
100
+ @@taxonomy_attributes = [:id, :name]
101
+
102
+ @@taxon_attributes = [
103
+ :id, :name, :pretty_name, :permalink, :parent_id,
104
+ :taxonomy_id, :meta_title, :meta_description
105
+ ]
106
+
107
+ @@inventory_unit_attributes = [
108
+ :id, :lock_version, :state, :variant_id, :shipment_id,
109
+ :return_authorization_id
110
+ ]
111
+
112
+ @@return_authorization_attributes = [
113
+ :id, :number, :state, :order_id, :memo, :created_at, :updated_at
114
+ ]
115
+
116
+ @@address_attributes = [
117
+ :id, :firstname, :lastname, :full_name, :address1, :address2, :city,
118
+ :zipcode, :phone, :company, :alternative_phone, :country_id, :state_id,
119
+ :label, :state_name, :state_text
120
+ ]
121
+
122
+ @@country_attributes = [:id, :iso_name, :iso, :iso3, :name, :numcode]
123
+
124
+ @@state_attributes = [:id, :name, :abbr, :country_id]
125
+
126
+ @@adjustment_attributes = [
127
+ :id, :source_type, :source_id, :adjustable_type, :adjustable_id,
128
+ :originator_type, :originator_id, :amount, :label, :mandatory,
129
+ :locked, :eligible, :created_at, :updated_at
130
+ ]
131
+
132
+ @@creditcard_attributes = [
133
+ :id, :month, :year, :cc_type, :last_digits, :name,
134
+ :gateway_customer_profile_id, :gateway_payment_profile_id
135
+ ]
136
+
137
+ @@payment_source_attributes = [
138
+ :id, :month, :year, :cc_type, :last_digits, :name
139
+ ]
140
+
141
+ @@user_attributes = [:id, :email, :created_at, :updated_at]
142
+
143
+ @@property_attributes = [:id, :name, :presentation]
144
+
145
+ @@stock_location_attributes = [
146
+ :id, :name, :address1, :address2, :city, :state_id, :state_name,
147
+ :country_id, :zipcode, :phone, :active
148
+ ]
149
+
150
+ @@stock_movement_attributes = [:id, :quantity, :stock_item_id]
151
+
152
+ @@stock_item_attributes = [
153
+ :id, :count_on_hand, :backorderable, :lock_version, :stock_location_id,
154
+ :variant_id
155
+ ]
156
+
157
+ @@promotion_attributes = [
158
+ :id, :name, :description, :expires_at, :starts_at, :type, :usage_limit,
159
+ :match_policy, :code, :advertise, :path
160
+ ]
161
+
162
+ @@store_attributes = [
163
+ :id, :name, :url, :meta_description, :meta_keywords, :seo_title,
164
+ :mail_from_address, :customer_support_email, :default_currency,
165
+ :code, :default, :facebook, :twitter, :instagram,
166
+ :supported_currencies, :default_locale, :supported_locales
167
+ ]
168
+
169
+ @@tag_attributes = [:id, :name]
170
+
171
+ @@customer_return_attributes = [
172
+ :id, :number, :order_id, :fully_reimbursed?, :pre_tax_total,
173
+ :created_at, :updated_at
174
+ ]
175
+
176
+ @@reimbursement_attributes = [
177
+ :id, :reimbursement_status, :customer_return_id, :order_id,
178
+ :number, :total, :created_at, :updated_at
179
+ ]
180
+
181
+ def variant_attributes
182
+ if @current_user_roles&.include?('admin')
183
+ @@variant_attributes + [:cost_price]
184
+ else
185
+ @@variant_attributes
186
+ end
187
+ end
188
+ end
189
+ end
190
+ end
@@ -0,0 +1,5 @@
1
+ module Spree
2
+ class ApiV1Configuration < Preferences::Configuration
3
+ preference :requires_authentication, :boolean, default: true
4
+ end
5
+ end
@@ -0,0 +1,2 @@
1
+ object false
2
+ node(:error) { I18n.t(:gateway_error, scope: 'spree.api', text: @error) }
@@ -0,0 +1,2 @@
1
+ object false
2
+ node(:error) { I18n.t(:invalid_api_key, key: api_key, scope: 'spree.api') }
@@ -0,0 +1,3 @@
1
+ object false
2
+ node(:error) { I18n.t(:invalid_resource, scope: 'spree.api') }
3
+ node(:errors) { @resource.errors.to_hash }
@@ -0,0 +1,2 @@
1
+ object false
2
+ node(:error) { I18n.t(:must_specify_api_key, scope: 'spree.api') }
@@ -0,0 +1,2 @@
1
+ object false
2
+ node(:error) { I18n.t(:resource_not_found, scope: 'spree.api') }
@@ -0,0 +1,2 @@
1
+ object false
2
+ node(:error) { I18n.t(:unauthorized, scope: 'spree.api') }
@@ -0,0 +1,10 @@
1
+ object @address
2
+ cache [I18n.locale, root_object]
3
+ attributes *address_attributes
4
+
5
+ child(:country) do |_address|
6
+ attributes *country_attributes
7
+ end
8
+ child(:state) do |_address|
9
+ attributes *state_attributes
10
+ end
@@ -0,0 +1,4 @@
1
+ object @adjustment
2
+ cache [I18n.locale, root_object]
3
+ attributes *adjustment_attributes
4
+ node(:display_amount) { |a| a.display_amount.to_s }
@@ -0,0 +1,7 @@
1
+ object false
2
+ child(@countries => :countries) do
3
+ attributes *country_attributes
4
+ end
5
+ node(:count) { @countries.count }
6
+ node(:current_page) { params[:page].try(:to_i) || 1 }
7
+ node(:pages) { @countries.total_pages }
@@ -0,0 +1,5 @@
1
+ object @country
2
+ attributes *country_attributes
3
+ child states: :states do
4
+ attributes :id, :name, :abbr, :country_id
5
+ end
@@ -0,0 +1,7 @@
1
+ object false
2
+ child(@credit_cards => :credit_cards) do
3
+ extends 'spree/api/v1/credit_cards/show'
4
+ end
5
+ node(:count) { @credit_cards.count }
6
+ node(:current_page) { params[:page].try(:to_i) || 1 }
7
+ node(:pages) { @credit_cards.total_pages }
@@ -0,0 +1,3 @@
1
+ object @credit_card
2
+ cache [I18n.locale, root_object]
3
+ attributes *creditcard_attributes
@@ -0,0 +1,7 @@
1
+ object false
2
+ child(@collection => :customer_returns) do
3
+ attributes *customer_return_attributes
4
+ end
5
+ node(:count) { @collection.count }
6
+ node(:current_page) { params[:page].try(:to_i) || 1 }
7
+ node(:pages) { @collection.total_pages }
@@ -0,0 +1,4 @@
1
+ object false
2
+ child(@images => :images) do
3
+ extends 'spree/api/v1/images/show'
4
+ end
@@ -0,0 +1,3 @@
1
+ object false
2
+ node(:attributes) { [*image_attributes] }
3
+ node(:required_attributes) { required_fields_for(Spree::Image) }
@@ -0,0 +1,6 @@
1
+ object @image
2
+ attributes *image_attributes
3
+ attributes :viewable_type, :viewable_id
4
+ Spree::Image.styles.each do |k, _v|
5
+ node("#{k}_url") { |i| main_app.url_for(i.url(k)) }
6
+ end
@@ -0,0 +1,2 @@
1
+ object @inventory_unit
2
+ attributes *inventory_unit_attributes
@@ -0,0 +1,3 @@
1
+ object false
2
+ node(:attributes) { [*line_item_attributes] - [:id] }
3
+ node(:required_attributes) { [:variant_id, :quantity] }
@@ -0,0 +1,14 @@
1
+ object @line_item
2
+ cache [I18n.locale, root_object]
3
+ attributes *line_item_attributes
4
+ node(:single_display_amount) { |li| li.single_display_amount.to_s }
5
+ node(:display_amount) { |li| li.display_amount.to_s }
6
+ node(:total, &:total)
7
+ child :variant do
8
+ extends 'spree/api/v1/variants/small'
9
+ attributes :product_id
10
+ end
11
+
12
+ child adjustments: :adjustments do
13
+ extends 'spree/api/v1/adjustments/show'
14
+ end
@@ -0,0 +1,3 @@
1
+ collection @option_types
2
+
3
+ extends 'spree/api/v1/option_types/show'
@@ -0,0 +1,3 @@
1
+ object false
2
+ node(:attributes) { [*option_type_attributes] }
3
+ node(:required_attributes) { required_fields_for(Spree::OptionType) }
@@ -0,0 +1,5 @@
1
+ object @option_type
2
+ attributes *option_type_attributes
3
+ child option_values: :option_values do
4
+ attributes *option_value_attributes
5
+ end
@@ -0,0 +1,3 @@
1
+ collection @option_values
2
+
3
+ extends 'spree/api/v1/option_values/show'
@@ -0,0 +1,3 @@
1
+ object false
2
+ node(:attributes) { [*option_value_attributes] }
3
+ node(:required_attributes) { required_fields_for(Spree::OptionValue) }
@@ -0,0 +1,2 @@
1
+ object @option_value
2
+ attributes *option_value_attributes
File without changes
File without changes
File without changes
File without changes
@@ -0,0 +1,2 @@
1
+ object false
2
+ node(:error) { @coupon_message }
@@ -0,0 +1,3 @@
1
+ object false
2
+ node(:error) { I18n.t(:could_not_transition, scope: 'spree.api.order') }
3
+ node(:errors) { @order.errors.to_hash }
@@ -0,0 +1,7 @@
1
+ object false
2
+ child(@orders => :orders) do
3
+ extends 'spree/api/v1/orders/order'
4
+ end
5
+ node(:count) { @orders.count }
6
+ node(:current_page) { params[:page].try(:to_i) || 1 }
7
+ node(:pages) { @orders.total_pages }
@@ -0,0 +1,2 @@
1
+ object false
2
+ node(:error) { Spree.t(:insufficient_quantity, scope: [:api, :order]) }
@@ -0,0 +1,2 @@
1
+ object false
2
+ node(:errors) { [I18n.t(:invalid_shipping_method, scope: 'spree.api.order')] }
@@ -0,0 +1,9 @@
1
+ object false
2
+
3
+ child(@orders => :orders) do
4
+ extends 'spree/api/v1/orders/show'
5
+ end
6
+
7
+ node(:count) { @orders.count }
8
+ node(:current_page) { params[:page].try(:to_i) || 1 }
9
+ node(:pages) { @orders.total_pages }
@@ -0,0 +1,10 @@
1
+ cache [I18n.locale, root_object]
2
+ attributes *order_attributes
3
+ node(:display_item_total) { |o| o.display_item_total.to_s }
4
+ node(:total_quantity) { |o| o.line_items.sum(:quantity) }
5
+ node(:display_total) { |o| o.display_total.to_s }
6
+ node(:display_ship_total, &:display_ship_total)
7
+ node(:display_tax_total, &:display_tax_total)
8
+ node(:display_adjustment_total, &:display_adjustment_total)
9
+ node(:token, &:token)
10
+ node(:checkout_steps, &:checkout_steps)
@@ -0,0 +1,3 @@
1
+ child available_payment_methods: :payment_methods do
2
+ attributes :id, :name, :method_type
3
+ end
@@ -0,0 +1,51 @@
1
+ object @order
2
+ extends 'spree/api/v1/orders/order'
3
+
4
+ if lookup_context.find_all("spree/api/v1/orders/#{root_object.state}").present?
5
+ extends "spree/api/v1/orders/#{root_object.state}"
6
+ end
7
+
8
+ child billing_address: :bill_address do
9
+ extends 'spree/api/v1/addresses/show'
10
+ end
11
+
12
+ child shipping_address: :ship_address do
13
+ extends 'spree/api/v1/addresses/show'
14
+ end
15
+
16
+ child line_items: :line_items do
17
+ extends 'spree/api/v1/line_items/show'
18
+ end
19
+
20
+ child payments: :payments do
21
+ attributes *payment_attributes
22
+
23
+ child payment_method: :payment_method do
24
+ attributes :id, :name
25
+ end
26
+
27
+ child source: :source do
28
+ if @current_user_roles.include?('admin')
29
+ attributes *payment_source_attributes + [:gateway_customer_profile_id, :gateway_payment_profile_id]
30
+ else
31
+ attributes *payment_source_attributes
32
+ end
33
+ end
34
+ end
35
+
36
+ child shipments: :shipments do
37
+ extends 'spree/api/v1/shipments/small'
38
+ end
39
+
40
+ child adjustments: :adjustments do
41
+ extends 'spree/api/v1/adjustments/show'
42
+ end
43
+
44
+ # Necessary for backend's order interface
45
+ node :permissions do
46
+ { can_update: current_ability.can?(:update, root_object) }
47
+ end
48
+
49
+ child valid_credit_cards: :credit_cards do
50
+ extends 'spree/api/v1/credit_cards/show'
51
+ end
@@ -0,0 +1,2 @@
1
+ object false
2
+ node(:error) { I18n.t(:credit_over_limit, limit: @payment.credit_allowed, scope: 'spree.api.payment') }
@@ -0,0 +1,7 @@
1
+ object false
2
+ child(@payments => :payments) do
3
+ attributes *payment_attributes
4
+ end
5
+ node(:count) { @payments.count }
6
+ node(:current_page) { params[:page].try(:to_i) || 1 }
7
+ node(:pages) { @payments.total_pages }
@@ -0,0 +1,5 @@
1
+ object false
2
+ node(:attributes) { [*payment_attributes] }
3
+ child @payment_methods => :payment_methods do
4
+ attributes *payment_method_attributes
5
+ end
@@ -0,0 +1,2 @@
1
+ object @payment
2
+ attributes *payment_attributes
@@ -0,0 +1,2 @@
1
+ object false
2
+ node(:error) { I18n.t(:update_forbidden, state: @payment.state, scope: 'spree.api.payment') }
@@ -0,0 +1,7 @@
1
+ object false
2
+ child(@product_properties => :product_properties) do
3
+ attributes *product_property_attributes
4
+ end
5
+ node(:count) { @product_properties.count }
6
+ node(:current_page) { params[:page].try(:to_i) || 1 }
7
+ node(:pages) { @product_properties.total_pages }
@@ -0,0 +1,2 @@
1
+ node(:attributes) { [*product_property_attributes] }
2
+ node(:required_attributes) { [] }
@@ -0,0 +1,2 @@
1
+ object @product_property
2
+ attributes *product_property_attributes
@@ -0,0 +1,9 @@
1
+ object false
2
+ node(:count) { @products.count }
3
+ node(:total_count) { @products.total_count }
4
+ node(:current_page) { params[:page] ? params[:page].to_i : 1 }
5
+ node(:per_page) { params[:per_page].try(:to_i) || Kaminari.config.default_per_page }
6
+ node(:pages) { @products.total_pages }
7
+ child(@products => :products) do
8
+ extends 'spree/api/v1/products/show'
9
+ end
@@ -0,0 +1,3 @@
1
+ object false
2
+ node(:attributes) { [*product_attributes] }
3
+ node(:required_attributes) { required_fields_for(Spree::Product) }
@@ -0,0 +1 @@
1
+ attributes *product_attributes
@@ -0,0 +1,36 @@
1
+ object @product
2
+ cache [I18n.locale, @current_user_roles.include?('admin'), current_currency, root_object]
3
+
4
+ attributes *product_attributes
5
+
6
+ node(:display_price) { |p| p.display_price.to_s }
7
+ node(:has_variants, &:has_variants?)
8
+ node(:taxon_ids, &:taxon_ids)
9
+ node(:display_current_currency_price) do |product|
10
+ price = product.price_in(current_currency)
11
+ Spree::Money.new(price.amount, currency: current_currency).to_s
12
+ end
13
+
14
+ child master: :master do
15
+ extends 'spree/api/v1/variants/small'
16
+ end
17
+
18
+ child variants: :variants do
19
+ extends 'spree/api/v1/variants/small'
20
+ end
21
+
22
+ child option_types: :option_types do
23
+ attributes *option_type_attributes
24
+ end
25
+
26
+ child product_properties: :product_properties do
27
+ attributes *product_property_attributes
28
+ end
29
+
30
+ child classifications: :classifications do
31
+ attributes :taxon_id, :position
32
+
33
+ child(:taxon) do
34
+ extends 'spree/api/v1/taxons/show'
35
+ end
36
+ end
@@ -0,0 +1,5 @@
1
+ object false
2
+ node(:success) { @handler.success }
3
+ node(:error) { @handler.error }
4
+ node(:successful) { @handler.successful? }
5
+ node(:status_code) { @handler.status_code }
@@ -0,0 +1,2 @@
1
+ object @promotion
2
+ attributes *promotion_attributes
@@ -0,0 +1,7 @@
1
+ object false
2
+ child(@properties => :properties) do
3
+ attributes *property_attributes
4
+ end
5
+ node(:count) { @properties.count }
6
+ node(:current_page) { params[:page].try(:to_i) || 1 }
7
+ node(:pages) { @properties.total_pages }
@@ -0,0 +1,2 @@
1
+ node(:attributes) { [*property_attributes] }
2
+ node(:required_attributes) { [] }
@@ -0,0 +1,2 @@
1
+ object @property
2
+ attributes *property_attributes
@@ -0,0 +1,7 @@
1
+ object false
2
+ child(@collection => :reimbursements) do
3
+ attributes *reimbursement_attributes
4
+ end
5
+ node(:count) { @collection.count }
6
+ node(:current_page) { params[:page].try(:to_i) || 1 }
7
+ node(:pages) { @collection.total_pages }
@@ -0,0 +1,7 @@
1
+ object false
2
+ child(@return_authorizations => :return_authorizations) do
3
+ attributes *return_authorization_attributes
4
+ end
5
+ node(:count) { @return_authorizations.count }
6
+ node(:current_page) { params[:page].try(:to_i) || 1 }
7
+ node(:pages) { @return_authorizations.total_pages }
@@ -0,0 +1,3 @@
1
+ object false
2
+ node(:attributes) { [*return_authorization_attributes] }
3
+ node(:required_attributes) { required_fields_for(Spree::ReturnAuthorization) }
@@ -0,0 +1,2 @@
1
+ object @return_authorization
2
+ attributes *return_authorization_attributes
@@ -0,0 +1,2 @@
1
+ object false
2
+ node(:error) { I18n.t(:stock_location_required, scope: 'spree.api') }