Class: Googlecal::Base
- Inherits:
-
Object
- Object
- Googlecal::Base
- Defined in:
- lib/googlecal/base.rb
Overview
:title: Base
Constant Summary collapse
- OOB_URL =
TODO: not sure what this is for, needs documentation
'urn:ietf:wg:oauth:2.0:oob'
Instance Attribute Summary collapse
-
#credentials ⇒ Object
Returns the value of attribute credentials.
-
#default_calendar ⇒ Object
Returns the value of attribute default_calendar.
Class Method Summary collapse
Instance Method Summary collapse
- #create_event(calendar_id = 'primary', **opts) ⇒ Object
-
#delete_event(calendar_id = 'primary', event_id) ⇒ Object
Delete an even from a calendar by event id.
-
#get_event(calendar_id = 'primary', event_id) ⇒ Object
Get an event by event id.
-
#initialize(application_name, calendar_id = 'primary', authenticate_with_env = false, credentials_path = File.join(Dir.home, '.credentials',"calendar-ruby-quickstart.yaml"), client_secrets_path = 'client_secret.json', scope = Google::Apis::CalendarV3::AUTH_CALENDAR) ⇒ Base
constructor
Initialize a new googlecal instance and authenticate with google with file paths.
Constructor Details
#initialize(application_name, calendar_id = 'primary', authenticate_with_env = false, credentials_path = File.join(Dir.home, '.credentials',"calendar-ruby-quickstart.yaml"), client_secrets_path = 'client_secret.json', scope = Google::Apis::CalendarV3::AUTH_CALENDAR) ⇒ Base
Initialize a new googlecal instance and authenticate with google with file paths
Attributes
-
:application_name:
- Name of application in gooogle console that you need to setup -
:authenticate_with_env:
- Optionally authenticate with enviroment variables instead of client_secrets_path -
:credentials_path:
- The file path to loading credentials path -
:client_secrets_path:
- The file path to json file holding client secrets -
:scope:
-The access scope for the use of the google api session
20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 |
# File 'lib/googlecal/base.rb', line 20 def initialize(application_name, calendar_id = 'primary', authenticate_with_env = false, credentials_path = File.join(Dir.home, '.credentials',"calendar-ruby-quickstart.yaml"), client_secrets_path = 'client_secret.json', scope = Google::Apis::CalendarV3::AUTH_CALENDAR) # authenticate with google if authenticate_with_env # set credentials @credentials = (scope) else # set credentials @credentials = (credentials_path, client_secrets_path, scope) end @@calendar_service = setup_calendar_service(application_name, @credentials) @@calendar_id = calendar_id end |
Instance Attribute Details
#credentials ⇒ Object
Returns the value of attribute credentials.
4 5 6 |
# File 'lib/googlecal/base.rb', line 4 def credentials @credentials end |
#default_calendar ⇒ Object
Returns the value of attribute default_calendar.
4 5 6 |
# File 'lib/googlecal/base.rb', line 4 def default_calendar @default_calendar end |
Class Method Details
.events(calendar_id = 'primary', opts = {}) ⇒ Object
38 39 40 41 |
# File 'lib/googlecal/base.rb', line 38 def self.events(calendar_id = 'primary', opts = {}) @@calendar_service.list_events(calendar_id, opts) end |
Instance Method Details
#create_event(calendar_id = 'primary', **opts) ⇒ Object
43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 |
# File 'lib/googlecal/base.rb', line 43 def create_event(calendar_id = 'primary', **opts) event = Google::Apis::CalendarV3::Event.new( summary: opts[:summary] || '', location: opts[:location] || '', start: { date_time: Time.now.iso8601, time_zone: 'America/Los_Angeles', }, end: { date_time: (Time.now + 10*60).iso8601, time_zone: 'America/Los_Angeles', } ) result = @@calendar_service.insert_event(calendar_id, event) return result end |
#delete_event(calendar_id = 'primary', event_id) ⇒ Object
Delete an even from a calendar by event id
Attributes
-
:calendar_id:
- Unique id of calendar -
:event_id:
- Unique id of event to be deleted
66 67 68 69 |
# File 'lib/googlecal/base.rb', line 66 def delete_event(calendar_id = 'primary', event_id) result = @@calendar_service.delete_event(calendar_id, event_id) return result end |
#get_event(calendar_id = 'primary', event_id) ⇒ Object
Get an event by event id
Attributes
-
:calendar_id:
- Unique id of calendar -
:event_id:
- Unique id of event
TODO: for some reason this part is not working with some of the tests i have tried with it
79 80 81 82 |
# File 'lib/googlecal/base.rb', line 79 def get_event(calendar_id = 'primary', event_id) result = @@calendar_service.get_event(calendar_id, event_id) return result end |