Class: Flickr::Photo
- Inherits:
-
Object
- Object
- Flickr::Photo
- Includes:
- Comparable, Proxy
- Defined in:
- lib/simple-flickr/photo.rb
Overview
Represents a Flickr Photo.
Constant Summary collapse
- PHOTO_SIZES =
{ 'square' => '_s', 'thumbnail' => '_t', 'small' => '_m', 'medium' => '', 'large' => '_b' }
Instance Attribute Summary
Attributes included from Proxy
Class Method Summary collapse
-
.api_query(api_method, client, options) ⇒ Object
Find Photos using a Flickr API method, a Flickr::Client and a hash of options.
-
.find(photo_id, client) ⇒ Object
Find a single photo using the Flickr photo ID and a Flickr::Client.
Instance Method Summary collapse
-
#<=>(other) ⇒ Object
Comparison with another Flickr::PHoto.
-
#initialize(xml, client) ⇒ Photo
constructor
Initialize the photo with an extra hack to ensure that various attributes are present, no matter whether flicker provides them as attributes or as seperate nodes (or by several different names, occasionally).
-
#person ⇒ Object
Get the person associated with this photo.
-
#url(size = 'medium') ⇒ Object
Return the url to an image for the specified size.
Methods included from Proxy
#id, included, #method_missing
Constructor Details
#initialize(xml, client) ⇒ Photo
Initialize the photo with an extra hack to ensure that various attributes are present, no matter whether flicker provides them as attributes or as seperate nodes (or by several different names, occasionally)
Parameters
See Flickr::Proxy#initialize
16 17 18 19 20 21 22 23 24 25 26 27 |
# File 'lib/simple-flickr/photo.rb', line 16 def initialize( xml, client ) super( xml, client ) @attributes['title'] ||= xml.search('title').text @attributes['description'] = xml.search('description').text @attributes['uploaded_at'] = Time.at((@attributes.delete('dateuploaded') or @attributes.delete('dateupload')).to_i).utc @attributes['owner'] ||= xml.at('owner').attributes['nsid'] if xml.at('owner') @attributes['taken_at'] = begin Time.parse("#{@attributes.delete('datetaken')} UTC") if @attributes.include?('datetaken') rescue ArgumentError nil end end |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method in the class Flickr::Proxy
Class Method Details
.api_query(api_method, client, options) ⇒ Object
Find Photos using a Flickr API method, a Flickr::Client and a hash of options.
This works the same as Flickr::Proxy#api_query, only it returns a Flickr::Photos object instead of an Array.
63 64 65 |
# File 'lib/simple-flickr/photo.rb', line 63 def self.api_query( api_method, client, ) Flickr::Photos.new( client.request(api_method, ).at('photos|photoset'), client ) # Photosets, unlike every other photos result, returns in a <photosets> node instead of <photos>. end |
.find(photo_id, client) ⇒ Object
Find a single photo using the Flickr photo ID and a Flickr::Client
Parameters
- :photo_id<String>
-
The flickr photo id (should be a ~10-digit integer)
- :client<Flickr::Client>
-
The flickr client object to use
72 73 74 |
# File 'lib/simple-flickr/photo.rb', line 72 def self.find( photo_id, client ) Photo.new( client.request('photos.getInfo', :photo_id => photo_id).at('photo'), client ) end |
Instance Method Details
#<=>(other) ⇒ Object
Comparison with another Flickr::PHoto.
Parameters
:other<Flickr::Photo>: The other photo to compare to.
Returns
Integer: -1, 0, 1 if the id of this Photo is less than, equal to, or greater than the other Photo.
44 45 46 47 |
# File 'lib/simple-flickr/photo.rb', line 44 def <=>( other ) return 0 if self.id == other.id self.id < other.id ? -1 : 1 end |
#person ⇒ Object
Get the person associated with this photo
Returns
Flickr::Person: The associated person object
33 34 35 |
# File 'lib/simple-flickr/photo.rb', line 33 def person Person.find_by_id( owner, @client ) end |
#url(size = 'medium') ⇒ Object
Return the url to an image for the specified size. This does not currently support ‘original’.
Parameters
- :size<String>
-
The desired size of the image. Can be
square,thumbnail,small,medium, orlarge.
Returns
- String
-
The url to the image.
56 57 58 |
# File 'lib/simple-flickr/photo.rb', line 56 def url( size = 'medium' ) "http://farm#{farm}.static.flickr.com/#{server}/#{id}_#{secret}#{PHOTO_SIZES[size]}.jpg" end |