spree_api 0.30.0.beta1 → 0.30.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,19 @@
1
+ Admin::UsersController.class_eval do
2
+
3
+ before_filter :load_roles, :only => [:edit, :new, :update, :create, :generate_api_key, :clear_api_key]
4
+
5
+ def generate_api_key
6
+ if object.generate_api_key!
7
+ flash.notice = t('api.key_generated')
8
+ end
9
+ redirect_to edit_object_path
10
+ end
11
+
12
+ def clear_api_key
13
+ if object.clear_api_key!
14
+ flash.notice = t('api.key_cleared')
15
+ end
16
+ redirect_to edit_object_path
17
+ end
18
+
19
+ end
@@ -24,17 +24,16 @@ class Api::BaseController < Spree::BaseController
24
24
 
25
25
  define_method :admin_token_passed_in_headers do
26
26
  token = request.headers['X-SpreeAPIKey']
27
- return false unless token
27
+ return access_denied unless token
28
28
  @current_user = User.find_by_api_key(token)
29
- @current_user.has_role? 'admin'
30
29
  end
31
30
 
32
31
  define_method :end_of_association_chain do
33
- (parent? ? parent_association : model).scoped(:include => eager_load_associations)
32
+ parent? ? parent_association.scoped : model.scoped(:include => eager_load_associations)
34
33
  end
35
34
 
36
35
  define_method :collection do
37
- @collection ||= search.all(:limit => 100)
36
+ @collection ||= search.do_search.all(:limit => 100)
38
37
  end
39
38
  end
40
39
 
@@ -29,7 +29,7 @@ class Api::ShipmentsController < Api::BaseController
29
29
  end
30
30
 
31
31
  def eager_load_associations
32
- [:shipping_method, {:shipping_charge => :order}, :address, {:inventory_units => [:variant]}]
32
+ [:shipping_method, :address, {:inventory_units => [:variant]}]
33
33
  end
34
34
 
35
35
  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,17 @@
1
+ User.class_eval do
2
+
3
+ def clear_api_key!
4
+ self.update_attribute(:api_key, "")
5
+ end
6
+
7
+ def generate_api_key!
8
+ self.update_attribute(:api_key, secure_digest(Time.now, (1..10).map{ rand.to_s }))
9
+ end
10
+
11
+ private
12
+
13
+ def secure_digest(*args)
14
+ Digest::SHA1.hexdigest(args.flatten.join('--'))
15
+ end
16
+
17
+ end
@@ -1,3 +1,4 @@
1
+ ---
1
2
  en:
2
3
  api: "API"
3
4
  api:
@@ -12,5 +13,4 @@ en:
12
13
  regenerate_key: "Regenerate API key"
13
14
  no_key: "No key defined"
14
15
  key_generated: "API key generated"
15
- key_cleared: "API key cleared"
16
-
16
+ key_cleared: "API key cleared"
data/lib/spree_api.rb CHANGED
@@ -4,43 +4,27 @@ require 'spree_api_hooks'
4
4
  module SpreeApi
5
5
  class Engine < Rails::Engine
6
6
  def self.activate
7
- lambda{
8
7
 
9
- Admin::UsersController.class_eval do
8
+ # RAILS3 TODO: Get the API stuff working with Devise
9
+ # Spree::BaseController.class_eval do
10
+ # private
11
+ # def current_user
12
+ # return @current_user if defined?(@current_user)
13
+ # if current_user_session && current_user_session.user
14
+ # return @current_user = current_user_session.user
15
+ # end
16
+ # if token = request.headers['X-SpreeAPIKey']
17
+ # @current_user = User.find_by_api_key(token)
18
+ # end
19
+ # end
20
+ # end
21
+
22
+ Dir.glob(File.join(File.dirname(__FILE__), "../app/**/*_decorator*.rb")) do |c|
23
+ Rails.env.production? ? require(c) : load(c)
24
+ end
10
25
 
11
- def generate_api_key
12
- if object.generate_api_key!
13
- flash.notice = t('api.key_generated')
14
- end
15
- redirect_to edit_object_path
16
- end
17
-
18
- end
19
-
20
- # RAILS3 TODO: Get the API stuff working with Devise
21
- # Spree::BaseController.class_eval do
22
- # private
23
- # def current_user
24
- # return @current_user if defined?(@current_user)
25
- # if current_user_session && current_user_session.user
26
- # return @current_user = current_user_session.user
27
- # end
28
- # if token = request.headers['X-SpreeAPIKey']
29
- # @current_user = User.find_by_api_key(token)
30
- # end
31
- # end
32
- # end
33
-
34
- LineItem.class_eval do
35
- def description
36
- d = variant.product.name.clone
37
- d << " (#{variant.options_text})" unless variant.option_values.empty?
38
- d
39
- end
40
- end
41
- }
42
26
  end
