latompa-fleakr 0.5.4 → 0.5.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.
@@ -22,15 +22,11 @@ module Fleakr
22
22
  # => #<Fleakr::Api::ValueParameter:0x1656da4 @include_in_signature=true, @name="foo", @value="bar">
23
23
  #
24
24
  def initialize(options = {})
25
- # TODO: need to find a way to move the unexpected behavior in Fleakr.token elsewhere
26
- @api_options = options.extract!(:authenticate?)
27
-
28
25
  @list = Hash.new
29
26
 
30
27
  options.each {|k,v| self << ValueParameter.new(k.to_s, v) }
31
28
 
32
29
  self << ValueParameter.new('api_key', Fleakr.api_key)
33
- self << ValueParameter.new('auth_token', Fleakr.token.value) if authenticate?
34
30
  end
35
31
 
36
32
  # Add a new parameter (ValueParameter / FileParameter) to the list
@@ -45,14 +41,6 @@ module Fleakr
45
41
  !Fleakr.shared_secret.blank?
46
42
  end
47
43
 
48
- # Should we send the auth_token with the request?
49
- #
50
- def authenticate?
51
- @api_options.has_key?(:authenticate?) ? @api_options[:authenticate?] : !Fleakr.token.blank?
52
- end
53
-
54
- # Access an individual parameter by key (symbol or string)
55
- #
56
44
  def [](key)
57
45
  list[key.to_s]
58
46
  end
@@ -3,7 +3,7 @@ module Fleakr
3
3
 
4
4
  MAJOR = 0
5
5
  MINOR = 5
6
- TINY = 0
6
+ TINY = 5
7
7
 
8
8
  def self.to_s
9
9
  [MAJOR, MINOR, TINY].join('.')
data/lib/fleakr.rb CHANGED
@@ -85,7 +85,7 @@ module Fleakr
85
85
  # Generic catch-all exception for any API errors
86
86
  class ApiError < StandardError; end
87
87
 
88
- mattr_accessor :api_key, :shared_secret, :mini_token, :auth_token, :frob
88
+ mattr_accessor :api_key, :shared_secret
89
89
 
90
90
  # Find a user based on some unique user data. This method will try to find
91
91
  # the user based on username and will fall back to email if that fails. Example:
@@ -138,34 +138,34 @@ module Fleakr
138
138
  Fleakr::Objects::Contact.find_all_contacts(params)
139
139
  end
140
140
 
141
- # Get the authentication token needed for authenticated requests. Will either use
142
- # a valid auth_token (if available) or a mini-token to generate the auth_token.
143
- #
144
- def self.token
145
- @token ||= begin
146
- if Fleakr.auth_token
147
- Fleakr::Objects::AuthenticationToken.from_auth_token(Fleakr.auth_token)
148
- elsif Fleakr.frob
149
- Fleakr::Objects::AuthenticationToken.from_frob(Fleakr.frob)
150
- elsif Fleakr.mini_token
151
- Fleakr::Objects::AuthenticationToken.from_mini_token(Fleakr.mini_token)
152
- end
153
- end
154
- end
155
-
156
- # Reset the cached token whenever setting a new value for the mini_token, auth_token, or frob
157
- #
158
- [:mini_token, :auth_token, :frob].each do |attribute|
159
- class_eval <<-ACCESSOR
160
- def self.#{attribute}=(#{attribute})
161
- reset_token
162
- @@#{attribute} = #{attribute}
163
- end
164
- ACCESSOR
165
- end
166
-
167
- def self.reset_token # :nodoc: #
168
- @token = nil
169
- end
141
+ # # Get the authentication token needed for authenticated requests. Will either use
142
+ # # a valid auth_token (if available) or a mini-token to generate the auth_token.
143
+ # #
144
+ # def self.token
145
+ # @token ||= begin
146
+ # if Fleakr.auth_token
147
+ # Fleakr::Objects::AuthenticationToken.from_auth_token(Fleakr.auth_token)
148
+ # elsif Fleakr.frob
149
+ # Fleakr::Objects::AuthenticationToken.from_frob(Fleakr.frob)
150
+ # elsif Fleakr.mini_token
151
+ # Fleakr::Objects::AuthenticationToken.from_mini_token(Fleakr.mini_token)
152
+ # end
153
+ # end
154
+ # end
155
+ #
156
+ # # Reset the cached token whenever setting a new value for the mini_token, auth_token, or frob
157
+ # #
158
+ # [:mini_token, :auth_token, :frob].each do |attribute|
159
+ # class_eval <<-ACCESSOR
160
+ # def self.#{attribute}=(#{attribute})
161
+ # reset_token
162
+ # @@#{attribute} = #{attribute}
163
+ # end
164
+ # ACCESSOR
165
+ # end
166
+ #
167
+ # def self.reset_token # :nodoc: #
168
+ # @token = nil
169
+ # end
170
170
 
