spree_api 0.30.2 → 0.40.0

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.
@@ -2,30 +2,30 @@ class Api::BaseController < Spree::BaseController
2
2
 
3
3
  def self.resource_controller_for_api
4
4
  resource_controller
5
+ before_filter :check_http_authorization
5
6
  skip_before_filter :verify_authenticity_token, :if => lambda { admin_token_passed_in_headers }
6
7
 
7
- index.response do |wants|
8
+ index do
8
9
  wants.json { render :json => collection.to_json(collection_serialization_options) }
9
10
  end
10
11
 
11
- show.response do |wants|
12
+ show do
12
13
  wants.json { render :json => object.to_json(object_serialization_options) }
14
+ failure.wants.json { render :text => "Failure\n", :status => 500 }
13
15
  end
14
16
 
15
17
  create do
16
- wants.json { redirect_to object_url, :status => 201 }
17
- failure.wants.json { render :json => object_errors.to_json, :status => 422 }
18
+ wants.json { render :text => "Resource created\n", :status => 201, :location => object_url }
19
+ failure.wants.json { render :text => "Failure\n", :status => 500 }
18
20
  end
19
21
 
20
22
  update do
21
23
  wants.json { render :nothing => true }
22
- failure.wants.json { render :json => object_errors.to_json, :status => 422 }
24
+ failure.wants.json { render :text => "Failure\n", :status => 500 }
23
25
  end
24
26
 
25
27
  define_method :admin_token_passed_in_headers do
26
- token = request.headers['X-SpreeAPIKey']
27
- return access_denied unless token
28
- @current_user = User.find_by_api_key(token)
28
+ request.headers['HTTP_AUTHORIZATION'].present?
29
29
  end
30
30
 
31
31
  define_method :end_of_association_chain do
@@ -33,7 +33,7 @@ class Api::BaseController < Spree::BaseController
33
33
  end
34
34
 
35
35
  define_method :collection do
36
- @collection ||= search.do_search.all(:limit => 100)
36
+ @collection ||= search.do_search.limit(100)
37
37
  end
38
38
  end
39
39
 
@@ -93,4 +93,9 @@ class Api::BaseController < Spree::BaseController
93
93
  {:errors => object.errors.full_messages}
94
94
  end
95
95
 
96
+ private
97
+ def check_http_authorization
98
+ render :text => "Access Denied\n", :status => 401 unless request.headers['HTTP_AUTHORIZATION'].present?
99
+ end
100
+
96
101
  end
@@ -1,13 +1,18 @@
1
1
  User.class_eval do
2
2
 
3
3
  def clear_api_key!
4
- self.update_attribute(:api_key, "")
4
+ self.update_attribute(:authentication_token, "")
5
5
  end
6
6
 
7
7
  def generate_api_key!
8
- self.update_attribute(:api_key, secure_digest(Time.now, (1..10).map{ rand.to_s }))
8
+ self.reset_authentication_token!
9
9
  end
10
10
 
11
+ #def self.authenticate_with_http(username, password)
12
+ # logger.debug(username)
13
+ # self.authenticate_with_token(:auth_token => username)
14
+ #end
15
+
11
16
  private
12
17
 
13
18
  def secure_digest(*args)
@@ -1,7 +1,7 @@
1
1
  <h2><%= t('api.access') %></h2>
2
2
 
3
- <% if @user.api_key.present? %>
4
- <p><strong><%= t('api.key') %></strong> <%= @user.api_key %></p>
3
+ <% if @user.authentication_token.present? %>
4
+ <p><strong><%= t('api.key') %></strong> <%= @user.authentication_token %></p>
5
5
  <%= form_tag clear_api_key_admin_user_path(@user), :method => :put do %>
6
6
  <%= button t("api.clear_key") %>
7
7
  <% end %>
@@ -0,0 +1,8 @@
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
+ %>
6
+ default: <%= std_opts %> features
7
+ wip: --tags @wip:3 --wip features
8
+ rerun: <%= rerun_opts %> --format rerun --out rerun.txt --strict --tags ~@wip
data/lib/spree_api.rb CHANGED
@@ -5,20 +5,6 @@ module SpreeApi
5
5
  class Engine < Rails::Engine
6
6
  def self.activate
7
7
 
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
8
  Dir.glob(File.join(File.dirname(__FILE__), "../app/**/*_decorator*.rb")) do |c|
23
9
  Rails.env.production? ? require(c) : load(c)
24
10
  end
@@ -11,7 +11,6 @@ namespace :spree_api do
11
11
  task :migrations do
12
12
  source = File.join(File.dirname(__FILE__), '..', '..', 'db')
13
13
  destination = File.join(Rails.root, 'db')
14
- puts "INFO: Mirroring assets from #{source} to #{destination}"
15
14
  Spree::FileUtilz.mirror_files(source, destination)
16
15
  end
17
16
 
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
- hash: 99
5
- prerelease:
4
+ hash: 191
5
+ prerelease: false
6
6
  segments:
7
7
  - 0
8
- - 30
9
- - 2
10
- version: 0.30.2
8
+ - 40
9
+ - 0
10
+ version: 0.40.0
11
11
  platform: ruby
12
12
  authors:
13
13
  - David North
@@ -15,7 +15,8 @@ autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2011-10-23 00:00:00 Z
18
+ date: 2010-12-22 00:00:00 -05:00
19
+ default_executable:
19
20
  dependencies:
20
21
  - !ruby/object:Gem::Dependency
21
22
  name: spree_core
@@ -25,12 +26,12 @@ dependencies:
25
26
  requirements:
26
27
  - - "="
27
28
  - !ruby/object:Gem::Version
28
- hash: 99
29
+ hash: 191
29
30
  segments:
30
31
  - 0
31
- - 30
32
- - 2
33
- version: 0.30.2
32
+ - 40
33
+ - 0
34
+ version: 0.40.0
34
35
  type: :runtime
35
36
  version_requirements: *id001
36
37
  description: Required dependancy for Spree
@@ -57,12 +58,14 @@ files:
57
58
  - app/models/line_item_decorator.rb
58
59
  - app/models/user_decorator.rb
59
60
  - app/views/admin/users/_api_fields.html.erb
61
+ - config/cucumber.yml
60
62
  - config/locales/en.yml
61
63
  - config/routes.rb
62
64
  - lib/spree_api.rb
63
65
  - lib/spree_api_hooks.rb
64
66
  - lib/tasks/install.rake
65
67
  - db/migrate/20100107141738_add_api_key_to_users.rb
68
+ has_rdoc: true
66
69
  homepage: http://spreecommerce.com
67
70
  licenses: []
68
71
 
@@ -94,7 +97,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
94
97
  requirements:
95
98
  - none
96
99
  rubyforge_project: spree_api
97
- rubygems_version: 1.8.10
100
+ rubygems_version: 1.3.7
98
101
  signing_key:
99
102
  specification_version: 3
100
103
  summary: Provides RESTful access for Spree.