goca-spree-api 3.1.14.rails.5.0

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 (151) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +17 -0
  3. data/Gemfile +5 -0
  4. data/LICENSE +26 -0
  5. data/Rakefile +16 -0
  6. data/app/controllers/spree/api/base_controller.rb +167 -0
  7. data/app/controllers/spree/api/v1/addresses_controller.rb +46 -0
  8. data/app/controllers/spree/api/v1/checkouts_controller.rb +103 -0
  9. data/app/controllers/spree/api/v1/classifications_controller.rb +20 -0
  10. data/app/controllers/spree/api/v1/countries_controller.rb +24 -0
  11. data/app/controllers/spree/api/v1/credit_cards_controller.rb +27 -0
  12. data/app/controllers/spree/api/v1/images_controller.rb +56 -0
  13. data/app/controllers/spree/api/v1/inventory_units_controller.rb +54 -0
  14. data/app/controllers/spree/api/v1/line_items_controller.rb +70 -0
  15. data/app/controllers/spree/api/v1/option_types_controller.rb +51 -0
  16. data/app/controllers/spree/api/v1/option_values_controller.rb +60 -0
  17. data/app/controllers/spree/api/v1/orders_controller.rb +148 -0
  18. data/app/controllers/spree/api/v1/payments_controller.rb +83 -0
  19. data/app/controllers/spree/api/v1/product_properties_controller.rb +70 -0
  20. data/app/controllers/spree/api/v1/products_controller.rb +126 -0
  21. data/app/controllers/spree/api/v1/promotions_controller.rb +28 -0
  22. data/app/controllers/spree/api/v1/properties_controller.rb +72 -0
  23. data/app/controllers/spree/api/v1/return_authorizations_controller.rb +71 -0
  24. data/app/controllers/spree/api/v1/shipments_controller.rb +163 -0
  25. data/app/controllers/spree/api/v1/states_controller.rb +37 -0
  26. data/app/controllers/spree/api/v1/stock_items_controller.rb +77 -0
  27. data/app/controllers/spree/api/v1/stock_locations_controller.rb +52 -0
  28. data/app/controllers/spree/api/v1/stock_movements_controller.rb +45 -0
  29. data/app/controllers/spree/api/v1/stores_controller.rb +57 -0
  30. data/app/controllers/spree/api/v1/taxonomies_controller.rb +66 -0
  31. data/app/controllers/spree/api/v1/taxons_controller.rb +95 -0
  32. data/app/controllers/spree/api/v1/users_controller.rb +60 -0
  33. data/app/controllers/spree/api/v1/variants_controller.rb +75 -0
  34. data/app/controllers/spree/api/v1/zones_controller.rb +51 -0
  35. data/app/helpers/spree/api/api_helpers.rb +173 -0
  36. data/app/models/spree/api_configuration.rb +5 -0
  37. data/app/views/spree/api/errors/gateway_error.v1.rabl +2 -0
  38. data/app/views/spree/api/errors/invalid_api_key.v1.rabl +2 -0
  39. data/app/views/spree/api/errors/invalid_resource.v1.rabl +3 -0
  40. data/app/views/spree/api/errors/must_specify_api_key.v1.rabl +2 -0
  41. data/app/views/spree/api/errors/not_found.v1.rabl +2 -0
  42. data/app/views/spree/api/errors/unauthorized.v1.rabl +2 -0
  43. data/app/views/spree/api/v1/addresses/show.v1.rabl +10 -0
  44. data/app/views/spree/api/v1/adjustments/show.v1.rabl +4 -0
  45. data/app/views/spree/api/v1/config/money.v1.rabl +2 -0
  46. data/app/views/spree/api/v1/config/show.v1.rabl +2 -0
  47. data/app/views/spree/api/v1/countries/index.v1.rabl +7 -0
  48. data/app/views/spree/api/v1/countries/show.v1.rabl +5 -0
  49. data/app/views/spree/api/v1/credit_cards/index.v1.rabl +7 -0
  50. data/app/views/spree/api/v1/credit_cards/show.v1.rabl +3 -0
  51. data/app/views/spree/api/v1/images/index.v1.rabl +4 -0
  52. data/app/views/spree/api/v1/images/new.v1.rabl +3 -0
  53. data/app/views/spree/api/v1/images/show.v1.rabl +6 -0
  54. data/app/views/spree/api/v1/inventory_units/show.rabl +2 -0
  55. data/app/views/spree/api/v1/line_items/new.v1.rabl +3 -0
  56. data/app/views/spree/api/v1/line_items/show.v1.rabl +15 -0
  57. data/app/views/spree/api/v1/option_types/index.v1.rabl +3 -0
  58. data/app/views/spree/api/v1/option_types/new.v1.rabl +3 -0
  59. data/app/views/spree/api/v1/option_types/show.v1.rabl +5 -0
  60. data/app/views/spree/api/v1/option_values/index.v1.rabl +3 -0
  61. data/app/views/spree/api/v1/option_values/new.v1.rabl +3 -0
  62. data/app/views/spree/api/v1/option_values/show.v1.rabl +2 -0
  63. data/app/views/spree/api/v1/orders/address.v1.rabl +0 -0
  64. data/app/views/spree/api/v1/orders/canceled.v1.rabl +0 -0
  65. data/app/views/spree/api/v1/orders/cart.v1.rabl +0 -0
  66. data/app/views/spree/api/v1/orders/complete.v1.rabl +0 -0
  67. data/app/views/spree/api/v1/orders/could_not_apply_coupon.v1.rabl +2 -0
  68. data/app/views/spree/api/v1/orders/could_not_transition.v1.rabl +3 -0
  69. data/app/views/spree/api/v1/orders/index.v1.rabl +7 -0
  70. data/app/views/spree/api/v1/orders/invalid_shipping_method.v1.rabl +2 -0
  71. data/app/views/spree/api/v1/orders/mine.v1.rabl +9 -0
  72. data/app/views/spree/api/v1/orders/order.v1.rabl +10 -0
  73. data/app/views/spree/api/v1/orders/payment.v1.rabl +3 -0
  74. data/app/views/spree/api/v1/orders/show.v1.rabl +51 -0
  75. data/app/views/spree/api/v1/payments/credit_over_limit.v1.rabl +2 -0
  76. data/app/views/spree/api/v1/payments/index.v1.rabl +7 -0
  77. data/app/views/spree/api/v1/payments/new.v1.rabl +5 -0
  78. data/app/views/spree/api/v1/payments/show.v1.rabl +2 -0
  79. data/app/views/spree/api/v1/payments/update_forbidden.v1.rabl +2 -0
  80. data/app/views/spree/api/v1/product_properties/index.v1.rabl +7 -0
  81. data/app/views/spree/api/v1/product_properties/new.v1.rabl +2 -0
  82. data/app/views/spree/api/v1/product_properties/show.v1.rabl +2 -0
  83. data/app/views/spree/api/v1/products/index.v1.rabl +9 -0
  84. data/app/views/spree/api/v1/products/new.v1.rabl +3 -0
  85. data/app/views/spree/api/v1/products/product.v1.rabl +1 -0
  86. data/app/views/spree/api/v1/products/show.v1.rabl +32 -0
  87. data/app/views/spree/api/v1/promotions/handler.v1.rabl +5 -0
  88. data/app/views/spree/api/v1/promotions/show.v1.rabl +2 -0
  89. data/app/views/spree/api/v1/properties/index.v1.rabl +7 -0
  90. data/app/views/spree/api/v1/properties/new.v1.rabl +2 -0
  91. data/app/views/spree/api/v1/properties/show.v1.rabl +2 -0
  92. data/app/views/spree/api/v1/return_authorizations/index.v1.rabl +7 -0
  93. data/app/views/spree/api/v1/return_authorizations/new.v1.rabl +3 -0
  94. data/app/views/spree/api/v1/return_authorizations/show.v1.rabl +2 -0
  95. data/app/views/spree/api/v1/shared/stock_location_required.v1.rabl +2 -0
  96. data/app/views/spree/api/v1/shipments/big.v1.rabl +48 -0
  97. data/app/views/spree/api/v1/shipments/cannot_ready_shipment.v1.rabl +2 -0
  98. data/app/views/spree/api/v1/shipments/mine.v1.rabl +9 -0
  99. data/app/views/spree/api/v1/shipments/show.v1.rabl +32 -0
  100. data/app/views/spree/api/v1/shipments/small.v1.rabl +37 -0
  101. data/app/views/spree/api/v1/shipping_rates/show.v1.rabl +2 -0
  102. data/app/views/spree/api/v1/states/index.v1.rabl +14 -0
  103. data/app/views/spree/api/v1/states/show.v1.rabl +2 -0
  104. data/app/views/spree/api/v1/stock_items/index.v1.rabl +7 -0
  105. data/app/views/spree/api/v1/stock_items/show.v1.rabl +5 -0
  106. data/app/views/spree/api/v1/stock_locations/index.v1.rabl +7 -0
  107. data/app/views/spree/api/v1/stock_locations/show.v1.rabl +8 -0
  108. data/app/views/spree/api/v1/stock_movements/index.v1.rabl +7 -0
  109. data/app/views/spree/api/v1/stock_movements/show.v1.rabl +5 -0
  110. data/app/views/spree/api/v1/stores/index.v1.rabl +4 -0
  111. data/app/views/spree/api/v1/stores/show.v1.rabl +2 -0
  112. data/app/views/spree/api/v1/taxonomies/index.v1.rabl +7 -0
  113. data/app/views/spree/api/v1/taxonomies/jstree.rabl +8 -0
  114. data/app/views/spree/api/v1/taxonomies/nested.v1.rabl +11 -0
  115. data/app/views/spree/api/v1/taxonomies/new.v1.rabl +3 -0
  116. data/app/views/spree/api/v1/taxonomies/show.v1.rabl +15 -0
  117. data/app/views/spree/api/v1/taxons/index.v1.rabl +12 -0
  118. data/app/views/spree/api/v1/taxons/jstree.rabl +8 -0
  119. data/app/views/spree/api/v1/taxons/new.v1.rabl +3 -0
  120. data/app/views/spree/api/v1/taxons/show.v1.rabl +6 -0
  121. data/app/views/spree/api/v1/taxons/taxons.v1.rabl +5 -0
  122. data/app/views/spree/api/v1/users/index.v1.rabl +7 -0
  123. data/app/views/spree/api/v1/users/new.v1.rabl +3 -0
  124. data/app/views/spree/api/v1/users/show.v1.rabl +10 -0
  125. data/app/views/spree/api/v1/variants/big.v1.rabl +14 -0
  126. data/app/views/spree/api/v1/variants/index.v1.rabl +9 -0
  127. data/app/views/spree/api/v1/variants/new.v1.rabl +2 -0
  128. data/app/views/spree/api/v1/variants/show.v1.rabl +3 -0
  129. data/app/views/spree/api/v1/variants/small.v1.rabl +17 -0
  130. data/app/views/spree/api/v1/zones/index.v1.rabl +7 -0
  131. data/app/views/spree/api/v1/zones/show.v1.rabl +6 -0
  132. data/config/initializers/metal_load_paths.rb +1 -0
  133. data/config/locales/en.yml +27 -0
  134. data/config/routes.rb +128 -0
  135. data/db/migrate/20100107141738_add_api_key_to_spree_users.rb +7 -0
  136. data/db/migrate/20120411123334_resize_api_key_field.rb +7 -0
  137. data/db/migrate/20120530054546_rename_api_key_to_spree_api_key.rb +7 -0
  138. data/db/migrate/20131017162334_add_index_to_user_spree_api_key.rb +7 -0
  139. data/lib/spree/api/controller_setup.rb +20 -0
  140. data/lib/spree/api/engine.rb +35 -0
  141. data/lib/spree/api/responders/rabl_template.rb +30 -0
  142. data/lib/spree/api/responders.rb +11 -0
  143. data/lib/spree/api/testing_support/caching.rb +10 -0
  144. data/lib/spree/api/testing_support/helpers.rb +44 -0
  145. data/lib/spree/api/testing_support/setup.rb +16 -0
  146. data/lib/spree/api.rb +10 -0
  147. data/lib/spree_api.rb +2 -0
  148. data/script/rails +9 -0
  149. data/spec/fixtures/thinking-cat.jpg +0 -0
  150. data/spree_api.gemspec +20 -0
  151. metadata +221 -0
