tumbz 0.0.4 → 0.0.5

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.
data/README.md CHANGED
@@ -74,6 +74,27 @@ review = Tumbz::Review.create(:product_external_id => "tt0458339", :positive =>
74
74
  # => #<Tumbz::Review(reviews/50b9ebd7a9d29c000200af7c) id="50b9ebd7a9d29c000200af7c" positive=true text=""…>
75
75
  ```
76
76
 
77
+ ### OAuth in a Web application
78
+
79
+ Since each request will probably have a different user (and a different `access_token`) it’s better to use some kind of filter to make sure each request gets its own user only. For example, with Ruby on Rails:
80
+
81
+ ```ruby
82
+ class ApplicationController < ActionController::Base
83
+ around_filter :do_with_tumbz_user
84
+
85
+ def do_with_tumbz_user
86
+ Tumbz::User.sign_in!("<email>", "<password>")
87
+ # or Tumbz::User.set_access_token!("<access_token>")
88
+
89
+ begin
90
+ yield
91
+ ensure
92
+ Tumbz::User.sign_out!
93
+ end
94
+ end
95
+ end
96
+ ```
97
+
77
98
  ## Contributing
78
99
 
79
100
  1. Fork it
@@ -7,7 +7,7 @@ module Tumbz
7
7
  end
8
8
 
9
9
  def call(env)
10
- env[:request_headers]["Authorization"] = "OAuth #{Tumbz.access_token}" unless Tumbz.access_token.nil?
10
+ env[:request_headers]["Authorization"] = "OAuth #{Thread.current[:tumbz_access_token]}" unless Thread.current[:tumbz_access_token].nil?
11
11
  @app.call(env)
12
12
  end
13
13
  end
@@ -7,13 +7,17 @@ module Tumbz
7
7
 
8
8
  def self.sign_in!(email, password)
9
9
  post_raw("auth", :email => email, :password => password) do |parsed_data|
10
- Tumbz.access_token = parsed_data[:data][:access_token]
10
+ Thread.current[:tumbz_access_token] = parsed_data[:data][:access_token]
11
11
  end
12
12
  end
13
13
 
14
+ def self.set_access_token!(access_token)
15
+ Thread.current[:tumbz_access_token] = access_token
16
+ end
17
+
14
18
  def self.sign_out!
15
- Tumbz.access_token = nil
16
- Tumbz.access_token.nil?
19
+ Thread.current[:tumbz_access_token] = nil
20
+ Thread.current[:tumbz_access_token].nil?
17
21
  end
18
22
  end
19
23
  end
@@ -1,3 +1,3 @@
1
1
  module Tumbz
2
- VERSION = "0.0.4"
2
+ VERSION = "0.0.5"
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: tumbz
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.4
4
+ version: 0.0.5
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -84,7 +84,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
84
84
  version: '0'
85
85
  segments:
86
86
  - 0
87
- hash: 1882409269895347375
87
+ hash: -3906599876790173656
88
88
  required_rubygems_version: !ruby/object:Gem::Requirement
89
89
  none: false
90
90
  requirements:
@@ -93,7 +93,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
93
93
  version: '0'
94
94
  segments:
95
95
  - 0
96
- hash: 1882409269895347375
96
+ hash: -3906599876790173656
97
97
  requirements: []
98
98
  rubyforge_project:
99
99
  rubygems_version: 1.8.23