commonthread-flickr_fu 0.2.2 → 0.3.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (53) hide show
  1. data/.gitignore +13 -0
  2. data/Rakefile +40 -8
  3. data/VERSION.yml +4 -0
  4. data/flickr_fu.gemspec +114 -33
  5. data/lib/flickr/base.rb +49 -22
  6. data/lib/flickr/contact.rb +16 -0
  7. data/lib/flickr/contacts.rb +55 -0
  8. data/lib/flickr/geo.rb +42 -0
  9. data/lib/flickr/location.rb +15 -0
  10. data/lib/flickr/photo.rb +23 -0
  11. data/lib/flickr/photos.rb +6 -1
  12. data/lib/flickr/photoset.rb +36 -0
  13. data/lib/flickr/photosets.rb +36 -0
  14. data/lib/flickr/urls.rb +44 -0
  15. data/lib/flickr_fu.rb +23 -1
  16. data/spec/fixtures/flickr/contacts/get_list-fail-99.xml +4 -0
  17. data/spec/fixtures/flickr/contacts/get_public_list-0.xml +7 -0
  18. data/spec/fixtures/flickr/photos/geo/get_location-0.xml +11 -0
  19. data/spec/fixtures/flickr/photos/geo/get_location-fail-2.xml +4 -0
  20. data/spec/fixtures/flickr/photos/get_info-0.xml +41 -0
  21. data/spec/fixtures/flickr/photos/get_info-1.xml +19 -0
  22. data/spec/fixtures/flickr/photos/get_sizes-0.xml +10 -0
  23. data/spec/fixtures/flickr/photos/get_sizes-1.xml +8 -0
  24. data/spec/fixtures/flickr/photos/licenses/get_info.xml +12 -0
  25. data/spec/fixtures/flickr/photosets/get_list-0.xml +13 -0
  26. data/spec/fixtures/flickr/photosets/get_photos-0.xml +7 -0
  27. data/spec/fixtures/flickr/test/echo-0.xml +5 -0
  28. data/spec/fixtures/flickr/test/null-fail-99.xml +4 -0
  29. data/spec/fixtures/flickr/urls/get_group-0.xml +4 -0
  30. data/spec/fixtures/flickr/urls/get_group-fail-1.xml +4 -0
  31. data/spec/fixtures/flickr/urls/get_user_photos-0.xml +4 -0
  32. data/spec/fixtures/flickr/urls/get_user_photos-fail-1.xml +4 -0
  33. data/spec/fixtures/flickr/urls/get_user_photos-fail-2.xml +4 -0
  34. data/spec/fixtures/flickr/urls/get_user_profile-0.xml +4 -0
  35. data/spec/fixtures/flickr/urls/get_user_profile-fail-1.xml +4 -0
  36. data/spec/fixtures/flickr/urls/get_user_profile-fail-2.xml +4 -0
  37. data/spec/fixtures/flickr/urls/lookup_group-0.xml +6 -0
  38. data/spec/fixtures/flickr/urls/lookup_group-fail-1.xml +4 -0
  39. data/spec/fixtures/flickr/urls/lookup_user-0.xml +6 -0
  40. data/spec/fixtures/flickr/videos/get_info-0.xml +31 -0
  41. data/spec/fixtures/flickr/videos/get_sizes-0.xml +13 -0
  42. data/spec/flickr/base_spec.rb +97 -0
  43. data/spec/flickr/contacts_spec.rb +47 -0
  44. data/spec/flickr/errors_spec.rb +21 -0
  45. data/spec/flickr/geo_spec.rb +20 -0
  46. data/spec/flickr/photo_spec.rb +123 -0
  47. data/spec/flickr/photos_spec.rb +50 -0
  48. data/spec/flickr/photosets_spec.rb +49 -0
  49. data/spec/flickr/test_spec.rb +34 -0
  50. data/spec/flickr/urls_spec.rb +99 -0
  51. data/spec/spec.opts +4 -0
  52. data/spec/spec_helper.rb +20 -0
  53. metadata +65 -7
