Module: Picasa::Album::ClassMethods

Includes:
Util
Defined in:
lib/picasa/album.rb

Overview

Class methods to be added to the class that will include this module.

Instance Method Summary collapse

Methods included from Util

#define_dependent_class_method, #define_dependent_class_methods, #define_static_dependent_class_method, #extract_auth_token, #raise_exception?

Instance Method Details

#belongs_to_picasa_user(params) ⇒ Object

Sets the user class configured so it can be used later.



15
16
17
18
19
20
21
# File 'lib/picasa/album.rb', line 15

def belongs_to_picasa_user 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::User.'
  end
  
  define_dependent_class_methods :user_class, params[:class_name]
end

#has_many_picasa_photos(params) ⇒ Object

Method used to tell the gem what is the class that implements the Picasa::Photo module.



26
27
28
29
30
31
32
# File 'lib/picasa/album.rb', line 26

def has_many_picasa_photos 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 :photo_class, params[:class_name]      
end

#picasa_find(user_id, album_id, auth_token) ⇒ Object

Find an album by user_id and album_id. It’s mandatory to inform the authentication token. If no album is found, then an exception is raised.



37
38
39
40
41
42
43
44
45
46
47
48
# File 'lib/picasa/album.rb', line 37

def picasa_find user_id, album_id, auth_token
  resp, data = Picasa::HTTP::Album.get_album user_id, album_id, auth_token
  
  if resp.code != "200" or resp.message != "OK"
    return nil
  end
  
  album = new
  album.send(:populate_attributes_from_xml, data)
  album.user = create_user user_id, auth_token
  album
end

#picasa_find_all(user_id, auth_token) ⇒ Object

Find an album by user_id and album_id. It’s mandatory to inform the authentication token. If no album is found, then an exception is raised.



53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
# File 'lib/picasa/album.rb', line 53

def picasa_find_all user_id, auth_token
  albums = []
  resp, data = Picasa::HTTP::Album.get_albums user_id, auth_token
  
  if resp.code != "200" or resp.message != "OK"
    return nil
  end
  
  doc = Nokogiri::XML(data)
  doc.css('entry').each do |entry|
    album = new
    album.send(:populate_attributes, entry)
    album.user = create_user user_id, auth_token
    albums << album
  end
  albums
end