lib/flickry/photo.rb in wideopenspaces-flickry-0.1.3 vs lib/flickry/photo.rb in wideopenspaces-flickry-0.1.5
- old
+ new
@@ -1,13 +1,14 @@
module Flickry
class Photo < Flickry::Base
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, [:comments, :dateuploaded, :description, :farm, :id, :isfavorite, :license,
+ 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],
@@ -15,14 +16,34 @@
: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)
-
- self.sizes = Flickry::Sizes.new(flickr.photos.getSizes(:photo_id => self.photo_id))
+
end
+
+ # Lazily fetches the photo's sizes when called, memoizes so later calls are faster...
+ def sizes
+ @sizes ||= Flickry::Sizes.new(flickr.photos.getSizes(:photo_id => self.photo_id))
+ end
+ # Lazily fetches the photo's comments when called, memoizes so later calls are faster...
+ 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
+
def visible_to_family?
self.visibility.isfamily == 1
end
def visible_to_friends?
@@ -30,22 +51,8 @@
end
def visible_to_public?
self.visibility.ispublic == 1
end
-
- def to_flickr_photo
- { :secret => self.secret,
- :originalsecret => self.originalsecret,
- :farm => self.farm,
- :server => self.server,
- :content_type => self.originalformat,
- :content => self.description,
- :created_at => Time.parse(self.dates.taken) }
- end
-
- def to_story
- return {:title => self.title, :slug => self.photo_id, :published_at => self.dates.taken }
- end
-
+
end
end
\ No newline at end of file