@@ -0,0 +1,60 @@
1
+ module Spree
2
+ module Api
3
+ module V1
4
+ class UsersController < Spree::Api::BaseController
5
+
6
+ rescue_from Spree::Core::DestroyWithOrdersError, with: :error_during_processing
7
+
8
+ def index
9
+ @users = Spree.user_class.accessible_by(current_ability,:read).ransack(params[:q]).result.page(params[:page]).per(params[:per_page])
10
+ respond_with(@users)
11
+ end
12
+
13
+ def show
14
+ respond_with(user)
15
+ end
16
+
17
+ def new
18
+ end
19
+
20
+ def create
21
+ authorize! :create, Spree.user_class
22
+ @user = Spree.user_class.new(user_params)
23
+ if @user.save
24
+ respond_with(@user, :status => 201, :default_template => :show)
25
+ else
26
+ invalid_resource!(@user)
27
+ end
28
+ end
29
+
30
+ def update
31
+ authorize! :update, user
32
+ if user.update_attributes(user_params)
33
+ respond_with(user, :status => 200, :default_template => :show)
34
+ else
35
+ invalid_resource!(user)
36
+ end
37
+ end
38
+
39
+ def destroy
40
+ authorize! :destroy, user
41
+ user.destroy
42
+ respond_with(user, :status => 204)
43
+ end
44
+
45
+ private
46
+
47
+ def user
48
+ @user ||= Spree.user_class.accessible_by(current_ability, :read).find(params[:id])
49
+ end
50
+
51
+ def user_params
52
+ params.require(:user).permit(permitted_user_attributes |
53
+ [bill_address_attributes: permitted_address_attributes,
54
+ ship_address_attributes: permitted_address_attributes])
55
+ end
56
+
57
+ end
58
+ end
59
+ end
60
+ end
@@ -0,0 +1,75 @@
1
+ module Spree
2
+ module Api
3
+ module V1
4
+ class VariantsController < Spree::Api::BaseController
5
+ before_action :product
6
+
7
+ def create
8
+ authorize! :create, Variant
9
+ @variant = scope.new(variant_params)
10
+ if @variant.save
11
+ respond_with(@variant, status: 201, default_template: :show)
12
+ else
13
+ invalid_resource!(@variant)
14
+ end
15
+ end
16
+
17
+ def destroy
18
+ @variant = scope.accessible_by(current_ability, :destroy).find(params[:id])
19
+ @variant.destroy
20
+ respond_with(@variant, status: 204)
21
+ end
22
+
23
+ # The lazyloaded associations here are pretty much attached to which nodes
24
+ # we render on the view so we better update it any time a node is included
25
+ # or removed from the views.
26
+ def index
27
+ @variants = scope.includes({ option_values: :option_type }, :product, :default_price, :images, { stock_items: :stock_location })
28
+ .ransack(params[:q]).result.page(params[:page]).per(params[:per_page])
29
+ respond_with(@variants)
30
+ end
31
+
32
+ def new
33
+ end
34
+
35
+ def show
36
+ @variant = scope.includes({ option_values: :option_type }, :option_values, :product, :default_price, :images, { stock_items: :stock_location })
37
+ .find(params[:id])
38
+ respond_with(@variant)
39
+ end
40
+
41
+ def update
42
+ @variant = scope.accessible_by(current_ability, :update).find(params[:id])
43
+ if @variant.update_attributes(variant_params)
44
+ respond_with(@variant, status: 200, default_template: :show)
45
+ else
46
+ invalid_resource!(@product)
47
+ end
48
+ end
49
+
50
+ private
51
+ def product
52
+ @product ||= Spree::Product.accessible_by(current_ability, :read).friendly.find(params[:product_id]) if params[:product_id]
53
+ end
54
+
55
+ def scope
56
+ if @product
57
+ variants = @product.variants_including_master
58
+ else
59
+ variants = Variant
60
+ end
61
+
62
+ if current_ability.can?(:manage, Variant) && params[:show_deleted]
63
+ variants = variants.with_deleted
64
+ end
65
+
66
+ variants.accessible_by(current_ability, :read)
67
+ end
68
+
69
+ def variant_params
70
+ params.require(:variant).permit(permitted_variant_attributes)
71
+ end
72
+ end
73
+ end
74
+ end
75
+ end
@@ -0,0 +1,51 @@
1
+ module Spree
2
+ module Api
3
+ module V1
4
+ class ZonesController < Spree::Api::BaseController
5
+
6
+ def create
7
+ authorize! :create, Zone
8
+ @zone = Zone.new(map_nested_attributes_keys(Spree::Zone, zone_params))
9
+ if @zone.save
10
+ respond_with(@zone, :status => 201, :default_template => :show)
11
+ else
12
+ invalid_resource!(@zone)
13
+ end
14
+ end
15
+
16
+ def destroy
17
+ authorize! :destroy, zone
18
+ zone.destroy
19
+ respond_with(zone, :status => 204)
20
+ end
21
+
22
+ def index
23
+ @zones = Zone.accessible_by(current_ability, :read).order('name ASC').ransack(params[:q]).result.page(params[:page]).per(params[:per_page])
24
+ respond_with(@zones)
25
+ end
26
+
27
+ def show
28
+ respond_with(zone)
29
+ end
30
+
31
+ def update
32
+ authorize! :update, zone
33
+ if zone.update_attributes(map_nested_attributes_keys(Spree::Zone, zone_params))
34
+ respond_with(zone, :status => 200, :default_template => :show)
35
+ else
36
+ invalid_resource!(zone)
37
+ end
38
+ end
39
+
40
+ private
41
+ def zone_params
42
+ params.require(:zone).permit!
43
+ end
44
+
45
+ def zone
46
+ @zone ||= Spree::Zone.accessible_by(current_ability, :read).find(params[:id])
47
+ end
48
+ end
49
+ end
50
+ end
51
+ end
@@ -0,0 +1,173 @@
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
+ ]
34
+
35
+ mattr_reader *ATTRIBUTES
36
+
37
+ def required_fields_for(model)
38
+ required_fields = model._validators.select do |field, validations|
39
+ validations.any? { |v| v.is_a?(ActiveModel::Validations::PresenceValidator) }
40
+ end.map(&:first) # get fields that are invalid
41
+ # Permalinks presence is validated, but are really automatically generated
42
+ # Therefore we shouldn't tell API clients that they MUST send one through
43
+ required_fields.map!(&:to_s).delete("permalink")
44
+ # Do not require slugs, either
45
+ required_fields.delete("slug")
46
+ required_fields
47
+ end
48
+
49
+ @@product_attributes = [
50
+ :id, :name, :description, :price, :display_price, :available_on,
51
+ :slug, :meta_description, :meta_keywords, :shipping_category_id,
52
+ :taxon_ids, :total_on_hand
53
+ ]
54
+
55
+ @@product_property_attributes = [
56
+ :id, :product_id, :property_id, :value, :property_name
57
+ ]
58
+
59
+ @@variant_attributes = [
60
+ :id, :name, :sku, :price, :weight, :height, :width, :depth, :is_master,
61
+ :slug, :description, :track_inventory
62
+ ]
63
+
64
+ @@image_attributes = [
65
+ :id, :position, :attachment_content_type, :attachment_file_name, :type,
66
+ :attachment_updated_at, :attachment_width, :attachment_height, :alt
67
+ ]
68
+
69
+ @@option_value_attributes = [
70
+ :id, :name, :presentation, :option_type_name, :option_type_id,
71
+ :option_type_presentation
72
+ ]
73
+
74
+ @@order_attributes = [
75
+ :id, :number, :item_total, :total, :ship_total, :state, :adjustment_total,
76
+ :user_id, :created_at, :updated_at, :completed_at, :payment_total,
77
+ :shipment_state, :payment_state, :email, :special_instructions, :channel,
78
+ :included_tax_total, :additional_tax_total, :display_included_tax_total,
79
+ :display_additional_tax_total, :tax_total, :currency, :considered_risky,
80
+ :canceler_id
81
+ ]
82
+
83
+ @@line_item_attributes = [:id, :quantity, :price, :variant_id]
84
+
85
+ @@option_type_attributes = [:id, :name, :presentation, :position]
86
+
87
+ @@payment_attributes = [
88
+ :id, :source_type, :source_id, :amount, :display_amount,
89
+ :payment_method_id, :state, :avs_response, :created_at,
90
+ :updated_at, :number
91
+ ]
92
+
93
+ @@payment_method_attributes = [:id, :name, :description]
94
+
95
+ @@shipment_attributes = [:id, :tracking, :number, :cost, :shipped_at, :state]
96
+
97
+ @@taxonomy_attributes = [:id, :name]
98
+
99
+ @@taxon_attributes = [
100
+ :id, :name, :pretty_name, :permalink, :parent_id,
101
+ :taxonomy_id
102
+ ]
103
+
104
+ @@inventory_unit_attributes = [
105
+ :id, :lock_version, :state, :variant_id, :shipment_id,
106
+ :return_authorization_id
107
+ ]
108
+
109
+ @@return_authorization_attributes = [
110
+ :id, :number, :state, :order_id, :memo, :created_at, :updated_at
111
+ ]
112
+
113
+ @@address_attributes = [
114
+ :id, :firstname, :lastname, :full_name, :address1, :address2, :city,
115
+ :zipcode, :phone, :company, :alternative_phone, :country_id, :state_id,
116
+ :state_name, :state_text
117
+ ]
118
+
119
+ @@country_attributes = [:id, :iso_name, :iso, :iso3, :name, :numcode]
120
+
121
+ @@state_attributes = [:id, :name, :abbr, :country_id]
122
+
123
+ @@adjustment_attributes = [
124
+ :id, :source_type, :source_id, :adjustable_type, :adjustable_id,
125
+ :originator_type, :originator_id, :amount, :label, :mandatory,
126
+ :locked, :eligible, :created_at, :updated_at
127
+ ]
128
+
129
+ @@creditcard_attributes = [
130
+ :id, :month, :year, :cc_type, :last_digits, :name,
131
+ :gateway_customer_profile_id, :gateway_payment_profile_id
132
+ ]
133
+
134
+ @@payment_source_attributes = [
135
+ :id, :month, :year, :cc_type, :last_digits, :name
136
+ ]
137
+
138
+ @@user_attributes = [:id, :email, :created_at, :updated_at]
139
+
140
+ @@property_attributes = [:id, :name, :presentation]
141
+
142
+ @@stock_location_attributes = [
143
+ :id, :name, :address1, :address2, :city, :state_id, :state_name,
144
+ :country_id, :zipcode, :phone, :active
145
+ ]
146
+
147
+ @@stock_movement_attributes = [:id, :quantity, :stock_item_id]
148
+
149
+ @@stock_item_attributes = [
150
+ :id, :count_on_hand, :backorderable, :lock_version, :stock_location_id,
151
+ :variant_id
152
+ ]
153
+
154
+ @@promotion_attributes = [
155
+ :id, :name, :description, :expires_at, :starts_at, :type, :usage_limit,
156
+ :match_policy, :code, :advertise, :path
157
+ ]
158
+
159
+ @@store_attributes = [
160
+ :id, :name, :url, :meta_description, :meta_keywords, :seo_title,
161
+ :mail_from_address, :default_currency, :code, :default
162
+ ]
163
+
164
+ def variant_attributes
165
+ if @current_user_roles && @current_user_roles.include?("admin")
166
+ @@variant_attributes + [:cost_price]
167
+ else
168
+ @@variant_attributes
169
+ end
170
+ end
171
+ end
172
+ end
173
+ end
@@ -0,0 +1,5 @@
1
+ module Spree
2
+ class ApiConfiguration < 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,2 @@
1
+ object false
2
+ node(:symbol) { ::Money.new(1, Spree::Config[:currency]).symbol }
@@ -0,0 +1,2 @@
1
+ object false
2
+ node(:default_country_id) { Spree::Config[:default_country_id] }
@@ -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,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.attachment_definitions[:attachment][:styles].each do |k,v|
5
+ node("#{k}_url") { |i| i.attachment.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,15 @@
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) { |li| li.total }
7
+ child :variant do
8
+ extends "spree/api/v1/variants/small"
9
+ attributes :product_id
10
+ child(:images => :images) { extends "spree/api/v1/images/show" }
11
+ end
12
+
13
+ child :adjustments => :adjustments do
14
+ extends "spree/api/v1/adjustments/show"
15
+ 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(: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) { |o| o.display_ship_total }
7
+ node(:display_tax_total) { |o| o.display_tax_total }
8
+ node(:display_adjustment_total) { |o| o.display_adjustment_total }
9
+ node(:token) { |o| o.guest_token }
10
+ node(:checkout_steps) { |o| o.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') }