My-Commerce_api 1.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/base_controller.rb +183 -0
  6. data/app/controllers/api/checkout1_controller.rb +89 -0
  7. data/app/controllers/api/countries_controller.rb +3 -0
  8. data/app/controllers/api/images_controller.rb +15 -0
  9. data/app/controllers/api/inventory_units_controller.rb +19 -0
  10. data/app/controllers/api/line_items_controller.rb +37 -0
  11. data/app/controllers/api/mail_methods_controller.rb +10 -0
  12. data/app/controllers/api/option_types_controller.rb +24 -0
  13. data/app/controllers/api/orders_controller.rb +51 -0
  14. data/app/controllers/api/overview_controller.rb +132 -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 +14 -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 +8 -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 +143 -0
  42. data/db/migrate/20100107141738_add_api_key_to_users.rb +9 -0
  43. data/lib/spree_api.rb +16 -0
  44. data/lib/spree_api_hooks.rb +3 -0
  45. data/lib/tasks/install.rake +23 -0
  46. metadata +115 -0
@@ -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=Spree::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=Spree::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=Spree::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
@@ -0,0 +1,3 @@
1
+ class Api::UsersController < Api::BaseController
2
+
3
+ end
@@ -0,0 +1,24 @@
1
+ class Api::VariantsController < 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=Spree::Variant.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::ZonesController < 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=Zone.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,7 @@
1
+ LineItem.class_eval do
2
+ def description
3
+ d = variant.product.name.clone
4
+ d << " (#{variant.options_text})" unless variant.option_values.empty?
5
+ d
6
+ end
7
+ end
@@ -0,0 +1,5 @@
1
+ Order.class_eval do
2
+ def self.find_by_param(param)
3
+ Order.where("id = ? OR number = ?", param, param).first
4
+ end
5
+ end
@@ -0,0 +1,5 @@
1
+ Shipment.class_eval do
2
+ def self.find_by_param(param)
3
+ Shipment.where("id = ? OR number = ?", param, param).first
4
+ end
5
+ end
@@ -0,0 +1,22 @@
1
+ User.class_eval do
2
+
3
+ def clear_api_key!
4
+ self.update_attribute(:authentication_token, "")
5
+ end
6
+
7
+ def generate_api_key!
8
+ self.reset_authentication_token!
9
+ end
10
+
11
+ #def self.authenticate_with_http(username, password)
12
+ # logger.debug(username)
13
+ # self.authenticate_with_token(:auth_token => username)
14
+ #end
15
+
16
+ private
17
+
18
+ def secure_digest(*args)
19
+ Digest::SHA1.hexdigest(args.flatten.join('--'))
20
+ end
21
+
22
+ end
@@ -0,0 +1,16 @@
1
+ <h2><%= t('api.access') %></h2>
2
+
3
+ <% if @user.authentication_token.present? %>
4
+ <p><strong><%= t('api.key') %></strong> <%= @user.authentication_token %></p>
5
+ <%= form_tag clear_api_key_admin_user_path(@user), :method => :put do %>
6
+ <%= button t("api.clear_key") %>
7
+ <% end %>
8
+ <%= form_tag generate_api_key_admin_user_path(@user), :method => :put do %>
9
+ <%= button t("api.regenerate_key") %>
10
+ <% end %>
11
+ <% else %>
12
+ <p><%= t('api.no_key') %></p>
13
+ <%= form_tag generate_api_key_admin_user_path(@user), :method => :put do %>
14
+ <%= button t("api.generate_key") %>
15
+ <% end %>
16
+ <% end %>
@@ -0,0 +1,10 @@
1
+ <%
2
+ rerun = File.file?('rerun.txt') ? IO.read('rerun.txt') : ""
3
+ rerun_opts = rerun.to_s.strip.empty? ? "--format #{ENV['CUCUMBER_FORMAT'] || 'progress'} features" : "--format #{ENV['CUCUMBER_FORMAT'] || 'pretty'} #{rerun}"
4
+ std_opts = "--format #{ENV['CUCUMBER_FORMAT'] || 'progress'} --strict --tags ~@wip"
5
+ ci_opts = "--format progress --strict"
6
+ %>
7
+ default: <%= std_opts %> features
8
+ wip: --tags @wip:3 --wip features
9
+ ci: <%= ci_opts %> features CI=true
10
+ rerun: <%= rerun_opts %> --format rerun --out rerun.txt --strict --tags ~@wip
@@ -0,0 +1,16 @@
1
+ ---
2
+ en:
3
+ api: "API"
4
+ api:
5
+ access: "API Access"
6
+ clear_key: "Clear API key"
7
+ errors:
8
+ invalid_event: "Invalid event name, valid names are %{events}"
9
+ invalid_event_for_object: "Valid event name but not allowed for this object, valid names are %{events}"
10
+ missing_event: "No event name supplied"
11
+ generate_key: "Generate API key"
12
+ key: "API Key"
13
+ regenerate_key: "Regenerate API key"
14
+ no_key: "No key defined"
15
+ key_generated: "API key generated"
16
+ key_cleared: "API key cleared"
data/config/routes.rb ADDED
@@ -0,0 +1,143 @@
1
+ Rails.application.routes.draw do
2
+ namespace :admin do
3
+ resources :users do
4
+ member do
5
+ put :generate_api_key
6
+ put :clear_api_key
7
+ end
8
+ end
9
+ end
10
+
11
+ namespace :api do
12
+ resources :taxonomies
13
+ match '/t/*id', :to => 'taxons#show', :as => :nested_taxons
14
+ resources :taxonomies do
15
+ member do
16
+ get :get_children
17
+ end
18
+ resources :taxons
19
+ end
20
+ resources :adjustments
21
+ resources :shipping_categories
22
+ resources :shipping_methods
23
+ resources :promotions
24
+ # resources :promotions do
25
+ # # resources :promotion_rules
26
+ # # resources :promotion_actions
27
+ # end
28
+ resources :tax_categories
29
+ resources :zones
30
+ # resources :payments do
31
+ # member do
32
+ # put :fire
33
+ # end
34
+ # end
35
+ resources :product_groups
36
+ resources :tax_rates
37
+ resources :payment_methods
38
+ resources :variants
39
+ resources :products do
40
+ resources :product_properties
41
+ resources :images do
42
+ collection do
43
+ post :update_positions
44
+ end
45
+ end
46
+ end
47
+
48
+ resources :shipments, :except => [:new,:edit] do
49
+ put :event, :on => :member
50
+ resources :inventory_units, :except => [:new,:edit] do
51
+ put :event, :on => :member
52
+ end
53
+ end
54
+ resources :creditcards
55
+ resources :creditcard_payments
56
+ resources :option_types
57
+ resources :properties
58
+ resources :prototypes
59
+ resources :shipping_methods
60
+ resources :mail_methods do
61
+ member do
62
+ post :testmail
63
+ end
64
+ end
65
+ resources :reports, :only => [:index, :show] do
66
+ collection do
67
+ get :sales_total
68
+ end
69
+ end
70
+ match '/checkout/update/:state' => 'checkout1#update', :as => :update_checkout ,:via=>:put
71
+ #match '/checkout/update/:state', :to => 'checkout#update_order',:via=>:put
72
+ #match '/checkout/:state', :to => 'checkout#edit', :as => :checkout_state, :via => :get
73
+ #match '/checkout', :to => 'checkout#edit', :state => 'address', :as => :checkout
74
+ #match '/checkout/payment', :to => 'checkout#payment', :via => :put
75
+ match '/overview/best_selling_products', :to => 'overview#best_selling_products', :via => :get
76
+ match '/overview/gross_selling_products', :to => 'overview#gross_selling_products', :via => :get
77
+ match '/overview/top_spenders', :to => 'overview#top_spenders', :via => :get
78
+ match '/overview/recent_orders', :to => 'overview#recent_orders', :via => :get
79
+ match '/overview/out_of_stock', :to => 'overview#out_of_stock', :via => :get
80
+ match '/overview/day_order_count', :to => 'overview#day_order_count', :via => :get
81
+ match '/overview/day_order_value', :to => 'overview#day_order_value', :via => :get
82
+ match '/overview/month_order_value', :to => 'overview#month_order_value', :via => :get
83
+ match '/overview/month_order_count', :to => 'overview#month_order_count', :via => :get
84
+ match '/products/add',:to=>'products#add',:via=>:post
85
+ #match '/products/remove',:to=>'products#remove',:via=>:delete
86
+ # resources :images
87
+ resources :orders, :except => [:new,:edit] do
88
+ put :event, :on => :member
89
+ resources :shipments, :except => [:new,:edit]
90
+ resources :line_items, :except => [:new,:edit]
91
+ resources :inventory_units, :except => [:new,:edit] do
92
+ put :event, :on => :member
93
+ end
94
+ end
95
+ resources :line_items,:only=>[:create]
96
+ resources :inventory_units, :except => [:new,:edit] do
97
+ put :event, :on => :member
98
+ end
99
+ resources :users , :except => [:new,:edit]
100
+ resources :user_sessions do
101
+ put :event, :on => :member
102
+ end
103
+ resources :products, :except => [:new,:edit] do
104
+ member do
105
+ delete :remove
106
+ end
107
+ end
108
+ resources :orders do
109
+ member do
110
+ put :fire
111
+ get :fire
112
+ post :resend
113
+ get :history
114
+ get :user
115
+ end
116
+
117
+ resources :adjustments
118
+ resources :line_items
119
+ resources :shipments do
120
+ member do
121
+ put :fire
122
+ end
123
+ end
124
+ resources :return_authorizations do
125
+ member do
126
+ put :fire
127
+ end
128
+ end
129
+ resources :payments do
130
+ member do
131
+ put :fire
132
+ end
133
+ end
134
+ end
135
+ resources :countries
136
+ resources :countries do
137
+ resources :states
138
+ end
139
+ resources :states
140
+
141
+ end
142
+
143
+ end
@@ -0,0 +1,9 @@
1
+ class AddApiKeyToUsers < ActiveRecord::Migration
2
+ def self.up
3
+ add_column "users", "api_key", :string, :limit => 40
4
+ end
5
+
6
+ def self.down
7
+ remove_column "users", "api_key"
8
+ end
9
+ end
data/lib/spree_api.rb ADDED
@@ -0,0 +1,16 @@
1
+ require 'spree_core'
2
+ require 'spree_api_hooks'
3
+
4
+ module SpreeApi
5
+ class Engine < Rails::Engine
6
+ def self.activate
7
+
8
+ Dir.glob(File.join(File.dirname(__FILE__), "../app/**/*_decorator*.rb")) do |c|
9
+ Rails.env.production? ? require(c) : load(c)
10
+ end
11
+
12
+ end
13
+ config.autoload_paths += %W(#{config.root}/lib)
14
+ config.to_prepare &method(:activate).to_proc
15
+ end
16
+ end
@@ -0,0 +1,3 @@
1
+ class ApiHooks < Spree::ThemeSupport::HookListener
2
+ insert_after :admin_user_edit_form, :partial => "admin/users/api_fields"
3
+ end
@@ -0,0 +1,23 @@
1
+ namespace :spree_api do
2
+ desc "Copies all migrations and assets (NOTE: This will be obsolete with Rails 3.1)"
3
+ task :install do
4
+ Rake::Task['spree_api:install:migrations'].invoke
5
+ Rake::Task['spree_api:install:assets'].invoke
6
+ end
7
+
8
+ namespace :install do
9
+
10
+ desc "Copies all migrations (NOTE: This will be obsolete with Rails 3.1)"
11
+ task :migrations do
12
+ source = File.join(File.dirname(__FILE__), '..', '..', 'db')
13
+ destination = File.join(Rails.root, 'db')
14
+ Spree::FileUtilz.mirror_files(source, destination)
15
+ end
16
+
17
+ desc "Copies all assets (NOTE: This will be obsolete with Rails 3.1)"
18
+ task :assets do
19
+ # No assets
20
+ end
21
+
22
+ end
23
+ end
metadata ADDED
@@ -0,0 +1,115 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: My-Commerce_api
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.0.0
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Santosh
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2012-03-23 00:00:00.000000000Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: My-Commerce_core
16
+ requirement: &79328780 !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - =
20
+ - !ruby/object:Gem::Version
21
+ version: 1.0.0
22
+ type: :runtime
23
+ prerelease: false
24
+ version_requirements: *79328780
25
+ - !ruby/object:Gem::Dependency
26
+ name: My-Commerce_auth
27
+ requirement: &79328560 !ruby/object:Gem::Requirement
28
+ none: false
29
+ requirements:
30
+ - - =
31
+ - !ruby/object:Gem::Version
32
+ version: 1.0.0
33
+ type: :runtime
34
+ prerelease: false
35
+ version_requirements: *79328560
36
+ description: Required dependancy for My-Commerce
37
+ email: santa.jyp@gmail.com
38
+ executables: []
39
+ extensions: []
40
+ extra_rdoc_files: []
41
+ files:
42
+ - LICENSE
43
+ - README.md
44
+ - app/models/shipment_decorator.rb
45
+ - app/models/user_decorator.rb
46
+ - app/models/line_item_decorator.rb
47
+ - app/models/order_decorator.rb
48
+ - app/controllers/admin/users_controller_decorator.rb
49
+ - app/controllers/api/variants_controller.rb
50
+ - app/controllers/api/adjustments_controller.rb
51
+ - app/controllers/api/promotions_controller.rb
52
+ - app/controllers/api/tax_rates_controller.rb
53
+ - app/controllers/api/line_items_controller.rb
54
+ - app/controllers/api/payments_controller.rb
55
+ - app/controllers/api/prototypes_controller.rb
56
+ - app/controllers/api/base_controller.rb
57
+ - app/controllers/api/product_groups_controller.rb
58
+ - app/controllers/api/shipments_controller.rb
59
+ - app/controllers/api/shipping_categories_controller.rb
60
+ - app/controllers/api/tax_categories_controller.rb
61
+ - app/controllers/api/reports_controller.rb
62
+ - app/controllers/api/images_controller.rb
63
+ - app/controllers/api/zones_controller.rb
64
+ - app/controllers/api/states_controller.rb
65
+ - app/controllers/api/shipping_methods_controller.rb
66
+ - app/controllers/api/products_controller.rb
67
+ - app/controllers/api/taxons_controller.rb
68
+ - app/controllers/api/properties_controller.rb
69
+ - app/controllers/api/inventory_units_controller.rb
70
+ - app/controllers/api/option_types_controller.rb
71
+ - app/controllers/api/taxonomies_controller.rb
72
+ - app/controllers/api/overview_controller.rb
73
+ - app/controllers/api/users_controller.rb
74
+ - app/controllers/api/orders_controller.rb
75
+ - app/controllers/api/payment_methods_controller.rb
76
+ - app/controllers/api/countries_controller.rb
77
+ - app/controllers/api/mail_methods_controller.rb
78
+ - app/controllers/api/checkout1_controller.rb
79
+ - app/views/admin/users/_api_fields.html.erb
80
+ - config/cucumber.yml
81
+ - config/routes.rb
82
+ - config/locales/en.yml
83
+ - lib/spree_api_hooks.rb
84
+ - lib/spree_api.rb
85
+ - lib/tasks/install.rake
86
+ - db/migrate/20100107141738_add_api_key_to_users.rb
87
+ homepage: http://google.com
88
+ licenses: []
89
+ post_install_message:
90
+ rdoc_options: []
91
+ require_paths:
92
+ - lib
93
+ required_ruby_version: !ruby/object:Gem::Requirement
94
+ none: false
95
+ requirements:
96
+ - - ! '>='
97
+ - !ruby/object:Gem::Version
98
+ version: 1.8.7
99
+ required_rubygems_version: !ruby/object:Gem::Requirement
100
+ none: false
101
+ requirements:
102
+ - - ! '>='
103
+ - !ruby/object:Gem::Version
104
+ version: '0'
105
+ segments:
106
+ - 0
107
+ hash: -658030979
108
+ requirements:
109
+ - none
110
+ rubyforge_project: My-Commerce_api
111
+ rubygems_version: 1.8.17
112
+ signing_key:
113
+ specification_version: 3
114
+ summary: Provides RESTful access for My-commerce
115
+ test_files: []