Class: Faceoff::Album

Inherits:
Object
  • Object
show all
Defined in:
lib/faceoff/album.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(faceoff, id, name) ⇒ Album

Returns a new instance of Album.



47
48
49
50
51
52
53
54
# File 'lib/faceoff/album.rb', line 47

def initialize faceoff, id, name
  @faceoff = faceoff
  @agent   = faceoff.agent

  @fid    = id
  @name   = name
  @photos = nil
end

Instance Attribute Details

#fidObject

Facebook album id.



41
42
43
# File 'lib/faceoff/album.rb', line 41

def fid
  @fid
end

#nameObject

Name of the album.



44
45
46
# File 'lib/faceoff/album.rb', line 44

def name
  @name
end

Class Method Details

.retrieve_all(faceoff, options = {}, &block) ⇒ Object

Returns an array of albums for the current user. Pass the :user_id option to override the logged in user.



10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
# File 'lib/faceoff/album.rb', line 10

def self.retrieve_all faceoff, options={}, &block
  albums = []
  limit  = options[:limit]
  start  = options[:start] || 0

  agent   = faceoff.agent
  user_id = options[:user_id] || faceoff.profile_id

  page = agent.get "/photos.php?id=#{user_id}"

  xpath = "table[@class='uiGrid fbPhotosGrid']/tbody/"+
          "/div[@class='pls photoDetails']/a"

  nodes = page.search(xpath)

  limit ||= nodes.length

  nodes[start, limit].each do |node|
    album_id   = $1 if node['href'] =~ /aid=(\d+)/
    album_name = node.text

    albums << new(faceoff, album_id, album_name)

    yield albums.last if block_given?
  end

  albums
end

Instance Method Details

#photos(reload = false, &block) ⇒ Object

Returns an array of photos.



60
61
62
63
64
65
66
67
68
69
70
# File 'lib/faceoff/album.rb', line 60

def photos reload=false, &block
  if @photos && !reload
    @photos.each &block if block_given?
    return @photos
  end

  options = {}
  options[:limit] = reload if Fixnum === reload

  @photos = Photo.photos_of_album @faceoff, @fid, options, &block
end

#save!(target = "./Albums") ⇒ Object

Save the album to the provided directory.



76
77
78
79
80
81
# File 'lib/faceoff/album.rb', line 76

def save! target="./Albums"
  dirname = File.join target, @name
  FileUtils.mkdir_p dirname

  self.photos{|p| p.save! dirname}
end