171
171
  end
@@ -86,42 +86,42 @@ module Fleakr::Api
86
86
  @parameter_list.sign?.should be(true)
87
87
  end
88
88
 
89
- should "know that it doesn't need to authenticate the request by default" do
90
- @parameter_list.authenticate?.should be(false)
91
- end
92
-
93
- should "know to authenticate the request when a token is available" do
94
- Fleakr.stubs(:token).with().returns(stub(:value => 'toke'))
95
- parameter_list = ParameterList.new
96
-
97
- parameter_list.authenticate?.should be(true)
98
- end
99
-
100
- should "not authenticate the request if it's been specifically told not to" do
101
- Fleakr.expects(:token).with().never
102
-
103
- parameter_list = ParameterList.new(:authenticate? => false)
104
- parameter_list.authenticate?.should be(false)
105
- end
106
-
107
-
108
- should "know to authenticate the request when asked" do
109
- Fleakr.expects(:token).with().returns(stub(:value => 'toke'))
110
-
111
- parameter_list = ParameterList.new(:authenticate? => true)
112
- parameter_list.authenticate?.should be(true)
113
- end
114
-
115
- should "contain the :auth_token parameter in the list if the request is to be authenticated" do
116
- Fleakr.expects(:token).with().returns(stub(:value => 'toke'))
117
-
118
- parameter_list = ParameterList.new(:authenticate? => true)
119
- auth_param = parameter_list[:auth_token]
120
-
121
- auth_param.name.should == 'auth_token'
122
- auth_param.value.should == 'toke'
123
- auth_param.include_in_signature?.should be(true)
124
- end
89
+ # should "know that it doesn't need to authenticate the request by default" do
90
+ # @parameter_list.authenticate?.should be(false)
91
+ # end
92
+
93
+ # should "know to authenticate the request when a token is available" do
94
+ # Fleakr.stubs(:token).with().returns(stub(:value => 'toke'))
95
+ # parameter_list = ParameterList.new
96
+ #
97
+ # parameter_list.authenticate?.should be(true)
98
+ # end
99
+
100
+ # should "not authenticate the request if it's been specifically told not to" do
101
+ # Fleakr.expects(:token).with().never
102
+ #
103
+ # parameter_list = ParameterList.new(:authenticate? => false)
104
+ # parameter_list.authenticate?.should be(false)
105
+ # end
106
+ #
107
+
108
+ # should "know to authenticate the request when asked" do
109
+ # Fleakr.expects(:token).with().returns(stub(:value => 'toke'))
110
+ #
111
+ # parameter_list = ParameterList.new(:authenticate? => true)
112
+ # parameter_list.authenticate?.should be(true)
113
+ # end
114
+
115
+ # should "contain the :auth_token parameter in the list if the request is to be authenticated" do
116
+ # Fleakr.expects(:token).with().returns(stub(:value => 'toke'))
117
+ #
118
+ # parameter_list = ParameterList.new(:authenticate? => true)
119
+ # auth_param = parameter_list[:auth_token]
120
+ #
121
+ # auth_param.name.should == 'auth_token'
122
+ # auth_param.value.should == 'toke'
123
+ # auth_param.include_in_signature?.should be(true)
124
+ # end
125
125
 
