public
Description: An update of Scott Raymond's insanely easy flickr library
Clone URL: git://github.com/ctagg/flickr.git
Bugfix: groups methods would fail if only one group returned
Chris Taggart (author)
Mon May 12 12:15:32 -0700 2008
commit  6c78cf871d5e329b7f5ac1453b656591dbced06e
tree    ac2bb905daabeaaf0968b12f8d047f91d6b687a2
parent  2bd476fc5b656b20adf451f647fb4dc88add782d
...
150
151
152
153
154
155
156
 
 
 
 
 
 
 
157
158
159
...
283
284
285
286
287
288
289
 
 
 
 
 
 
290
291
292
...
150
151
152
 
 
 
 
153
154
155
156
157
158
159
160
161
162
...
286
287
288
 
 
 
 
289
290
291
292
293
294
295
296
297
0
@@ -150,10 +150,13 @@ class Flickr
0
 
0
   # Implements flickr.groups.search
0
   def groups(group_name, options={})
0
- groups_search({"text" => group_name}.merge(options))['groups']['group'].collect { |group| Group.new( "id" => group['nsid'],
0
- "name" => group['name'],
0
- "eighteenplus" => group['eighteenplus'],
0
- "client" => self) }
0
+ collection = groups_search({"text" => group_name}.merge(options))['groups']['group']
0
+ collection = [collection] if collection.is_a? Hash
0
+
0
+ collection.collect { |group| Group.new( "id" => group['nsid'],
0
+ "name" => group['name'],
0
+ "eighteenplus" => group['eighteenplus'],
0
+ "client" => self) }
0
   end
0
   
0
   # Implements flickr.tags.getRelated
0
@@ -283,10 +286,12 @@ class Flickr
0
         
0
     # Implements flickr.people.getPublicGroups
0
     def groups
0
- @client.people_getPublicGroups('user_id'=>@id)['groups']['group'].collect { |group| Group.new( "id" => group['nsid'],
0
- "name" => group['name'],
0
- "eighteenplus" => group['eighteenplus'],
0
- "client" => @client) }
0
+ collection = @client.people_getPublicGroups('user_id'=>@id)['groups']['group']
0
+ collection = [collection] if collection.is_a? Hash
0
+ collection.collect { |group| Group.new( "id" => group['nsid'],
0
+ "name" => group['name'],
0
+ "eighteenplus" => group['eighteenplus'],
0
+ "client" => @client) }
0
     end
0
     
0
     # Implements flickr.people.getPublicPhotos. Options hash allows you to add
...
235
236
237
 
 
 
 
 
 
 
 
238
239
240
...
329
330
331
 
 
 
 
 
 
 
332
333
334
...
774
775
776
 
 
 
 
 
 
 
 
777
778
779
...
235
236
237
238
239
240
241
242
243
244
245
246
247
248
...
337
338
339
340
341
342
343
344
345
346
347
348
349
...
789
790
791
792
793
794
795
796
797
798
799
800
801
802
0
@@ -235,6 +235,14 @@ class TestFlickr < Test::Unit::TestCase
0
     assert_equal f, group.client
0
   end
0
   
0
+ def test_should_instantiate_groups_from_search_response_with_single_group_returned
0
+ f = flickr_client
0
+ f.stubs(:request).returns(dummy_single_group_response)
0
+ assert_kind_of Array, groups = f.groups("foo")
0
+ assert_equal 1, groups.size
0
+ assert_equal "group1", groups.first.id
0
+ end
0
+
0
   # ##### DIRECT MODE
0
   #
0
   # def test_test_echo
0
@@ -329,6 +337,13 @@ class TestFlickr < Test::Unit::TestCase
0
     assert_equal f, group.client
0
   end
0
   
0
+ def test_should_instantiate_users_public_groups_when_only_one_returned
0
+ f = flickr_client
0
+ f.stubs(:request).returns(dummy_single_group_response)
0
+ user = new_user( 'client' => f )
0
+ groups = user.groups
0
+ assert_equal 1, groups.size
0
+ end
0
   # def test_getInfo
0
   # @u.getInfo
0
   # assert_equal @username, @u.username
0
@@ -774,6 +789,14 @@ class TestFlickr < Test::Unit::TestCase
0
            "eighteenplus" => "1"}] } }
0
   end
0
   
0
+ def dummy_single_group_response
0
+ { "groups" =>
0
+ { "group" =>
0
+ { "nsid" => "group1",
0
+ "name" => "Group One",
0
+ "eighteenplus" => "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.