Class: Picasa::Photo

Inherits:
Object
  • Object
show all
Defined in:
lib/picasa.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializePhoto

Returns a new instance of Photo.



488
489
490
# File 'lib/picasa.rb', line 488

def initialize()
  thumbnails = []
end

Instance Attribute Details

#album_idObject

Returns the value of attribute album_id.



478
479
480
# File 'lib/picasa.rb', line 478

def album_id
  @album_id
end

#clientObject

Returns the value of attribute client.



480
481
482
# File 'lib/picasa.rb', line 480

def client
  @client
end

#descriptionObject

Returns the value of attribute description.



477
478
479
# File 'lib/picasa.rb', line 477

def description
  @description
end

#edit_urlObject

Returns the value of attribute edit_url.



486
487
488
# File 'lib/picasa.rb', line 486

def edit_url
  @edit_url
end

#heightObject

Returns the value of attribute height.



482
483
484
# File 'lib/picasa.rb', line 482

def height
  @height
end

#idObject

Returns the value of attribute id.



476
477
478
# File 'lib/picasa.rb', line 476

def id
  @id
end

#is_commentableObject

Returns the value of attribute is_commentable.



481
482
483
# File 'lib/picasa.rb', line 481

def is_commentable
  @is_commentable
end

#mediumObject

Returns the value of attribute medium.



482
483
484
# File 'lib/picasa.rb', line 482

def medium
  @medium
end

#number_of_commentsObject

Returns the value of attribute number_of_comments.



481
482
483
# File 'lib/picasa.rb', line 481

def number_of_comments
  @number_of_comments
end

#picasa_sessionObject

Returns the value of attribute picasa_session.



474
475
476
# File 'lib/picasa.rb', line 474

def picasa_session
  @picasa_session
end

#self_xml_urlObject

Returns the value of attribute self_xml_url.



486
487
488
# File 'lib/picasa.rb', line 486

def self_xml_url
  @self_xml_url
end

#sizeObject

Returns the value of attribute size.



479
480
481
# File 'lib/picasa.rb', line 479

def size
  @size
end

#thumbnailsObject

Returns the value of attribute thumbnails.



483
484
485
# File 'lib/picasa.rb', line 483

def thumbnails
  @thumbnails
end

#titleObject

Returns the value of attribute title.



477
478
479
# File 'lib/picasa.rb', line 477

def title
  @title
end

#typeObject

Returns the value of attribute type.



482
483
484
# File 'lib/picasa.rb', line 482

def type
  @type
end

#urlObject

Returns the value of attribute url.



482
483
484
# File 'lib/picasa.rb', line 482

def url
  @url
end

#version_numberObject

Returns the value of attribute version_number.



485
486
487
# File 'lib/picasa.rb', line 485

def version_number
  @version_number
end

#widthObject

Returns the value of attribute width.



482
483
484
# File 'lib/picasa.rb', line 482

def width
  @width
end

#xmlObject

Returns the value of attribute xml.



484
485
486
# File 'lib/picasa.rb', line 484

def xml
  @xml
end

Instance Method Details

#move_to_album(picasa_album_id) ⇒ Object



530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
# File 'lib/picasa.rb', line 530

def move_to_album(picasa_album_id)

  updatePhotoXml = "<entry xmlns='http://www.w3.org/2005/Atom'
                xmlns:media='http://search.yahoo.com/mrss/'
                xmlns:gphoto='http://schemas.google.com/photos/2007'>
                  <title type='text'>#{self.title}</title>
                  <summary type='text'>#{self.description}</summary>
                  <gphoto:albumid>#{picasa_album_id}</gphoto:albumid>
                  <gphoto:checksum></gphoto:checksum>
                  <gphoto:client></gphoto:client>
                  <gphoto:rotation>#{0}</gphoto:rotation>
                  <gphoto:timestamp>#{Time.new.to_i.to_s}</gphoto:timestamp>
                  <gphoto:commentingEnabled>#{self.is_commentable.to_s}</gphoto:commentingEnabled>
                  <category scheme='http://schemas.google.com/g/2005#kind'
                    term='http://schemas.google.com/photos/2007#photo'></category>
                </entry>"

  url = "http://picasaweb.google.com/data/entry/api/user/#{self.picasa_session.user_id}/albumid/#{self.album_id}/photoid/#{self.id}/#{self.version_number}"

  uri = URI.parse(url)
  http = Net::HTTP.new(uri.host, uri.port)

  headers = {"Content-Type" => "application/atom+xml", "Authorization" => "GoogleLogin auth=#{self.picasa_session.auth_key}"}

  response, data = http.put(uri.path, updatePhotoXml, headers)
  data = response.body

  if(response.code == "200")
    #parse the entry xml element and get the photo object
    new_photo = Picasa.parse_photo_entry(XmlSimple.xml_in(data.to_s, { 'ForceArray' => false }))
    self.version_number = new_photo.version_number
    self.album_id = new_photo.album_id

    return true
  else
    return false
  end

end

#updateObject



492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
# File 'lib/picasa.rb', line 492

def update()

  updatePhotoXml = "<entry xmlns='http://www.w3.org/2005/Atom'
                xmlns:media='http://search.yahoo.com/mrss/'
                xmlns:gphoto='http://schemas.google.com/photos/2007'>
                  <title type='text'>#{self.title}</title>
                  <summary type='text'>#{self.description}</summary>
                  <gphoto:checksum></gphoto:checksum>
                  <gphoto:client></gphoto:client>
                  <gphoto:rotation>#{0}</gphoto:rotation>
                  <gphoto:timestamp>#{Time.new.to_i.to_s}</gphoto:timestamp>
                  <gphoto:commentingEnabled>#{self.is_commentable.to_s}</gphoto:commentingEnabled>
                  <category scheme='http://schemas.google.com/g/2005#kind'
                    term='http://schemas.google.com/photos/2007#photo'></category>
                </entry>"

  url = "http://picasaweb.google.com/data/entry/api/user/#{self.picasa_session.user_id}/albumid/#{self.album_id}/photoid/#{self.id}/#{self.version_number}"

  uri = URI.parse(url)
  http = Net::HTTP.new(uri.host, uri.port)

  headers = {"Content-Type" => "application/atom+xml", "Authorization" => "GoogleLogin auth=#{self.picasa_session.auth_key}"}

  response, data = http.put(uri.path, updatePhotoXml, headers)
  data = response.body

  if(response.code == "200")
    #parse the entry xml element and get the photo object
    #new_photo = Picasa.parse_photo_entry(data)
    new_photo = Picasa.parse_photo_entry(XmlSimple.xml_in(data.to_s, { 'ForceArray' => false }))
    self.version_number = new_photo.version_number

    return true
  else
    return false
  end
end