Class: Googletastic::Calendar

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

Constant Summary

Constants included from Mixins::Namespaces

Mixins::Namespaces::NAMESPACES

Instance Attribute Summary collapse

Attributes inherited from Base

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

Attributes included from Mixins::Attributes

#attributes

Class Method Summary collapse

Methods inherited from Base

client_class, #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

#colorObject

Returns the value of attribute color.



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

def color
  @color
end

#created_atObject

Returns the value of attribute created_at.



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

def created_at
  @created_at
end

#hiddenObject

Returns the value of attribute hidden.



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

def hidden
  @hidden
end

#roleObject

Returns the value of attribute role.



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

def role
  @role
end

#selectedObject

Returns the value of attribute selected.



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

def selected
  @selected
end

#timezoneObject

Returns the value of attribute timezone.



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

def timezone
  @timezone
end

#titleObject

Returns the value of attribute title.



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

def title
  @title
end

#updated_atObject

Returns the value of attribute updated_at.



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

def updated_at
  @updated_at
end

Class Method Details

.index_urlObject



8
9
10
# File 'lib/googletastic/calendar.rb', line 8

def index_url
  "http://www.google.com/calendar/feeds/default/allcalendars/full"
end

.marshall(record) ⇒ Object



43
44
45
46
47
48
49
50
51
52
53
54
55
56
# File 'lib/googletastic/calendar.rb', line 43

def marshall(record)
  Nokogiri::XML::Builder.new { |xml| 
    xml.entry(ns_xml("atom", "gCal")) {
      if record.id
        xml.id {
          xml.text "#{ID}#{record.id}"
        }
      end
      xml.title {
        xml.text record.title
      }
    }
  }.to_xml
end

.show_url(id) ⇒ Object



12
13
14
# File 'lib/googletastic/calendar.rb', line 12

def show_url(id)
  "http://www.google.com/calendar/embed?src=#{id}"
end

.unmarshall(xml) ⇒ Object



16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
# File 'lib/googletastic/calendar.rb', line 16

def unmarshall(xml)
  records = xml.xpath("//atom:entry", ns_tag("atom")).collect do |record|
    id          = record.xpath("atom:id", ns_tag("atom")).first.text
    title       = record.xpath("atom:title", 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
    
    role        = record.xpath("gCal:accesslevel", ns_tag("gCal")).first["value"]
    color       = record.xpath("gCal:color", ns_tag("gCal")).first["value"]
    hidden      = record.xpath("gCal:hidden", ns_tag("gCal")).first["value"]
    selected    = record.xpath("gCal:selected", ns_tag("gCal")).first["value"]
    timezone    = record.xpath("gCal:timezone", ns_tag("gCal")).first["value"]
    
    Googletastic::Calendar.new(
      :id => id,
      :title => title,
      :created_at => created_at,
      :updated_at => updated_at,
      :role => role,
      :color => color,
      :selected => selected,
      :timezone => timezone
    )
  end
  records
end