Class: RubyPicasa::Base

Inherits:
Objectify::DocumentParser
  • Object
show all
Defined in:
lib/ruby_picasa/types.rb

Overview

Base class for User, Photo and Album types, not used independently.

attribute :id, 'gphoto:id'
attribute :feed_id, 'id'
attributes :updated, :title

has_many :links, Objectify::Atom::Link, 'link'
has_one :content, PhotoUrl, 'media:content'
has_many :thumbnails, ThumbnailUrl, 'media:thumbnail'
has_one :author, Objectify::Atom::Author, 'author'

Direct Known Subclasses

Album, Photo, User

Instance Method Summary collapse

Instance Method Details

#feed(options = {}) ⇒ Object

Retrieves the data feed at the url of the current record.



68
69
70
# File 'lib/ruby_picasa/types.rb', line 68

def feed(options = {})
  session.get_url(link('http://schemas.google.com/g/2005#feed').href, options)
end

Return the link object with the specified rel attribute value.



50
51
52
# File 'lib/ruby_picasa/types.rb', line 50

def link(rel)
  links.find { |l| rel === l.rel }
end

#nextObject

If the results are paginated, retrieve the next page.



73
74
75
76
77
# File 'lib/ruby_picasa/types.rb', line 73

def next
  if link = link('next')
    session.get_url(link.href)
  end
end

#previousObject

If the results are paginated, retrieve the previous page.



80
81
82
83
84
# File 'lib/ruby_picasa/types.rb', line 80

def previous
  if link = link('previous')
    session.get_url(link.href)
  end
end

#sessionObject

Should return the Picasa instance that retrieved this data.



59
60
61
62
63
64
65
# File 'lib/ruby_picasa/types.rb', line 59

def session
  if @session
    @session
  else
    @session = parent.session if parent
  end
end

#session=(session) ⇒ Object



54
55
56
# File 'lib/ruby_picasa/types.rb', line 54

def session=(session)
  @session = session
end

#thumbnail(thumb_name) ⇒ Object

See url for possible image sizes

Raises:



132
133
134
135
136
137
138
139
140
141
142
143
# File 'lib/ruby_picasa/types.rb', line 132

def thumbnail(thumb_name)
  raise PicasaError, 'Invalid thumbnail size' unless Photo::VALID.include?(thumb_name.to_s)
  thumb = thumbnails.find { |t| t.thumb_name == thumb_name }
  if thumb
    thumb
  elsif session
    f = feed(:thumbsize => thumb_name)
    if f
      f.thumbnails.first
    end
  end
end

#url(thumb_name = nil, options = nil) ⇒ Object

Thumbnail names are by image width in pixels. Sizes up to 160 may be either cropped (square) or uncropped:

cropped:        32c, 48c, 64c, 72c, 144c, 160c
uncropped:      32u, 48u, 64u, 72u, 144u, 160u

The rest of the image sizes should be specified by the desired width alone. Widths up to 800px may be embedded on a webpage:

embeddable:     200, 288, 320, 400, 512, 576, 640, 720, 800
not embeddable: 912, 1024, 1152, 1280, 1440, 1600

if a options is set to true or a hash is given, the width and height of the image will be added to the hash and returned. Useful for passing to the rails image_tag helper as follows:

image_tag(*image.url('72c', { :class => 'thumb' }))

which results in:

<img href="..." class="thumb" width="72" height="72">


108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
# File 'lib/ruby_picasa/types.rb', line 108

def url(thumb_name = nil, options = nil)
  url = nil
  if thumb_name.is_a? Hash
    options = thumb_name
    thumb_name = nil
  end
  options = {} if options and not options.is_a? Hash
  if thumb_name
    if thumb = thumbnail(thumb_name)
      url = thumb.url
      options = { :width => thumb.width, :height => thumb.height }.merge(options) if options
    end
  else
    url = content.url
    options = { :width => content.width, :height => content.height }.merge(options) if options
  end
  if options
    [url, options]
  else
    url
  end
end