public
Description: An update of Scott Raymond's insanely easy flickr library
Clone URL: git://github.com/ctagg/flickr.git
* Tweaked internals so new client instance isn't created each time new 
object (e.g. photo, user) is created
* Improved test coverage
Chris Taggart (author)
Mon May 12 04:32:38 -0700 2008
commit  f73d71b990b1ca0a392973e6dc8d7ac78cdf5b10
tree    1f2f4ad786f64d70485895558f118dc959ab24ff
parent  ac318ba401f5a676b324a16e7fb5b11951abed10
...
 
 
 
 
 
 
1
2
3
4
5
 
6
7
8
...
1
2
3
4
5
6
7
8
9
10
 
11
12
13
14
0
@@ -1,8 +1,14 @@
0
+== 1.0.5 2008-05-12
0
+
0
+* Minor enhancements:
0
+ * Tweaked internals so new client instance isn't created each time new object (e.g. photo, user) is created
0
+ * Improved test coverage
0
+
0
 == 1.0.4 2008-05-11
0
 
0
 * 1 major enhancement:
0
   * Added authentication facility as per current Flickr API
0
-* 1 minor enhancements:
0
+* 3 minor enhancements:
0
   * Improved test suite
0
   * Improved API for creating Flickr objects (old one still works)
0
   * Protected methods that are only used internally (e.g. request, request_url)
...
18
19
20
21
 
22
23
24
...
18
19
20
 
