public
Description: An update of Scott Raymond's insanely easy flickr library
Clone URL: git://github.com/ctagg/flickr.git
* Updated and refactored Flickr::Group class and Flickr#groups method to 
work with current Flickr API.
Flickr#groups now searches for given group, rather than 
groups.getActiveList (which no longer exists as Flickr API call)
Chris Taggart (author)
Mon May 12 05:46:57 -0700 2008
commit  12a6397989f5db3cd38eca633e3d0e5324ed006b
tree    ec54cf076fdf48c0e0ac2ebd91a1b404921761c5
parent  f73d71b990b1ca0a392973e6dc8d7ac78cdf5b10
...
1
2
 
 
3
4
5
...
1
2
3
4
5
6
7
0
@@ -1,5 +1,7 @@
0
 == 1.0.5 2008-05-12
0
 
0
+* 1 major enhancement:
0
+ * Updated and refactored Flickr::Group class and Flickr#groups method to work with current Flickr API. Flickr#groups now searches for given group, rather than groups.getActiveList (which no longer exists as Flickr API call)
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
...
148
149
150
151
152
153
 
 
 
 
 
 
154
155
156
...
581
582
583
584
585
586
587
 
 
 
 
 
 
 
 
588
589
590
...
148
149
150
 
 
 
151
152
153
154
155
156
157
158
159
...
584
585
586
 
 
 
 
587
588
589
590
591
592
593
594
595
596
597
0
@@ -148,9 +148,12 @@ class Flickr
0
     return User.new("id" => user["nsid"], "username" => user["username"], "client" => self)
0
   end
0
 
0
- # Implements flickr.groups.getActiveList
0
- def groups
0
- groups_getActiveList['activegroups']['group'].collect { |group| Group.new(group['nsid'], @api_key) }
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
   end
0
   
0
   # Implements flickr.tags.getRelated
0
@@ -581,10 +584,14 @@ class Flickr
0
   class Group
0
     attr_reader :id, :client, :name, :members, :online, :privacy, :chatid, :chatcount, :url
0
     
0
- def initialize(id=nil, api_key=nil)
0
- @id = id
0
- @api_key = api_key
0
- @client = Flickr.new @api_key
0
+ def initialize(id_or_params_hash=nil, api_key=nil)
0
+ if id_or_params_hash.is_a?(Hash)
0
+ id_or_params_hash.each { |k,v| self.instance_variable_set("@#{k}", v) } # convert extra_params into instance variables
0
+ else
0
+ @id = id_or_params_hash
0
+ @api_key = api_key
0
+ @client = Flickr.new @api_key
0
+ end
0
     end
0
 
0
     # Implements flickr.groups.getInfo and flickr.urls.getGroup
...
7
8
9
10
 
11
12
13
...
34
35
36
37
 
38
39
40
...
44
45
46
47
 
48
49
50
...
86
87
88
89
 
90
91
92
...
162
163
164
165
 
166
167
168
...
180
181
182
183
 
184
185
186
...
188
189
190
191
 
192
193
194
...
211
212
213
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
214
215
216
...
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
...
251
252
253
254
 
255
256
257
...
414
415
416
417
 
418
419
 
420
421
422
...
599
600
601
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
602
603
604
...
674
675
676
677
 
678
679
680
681
682
683
684
685
 
 
686
687
688
...
692
693
694
 
 
 
 
 
 
 
 
 
 
 
695
696
697
...
7
8
9
 
10
11
12
13
...
34
35
36
 
37
38
39
40
...
44
45
46
 
47
48
49
50
...
86
87
88
 
89
90
91
92
...
162
163
164
 
165
166
167
168
...
180
181
182
 
183
184
185
186
...
188
189
190
 
191
192
193
194
...
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
...
256
257
258
 
 
 
 
 
 
 
 
 
259
260
261
...
266
267
268
 
269
270
271
272
...
429
430
431
 
432
433
 
434
435
436
437
...
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
...
739
740
741
 
742
743
744
745
746
747
748
 
 
749
750
751
752
753
...
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
0
@@ -7,7 +7,7 @@ class TestFlickr < Test::Unit::TestCase
0
 
0
   # Flickr client tests
0
   #
0
- # instatiation tests
0
+ # instantiation tests
0
   def test_should_instantiate_new_flickr_client
0
     Flickr.any_instance.stubs(:login)
0
     flickr = Flickr.new('some_api_key', 'email@test.com', 'some_password', 'some_shared_secret')
