Module: Picasa::HTTP::Album

Defined in:
lib/picasa/http/album.rb

Class Method Summary collapse

Class Method Details

.delete_album(user_id, album_id, auth_token) ⇒ Object

Do a delete request to delete an album from a user



49
50
51
52
53
54
55
# File 'lib/picasa/http/album.rb', line 49

def self.delete_album user_id, album_id, auth_token
  headers = albums_headers auth_token, "If-Match" => "*"
  
  uri = album_uri user_id, album_id
  http = Net::HTTP.new(uri.host, uri.port)
  http.send_request('DELETE',uri.path, nil, headers)
end

.get_album(user_id, album_id, auth_token = nil) ⇒ Object

Do a get request to retrieve one specific album from a user



71
72
73
74
75
76
77
78
# File 'lib/picasa/http/album.rb', line 71

def self.get_album user_id, album_id, auth_token = nil
  headers = albums_headers auth_token
  
  uri = album_uri user_id, album_id
  
  http = Net::HTTP.new(uri.host, 80)
  http.get uri.path, headers
end

.get_albums(user_id, auth_token) ⇒ Object

Do a get request to retrieve all the albums from a user using the user_id.



60
61
62
63
64
65
66
67
# File 'lib/picasa/http/album.rb', line 60

def self.get_albums user_id, auth_token
  headers = albums_headers auth_token
  
  uri = albums_uri user_id
  
  http = Net::HTTP.new(uri.host, 80)
  http.get uri.path, headers
end

.post_album(user_id, auth_token, params) ⇒ Object

Do a post request to create an album into the user account. The attributes used to create the album are:

title, summary, location, keywords



11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
# File 'lib/picasa/http/album.rb', line 11

def self.post_album user_id, auth_token, params
  
  puts params.inspect
  
  headers = albums_headers auth_token
  
  uri = albums_uri user_id
  http = Net::HTTP.new(uri.host, uri.port)
  
  # Render the album template
  template_path = File.dirname(__FILE__) + '/../template/'
  template = ERB.new File.open(template_path+"album.xml.erb").read
  
  data = template.result(binding)
  
  puts data
  
  return http.post(uri.path, data, headers)
end

.update_album(user_id, album_id, auth_token, params) ⇒ Object

Do a put request to update album data

Raises:

  • (Exception)


33
34
35
36
37
38
39
40
41
42
43
44
45
# File 'lib/picasa/http/album.rb', line 33

def self.update_album user_id, album_id, auth_token, params
  resp, data = get_album user_id, album_id, auth_token
  
  raise Exception, "Album not found." unless resp.code == "200"

  data = update_album_xml data, params 
  
  headers = albums_headers auth_token, "If-Match" => "*"
  
  uri = album_uri user_id, album_id
  http = Net::HTTP.new(uri.host, uri.port)
  http.send_request('PUT',uri.path, data, headers)
end