Class: Google::Event
Overview
Public: API methods for a calendar events.
Instance Method Summary collapse
-
#delete(id) ⇒ Object
Public: Deletes a single event.
-
#get(id) ⇒ Object
Public: Gets a single event.
-
#insert(event) ⇒ Object
Public: Inserts a new single event.
-
#list ⇒ Object
Public: Gets a list of events for a specific calendar.
-
#nested_for(calendar_id) ⇒ Object
Public: Saves a calendar id for methods that require a calendar for the API methods.
-
#quick_add(text) ⇒ Object
Public: Inserts a new single event that is parsed from a line of text.
-
#update(id, event) ⇒ Object
Public: Updates a single event.
Methods inherited from Client
#http_delete, #http_get, #http_post, #http_put, #initialize
Constructor Details
This class inherits a constructor from Google::Client
Instance Method Details
#delete(id) ⇒ Object
Public: Deletes a single event.
id - The id of the event to delete.
Raises a Google::CalendarRequiredError if a calendar is not supplied (nested_for) was not called.
Returns the response from the delete operation.
92 93 94 95 |
# File 'lib/gcal_unit/event.rb', line 92 def delete(id) raise Google::CalendarRequiredError if @calendar_id.nil? http_delete "/calendars/#{@calendar_id}/events/#{id}" end |
#get(id) ⇒ Object
Public: Gets a single event.
id - The id of the event to retrieve.
Raises a Google::CalendarRequiredError if a calendar is not supplied (nested_for) was not called.
Returns a hash of metadata for an event.
35 36 37 38 39 |
# File 'lib/gcal_unit/event.rb', line 35 def get(id) raise Google::CalendarRequiredError if @calendar_id.nil? response = http_get "/calendars/#{@calendar_id}/events/#{id}" JSON.parse(response.body) end |
#insert(event) ⇒ Object
Public: Inserts a new single event.
event - A hash containing the data for an event to add.
Raises a Google::CalendarRequiredError if a calendar is not supplied (nested_for) was not called.
Returns a hash of metadata for the event that was added.
49 50 51 52 53 |
# File 'lib/gcal_unit/event.rb', line 49 def insert(event) raise Google::CalendarRequiredError if @calendar_id.nil? response = http_post "/calendars/#{@calendar_id}/events", :body => JSON.dump(event) JSON.parse(response.body) end |
#list ⇒ Object
Public: Gets a list of events for a specific calendar.
Raises a Google::CalendarRequiredError if a calendar is not supplied (nested_for) was not called.
Returns a hash of metadata for the calendars events.
21 22 23 24 25 |
# File 'lib/gcal_unit/event.rb', line 21 def list raise Google::CalendarRequiredError if @calendar_id.nil? response = http_get "/calendars/#{@calendar_id}/events" JSON.parse(response.body) end |
#nested_for(calendar_id) ⇒ Object
Public: Saves a calendar id for methods that require a calendar for the API methods.
calendar_id - Identifier for a specific calendar.
Returns the event object for chaining
10 11 12 13 |
# File 'lib/gcal_unit/event.rb', line 10 def nested_for(calendar_id) @calendar_id = calendar_id self end |
#quick_add(text) ⇒ Object
Public: Inserts a new single event that is parsed from a line of text.
text - A sentence that is parsed into a single event.
Raises a Google::CalendarRequiredError if a calendar is not supplied (nested_for) was not called.
Returns a hash of metadata for the event that was added.
63 64 65 66 67 |
# File 'lib/gcal_unit/event.rb', line 63 def quick_add(text) raise Google::CalendarRequiredError if @calendar_id.nil? response = http_post "/calendars/#{@calendar_id}/events/quickAdd", :query => { :text => text } JSON.parse(response.body) end |
#update(id, event) ⇒ Object
Public: Updates a single event.
id - The id of the event to update. event - A hash containing the data for the event to update.
Raises a Google::CalendarRequiredError if a calendar is not supplied (nested_for) was not called.
Returns a hash of metadata for the event that was updated.
78 79 80 81 82 |
# File 'lib/gcal_unit/event.rb', line 78 def update(id, event) raise Google::CalendarRequiredError if @calendar_id.nil? response = http_put "/calendars/#{@calendar_id}/events/#{id}", :body => JSON.dump(event) JSON.parse(response.body) end |