Permalink
Browse files

Switch on photo for what type of XML is being passed in

  • Loading branch information...
1 parent b9444d3 commit 91e523e207c391593a2c16589001611146a04f80 @quirkey committed Aug 23, 2009
Showing with 53 additions and 28 deletions.
  1. +53 −28 lib/flickr/photo.rb
View
@@ -23,34 +23,59 @@ def initialize(flickr, attributes)
end
def self.from_response(flickr, photo)
- new(flickr, {
- :id => photo[:id].to_i,
- :owner => photo[:owner],
- :secret => photo[:secret],
- :server => photo[:server],
- :farm => photo[:farm],
- :title => photo[:title],
- :is_public => photo[:ispublic],
- :is_friend => photo[:isfriend],
- :is_family => photo[:isfamily],
- :license_id => photo[:license].to_i,
- :uploaded_at => (Time.at(photo[:dateupload].to_i) rescue nil),
- :taken_at => (Time.parse(photo[:datetaken]) rescue nil),
- :owner_name => photo[:ownername],
- :icon_server => photo[:iconserver],
- :icon_farm => photo[:iconfarm],
- :original_format => photo[:originalformat],
- :updated_at => (Time.at(photo[:lastupdate].to_i) rescue nil),
- :location => [photo[:latitude], photo[:longitude], photo[:accuracy]],
- :tags => photo[:tags],
- :machine_tags => photo[:machine_tags],
- :o_dims => photo[:o_dims],
- :views => photo[:views].to_i,
- :media => photo[:media],
- :info_added => !!photo.description,
- :description => photo.description,
- :url_photopage => (photo.urls ? photo.urls.url : nil)
- })
+ # switch on the kind of photo response
+ attrs = if photo.description
+ {
+ :id => photo[:id].to_i,
+ :owner => photo.owner[:nsid],
+ :secret => photo[:secret],
+ :server => photo[:server],
+ :farm => photo[:farm],
+ :title => photo.title,
+ :is_public => photo.visibility[:ispublic],
+ :is_friend => photo.visibility[:isfriend],
+ :is_family => photo.visibility[:isfamily],
+ :license_id => photo[:license].to_i,
+ :uploaded_at => (Time.at(photo[:dateuploaded]) rescue nil),
+ :taken_at => (Time.parse(photo.dates[:taken]) rescue nil),
+ :owner_name => photo.owner[:username],
+ :original_format => photo[:originalformat],
+ :updated_at => (Time.at(photo.dates[:lastupdate].to_i) rescue nil),
+ :location => [photo.location[:latitude], photo.location[:longitude], photo.location[:accuracy]],
+ :tags => photo.tags.tag.collect {|t| t[:raw]},
+ :media => photo[:media],
+ :info_added => true,
+ :description => photo.description,
+ :url_photopage => (photo.urls ? photo.urls.url.to_s : nil)
+ }
+ else
+ {
+ :id => photo[:id].to_i,
+ :owner => photo[:owner],
+ :secret => photo[:secret],
+ :server => photo[:server],
+ :farm => photo[:farm],
+ :title => photo[:title],
+ :is_public => photo[:ispublic],
+ :is_friend => photo[:isfriend],
+ :is_family => photo[:isfamily],
+ :license_id => photo[:license].to_i,
+ :uploaded_at => (Time.at(photo[:dateupload].to_i) rescue nil),
+ :taken_at => (Time.parse(photo[:datetaken]) rescue nil),
+ :owner_name => photo[:ownername],
+ :icon_server => photo[:iconserver],
+ :icon_farm => photo[:iconfarm],
+ :original_format => photo[:originalformat],
+ :updated_at => (Time.at(photo[:lastupdate].to_i) rescue nil),
+ :location => [photo[:latitude], photo[:longitude], photo[:accuracy]],
+ :tags => photo[:tags],
+ :machine_tags => photo[:machine_tags],
+ :o_dims => photo[:o_dims],
+ :views => photo[:views].to_i,
+ :media => photo[:media]
+ }
+ end
+ new(flickr, attrs.reject {|k,v| v.nil? })
end

0 comments on commit 91e523e

Please sign in to comment.