Module: Picasa::Photo::ClassMethods
- Defined in:
- lib/picasa/photo.rb
Overview
Class methods to be added to the class that will include this module.
Instance Method Summary collapse
-
#belongs_to_picasa_album(params) ⇒ Object
Sets the user class configured so it can be used later.
-
#picasa_find(user_id, album_id, photo_id, auth_token) ⇒ Object
Find a photo by user_id, album_id and photo_id If no album is found, then an exception is raised.
-
#picasa_find_all(user_id, album_id, auth_token) ⇒ Object
Find all photos from an album using user_id, album_id If no album is found, then an exception is raised.
Instance Method Details
#belongs_to_picasa_album(params) ⇒ Object
Sets the user class configured so it can be used later.
14 15 16 17 18 19 20 |
# File 'lib/picasa/photo.rb', line 14 def belongs_to_picasa_album params unless params[:class_name] and params[:class_name].class == String raise Exception, 'You should pass the string of the class name that includes Picasa::Album.' end define_dependent_class_methods :album_class, params[:class_name] end |
#picasa_find(user_id, album_id, photo_id, auth_token) ⇒ Object
Find a photo by user_id, album_id and photo_id If no album is found, then an exception is raised.
25 26 27 28 29 30 31 32 33 34 35 36 37 |
# File 'lib/picasa/photo.rb', line 25 def picasa_find user_id, album_id, photo_id, auth_token resp, data = Picasa::HTTP::Photo.get_photo user_id, album_id, photo_id, auth_token if resp.code != "200" or resp. != "OK" raise Exception, "Photo not found" end photo = new photo.send(:populate_attributes_from_xml, data) photo.album = album_class.picasa_find user_id, album_id, auth_token photo.file = Picasa::HTTP::Photo.download_image photo.media_content_url photo end |
#picasa_find_all(user_id, album_id, auth_token) ⇒ Object
Find all photos from an album using user_id, album_id If no album is found, then an exception is raised.
42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 |
# File 'lib/picasa/photo.rb', line 42 def picasa_find_all user_id, album_id, auth_token resp, data = Picasa::HTTP::Photo.get_photos user_id, album_id, auth_token if resp.code != "200" or resp. != "OK" raise Exception, "Error while retrieving photos. Code: #{resp.code}, Message: #{resp.}\n"+ "#{user_id}, #{album_id}, #{auth_token}" end photos = [] album = album_class.picasa_find user_id, album_id, auth_token doc = Nokogiri::XML(data) doc.xpath('//xmlns:entry').each do |entry| photo = new photo.send(:populate_attributes, entry) photo.album = album photos << photo end photos end |