Class: FbGraph::Album

Inherits:
Node
  • Object
show all
Includes:
Connections::Comments, Connections::Likes, Connections::Photos
Defined in:
lib/fb_graph/album.rb

Overview

Authentication

  • Access token is required to fetch album info.

Attributes

from

FbGraph::User or FbGraph::Page

name

String

description

String

location

String ex.) “NYC”

link

String

privacy

String ex.) “everyone”

count

Integer

created_time

Time (UTC)

updated_time

Time (UTC)

Connections

photos

Array of FbGraph::Photo

comments

Array of FbGraph::Comment

likes

Array of FbGraph::Page

Examples

Fetch album info

album = FbGraph::Album.new(ALBUM_ID)
album.fetch(:access_token => ACCESS_TOKEN)

or

FbGraph::album.fetch(ALBUM_ID, :access_token => ACCESS_TOKEN)

Fetch connection

photos = album.photos
likes = album.likes
comments = album.comments

Pagination

photos = album.photos
photos_next = photos.next
photos_previous = photos.previous
photos = album.photos(:since => '2010-09-01', :until => '2010-10-01')
photos = album.photos(:offset => 20, :limit => 20)

Creat new album

See RDoc for FbGraph::Connections::Albums

Upload a photo

album.photo!(
  :image => File.new(File.join(File.dirname(__FILE__), 'nov.gif')),
  :name => "name",
  :message => 'message'
)

Post a comment

album.comment!(
  :access_token => ACCESS_TOKEN,
  :message => 'Hey, I\'m testing you!'
)

Delete a comment

comment = album.comments.last
comment.destroy

Like and unlike

album.like!
album.unlike!

Notes

Attribute from

Both facebook user and page can have albums, so from can be either FbGraph::User or FbGraph::Page.

  • When you called ablums connection of FbGraph::User, all from should be FbGraph::User.

  • When you called ablums connection of FbGraph::Page, all from should be FbGraph::Page.

  • When you fetched an album by objedt id, from can be either FbGraph::User or FbGraph::Page.

Cached comments

When album object fetched, several comments are included in the response. So first time you called album.comments, those cached comments will be returned. If you put any option parameter like album.comments(:access_token => ACCESS_TOKEN), fb_graph ignores those cached comments and fetch comments via Graph API.

If cached “album.comments” are blank, probably the album has no comments yet.

Instance Attribute Summary collapse

Attributes inherited from Node

#access_token, #endpoint, #identifier

Instance Method Summary collapse

Methods included from Connections::Likes

#likes

Methods included from Connections::Comments

#comment!, #comments, #like!, #unlike!

Methods included from Connections::Photos

#photo!, #photos

Methods inherited from Node

#connection, #destroy, fetch, #fetch

Methods included from Comparison

#==

Constructor Details

#initialize(identifier, attributes = {}) ⇒ Album

Returns a new instance of Album.



102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
# File 'lib/fb_graph/album.rb', line 102

def initialize(identifier, attributes = {})
  super
  @from = if (from = attributes[:from])
    if from[:category]
      FbGraph::Page.new(from.delete(:id), from)
    else
      FbGraph::User.new(from.delete(:id), from)
    end
  end
  @name = attributes[:name]
  # NOTE:
  # for some reason, facebook uses different parameter names.
  # "description" in GET & "message" in POST
  # TODO:
  # check whether this issue is solved or not
  @description = attributes[:description] || attributes[:message]
  @location    = attributes[:location]
  @link        = attributes[:link]
  @privacy     = attributes[:privacy]
  @count       = attributes[:count]
  @created_time = if attributes[:created_time]
    Time.parse(attributes[:created_time]).utc
  end
  @updated_time = if attributes[:updated_time]
    Time.parse(attributes[:updated_time]).utc
  end

  # cached connection
  @_comments_ = FbGraph::Collection.new(attributes[:comments])
end

Instance Attribute Details

#countObject

Returns the value of attribute count.



100
101
102
# File 'lib/fb_graph/album.rb', line 100

def count
  @count
end

#created_timeObject

Returns the value of attribute created_time.



100
101
102
# File 'lib/fb_graph/album.rb', line 100

def created_time
  @created_time
end

#descriptionObject

Returns the value of attribute description.



100
101
102
# File 'lib/fb_graph/album.rb', line 100

def description
  @description
end

#fromObject

Returns the value of attribute from.



100
101
102
# File 'lib/fb_graph/album.rb', line 100

def from
  @from
end

Returns the value of attribute link.



100
101
102
# File 'lib/fb_graph/album.rb', line 100

def link
  @link
end

#locationObject

Returns the value of attribute location.



100
101
102
# File 'lib/fb_graph/album.rb', line 100

def location
  @location
end

#nameObject

Returns the value of attribute name.



100
101
102
# File 'lib/fb_graph/album.rb', line 100

def name
  @name
end

#privacyObject

Returns the value of attribute privacy.



100
101
102
# File 'lib/fb_graph/album.rb', line 100

def privacy
  @privacy
end

#updated_timeObject

Returns the value of attribute updated_time.



100
101
102
# File 'lib/fb_graph/album.rb', line 100

def updated_time
  @updated_time
end