Class: Rufus::Google::Calendar

Inherits:
Object
  • Object
show all
Includes:
CollectionMixin
Defined in:
lib/rufus/gcal.rb

Instance Attribute Summary

Attributes included from CollectionMixin

#href, #name

Class Method Summary collapse

Instance Method Summary collapse

Methods included from CollectionMixin

#delete!, #initialize, #post!

Class Method Details

.get_calendars(options) ⇒ Object

Returns a hash calendar_name => calendar

an example :

calendars = Rufus::Google::Calendar.get_calendars(
  :account => ENV['GUSER'], :password => env['GPASS'])
calendars.values.each { |c| p [ c.name, c.href ] }


86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
# File 'lib/rufus/gcal.rb', line 86

def self.get_calendars (options)

  options[:service] = :cl

  feed = Rufus::Google.feed_for(
    'https://www.google.com/calendar/feeds/default', options)

  feed.update! # fetch the data over the net

  feed.entries.inject({}) { |h, e|
    c = Calendar.new(options[:auth], e)
    h[c.name] = c
    h
  }
end

Instance Method Details

#events(query = {}) ⇒ Object

Returns all the events in the calendar.

The query hash can be used to ‘query’ those events. It currently accepts :q, :start_min and :start_max as keys.



52
53
54
55
56
57
58
59
60
61
62
63
64
# File 'lib/rufus/gcal.rb', line 52

def events (query={})

  q = query.inject([]) { |a, (k, v)|
    a << "#{k.to_s.gsub(/\_/, '-')}=#{v}"
  }.join("&")

  q = "?#{q}" if q.length > 0

  feed = Rufus::Google.feed_for("#{href}#{q}", @token)
  feed.update!

  feed.entries.collect { |e| Event.new(e) }
end

#post_quick!(event_text) ⇒ Object

Posts (creates) a QuickAdd event in this calendar.

code.google.com/apis/calendar/developers_guide_protocol.html#CreatingQuickAdd



72
73
74
75
# File 'lib/rufus/gcal.rb', line 72

def post_quick! (event_text)

  post!(Event.create_quick(event_text))
end