Class: Googlecal::GEvent

Inherits:
Base
  • Object
show all
Defined in:
lib/googlecal/gevent.rb

Constant Summary

Constants inherited from Base

Base::OOB_URL

Instance Attribute Summary collapse

Attributes inherited from Base

#credentials, #default_calendar

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Base

#create_event, #delete_event, events, #get_event

Constructor Details

#initialize(event = nil) ⇒ GEvent

initialize with a google event instance



10
11
12
# File 'lib/googlecal/gevent.rb', line 10

def initialize(event = nil)
  @event = event
end

Instance Attribute Details

#end_timeObject

Returns the value of attribute end_time.



4
5
6
# File 'lib/googlecal/gevent.rb', line 4

def end_time
  @end_time
end

#start_timeObject

Returns the value of attribute start_time.



4
5
6
# File 'lib/googlecal/gevent.rb', line 4

def start_time
  @start_time
end

#summaryObject

Returns the value of attribute summary.



4
5
6
# File 'lib/googlecal/gevent.rb', line 4

def summary
  @summary
end

Class Method Details

.create(event_params, calendar_id = Base.calendar_id) ⇒ Object

create and save a new event through googles api



52
53
54
55
56
57
58
59
60
# File 'lib/googlecal/gevent.rb', line 52

def self.create(event_params, calendar_id = Base.calendar_id)
  # event creation
  event = service.insert_event(calendar_id, Google::Apis::CalendarV3::Event.new(event_params))
  if event
    return GEvent.new(event)
  else
    return false
  end
end

.find(event_id, calendar_id = Base.calendar_id) ⇒ Object

find google calendar event by event_id :event_id: - Unique event id given by google cal api



80
81
82
83
84
85
86
87
88
# File 'lib/googlecal/gevent.rb', line 80

def self.find(event_id, calendar_id = Base.calendar_id)
  # find by google event id
  begin
    event = service.get_event(calendar_id, event_id)
    return event
  catch e
    return nil
  end
end

.search(query, calendar_id = Base.calendar_id) ⇒ Object



90
91
92
93
94
95
96
97
# File 'lib/googlecal/gevent.rb', line 90

def self.search(query, calendar_id = Base.calendar_id)
  begin
    events = service.list_events(calendar_id, q: query)
    return events
    catch e
    return nil
  end
end

Instance Method Details

#delete(calendar_id = Base.calendar_id) ⇒ Object

delete event by event.id in googles api DELETES EVENT



64
65
66
67
68
69
# File 'lib/googlecal/gevent.rb', line 64

def delete(calendar_id = Base.calendar_id)
  # delete instance of event
  # update event instance
  @event = service.delete_event(calendar_id, id)
  return true
end

#idObject



14
15
16
# File 'lib/googlecal/gevent.rb', line 14

def id
  @event.id
end

#saveObject



47
48
49
# File 'lib/googlecal/gevent.rb', line 47

def save
  update(start: { date_time: start_time }, end: { date_time: end_time })
end

#statusObject



43
44
45
# File 'lib/googlecal/gevent.rb', line 43

def status
  @event.status
end

#update(params, calendar_id = Base.calendar_id) ⇒ Object

update google calendar event by event.id



72
73
74
75
76
# File 'lib/googlecal/gevent.rb', line 72

def update(params, calendar_id = Base.calendar_id)
  # delta update
  # TODO: update calendar event
  service.update_event(calendar_id, id, @event)
end