@@ -0,0 +1,15 @@
1
+ class Flickr::Photos::Location
2
+
3
+ attr_accessor :latitude, :longitude, :accuracy
4
+
5
+ # Create an instance of Flickr::Photos::Location
6
+ #
7
+ # Params
8
+ # * attributes (Required)
9
+ # a hash of attributes used to set the initial values of the Location object
10
+ def initialize(attributes)
11
+ attributes.each do |k,v|
12
+ send("#{k}=", v)
13
+ end
14
+ end
15
+ end
@@ -146,6 +146,29 @@ class Flickr::Photos::Photo
146
146
  def license
147
147
  @flickr.photos.licenses[self.license_id]
148
148
  end
149
+
150
+ # Returns the location of the photo (if available)
151
+ # or nil if photo is not geo-tagged.
152
+ def location
153
+ begin
154
+ @location ||= @flickr.photos.geo.get_location(self.id)
155
+ rescue Flickr::Error => e
156
+ if e.code == 2 # 2: Photo has no location information.
157
+ return nil
158
+ else
159
+ raise e
160
+ end
161
+ end
162
+ end
163
+
164
+ def location= location
165
+ if !location.nil?
166
+ @flickr.photos.geo.set_location(self.id, location.latitude, location.longitude, location.accuracy)
167
+ else
168
+ @flickr.photos.geo.remove_location(self.id)
169
+ end
170
+ @location = location
171
+ end
149
172
 
150
173
  # Sets the license for a photo.
151
174
  #
@@ -148,7 +148,7 @@ class Flickr::Photos < Flickr::Base
148
148
  # * media (Optional)
149
149
  # The type of media to search for. 'photo', 'video', or 'both' are allowed arguments, with 'both' being the default.
150
150
  #
151
- def get_recent(options)
151
+ def get_recent(options = {})
152
152
  options.merge!({:extras => "license,date_upload,date_taken,owner_name,icon_server,original_format,last_update,geo,tags,machine_tags,o_dims,views,media"})
153
153
 
154
154
  rsp = @flickr.send_request('flickr.photos.getRecent', options)
@@ -201,6 +201,11 @@ class Flickr::Photos < Flickr::Base
201
201
  end
202
202
  end
203
203
  end
204
+
205
+ # creates and/or returns the Flickr::Photos::Geo object
206
+ def geo
207
+ @geo ||= Flickr::Photos::Geo.new(@flickr)
208
+ end
204
209
 
205
210
  # Returns a Flickr::Photos::Photo object of the given id.
206
211
  # Raises an error if photo not found