21
22
23
24
0
@@ -18,7 +18,7 @@ Rake::RDocTask.new { |rdoc|
0
 spec = Gem::Specification.new do |s|
0
   s.add_dependency('xml-simple', '>= 1.0.7')
0
   s.name = 'flickr'
0
- s.version = "1.0.4"
0
+ s.version = "1.0.5"
0
   s.platform = Gem::Platform::RUBY
0
   s.summary = "An insanely easy interface to the Flickr photo-sharing service. By Scott Raymond. Maintainer: Patrick Plattes"
0
   s.requirements << 'Flickr developers API key'
...
70
71
72
73
 
74
75
76
...
103
104
105
106
 
 
107
108
109
...
144
145
146
147
 
148
149
150
...
70
71
72
 
73
74
75
76
...
103
104
105
 
106
107
108
109
110
...
145
146
147
 
148
149
150
151
0
@@ -70,7 +70,7 @@ class Flickr
0
   # client object shuld be initialized with this. You'll also need a shared
0
   # secret code if you want to use authentication (e.g. to get a user's
0
   # private photos)
0
- # There are two ways to initalze the Flickr client. The preferred way is with
0
+ # There are two ways to initialize the Flickr client. The preferred way is with
0
   # a hash of params, e.g. 'api_key' => 'your_api_key', 'shared_secret' =>
0
   # 'shared_secret_code'. The older (deprecated) way is to pass an ordered series of
0
   # arguments. This is provided for continuity only, as several of the arguments
0
@@ -103,7 +103,8 @@ class Flickr
0
   end
0
   
0
   # Stores authentication credentials to use on all subsequent calls.
0
- # If authentication succeeds, returns a User object
0
+ # If authentication succeeds, returns a User object.
0
+ # NB This call is no longer in API and will result in an error if called
0
   def login(email='', password='')
0
     @email = email
0
     @password = password
0
@@ -144,7 +145,7 @@ class Flickr
0
   # Implements flickr.people.findByEmail and flickr.people.findByUsername.
0
   def users(lookup=nil)
0
     user = people_findByEmail('find_email'=>lookup)['user'] rescue people_findByUsername('username'=>lookup)['user']
0
- return User.new(user["nsid"], user["username"], nil, nil, @api_key)
0
+ return User.new("id" => user["nsid"], "username" => user["username"], "client" => self)
0
   end
0
 
0
   # Implements flickr.groups.getActiveList
...
188
189
190
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
191
192
193
...
200
201
202
203
204
205
206
207
208
209
210
211
212
213
...
222
223
224
225
226
227
228
229
230
231
232
233
...
240
241
242
 
 
243
244
245
...
267
268
269
270
 
 
 
271
272
273
274
275
276
277
278
279
280
 
 
 
 
 
 
 
 
 
 
 
281
282
283
...
665
666
667
 
 
 
 
 
 
 
668
669
670
...
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
...
223
224
225
 
 
 
 
 
 
 
 
226
227
228
...
237
238
239
 
 
 
 
 
 
240
241
242
...
249
250
251
252
253
254
255
256
...
278
279
280
 
281
282
283
284
285
286
287
288
289
 
 
 
 
290
291
292
293
294
295
296
297
298
299
300
301
302
303
...
685
686
687
688
689
690
691
692
693
694
695
696
697
0
@@ -188,6 +188,29 @@ class TestFlickr < Test::Unit::TestCase
0
     assert_kind_of Flickr::Photo, photos.first
0
   end
0
   
0
+ # users tests
0
+ def test_should_find_user_from_email
0
+ f = flickr_client
0
+ f.expects(:request).with('people.findByEmail', anything).returns(dummy_user_response)
0
+ assert_kind_of Flickr::User, user = f.users("email@test.com")
0
+ assert_equal "12037949632@N01", user.id
0
+ assert_equal "Stewart", user.username
0
+ end
0
+
0
+ def test_should_find_user_from_username_if_fails_to_get_from_email
0
+ f = flickr_client
0
+ f.expects(:request).with('people.findByEmail', anything).raises
0
+ f.expects(:request).with('people.findByUsername', anything).returns(dummy_user_response)
0
+ assert_kind_of Flickr::User, f.users("email@test.com")
0
+ end
0
+
0
+ def test_should_pass_on_flickr_client_when_finding_user
0
+ f = flickr_client
0
+ f.stubs(:request).returns(dummy_user_response)
0
+ user = f.users("email@test.com")
0
+ assert_equal f, user.client
0
+ end
0
+
0
   # ##### DIRECT MODE
0
   #
0
   # def test_test_echo
0
@@ -200,14 +223,6 @@ class TestFlickr < Test::Unit::TestCase
0
   #
0
   # ##### BASICS
0
   #
0
- # def test_request
0
- # assert_equal @f.request('test.echo')['stat'], 'ok'
0
- # end
0
- #
0
- # def test_request_url
0
- # assert_equal "http://flickr.com/services/rest/?api_key=#{@api_key}&method=flickr.test.echo&foo=bar&email=#{@email}&password=#{@password}", @f.request_url('test.echo', ['foo'=>'bar'])
0
- # end
0
- #
0
   # def test_login
0
   # assert_equal @username, @f.user.getInfo.username
0
   # end
0
@@ -222,12 +237,6 @@ class TestFlickr < Test::Unit::TestCase
0
   # assert_equal @user_id, @f.photos('user_id'=>@user_id).first.getInfo.owner.id # search by user_id
0
   # end
0
   #
0
- # def test_users
0
- # assert_equal @username, @f.users(@email).getInfo.username # find by email
0
- # assert_equal @username, @f.users(@username).getInfo.username # find by username
0
- # assert_kind_of Flickr::User, @f.users.first # find all online users
0
- # end
0
- #
0
   # def test_groups
0
   # assert_kind_of Flickr::Group, @f.groups.first # find all active groups
0
   # end
0
@@ -240,6 +249,8 @@ class TestFlickr < Test::Unit::TestCase
0
   #
0
   # Flickr#photos tests
0
   #
0
+
0
+
0
   # ##### USER
0
   #
0
   def test_should_instantiate_user
0
@@ -267,17 +278,26 @@ class TestFlickr < Test::Unit::TestCase
0
     assert_equal 'bar456', user.client.api_key
0
   end
0
   
0
- def test_should_instantiate_new_client_when_instantiating_user
0
+ def test_should_instantiate_new_client_when_instantiating_user_if_no_client_passed_in_params
0
+ f = flickr_client
0
+ Flickr.expects(:new).returns(f)
0
     user = Flickr::User.new({ 'id' => 'foo123',
0
                               'username' => 'some_user',
0
                               'name' => 'Some User',
0
                               'auth_token' => 'foobar789',
0
                               'shared_secret' => 'some_secret',
0
                               'api_key' => 'an_api_key' })
0
- assert_kind_of Flickr, user.client
0
- assert_equal 'foobar789', user.client.auth_token
0
- assert_equal 'an_api_key', user.client.api_key
0
- assert_equal 'some_secret', user.client.instance_variable_get(:@shared_secret)
0
+ assert_equal f, user.client
0
+ end
0
+
0
+ def test_should_not_instantiate_new_client_when_instantiating_user_if_client_passed_in_params
0
+ f = flickr_client
0
+ Flickr.expects(:new).never
0
+ user = Flickr::User.new({ 'id' => 'foo123',
0
+ 'username' => 'some_user',
0
+ 'name' => 'Some User',
0
+ 'client' => f })
0
+ assert_equal f, user.client
0
   end
0
   
0
   def test_should_not_instantiate_new_client_if_existing_client_passed
0
@@ -665,6 +685,13 @@ class TestFlickr < Test::Unit::TestCase
0
            "key2" => "value2" } } }
0
   end
0
   
0
+ def dummy_user_response
0
+ { "user" =>
0
+ { "nsid" => "12037949632@N01",
0
+ "username" => "Stewart" }
0
+ }
0
+ end
0
+
0
   def successful_xml_response
0
     <<-EOF
0
       <?xml version="1.0" encoding="utf-8" ?>

Comments

    No one has commented yet.