Class: Flickry::Photo
- Inherits:
-
Base
- Object
- OpenStruct
- SuperStruct
- Base
- Flickry::Photo
- Defined in:
- lib/flickry/photo.rb
Instance Method Summary collapse
-
#comments ⇒ Object
Lazily fetches the photo’s comments when called, memoizes so later calls are faster…
-
#initialize(flickr_id) ⇒ Photo
constructor
A new instance of Photo.
-
#sizes ⇒ Object
Lazily fetches the photo’s sizes when called, memoizes so later calls are faster…
- #visible_to_family? ⇒ Boolean
- #visible_to_friends? ⇒ Boolean
- #visible_to_public? ⇒ Boolean
Methods inherited from Base
Methods inherited from SuperStruct
#[], #[]=, #each, #each_pair, #members
Constructor Details
#initialize(flickr_id) ⇒ Photo
Returns a new instance of Photo.
3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 |
# File 'lib/flickry/photo.rb', line 3 def initialize(flickr_id) super(nil) foto = flickr.photos.getInfo(:photo_id => flickr_id) self.raw_photo = foto self.photo_id = flickr_id extract_attrs!(foto, [:dateuploaded, :description, :farm, :id, :isfavorite, :license, :media, :notes, :originalformat, :originalsecret, :rotation, :secret, :server, :tags, :title, :urls]) extract_attrs_into_substructs!(foto, { :dates => [:lastupdate, :posted, :taken, :takengranularity], :editability => [:canaddmeta, :cancomment], :geoperms => [:iscontact, :isfamily, :isfriend, :ispublic], :usage => [:canblog, :candownload, :canprint], :visibility => [:isfamily, :isfriend, :ispublic] }) self.location = Flickry::Location.new(foto.respond_to?(:location) ? foto.location : nil) self.owner = Flickry::Person.new(foto.respond_to?(:owner) ? foto.owner : nil) end |
Instance Method Details
#comments ⇒ Object
Lazily fetches the photo’s comments when called, memoizes so later calls are faster…
30 31 32 33 34 35 36 37 38 39 40 41 42 43 |
# File 'lib/flickry/photo.rb', line 30 def comments return @comments if @comments if raw_photo.comments.to_i == 0 @comments = [] else @comments = [] flickr_comments = flickr.photos.comments.getList(:photo_id => self.photo_id) flickr_comments.each do |comment| @comments << Flickry::Comment.new(comment) end end return @comments end |
#sizes ⇒ Object
Lazily fetches the photo’s sizes when called, memoizes so later calls are faster…
25 26 27 |
# File 'lib/flickry/photo.rb', line 25 def sizes @sizes ||= Flickry::Sizes.new(flickr.photos.getSizes(:photo_id => self.photo_id)) end |
#visible_to_family? ⇒ Boolean
45 46 47 |
# File 'lib/flickry/photo.rb', line 45 def visible_to_family? self.visibility.isfamily == 1 end |
#visible_to_friends? ⇒ Boolean
49 50 51 |
# File 'lib/flickry/photo.rb', line 49 def visible_to_friends? self.visibility.isfriend == 1 end |
#visible_to_public? ⇒ Boolean
53 54 55 |
# File 'lib/flickry/photo.rb', line 53 def visible_to_public? self.visibility.ispublic == 1 end |