googlecal 0.1.0 → 0.1.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/.DS_Store +0 -0
- data/.gitignore +1 -1
- data/.travis.yml +4 -1
- data/README.md +5 -2
- data/bin/console +1 -0
- data/client_secret.json.enc +2 -0
- data/docs/Gemfile.html +98 -0
- data/docs/Gemfile_lock.html +187 -0
- data/docs/Googlecal.html +384 -0
- data/docs/Googlecal/Base.html +319 -0
- data/docs/Googlecal/GCalendar.html +265 -0
- data/docs/Googlecal/GEvent.html +418 -0
- data/docs/LICENSE.html +115 -0
- data/docs/Object.html +113 -0
- data/docs/README_md.html +161 -0
- data/docs/Rakefile.html +99 -0
- data/docs/bin/setup.html +99 -0
- data/docs/client_secret_json.html +96 -0
- data/docs/created.rid +19 -0
- data/docs/css/fonts.css +167 -0
- data/docs/css/rdoc.css +590 -0
- data/docs/fonts/Lato-Light.ttf +0 -0
- data/docs/fonts/Lato-LightItalic.ttf +0 -0
- data/docs/fonts/Lato-Regular.ttf +0 -0
- data/docs/fonts/Lato-RegularItalic.ttf +0 -0
- data/docs/fonts/SourceCodePro-Bold.ttf +0 -0
- data/docs/fonts/SourceCodePro-Regular.ttf +0 -0
- data/docs/googlecal_gemspec.html +126 -0
- data/docs/images/add.png +0 -0
- data/docs/images/arrow_up.png +0 -0
- data/docs/images/brick.png +0 -0
- data/docs/images/brick_link.png +0 -0
- data/docs/images/bug.png +0 -0
- data/docs/images/bullet_black.png +0 -0
- data/docs/images/bullet_toggle_minus.png +0 -0
- data/docs/images/bullet_toggle_plus.png +0 -0
- data/docs/images/date.png +0 -0
- data/docs/images/delete.png +0 -0
- data/docs/images/find.png +0 -0
- data/docs/images/loadingAnimation.gif +0 -0
- data/docs/images/macFFBgHack.png +0 -0
- data/docs/images/package.png +0 -0
- data/docs/images/page_green.png +0 -0
- data/docs/images/page_white_text.png +0 -0
- data/docs/images/page_white_width.png +0 -0
- data/docs/images/plugin.png +0 -0
- data/docs/images/ruby.png +0 -0
- data/docs/images/tag_blue.png +0 -0
- data/docs/images/tag_green.png +0 -0
- data/docs/images/transparent.png +0 -0
- data/docs/images/wrench.png +0 -0
- data/docs/images/wrench_orange.png +0 -0
- data/docs/images/zoom.png +0 -0
- data/docs/index.html +111 -0
- data/docs/js/darkfish.js +161 -0
- data/docs/js/jquery.js +4 -0
- data/docs/js/navigation.js +142 -0
- data/docs/js/navigation.js.gz +0 -0
- data/docs/js/search.js +109 -0
- data/docs/js/search_index.js +1 -0
- data/docs/js/search_index.js.gz +0 -0
- data/docs/js/searcher.js +228 -0
- data/docs/js/searcher.js.gz +0 -0
- data/docs/table_of_contents.html +191 -0
- data/lib/googlecal.rb +2 -157
- data/lib/googlecal/base.rb +191 -0
- data/lib/googlecal/gcalendar.rb +27 -0
- data/lib/googlecal/gevent.rb +97 -0
- data/lib/googlecal/version.rb +1 -1
- metadata +63 -1
Binary file
|
@@ -0,0 +1,191 @@
|
|
1
|
+
<!DOCTYPE html>
|
2
|
+
|
3
|
+
<html>
|
4
|
+
<head>
|
5
|
+
<meta charset="UTF-8">
|
6
|
+
|
7
|
+
<title>Table of Contents - Googlecal</title>
|
8
|
+
|
9
|
+
<script type="text/javascript">
|
10
|
+
var rdoc_rel_prefix = "./";
|
11
|
+
</script>
|
12
|
+
|
13
|
+
<script src="./js/jquery.js"></script>
|
14
|
+
<script src="./js/darkfish.js"></script>
|
15
|
+
|
16
|
+
<link href="./css/fonts.css" rel="stylesheet">
|
17
|
+
<link href="./css/rdoc.css" rel="stylesheet">
|
18
|
+
|
19
|
+
|
20
|
+
|
21
|
+
<body id="top" class="table-of-contents">
|
22
|
+
<main role="main">
|
23
|
+
<h1 class="class">Table of Contents - Googlecal</h1>
|
24
|
+
|
25
|
+
<h2 id="pages">Pages</h2>
|
26
|
+
<ul>
|
27
|
+
<li class="file">
|
28
|
+
<a href="Gemfile.html">Gemfile</a>
|
29
|
+
</li>
|
30
|
+
<li class="file">
|
31
|
+
<a href="Gemfile_lock.html">Gemfile.lock</a>
|
32
|
+
</li>
|
33
|
+
<li class="file">
|
34
|
+
<a href="LICENSE.html">LICENSE</a>
|
35
|
+
</li>
|
36
|
+
<li class="file">
|
37
|
+
<a href="README_md.html">README</a>
|
38
|
+
|
39
|
+
<ul>
|
40
|
+
<li><a href="README_md.html#label-Googlecal">Googlecal</a>
|
41
|
+
<li><a href="README_md.html#label-This+project+is+in+Alpha-21-21-21">This project is in Alpha!!!</a>
|
42
|
+
<li><a href="README_md.html#label-Testing+Setup">Testing Setup</a>
|
43
|
+
<li><a href="README_md.html#label-Generating+Documentation">Generating Documentation</a>
|
44
|
+
</ul>
|
45
|
+
</li>
|
46
|
+
<li class="file">
|
47
|
+
<a href="Rakefile.html">Rakefile</a>
|
48
|
+
</li>
|
49
|
+
<li class="file">
|
50
|
+
<a href="bin/setup.html">setup</a>
|
51
|
+
</li>
|
52
|
+
<li class="file">
|
53
|
+
<a href="client_secret_json.html">client_secret.json</a>
|
54
|
+
</li>
|
55
|
+
<li class="file">
|
56
|
+
<a href="googlecal_gemspec.html">googlecal.gemspec</a>
|
57
|
+
</li>
|
58
|
+
|
59
|
+
</ul>
|
60
|
+
|
61
|
+
<h2 id="classes">Classes and Modules</h2>
|
62
|
+
<ul>
|
63
|
+
<li class="module">
|
64
|
+
<a href="Googlecal.html">Googlecal</a>
|
65
|
+
</li>
|
66
|
+
<li class="class">
|
67
|
+
<a href="Googlecal/Base.html">Googlecal::Base</a>
|
68
|
+
</li>
|
69
|
+
<li class="class">
|
70
|
+
<a href="Googlecal/GCalendar.html">Googlecal::GCalendar</a>
|
71
|
+
</li>
|
72
|
+
<li class="class">
|
73
|
+
<a href="Googlecal/GEvent.html">Googlecal::GEvent</a>
|
74
|
+
</li>
|
75
|
+
<li class="class">
|
76
|
+
<a href="Object.html">Object</a>
|
77
|
+
</li>
|
78
|
+
</ul>
|
79
|
+
|
80
|
+
<h2 id="methods">Methods</h2>
|
81
|
+
<ul>
|
82
|
+
|
83
|
+
<li class="method">
|
84
|
+
<a href="Googlecal.html#method-c-create">::create</a>
|
85
|
+
—
|
86
|
+
<span class="container">Googlecal</span>
|
87
|
+
|
88
|
+
<li class="method">
|
89
|
+
<a href="Googlecal.html#method-c-find">::find</a>
|
90
|
+
—
|
91
|
+
<span class="container">Googlecal</span>
|
92
|
+
|
93
|
+
<li class="method">
|
94
|
+
<a href="Googlecal/GCalendar.html#method-c-find">::find</a>
|
95
|
+
—
|
96
|
+
<span class="container">Googlecal::GCalendar</span>
|
97
|
+
|
98
|
+
<li class="method">
|
99
|
+
<a href="Googlecal/Base.html#method-c-new">::new</a>
|
100
|
+
—
|
101
|
+
<span class="container">Googlecal::Base</span>
|
102
|
+
|
103
|
+
<li class="method">
|
104
|
+
<a href="Googlecal/GCalendar.html#method-c-new">::new</a>
|
105
|
+
—
|
106
|
+
<span class="container">Googlecal::GCalendar</span>
|
107
|
+
|
108
|
+
<li class="method">
|
109
|
+
<a href="Googlecal/GEvent.html#method-c-new">::new</a>
|
110
|
+
—
|
111
|
+
<span class="container">Googlecal::GEvent</span>
|
112
|
+
|
113
|
+
<li class="method">
|
114
|
+
<a href="Googlecal/Base.html#method-i-create_event">#create_event</a>
|
115
|
+
—
|
116
|
+
<span class="container">Googlecal::Base</span>
|
117
|
+
|
118
|
+
<li class="method">
|
119
|
+
<a href="Googlecal/GCalendar.html#method-i-delete">#delete</a>
|
120
|
+
—
|
121
|
+
<span class="container">Googlecal::GCalendar</span>
|
122
|
+
|
123
|
+
<li class="method">
|
124
|
+
<a href="Googlecal.html#method-i-delete">#delete</a>
|
125
|
+
—
|
126
|
+
<span class="container">Googlecal</span>
|
127
|
+
|
128
|
+
<li class="method">
|
129
|
+
<a href="Googlecal.html#method-i-delete_event">#delete_event</a>
|
130
|
+
—
|
131
|
+
<span class="container">Googlecal</span>
|
132
|
+
|
133
|
+
<li class="method">
|
134
|
+
<a href="Googlecal/GEvent.html#method-i-end_time-3D">#end_time=</a>
|
135
|
+
—
|
136
|
+
<span class="container">Googlecal::GEvent</span>
|
137
|
+
|
138
|
+
<li class="method">
|
139
|
+
<a href="Googlecal/Base.html#method-i-events">#events</a>
|
140
|
+
—
|
141
|
+
<span class="container">Googlecal::Base</span>
|
142
|
+
|
143
|
+
<li class="method">
|
144
|
+
<a href="Googlecal.html#method-i-get_event">#get_event</a>
|
145
|
+
—
|
146
|
+
<span class="container">Googlecal</span>
|
147
|
+
|
148
|
+
<li class="method">
|
149
|
+
<a href="Googlecal/GEvent.html#method-i-id">#id</a>
|
150
|
+
—
|
151
|
+
<span class="container">Googlecal::GEvent</span>
|
152
|
+
|
153
|
+
<li class="method">
|
154
|
+
<a href="Googlecal/GEvent.html#method-i-save">#save</a>
|
155
|
+
—
|
156
|
+
<span class="container">Googlecal::GEvent</span>
|
157
|
+
|
158
|
+
<li class="method">
|
159
|
+
<a href="Googlecal/GEvent.html#method-i-start_time-3D">#start_time=</a>
|
160
|
+
—
|
161
|
+
<span class="container">Googlecal::GEvent</span>
|
162
|
+
|
163
|
+
<li class="method">
|
164
|
+
<a href="Googlecal/GEvent.html#method-i-status">#status</a>
|
165
|
+
—
|
166
|
+
<span class="container">Googlecal::GEvent</span>
|
167
|
+
|
168
|
+
<li class="method">
|
169
|
+
<a href="Googlecal/GEvent.html#method-i-summary-3D">#summary=</a>
|
170
|
+
—
|
171
|
+
<span class="container">Googlecal::GEvent</span>
|
172
|
+
|
173
|
+
<li class="method">
|
174
|
+
<a href="Googlecal.html#method-i-update">#update</a>
|
175
|
+
—
|
176
|
+
<span class="container">Googlecal</span>
|
177
|
+
|
178
|
+
<li class="method">
|
179
|
+
<a href="Googlecal/GCalendar.html#method-i-update">#update</a>
|
180
|
+
—
|
181
|
+
<span class="container">Googlecal::GCalendar</span>
|
182
|
+
</ul>
|
183
|
+
</main>
|
184
|
+
|
185
|
+
|
186
|
+
<footer id="validator-badges" role="contentinfo">
|
187
|
+
<p><a href="http://validator.w3.org/check/referer">Validate</a>
|
188
|
+
<p>Generated by <a href="http://docs.seattlerb.org/rdoc/">RDoc</a> 4.3.0.
|
189
|
+
<p>Based on <a href="http://deveiate.org/projects/Darkfish-RDoc/">Darkfish</a> by <a href="http://deveiate.org">Michael Granger</a>.
|
190
|
+
</footer>
|
191
|
+
|
data/lib/googlecal.rb
CHANGED
@@ -3,164 +3,9 @@ require "googlecal/version"
|
|
3
3
|
require 'google/apis/calendar_v3'
|
4
4
|
require 'googleauth'
|
5
5
|
require 'googleauth/stores/file_token_store'
|
6
|
+
require 'googlecal/base'
|
7
|
+
require 'googlecal/gevent'
|
6
8
|
|
7
9
|
# :title: Googlecal
|
8
10
|
module Googlecal
|
9
|
-
# :title: Base
|
10
|
-
class Base
|
11
|
-
attr_accessor :credentials, :default_calendar
|
12
|
-
|
13
|
-
# TODO: not sure what this is for, needs documentation
|
14
|
-
OOB_URL = 'urn:ietf:wg:oauth:2.0:oob'
|
15
|
-
|
16
|
-
# Initialize a new googlecal instance and authenticate with google with file paths
|
17
|
-
#
|
18
|
-
# ==== Attributes
|
19
|
-
#
|
20
|
-
# * +:application_name:+ - Name of application in gooogle console that you need to setup
|
21
|
-
# * +:authenticate_with_env:+ - Optionally authenticate with enviroment variables instead of client_secrets_path
|
22
|
-
# * +:credentials_path:+ - The file path to loading credentials path
|
23
|
-
# * +:client_secrets_path:+ - The file path to json file holding client secrets
|
24
|
-
# * +:scope:+ -The access scope for the use of the google api session
|
25
|
-
def initialize(application_name,
|
26
|
-
authenticate_with_env = false,
|
27
|
-
credentials_path = File.join(Dir.home, '.credentials',"calendar-ruby-quickstart.yaml"),
|
28
|
-
client_secrets_path = 'client_secret.json',
|
29
|
-
scope = Google::Apis::CalendarV3::AUTH_CALENDAR)
|
30
|
-
# authenticate with google
|
31
|
-
if authenticate_with_env
|
32
|
-
# set credentials
|
33
|
-
@credentials = authorize_with_env(scope)
|
34
|
-
else
|
35
|
-
# set credentials
|
36
|
-
@credentials = authorize(credentials_path, client_secrets_path, scope)
|
37
|
-
end
|
38
|
-
@calendar_service = setup_calendar_service(application_name, @credentials)
|
39
|
-
end
|
40
|
-
|
41
|
-
def events(calendar_id = 'primary', **opts)
|
42
|
-
@calendar_service.list_events(calendar_id,
|
43
|
-
max_results: 10)
|
44
|
-
end
|
45
|
-
|
46
|
-
def create_event(calendar_id = 'primary', **opts)
|
47
|
-
event = Google::Apis::CalendarV3::Event.new(
|
48
|
-
summary: opts[:summary] || '',
|
49
|
-
location: opts[:location] || '',
|
50
|
-
start: {
|
51
|
-
date_time: Time.now.iso8601,
|
52
|
-
time_zone: 'America/Los_Angeles',
|
53
|
-
},
|
54
|
-
end: {
|
55
|
-
date_time: (Time.now + 10*60).iso8601,
|
56
|
-
time_zone: 'America/Los_Angeles',
|
57
|
-
}
|
58
|
-
)
|
59
|
-
result = @calendar_service.insert_event(calendar_id, event)
|
60
|
-
return result
|
61
|
-
end
|
62
|
-
|
63
|
-
# Delete an even from a calendar by event id
|
64
|
-
#
|
65
|
-
# ==== Attributes
|
66
|
-
#
|
67
|
-
# * +:calendar_id:+ - Unique id of calendar
|
68
|
-
# * +:event_id:+ - Unique id of event to be deleted
|
69
|
-
def delete_event(calendar_id = 'primary', event_id)
|
70
|
-
result = @calendar_service.delete_event(calendar_id, event_id)
|
71
|
-
return result
|
72
|
-
end
|
73
|
-
|
74
|
-
# Get an event by event id
|
75
|
-
#
|
76
|
-
# ==== Attributes
|
77
|
-
#
|
78
|
-
# * +:calendar_id:+ - Unique id of calendar
|
79
|
-
# * +:event_id:+ - Unique id of event
|
80
|
-
# TODO: for some reason this part is not working with some of the tests i have tried
|
81
|
-
# with it
|
82
|
-
def get_event(calendar_id = 'primary', event_id)
|
83
|
-
result = @calendar_service.get_acl(calendar_id, event_id)
|
84
|
-
return result
|
85
|
-
end
|
86
|
-
|
87
|
-
private
|
88
|
-
|
89
|
-
# Authenticate with google with file paths and a scope
|
90
|
-
#
|
91
|
-
# ==== Attributes
|
92
|
-
#
|
93
|
-
# * +:credentials_path:+ - The file path to loading credentials path
|
94
|
-
# * +:client_secrets_path:+ - The file path to json file holding client secrets
|
95
|
-
# * +:scope:+ - The access scope for the use of the google api session
|
96
|
-
def authorize(credentials_path, client_secrets_path, scope)
|
97
|
-
FileUtils.mkdir_p(File.dirname(credentials_path))
|
98
|
-
client_id = Google::Auth::ClientId.from_file(client_secrets_path)
|
99
|
-
token_store = Google::Auth::Stores::FileTokenStore.new(file: credentials_path)
|
100
|
-
authorizer = Google::Auth::UserAuthorizer.new(client_id, scope, token_store)
|
101
|
-
user_id = 'default'
|
102
|
-
credentials = authorizer.get_credentials(user_id)
|
103
|
-
# check if loaded credentials exist
|
104
|
-
if credentials.nil?
|
105
|
-
url = authorizer.get_authorization_url(base_url: OOB_URL)
|
106
|
-
# user must verify application
|
107
|
-
puts "Open the following url in the browser"
|
108
|
-
puts url
|
109
|
-
code = gets
|
110
|
-
credentials = authorizer.get_and_store_credentials_from_code(
|
111
|
-
user_id: user_id,
|
112
|
-
code: code,
|
113
|
-
base_url: OOB_URL
|
114
|
-
)
|
115
|
-
end
|
116
|
-
# return the produced credentials
|
117
|
-
return credentials
|
118
|
-
end
|
119
|
-
|
120
|
-
# Authenticate with enviroment variables
|
121
|
-
#
|
122
|
-
# ==== Attributes
|
123
|
-
#
|
124
|
-
# * +:credentials_path:+ - The file path to store the credentials
|
125
|
-
# * +:scope:+ - The access scope for the use of the google api session
|
126
|
-
def authorize_with_env(scope)
|
127
|
-
FileUtils.mkdir_p(File.dirname(ENV['GCAL_TOKEN_STORE_PATH']))
|
128
|
-
# get values for env varibales
|
129
|
-
client_id = Google::Auth::ClientId.new(ENV['GCAL_CLIENT_ID'], ENV['GCAL_CLIENT_SECRET'])
|
130
|
-
# setup token store for the file
|
131
|
-
token_store = Google::Auth::Stores::FileTokenStore.new(file: ENV['GCAL_TOKEN_STORE_PATH'])
|
132
|
-
authorizer = Google::Auth::UserAuthorizer.new(client_id, scope, token_store)
|
133
|
-
user_id = 'default'
|
134
|
-
credentials = authorizer.get_credentials(user_id)
|
135
|
-
# check if loaded credentials exist
|
136
|
-
if credentials.nil?
|
137
|
-
url = authorizer.get_authorization_url(base_url: OOB_URL)
|
138
|
-
# user must verify application
|
139
|
-
puts "Open the following url in the browser"
|
140
|
-
puts url
|
141
|
-
code = gets
|
142
|
-
credentials = authorizer.get_and_store_credentials_from_code(
|
143
|
-
user_id: user_id,
|
144
|
-
code: code,
|
145
|
-
base_url: OOB_URL
|
146
|
-
)
|
147
|
-
end
|
148
|
-
# return the produced credentials
|
149
|
-
return credentials
|
150
|
-
end
|
151
|
-
|
152
|
-
# Setup calendar service for a session
|
153
|
-
#
|
154
|
-
# ==== Attributes
|
155
|
-
#
|
156
|
-
# * +:application_name:+ - Name of application setup in google console
|
157
|
-
# * +:credentials:+ - User authentication credentials
|
158
|
-
def setup_calendar_service(application_name, credentials)
|
159
|
-
service = Google::Apis::CalendarV3::CalendarService.new
|
160
|
-
service.client_options.application_name = application_name
|
161
|
-
service.authorization = credentials
|
162
|
-
# return service once it is setup
|
163
|
-
return service
|
164
|
-
end
|
165
|
-
end
|
166
11
|
end
|
@@ -0,0 +1,191 @@
|
|
1
|
+
module Googlecal
|
2
|
+
# :title: Base
|
3
|
+
class Base
|
4
|
+
attr_accessor :credentials, :default_calendar
|
5
|
+
# static instance
|
6
|
+
# - GoogleCalendar Service service
|
7
|
+
|
8
|
+
# TODO: not sure what this is for, needs documentation
|
9
|
+
OOB_URL = 'urn:ietf:wg:oauth:2.0:oob'
|
10
|
+
|
11
|
+
# Initialize a new googlecal instance and authenticate with google with file paths
|
12
|
+
#
|
13
|
+
# ==== Attributes
|
14
|
+
#
|
15
|
+
# * +:application_name:+ - Name of application in gooogle console that you need to setup
|
16
|
+
# * +:authenticate_with_env:+ - Optionally authenticate with enviroment variables instead of client_secrets_path
|
17
|
+
# * +:credentials_path:+ - The file path to loading credentials path
|
18
|
+
# * +:client_secrets_path:+ - The file path to json file holding client secrets
|
19
|
+
# * +:scope:+ -The access scope for the use of the google api session
|
20
|
+
def initialize(application_name,
|
21
|
+
calendar_id = 'primary',
|
22
|
+
authenticate_with_env = false,
|
23
|
+
credentials_path = File.join(Dir.home, '.credentials',"calendar-ruby-quickstart.yaml"),
|
24
|
+
client_secrets_path = 'client_secret.json',
|
25
|
+
scope = Google::Apis::CalendarV3::AUTH_CALENDAR)
|
26
|
+
# authenticate with google
|
27
|
+
if authenticate_with_env
|
28
|
+
# set credentials
|
29
|
+
@credentials = authorize_with_env(scope)
|
30
|
+
else
|
31
|
+
# set credentials
|
32
|
+
@credentials = authorize(credentials_path, client_secrets_path, scope)
|
33
|
+
end
|
34
|
+
@@calendar_service = setup_calendar_service(application_name, @credentials)
|
35
|
+
@@calendar_id = calendar_id
|
36
|
+
end
|
37
|
+
|
38
|
+
def events(calendar_id = 'primary', **opts)
|
39
|
+
@@calendar_service.list_events(calendar_id,
|
40
|
+
max_results: 10)
|
41
|
+
end
|
42
|
+
|
43
|
+
def create_event(calendar_id = 'primary', **opts)
|
44
|
+
event = Google::Apis::CalendarV3::Event.new(
|
45
|
+
summary: opts[:summary] || '',
|
46
|
+
location: opts[:location] || '',
|
47
|
+
start: {
|
48
|
+
date_time: Time.now.iso8601,
|
49
|
+
time_zone: 'America/Los_Angeles',
|
50
|
+
},
|
51
|
+
end: {
|
52
|
+
date_time: (Time.now + 10*60).iso8601,
|
53
|
+
time_zone: 'America/Los_Angeles',
|
54
|
+
}
|
55
|
+
)
|
56
|
+
result = @@calendar_service.insert_event(calendar_id, event)
|
57
|
+
return result
|
58
|
+
end
|
59
|
+
|
60
|
+
# Delete an even from a calendar by event id
|
61
|
+
#
|
62
|
+
# ==== Attributes
|
63
|
+
#
|
64
|
+
# * +:calendar_id:+ - Unique id of calendar
|
65
|
+
# * +:event_id:+ - Unique id of event to be deleted
|
66
|
+
def delete_event(calendar_id = 'primary', event_id)
|
67
|
+
result = @@calendar_service.delete_event(calendar_id, event_id)
|
68
|
+
return result
|
69
|
+
end
|
70
|
+
|
71
|
+
# Get an event by event id
|
72
|
+
#
|
73
|
+
# ==== Attributes
|
74
|
+
#
|
75
|
+
# * +:calendar_id:+ - Unique id of calendar
|
76
|
+
# * +:event_id:+ - Unique id of event
|
77
|
+
# TODO: for some reason this part is not working with some of the tests i have tried
|
78
|
+
# with it
|
79
|
+
def get_event(calendar_id = 'primary', event_id)
|
80
|
+
result = @@calendar_service.get_event(calendar_id, event_id)
|
81
|
+
return result
|
82
|
+
end
|
83
|
+
|
84
|
+
private
|
85
|
+
|
86
|
+
# Authenticate with google with file paths and a scope
|
87
|
+
#
|
88
|
+
# ==== Attributes
|
89
|
+
#
|
90
|
+
# * +:credentials_path:+ - The file path to loading credentials path
|
91
|
+
# * +:client_secrets_path:+ - The file path to json file holding client secrets
|
92
|
+
# * +:scope:+ - The access scope for the use of the google api session
|
93
|
+
def authorize(credentials_path, client_secrets_path, scope)
|
94
|
+
FileUtils.mkdir_p(File.dirname(credentials_path))
|
95
|
+
client_id = Google::Auth::ClientId.from_file(client_secrets_path)
|
96
|
+
token_store = Google::Auth::Stores::FileTokenStore.new(file: credentials_path)
|
97
|
+
authorizer = Google::Auth::UserAuthorizer.new(client_id, scope, token_store)
|
98
|
+
user_id = 'default'
|
99
|
+
credentials = authorizer.get_credentials(user_id)
|
100
|
+
# check if loaded credentials exist
|
101
|
+
if credentials.nil?
|
102
|
+
url = authorizer.get_authorization_url(base_url: OOB_URL)
|
103
|
+
# user must verify application
|
104
|
+
puts "Open the following url in the browser"
|
105
|
+
puts url
|
106
|
+
code = nil
|
107
|
+
if ENV['GOOGLE_CLIENT_SECRETE_TOKEN']
|
108
|
+
code = ENV['GOOGLE_CLIENT_SECRETE_TOKEN']
|
109
|
+
credentials = authorizer.get_and_store_credentials_from_code(
|
110
|
+
user_id: user_id,
|
111
|
+
code: code,
|
112
|
+
base_url: OOB_URL
|
113
|
+
)
|
114
|
+
return credentials
|
115
|
+
else
|
116
|
+
code = gets
|
117
|
+
credentials = authorizer.get_and_store_credentials_from_code(
|
118
|
+
user_id: user_id,
|
119
|
+
code: code,
|
120
|
+
base_url: OOB_URL
|
121
|
+
)
|
122
|
+
return credentials
|
123
|
+
end
|
124
|
+
end
|
125
|
+
# return the produced credentials
|
126
|
+
return credentials
|
127
|
+
end
|
128
|
+
|
129
|
+
# Authenticate with enviroment variables
|
130
|
+
#
|
131
|
+
# ==== Attributes
|
132
|
+
#
|
133
|
+
# * +:credentials_path:+ - The file path to store the credentials
|
134
|
+
# * +:scope:+ - The access scope for the use of the google api session
|
135
|
+
def authorize_with_env(scope)
|
136
|
+
FileUtils.mkdir_p(File.dirname(ENV['GCAL_TOKEN_STORE_PATH']))
|
137
|
+
# get values for env varibales
|
138
|
+
client_id = Google::Auth::ClientId.new(ENV['GCAL_CLIENT_ID'], ENV['GCAL_CLIENT_SECRET'])
|
139
|
+
# setup token store for the file
|
140
|
+
token_store = Google::Auth::Stores::FileTokenStore.new(file: ENV['GCAL_TOKEN_STORE_PATH'])
|
141
|
+
authorizer = Google::Auth::UserAuthorizer.new(client_id, scope, token_store)
|
142
|
+
user_id = 'default'
|
143
|
+
credentials = authorizer.get_credentials(user_id)
|
144
|
+
# check if loaded credentials exist
|
145
|
+
if credentials.nil?
|
146
|
+
url = authorizer.get_authorization_url(base_url: OOB_URL)
|
147
|
+
# user must verify application
|
148
|
+
puts "Open the following url in the browser"
|
149
|
+
puts url
|
150
|
+
code = gets
|
151
|
+
credentials = authorizer.get_and_store_credentials_from_code(
|
152
|
+
user_id: user_id,
|
153
|
+
code: code,
|
154
|
+
base_url: OOB_URL
|
155
|
+
)
|
156
|
+
end
|
157
|
+
# return the produced credentials
|
158
|
+
return credentials
|
159
|
+
end
|
160
|
+
|
161
|
+
# Setup calendar service for a session
|
162
|
+
#
|
163
|
+
# ==== Attributes
|
164
|
+
#
|
165
|
+
# * +:application_name:+ - Name of application setup in google console
|
166
|
+
# * +:credentials:+ - User authentication credentials
|
167
|
+
def setup_calendar_service(application_name, credentials)
|
168
|
+
service = Google::Apis::CalendarV3::CalendarService.new
|
169
|
+
service.client_options.application_name = application_name
|
170
|
+
service.authorization = credentials
|
171
|
+
# return service once it is setup
|
172
|
+
return service
|
173
|
+
end
|
174
|
+
|
175
|
+
# controlled access to the initialized google calendar service provider
|
176
|
+
def self.service
|
177
|
+
# check if CalendarService has been initialized and setup
|
178
|
+
if @@calendar_service.nil?
|
179
|
+
puts 'Googlecal service has not been initialize, please initialize Googlecal::Base
|
180
|
+
in order to use google calendar service'
|
181
|
+
return nil
|
182
|
+
else
|
183
|
+
return @@calendar_service
|
184
|
+
end
|
185
|
+
end
|
186
|
+
|
187
|
+
def self.calendar_id
|
188
|
+
@@calendar_id
|
189
|
+
end
|
190
|
+
end
|
191
|
+
end
|