Class: Net::Flickr::Photo
- Inherits:
-
Object
- Object
- Net::Flickr::Photo
- Defined in:
- lib/net/flickr/photo.rb
Overview
A Flickr photo.
Don’t instantiate this class yourself. Use the methods in Flickr::Photos to retrieve photos from Flickr.
Constant Summary collapse
- SIZE_SUFFIX =
{ :square => 's', :thumb => 't', :small => 'm', :medium => nil, :large => 'b', :original => 'o' }
Instance Attribute Summary collapse
-
#farm ⇒ Object
readonly
– Public Instance Methods ++.
-
#id ⇒ Object
readonly
– Public Instance Methods ++.
-
#secret ⇒ Object
readonly
– Public Instance Methods ++.
-
#server ⇒ Object
readonly
– Public Instance Methods ++.
Instance Method Summary collapse
-
#delete ⇒ Object
Deletes this photo from Flickr.
-
#description ⇒ Object
Gets this photo’s description.
-
#description=(value) ⇒ Object
Sets this photo’s description.
-
#exif ⇒ Object
flickr.photos.getExif.
-
#family? ⇒ Boolean
Whether or not this photo is visible to family.
-
#favorites ⇒ Object
flickr.photos.getFavorites.
-
#friend? ⇒ Boolean
Whether or not this photo is visible to friends.
-
#gps ⇒ Object
flickr.photos.getExif.
-
#initialize(flickr, photo_xml) ⇒ Photo
constructor
A new instance of Photo.
-
#modified ⇒ Object
Gets the time this photo was last modified.
-
#next ⇒ Object
Gets the next photo in the owner’s photo stream, or
nil
if this is the last photo in the stream. -
#owner ⇒ Object
Gets the user id of this photo’s owner.
-
#page_url ⇒ Object
Gets the URL of this photo’s Flickr photo page.
-
#pools ⇒ Object
flickr.photos.getAllContexts.
-
#posted ⇒ Object
Gets the time this photo was posted to Flickr.
-
#posted=(time) ⇒ Object
flickr.photos.setDates.
-
#previous ⇒ Object
(also: #prev)
Gets the previous photo in the owner’s photo stream, or
nil
if this is the first photo in the stream. -
#public? ⇒ Boolean
Whether or not this photo is visible to the general public.
-
#sets ⇒ Object
flickr.photos.getAllContexts.
-
#sizes ⇒ Object
flickr.photos.getSizes.
-
#source_url(size = :medium) ⇒ Object
Gets the source URL for this photo at one of the following specified sizes.
-
#tags ⇒ Object
flickr.photos.getInfo.
-
#taken ⇒ Object
Gets the time this photo was taken.
-
#taken=(time) ⇒ Object
flickr.photos.setDates.
-
#tiff ⇒ Object
flickr.photos.getExif.
-
#title ⇒ Object
Gets this photo’s title.
-
#title=(value) ⇒ Object
Sets this photo’s title.
Constructor Details
#initialize(flickr, photo_xml) ⇒ Photo
Returns a new instance of Photo.
51 52 53 54 55 56 57 58 59 |
# File 'lib/net/flickr/photo.rb', line 51 def initialize(flickr, photo_xml) @flickr = flickr parse_xml(photo_xml) # Detailed photo info. @context_xml = nil @info_xml = nil end |
Instance Attribute Details
#farm ⇒ Object (readonly)
– Public Instance Methods ++
49 50 51 |
# File 'lib/net/flickr/photo.rb', line 49 def farm @farm end |
#id ⇒ Object (readonly)
– Public Instance Methods ++
49 50 51 |
# File 'lib/net/flickr/photo.rb', line 49 def id @id end |
#secret ⇒ Object (readonly)
– Public Instance Methods ++
49 50 51 |
# File 'lib/net/flickr/photo.rb', line 49 def secret @secret end |
#server ⇒ Object (readonly)
– Public Instance Methods ++
49 50 51 |
# File 'lib/net/flickr/photo.rb', line 49 def server @server end |
Instance Method Details
#delete ⇒ Object
Deletes this photo from Flickr. This method requires authentication with delete
permission.
63 64 65 |
# File 'lib/net/flickr/photo.rb', line 63 def delete @flickr.photos.delete(@id) end |
#description ⇒ Object
Gets this photo’s description.
68 69 70 71 |
# File 'lib/net/flickr/photo.rb', line 68 def description info_xml = get_info return info_xml.at('description').inner_text end |
#description=(value) ⇒ Object
Sets this photo’s description. This method requires authentication with write
permission.
75 76 77 |
# File 'lib/net/flickr/photo.rb', line 75 def description=(value) (@title, value) end |
#exif ⇒ Object
flickr.photos.getExif
80 81 82 |
# File 'lib/net/flickr/photo.rb', line 80 def exif raise NotImplementedError end |
#family? ⇒ Boolean
Whether or not this photo is visible to family.
85 86 87 88 |
# File 'lib/net/flickr/photo.rb', line 85 def family? get_info if @is_family.nil? return @is_family || @is_public end |
#favorites ⇒ Object
flickr.photos.getFavorites
91 92 93 |
# File 'lib/net/flickr/photo.rb', line 91 def favorites raise NotImplementedError end |
#friend? ⇒ Boolean
Whether or not this photo is visible to friends.
96 97 98 99 |
# File 'lib/net/flickr/photo.rb', line 96 def friend? get_info if @is_friend.nil? return @is_friend || @is_public end |
#gps ⇒ Object
flickr.photos.getExif
102 103 104 |
# File 'lib/net/flickr/photo.rb', line 102 def gps raise NotImplementedError end |
#modified ⇒ Object
Gets the time this photo was last modified.
107 108 109 110 |
# File 'lib/net/flickr/photo.rb', line 107 def modified info_xml = get_info return Time.at(info_xml.at('dates')[:lastupdate].to_i) end |
#next ⇒ Object
Gets the next photo in the owner’s photo stream, or nil
if this is the last photo in the stream.
114 115 116 117 118 119 120 |
# File 'lib/net/flickr/photo.rb', line 114 def next context_xml = get_context next_xml = context_xml.at('nextphoto') return Photo.new(@flickr, next_xml) if next_xml[:id] != '0' return nil end |
#owner ⇒ Object
Gets the user id of this photo’s owner.
123 124 125 |
# File 'lib/net/flickr/photo.rb', line 123 def owner @owner end |
#page_url ⇒ Object
Gets the URL of this photo’s Flickr photo page.
128 129 130 |
# File 'lib/net/flickr/photo.rb', line 128 def page_url return "http://www.flickr.com/photos/#{@owner}/#{@id}" end |
#pools ⇒ Object
flickr.photos.getAllContexts
133 134 135 |
# File 'lib/net/flickr/photo.rb', line 133 def pools raise NotImplementedError end |
#posted ⇒ Object
Gets the time this photo was posted to Flickr.
138 139 140 141 |
# File 'lib/net/flickr/photo.rb', line 138 def posted info_xml = get_info return Time.at(info_xml.at('dates')[:posted].to_i) end |
#posted=(time) ⇒ Object
flickr.photos.setDates
144 145 |
# File 'lib/net/flickr/photo.rb', line 144 def posted=(time) end |
#previous ⇒ Object Also known as: prev
Gets the previous photo in the owner’s photo stream, or nil
if this is the first photo in the stream.
149 150 151 152 153 154 155 |
# File 'lib/net/flickr/photo.rb', line 149 def previous context_xml = get_context prev_xml = context_xml.at('prevphoto') return Photo.new(@flickr, prev_xml) if prev_xml[:id] != '0' return nil end |
#public? ⇒ Boolean
Whether or not this photo is visible to the general public.
160 161 162 163 |
# File 'lib/net/flickr/photo.rb', line 160 def public? get_info if @is_public.nil? return @is_public end |
#sets ⇒ Object
flickr.photos.getAllContexts
166 167 168 |
# File 'lib/net/flickr/photo.rb', line 166 def sets raise NotImplementedError end |
#sizes ⇒ Object
flickr.photos.getSizes
171 172 173 |
# File 'lib/net/flickr/photo.rb', line 171 def sizes raise NotImplementedError end |
#source_url(size = :medium) ⇒ Object
Gets the source URL for this photo at one of the following specified sizes. Returns nil
if the specified size is not available.
- :square
-
75x75px
- :thumb
-
100px on longest side
- :small
-
240px on longest side
- :medium
-
500px on longest side
- :large
-
1024px on longest side (not available for all images)
- :original
-
original image in original file format
184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 |
# File 'lib/net/flickr/photo.rb', line 184 def source_url(size = :medium) suffix = SIZE_SUFFIX[size] case size when :medium return "http://farm#{@farm}.static.flickr.com/#{@server}/#{@id}_" + "#{@secret}.jpg" when :original info_xml = get_info original_secret = info_xml[:originalsecret] original_format = info_xml[:originalformat] return nil if original_secret.nil? || original_format.nil? return "http://farm#{@farm}.static.flickr.com/#{@server}/#{@id}_" + "#{original_secret}_o.#{original_format}" else return "http://farm#{@farm}.static.flickr.com/#{@server}/#{@id}_" + "#{@secret}_#{suffix}.jpg" end end |
#tags ⇒ Object
flickr.photos.getInfo
209 210 211 |
# File 'lib/net/flickr/photo.rb', line 209 def raise NotImplementedError end |
#taken ⇒ Object
Gets the time this photo was taken.
214 215 216 217 |
# File 'lib/net/flickr/photo.rb', line 214 def taken info_xml = get_info return Time.parse(info_xml.at('dates')[:taken]) end |
#taken=(time) ⇒ Object
flickr.photos.setDates
220 221 222 |
# File 'lib/net/flickr/photo.rb', line 220 def taken=(time) raise NotImplementedError end |
#tiff ⇒ Object
flickr.photos.getExif
225 226 227 |
# File 'lib/net/flickr/photo.rb', line 225 def tiff raise NotImplementedError end |
#title ⇒ Object
Gets this photo’s title.
230 231 232 |
# File 'lib/net/flickr/photo.rb', line 230 def title @title end |
#title=(value) ⇒ Object
Sets this photo’s title. This method requires authentication with write
permission.
236 237 238 |
# File 'lib/net/flickr/photo.rb', line 236 def title=(value) (value, description) end |