Class: Googletastic::Image

Inherits:
Base
  • Object
show all
Defined in:
lib/googletastic/image.rb

Constant Summary

Constants included from Mixins::Namespaces

Mixins::Namespaces::NAMESPACES

Instance Attribute Summary collapse

Attributes inherited from Base

#acl, #attachment_path, #etag, #head, #keep_raw, #raw, #response, #synced_with

Attributes included from Mixins::Attributes

#attributes

Class Method Summary collapse

Methods inherited from Base

#initialize, #to_xml

Methods included from Mixins::Pagination

included

Methods included from Mixins::Finders

included

Methods included from Mixins::Parsing

included

Methods included from Mixins::Requesting

included

Methods included from Mixins::Attributes

#attribute_names, #has_attribute?, #inspect

Methods included from Mixins::Namespaces

included

Constructor Details

This class inherits a constructor from Googletastic::Base

Instance Attribute Details

#accessObject

Returns the value of attribute access.



4
5
6
# File 'lib/googletastic/image.rb', line 4

def access
  @access
end

#album_idObject

Returns the value of attribute album_id.



4
5
6
# File 'lib/googletastic/image.rb', line 4

def album_id
  @album_id
end

#commentableObject

Returns the value of attribute commentable.



4
5
6
# File 'lib/googletastic/image.rb', line 4

def commentable
  @commentable
end

#content_typeObject

Returns the value of attribute content_type.



3
4
5
# File 'lib/googletastic/image.rb', line 3

def content_type
  @content_type
end

#created_atObject

Returns the value of attribute created_at.



4
5
6
# File 'lib/googletastic/image.rb', line 4

def created_at
  @created_at
end

#heightObject

Returns the value of attribute height.



3
4
5
# File 'lib/googletastic/image.rb', line 3

def height
  @height
end

#idObject

Returns the value of attribute id.



4
5
6
# File 'lib/googletastic/image.rb', line 4

def id
  @id
end

#kindObject

Returns the value of attribute kind.



4
5
6
# File 'lib/googletastic/image.rb', line 4

def kind
  @kind
end

#sizeObject

Returns the value of attribute size.



3
4
5
# File 'lib/googletastic/image.rb', line 3

def size
  @size
end

#summaryObject

Returns the value of attribute summary.



3
4
5
# File 'lib/googletastic/image.rb', line 3

def summary
  @summary
end

#thumbnailsObject

Returns the value of attribute thumbnails.



3
4
5
# File 'lib/googletastic/image.rb', line 3

def thumbnails
  @thumbnails
end

#titleObject

Returns the value of attribute title.



3
4
5
# File 'lib/googletastic/image.rb', line 3

def title
  @title
end

#updated_atObject

Returns the value of attribute updated_at.



4
5
6
# File 'lib/googletastic/image.rb', line 4

def updated_at
  @updated_at
end

#urlObject

Returns the value of attribute url.



3
4
5
# File 'lib/googletastic/image.rb', line 3

def url
  @url
end

#widthObject

Returns the value of attribute width.



3
4
5
# File 'lib/googletastic/image.rb', line 3

def width
  @width
end

Class Method Details

.build_url(options) ⇒ Object



41
42
43
44
45
46
47
48
# File 'lib/googletastic/image.rb', line 41

def build_url(options)
  base = options.has_key?(:url) ? options[:url] : self.index_url
  options[:url] = base
  options[:kind] = "photo" unless options.has_key?(:kind)
  options[:access] ||= "all"
  #options[:image_max_size] = 720 unless options.has_key?(:image_max_size)
  super(options)
end

.client_classObject



33
34
35
# File 'lib/googletastic/image.rb', line 33

def client_class
  "Photos"
end

.index_urlObject



37
38
39
# File 'lib/googletastic/image.rb', line 37

def index_url
  "http://picasaweb.google.com/data/feed/api/user/#{Googletastic.credentials[:username]}"
end

.marshall(record) ⇒ Object

not implemented



104
105
106
107
108
109
110
111
112
113
114
115
116
117
# File 'lib/googletastic/image.rb', line 104

def marshall(record)
  Nokogiri::XML::Builder.new { |xml| 
    xml.entry('xmlns' => Googletastic::ATOM_NS, 'xmlns:docs' => ns("docs")) {
      if record.id
        xml.id {
          xml.text show_url(record.id)
        }
      end
      xml.title {
        xml.text record.title
      }
    }
  }.to_xml
end

.unmarshall(xml) ⇒ Object



50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
# File 'lib/googletastic/image.rb', line 50

def unmarshall(xml)
  records = xml.xpath("//atom:entry", ns_tag("atom")).collect do |record|
    # thumbnails
    thumbnails = record.xpath("media:group/media:thumbnail").collect do |thumbnail|
      url     = thumbnail["url"]
      width   = thumbnail["width"].to_i
      height  = thumbnail["height"].to_i
      Googletastic::Thumbnail.new(
        :url => url,
        :width => width,
        :height => height
      )
    end

    id            = record.xpath("atom:id", ns_tag("atom")).first.text
    created_at    = record.xpath("atom:published", ns_tag("atom")).first.text
    updated_at    = record.xpath("atom:updated", ns_tag("atom")).first.text
    kind          = "photo"
    title         = record.xpath("atom:title", ns_tag("atom")).first.text
    summary       = record.xpath("atom:summary", ns_tag("atom")).first.text
                
    album_id      = record.xpath("gphoto:albumid", ns_tag("gphoto")).first.text
    access        = record.xpath("gphoto:access", ns_tag("gphoto")).first.text
    width         = record.xpath("gphoto:width", ns_tag("gphoto")).first.text.to_i
    height        = record.xpath("gphoto:height", ns_tag("gphoto")).first.text.to_i
    size          = record.xpath("gphoto:size", ns_tag("gphoto")).first.text.to_i
    
    commentable   = record.xpath("gphoto:commentingEnabled", ns_tag("gphoto")).first.text == "true" ? true : false
                
    content       = record.xpath("media:group/media:content").first
    url           = content["url"].to_s
    content_type  = content["type"].to_s

    Googletastic::Image.new(
      :id => id,
      :created_at => created_at,
      :kind => kind,
      :title => title,
      :summary => summary,
      :album_id => album_id,
      :access => access,
      :width => width,
      :height => height,
      :size => size,
      :commentable => commentable,
      :url => url,
      :content_type => content_type,
      :thumbnails => thumbnails
    )
  end
  records
end

.valid_access?(value) ⇒ Boolean

Returns:

  • (Boolean)


21
22
23
# File 'lib/googletastic/image.rb', line 21

def valid_access?(value)
  %w(all private public visible).include?(value)
end

.valid_image_max_size?(value) ⇒ Boolean

Returns:

  • (Boolean)


25
26
27
# File 'lib/googletastic/image.rb', line 25

def valid_image_max_size?(value)
  [94, 110, 128, 200, 220, 288, 320, 400, 512, 576, 640, 720, 800, 912, 1024, 1152, 1280, 1440, 1600].include?(value)
end

.valid_kind?(value) ⇒ Boolean

Returns:

  • (Boolean)


29
30
31
# File 'lib/googletastic/image.rb', line 29

def valid_kind?(value)
  %w(album photo comment tag user).include?(value)
end

.valid_queriesObject



9
10
11
12
13
14
15
16
17
18
19
# File 'lib/googletastic/image.rb', line 9

def valid_queries
  {
    :access => "access",
    :geo_coordinates => "bbox",
    :geo_location => "l",
    :image_max_size => "imgmax",
    :thumb_size => "thumbsize",
    :kind => "kind",
    :tag => "tag",
  }.merge(super)
end