Class: Readiness::GoogleCalendar::Events

Inherits:
Client
  • Object
show all
Defined in:
lib/support_readiness/google_calendar/events.rb

Overview

Defines the class Events within the module Readiness::GoogleCalendar.

Author:

  • Jason Colyer

Since:

  • 1.0.12

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Client

auth_error, bad_request_error, convert_actions, convert_conditions, convert_standard_names_to_ids, convert_ticket_form_agent_conditions, convert_ticket_form_brands, convert_ticket_form_end_user_conditions, convert_ticket_form_names_to_ids, convert_view_names_to_ids, convert_view_restrictions, covert_ticket_form_field_ids, create_package!, erb_renderer, handle_request_error, not_found_error, not_processible_error, put_into_archive, recursively_deflate_directory, timestamp_filename, to_clean_json, to_clean_json_with_key, to_hash, to_nearly_clean_json, to_nearly_clean_json_with_key, to_param_string, write_entries

Constructor Details

#initialize(object = {}) ⇒ Events

Creates a new Readiness::GoogleCalendar::Events instance

Examples:

require 'support_readiness'
Readiness::GoogleCalendar::Events.new

Parameters:

Author:

  • Jason Colyer

Since:

  • 1.0.12



49
50
51
52
53
54
55
56
57
58
59
60
61
# File 'lib/support_readiness/google_calendar/events.rb', line 49

def initialize(object = {})
  @attachments = object['attachments']
  @attendees = object['attendees']
  @created = object['created']
  @creator = object['creator']
  @description = object['description']
  @end = object['end']
  @id = object['id']
  @location = object['location']
  @start = object['start']
  @summary = object['summary']
  @updated = object['updated']
end

Instance Attribute Details

#attachmentsObject

Since:

  • 1.0.12



14
15
16
# File 'lib/support_readiness/google_calendar/events.rb', line 14

def attachments
  @attachments
end

#attendeesObject

Since:

  • 1.0.12



14
15
16
# File 'lib/support_readiness/google_calendar/events.rb', line 14

def attendees
  @attendees
end

#createdObject

Since:

  • 1.0.12



14
15
16
# File 'lib/support_readiness/google_calendar/events.rb', line 14

def created
  @created
end

#creatorObject

Since:

  • 1.0.12



14
15
16
# File 'lib/support_readiness/google_calendar/events.rb', line 14

def creator
  @creator
end

#descriptionObject

Since:

  • 1.0.12



14
15
16
# File 'lib/support_readiness/google_calendar/events.rb', line 14

def description
  @description
end

#endObject

The time to use for the end of the event. When creating an event, you need to pass a Time/DateTime object for this.

Examples:

require 'support_readiness'
event = Readiness::GoogleCalendar::Events.new
event.end = Time.parse('2024-12-18 20:45')
require 'support_readiness'
event = Readiness::GoogleCalendar::Events.new
event.end = DateTime.now

Returns:

  • (Object)

    a Time or DateTime object

Since:

  • 1.0.12



38
39
40
# File 'lib/support_readiness/google_calendar/events.rb', line 38

def end
  @end
end

#idObject

Since:

  • 1.0.12



14
15
16
# File 'lib/support_readiness/google_calendar/events.rb', line 14

def id
  @id
end

#locationObject

Since:

  • 1.0.12



14
15
16
# File 'lib/support_readiness/google_calendar/events.rb', line 14

def location
  @location
end

#startObject

The time to use for the start of the event. When creating an event, you need to pass a Time/DateTime object for this.

Examples:

require 'support_readiness'
event = Readiness::GoogleCalendar::Events.new
event.start = Time.parse('2024-12-18 20:45')
require 'support_readiness'
event = Readiness::GoogleCalendar::Events.new
event.start = DateTime.now

Returns:

  • (Object)

    a Time or DateTime object

Since:

  • 1.0.12



26
27
28
# File 'lib/support_readiness/google_calendar/events.rb', line 26

def start
  @start
end

#summaryObject

Since:

  • 1.0.12



14
15
16
# File 'lib/support_readiness/google_calendar/events.rb', line 14

def summary
  @summary
end

#updatedObject

