Class: Googletastic::Event

Inherits:
Base
  • Object
show all
Defined in:
lib/googletastic/event.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

Instance 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

#calendar_idObject

not yet implemented



7
8
9
# File 'lib/googletastic/event.rb', line 7

def calendar_id
  @calendar_id
end

#commentsObject

Returns the value of attribute comments.



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

def comments
  @comments
end

#created_atObject

Returns the value of attribute created_at.



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

def created_at
  @created_at
end

#descriptionObject

Returns the value of attribute description.



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

def description
  @description
end

#end_timeObject

Returns the value of attribute end_time.



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

def end_time
  @end_time
end

#guests_can_inviteObject

Returns the value of attribute guests_can_invite.



5
6
7
# File 'lib/googletastic/event.rb', line 5

def guests_can_invite
  @guests_can_invite
end

#guests_can_joinObject

Returns the value of attribute guests_can_join.



5
6
7
# File 'lib/googletastic/event.rb', line 5

def guests_can_join
  @guests_can_join
end

#guests_can_modifyObject

Returns the value of attribute guests_can_modify.



5
6
7
# File 'lib/googletastic/event.rb', line 5

def guests_can_modify
  @guests_can_modify
end

#guests_can_see_guestsObject

Returns the value of attribute guests_can_see_guests.



5
6
7
# File 'lib/googletastic/event.rb', line 5

def guests_can_see_guests
  @guests_can_see_guests
end

#repeatsObject

not yet implemented



7
8
9
# File 'lib/googletastic/event.rb', line 7

def repeats
  @repeats
end

#sequenceObject

Returns the value of attribute sequence.



5
6
7
# File 'lib/googletastic/event.rb', line 5

def sequence
  @sequence
end

#start_timeObject

Returns the value of attribute start_time.



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

def start_time
  @start_time
end

#statusObject

Returns the value of attribute status.



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

def status
  @status
end

#titleObject

Returns the value of attribute title.



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

def title
  @title
end

#updated_atObject

Returns the value of attribute updated_at.



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

def updated_at
  @updated_at
end

#whereObject

Returns the value of attribute where.



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

def where
  @where
end

#whoObject

Returns the value of attribute who.



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

def who
  @who
end

Class Method Details

.client_classObject



22
23
24
# File 'lib/googletastic/event.rb', line 22

def client_class
  "Calendar"
end

.edit_url(id) ⇒ Object



30
31
32
# File 'lib/googletastic/event.rb', line 30

def edit_url(id)
  "http://www.google.com/calendar/feeds/default/private/full/#{id}"
end

.index_urlObject



26
27
28
# File 'lib/googletastic/event.rb', line 26

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

.marshall(record) ⇒ Object



107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
# File 'lib/googletastic/event.rb', line 107

def marshall(record)
  Nokogiri::XML::Builder.new { |xml| 
    xml.entry(ns_xml("atom", "gCal", "gd")) {
      if record.id
        xml.id_ {
          xml.text record.id
        }
      end
      if record.created_at
        xml.published {
          xml.text record.created_at
        }
      end
      if record.updated_at
        xml.updated {
          xml.text record.updated_at
        }
      end
      xml.title {
        xml.text record.title
      }
      xml.content {
        xml.text record.description
      }
      record.who.each do |who|
        xml["gd"].who(
          :email => who.email, 
          :rel => "http://schemas.google.com/g/2005#event.#{who.role}",
          :valueString => who.name
        ) {
          xml["gd"].attendeeStatus(:value => "http://schemas.google.com/g/2005#event.#{record.status}")
        }
      end unless record.who.nil?
      xml["gd"].where("valueString" => record.where)
      
      xml["gd"].when("startTime" => record.start_time, "endTime" => record.end_time)
    }
  }.to_xml
end

.unmarshall(xml) ⇒ Object



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
102
103
104
105
# File 'lib/googletastic/event.rb', line 57

def unmarshall(xml)
  records = xml.xpath("//atom:entry", ns_tag("atom")).collect do |record|
    id          = record.xpath("atom:id", ns_tag("atom")).first.text.split("/").last
    title       = record.xpath("atom:title", ns_tag("atom")).first.text
    description = record.xpath("atom:content", 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
    
    status      = record.xpath("gd:eventStatus", ns_tag("gd")).first["value"].gsub("http://schemas.google.com/g/2005#event.", "")
    where       = record.xpath("gd:where", ns_tag("gd")).first["valueString"].to_s
    
    who         = record.xpath("gd:who", ns_tag("gd")).collect do |who|
      Googletastic::Attendee.new(
        :name => who["valueString"].to_s,
        :email => who["email"],
        :role => who["rel"].gsub("http://schemas.google.com/g/2005#event.", "")
      )
    end

    time        = record.xpath("gd:when", ns_tag("gd")).first
    start_time  = time["startTime"].to_s
    end_time    = time["endTime"].to_s
    
    guests_can_join     = record.xpath("gCal:anyoneCanAddSelf", ns_tag("gCal")).first["value"] == "true" ? true : false
    guests_can_invite   = record.xpath("gCal:guestsCanInviteOthers", ns_tag("gCal")).first["value"] == "true" ? true : false
    guests_can_modify   = record.xpath("gCal:guestsCanModify", ns_tag("gCal")).first["value"] == "true" ? true : false
    guests_can_see_guests = record.xpath("gCal:guestsCanSeeGuests", ns_tag("gCal")).first["value"] == "true" ? true : false
    sequence            = record.xpath("gCal:sequence", ns_tag("gCal")).first["value"].to_i
    
    Googletastic::Event.new(
      :id => id,
      :title => title,
      :description => description,
      :created_at => created_at,
      :updated_at => updated_at,
      :status => status,
      :where => where,
      :who => who,
      :start_time => start_time,
      :end_time => end_time,
      :guests_can_join => guests_can_join,
      :guests_can_invite => guests_can_invite,
      :guests_can_modify => guests_can_modify,
      :guests_can_see_guests => guests_can_see_guests,
      :sequence => sequence
    )
  end
  records
end

.valid_order?(value) ⇒ Boolean

Returns:

  • (Boolean)


49
50
51
# File 'lib/googletastic/event.rb', line 49

def valid_order?(value)
  %w(lastmodified starttime).include?(value)
end

.valid_queriesObject



36
37
38
39
40
41
42
43
44
45
46
47
# File 'lib/googletastic/event.rb', line 36

def valid_queries
  {
    :timezone => "ctz",
    :future_only => "futureevents",
    :order => "orderby",
    :collapse_recurring => "singleevents",
    :show_hidden => "showhidden",
    :before => "start-max",
    :after => "start-min",
    :sort => "sortorder" # should be merged with "order"
  }.merge(super)
end

.valid_sort?(value) ⇒ Boolean

Returns:

  • (Boolean)


53
54
55
# File 'lib/googletastic/event.rb', line 53

def valid_sort?(value)
  %w(ascending descending).include?(value)
end

Instance Method Details

#edit_urlObject



16
17
18
# File 'lib/googletastic/event.rb', line 16

def edit_url
  self.class.edit_url(self.id)
end

#new_record?Boolean

Returns:

  • (Boolean)


9
10
11
12
13
14
# File 'lib/googletastic/event.rb', line 9

def new_record?
  return false if !self.id.nil?
  return true
  # not yet using this
  return self.class.first(:start_time => self.start_time, :end_time => self.end_time).nil?
end