rfcommerce_api 0.0.3

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 (47) hide show
  1. data/Gemfile +36 -0
  2. data/LICENSE +26 -0
  3. data/README.md +16 -0
  4. data/app/controllers/admin/users_controller_decorator.rb +19 -0
  5. data/app/controllers/api/adjustments_controller.rb +13 -0
  6. data/app/controllers/api/base_controller.rb +183 -0
  7. data/app/controllers/api/checkout1_controller.rb +89 -0
  8. data/app/controllers/api/countries_controller.rb +3 -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/overview_controller.rb +132 -0
  16. data/app/controllers/api/payment_methods_controller.rb +24 -0
  17. data/app/controllers/api/payments_controller.rb +3 -0
  18. data/app/controllers/api/product_groups_controller.rb +14 -0
  19. data/app/controllers/api/products_controller.rb +14 -0
  20. data/app/controllers/api/promotions_controller.rb +14 -0
  21. data/app/controllers/api/properties_controller.rb +26 -0
  22. data/app/controllers/api/prototypes_controller.rb +24 -0
  23. data/app/controllers/api/reports_controller.rb +8 -0
  24. data/app/controllers/api/shipments_controller.rb +37 -0
  25. data/app/controllers/api/shipping_categories_controller.rb +13 -0
  26. data/app/controllers/api/shipping_methods_controller.rb +24 -0
  27. data/app/controllers/api/states_controller.rb +8 -0
  28. data/app/controllers/api/tax_categories_controller.rb +24 -0
  29. data/app/controllers/api/tax_rates_controller.rb +24 -0
  30. data/app/controllers/api/taxonomies_controller.rb +12 -0
  31. data/app/controllers/api/taxons_controller.rb +17 -0
  32. data/app/controllers/api/users_controller.rb +3 -0
  33. data/app/controllers/api/variants_controller.rb +24 -0
  34. data/app/controllers/api/zones_controller.rb +24 -0
  35. data/app/models/line_item_decorator.rb +7 -0
  36. data/app/models/order_decorator.rb +5 -0
  37. data/app/models/shipment_decorator.rb +5 -0
  38. data/app/models/user_decorator.rb +22 -0
  39. data/app/views/admin/users/_api_fields.html.erb +16 -0
  40. data/config/cucumber.yml +10 -0
  41. data/config/locales/en.yml +16 -0
  42. data/config/routes.rb +143 -0
  43. data/db/migrate/20100107141738_add_api_key_to_users.rb +9 -0
  44. data/lib/spree_api.rb +16 -0
  45. data/lib/spree_api_hooks.rb +3 -0
  46. data/lib/tasks/install.rake +23 -0
  47. metadata +168 -0