126
126
  should "include the signature in the list of parameters if the request is to be signed" do
127
127
  parameter_list = ParameterList.new
@@ -4,7 +4,7 @@ class FleakrTest < Test::Unit::TestCase
4
4
 
5
5
  context "The Fleakr module" do
6
6
 
7
- [:api_key, :shared_secret, :mini_token, :auth_token].each do |attribute|
7
+ [:api_key, :shared_secret].each do |attribute|
8
8
  should "be able to set a value for :#{attribute}" do
9
9
  value = 'value'
10
10
 
@@ -74,98 +74,98 @@ class FleakrTest < Test::Unit::TestCase
74
74
  Fleakr.upload(filename, :title => 'bop bip').should == [new_image]
75
75
  end
76
76
 
77
- should "be able to reset the cached token" do
78
- @token = stub()
79
- Fleakr.expects(:auth_token).with().at_least_once.returns('abc123')
80
- Fleakr::Objects::AuthenticationToken.expects(:from_auth_token).with('abc123').times(2).returns(@token)
81
- Fleakr.token # once
82
- Fleakr.reset_token
83
- Fleakr.token # twice
84
- end
85
-
86
- should "not have a token by default" do
87
- Fleakr.expects(:mini_token).with().returns(nil)
88
- Fleakr.expects(:auth_token).with().returns(nil)
89
- Fleakr.expects(:frob).with().returns(nil)
90
-
91
- Fleakr.token.should be(nil)
92
- end
93
-
94
- [:mini_token, :auth_token, :frob].each do |attribute|
95
- should "reset_token when :#{attribute} is set" do
96
- Fleakr.expects(:reset_token).with().at_least_once
97
- Fleakr.send("#{attribute}=".to_sym, 'value')
98
- end
99
- end
100
-
101
- context "when generating an AuthenticationToken from an auth_token string" do
102
-
103
- setup do
104
- @token = stub()
105
-
106
- Fleakr.expects(:auth_token).with().at_least_once.returns('abc123')
107
- Fleakr::Objects::AuthenticationToken.expects(:from_auth_token).with('abc123').returns(@token)
108
- end
109
-
110
- # Make sure to clear the cache
111
- teardown { Fleakr.auth_token = nil }
112
-
113
- should "return the token" do
114
- Fleakr.token.should == @token
115
- end
116
-
117
- should "cache the result" do
118
- 2.times { Fleakr.token }
119
- end
120
-
121
- end
122
-
123
- context "when generating an AuthenticationToken from a frob string" do
124
-
125
- setup do
126
- @token = stub()
127
-
128
- Fleakr.expects(:auth_token).with().at_least_once.returns(nil)
129
- Fleakr.expects(:frob).with().at_least_once.returns('abc123')
130
- Fleakr::Objects::AuthenticationToken.expects(:from_frob).with('abc123').returns(@token)
131
- end
132
-
133
- # Make sure to clear the cache
134
- teardown { Fleakr.frob = nil }
135
-
136
- should "return the token" do
137
- Fleakr.token.should == @token
138
- end
139
-
140
- should "cache the result" do
141
- 2.times { Fleakr.token }
142
- end
143
-
144
- end
145
-
146
- context "when generating an AuthenticationToken from a mini_token string" do
147
-
148
- setup do
149
- @token = stub()
150
-
151
- Fleakr.expects(:auth_token).with().at_least_once.returns(nil)
152
- Fleakr.expects(:mini_token).with().at_least_once.returns('123-123-123')
153
- Fleakr::Objects::AuthenticationToken.expects(:from_mini_token).with('123-123-123').returns(@token)
154
- end
155
-
156
- # Make sure to clear the cache
157
- teardown { Fleakr.mini_token = nil }
158
-
159
- should "return the token" do
160
- Fleakr.token.should == @token
161
- end
162
-
163
- should "cache the result" do
164
- 2.times { Fleakr.token }
165
- end
166
-
167
- end
77
+ # should "be able to reset the cached token" do
78
+ # @token = stub()
79
+ # Fleakr.expects(:auth_token).with().at_least_once.returns('abc123')
80
+ # Fleakr::Objects::AuthenticationToken.expects(:from_auth_token).with('abc123').times(2).returns(@token)
81
+ # Fleakr.token # once
82
+ # Fleakr.reset_token
83
+ # Fleakr.token # twice
84
+ # end
85
+ #
86
+ # should "not have a token by default" do
87
+ # Fleakr.expects(:mini_token).with().returns(nil)
88
+ # Fleakr.expects(:auth_token).with().returns(nil)
89
+ # Fleakr.expects(:frob).with().returns(nil)
90
+ #
91
+ # Fleakr.token.should be(nil)
92
+ # end
93
+ #
94
+ # [:mini_token, :auth_token, :frob].each do |attribute|
95
+ # should "reset_token when :#{attribute} is set" do
96
+ # Fleakr.expects(:reset_token).with().at_least_once
97
+ # Fleakr.send("#{attribute}=".to_sym, 'value')
98
+ # end
99
+ # end
168
100
 
