Class: Flickr::Photos::Photo
Overview
wrapping class to hold an flickr photo
Instance Attribute Summary collapse
-
#comment_count ⇒ Object
comment attributes.
-
#comments(options = {}) ⇒ Object
Returns a list of comments for the photo.
-
#description ⇒ Object
:nodoc:.
-
#farm ⇒ Object
standard attributes.
-
#geo ⇒ Object
extra attributes.
-
#icon_server ⇒ Object
extra attributes.
-
#id ⇒ Object
standard attributes.
-
#info_added ⇒ Object
info attributes.
-
#is_family ⇒ Object
standard attributes.
-
#is_friend ⇒ Object
standard attributes.
-
#is_public ⇒ Object
standard attributes.
-
#license_id ⇒ Object
extra attributes.
-
#machine_tags ⇒ Object
extra attributes.
-
#media ⇒ Object
extra attributes.
-
#notes ⇒ Object
:nodoc:.
-
#o_dims ⇒ Object
extra attributes.
-
#original_format ⇒ Object
extra attributes.
-
#original_secret ⇒ Object
:nodoc:.
-
#owner ⇒ Object
standard attributes.
-
#owner_name ⇒ Object
extra attributes.
-
#owner_realname ⇒ Object
:nodoc:.
-
#owner_username ⇒ Object
:nodoc:.
-
#secret ⇒ Object
standard attributes.
-
#server ⇒ Object
standard attributes.
-
#tags ⇒ Object
extra attributes.
-
#taken_at ⇒ Object
extra attributes.
-
#title ⇒ Object
standard attributes.
-
#updated_at ⇒ Object
extra attributes.
-
#uploaded_at ⇒ Object
extra attributes.
-
#url_photopage ⇒ Object
:nodoc:.
-
#views ⇒ Object
extra attributes.
Instance Method Summary collapse
-
#add_comment(message) ⇒ Object
Add comment to a photo as the currently authenticated user.
-
#add_note(message, x, y, w, h) ⇒ Object
Add a note to a photo.
-
#add_tags(tags) ⇒ Object
Add tags to a photo.
-
#image_url(size = :medium) ⇒ Object
retreive the url to the image stored on flickr.
-
#initialize(flickr, attributes) ⇒ Photo
constructor
create a new instance of a flickr photo.
-
#license ⇒ Object
return the license associated with the photo.
-
#location ⇒ Object
Returns the location of the photo (if available) or nil if photo is not geo-tagged.
- #location=(location) ⇒ Object
-
#photo_size(size = :medium) ⇒ Object
returns an instance of Flickr::Photos::Size for the required size.
- #photopage_url ⇒ Object
-
#rotate(degrees) ⇒ Object
Rotate a photo.
-
#save_as(filename, size = :medium) ⇒ Object
save the current photo to the local computer.
-
#set_license(license_id) ⇒ Object
Sets the license for a photo.
-
#sizes ⇒ Object
:nodoc:.
-
#url(size = :medium) ⇒ Object
Alias to image_url method.
- #video_url ⇒ Object
Constructor Details
#initialize(flickr, attributes) ⇒ Photo
create a new instance of a flickr photo.
Params
-
flickr (Required)
the flickr object
-
attributes (Required)
a hash of attributes used to set the initial values of the photo object
15 16 17 18 19 20 |
# File 'lib/flickr/photo.rb', line 15 def initialize(flickr, attributes) @flickr = flickr attributes.each do |k,v| send("#{k}=", v) end end |
Instance Attribute Details
#comment_count ⇒ Object
comment attributes
6 7 8 |
# File 'lib/flickr/photo.rb', line 6 def comment_count @comment_count end |
#comments(options = {}) ⇒ Object
Returns a list of comments for the photo
Params
-
options (Optional)
additional parameters to pass to flickr. :min_comment_date - Minimum date that a comment was added. The date should be in the form of a unix timestamp. :max_comment_date - Maximum date that a comment was added. The date should be in the form of a unix timestamp.
6 7 8 |
# File 'lib/flickr/photo.rb', line 6 def comments @comments end |
#description ⇒ Object
:nodoc:
5 6 7 |
# File 'lib/flickr/photo.rb', line 5 def description @description end |
#icon_server ⇒ Object
extra attributes
4 5 6 |
# File 'lib/flickr/photo.rb', line 4 def icon_server @icon_server end |
#info_added ⇒ Object
info attributes
5 6 7 |
# File 'lib/flickr/photo.rb', line 5 def info_added @info_added end |
#is_family ⇒ Object
standard attributes
3 4 5 |
# File 'lib/flickr/photo.rb', line 3 def is_family @is_family end |
#is_friend ⇒ Object
standard attributes
3 4 5 |
# File 'lib/flickr/photo.rb', line 3 def is_friend @is_friend end |
#is_public ⇒ Object
standard attributes
3 4 5 |
# File 'lib/flickr/photo.rb', line 3 def is_public @is_public end |
#license_id ⇒ Object
extra attributes
4 5 6 |
# File 'lib/flickr/photo.rb', line 4 def license_id @license_id end |
#machine_tags ⇒ Object
extra attributes
4 5 6 |
# File 'lib/flickr/photo.rb', line 4 def @machine_tags end |
#original_format ⇒ Object
extra attributes
4 5 6 |
# File 'lib/flickr/photo.rb', line 4 def original_format @original_format end |
#original_secret ⇒ Object
:nodoc:
5 6 7 |
# File 'lib/flickr/photo.rb', line 5 def original_secret @original_secret end |
#owner_name ⇒ Object
extra attributes
4 5 6 |
# File 'lib/flickr/photo.rb', line 4 def owner_name @owner_name end |
#owner_realname ⇒ Object
:nodoc:
5 6 7 |
# File 'lib/flickr/photo.rb', line 5 def owner_realname @owner_realname end |
#owner_username ⇒ Object
:nodoc:
5 6 7 |
# File 'lib/flickr/photo.rb', line 5 def owner_username @owner_username end |
#secret ⇒ Object
standard attributes
3 4 5 |
# File 'lib/flickr/photo.rb', line 3 def secret @secret end |
#server ⇒ Object
standard attributes
3 4 5 |
# File 'lib/flickr/photo.rb', line 3 def server @server end |
#taken_at ⇒ Object
extra attributes
4 5 6 |
# File 'lib/flickr/photo.rb', line 4 def taken_at @taken_at end |
#updated_at ⇒ Object
extra attributes
4 5 6 |
# File 'lib/flickr/photo.rb', line 4 def updated_at @updated_at end |
#uploaded_at ⇒ Object
extra attributes
4 5 6 |
# File 'lib/flickr/photo.rb', line 4 def uploaded_at @uploaded_at end |
#url_photopage ⇒ Object
:nodoc:
5 6 7 |
# File 'lib/flickr/photo.rb', line 5 def url_photopage @url_photopage end |
Instance Method Details
#add_comment(message) ⇒ Object
Add comment to a photo as the currently authenticated user.
Params
-
message (Required)
text of the comment
127 128 129 130 |
# File 'lib/flickr/photo.rb', line 127 def add_comment() @flickr.send_request('flickr.photos.comments.addComment', {:photo_id => self.id, :comment_text => }, :post) true end |
#add_note(message, x, y, w, h) ⇒ Object
Add a note to a photo. Coordinates and sizes are in pixels, based on the 500px image size shown on individual photo pages.
Params
-
message (Required)
The text of the note
-
x (Required)
The left coordinate of the note
-
y (Required)
The top coordinate of the note
-
w (Required)
The width of the note
-
h (Required)
The height of the note
146 147 148 149 |
# File 'lib/flickr/photo.rb', line 146 def add_note(, x, y, w, h) @flickr.send_request('flickr.photos.notes.add', {:photo_id => self.id, :note_x => x, :note_y => y, :note_w => w, :note_h => h, :note_text => }, :post) true end |
#add_tags(tags) ⇒ Object
Add tags to a photo.
Params
-
tags (Required)
comma seperated list of
116 117 118 119 |
# File 'lib/flickr/photo.rb', line 116 def () @flickr.send_request('flickr.photos.addTags', {:photo_id => self.id, :tags => }, :post) true end |
#image_url(size = :medium) ⇒ Object
retreive the url to the image stored on flickr
Params
-
size (Optional)
the size of the image to return. Optional sizes are: :square - square 75x75 :thumbnail - 100 on longest side :small - 240 on longest side :medium - 500 on longest side :large - 1024 on longest side (only exists for very large original images) :original - original image, either a jpg, gif or png, depending on source format
57 58 59 60 61 62 63 64 65 66 67 68 69 |
# File 'lib/flickr/photo.rb', line 57 def image_url(size = :medium) # It turns out that flickr always stores all the sizes of the picture even when getSizes call returns otherwise. # Not calling getSizes is also very important for performance reasons. # Retrieving 30 search results means calling the API 31 times if you call getSizes every time. # Mind that you still need to call getSizes if you go out for the original image. if size == :original size_hash[size.to_s].source if size_hash.has_key? size.to_s else key = "_#{size_key(size.to_sym)}" key = "" if key == "_" "http://farm#{farm}.static.flickr.com/#{server}/#{id}_#{secret}#{key}.jpg" end end |
#license ⇒ Object
return the license associated with the photo
164 165 166 |
# File 'lib/flickr/photo.rb', line 164 def license @flickr.photos.licenses[self.license_id] end |
#location ⇒ Object
Returns the location of the photo (if available) or nil if photo is not geo-tagged.
170 171 172 173 174 175 176 177 178 179 180 |
# File 'lib/flickr/photo.rb', line 170 def location begin @location ||= @flickr.photos.geo.get_location(self.id) rescue Flickr::Error => e if e.code == 2 # 2: Photo has no location information. return nil else raise e end end end |
#location=(location) ⇒ Object
182 183 184 185 186 187 188 189 |
# File 'lib/flickr/photo.rb', line 182 def location= location if !location.nil? @flickr.photos.geo.set_location(self.id, location.latitude, location.longitude, location.accuracy) else @flickr.photos.geo.remove_location(self.id) end @location = location end |
#photo_size(size = :medium) ⇒ Object
returns an instance of Flickr::Photos::Size for the required size
Params
* size (Optional)
the size of the size instance to return. Optional sizes are:
:square - square 75x75
:thumbnail - 100 on longest side
:small - 240 on longest side
:medium - 500 on longest side
:large - 1024 on longest side (only exists for very large original images)
:original - original image, either a jpg, gif or png, depending on source format
Examples
Photo.photo_size(:square).source
Photo.photo_size(:large).width
41 42 43 |
# File 'lib/flickr/photo.rb', line 41 def photo_size(size = :medium) size_hash.fetch(size.to_s, size_hash['medium']) end |
#photopage_url ⇒ Object
71 72 73 74 |
# File 'lib/flickr/photo.rb', line 71 def photopage_url # Keeping the same convention as image_url (foo_url) url_photopage end |
#rotate(degrees) ⇒ Object
Rotate a photo.
Params
-
degrees (Required)
The amount of degrees by which to rotate the photo (clockwise) from it's current orientation. Valid values are 90, 180 and 270.
157 158 159 160 |
# File 'lib/flickr/photo.rb', line 157 def rotate(degrees) @flickr.send_request('flickr.photos.transform.rotate', {:photo_id => self.id, :degrees => degrees}, :post) true end |
#save_as(filename, size = :medium) ⇒ Object
save the current photo to the local computer
Params
-
filename (Required)
name of the new file omiting the extention (ex. photo_1)
-
size (Optional)
the size of the image to return. Optional sizes are: :small - square 75x75 :thumbnail - 100 on longest side :small - 240 on longest side :medium - 500 on longest side :large - 1024 on longest side (only exists for very large original images) :original - original image, either a jpg, gif or png, depending on source format
96 97 98 99 100 101 102 103 104 105 106 107 108 |
# File 'lib/flickr/photo.rb', line 96 def save_as(filename, size = :medium) format = size.to_sym == :original ? (self.original_format || 'jpg') : 'jpg' filename = "#{filename}.#{format}" if File.exists?(filename) or not self.url(size) false else f = File.new(filename, 'w+') f.puts open(self.url(size)).read f.close f end end |
#set_license(license_id) ⇒ Object
Sets the license for a photo.
Params
-
license_id (Required)
The license to apply, or 0 (zero) to remove the current license.
196 197 198 199 |
# File 'lib/flickr/photo.rb', line 196 def set_license(license_id) @flickr.send_request('flickr.photos.licenses.setLicense', {:photo_id => self.id, :license_id => license_id}, :post) true end |
#sizes ⇒ Object
:nodoc:
258 259 260 261 262 263 264 265 266 267 268 269 |
# File 'lib/flickr/photo.rb', line 258 def sizes # :nodoc: @sizes ||= begin rsp = @flickr.send_request('flickr.photos.getSizes', :photo_id => self.id) _sizes = [] rsp.sizes.size.each do |size| _sizes << Flickr::Photos::Size.new(:label => size[:label], :width => size[:width], :height => size[:height], :source => size[:source], :url => size[:url]) end _sizes end end |
#url(size = :medium) ⇒ Object
Alias to image_url method
23 24 25 |
# File 'lib/flickr/photo.rb', line 23 def url(size = :medium) image_url(size) end |
#video_url ⇒ Object
76 77 78 79 80 |
# File 'lib/flickr/photo.rb', line 76 def video_url if size_hash['video player'] size_hash['video player'].source end end |