@@ -0,0 +1,36 @@
1
+ class Flickr::Photosets::Photoset
2
+ attr_accessor :id,:num_photos,:title,:description
3
+
4
+ def initialize(flickr, attributes)
5
+ @flickr = flickr
6
+ attributes.each do |k,v|
7
+ send("#{k}=", v)
8
+ end
9
+ end
10
+
11
+ def get_photos(options={})
12
+ options = options.merge(:photoset_id=>id)
13
+ rsp = @flickr.send_request('flickr.photosets.getPhotos', options)
14
+ collect_photos(rsp)
15
+ end
16
+
17
+ protected
18
+ def collect_photos(rsp)
19
+ photos = []
20
+ return photos unless rsp
21
+ if rsp.photoset.photo
22
+ rsp.photoset.photo.each do |photo|
23
+ attributes = create_attributes(photo)
24
+ photos << Flickr::Photos::Photo.new(@flickr,attributes)
25
+ end
26
+ end
27
+ return photos
28
+ end
29
+
30
+ def create_attributes(photo)
31
+ {:id => photo[:id],
32
+ :secret => photo[:secret],
33
+ :server => photo[:server],
34
+ :title => photo[:title]}
35
+ end
36
+ end
@@ -0,0 +1,36 @@
1
+ class Flickr::Photosets < Flickr::Base
2
+ def initialize(flickr)
3
+ @flickr = flickr
4
+ end
5
+
6
+ # Get the authorized user's contact list.
7
+ #
8
+ def get_list(options={})
9
+ rsp = @flickr.send_request('flickr.photosets.getList', options)
10
+ collect_photosets(rsp)
11
+ end
12
+
13
+ protected
14
+ def collect_photosets(rsp)
15
+ photosets = []
16
+ return photosets unless rsp
17
+ if rsp.photosets.photoset
18
+ rsp.photosets.photoset.each do |photoset|
19
+ attributes = create_attributes(photoset)
20
+ photosets << Photoset.new(@flickr, attributes)
21
+ end
22
+ end
23
+ return photosets
24
+ end
25
+
26
+ def create_attributes(photoset)
27
+
28
+ {
29
+ :id => photoset[:id],
30
+ :num_photos => photoset[:photos],
31
+ :title => photoset.title,
32
+ :description => photoset.description
33
+ }
34
+ end
35
+
36
+ end
@@ -0,0 +1,44 @@
1
+ # Wrapping class that holds methods in the flickr.urls namespace
2
+ class Flickr::Urls < Flickr::Base
3
+ def initialize(flickr)
4
+ @flickr = flickr
5
+ end
6
+
7
+ def get_group group_id
8
+ rsp = @flickr.send_request('flickr.urls.getGroup', {:group_id => group_id})
9
+ rsp.group[:url]
10
+ end
11
+
12
+ def get_user_photos user_id
13
+ rsp = @flickr.send_request('flickr.urls.getUserPhotos', {:user_id => user_id})
14
+ rsp.user[:url]
15
+ end
16
+
17
+ def get_user_profile user_id
18
+ rsp = @flickr.send_request('flickr.urls.getUserProfile', {:user_id => user_id})
19
+ rsp.user[:url]
20
+ end
21
+
22
+ def lookup_group url #, options = {}
23
+ #options.symbolize_keys!
24
+ #options.reverse_merge!({:include_groupname => false})
25
+ rsp = @flickr.send_request('flickr.urls.lookupGroup', {:url => url})
26
+ #if options[:include_groupname]
27
+ #[rsp.group[:id], {:groupname => rsp.group.groupname}]
28
+ #else
29
+ rsp.group[:id]
30
+ #end
31
+ end
32
+
33
+ def lookup_user url
34
+ rsp = @flickr.send_request('flickr.urls.lookupUser', {:url => url})
35
+ user_id = UserLookupResult.new(rsp.user[:id])
36
+ user_id.username = rsp.user.username
37
+ user_id
38
+ end
39
+
40
+ class UserLookupResult < String
41
+ attr_accessor :username
42
+ end
43
+
44
+ end
@@ -11,7 +11,29 @@ require 'time'
11
11
  require 'date'
12
12
 
13
13
  # base must load first
14
- %w(base test auth token photos photo photo_response comment note size uploader status people person license errors).each do |file|
14
+ [ "base",
15
+ "test",
16
+ "auth",
17
+ "token",
18
+ "photos",
19
+ "photo",
20
+ "photo_response",
21
+ "photosets",
22
+ "photoset",
23
+ "comment",
24
+ "note",
25
+ "size",
26
+ "uploader",
27
+ "status",
28
+ "people",
29
+ "person",
30
+ "license",
31
+ "errors",
32
+ "contacts",
33
+ "contact",
34
+ "geo",
35
+ "location",
36
+ "urls" ].each do |file|
15
37
  require File.join(File.dirname(__FILE__), 'flickr', file)
16
38
  end
17
39
 
