Class: Picasa::API::Tag

Inherits:
Base
  • Object
show all
Defined in:
lib/picasa/api/tag.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 tag for a photo.


35
36
37
38
39
40
41
42
43
44
45
46
47
# File 'lib/picasa/api/tag.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[:title] || raise(ArgumentError, "You must specify title")

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

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

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

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

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

Removes a tag from given photo.


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

def destroy(tag_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}/tag/#{tag_id}"
  Connection.new.delete(path: path, headers: auth_header)
  true
end

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

Returns tag list - when album_id is not specified, list of user tags will be returned

Options Hash (options):

  • :album_id (String)

    retrieve tags for given album

  • :photo_id (String)

    retrieve tags for given photo (album_id must be provided)

Raises:


13
14
15
16
17
18
19
20
21
22
23
24
25
# File 'lib/picasa/api/tag.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: "tag"), headers: auth_header)

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