Module: Picasa::HTTP::Photo
- Defined in:
- lib/picasa/http/photo.rb
Class Method Summary collapse
-
.delete_photo(user_id, album_id, photo_id, auth_token) ⇒ Object
Do a delete request to delete a photo from an album.
- .download_image(link) ⇒ Object
-
.get_photo(user_id, album_id, photo_id, auth_token) ⇒ Object
Do a get request to retrieve one photo from an album.
-
.get_photos(user_id, album_id, auth_token) ⇒ Object
Do a get request to retrieve all the photos from an album.
-
.post_photo(user_id, album_id, auth_token, summary, file) ⇒ Object
Do a post request to save a new photo.
-
.update_photo(user_id, album_id, photo_id, auth_token, summary, file) ⇒ Object
Do a put request to update a photo from an album.
Class Method Details
.delete_photo(user_id, album_id, photo_id, auth_token) ⇒ Object
Do a delete request to delete a photo from an album
44 45 46 47 48 49 50 |
# File 'lib/picasa/http/photo.rb', line 44 def self.delete_photo user_id, album_id, photo_id, auth_token uri = photo_uri user_id, album_id, photo_id headers = photos_headers auth_token, "If-Match" => "*" http = Net::HTTP.new(uri.host, uri.port) http.send_request('DELETE',uri.path, nil, headers) end |
.download_image(link) ⇒ Object
72 73 74 75 76 77 78 79 80 81 82 83 84 85 |
# File 'lib/picasa/http/photo.rb', line 72 def self.download_image link uri = URI.parse link file_name = link.split("/").last http = Net::HTTP.new(uri.host) resp = http.get uri.path tempfilename = File.join(Dir.tmpdir, file_name) tempfile = File.new(tempfilename, "w") tempfile.write resp.body tempfile.close tempfile end |
.get_photo(user_id, album_id, photo_id, auth_token) ⇒ Object
Do a get request to retrieve one photo from an album
17 18 19 20 21 |
# File 'lib/picasa/http/photo.rb', line 17 def self.get_photo user_id, album_id, photo_id, auth_token uri = photo_uri user_id, album_id, photo_id http = Net::HTTP.new(uri.host) http.get uri.path, auth_header(auth_token) end |
.get_photos(user_id, album_id, auth_token) ⇒ Object
Do a get request to retrieve all the photos from an album
9 10 11 12 13 |
# File 'lib/picasa/http/photo.rb', line 9 def self.get_photos user_id, album_id, auth_token uri = photos_uri user_id, album_id http = Net::HTTP.new(uri.host) http.get uri.path, auth_header(auth_token) end |
.post_photo(user_id, album_id, auth_token, summary, file) ⇒ Object
Do a post request to save a new photo.
25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 |
# File 'lib/picasa/http/photo.rb', line 25 def self.post_photo user_id, album_id, auth_token, summary, file uri = photos_uri user_id, album_id template_path = File.dirname(__FILE__) + '/../template/' template = ERB.new File.open(template_path+"photo.erb").read body = template.result(binding) http = Net::HTTP.new(uri.host, uri.port) request = Net::HTTP::Post.new(uri.request_uri) request.body = body request["Content-Type"] = "multipart/related; boundary=\"END_OF_PART\"" request["Authorization"] = "GoogleLogin auth=#{auth_token}" http.request(request) end |
.update_photo(user_id, album_id, photo_id, auth_token, summary, file) ⇒ Object
Do a put request to update a photo from an album
54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 |
# File 'lib/picasa/http/photo.rb', line 54 def self.update_photo user_id, album_id, photo_id, auth_token, summary, file uri = photo_media_uri user_id, album_id, photo_id template_path = File.dirname(__FILE__) + '/../template/' template = ERB.new File.open(template_path+"photo.erb").read body = template.result(binding) http = Net::HTTP.new(uri.host, uri.port) request = Net::HTTP::Put.new(uri.request_uri) request.body = body request["Content-Type"] = "multipart/related; boundary=\"END_OF_PART\"" request["Authorization"] = "GoogleLogin auth=#{auth_token}" request["If-Match"] = "*" http.request(request) end |