Class: RubyPicasa::Base
- Inherits:
-
Objectify::DocumentParser
- Object
- Objectify::DocumentParser
- RubyPicasa::Base
- Defined in:
- lib/ruby_picasa/types.rb
Overview
Note that in all defined classes I’m ignoring values I don’t happen to need or know about. Please do add support for the ones I’ve missed. Be sure to declare which namespaces are supported with the namespaces method. Any elements defined in other namespaces are automatically ignored.
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'
Instance Method Summary collapse
-
#feed(options = {}) ⇒ Object
Retrieves the data feed at the url of the current record.
-
#link(rel) ⇒ Object
Return the link object with a matching rel attribute value.
-
#next ⇒ Object
If the results are paginated, retrieve the next page.
-
#previous ⇒ Object
If the results are paginated, retrieve the previous page.
-
#session ⇒ Object
Should return the Picasa instance that retrieved this data.
- #session=(session) ⇒ Object
-
#tb(new_size, crop = false) ⇒ Object
convert a thumbnail from a size to another, example: tb(160) converts this thumbnail url:
into this one with new size:
the thumb does not need to exist on the xml. -
#thumbnail(thumb_name) ⇒ Object
See
urlfor possible image sizes. -
#url(thumb_name = nil, options = nil) ⇒ Object
Thumbnail names are by image width in pixels.
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( = {}) session.get_url(link('http://schemas.google.com/g/2005#feed').href, ) end |
#link(rel) ⇒ Object
Return the link object with a matching rel attribute value. rel can be either a fully matching string or a regular expression.
50 51 52 |
# File 'lib/ruby_picasa/types.rb', line 50 def link(rel) links.find { |l| rel === l.rel } end |
#next ⇒ Object
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 |
#previous ⇒ Object
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 |
#session ⇒ Object
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 |
#tb(new_size, crop = false) ⇒ Object
convert a thumbnail from a size to another, example: tb(160) converts this thumbnail url:
into this one with new size:
the thumb does not need to exist on the xml
151 152 153 154 155 156 |
# File 'lib/ruby_picasa/types.rb', line 151 def tb(new_size, crop = false) crop = crop ? "-c" : "" parts = thumbnails.first.url.split "/" parts[-2] = "s" + new_size.to_s + crop parts.join "/" end |
#thumbnail(thumb_name) ⇒ Object
See url for possible image sizes
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, = nil) url = nil if thumb_name.is_a? Hash = thumb_name thumb_name = nil end = {} if and not .is_a? Hash if thumb_name if thumb = thumbnail(thumb_name) url = thumb.url = { :width => thumb.width, :height => thumb.height }.merge() if end else url = content.url = { :width => content.width, :height => content.height }.merge() if end if [url, ] else url end end |