Since:

  • 1.0.12



14
15
16
# File 'lib/support_readiness/google_calendar/events.rb', line 14

def updated
  @updated
end

Class Method Details

.create!(client, event) ⇒ Object

Creates an event on a calendar

Examples:

config = Readiness::GoogleCalendar::Configuration.new
config.calendar_id = 'test@example.com'
config.filepath = 'temp.json'
client = Readiness::GoogleCalendar::Client.new(config)
event = Readiness::GoogleCalendar::Events.new
event.description = 'Test from Jason'
event.end = Time.parse('2024-10-04 11:00')
event.start = DateTime.parse('2024-10-04 10:00')
event.summary = 'Jason Test'
create = Readiness::GoogleCalendar::Events.create!(client, event)
pp create.id
# => "um4es01mlbn6nqh3gn25phtlvk"

Parameters:

Returns:

  • (Object)

    An instance of Google::Apis::CalendarV3::Event

Author:

  • Jason Colyer

Since:

  • 1.0.12



123
124
125
126
# File 'lib/support_readiness/google_calendar/events.rb', line 123

def self.create!(client, event)
  google_event = to_google_event(event)
  client.service.insert_event(client.calendar_id, google_event)
end

.delete!(client, event) ⇒ Boolean

Deletes an event on a calendar

Examples:

config = Readiness::GoogleCalendar::Configuration.new
config.calendar_id = 'test@example.com'
config.filepath = 'temp.json'
client = Readiness::GoogleCalendar::Client.new(config)
event = Readiness::GoogleCalendar::Events.new
event.id = 'um4es01mlbn6nqh3gn25phtlvk'
delete = Readiness::GoogleCalendar::Events.delete!(client, event)
pp delete
# => true

Parameters:

Returns:

  • (Boolean)

Author:

  • Jason Colyer

Since:

  • 1.0.12



146
147
148
149
# File 'lib/support_readiness/google_calendar/events.rb', line 146

def self.delete!(client, event)
  client.service.delete_event(client.calendar_id, event.id)
  true
end

.list(client, start_time, end_time, max = 1000) ⇒ Array

Lists all events on a calendar within specified time range

Examples:

config = Readiness::GoogleCalendar::Configuration.new
config.calendar_id = 'test@example.com'
config.filepath = 'temp.json'
client = Readiness::GoogleCalendar::Client.new(config)
events = Readiness::GoogleCalendar::Events.list(client, DateTime.now, (DateTime.now + 5.hours))
pp events.count
# => 6

Parameters:

  • client (Object)

    An instance of Client

  • start_time (Object)

    A Time or DateTime object

  • end_time (Object)

    A Time or DateTime object

  • max (Integer) (defaults to: 1000)

    The max number of results per page

Returns:

  • (Array)

Author:

  • Jason Colyer

Since:

  • 1.0.12



81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
# File 'lib/support_readiness/google_calendar/events.rb', line 81

def self.list(client, start_time, end_time, max = 1000)
  items = []
  page_token = nil
  loop do
    response = client.service.list_events(
      client.calendar_id,
      max_results: max,
      single_events: true,
      order_by: 'startTime',
      page_token: page_token,
      time_min: start_time.rfc3339,
      time_max: end_time.rfc3339
    )
    items += response.items
    break if response.next_page_token.nil?

    page_token = response.next_page_token
  end
  items
end

.to_google_event(event) ⇒ Object

Converts an instance of Readiness::GoogleCalendar::Events to Google::Apis::CalendarV3::Event

Parameters:

Returns:

  • (Object)

    An instance of Google::Apis::CalendarV3::Event

Author:

  • Jason Colyer

Since:

  • 1.0.12



158
159
160
161
162
163
164
165
166
# File 'lib/support_readiness/google_calendar/events.rb', line 158

def self.to_google_event(event)
  Google::Apis::CalendarV3::Event.new(
    description: event.description,
    end: Google::Apis::CalendarV3::EventDateTime.new(date_time: event.end.rfc3339),
    location: event.location,
    start: Google::Apis::CalendarV3::EventDateTime.new(date_time: event.start.rfc3339),
    summary: event.summary
  )
end