Module: Picasa::Client::Media

Includes:
Base
Included in:
Picasa::Client
Defined in:
lib/picasa/client/media.rb

Constant Summary

Constants included from Base

Base::DEFAULT_LANGUAGE

Instance Method Summary collapse

Methods included from Base

#format_response

Instance Method Details

#add_photo_tag(gallery_id, photo_id, tag) ⇒ Object



31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
# File 'lib/picasa/client/media.rb', line 31

def add_photo_tag gallery_id, photo_id, tag
  body = "\r\n"
  body += "<entry xmlns='http://www.w3.org/2005/Atom'>"
  body += "<title>#{tag}</title>"
  body += "<category scheme=\"http://schemas.google.com/g/2005#kind\" term=\"http://schemas.google.com/photos/2007#tag\"/>"
  body += "</entry>\r\n"

  response = post("https://picasaweb.google.com/data/feed/api/user/default/albumid/#{gallery_id}/photoid/#{photo_id}", body)
  status, headers, body = response
  case status
    when 200
      return body
    else
      return body
    #raise(StandardError, "#{status.to_s} - #{body.to_s}")
  end
end

#create_photo(gallery_id, options = {}) ⇒ Object

Accepted image formats image/bmp image/gif image/jpeg image/png



89
90
91
92
93
94
95
96
97
98
99
100
101
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
# File 'lib/picasa/client/media.rb', line 89

def create_photo gallery_id, options = {}
  title   = options[:title].nil? ? "" : options[:title]
  summary = options[:summary].nil? ? "" : options[:summary]

  string_body = "<entry xmlns='http://www.w3.org/2005/Atom'>
  <title>#{title}</title>
  <summary>#{summary}</summary>
  <category scheme=\"http://schemas.google.com/g/2005#kind\"
    term=\"http://schemas.google.com/photos/2007#photo\"/>
</entry>
"
  uri         = "https://picasaweb.google.com/data/feed/api/user/default/albumid/#{gallery_id}"

  #@xml_io = FileUploadIO.new('/tmp/atom_body_0.atom', "application/atom+xml")
  @xml_io     = FileUploadIO.new('/tmp/atom_body.atom', "application/atom+xml", string_body)

  @photo_io = FileUploadIO.new('/home/trooper/Projetos/Aggregator-Tests/public/images/eu_s2b.jpg', "image/jpeg")

  headers        = {
      'Content-Type'  => 'multipart/related',
      'GData-Version' => '2',
      'Authorization' => "OAuth #{@client.access_token}",
      'MIME-version'  => '1.0',
  }
  params         = {
      :file_0 => @xml_io,
      :file_1 => @photo_io,
  }
  multipart_post = MultiPart::Post.new(params, headers)

  res                   = multipart_post.submit(uri, nil, 'multipart/related')
  status, headers, body = format_response(res)
  case status
    when 201
      return body
    else
      return body
    #raise(StandardError, "#{status.to_s} - #{body.to_s}")
  end
end

#delete_photo(gallery_id, photo_id) ⇒ Object



49
50
51
52
53
54
55
56
57
58
# File 'lib/picasa/client/media.rb', line 49

def delete_photo gallery_id, photo_id
  response = delete("https://picasaweb.google.com/data/feed/api/user/default/albumid/#{gallery_id}/photoid/#{photo_id}")
  status, headers, body = response
  case status
    when 200
      return body
    else
      return body
  end
end

#delete_photo_comment(gallery_id, photo_id, comment_id) ⇒ Object



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

def delete_photo_comment gallery_id, photo_id, comment_id
  response = delete("https://picasaweb.google.com/data/feed/api/user/default/albumid/#{gallery_id}/photoid/#{photo_id}/commentid/#{comment_id}")
  status, headers, body = response
  case status
    when 200
      return body
    else
      return body
    #raise(StandardError, "#{status.to_s} - #{body.to_s}")
  end
end

#delete_photo_tag(gallery_id, photo_id, tag_id) ⇒ Object



72
73
74
75
76
77
78
79
80
81
82
# File 'lib/picasa/client/media.rb', line 72

def delete_photo_tag gallery_id, photo_id, tag_id
  response = delete("https://picasaweb.google.com/data/feed/api/user/default/albumid/#{gallery_id}/photoid/#{photo_id}/tag/#{tag_id}")
  status, headers, body = response
  case status
    when 200
      return body
    else
      return body
    #raise(StandardError, "#{status.to_s} - #{body.to_s}")
  end
end

#get_photos(gallery_id) ⇒ Object



8
9
10
11
12
13
14
15
16
17
18
# File 'lib/picasa/client/media.rb', line 8

def get_photos gallery_id
  response = get("https://picasaweb.google.com/data/feed/api/user/default/albumid/#{gallery_id}?alt=json")
  status, headers, body = response
  case status
    when 200
      photos = MultiJson.decode(body.first)
      return photos["feed"]["entry"]
    else
      raise(StandardError, "#{status.to_s} - #{body.to_s}")
  end
end

#list_photo_tags(gallery_id, photo_id) ⇒ Object



20
21
22
23
24
25
26
27
28
29
# File 'lib/picasa/client/media.rb', line 20

def list_photo_tags gallery_id, photo_id
  response = get("https://picasaweb.google.com/data/feed/api/user/default/albumid/#{gallery_id}/photoid/#{photo_id}?kind=tag")
  status, headers, body = response
  case status
    when 200
      return body
    else
      return body
  end
end