Class: Picasa::API::Comment

Inherits:
Base
  • Object
show all
Defined in:
lib/picasa/api/comment.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::Tag

Creates a comment for a photo.

Parameters:

  • (Hash)
  • options (Hash)

    a customizable set of options

Returns:


35
36
37
38
39
40
41
42
43
44
45
46
47
# File 'lib/picasa/api/comment.rb', line 35

def create(params = {})
  album_id = params.delete(:album_id) || raise(ArgumentError, "You must specify album_id")
  photo_id = params.delete(:photo_id) || raise(ArgumentError, "You must specify photo_id")
  params[:content] || raise(ArgumentError, "You must specify content")

  path = "/data/feed/api/user/#{user_id}/albumid/#{album_id}/photoid/#{photo_id}"

  template = Template.new("new_comment", params)

  response = Connection.new.post(path: path, body: template.render, headers: auth_header)

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

#destroy(comment_id, params = {}) ⇒ true Also known as: delete

Removes a comment from given photo.

Parameters:

  • comment_id (String)

    comment id

  • (Hash)
  • options (Hash)

    a customizable set of options

Returns:

  • (true)

57
58
59
60
61
62
63
64
# File 'lib/picasa/api/comment.rb', line 57

def destroy(comment_id, params = {})
  album_id = params.delete(:album_id) || raise(ArgumentError, "You must specify album_id")
  photo_id = params.delete(:photo_id) || raise(ArgumentError, "You must specify photo_id")

  path = "/data/entry/api/user/#{user_id}/albumid/#{album_id}/photoid/#{photo_id}/commentid/#{comment_id}"
  Connection.new.delete(path: path, headers: auth_header)
  true
end

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

Returns comment list - when album_id is not specified, list of user comments will be returned

Parameters:

  • options (Hash) (defaults to: {})

    additional options included in request

Options Hash (options):

  • :album_id (String)

    retrieve comments for given album

  • :photo_id (String)

    retrieve comments for given photo (album_id must be provided)

Returns:

Raises:


13
14
15
16
17
18
19
20
21
22
23
24
25
# File 'lib/picasa/api/comment.rb', line 13

def list(options = {})
  album_id = options.delete(:album_id)
  photo_id = options.delete(:photo_id)
  raise(ArgumentError, "You must specify album_id when providing photo_id") if photo_id && !album_id

  path = "/data/feed/api/user/#{user_id}"
  path << "/albumid/#{album_id}" if album_id
  path << "/photoid/#{photo_id}" if photo_id

  response = Connection.new.get(path: path, query: options.merge(kind: "comment"), headers: auth_header)

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