169
- end
101
+ # context "when generating an AuthenticationToken from an auth_token string" do
102
+ #
103
+ # setup do
104
+ # @token = stub()
105
+ #
106
+ # Fleakr.expects(:auth_token).with().at_least_once.returns('abc123')
107
+ # Fleakr::Objects::AuthenticationToken.expects(:from_auth_token).with('abc123').returns(@token)
108
+ # end
109
+ #
110
+ # # Make sure to clear the cache
111
+ # teardown { Fleakr.auth_token = nil }
112
+ #
113
+ # should "return the token" do
114
+ # Fleakr.token.should == @token
115
+ # end
116
+ #
117
+ # should "cache the result" do
118
+ # 2.times { Fleakr.token }
119
+ # end
120
+ #
121
+ # end
122
+ #
123
+ # context "when generating an AuthenticationToken from a frob string" do
124
+ #
125
+ # setup do
126
+ # @token = stub()
127
+ #
128
+ # Fleakr.expects(:auth_token).with().at_least_once.returns(nil)
129
+ # Fleakr.expects(:frob).with().at_least_once.returns('abc123')
130
+ # Fleakr::Objects::AuthenticationToken.expects(:from_frob).with('abc123').returns(@token)
131
+ # end
132
+ #
133
+ # # Make sure to clear the cache
134
+ # teardown { Fleakr.frob = nil }
135
+ #
136
+ # should "return the token" do
137
+ # Fleakr.token.should == @token
138
+ # end
139
+ #
140
+ # should "cache the result" do
141
+ # 2.times { Fleakr.token }
142
+ # end
143
+ #
144
+ # end
145
+ #
146
+ # context "when generating an AuthenticationToken from a mini_token string" do
147
+ #
148
+ # setup do
149
+ # @token = stub()
150
+ #
151
+ # Fleakr.expects(:auth_token).with().at_least_once.returns(nil)
152
+ # Fleakr.expects(:mini_token).with().at_least_once.returns('123-123-123')
153
+ # Fleakr::Objects::AuthenticationToken.expects(:from_mini_token).with('123-123-123').returns(@token)
154
+ # end
155
+ #
156
+ # # Make sure to clear the cache
157
+ # teardown { Fleakr.mini_token = nil }
158
+ #
159
+ # should "return the token" do
160
+ # Fleakr.token.should == @token
161
+ # end
162
+ #
163
+ # should "cache the result" do
164
+ # 2.times { Fleakr.token }
165
+ # end
166
+ #
167
+ # end
168
+ #
169
+ end
170
170
 
171
171
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: latompa-fleakr
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.5.4
4
+ version: 0.5.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - Patrick Reagan