spree_api 1.3.5 → 2.0.0.rc1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +14 -6
- data/Rakefile +1 -1
- data/app/controllers/spree/api/addresses_controller.rb +0 -1
- data/app/controllers/spree/api/base_controller.rb +21 -9
- data/app/controllers/spree/api/checkouts_controller.rb +40 -20
- data/app/controllers/spree/api/countries_controller.rb +0 -1
- data/app/controllers/spree/api/inventory_units_controller.rb +1 -1
- data/app/controllers/spree/api/option_types_controller.rb +46 -0
- data/app/controllers/spree/api/option_values_controller.rb +56 -0
- data/app/controllers/spree/api/orders_controller.rb +1 -21
- data/app/controllers/spree/api/product_properties_controller.rb +0 -1
- data/app/controllers/spree/api/products_controller.rb +12 -27
- data/app/controllers/spree/api/properties_controller.rb +61 -0
- data/app/controllers/spree/api/shipments_controller.rb +51 -1
- data/app/controllers/spree/api/states_controller.rb +32 -0
- data/app/controllers/spree/api/stock_items_controller.rb +70 -0
- data/app/controllers/spree/api/stock_locations_controller.rb +45 -0
- data/app/controllers/spree/api/stock_movements_controller.rb +55 -0
- data/app/controllers/spree/api/taxonomies_controller.rb +5 -0
- data/app/controllers/spree/api/taxons_controller.rb +16 -2
- data/app/controllers/spree/api/variants_controller.rb +1 -1
- data/app/controllers/spree/api/zones_controller.rb +0 -1
- data/app/helpers/spree/api/api_helpers.rb +34 -7
- data/app/models/spree/api_configuration.rb +1 -2
- data/app/models/spree/line_item_decorator.rb +1 -1
- data/app/models/spree/order_decorator.rb +6 -169
- data/app/overrides/api_admin_user_edit_form.rb +7 -6
- data/app/views/spree/admin/users/_api_fields.html.erb +7 -8
- data/app/views/spree/api/addresses/show.v1.rabl +2 -2
- data/app/views/spree/api/adjustments/show.v1.rabl +2 -0
- data/app/views/spree/api/credit_cards/show.v1.rabl +2 -0
- data/app/views/spree/api/option_types/index.v1.rabl +3 -0
- data/app/views/spree/api/option_types/show.v1.rabl +5 -0
- data/app/views/spree/api/option_values/index.v1.rabl +3 -0
- data/app/views/spree/api/option_values/show.v1.rabl +2 -0
- data/app/views/spree/api/orders/could_not_apply_coupon.v1.rabl +2 -0
- data/app/views/spree/api/orders/delivery.v1.rabl +2 -2
- data/app/views/spree/api/orders/payment.v1.rabl +3 -0
- data/app/views/spree/api/orders/show.v1.rabl +8 -0
- data/app/views/spree/api/properties/index.v1.rabl +7 -0
- data/app/views/spree/api/properties/new.v1.rabl +2 -0
- data/app/views/spree/api/properties/show.v1.rabl +2 -0
- data/app/views/spree/api/shared/stock_location_required.v1.rabl +2 -0
- data/app/views/spree/api/shipments/show.v1.rabl +7 -0
- data/app/views/spree/api/states/index.v1.rabl +14 -0
- data/app/views/spree/api/states/show.v1.rabl +2 -0
- data/app/views/spree/api/stock_items/index.v1.rabl +7 -0
- data/app/views/spree/api/stock_items/show.v1.rabl +5 -0
- data/app/views/spree/api/stock_locations/index.v1.rabl +7 -0
- data/app/views/spree/api/stock_locations/show.v1.rabl +8 -0
- data/app/views/spree/api/stock_movements/index.v1.rabl +7 -0
- data/app/views/spree/api/stock_movements/show.v1.rabl +5 -0
- data/app/views/spree/api/taxonomies/jstree.rabl +8 -0
- data/app/views/spree/api/taxons/jstree.rabl +8 -0
- data/app/views/spree/api/variants/index.v1.rabl +14 -1
- data/app/views/spree/api/variants/variant.v1.rabl +0 -4
- data/config/locales/en.yml +1 -0
- data/config/routes.rb +29 -3
- data/lib/spree/api.rb +0 -2
- data/lib/spree/api/controller_setup.rb +6 -1
- data/lib/spree/api/testing_support/helpers.rb +1 -1
- data/lib/spree/api/testing_support/setup.rb +13 -0
- data/spec/controllers/spree/api/base_controller_spec.rb +14 -1
- data/spec/controllers/spree/api/checkouts_controller_spec.rb +59 -28
- data/spec/controllers/spree/api/line_items_controller_spec.rb +1 -5
- data/spec/controllers/spree/api/option_types_controller_spec.rb +116 -0
- data/spec/controllers/spree/api/option_values_controller_spec.rb +128 -0
- data/spec/controllers/spree/api/orders_controller_spec.rb +11 -93
- data/spec/controllers/spree/api/product_properties_controller_spec.rb +2 -2
- data/spec/controllers/spree/api/products_controller_spec.rb +18 -76
- data/spec/controllers/spree/api/properties_controller_spec.rb +89 -0
- data/spec/controllers/spree/api/return_authorizations_controller_spec.rb +1 -9
- data/spec/controllers/spree/api/shipments_controller_spec.rb +80 -5
- data/spec/controllers/spree/api/states_controller_spec.rb +76 -0
- data/spec/controllers/spree/api/stock_items_controller_spec.rb +88 -0
- data/spec/controllers/spree/api/stock_locations_controller_spec.rb +86 -0
- data/spec/controllers/spree/api/stock_movements_controller_spec.rb +72 -0
- data/spec/controllers/spree/api/taxonomies_controller_spec.rb +7 -0
- data/spec/controllers/spree/api/taxons_controller_spec.rb +29 -2
- data/spec/controllers/spree/api/unauthenticated_products_controller_spec.rb +1 -1
- data/spec/controllers/spree/api/variants_controller_spec.rb +5 -16
- data/spec/fixtures/thinking-cat.jpg +0 -0
- data/spec/models/spree/order_spec.rb +7 -328
- data/spec/spec_helper.rb +18 -2
- data/spree_api.gemspec +2 -1
- metadata +67 -16
- data/.rspec +0 -1
- data/app/controllers/spree/base_controller_decorator.rb +0 -15
- data/app/overrides/api_key_spree_layout.rb +0 -7
- data/app/views/spree/api/_key.html.erb +0 -4
- data/db/migrate/20131017162334_add_index_to_user_spree_api_key.rb +0 -7
@@ -1,6 +1,7 @@
|
|
1
|
-
Deface
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
1
|
+
if defined?(Deface)
|
2
|
+
Deface::Override.new(:virtual_path => "spree/admin/users/edit",
|
3
|
+
:name => "api_admin_user_edit_form",
|
4
|
+
:insert_after => "[data-hook='admin_user_edit_general_settings']",
|
5
|
+
:partial => "spree/admin/users/api_fields",
|
6
|
+
:disabled => false)
|
7
|
+
end
|
@@ -1,32 +1,31 @@
|
|
1
1
|
<fieldset data-hook="admin_user_api_key" class="omega six columns">
|
2
|
-
<legend><%= t('access', :scope => '
|
2
|
+
<legend><%= Spree.t('access', :scope => 'api') %></legend>
|
3
3
|
|
4
4
|
<% if @user.spree_api_key.present? %>
|
5
5
|
<div class="field">
|
6
|
-
<%= label_tag t('key', :scope => '
|
6
|
+
<%= label_tag Spree.t('key', :scope => 'api') %>:
|
7
7
|
<%= @user.spree_api_key %>
|
8
8
|
</div>
|
9
9
|
<div class="filter-actions actions">
|
10
10
|
<%= form_tag spree.clear_api_key_admin_user_path(@user), :method => :put do %>
|
11
|
-
<%= button t('clear_key', :scope => '
|
11
|
+
<%= button Spree.t('clear_key', :scope => 'api'), 'icon-trash' %>
|
12
12
|
<% end %>
|
13
13
|
|
14
|
-
<span class="or"><%= t(:or)%></span>
|
14
|
+
<span class="or"><%= Spree.t(:or)%></span>
|
15
15
|
|
16
16
|
<%= form_tag spree.generate_api_key_admin_user_path(@user), :method => :put do %>
|
17
|
-
<%= button t('regenerate_key', :scope => '
|
17
|
+
<%= button Spree.t('regenerate_key', :scope => 'api'), 'icon-refresh' %>
|
18
18
|
<% end %>
|
19
19
|
</div>
|
20
20
|
|
21
21
|
<% else %>
|
22
22
|
|
23
|
-
<div class="no-objects-found"><%= t('no_key', :scope => '
|
23
|
+
<div class="no-objects-found"><%= Spree.t('no_key', :scope => 'api') %></div>
|
24
24
|
|
25
25
|
<div class="filter-actions actions">
|
26
26
|
<%= form_tag spree.generate_api_key_admin_user_path(@user), :method => :put do %>
|
27
|
-
<%= button t('generate_key', :scope => '
|
27
|
+
<%= button Spree.t('generate_key', :scope => 'api'), 'icon-key' %>
|
28
28
|
<% end %>
|
29
29
|
</div>
|
30
30
|
<% end %>
|
31
|
-
|
32
31
|
</fieldset>
|
@@ -4,8 +4,8 @@ attributes :id, :firstname, :lastname, :address1, :address2,
|
|
4
4
|
:company, :alternative_phone, :country_id, :state_id,
|
5
5
|
:state_name
|
6
6
|
child(:country) do |address|
|
7
|
-
attributes
|
7
|
+
attributes *country_attributes
|
8
8
|
end
|
9
9
|
child(:state) do |address|
|
10
|
-
attributes
|
10
|
+
attributes *state_attributes
|
11
11
|
end
|
@@ -1,3 +1,3 @@
|
|
1
|
-
child(:
|
2
|
-
|
1
|
+
child(:shipments => :shipments) do
|
2
|
+
extends "spree/api/shipments/show"
|
3
3
|
end
|
@@ -27,3 +27,11 @@ end
|
|
27
27
|
child :shipments => :shipments do
|
28
28
|
extends "spree/api/shipments/show"
|
29
29
|
end
|
30
|
+
|
31
|
+
child :adjustments => :adjustments do
|
32
|
+
extends "spree/api/adjustments/show"
|
33
|
+
end
|
34
|
+
|
35
|
+
child :credit_cards => :credit_cards do
|
36
|
+
extends "spree/api/credit_cards/show"
|
37
|
+
end
|
@@ -1,7 +1,14 @@
|
|
1
1
|
object @shipment
|
2
2
|
attributes *shipment_attributes
|
3
3
|
node(:order_id) { |shipment| shipment.order.number }
|
4
|
+
node(:stock_location_name) { |shipment| shipment.stock_location.name }
|
5
|
+
child :shipping_rates => :shipping_rates do
|
6
|
+
attributes :id, :cost, :selected, :shipment_id, :shipping_method_id
|
7
|
+
end
|
4
8
|
child :shipping_method => :shipping_method do
|
5
9
|
attributes :name, :zone_id, :shipping_category_id
|
6
10
|
end
|
7
11
|
|
12
|
+
child :inventory_units => :inventory_units do
|
13
|
+
attribute *inventory_unit_attributes
|
14
|
+
end
|
@@ -0,0 +1,14 @@
|
|
1
|
+
object false
|
2
|
+
if @country
|
3
|
+
node(:states_required) { @country.states_required }
|
4
|
+
end
|
5
|
+
|
6
|
+
child(@states => :states) do
|
7
|
+
attributes *state_attributes
|
8
|
+
end
|
9
|
+
|
10
|
+
if @states.respond_to?(:num_pages)
|
11
|
+
node(:count) { @states.count }
|
12
|
+
node(:current_page) { params[:page] || 1 }
|
13
|
+
node(:pages) { @states.num_pages }
|
14
|
+
end
|
@@ -7,5 +7,18 @@ node(:pages) { @variants.num_pages }
|
|
7
7
|
child(@variants => :variants) do
|
8
8
|
attributes *variant_attributes
|
9
9
|
child(:option_values => :option_values) { attributes *option_value_attributes }
|
10
|
-
child(:images => :images)
|
10
|
+
child(:images => :images) do
|
11
|
+
attributes *image_attributes
|
12
|
+
code(:urls) do |v|
|
13
|
+
v.attachment.styles.keys.inject({}) { |urls, style| urls[style] = v.attachment.url(style); urls }
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
child(:stock_items) do
|
18
|
+
attributes :id, :count_on_hand, :stock_location_id, :backorderable
|
19
|
+
|
20
|
+
glue(:stock_location) do
|
21
|
+
attribute :name => :stock_location_name
|
22
|
+
end
|
23
|
+
end
|
11
24
|
end
|
data/config/locales/en.yml
CHANGED
@@ -21,4 +21,5 @@ en:
|
|
21
21
|
invalid_shipping_method: "Invalid shipping method specified."
|
22
22
|
shipment:
|
23
23
|
cannot_ready: "Cannot ready shipment."
|
24
|
+
stock_location_required: "A stock_location_id parameter must be provided in order to retrieve stock movements."
|
24
25
|
invalid_taxonomy_id: "Invalid taxonomy id."
|
data/config/routes.rb
CHANGED
@@ -15,10 +15,19 @@ Spree::Core::Engine.routes.draw do
|
|
15
15
|
end
|
16
16
|
|
17
17
|
resources :images
|
18
|
-
resources :checkouts
|
18
|
+
resources :checkouts do
|
19
|
+
member do
|
20
|
+
put :next
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
19
24
|
resources :variants, :only => [:index] do
|
20
25
|
end
|
21
26
|
|
27
|
+
resources :option_types do
|
28
|
+
resources :option_values
|
29
|
+
end
|
30
|
+
|
22
31
|
resources :orders do
|
23
32
|
resources :return_authorizations
|
24
33
|
member do
|
@@ -39,21 +48,38 @@ Spree::Core::Engine.routes.draw do
|
|
39
48
|
end
|
40
49
|
end
|
41
50
|
|
42
|
-
resources :shipments do
|
51
|
+
resources :shipments, :only => [:create, :update] do
|
43
52
|
member do
|
44
53
|
put :ready
|
45
54
|
put :ship
|
55
|
+
put :add
|
56
|
+
put :remove
|
46
57
|
end
|
47
58
|
end
|
48
59
|
end
|
49
60
|
|
50
61
|
resources :zones
|
51
62
|
resources :countries, :only => [:index, :show]
|
63
|
+
resources :states, :only => [:index, :show]
|
52
64
|
resources :addresses, :only => [:show, :update]
|
65
|
+
|
53
66
|
resources :taxonomies do
|
54
|
-
|
67
|
+
member do
|
68
|
+
get :jstree
|
69
|
+
end
|
70
|
+
resources :taxons do
|
71
|
+
member do
|
72
|
+
get :jstree
|
73
|
+
end
|
74
|
+
end
|
55
75
|
end
|
76
|
+
resources :taxons, :only => [:index]
|
56
77
|
resources :inventory_units, :only => [:show, :update]
|
57
78
|
resources :users
|
79
|
+
resources :properties
|
80
|
+
resources :stock_locations do
|
81
|
+
resources :stock_movements
|
82
|
+
resources :stock_items
|
83
|
+
end
|
58
84
|
end
|
59
85
|
end
|
data/lib/spree/api.rb
CHANGED
@@ -1,3 +1,5 @@
|
|
1
|
+
require 'spree/api/responders'
|
2
|
+
|
1
3
|
module Spree
|
2
4
|
module Api
|
3
5
|
module ControllerSetup
|
@@ -14,12 +16,15 @@ module Spree
|
|
14
16
|
include ActionController::ImplicitRender
|
15
17
|
include ActionController::Rescue
|
16
18
|
include ActionController::MimeResponds
|
19
|
+
include ActionController::Head
|
17
20
|
|
18
21
|
include CanCan::ControllerAdditions
|
19
|
-
include
|
22
|
+
include Spree::Core::ControllerHelpers::Auth
|
23
|
+
|
20
24
|
prepend_view_path Rails.root + "app/views"
|
21
25
|
append_view_path File.expand_path("../../../app/views", File.dirname(__FILE__))
|
22
26
|
|
27
|
+
self.responder = Spree::Api::Responders::AppResponder
|
23
28
|
respond_to :json
|
24
29
|
end
|
25
30
|
end
|
@@ -9,6 +9,19 @@ module Spree
|
|
9
9
|
user
|
10
10
|
end
|
11
11
|
end
|
12
|
+
|
13
|
+
# Default kaminari's pagination to a certain range
|
14
|
+
# Means that you don't need to create 25 objects to test pagination
|
15
|
+
def default_per_page(count)
|
16
|
+
before do
|
17
|
+
@current_default_per_page = Kaminari.config.default_per_page
|
18
|
+
Kaminari.config.default_per_page = 1
|
19
|
+
end
|
20
|
+
|
21
|
+
after do
|
22
|
+
Kaminari.config.default_per_page = @current_default_per_page
|
23
|
+
end
|
24
|
+
end
|
12
25
|
end
|
13
26
|
end
|
14
27
|
end
|
@@ -4,7 +4,20 @@ describe Spree::Api::BaseController do
|
|
4
4
|
render_views
|
5
5
|
controller(Spree::Api::BaseController) do
|
6
6
|
def index
|
7
|
-
render :
|
7
|
+
render :text => { "products" => [] }.to_json
|
8
|
+
end
|
9
|
+
end
|
10
|
+
|
11
|
+
context "signed in as a user using an authentication extension" do
|
12
|
+
before do
|
13
|
+
controller.stub :try_spree_current_user => stub(:email => "spree@example.com")
|
14
|
+
Spree::Api::Config[:requires_authentication] = true
|
15
|
+
end
|
16
|
+
|
17
|
+
it "can make a request" do
|
18
|
+
api_get :index
|
19
|
+
json_response.should == { "products" => [] }
|
20
|
+
response.status.should == 200
|
8
21
|
end
|
9
22
|
end
|
10
23
|
|