dup_spree_api 1.3.0.rc1
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +17 -0
- data/.rspec +1 -0
- data/Gemfile +5 -0
- data/LICENSE +22 -0
- data/Rakefile +30 -0
- data/app/controllers/spree/api/addresses_controller.rb +20 -0
- data/app/controllers/spree/api/base_controller.rb +114 -0
- data/app/controllers/spree/api/countries_controller.rb +18 -0
- data/app/controllers/spree/api/images_controller.rb +32 -0
- data/app/controllers/spree/api/line_items_controller.rb +40 -0
- data/app/controllers/spree/api/orders_controller.rb +85 -0
- data/app/controllers/spree/api/payments_controller.rb +80 -0
- data/app/controllers/spree/api/product_properties_controller.rb +65 -0
- data/app/controllers/spree/api/products_controller.rb +49 -0
- data/app/controllers/spree/api/return_authorizations_controller.rb +54 -0
- data/app/controllers/spree/api/shipments_controller.rb +43 -0
- data/app/controllers/spree/api/taxonomies_controller.rb +50 -0
- data/app/controllers/spree/api/taxons_controller.rb +53 -0
- data/app/controllers/spree/api/variants_controller.rb +75 -0
- data/app/controllers/spree/api/zones_controller.rb +46 -0
- data/app/helpers/spree/api/api_helpers.rb +76 -0
- data/app/models/spree/api_configuration.rb +5 -0
- data/app/models/spree/line_item_decorator.rb +3 -0
- data/app/models/spree/option_value_decorator.rb +5 -0
- data/app/models/spree/order_decorator.rb +13 -0
- data/app/models/spree/user_decorator.rb +13 -0
- data/app/overrides/api_admin_user_edit_form.rb +6 -0
- data/app/views/spree/admin/users/_api_fields.html.erb +32 -0
- data/app/views/spree/api/addresses/show.v1.rabl +11 -0
- data/app/views/spree/api/countries/index.v1.rabl +7 -0
- data/app/views/spree/api/countries/show.v1.rabl +5 -0
- data/app/views/spree/api/errors/gateway_error.v1.rabl +2 -0
- data/app/views/spree/api/errors/invalid_api_key.v1.rabl +2 -0
- data/app/views/spree/api/errors/invalid_resource.v1.rabl +3 -0
- data/app/views/spree/api/errors/must_specify_api_key.v1.rabl +2 -0
- data/app/views/spree/api/errors/not_found.v1.rabl +2 -0
- data/app/views/spree/api/errors/unauthorized.v1.rabl +2 -0
- data/app/views/spree/api/images/show.v1.rabl +3 -0
- data/app/views/spree/api/line_items/new.v1.rabl +3 -0
- data/app/views/spree/api/line_items/show.v1.rabl +5 -0
- data/app/views/spree/api/orders/address.v1.rabl +0 -0
- data/app/views/spree/api/orders/canceled.v1.rabl +0 -0
- data/app/views/spree/api/orders/cart.v1.rabl +0 -0
- data/app/views/spree/api/orders/complete.v1.rabl +0 -0
- data/app/views/spree/api/orders/could_not_transition.v1.rabl +3 -0
- data/app/views/spree/api/orders/delivery.v1.rabl +3 -0
- data/app/views/spree/api/orders/index.v1.rabl +7 -0
- data/app/views/spree/api/orders/invalid_shipping_method.v1.rabl +2 -0
- data/app/views/spree/api/orders/payment.v1.rabl +4 -0
- data/app/views/spree/api/orders/show.v1.rabl +29 -0
- data/app/views/spree/api/payments/credit_over_limit.v1.rabl +2 -0
- data/app/views/spree/api/payments/index.v1.rabl +7 -0
- data/app/views/spree/api/payments/new.v1.rabl +6 -0
- data/app/views/spree/api/payments/show.v1.rabl +2 -0
- data/app/views/spree/api/product_properties/index.v1.rabl +7 -0
- data/app/views/spree/api/product_properties/new.v1.rabl +2 -0
- data/app/views/spree/api/product_properties/show.v1.rabl +2 -0
- data/app/views/spree/api/products/index.v1.rabl +8 -0
- data/app/views/spree/api/products/new.v1.rabl +3 -0
- data/app/views/spree/api/products/product.v1.rabl +1 -0
- data/app/views/spree/api/products/show.v1.rabl +25 -0
- data/app/views/spree/api/return_authorizations/index.v1.rabl +7 -0
- data/app/views/spree/api/return_authorizations/new.v1.rabl +3 -0
- data/app/views/spree/api/return_authorizations/show.v1.rabl +2 -0
- data/app/views/spree/api/shipments/cannot_ready_shipment.v1.rabl +2 -0
- data/app/views/spree/api/shipments/show.v1.rabl +7 -0
- data/app/views/spree/api/taxonomies/index.v1.rabl +7 -0
- data/app/views/spree/api/taxonomies/nested.v1.rabl +11 -0
- data/app/views/spree/api/taxonomies/new.v1.rabl +3 -0
- data/app/views/spree/api/taxonomies/show.v1.rabl +15 -0
- data/app/views/spree/api/taxons/index.v1.rabl +4 -0
- data/app/views/spree/api/taxons/new.v1.rabl +3 -0
- data/app/views/spree/api/taxons/show.v1.rabl +8 -0
- data/app/views/spree/api/taxons/taxons.v1.rabl +7 -0
- data/app/views/spree/api/variants/index.v1.rabl +10 -0
- data/app/views/spree/api/variants/new.v1.rabl +2 -0
- data/app/views/spree/api/variants/show.v1.rabl +3 -0
- data/app/views/spree/api/variants/variant.v1.rabl +1 -0
- data/app/views/spree/api/zones/index.v1.rabl +7 -0
- data/app/views/spree/api/zones/show.v1.rabl +6 -0
- data/config/initializers/metal_load_paths.rb +1 -0
- data/config/locales/en.yml +23 -0
- data/config/routes.rb +56 -0
- data/db/migrate/20100107141738_add_api_key_to_spree_users.rb +7 -0
- data/db/migrate/20120411123334_resize_api_key_field.rb +7 -0
- data/db/migrate/20120530054546_rename_api_key_to_spree_api_key.rb +7 -0
- data/lib/spree/api.rb +12 -0
- data/lib/spree/api/controller_setup.rb +27 -0
- data/lib/spree/api/engine.rb +35 -0
- data/lib/spree/api/responders.rb +11 -0
- data/lib/spree/api/responders/rabl_template.rb +22 -0
- data/lib/spree/api/testing_support/helpers.rb +35 -0
- data/lib/spree/api/testing_support/setup.rb +28 -0
- data/lib/spree/api/version.rb +5 -0
- data/lib/spree_api.rb +3 -0
- data/script/rails +9 -0
- data/spec/controllers/spree/api/addresses_controller_spec.rb +45 -0
- data/spec/controllers/spree/api/base_controller_spec.rb +42 -0
- data/spec/controllers/spree/api/countries_controller_spec.rb +48 -0
- data/spec/controllers/spree/api/images_controller_spec.rb +66 -0
- data/spec/controllers/spree/api/line_items_controller_spec.rb +77 -0
- data/spec/controllers/spree/api/orders_controller_spec.rb +255 -0
- data/spec/controllers/spree/api/payments_controller_spec.rb +203 -0
- data/spec/controllers/spree/api/product_properties_controller_spec.rb +116 -0
- data/spec/controllers/spree/api/products_controller_spec.rb +211 -0
- data/spec/controllers/spree/api/return_authorizations_controller_spec.rb +155 -0
- data/spec/controllers/spree/api/shipments_controller_spec.rb +59 -0
- data/spec/controllers/spree/api/taxonomies_controller_spec.rb +107 -0
- data/spec/controllers/spree/api/taxons_controller_spec.rb +87 -0
- data/spec/controllers/spree/api/unauthenticated_products_controller_spec.rb +26 -0
- data/spec/controllers/spree/api/variants_controller_spec.rb +155 -0
- data/spec/controllers/spree/api/zones_controller_spec.rb +111 -0
- data/spec/fixtures/thinking-cat.jpg +0 -0
- data/spec/models/spree/legacy_user_spec.rb +19 -0
- data/spec/models/spree/order_spec.rb +18 -0
- data/spec/shared_examples/protect_product_actions.rb +17 -0
- data/spec/spec_helper.rb +27 -0
- data/spec/support/controller_hacks.rb +27 -0
- data/spec/support/database_cleaner.rb +14 -0
- data/spec/support/have_attributes_matcher.rb +13 -0
- data/spree_api.gemspec +23 -0
- metadata +254 -0
@@ -0,0 +1,13 @@
|
|
1
|
+
Spree::Order.class_eval do
|
2
|
+
def self.build_from_api(user, params)
|
3
|
+
order = create
|
4
|
+
params[:line_items_attributes] ||= []
|
5
|
+
params[:line_items_attributes].each do |line_item|
|
6
|
+
order.add_variant(Spree::Variant.find(line_item[:variant_id]), line_item[:quantity])
|
7
|
+
end
|
8
|
+
|
9
|
+
order.user = user
|
10
|
+
order.email = user.email
|
11
|
+
order
|
12
|
+
end
|
13
|
+
end
|
@@ -0,0 +1,32 @@
|
|
1
|
+
<fieldset data-hook="admin_user_api_key" class="omega six columns">
|
2
|
+
<legend><%= t('access', :scope => 'spree.api') %></legend>
|
3
|
+
|
4
|
+
<% if @user.spree_api_key.present? %>
|
5
|
+
<div class="field">
|
6
|
+
<%= label_tag t('key', :scope => 'spree.api') %>:
|
7
|
+
<%= @user.spree_api_key %>
|
8
|
+
</div>
|
9
|
+
<div class="filter-actions actions">
|
10
|
+
<%= form_tag spree.clear_api_key_admin_user_path(@user), :method => :put do %>
|
11
|
+
<%= button t('clear_key', :scope => 'spree.api'), 'icon-trash' %>
|
12
|
+
<% end %>
|
13
|
+
|
14
|
+
<span class="or"><%= t(:or)%></span>
|
15
|
+
|
16
|
+
<%= form_tag spree.generate_api_key_admin_user_path(@user), :method => :put do %>
|
17
|
+
<%= button t('regenerate_key', :scope => 'spree.api'), 'icon-refresh' %>
|
18
|
+
<% end %>
|
19
|
+
</div>
|
20
|
+
|
21
|
+
<% else %>
|
22
|
+
|
23
|
+
<div class="no-objects-found"><%= t('no_key', :scope => 'spree.api') %></div>
|
24
|
+
|
25
|
+
<div class="filter-actions actions">
|
26
|
+
<%= form_tag spree.generate_api_key_admin_user_path(@user), :method => :put do %>
|
27
|
+
<%= button t('generate_key', :scope => 'spree.api'), 'icon-key' %>
|
28
|
+
<% end %>
|
29
|
+
</div>
|
30
|
+
<% end %>
|
31
|
+
|
32
|
+
</fieldset>
|
@@ -0,0 +1,11 @@
|
|
1
|
+
object @address
|
2
|
+
attributes :id, :firstname, :lastname, :address1, :address2,
|
3
|
+
:city, :zipcode, :phone,
|
4
|
+
:company, :alternative_phone, :country_id, :state_id,
|
5
|
+
:state_name
|
6
|
+
child(:country) do |address|
|
7
|
+
attributes :id, :iso_name, :iso, :iso3, :name, :numcode
|
8
|
+
end
|
9
|
+
child(:state) do |address|
|
10
|
+
attributes :abbr, :country_id, :id, :name
|
11
|
+
end
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
@@ -0,0 +1,29 @@
|
|
1
|
+
object @order
|
2
|
+
attributes *order_attributes
|
3
|
+
|
4
|
+
if lookup_context.find_all("spree/api/orders/#{@order.state}").present?
|
5
|
+
extends "spree/api/orders/#{@order.state}"
|
6
|
+
end
|
7
|
+
|
8
|
+
child :billing_address => :bill_address do
|
9
|
+
extends "spree/api/addresses/show"
|
10
|
+
end
|
11
|
+
|
12
|
+
child :shipping_address => :ship_address do
|
13
|
+
extends "spree/api/addresses/show"
|
14
|
+
end
|
15
|
+
|
16
|
+
child :line_items => :line_items do
|
17
|
+
extends "spree/api/line_items/show"
|
18
|
+
end
|
19
|
+
|
20
|
+
child :payments => :payments do
|
21
|
+
attributes :id, :amount, :state, :payment_method_id
|
22
|
+
child :payment_method => :payment_method do
|
23
|
+
attributes :id, :name, :environment
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
child :shipments => :shipments do
|
28
|
+
extends "spree/api/shipments/show"
|
29
|
+
end
|
@@ -0,0 +1 @@
|
|
1
|
+
attributes *product_attributes
|
@@ -0,0 +1,25 @@
|
|
1
|
+
object @product
|
2
|
+
attributes *product_attributes
|
3
|
+
child :variants_including_master => :variants do
|
4
|
+
attributes *variant_attributes
|
5
|
+
|
6
|
+
child :option_values => :option_values do
|
7
|
+
attributes *option_value_attributes
|
8
|
+
end
|
9
|
+
end
|
10
|
+
|
11
|
+
child :images => :images do
|
12
|
+
extends "spree/api/images/show"
|
13
|
+
end
|
14
|
+
|
15
|
+
child :option_types => :option_types do
|
16
|
+
attributes *option_type_attributes
|
17
|
+
|
18
|
+
child :option_values => :option_values do
|
19
|
+
attributes *option_value_attributes
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
child :product_properties => :product_properties do
|
24
|
+
attributes *product_property_attributes
|
25
|
+
end
|
@@ -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] || 1 }
|
7
|
+
node(:pages) { @return_authorizations.num_pages }
|
@@ -0,0 +1,15 @@
|
|
1
|
+
object @taxonomy
|
2
|
+
|
3
|
+
if set = params[:set]
|
4
|
+
extends "spree/api/taxonomies/#{set}"
|
5
|
+
else
|
6
|
+
attributes *taxonomy_attributes
|
7
|
+
|
8
|
+
child :root => :root do
|
9
|
+
attributes *taxon_attributes
|
10
|
+
|
11
|
+
child :children => :taxons do
|
12
|
+
attributes *taxon_attributes
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
@@ -0,0 +1,10 @@
|
|
1
|
+
object false
|
2
|
+
node(:count) { @variants.count }
|
3
|
+
node(:total_count) { @variants.total_count }
|
4
|
+
node(:current_page) { params[:page] ? params[:page].to_i : 1 }
|
5
|
+
node(:pages) { @variants.num_pages }
|
6
|
+
|
7
|
+
child(@variants => :variants) do
|
8
|
+
attributes *variant_attributes
|
9
|
+
child(:option_values => :option_values) { attributes *option_value_attributes }
|
10
|
+
end
|
@@ -0,0 +1 @@
|
|
1
|
+
attributes *variant_attributes
|