@@ -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]
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,132 @@
1
+ class Api::OverviewController < Api::BaseController
2
+ def best_selling_products
3
+ return_data=Hash.new
4
+ prod_array=Array.new
5
+ best=ActiveRecord::Base.connection.execute("Select A.id,A.name,sum(C.quantity) qty from spree_products A, spree_variants B, spree_line_items C,spree_orders D where A.id=B.product_id and B.id=C.variant_id and C.order_id=D.id and D.payment_state in ('paid','completed','payment','complete') group by A.id,A.name order by 3,1")
6
+ best.each do |pr|
7
+ prod_dtl=Hash.new
8
+ prod_dtl[:id]=pr[0]
9
+ prod_dtl[:name]=pr[1]
10
+ prod_dtl[:qty]=pr[2]
11
+ prod_array.push prod_dtl
12
+ end
13
+ return_data[:products] = prod_array
14
+ render :json => return_data.to_json, :status => 201
15
+ end
16
+
17
+ def gross_selling_products
18
+ return_data=Hash.new
19
+ prod_array=Array.new
20
+ best=ActiveRecord::Base.connection.execute("Select A.id,A.name,sum(B.cost_price * C.quantity) amount from spree_products A, spree_variants B, spree_line_items C,spree_orders D where A.id=B.product_id and B.id=C.variant_id and C.order_id=D.id and D.payment_state in ('paid','completed','payment','complete') group by A.id,A.name order by 3,1")
21
+ best.each do |pr|
22
+ prod_dtl=Hash.new
23
+ prod_dtl[:id]=pr[0]
24
+ prod_dtl[:name]=pr[1]
25
+ prod_dtl[:amount]=pr[2]
26
+ prod_array.push prod_dtl
27
+ end
28
+ return_data[:products] = prod_array
29
+ render :json => return_data.to_json, :status => 201
30
+ end
31
+
32
+ def top_spenders
33
+ return_data=Hash.new
34
+ prod_array=Array.new
35
+ best=ActiveRecord::Base.connection.execute("Select A.id,A.email,sum(C.quantity),sum(B.cost_price * C.quantity) from spree_users A, spree_variants B, spree_line_items C, spree_orders D where A.id=D.user_id and B.id=C.variant_id and C.order_id=D.id and D.payment_state in ('paid','completed','payment','complete') group by A.id,A.email order by 4,1")
36
+ best.each do |pr|
37
+ prod_dtl=Hash.new
38
+ prod_dtl[:id]=pr[0]
39
+ prod_dtl[:email]=pr[1]
40
+ prod_dtl[:qty]=pr[2]
41
+ prod_dtl[:value]=pr[3]
42
+ prod_array.push prod_dtl
43
+ end
44
+ return_data[:spenders] = prod_array
45
+ render :json => return_data.to_json, :status => 201
46
+ end
47
+ def recent_orders
48
+ return_data=Hash.new
49
+ prod_array=Array.new
50
+ best=ActiveRecord::Base.connection.execute("Select A.id,A.email,D.id,D.number,D.created_at,D.total from spree_users A, spree_orders D where A.id=D.user_id and D.payment_state in ('paid','completed','payment','complete') order by 4,3")
51
+ best.each do |pr|
52
+ prod_dtl=Hash.new
53
+ prod_dtl[:user_id]=pr[0]
54
+ prod_dtl[:email]=pr[1]
55
+ prod_dtl[:order_id]=pr[2]
56
+ prod_dtl[:order_number]=pr[3]
57
+ prod_dtl[:order_date]=pr[4]
58
+ prod_dtl[:order_total]=pr[5]
59
+ prod_array.push prod_dtl
60
+ end
61
+ return_data[:orders] = prod_array
62
+ render :json => return_data.to_json, :status => 201
63
+ end
64
+ def out_of_stock
65
+ return_data=Hash.new
66
+ prod_array=Array.new
67
+ best=ActiveRecord::Base.connection.execute("Select A.id,A.name,B.count_on_hand from spree_products A, spree_variants B where A.id=B.product_id and B.count_on_hand <=0 order by 1,2")
68
+ best.each do |pr|
69
+ prod_dtl=Hash.new
70
+ prod_dtl[:id]=pr[0]
71
+ prod_dtl[:name]=pr[1]
72
+ prod_dtl[:count_on_hand]=pr[2]
73
+ prod_array.push prod_dtl
74
+ end
75
+ return_data[:products] = prod_array
76
+ render :json => return_data.to_json, :status => 201
77
+ end
78
+ def day_order_count
79
+ return_data=Hash.new
80
+ prod_array=Array.new
81
+ best=ActiveRecord::Base.connection.execute("Select DATE(created_at),count(*) from spree_orders where payment_state in ('paid','completed','payment','complete') group by DATE(created_at) order by 1 DESC")
82
+ best.each do |pr|
83
+ prod_dtl=Hash.new
84
+ prod_dtl[:order_date]=pr[0]
85
+ prod_dtl[:order_count]=pr[1]
86
+ prod_array.push prod_dtl
87
+ end
88
+ return_data[:orders] = prod_array
89
+ render :json => return_data.to_json, :status => 201
90
+ end
91
+ def day_order_value
92
+ return_data=Hash.new
93
+ prod_array=Array.new
94
+ best=ActiveRecord::Base.connection.execute("Select DATE(created_at),sum(total) from spree_orders where payment_state in ('paid','completed','payment','complete') group by DATE(created_at) order by 1 DESC")
95
+ best.each do |pr|
96
+ prod_dtl=Hash.new
97
+ prod_dtl[:order_date]=pr[0]
98
+ prod_dtl[:total_order_value]=pr[1]
99
+ prod_array.push prod_dtl
100
+ end
101
+ return_data[:orders] = prod_array
102
+ render :json => return_data.to_json, :status => 201
103
+ end
104
+ def month_order_value
105
+ return_data=Hash.new
106
+ prod_array=Array.new
107
+ best=ActiveRecord::Base.connection.execute("Select Month(created_at),Year(created_at),sum(total) from spree_orders where payment_state in ('paid','completed','payment','complete') group by Month(created_at),Year(created_at) order by 2 DESC ,1 DESC")
108
+ best.each do |pr|
109
+ prod_dtl=Hash.new
110
+ prod_dtl[:order_month]=pr[0]
111
+ prod_dtl[:order_year]=pr[1]
112
+ prod_dtl[:total_order_value]=pr[2]
113
+ prod_array.push prod_dtl
114
+ end
115
+ return_data[:orders] = prod_array
116
+ render :json => return_data.to_json, :status => 201
117
+ end
118
+ def month_order_count
119
+ return_data=Hash.new
120
+ prod_array=Array.new
121
+ best=ActiveRecord::Base.connection.execute("Select Month(created_at),Year(created_at),count(*) from spree_orders where payment_state in ('paid','completed','payment','complete') group by Month(created_at),Year(created_at) order by 2 DESC ,1 DESC")
122
+ best.each do |pr|
123
+ prod_dtl=Hash.new
124
+ prod_dtl[:order_month]=pr[0]
125
+ prod_dtl[:order_year]=pr[1]
126
+ prod_dtl[:order_count]=pr[2]
127
+ prod_array.push prod_dtl
128
+ end
129
+ return_data[:orders] = prod_array
130
+ render :json => return_data.to_json, :status => 201
131
+ end
132
+ 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,14 @@
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
+ 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 Spree::Api::ShippingMethodsController < Spree::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=Spree::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,8 @@
1
+ class Api::StatesController < Api::BaseController
2
+ before_filter :access_denied, :except => [:index, :show]
3
+
4
+ private
5
+ def parent
6
+ @parent ||= Country.find(params[:country_id])
7
+ end
8
+ end