Class: Picasa::API::Album

Inherits:
Base
  • Object
show all
Defined in:
lib/picasa/api/album.rb

Instance Attribute Summary

Attributes inherited from Base

#access_token, #authorization_header, #user_id

Instance Method Summary collapse

Methods inherited from Base

#auth_header, #initialize

Constructor Details

This class inherits a constructor from Picasa::API::Base

Instance Method Details

#create(params = {}) ⇒ Presenter::Album

Creates album


49
50
51
52
53
54
55
56
57
58
59
60
# File 'lib/picasa/api/album.rb', line 49

def create(params = {})
  params[:title] || raise(ArgumentError, "You must specify title")
  # API takes timestamp with milliseconds
  params[:timestamp] = (params[:timestamp] || Time.now.to_i) * 1000
  params[:access] ||= "private"

  template = Template.new(:new_album, params)
  path = "/data/feed/api/user/#{user_id}"
  response = Connection.new.post(path: path, body: template.render, headers: auth_header)

  Presenter::Album.new(response.parsed_response["entry"])
end

#destroy(album_id, options = {}) ⇒ true Also known as: delete

Destroys given album

Options Hash (options):

  • :etag (String)

    destroys only when ETag matches - protects before destroying other client changes

Raises:


97
98
99
100
101
102
# File 'lib/picasa/api/album.rb', line 97

def destroy(album_id, options = {})
  headers = auth_header.merge({"If-Match" => options.fetch(:etag, "*")})
  path = "/data/entry/api/user/#{user_id}/albumid/#{album_id}"
  Connection.new.delete(path: path, headers: headers)
  true
end

#list(options = {}) ⇒ Presenter::AlbumList

Returns album list

Options Hash (options):

  • :access (all, private, public, visible)

    which data should be retrieved when authenticated

  • :fields (String)
  • :max_results (String, Integer)

    how many albums response should include

  • :start_index (String, Integer)

    1-based index of the first result to be retrieved


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

def list(options = {})
  path = "/data/feed/api/user/#{user_id}"
  response = Connection.new.get(path: path, query: options, headers: auth_header)

  Presenter::AlbumList.new(response.parsed_response["feed"])
end

#show(album_id, options = {}) ⇒ Presenter::Album

Returns photo list for given album

Options Hash (options):

Raises:


32
33
34
35
36
37
# File 'lib/picasa/api/album.rb', line 32

def show(album_id, options = {})
  path = "/data/feed/api/user/#{user_id}/albumid/#{album_id}"
  response = Connection.new.get(path: path, query: options, headers: auth_header)

  Presenter::Album.new(response.parsed_response["feed"])
end

#update(album_id, params = {}) ⇒ Presenter::Album

Update properties of given album


75
76
77
78
79
80
81
82
83
84
85
86
# File 'lib/picasa/api/album.rb', line 75

def update(album_id, params = {})
  if params.has_key?(:timestamp)
    params[:timestamp] = params[:timestamp].to_i * 1000
  end
  headers = auth_header.merge({"If-Match" => params.fetch(:etag, "*")})

  template = Template.new(:new_album, params)
  path = "/data/entry/api/user/#{user_id}/albumid/#{album_id}"
  response = Connection.new.patch(path: path, body: template.render, headers: headers)

  Presenter::Album.new(response.parsed_response["entry"])
end