Class: Picasa::API::Photo
Instance Attribute Summary
Attributes inherited from Base
#access_token, #authorization_header, #user_id
Instance Method Summary collapse
-
#create(album_id, params = {}) ⇒ Object
Creates photo for given album.
-
#destroy(album_id, photo_id, options = {}) ⇒ true
(also: #delete)
Destroys given photo.
-
#update(album_id, photo_id, params = {}) ⇒ Presenter::Photo
Updates metadata for photo.
Methods inherited from Base
Constructor Details
This class inherits a constructor from Picasa::API::Base
Instance Method Details
#create(album_id, params = {}) ⇒ Object
Creates photo for given album
16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 |
# File 'lib/picasa/api/photo.rb', line 16 def create(album_id, params = {}) file = params[:file_path] ? File.new(params.delete(:file_path)) : File::Null.new params[:boundary] ||= "===============PicasaRubyGem==" params[:title] ||= file.name || raise(ArgumentError.new("title must be specified")) params[:binary] ||= file.binary || raise(ArgumentError.new("binary must be specified")) params[:content_type] ||= file.content_type || raise(ArgumentError.new("content_type must be specified")) template = Template.new(:new_photo, params) headers = auth_header.merge({"Content-Type" => "multipart/related; boundary=\"#{params[:boundary]}\""}) path = "/data/feed/api/user/#{user_id}/albumid/#{album_id}" response = Connection.new.post(path: path, body: template.render, headers: headers) Presenter::Photo.new(response.parsed_response["entry"]) end |
#destroy(album_id, photo_id, options = {}) ⇒ true Also known as: delete
Destroys given photo
69 70 71 72 73 74 |
# File 'lib/picasa/api/photo.rb', line 69 def destroy(album_id, photo_id, = {}) headers = auth_header.merge({"If-Match" => .fetch(:etag, "*")}) path = "/data/entry/api/user/#{user_id}/albumid/#{album_id}/photoid/#{photo_id}" Connection.new.delete(path: path, headers: headers) true end |
#update(album_id, photo_id, params = {}) ⇒ Presenter::Photo
Updates metadata for photo
45 46 47 48 49 50 51 52 53 54 55 56 57 |
# File 'lib/picasa/api/photo.rb', line 45 def update(album_id, photo_id, params = {}) template = Template.new(:update_photo, params) headers = auth_header.merge({"Content-Type" => "application/xml", "If-Match" => params.fetch(:etag, "*")}) if params.has_key?(:timestamp) params[:timestamp] = params[:timestamp].to_i * 1000 end path = "/data/entry/api/user/#{user_id}/albumid/#{album_id}/photoid/#{photo_id}" response = Connection.new.patch(path: path, body: template.render, headers: headers) Presenter::Photo.new(response.parsed_response["entry"]) end |