@@ -0,0 +1,4 @@
1
+ <?xml version="1.0" encoding="utf-8" ?>
2
+ <rsp stat="fail">
3
+ <err code="99" msg="Insufficient permissions. Method requires read privileges; none granted."/>
4
+ </rsp>
@@ -0,0 +1,7 @@
1
+ <?xml version="1.0" encoding="utf-8" ?>
2
+ <rsp stat="ok">
3
+ <contacts page="1" pages="1" per_page="1000" perpage="1000" total="2">
4
+ <contact nsid="40718771@N00" username="kooop" iconserver="2" iconfarm="1" ignored="0" />
5
+ <contact nsid="20039881@N00" username="wayoutwest" iconserver="1" iconfarm="1" ignored="0" />
6
+ </contacts>
7
+ </rsp>
@@ -0,0 +1,11 @@
1
+ <?xml version="1.0" encoding="utf-8" ?>
2
+ <rsp stat="ok">
3
+ <photo id="2984637736">
4
+ <location latitude="50.041376" longitude="21.999006" accuracy="16" context="0" place_id="X.5ul_ucAJtJcT0" woeid="517126">
5
+ <locality place_id="X.5ul_ucAJtJcT0" woeid="517126">Rzeszów</locality>
6
+ <county place_id="gUrbqNqYA5n4kv.erw" woeid="12591341">Rzeszów</county>
7
+ <region place_id="acDFruGYA5lyOpcIVg" woeid="12577943">Subcarpathia</region>
8
+ <country place_id="0kV97TybAphIxvm14g" woeid="23424923">Poland</country>
9
+ </location>
10
+ </photo>
11
+ </rsp>
@@ -0,0 +1,4 @@
1
+ <?xml version="1.0" encoding="utf-8" ?>
2
+ <rsp stat="fail">
3
+ <err code="2" msg="Photo has no location information."/>
4
+ </rsp>
@@ -0,0 +1,41 @@
1
+ <?xml version="1.0" encoding="utf-8" ?>
2
+ <rsp stat="ok">
3
+ <photo id="2984637736" secret="9e5762e027" server="3180" farm="4" dateuploaded="1225297614" isfavorite="0" license="0" rotation="0" media="photo">
4
+ <owner nsid="80755658@N00" username="Maciej Biłas" realname="Maciej Biłas" location="Rzeszów, Poland"/>
5
+ <title>Demolition of Hotel Rzeszów</title>
6
+ <description>
7
+ The last picture from a quite old event. The demolition of the best known hotel in Rzeszów called Hotel Rzeszów.
8
+ </description>
9
+ <visibility ispublic="1" isfriend="0" isfamily="0"/>
10
+ <dates posted="1225297614" taken="2007-04-20 17:56:06" takengranularity="0" lastupdate="1227358764"/>
11
+ <editability cancomment="0" canaddmeta="0"/>
12
+ <usage candownload="0" canblog="0" canprint="0"/>
13
+ <comments>0</comments>
14
+ <notes/>
15
+ <tags>
16
+ <tag id="4963651-2984637736-9769036" author="80755658@N00" raw="Hotel Rzeszów" machine_tag="0">hotelrzeszów
17
+ </tag>
18
+ <tag id="4963651-2984637736-9381" author="80755658@N00" raw="demolition" machine_tag="0">demolition
19
+ </tag>
20
+ <tag id="4963651-2984637736-1888184" author="80755658@N00" raw="Rzeszów" machine_tag="0">rzeszów
21
+ </tag>
22
+ <tag id="4963651-2984637736-8302" author="80755658@N00" raw="Poland" machine_tag="0">poland
23
+ </tag>
24
+ </tags>
25
+ <location latitude="50.041376" longitude="21.999006" accuracy="16" place_id="X.5ul_ucAJtJcT0" woeid="517126">
26
+ <locality place_id="X.5ul_ucAJtJcT0" woeid="517126">Rzeszów
27
+ </locality>
28
+ <county place_id="gUrbqNqYA5n4kv.erw" woeid="12591341">Rzeszów
29
+ </county>
30
+ <region place_id="acDFruGYA5lyOpcIVg" woeid="12577943">Subcarpathia
31
+ </region>
32
+ <country place_id="0kV97TybAphIxvm14g" woeid="23424923">Poland
33
+ </country>
34
+ </location>
35
+ <geoperms ispublic="1" iscontact="0" isfriend="0" isfamily="0"/>
36
+ <urls>
37
+ <url type="photopage">http://www.flickr.com/photos/lvizard/2984637736/
38
+ </url>
39
+ </urls>
40
+ </photo>
41
+ </rsp>
@@ -0,0 +1,19 @@
1
+ <?xml version="1.0" encoding="utf-8" ?>
2
+ <rsp stat="ok">
3
+ <photo id="3059178826" secret="951324cc9f" server="3008" farm="4" dateuploaded="1227628465" isfavorite="0" license="0" rotation="0" originalsecret="fdbf0e4ced" originalformat="jpg" views="0" media="photo">
4
+ <owner nsid="80755658@N00" username="Maciej Biłas" realname="Maciej Biłas" location="Rzeszów, Poland"/>
5
+ <title>test</title>
6
+ <description/>
7
+ <visibility ispublic="0" isfriend="0" isfamily="0"/>
8
+ <dates posted="1227628465" taken="2008-11-25 16:54:25" takengranularity="0" lastupdate="1227628476"/>
9
+ <permissions permcomment="3" permaddmeta="2"/>
10
+ <editability cancomment="1" canaddmeta="1"/>
11
+ <usage candownload="0" canblog="1" canprint="1"/>
12
+ <comments>0</comments>
13
+ <notes/>
14
+ <tags/>
15
+ <urls>
16
+ <url type="photopage">http://www.flickr.com/photos/lvizard/3059178826/</url>
17
+ </urls>
18
+ </photo>
19
+ </rsp>
@@ -0,0 +1,10 @@
1
+ <?xml version="1.0" encoding="utf-8" ?>
2
+ <rsp stat="ok">
3
+ <sizes canblog="0" canprint="0" candownload="0">
4
+ <size label="Square" width="75" height="75" source="http://farm4.static.flickr.com/3180/2984637736_9e5762e027_s.jpg" url="http://www.flickr.com/photos/lvizard/2984637736/sizes/sq/" media="photo"/>
5
+ <size label="Thumbnail" width="100" height="67" source="http://farm4.static.flickr.com/3180/2984637736_9e5762e027_t.jpg" url="http://www.flickr.com/photos/lvizard/2984637736/sizes/t/" media="photo"/>
6
+ <size label="Small" width="240" height="160" source="http://farm4.static.flickr.com/3180/2984637736_9e5762e027_m.jpg" url="http://www.flickr.com/photos/lvizard/2984637736/sizes/s/" media="photo"/>
7
+ <size label="Medium" width="500" height="333" source="http://farm4.static.flickr.com/3180/2984637736_9e5762e027.jpg" url="http://www.flickr.com/photos/lvizard/2984637736/sizes/m/" media="photo"/>
8
+ <size label="Large" width="1024" height="683" source="http://farm4.static.flickr.com/3180/2984637736_9e5762e027_b.jpg" url="http://www.flickr.com/photos/lvizard/2984637736/sizes/l/" media="photo"/>
9
+ </sizes>
10
+ </rsp>
@@ -0,0 +1,8 @@
1
+ <?xml version="1.0" encoding="utf-8" ?>
2
+ <rsp stat="ok">
3
+ <sizes canblog="1" canprint="1" candownload="0">
4
+ <size label="Square" width="75" height="75" source="http://farm4.static.flickr.com/3008/3059178826_951324cc9f_s.jpg" url="http://www.flickr.com/photos/lvizard/3059178826/sizes/sq/" media="photo"/>
5
+ <size label="Thumbnail" width="70" height="72" source="http://farm4.static.flickr.com/3008/3059178826_951324cc9f_t.jpg" url="http://www.flickr.com/photos/lvizard/3059178826/sizes/t/" media="photo"/>
6
+ <size label="Original" width="70" height="72" source="http://farm4.static.flickr.com/3008/3059178826_fdbf0e4ced_o.jpg" url="http://www.flickr.com/photos/lvizard/3059178826/sizes/o/" media="photo"/>
7
+ </sizes>
8
+ </rsp>
@@ -0,0 +1,12 @@
1
+ <?xml version="1.0" encoding="utf-8" ?>
2
+ <rsp stat="ok">
3
+ <licenses>
4
+ <license id="0" name="All Rights Reserved" url=""/>
5
+ <license id="4" name="Attribution License" url="http://creativecommons.org/licenses/by/2.0/"/>
6
+ <license id="6" name="Attribution-NoDerivs License" url="http://creativecommons.org/licenses/by-nd/2.0/"/>
7
+ <license id="3" name="Attribution-NonCommercial-NoDerivs License" url="http://creativecommons.org/licenses/by-nc-nd/2.0/"/>
8
+ <license id="2" name="Attribution-NonCommercial License" url="http://creativecommons.org/licenses/by-nc/2.0/"/>
9
+ <license id="1" name="Attribution-NonCommercial-ShareAlike License" url="http://creativecommons.org/licenses/by-nc-sa/2.0/"/>
10
+ <license id="5" name="Attribution-ShareAlike License" url="http://creativecommons.org/licenses/by-sa/2.0/"/>
11
+ </licenses>
12
+ </rsp>
@@ -0,0 +1,13 @@
1
+ <?xml version="1.0" encoding="utf-8" ?>
2
+ <rsp stat="ok">
3
+ <photosets cancreate="1">
4
+ <photoset id="5" primary="2483" secret="abcdef" server="8" photos="4" farm="1">
5
+ <title>Test</title>
6
+ <description>foo</description>
7
+ </photoset>
8
+ <photoset id="4" primary="1234" secret="832659" server="3" photos="12" farm="1">
9
+ <title>My Set</title>
10
+ <description>bar</description>
11
+ </photoset>
12
+ </photosets>
13
+ </rsp>
@@ -0,0 +1,7 @@
1
+ <?xml version="1.0" encoding="utf-8" ?>
2
+ <rsp stat="ok">
3
+ <photoset id="4" primary="2483" page="1" perpage="500" pages="1" total="2">
4
+ <photo id="2484" secret="123456" server="1" title="my photo" isprimary="0" />
5
+ <photo id="2483" secret="123456" server="1" title="flickr rocks" isprimary="1" />
6
+ </photoset>
7
+ </rsp>
@@ -0,0 +1,5 @@
1
+ <?xml version="1.0" encoding="utf-8" ?>
2
+ <rsp stat="ok">
3
+ <method>flickr.test.echo</method>
4
+ <foo>bar</foo>
5
+ </rsp>
@@ -0,0 +1,4 @@
1
+ <?xml version="1.0" encoding="utf-8" ?>
2
+ <rsp stat="fail">
3
+ <err code="99" msg="Insufficient permissions. Method requires read privileges; none granted."/>
4
+ </rsp>
@@ -0,0 +1,4 @@
1
+ <?xml version="1.0" encoding="utf-8" ?>
2
+ <rsp stat="ok">
3
+ <group nsid="34427469792@N01" url="http://www.flickr.com/groups/central/"/>
4
+ </rsp>
@@ -0,0 +1,4 @@
1
+ <?xml version="1.0" encoding="utf-8" ?>
2
+ <rsp stat="fail">
3
+ <err code="1" msg="Group not found"/>
4
+ </rsp>
@@ -0,0 +1,4 @@
1
+ <?xml version="1.0" encoding="utf-8" ?>
2
+ <rsp stat="ok">
3
+ <user nsid="80755658@N00" url="http://www.flickr.com/photos/lvizard/"/>
4
+ </rsp>
@@ -0,0 +1,4 @@
1
+ <?xml version="1.0" encoding="utf-8" ?>
2
+ <rsp stat="fail">
3
+ <err code="1" msg="User not found"/>
4
+ </rsp>
@@ -0,0 +1,4 @@
1
+ <?xml version="1.0" encoding="utf-8" ?>
2
+ <rsp stat="fail">
3
+ <err code="2" msg="No user specified"/>
4
+ </rsp>
@@ -0,0 +1,4 @@
1
+ <?xml version="1.0" encoding="utf-8" ?>
2
+ <rsp stat="ok">
3
+ <user nsid="80755658@N00" url="http://www.flickr.com/people/lvizard/"/>
4
+ </rsp>
@@ -0,0 +1,4 @@
1
+ <?xml version="1.0" encoding="utf-8" ?>
2
+ <rsp stat="fail">
3
+ <err code="1" msg="User not found"/>
4
+ </rsp>
@@ -0,0 +1,4 @@
1
+ <?xml version="1.0" encoding="utf-8" ?>
2
+ <rsp stat="fail">
3
+ <err code="2" msg="No user specified"/>
4
+ </rsp>
@@ -0,0 +1,6 @@
1
+ <?xml version="1.0" encoding="utf-8" ?>
2
+ <rsp stat="ok">
3
+ <group id="34427469792@N01">
4
+ <groupname>FlickrCentral</groupname>
5
+ </group>
6
+ </rsp>
@@ -0,0 +1,4 @@
1
+ <?xml version="1.0" encoding="utf-8" ?>
2
+ <rsp stat="fail">
3
+ <err code="1" msg="Group not found"/>
4
+ </rsp>