43
27
  config.autoload_paths += %W(#{config.root}/lib)
44
- config.to_prepare &self.activate
28
+ config.to_prepare &method(:activate).to_proc
45
29
  end
46
- end
30
+ end
@@ -0,0 +1,24 @@
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
+ puts "INFO: Mirroring assets from #{source} to #{destination}"
15
+ Spree::FileUtilz.mirror_files(source, destination)
16
+ end
17
+
18
+ desc "Copies all assets (NOTE: This will be obsolete with Rails 3.1)"
19
+ task :assets do
20
+ # No assets
21
+ end
22
+
23
+ end
24
+ end
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: spree_api
3
3
  version: !ruby/object:Gem::Version
4
- prerelease: true
4
+ hash: 103
5
+ prerelease: false
5
6
  segments:
6
7
  - 0
7
8
  - 30
8
9
  - 0
9
- - beta1
10
- version: 0.30.0.beta1
10
+ version: 0.30.0
11
11
  platform: ruby
12
12
  authors:
13
13
  - David North
@@ -15,22 +15,23 @@ autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2010-09-03 00:00:00 -04:00
18
+ date: 2010-11-09 00:00:00 -05:00
19
19
  default_executable:
20
20
  dependencies:
21
21
  - !ruby/object:Gem::Dependency
22
22
  name: spree_core
23
23
  prerelease: false
24
24
  requirement: &id001 !ruby/object:Gem::Requirement
25
+ none: false
25
26
  requirements:
26
27
  - - "="
27
28
  - !ruby/object:Gem::Version
29
+ hash: 103
28
30
  segments:
29
31
  - 0
30
32
  - 30
31
33
  - 0
32
- - beta1
33
- version: 0.30.0.beta1
34
+ version: 0.30.0
34
35
  type: :runtime
35
36
  version_requirements: *id001
36
37
  description: Required dependancy for Spree
@@ -44,6 +45,7 @@ extra_rdoc_files: []
44
45
  files:
45
46
  - LICENSE
46
47
  - README.md
48
+ - app/controllers/admin/users_controller_decorator.rb
47
49
  - app/controllers/api/base_controller.rb
48
50
  - app/controllers/api/countries_controller.rb
49
51
  - app/controllers/api/inventory_units_controller.rb
@@ -53,15 +55,15 @@ files:
53
55
  - app/controllers/api/shipments_controller.rb
54
56
  - app/controllers/api/states_controller.rb
55
57
  - app/helpers/api/shipments_helper.rb
58
+ - app/models/line_item_decorator.rb
59
+ - app/models/user_decorator.rb
56
60
  - app/views/admin/users/_api_fields.html.erb
57
61
  - config/locales/en.yml
58
- - config/locales/ru-RU.yml
59
62
  - config/routes.rb
60
- - lib/generators/spree_api/install_generator.rb
61
- - lib/generators/templates/db/migrate/20100107141738_add_api_key_to_users.rb
62
63
  - lib/spree_api.rb
63
64
  - lib/spree_api_hooks.rb
64
- - lib/tasks/api.rake
65
+ - lib/tasks/install.rake
66
+ - db/migrate/20100107141738_add_api_key_to_users.rb
65
67
  has_rdoc: true
66
68
  homepage: http://spreecommerce.com
67
69
  licenses: []
@@ -72,27 +74,29 @@ rdoc_options: []
72
74
  require_paths:
73
75
  - lib
74
76
  required_ruby_version: !ruby/object:Gem::Requirement
77
+ none: false
75
78
  requirements:
76
79
  - - ">="
77
80
  - !ruby/object:Gem::Version
81
+ hash: 57
78
82
  segments:
79
83
  - 1
80
84
  - 8
81
85
  - 7
82
86
  version: 1.8.7
83
87
  required_rubygems_version: !ruby/object:Gem::Requirement
88
+ none: false
84
89
  requirements:
85
- - - ">"
90
+ - - ">="
86
91
  - !ruby/object:Gem::Version
92
+ hash: 3
87
93
  segments:
88
- - 1
89
- - 3
90
- - 1
91
- version: 1.3.1
94
+ - 0
95
+ version: "0"
92
96
  requirements:
93
97
  - none
94
98
  rubyforge_project: spree_api
95
- rubygems_version: 1.3.6
99
+ rubygems_version: 1.3.7
96
100
  signing_key:
97
101
  specification_version: 3
98
102
  summary: Provides RESTful access for Spree.
@@ -1,16 +0,0 @@
1
- ru-RU:
2
- api: "API"
3
- api:
4
- access: "API доступ"
5
- clear_key: "Удалить ключ API"
6
- errors:
7
- invalid_event: "Недопустимое действие, допустимые действия: %{events}"
8
- invalid_event_for_object: "Допустимое действие, но не разрешённое для заданного объекта, разрешённые действия: %{events}"
9
- missing_event: "Действие не указано"
10
- generate_key: "Сгенирировать ключ API"
11
- key: "Ключ API"
12
- regenerate_key: "Перегенерировать ключ API"
13
- no_key: "Ключ не определён"
14
- key_generated: "Ключ API сгенерирован"
15
- key_cleared: "Ключ API удалён"
16
-
@@ -1,14 +0,0 @@
1
- module SpreeApi
2
- module Generators
3
- class InstallGenerator < Rails::Generators::Base
4
- source_root File.expand_path("../../templates", __FILE__)
5
-
6
- desc "Configures an existing Rails application to use spree_api"
7
-
8
- def copy_migrations
9
- directory "db"
10
- end
11
-
12
- end
13
- end
14
- end
data/lib/tasks/api.rake DELETED
@@ -1,8 +0,0 @@
1
- namespace :spree do
2
- desc "Synchronize public assets, migrations, seed and sample data from the Spree gems"
3
- task :sync do
4
- migration_dir = File.join(File.dirname(__FILE__), '..', '..', 'db', 'migrate')
5
- puts "Mirror: #{migration_dir}"
6
- Spree::FileUtilz.mirror_with_backup(migration_dir, File.join(Rails.root, 'db', 'migrate'))
7
- end
8
- end