latompa-fleakr 0.5.5 → 0.5.7
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/lib/fleakr/api/parameter_list.rb +12 -0
- data/lib/fleakr/objects/photo.rb +1 -1
- data/lib/fleakr/version.rb +2 -2
- data/lib/fleakr.rb +34 -30
- data/test/fixtures/people.getPublicPhotos.xml +2 -2
- data/test/unit/fleakr/api/parameter_list_test.rb +36 -36
- data/test/unit/fleakr/objects/photo_test.rb +7 -6
- data/test/unit/fleakr_test.rb +85 -93
- metadata +1 -1
@@ -22,11 +22,15 @@ 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
|
+
|
25
28
|
@list = Hash.new
|
26
29
|
|
27
30
|
options.each {|k,v| self << ValueParameter.new(k.to_s, v) }
|
28
31
|
|
29
32
|
self << ValueParameter.new('api_key', Fleakr.api_key)
|
33
|
+
self << ValueParameter.new('auth_token', Fleakr.token.value) if authenticate?
|
30
34
|
end
|
31
35
|
|
32
36
|
# Add a new parameter (ValueParameter / FileParameter) to the list
|
@@ -41,6 +45,14 @@ module Fleakr
|
|
41
45
|
!Fleakr.shared_secret.blank?
|
42
46
|
end
|
43
47
|
|
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
|
+
#
|
44
56
|
def [](key)
|
45
57
|
list[key.to_s]
|
46
58
|
end
|
data/lib/fleakr/objects/photo.rb
CHANGED
@@ -40,7 +40,7 @@ module Fleakr
|
|
40
40
|
def_delegators :context, :next, :previous
|
41
41
|
|
42
42
|
flickr_attribute :id, :from => ['@id', 'photoid']
|
43
|
-
flickr_attribute :title, :description, :secret, :posted, :taken, :url
|
43
|
+
flickr_attribute :title, :description, :secret, :posted, :taken, :url, :dateupload
|
44
44
|
flickr_attribute :farm_id, :from => '@farm'
|
45
45
|
flickr_attribute :server_id, :from => '@server'
|
46
46
|
flickr_attribute :owner_id, :from => ['@owner', 'owner@nsid']
|
data/lib/fleakr/version.rb
CHANGED
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
|
88
|
+
mattr_accessor :api_key, :shared_secret, :mini_token, :auth_token, :frob
|
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,38 @@ module Fleakr
|
|
138
138
|
Fleakr::Objects::Contact.find_all_contacts(params)
|
139
139
|
end
|
140
140
|
|
141
|
-
#
|
142
|
-
#
|
143
|
-
#
|
144
|
-
|
145
|
-
|
146
|
-
|
147
|
-
|
148
|
-
|
149
|
-
|
150
|
-
|
151
|
-
|
152
|
-
|
153
|
-
|
154
|
-
|
155
|
-
|
156
|
-
#
|
157
|
-
#
|
158
|
-
|
159
|
-
|
160
|
-
|
161
|
-
|
162
|
-
|
163
|
-
|
164
|
-
|
165
|
-
|
166
|
-
|
167
|
-
|
168
|
-
|
169
|
-
|
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
|
+
Thread.current[: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
|
+
Fleakr.reset_token
|
162
|
+
Thread.current[:#{attribute}] = #{attribute}
|
163
|
+
end
|
164
|
+
|
165
|
+
def self.#{attribute}
|
166
|
+
Thread.current[:#{attribute}]
|
167
|
+
end
|
168
|
+
ACCESSOR
|
169
|
+
end
|
170
|
+
|
171
|
+
def self.reset_token # :nodoc: #
|
172
|
+
Thread.current[:token] = nil
|
173
|
+
end
|
170
174
|
|
171
175
|
end
|
@@ -1,7 +1,7 @@
|
|
1
1
|
<?xml version="1.0" encoding="utf-8" ?>
|
2
2
|
<rsp stat="ok">
|
3
3
|
<photos page="1" pages="1" perpage="100" total="76">
|
4
|
-
<photo id="2924549350" owner="21775151@N06" secret="cbc1804258" server="3250" farm="4" title="Photo #1" ispublic="1" isfriend="0" isfamily="0" />
|
5
|
-
<photo id="2923697303" owner="21775151@N06" secret="649aa95f29" server="3208" farm="4" title="Photo #2" ispublic="1" isfriend="0" isfamily="0" />
|
4
|
+
<photo id="2924549350" owner="21775151@N06" secret="cbc1804258" server="3250" farm="4" title="Photo #1" ispublic="1" isfriend="0" isfamily="0" dateupload="555"/>
|
5
|
+
<photo id="2923697303" owner="21775151@N06" secret="649aa95f29" server="3208" farm="4" title="Photo #2" ispublic="1" isfriend="0" isfamily="0" dateupload="555"/>
|
6
6
|
</photos>
|
7
7
|
</rsp>
|
@@ -86,42 +86,42 @@ module Fleakr::Api
|
|
86
86
|
@parameter_list.sign?.should be(true)
|
87
87
|
end
|
88
88
|
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
|
116
|
-
|
117
|
-
|
118
|
-
|
119
|
-
|
120
|
-
|
121
|
-
|
122
|
-
|
123
|
-
|
124
|
-
|
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
|
@@ -67,12 +67,13 @@ module Fleakr::Objects
|
|
67
67
|
@object = Photo.new(Hpricot.XML(read_fixture('people.getPublicPhotos')).at('rsp/photos/photo'))
|
68
68
|
end
|
69
69
|
|
70
|
-
should_have_a_value_for :id
|
71
|
-
should_have_a_value_for :title
|
72
|
-
should_have_a_value_for :farm_id
|
73
|
-
should_have_a_value_for :server_id
|
74
|
-
should_have_a_value_for :secret
|
75
|
-
should_have_a_value_for :owner_id
|
70
|
+
should_have_a_value_for :id => '2924549350'
|
71
|
+
should_have_a_value_for :title => 'Photo #1'
|
72
|
+
should_have_a_value_for :farm_id => '4'
|
73
|
+
should_have_a_value_for :server_id => '3250'
|
74
|
+
should_have_a_value_for :secret => 'cbc1804258'
|
75
|
+
should_have_a_value_for :owner_id => '21775151@N06'
|
76
|
+
should_have_a_value_for :dateupload => '555'
|
76
77
|
|
77
78
|
end
|
78
79
|
|
data/test/unit/fleakr_test.rb
CHANGED
@@ -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].each do |attribute|
|
7
|
+
[:api_key, :shared_secret, :mini_token, :auth_token].each do |attribute|
|
8
8
|
should "be able to set a value for :#{attribute}" do
|
9
9
|
value = 'value'
|
10
10
|
|
@@ -74,98 +74,90 @@ class FleakrTest < Test::Unit::TestCase
|
|
74
74
|
Fleakr.upload(filename, :title => 'bop bip').should == [new_image]
|
75
75
|
end
|
76
76
|
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
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
|
+
[:mini_token, :auth_token, :frob].each do |attribute|
|
87
|
+
should "reset_token when :#{attribute} is set" do
|
88
|
+
Fleakr.expects(:reset_token).with().at_least_once
|
89
|
+
Fleakr.send("#{attribute}=".to_sym, 'value')
|
90
|
+
end
|
91
|
+
end
|
92
|
+
|
93
|
+
context "when generating an AuthenticationToken from an auth_token string" do
|
94
|
+
|
95
|
+
setup do
|
96
|
+
@token = stub()
|
97
|
+
|
98
|
+
Fleakr.expects(:auth_token).with().at_least_once.returns('abc123')
|
99
|
+
Fleakr::Objects::AuthenticationToken.expects(:from_auth_token).with('abc123').returns(@token)
|
100
|
+
end
|
101
|
+
|
102
|
+
# Make sure to clear the cache
|
103
|
+
teardown { Fleakr.auth_token = nil }
|
104
|
+
|
105
|
+
should "return the token" do
|
106
|
+
Fleakr.token.should == @token
|
107
|
+
end
|
108
|
+
|
109
|
+
should "cache the result" do
|
110
|
+
2.times { Fleakr.token }
|
111
|
+
end
|
112
|
+
|
113
|
+
end
|
114
|
+
|
115
|
+
context "when generating an AuthenticationToken from a frob string" do
|
116
|
+
|
117
|
+
setup do
|
118
|
+
@token = stub()
|
119
|
+
|
120
|
+
Fleakr.expects(:auth_token).with().at_least_once.returns(nil)
|
121
|
+
Fleakr.expects(:frob).with().at_least_once.returns('abc123')
|
122
|
+
Fleakr::Objects::AuthenticationToken.expects(:from_frob).with('abc123').returns(@token)
|
123
|
+
end
|
124
|
+
|
125
|
+
# Make sure to clear the cache
|
126
|
+
teardown { Fleakr.frob = nil }
|
127
|
+
|
128
|
+
should "return the token" do
|
129
|
+
Fleakr.token.should == @token
|
130
|
+
end
|
131
|
+
|
132
|
+
should "cache the result" do
|
133
|
+
2.times { Fleakr.token }
|
134
|
+
end
|
135
|
+
|
136
|
+
end
|
137
|
+
|
138
|
+
context "when generating an AuthenticationToken from a mini_token string" do
|
139
|
+
|
140
|
+
setup do
|
141
|
+
@token = stub()
|
142
|
+
|
143
|
+
Fleakr.expects(:auth_token).with().at_least_once.returns(nil)
|
144
|
+
Fleakr.expects(:mini_token).with().at_least_once.returns('123-123-123')
|
145
|
+
Fleakr::Objects::AuthenticationToken.expects(:from_mini_token).with('123-123-123').returns(@token)
|
146
|
+
end
|
147
|
+
|
148
|
+
# Make sure to clear the cache
|
149
|
+
teardown { Fleakr.mini_token = nil }
|
150
|
+
|
151
|
+
should "return the token" do
|
152
|
+
Fleakr.token.should == @token
|
153
|
+
end
|
154
|
+
|
155
|
+
should "cache the result" do
|
156
|
+
2.times { Fleakr.token }
|
157
|
+
end
|
158
|
+
|
159
|
+
end
|
100
160
|
|
101
|
-
|
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
|
161
|
+
end
|
170
162
|
|
171
163
|
end
|