Class: GoogleCalendar::Event
- Inherits:
-
Object
- Object
- GoogleCalendar::Event
- Extended by:
- Connection
- Defined in:
- lib/google_calendar_oauth2/event.rb
Instance Attribute Summary collapse
-
#calendar_id ⇒ Object
Returns the value of attribute calendar_id.
-
#created_at ⇒ Object
Returns the value of attribute created_at.
-
#end_time ⇒ Object
Returns the value of attribute end_time.
-
#etag ⇒ Object
Returns the value of attribute etag.
-
#html_link ⇒ Object
Returns the value of attribute html_link.
-
#id ⇒ Object
Returns the value of attribute id.
-
#sequence ⇒ Object
Returns the value of attribute sequence.
-
#start_time ⇒ Object
Returns the value of attribute start_time.
-
#status ⇒ Object
Returns the value of attribute status.
-
#summary ⇒ Object
Returns the value of attribute summary.
-
#updated_at ⇒ Object
Returns the value of attribute updated_at.
Class Method Summary collapse
- .create(calendar_id, attrs) ⇒ Object
- .delete(calendar_id, event_id) ⇒ Object
- .find_by_id(calendar_id, id) ⇒ Object
- .find_by_name(calendar_id, query) ⇒ Object
- .list(calendar_id) ⇒ Object
Instance Method Summary collapse
- #attributes ⇒ Object
-
#initialize(attrs) ⇒ Event
(also: #attributes=)
constructor
A new instance of Event.
- #to_s ⇒ Object
- #update(attrs = {}) ⇒ Object
Methods included from Connection
Constructor Details
#initialize(attrs) ⇒ Event Also known as: attributes=
Returns a new instance of Event.
7 8 9 10 11 12 13 14 15 16 17 18 19 |
# File 'lib/google_calendar_oauth2/event.rb', line 7 def initialize(attrs) @id = attrs['id'] @etag = attrs['etag'] @summary = attrs['summary'] @status = attrs['status'] @html_link = attrs['htmlLink'] @created_at = attrs['created'] @updated_at = attrs['updated'] @calendar_id = attrs['calendar_id'] @sequence = attrs['sequence'] @start_time = attrs['start']['dateTime'] @end_time = attrs['end']['dateTime'] end |
Instance Attribute Details
#calendar_id ⇒ Object
Returns the value of attribute calendar_id.
3 4 5 |
# File 'lib/google_calendar_oauth2/event.rb', line 3 def calendar_id @calendar_id end |
#created_at ⇒ Object
Returns the value of attribute created_at.
3 4 5 |
# File 'lib/google_calendar_oauth2/event.rb', line 3 def created_at @created_at end |
#end_time ⇒ Object
Returns the value of attribute end_time.
3 4 5 |
# File 'lib/google_calendar_oauth2/event.rb', line 3 def end_time @end_time end |
#etag ⇒ Object
Returns the value of attribute etag.
3 4 5 |
# File 'lib/google_calendar_oauth2/event.rb', line 3 def etag @etag end |
#html_link ⇒ Object
Returns the value of attribute html_link.
3 4 5 |
# File 'lib/google_calendar_oauth2/event.rb', line 3 def html_link @html_link end |
#id ⇒ Object
Returns the value of attribute id.
3 4 5 |
# File 'lib/google_calendar_oauth2/event.rb', line 3 def id @id end |
#sequence ⇒ Object
Returns the value of attribute sequence.
3 4 5 |
# File 'lib/google_calendar_oauth2/event.rb', line 3 def sequence @sequence end |
#start_time ⇒ Object
Returns the value of attribute start_time.
3 4 5 |
# File 'lib/google_calendar_oauth2/event.rb', line 3 def start_time @start_time end |
#status ⇒ Object
Returns the value of attribute status.
3 4 5 |
# File 'lib/google_calendar_oauth2/event.rb', line 3 def status @status end |
#summary ⇒ Object
Returns the value of attribute summary.
3 4 5 |
# File 'lib/google_calendar_oauth2/event.rb', line 3 def summary @summary end |
#updated_at ⇒ Object
Returns the value of attribute updated_at.
3 4 5 |
# File 'lib/google_calendar_oauth2/event.rb', line 3 def updated_at @updated_at end |
Class Method Details
.create(calendar_id, attrs) ⇒ Object
75 76 77 78 79 80 81 82 |
# File 'lib/google_calendar_oauth2/event.rb', line 75 def self.create(calendar_id, attrs) new connection.execute( api_method: client.events.insert, parameters: { 'calendarId' => calendar_id }, body: [JSON.dump(attrs)], headers: {'Content-Type' => 'application/json'} ).data.to_hash.merge 'calendar_id' => calendar_id end |
.delete(calendar_id, event_id) ⇒ Object
100 101 102 103 104 105 106 107 108 |
# File 'lib/google_calendar_oauth2/event.rb', line 100 def self.delete(calendar_id, event_id) connection.execute( api_method: client.events.delete, parameters: { 'calendarId' => calendar_id, 'eventId' => event_id } ) end |
.find_by_id(calendar_id, id) ⇒ Object
64 65 66 67 68 69 70 71 72 73 |
# File 'lib/google_calendar_oauth2/event.rb', line 64 def self.find_by_id(calendar_id, id) event = connection.execute( api_method: client.events.get, parameters: { 'calendarId' => calendar_id, 'eventId' => id } ) new event.data.to_hash.merge 'calendar_id' => calendar_id end |
.find_by_name(calendar_id, query) ⇒ Object
55 56 57 58 59 60 61 62 |
# File 'lib/google_calendar_oauth2/event.rb', line 55 def self.find_by_name(calendar_id, query) list(calendar_id).each do |event| if event.summary == query return @event = new(event.merge({ 'calendar_id' => calendar_id })) end end @event end |
.list(calendar_id) ⇒ Object
46 47 48 49 50 51 52 53 |
# File 'lib/google_calendar_oauth2/event.rb', line 46 def self.list(calendar_id) list = connection.execute(api_method: client.events.list, parameters: { 'calendarId' => calendar_id }) events = [] list.data.items.each do |event| events << new(event) end events end |
Instance Method Details
#attributes ⇒ Object
27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 |
# File 'lib/google_calendar_oauth2/event.rb', line 27 def attributes { id: id, etag: etag, status: status, html_link: html_link, created_at: created_at, updated_at: updated_at, calendar_id: calendar_id, sequence: sequence, start: { :dateTime => start_time }, end: { :dateTime => end_time } } end |
#to_s ⇒ Object
23 24 25 |
# File 'lib/google_calendar_oauth2/event.rb', line 23 def to_s "#<Event id: #{self.id}, start_time: #{self.start_time}, end_time: #{self.end_time}, calendar_id: #{self.calendar_id}, sequence: #{self.sequence}, etag: #{self.etag}, status: #{self.status}, html_link: #{self.html_link}, created_at: #{self.created_at}, updated_at: #{self.updated_at}>" end |
#update(attrs = {}) ⇒ Object
84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 |
# File 'lib/google_calendar_oauth2/event.rb', line 84 def update(attrs = {}) self.sequence = self.sequence.nil? ? 1 : self.sequence + 1 attrs = self.attributes.merge(attrs) result = Event.connection.execute( api_method: Event.client.events.update, parameters: { 'calendarId' => self.calendar_id, 'eventId' => self.id }, body: [JSON.dump(attrs)], headers: {'Content-Type' => 'application/json'} ).data.to_hash.merge('calendar_id' => self.calendar_id) self.attributes = result self end |