apispree_api 0.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (46) hide show
  1. data/LICENSE +26 -0
  2. data/README.md +16 -0
  3. data/app/controllers/admin/users_controller_decorator.rb +19 -0
  4. data/app/controllers/api/adjustments_controller.rb +13 -0
  5. data/app/controllers/api/analyses_controller.rb +134 -0
  6. data/app/controllers/api/base_controller.rb +187 -0
  7. data/app/controllers/api/checkout1_controller.rb +4 -0
  8. data/app/controllers/api/countries_controller.rb +14 -0
  9. data/app/controllers/api/images_controller.rb +15 -0
  10. data/app/controllers/api/inventory_units_controller.rb +19 -0
  11. data/app/controllers/api/line_items_controller.rb +37 -0
  12. data/app/controllers/api/mail_methods_controller.rb +10 -0
  13. data/app/controllers/api/option_types_controller.rb +24 -0
  14. data/app/controllers/api/orders_controller.rb +51 -0
  15. data/app/controllers/api/payment_methods_controller.rb +24 -0
  16. data/app/controllers/api/payments_controller.rb +3 -0
  17. data/app/controllers/api/product_groups_controller.rb +14 -0
  18. data/app/controllers/api/products_controller.rb +25 -0
  19. data/app/controllers/api/promotions_controller.rb +14 -0
  20. data/app/controllers/api/properties_controller.rb +26 -0
  21. data/app/controllers/api/prototypes_controller.rb +24 -0
  22. data/app/controllers/api/reports_controller.rb +8 -0
  23. data/app/controllers/api/shipments_controller.rb +37 -0
  24. data/app/controllers/api/shipping_categories_controller.rb +13 -0
  25. data/app/controllers/api/shipping_methods_controller.rb +24 -0
  26. data/app/controllers/api/states_controller.rb +19 -0
  27. data/app/controllers/api/tax_categories_controller.rb +24 -0
  28. data/app/controllers/api/tax_rates_controller.rb +24 -0
  29. data/app/controllers/api/taxonomies_controller.rb +12 -0
  30. data/app/controllers/api/taxons_controller.rb +17 -0
  31. data/app/controllers/api/users_controller.rb +3 -0
  32. data/app/controllers/api/variants_controller.rb +24 -0
  33. data/app/controllers/api/zones_controller.rb +24 -0
  34. data/app/models/line_item_decorator.rb +7 -0
  35. data/app/models/order_decorator.rb +5 -0
  36. data/app/models/shipment_decorator.rb +5 -0
  37. data/app/models/user_decorator.rb +22 -0
  38. data/app/views/admin/users/_api_fields.html.erb +16 -0
  39. data/config/cucumber.yml +10 -0
  40. data/config/locales/en.yml +16 -0
  41. data/config/routes.rb +144 -0
  42. data/db/migrate/20100107141738_add_api_key_to_users.rb +9 -0
  43. data/lib/apispree_api.rb +16 -0
  44. data/lib/spree_api_hooks.rb +3 -0
  45. data/lib/tasks/install.rake +23 -0
  46. metadata +112 -0
