Class: Google::Calendar::Event

Inherits:
Object
  • Object
show all
Defined in:
lib/google/calendar/event.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(options = {}) ⇒ Event

Returns a new instance of Event.



24
25
26
# File 'lib/google/calendar/event.rb', line 24

def initialize(options={})
  update_attributes(options)
end

Instance Attribute Details

#createdObject (readonly)

API Reference

* https://developers.google.com/google-apps/calendar/v3/reference/#Events

Supported Google Calendar API (Events)

Method    VERB    PATH
--------  ------  --------------------------------------
get       GET     /calendars/:calendarId/events/:eventId
list      GET     /calendars/:calendarId/events
insert    POST    /calendars/:calendarId/events
delete    DELETE  /calendars/:calendarId/events/:eventId
quickAdd  POST    /calendars/:calendarId/events/quickAdd
update    PUT     /calendars/:calendarId/events/:eventId


21
22
23
# File 'lib/google/calendar/event.rb', line 21

def created
  @created
end

#creatorObject (readonly)

Returns the value of attribute creator.



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

def creator
  @creator
end

#endObject

Returns the value of attribute end.



23
24
25
# File 'lib/google/calendar/event.rb', line 23

def end
  @end
end

#etagObject (readonly)

API Reference

* https://developers.google.com/google-apps/calendar/v3/reference/#Events

Supported Google Calendar API (Events)

Method    VERB    PATH
--------  ------  --------------------------------------
get       GET     /calendars/:calendarId/events/:eventId
list      GET     /calendars/:calendarId/events
insert    POST    /calendars/:calendarId/events
delete    DELETE  /calendars/:calendarId/events/:eventId
quickAdd  POST    /calendars/:calendarId/events/quickAdd
update    PUT     /calendars/:calendarId/events/:eventId


21
22
23
# File 'lib/google/calendar/event.rb', line 21

def etag
  @etag
end

API Reference

* https://developers.google.com/google-apps/calendar/v3/reference/#Events

Supported Google Calendar API (Events)

Method    VERB    PATH
--------  ------  --------------------------------------
get       GET     /calendars/:calendarId/events/:eventId
list      GET     /calendars/:calendarId/events
insert    POST    /calendars/:calendarId/events
delete    DELETE  /calendars/:calendarId/events/:eventId
quickAdd  POST    /calendars/:calendarId/events/quickAdd
update    PUT     /calendars/:calendarId/events/:eventId


21
22
23
# File 'lib/google/calendar/event.rb', line 21

def htmlLink
  @htmlLink
end

#iCalUIDObject (readonly)

Returns the value of attribute iCalUID.



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

def iCalUID
  @iCalUID
end

#idObject (readonly)

API Reference

* https://developers.google.com/google-apps/calendar/v3/reference/#Events

Supported Google Calendar API (Events)

Method    VERB    PATH
--------  ------  --------------------------------------
get       GET     /calendars/:calendarId/events/:eventId
list      GET     /calendars/:calendarId/events
insert    POST    /calendars/:calendarId/events
delete    DELETE  /calendars/:calendarId/events/:eventId
quickAdd  POST    /calendars/:calendarId/events/quickAdd
update    PUT     /calendars/:calendarId/events/:eventId


21
22
23
# File 'lib/google/calendar/event.rb', line 21

def id
  @id
end

#kindObject (readonly)

API Reference

* https://developers.google.com/google-apps/calendar/v3/reference/#Events

Supported Google Calendar API (Events)

Method    VERB    PATH
--------  ------  --------------------------------------
get       GET     /calendars/:calendarId/events/:eventId
list      GET     /calendars/:calendarId/events
insert    POST    /calendars/:calendarId/events
delete    DELETE  /calendars/:calendarId/events/:eventId
quickAdd  POST    /calendars/:calendarId/events/quickAdd
update    PUT     /calendars/:calendarId/events/:eventId


21
22
23
# File 'lib/google/calendar/event.rb', line 21

def kind
  @kind
end

#organizerObject (readonly)

Returns the value of attribute organizer.



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

def organizer
  @organizer
end

#remindersObject (readonly)

Returns the value of attribute reminders.



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

def reminders
  @reminders
end

#sequenceObject (readonly)

Returns the value of attribute sequence.



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

def sequence
  @sequence
end

#startObject

Returns the value of attribute start.



23
24
25
# File 'lib/google/calendar/event.rb', line 23

def start
  @start
end

#statusObject (readonly)

API Reference

* https://developers.google.com/google-apps/calendar/v3/reference/#Events

Supported Google Calendar API (Events)

Method    VERB    PATH
--------  ------  --------------------------------------
get       GET     /calendars/:calendarId/events/:eventId
list      GET     /calendars/:calendarId/events
insert    POST    /calendars/:calendarId/events
delete    DELETE  /calendars/:calendarId/events/:eventId
quickAdd  POST    /calendars/:calendarId/events/quickAdd
update    PUT     /calendars/:calendarId/events/:eventId


21
22
23
# File 'lib/google/calendar/event.rb', line 21

def status
  @status
end

#summaryObject

Returns the value of attribute summary.



23
24
25
# File 'lib/google/calendar/event.rb', line 23

def summary
  @summary
end

#transparencyObject (readonly)

Returns the value of attribute transparency.



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