0
@@ -34,7 +34,7 @@ class TestFlickr < Test::Unit::TestCase
0
     flickr = Flickr.new('api_key' => 'some_api_key', 'email' => 'email@test.com', 'password' => 'some_password', 'shared_secret' => 'some_shared_secret', 'foo' => 'bar')
0
   end
0
   
0
- # signature_from tests
0
+ # signature_from method tests
0
   def test_should_return_signature_from_given_params
0
     assert_equal Digest::MD5.hexdigest('shared_secret_codea_param1234xb_param5678yc_param97531t'),
0
                    authenticated_flickr_client.send(:signature_from, {:b_param => '5678y', 'c_param' => '97531t', :a_param => '1234x', :d_param => nil})
0
@@ -44,7 +44,7 @@ class TestFlickr < Test::Unit::TestCase
0
     assert_nil flickr_client.send(:signature_from, {:b_param => '5678y', :c_param => '97531t', :a_param => '1234x'})
0
   end
0
   
0
- # request_url tests
0
+ # request_url method tests
0
   def test_should_get_signature_for_params_when_building_url
0
     f = authenticated_flickr_client
0
     f.expects(:signature_from).with( 'method' => 'flickr.someMethod',
0
@@ -86,7 +86,7 @@ class TestFlickr < Test::Unit::TestCase
0
     f.some_unknown_methodForFlickr
0
   end
0
   
0
- # request tests
0
+ # request method tests
0
   def test_should_make_successful_request
0
     f = flickr_client
0
     f.expects(:http_get).with('some.url').returns(successful_xml_response)
0
@@ -162,7 +162,7 @@ class TestFlickr < Test::Unit::TestCase
0
     assert_equal f, user.client
0
   end
0
   
0
- # photos tests
0
+ # photos method tests
0
   def test_should_get_recent_photos_if_no_params_for_photos
0
     f = flickr_client
0
     f.expects(:photos_getRecent).returns({"photos" => {"photo" => []}})
0
@@ -180,7 +180,7 @@ class TestFlickr < Test::Unit::TestCase
0
     f.photos
0
   end
0
   
0
- # photos_search tests
0
+ # photos_search method tests
0
   def test_should_search_photos
0
     f = authenticated_flickr_client
0
     f.expects(:request).with('photos.search', anything).returns(dummy_photos_response)
0
@@ -188,7 +188,7 @@ class TestFlickr < Test::Unit::TestCase
0
     assert_kind_of Flickr::Photo, photos.first
0
   end
0
   
0
- # users tests
0
+ # users method 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
@@ -211,6 +211,30 @@ class TestFlickr < Test::Unit::TestCase
0
     assert_equal f, user.client
0
   end
0
   
0
+ # groups method tests
0
+ def test_should_search_for_given_group
0
+ f = flickr_client
0
+ f.expects(:request).with("groups.search", {"text" => "foo"}).returns(dummy_groups_response)
0
+ f.groups("foo")
0
+ end
0
+
0
+ def test_should_search_for_given_group_with_additional_params
0
+ f = flickr_client
0
+ f.expects(:request).with("groups.search", {"text" => "foo", "per_page" => "1"}).returns(dummy_groups_response)
0
+ f.groups("foo", "per_page" => "1")
0
+ end
0
+
0
+ def test_should_instantiate_groups_from_search_response
0
+ f = flickr_client
0
+ f.stubs(:request).returns(dummy_groups_response)
0
+ assert_kind_of Array, groups = f.groups("foo")
0
+ assert_kind_of Flickr::Group, group = groups.first
0
+ assert_equal "group1", group.id
0
+ assert_equal "Group One", group.name
0
+ assert_equal "0", group.instance_variable_get(:@eighteenplus)
0
+ assert_equal f, group.client
0
+ end
0
+
0
   # ##### DIRECT MODE
0
   #
0
   # def test_test_echo
0
@@ -232,15 +256,6 @@ class TestFlickr < Test::Unit::TestCase
0
   # assert_equal @user_id, @f.find_by_url(@user_url).getInfo.id # find user by URL
0
   # end
0
   #
0
- # def test_photos
0
- # assert_equal 100, @f.photos.size # find recent
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_groups
0
- # assert_kind_of Flickr::Group, @f.groups.first # find all active groups
0
- # end
0
- #
0
   # def test_licenses
0
   # assert_kind_of Array, @f.licenses # find all licenses
0
   # end
0
@@ -251,7 +266,7 @@ class TestFlickr < Test::Unit::TestCase
0
   #
0
   
0
   
0
- # ##### USER
0
+ # ##### Flickr::User tests
0
   #
0
   def test_should_instantiate_user
0
     user = Flickr::User.new({ 'id' => 'foo123',
0
@@ -414,9 +429,9 @@ class TestFlickr < Test::Unit::TestCase
0
     user.contactsPhotos
0
   end
0
   
0
- ##### PHOTO
0
+ # ##### Flickr::Photo tests
0
 
0
- def test_should_store_initialize_from_id
0
+ def test_should_initialize_photo_from_id
0
     photo = Flickr::Photo.new("foo123")
0
     assert_equal "foo123", photo.id
0
   end
0
@@ -599,6 +614,56 @@ class TestFlickr < Test::Unit::TestCase
0
     photo.context
0
   end
0
   
0
+ # ##### Flickr::Group tests
0
+ #
0
+ def test_should_instantiate_group_from_id
0
+ group = Flickr::Group.new("group1")
0
+ assert_equal "group1", group.id
0
+ end
0
+
0
+ # tests old api for instantiating groups
0
+ def test_should_instantiate_group_from_id_and_api_key
0
+ f = flickr_client
0
+ Flickr.expects(:new).with("some_api_key").returns(f)
0
+ group = Flickr::Group.new("group1", "some_api_key")
0
+ assert_equal f, group.client
0
+ end
0
+
0
+ # new api for instantiating groups
0
+ def test_should_instantiate_group_from_params_hash
0
+ group = Flickr::Group.new("id" => "group1", "name" => "Group One", "foo" => "bar")
0
+ assert_equal "group1", group.id
0
+ assert_equal "Group One", group.name
0
+ assert_equal "bar", group.instance_variable_get(:@foo)
0
+ end
0
+
0
+ def test_should_use_flickr_client_passed_in_params_hash_when_instantiating_group
0
+ f = flickr_client
0
+ Flickr.expects(:new).never
0
+ group = Flickr::Group.new("id" => "group1", "name" => "Group One", "client" => f)
0
+ assert_equal f, group.client
0
+ end
0
+
0
+ # def test_should_initialize_photo_from_id
0
+ # photo = Flickr::Photo.new("foo123")
0
+ # assert_equal "foo123", photo.id
0
+ # end
0
+ #
0
+ # def test_should_save_extra_params_as_instance_variables
0
+ # photo = Flickr::Photo.new('foo123', 'some_api_key', { 'key1' => 'value1', 'key2' => 'value2'})
0
+ # assert_equal 'value1', photo.instance_variable_get(:@key1)
0
+ # assert_equal 'value2', photo.instance_variable_get(:@key2)
0
+ # end
0
+ #
0
+ # def test_should_be_able_to_access_instance_variables_through_hash_like_interface
0
+ # photo = Flickr::Photo.new
0
+ # photo.instance_variable_set(:@key1, 'value1')
0
+ # assert_equal 'value1', photo['key1']
0
+ # assert_equal 'value1', photo[:key1]
0
+ # assert_nil photo[:key2]
0
+ # assert_nil photo['key2']
0
+ # end
0
+
0
   # ##### PHOTOSETS
0
   #
0
   # #def setup
0
@@ -674,15 +739,15 @@ class TestFlickr < Test::Unit::TestCase
0
            "key1" => "value1",
0
            "key2" => "value2" },
0
          { "id" => "bar456",
0
- "key3" => "value3"}] } }
0
+ "key3" => "value3"}] } }
0
   end
0
   
0
   def dummy_single_photo_response
0
     { "photos" =>
0
       { "photo" =>
0
         { "id" => "foo123",
0
- "key1" => "value1",
0
- "key2" => "value2" } } }
0
+ "key1" => "value1",
0
+ "key2" => "value2" } } }
0
   end
0
   
0
   def dummy_user_response
0
@@ -692,6 +757,17 @@ class TestFlickr < Test::Unit::TestCase
0
     }
0
   end
0
   
0
+ def dummy_groups_response
0
+ { "groups" =>
0
+ { "group" =>
0
+ [{ "nsid" => "group1",
0
+ "name" => "Group One",
0
+ "eighteenplus" => "0" },
0
+ { "nsid" => "group2",
0
+ "name" => "Group Two",
0
+ "eighteenplus" => "1"}] } }
0
+ end
0
+
0
   def successful_xml_response
0
     <<-EOF
0
       <?xml version="1.0" encoding="utf-8" ?>

Comments

    No one has commented yet.