@@ -0,0 +1,37 @@
1
+ class Api::LineItemsController < Api::BaseController
2
+
3
+ private
4
+ def parent
5
+ if params[:order_id]
6
+ @parent ||= Order.find_by_param(params[:order_id])
7
+ end
8
+ end
9
+
10
+ def parent_data
11
+ params[:order_id]
12
+ end
13
+
14
+ def collection_serialization_options
15
+ { :include => [:variant], :methods => [:description] }
16
+ end
17
+
18
+ def object_serialization_options
19
+ collection_serialization_options
20
+ end
21
+ public
22
+ def create
23
+ quantity = params[:line_item][:quantity]
24
+ @variant = Variant.find_by_id(params[:line_item][:variant_id])
25
+ @order = current_order(true)
26
+ @order.add_variant(@variant, quantity.to_i) if quantity.to_i > 0
27
+ @response = Order.find_by_id(@order.id)
28
+ render :json => @response.to_json, :status => 201
29
+ end
30
+ def destroy
31
+ @object=LineItem.find_by_id(params[:id])
32
+ @object.destroy
33
+ if @object.destroy
34
+ render :text => 'Destroyed'
35
+ end
36
+ end
37
+ end
@@ -0,0 +1,10 @@
1
+ class Api::MailMethodsController < Api::BaseController
2
+ def testmail
3
+ p "$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$"
4
+ if TestMailer.test_email(@mail_method, current_user).deliver
5
+ respond_to do |f|
6
+ f.json {render :json=>{:response=>:sucess}}
7
+ end
8
+ end
9
+ end
10
+ end
@@ -0,0 +1,24 @@
1
+ class Api::OptionTypesController < Api::BaseController
2
+
3
+ # Looks like this action is unused
4
+ # def filtered
5
+ # @properties = Property.where('lower(name) LIKE ?', "%#{params[:q].mb_chars.downcase}%").order(:name)
6
+ # respond_with(@properties) do |format|
7
+ # format.html { render :template => "spree/admin/properties/filtered", :formats => [:html], :handlers => [:erb], :layout => false }
8
+ # end
9
+ # end
10
+ # end
11
+ # end
12
+ public
13
+ def destroy
14
+ puts "&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&"
15
+ puts params[object_name]
16
+ puts params[:id]
17
+ @object=OptionType.find_by_id(params[:id])
18
+ @object.destroy
19
+ if @object.destroy
20
+ render :text => 'Destroyed'
21
+ end
22
+ end
23
+
24
+ end
@@ -0,0 +1,51 @@
1
+ class Api::OrdersController < Api::BaseController
2
+ before_filter :access_denied, :except => [:index, :show,:create,:update,:destroy]
3
+
4
+ private
5
+
6
+ def find_resource
7
+ Order.find_by_param(params[:id])
8
+ end
9
+
10
+ def object_serialization_options
11
+ { :include => {
12
+ :bill_address => {:include => [:country, :state]},
13
+ :ship_address => {:include => [:country, :state]},
14
+ :shipments => {:include => [:shipping_method, :address]},
15
+ :line_items => {:include => [:variant]}
16
+ }
17
+ }
18
+ end
19
+ public
20
+ def update
21
+ @object=Order.find_by_id(params[:id])
22
+ if @object.update_attributes(params[object_name])
23
+
24
+ @response=Order.find_by_id(@object.id)
25
+ render :json => @response.to_json, :status => 201
26
+ else
27
+ respond_with(@object.errors, :status => 422)
28
+ end
29
+ end
30
+ def destroy
31
+ @object=Order.find_by_id(params[:id])
32
+ @object.destroy
33
+ if @object.destroy
34
+ render :text => 'Destroyed'
35
+ end
36
+
37
+ end
38
+
39
+ #~ def create
40
+ #~ @order = Order.new
41
+ #~ @order.user_id = current_user.id
42
+ #~ if @order.save
43
+ #~ #render :text => "Resource created\n", :status => 201, :location => object_url
44
+ #~ #render :text => @object.to_json, :status => 201, :location => object_url
45
+ #~ render :json => @object.to_json, :status => 201
46
+ #~ else
47
+ #~ respond_with(@object.errors, :status => 422)
48
+ #~ end
49
+ #~ end
50
+
51
+ end
@@ -0,0 +1,24 @@
1
+ class Api::PaymentMethodsController< Api::BaseController
2
+
3
+ # Looks like this action is unused
4
+ # def filtered
5
+ # @properties = Property.where('lower(name) LIKE ?', "%#{params[:q].mb_chars.downcase}%").order(:name)
6
+ # respond_with(@properties) do |format|
7
+ # format.html { render :template => "spree/admin/properties/filtered", :formats => [:html], :handlers => [:erb], :layout => false }
8
+ # end
9
+ # end
10
+ # end
11
+ # end
12
+ public
13
+ def destroy
14
+ puts "&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&"
15
+ puts params[object_name]
16
+ puts params[:id]
17
+ @object=PaymentMethod.find_by_id(params[:id])
18
+ @object.destroy
19
+ if @object.destroy
20
+ render :text => 'Destroyed'
21
+ end
22
+ end
23
+
24
+ end
@@ -0,0 +1,3 @@
1
+ class Api::PaymentsController < Admin::PaymentsController
2
+
3
+ end
@@ -0,0 +1,14 @@
1
+ class Api::ProductGroupsController < Api::BaseController
2
+ public
3
+ def destroy
4
+ puts "&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&"
5
+ puts params[object_name]
6
+ puts params[:id]
7
+ @object=ProductGroup.find_by_id(params[:id])
8
+ @object.destroy
9
+ if @object.destroy
10
+ render :text => 'Destroyed'
11
+ end
12
+ end
13
+
14
+ end
@@ -0,0 +1,25 @@
1
+ class Api::ProductsController < Api::BaseController
2
+ include Spree::Search
3
+
4
+ private
5
+ def collection
6
+ params[:per_page] ||= 100
7
+ @searcher = Spree::Config.searcher_class.new(params)
8
+ @collection = @searcher.retrieve_products
9
+ end
10
+
11
+ def object_serialization_options
12
+ { :include => [:master, :variants, :taxons] }
13
+ end
14
+ public
15
+ def destroy
16
+ puts "&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&"
17
+ puts params[object_name]
18
+ puts params[:id]
19
+ @object=Product.find_by_id(params[:id])
20
+ @object.destroy
21
+ if @object.destroy
22
+ render :text => 'Destroyed'
23
+ end
24
+ end
25
+ end
@@ -0,0 +1,14 @@
1
+ class Api::PromotionsController < Api::BaseController
2
+
3
+ public
4
+ def destroy
5
+ puts "&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&"
6
+ puts params[object_name]
7
+ puts params[:id]
8
+ @object=Promotion.find_by_id(params[:id])
9
+ @object.destroy
10
+ if @object.destroy
11
+ render :text => 'Destroyed'
12
+ end
13
+ end
14
+ end
@@ -0,0 +1,26 @@
1
+ # module Spree
2
+ # module Admin
3
+ class Api::PropertiesController < Api::BaseController
4
+
5
+ # Looks like this action is unused
6
+ # def filtered
7
+ # @properties = Property.where('lower(name) LIKE ?', "%#{params[:q].mb_chars.downcase}%").order(:name)
8
+ # respond_with(@properties) do |format|
9
+ # format.html { render :template => "spree/admin/properties/filtered", :formats => [:html], :handlers => [:erb], :layout => false }
10
+ # end
11
+ # end
12
+ # end
13
+ # end
14
+ public
15
+ def destroy
16
+ puts "&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&"
17
+ puts params[object_name]
18
+ puts params[:id]
19
+ @object=Property.find_by_id(params[:id])
20
+ @object.destroy
21
+ if @object.destroy
22
+ render :text => 'Destroyed'
23
+ end
24
+ end
25
+
26
+ end
@@ -0,0 +1,24 @@
1
+ class Api::PrototypesController < Api::BaseController
2
+
3
+ # Looks like this action is unused
4
+ # def filtered
5
+ # @properties = Property.where('lower(name) LIKE ?', "%#{params[:q].mb_chars.downcase}%").order(:name)
6
+ # respond_with(@properties) do |format|
7
+ # format.html { render :template => "spree/admin/properties/filtered", :formats => [:html], :handlers => [:erb], :layout => false }
8
+ # end
9
+ # end
10
+ # end
11
+ # end
12
+ public
13
+ def destroy
14
+ puts "&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&"
15
+ puts params[object_name]
16
+ puts params[:id]
17
+ @object=Prototype.find_by_id(params[:id])
18
+ @object.destroy
19
+ if @object.destroy
20
+ render :text => 'Destroyed'
21
+ end
22
+ end
23
+
24
+ end
@@ -0,0 +1,8 @@
1
+ class Api::ReportsController < Api::BaseController
2
+ def sales_total
3
+ @search = Order.metasearch(params[:search])
4
+ @item_total = @search.sum(:item_total)
5
+ @adjustment_total = @search.sum(:adjustment_total)
6
+ @sales_total = @search.sum(:total)
7
+ end
8
+ end
@@ -0,0 +1,37 @@
1
+ class Api::ShipmentsController < Admin::ShipmentsController
2
+
3
+ #~ private
4
+ #~ def parent
5
+ #~ if params[:order_id]
6
+ #~ @parent ||= Order.find_by_param(params[:order_id])
7
+ #~ end
8
+ #~ end
9
+
10
+ #~ def collection_serialization_options
11
+ #~ { :include => {:shipping_method => {}, :address => {}, :inventory_units => {:include => :variant}},
12
+ #~ :except => [:shipping_method_id, :address_id] }
13
+ #~ end
14
+
15
+ #~ def object_serialization_options
16
+ #~ { :include => {
17
+ #~ :shipping_method => {},
18
+ #~ :address => {:include => [:country, :state]},
19
+ #~ :inventory_units => {
20
+ #~ :include => {
21
+ #~ :variant => {
22
+ #~ :include => {
23
+ #~ :product => {:only => [:name]}
24
+ #~ }
25
+ #~ }
26
+ #~ }
27
+ #~ }
28
+ #~ },
29
+ #~ :except => [:shipping_method_id, :address_id]
30
+ #~ }
31
+ #~ end
32
+
33
+ #~ def eager_load_associations
34
+ #~ [:shipping_method, :address, {:inventory_units => [:variant]}]
35
+ #~ end
36
+
37
+ end
@@ -0,0 +1,13 @@
1
+ class Api::ShippingCategoriesController < Api::BaseController
2
+ public
3
+ def destroy
4
+ puts "&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&"
5
+ puts params[object_name]
6
+ puts params[:id]
7
+ @object=ShippingCategory.find_by_id(params[:id])
8
+ @object.destroy
9
+ if @object.destroy
10
+ render :text => 'Destroyed Successfully'
11
+ end
12
+ end
13
+ end
@@ -0,0 +1,24 @@
1
+ class Api::ShippingMethodsController < Api::BaseController
2
+
3
+ # Looks like this action is unused
4
+ # def filtered
5
+ # @properties = Property.where('lower(name) LIKE ?', "%#{params[:q].mb_chars.downcase}%").order(:name)
6
+ # respond_with(@properties) do |format|
7
+ # format.html { render :template => "spree/admin/properties/filtered", :formats => [:html], :handlers => [:erb], :layout => false }
8
+ # end
9
+ # end
10
+ # end
11
+ # end
12
+ public
13
+ def destroy
14
+ puts "&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&"
15
+
16
+ puts params[:id]
17
+ @object=ShippingMethod.find_by_id(params[:id])
18
+ @object.destroy
19
+ if @object.destroy
20
+ render :text => "Status => Success", :status => 201
21
+ end
22
+ end
23
+
24
+ end
@@ -0,0 +1,19 @@
1
+ class Api::StatesController < Api::BaseController
2
+ before_filter :access_denied, :except => [:index, :show,:create,:update,:destroy]
3
+
4
+ private
5
+ def parent
6
+ @parent ||= Country.find(params[:country_id])
7
+ end
8
+ public
9
+ def destroy
10
+ puts "&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&"
11
+ puts params[object_name]
12
+ puts params[:id]
13
+ @object=State.find_by_id(params[:id])
14
+ @object.destroy
15
+ if @object.destroy
16
+ render :text => 'Destroyed'
17
+ end
18
+ end
19
+ end
@@ -0,0 +1,24 @@
1
+ class Api::TaxCategoriesController < Api::BaseController
2
+
3
+ # Looks like this action is unused
4
+ # def filtered
5
+ # @properties = Property.where('lower(name) LIKE ?', "%#{params[:q].mb_chars.downcase}%").order(:name)
6
+ # respond_with(@properties) do |format|
7
+ # format.html { render :template => "spree/admin/properties/filtered", :formats => [:html], :handlers => [:erb], :layout => false }
8
+ # end
9
+ # end
10
+ # end
11
+ # end
12
+ public
13
+ def destroy
14
+ puts "&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&"
15
+ puts params[object_name]
16
+ puts params[:id]
17
+ @object=TaxCategory.find_by_id(params[:id])
18
+ @object.destroy
19
+ if @object.destroy
20
+ render :text => 'Destroyed'
21
+ end
22
+ end
23
+
24
+ end
@@ -0,0 +1,24 @@
1
+ class Api::TaxRatesController < Api::BaseController
2
+
3
+ # Looks like this action is unused
4
+ # def filtered
5
+ # @properties = Property.where('lower(name) LIKE ?', "%#{params[:q].mb_chars.downcase}%").order(:name)
6
+ # respond_with(@properties) do |format|
7
+ # format.html { render :template => "spree/admin/properties/filtered", :formats => [:html], :handlers => [:erb], :layout => false }
8
+ # end
9
+ # end
10
+ # end
11
+ # end
12
+ public
13
+ def destroy
14
+ puts "&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&"
15
+ puts params[object_name]
16
+ puts params[:id]
17
+ @object=TaxRate.find_by_id(params[:id])
18
+ @object.destroy
19
+ if @object.destroy
20
+ render :text => 'Destroyed'
21
+ end
22
+ end
23
+
24
+ end
@@ -0,0 +1,12 @@
1
+ class Api::TaxonomiesController < Api::BaseController
2
+
3
+ public
4
+ def destroy
5
+ puts params[:id]
6
+ @object=Taxonomy.find_by_id(params[:id])
7
+ @object.destroy
8
+ if @object.destroy
9
+ render :text => "Status => Success", :status => 201
10
+ end
11
+ end
12
+ end
@@ -0,0 +1,17 @@
1
+ class Api::TaxonsController < Api::BaseController
2
+ # def index
3
+ # @taxons=Spree::Taxon.all
4
+ # puts @taxons
5
+ # end
6
+ public
7
+ def destroy
8
+ puts params[:id]
9
+ @object=Taxon.find_by_id(params[:id])
10
+ @object.destroy
11
+ if @object.destroy
12
+ render :text => "Status => Success", :status => 201
13
+ end
14
+ end
15
+
16
+
17
+ end