def transparency
  @transparency
end

#updatedObject (readonly)

API Reference

* https://developers.google.com/google-apps/calendar/v3/reference/#Events

Supported Google Calendar API (Events)

Method    VERB    PATH
--------  ------  --------------------------------------
get       GET     /calendars/:calendarId/events/:eventId
list      GET     /calendars/:calendarId/events
insert    POST    /calendars/:calendarId/events
delete    DELETE  /calendars/:calendarId/events/:eventId
quickAdd  POST    /calendars/:calendarId/events/quickAdd
update    PUT     /calendars/:calendarId/events/:eventId


21
22
23
# File 'lib/google/calendar/event.rb', line 21

def updated
  @updated
end

Class Method Details

.delete(id) ⇒ Object



70
71
72
# File 'lib/google/calendar/event.rb', line 70

def self.delete(id)
  self.new(id: id).fetch.delete
end

.get(id) ⇒ Object

API

get

GET /calendars/:calendarId/events/eventId


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

def self.get(id)
  self.new(id: id).fetch
end

.insert(options = {}) ⇒ Object



58
59
60
# File 'lib/google/calendar/event.rb', line 58

def self.insert(options={})
  self.new(options).insert
end

.list(st, et) ⇒ Object

API

list

GET /calendars/:calendarId/events


41
42
43
44
45
46
47
48
# File 'lib/google/calendar/event.rb', line 41

def self.list(st, et)
  params = { calendarId:   Calendar.id,
             orderBy:      'startTime',
             timeMax:      et.to_time.utc.iso8601,
             timeMin:      st.to_time.utc.iso8601,
             singleEvents: 'True' }
  request(Calendar.api.events.list, params)
end

.quickAdd(text) ⇒ Object

API

quickAdd

POST /calendars/:calendarId/events/quickAdd


76
77
78
79
# File 'lib/google/calendar/event.rb', line 76

def self.quickAdd(text)
  params = { calendarId: Calendar.id, text: text }
  request(Calendar.api.events.quick_add, params)
end

.this_monthObject



132
133
134
135
136
# File 'lib/google/calendar/event.rb', line 132

def self.this_month
  start_time = Date.today.beginning_of_month
  end_time   = Date.today.end_of_month
  list(start_time, end_time)
end

.this_weekObject



126
127
128
129
130
# File 'lib/google/calendar/event.rb', line 126

def self.this_week
  start_time = Date.today.beginning_of_week
  end_time   = Date.today.end_of_week
  list(start_time, end_time)
end

.this_yearObject



138
139
140
141
142
# File 'lib/google/calendar/event.rb', line 138

def self.this_year
  start_time = Date.today.beginning_of_year
  end_time   = Date.today.end_of_year
  list(start_time, end_time)
end

.todayObject



108
109
110
111
112
# File 'lib/google/calendar/event.rb', line 108

def self.today
  start_time = Date.today
  end_time   = Date.tomorrow
  list(start_time, end_time)
end

.tomorrowObject



114
115
116
117
118
# File 'lib/google/calendar/event.rb', line 114

def self.tomorrow
  start_time = Date.tomorrow
  end_time   = Date.tomorrow.tomorrow
  list(start_time, end_time)
end

.yesterdayObject



120
121
122
123
124
# File 'lib/google/calendar/event.rb', line 120

def self.yesterday
  start_time = Date.yesterday
  end_time   = Date.today
  list(start_time, end_time)
end

Instance Method Details

#deleteObject

API

delete

DELETE /calendars/:calendarId/events/:eventId


64
65
66
67
68
# File 'lib/google/calendar/event.rb', line 64

def delete
  params  = { calendarId: Calendar.id, eventId: id }
  request(Calendar.api.events.delete, params)
  self
end

#fetchObject



34
35
36
37
# File 'lib/google/calendar/event.rb', line 34

def fetch
  params  = { calendarId: Calendar.id, eventId: id }
  request(Calendar.api.events.get, params)
end

#insertObject

API

insert

POST /calendars/:calendarId/events


52
53
54
55
56
# File 'lib/google/calendar/event.rb', line 52

def insert
  params = { calendarId: Calendar.id }
  body   = self.to_json
  request(Calendar.api.events.insert, params, body)
end

#num_of_daysObject



102
103
104
105
106
# File 'lib/google/calendar/event.rb', line 102

def num_of_days
  start_date = (self.start.date || self.start.dateTime).to_date
  end_date   = (self.end.date   || self.end.dateTime  ).to_date
  (end_date - start_date).to_i + 1
end

#to_hashObject



90
91
92
93
94
95
96
# File 'lib/google/calendar/event.rb', line 90

def to_hash
  self.instance_variables.inject(Hashie::Mash.new) do |hash, name|
    key = name.to_s.delete("@").to_sym
    hash[key] = self.instance_variable_get(name)
    hash
  end
end

#to_jsonObject



98
99
100
# File 'lib/google/calendar/event.rb', line 98

def to_json
  self.to_hash.to_json
end

#updateObject

API

update

PUT /calendars/:calendarId/events/:eventId


83
84
85
86
87
88
# File 'lib/google/calendar/event.rb', line 83

def update
  params = { calendarId: Calendar.id, eventId: id }
  body = self.to_json
  request(Calendar.api.events.update, params, body)
  self
end