polyhoraire 1.1 → 1.2
Sign up to get free protection for your applications and to get access to all the features.
- data/Readme.rdoc +4 -2
- data/lib/google_exporter.rb +32 -39
- data/test/test_google_exporter.rb +1 -0
- metadata +8 -8
data/Readme.rdoc
CHANGED
data/lib/google_exporter.rb
CHANGED
@@ -3,40 +3,42 @@ require 'google/api_client'
|
|
3
3
|
require 'nokogiri'
|
4
4
|
require 'yaml'
|
5
5
|
require 'tzinfo'
|
6
|
-
require 'data_mapper'
|
7
6
|
|
8
7
|
require 'polyhoraire'
|
9
8
|
|
10
9
|
|
11
10
|
# Set up our token store
|
12
|
-
DataMapper.setup(:default, 'sqlite::memory:')
|
13
11
|
class TokenPair
|
14
|
-
include DataMapper::Resource
|
15
|
-
|
16
|
-
property :id, Serial
|
17
|
-
property :refresh_token, String, :length => 255
|
18
|
-
property :access_token, String, :length => 255
|
19
|
-
property :expires_in, Integer
|
20
|
-
property :issued_at, Integer
|
21
12
|
|
13
|
+
def initialize(hash)
|
14
|
+
if hash != nil
|
15
|
+
@access_token = hash[:access_token]
|
16
|
+
@expires_in = hash[:expires_in]
|
17
|
+
@issued_at = hash[:issued_at]
|
18
|
+
@refresh_token= hash[:refresh_token]
|
19
|
+
end
|
20
|
+
end
|
22
21
|
|
23
22
|
def update_token!(object)
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
23
|
+
@refresh_token = object.refresh_token
|
24
|
+
@access_token = object.access_token
|
25
|
+
@expires_in = object.expires_in
|
26
|
+
@issued_at = object.issued_at
|
27
|
+
end
|
28
|
+
|
29
|
+
def set?
|
30
|
+
@refresh_token != nil
|
28
31
|
end
|
29
32
|
|
30
33
|
def to_hash
|
31
34
|
return {
|
32
|
-
:refresh_token
|
33
|
-
:access_token
|
34
|
-
:expires_in
|
35
|
-
:issued_at
|
35
|
+
:refresh_token => @refresh_token,
|
36
|
+
:access_token => @access_token,
|
37
|
+
:expires_in => @expires_in,
|
38
|
+
:issued_at => Time.at(@issued_at)
|
36
39
|
}
|
37
40
|
end
|
38
41
|
end
|
39
|
-
TokenPair.auto_migrate!
|
40
42
|
|
41
43
|
|
42
44
|
class GoogleExporter
|
@@ -67,6 +69,7 @@ class GoogleExporter
|
|
67
69
|
courseBeginsOn += 7 if period.week == 2
|
68
70
|
event = {
|
69
71
|
'summary' => course.acronym + '(' + period.group + ') ' + (period.isLab ? '[Lab]' : '') ,
|
72
|
+
'description' => course.description ,
|
70
73
|
'location' => period.location,
|
71
74
|
'timeZone' => 'America/Montreal',
|
72
75
|
'start' => {
|
@@ -132,7 +135,7 @@ class GoogleExporter
|
|
132
135
|
end
|
133
136
|
|
134
137
|
# Returns access token
|
135
|
-
def authWeb(code,
|
138
|
+
def authWeb(code,callBackURI,tokenPair = nil)
|
136
139
|
oauth_yaml = YAML.load_file(Poly::userConfDir + '/google-api.yaml')
|
137
140
|
|
138
141
|
@client = Google::APIClient.new
|
@@ -142,10 +145,8 @@ class GoogleExporter
|
|
142
145
|
@client.authorization.redirect_uri = callBackURI
|
143
146
|
@client.authorization.code = code if code
|
144
147
|
|
145
|
-
if
|
146
|
-
|
147
|
-
token_pair = TokenPair.get(tokenID)
|
148
|
-
@client.authorization.update_token!(token_pair.to_hash)
|
148
|
+
if tokenPair.set?
|
149
|
+
@client.authorization.update_token!(tokenPair.to_hash)
|
149
150
|
end
|
150
151
|
|
151
152
|
if @client.authorization.refresh_token && @client.authorization.expired?
|
@@ -156,22 +157,7 @@ class GoogleExporter
|
|
156
157
|
|
157
158
|
return @client.authorization.access_token
|
158
159
|
end
|
159
|
-
|
160
|
-
# Returns the session token
|
161
|
-
def authWebCallback(tokenID)
|
162
|
-
@client.authorization.fetch_access_token!
|
163
|
-
# Persist the token here
|
164
|
-
token_pair = if tokenID
|
165
|
-
TokenPair.get(tokenID)
|
166
|
-
else
|
167
|
-
TokenPair.new
|
168
|
-
end
|
169
|
-
TokenPair.auto_migrate!
|
170
|
-
token_pair.update_token!(@client.authorization)
|
171
|
-
token_pair.save
|
172
|
-
|
173
|
-
return token_pair.id
|
174
|
-
end
|
160
|
+
|
175
161
|
|
176
162
|
def authURI
|
177
163
|
@client.authorization.authorization_uri.to_s
|
@@ -195,6 +181,13 @@ class GoogleExporter
|
|
195
181
|
@client = client
|
196
182
|
end
|
197
183
|
|
184
|
+
def newTokenPair
|
185
|
+
@client.authorization.fetch_access_token!
|
186
|
+
token = TokenPair.new(nil)
|
187
|
+
token.update_token!(@client.authorization)
|
188
|
+
return token
|
189
|
+
end
|
190
|
+
|
198
191
|
private
|
199
192
|
|
200
193
|
def dateTime(date, time)
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: polyhoraire
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: '1.
|
4
|
+
version: '1.2'
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,11 +9,11 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2012-
|
12
|
+
date: 2012-02-12 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: nokogiri
|
16
|
-
requirement: &
|
16
|
+
requirement: &19897620 !ruby/object:Gem::Requirement
|
17
17
|
none: false
|
18
18
|
requirements:
|
19
19
|
- - ! '>='
|
@@ -21,10 +21,10 @@ dependencies:
|
|
21
21
|
version: '0'
|
22
22
|
type: :runtime
|
23
23
|
prerelease: false
|
24
|
-
version_requirements: *
|
24
|
+
version_requirements: *19897620
|
25
25
|
- !ruby/object:Gem::Dependency
|
26
26
|
name: tzinfo
|
27
|
-
requirement: &
|
27
|
+
requirement: &19897180 !ruby/object:Gem::Requirement
|
28
28
|
none: false
|
29
29
|
requirements:
|
30
30
|
- - ! '>='
|
@@ -32,10 +32,10 @@ dependencies:
|
|
32
32
|
version: '0'
|
33
33
|
type: :runtime
|
34
34
|
prerelease: false
|
35
|
-
version_requirements: *
|
35
|
+
version_requirements: *19897180
|
36
36
|
- !ruby/object:Gem::Dependency
|
37
37
|
name: google-api-client
|
38
|
-
requirement: &
|
38
|
+
requirement: &19896760 !ruby/object:Gem::Requirement
|
39
39
|
none: false
|
40
40
|
requirements:
|
41
41
|
- - ! '>='
|
@@ -43,7 +43,7 @@ dependencies:
|
|
43
43
|
version: '0'
|
44
44
|
type: :runtime
|
45
45
|
prerelease: false
|
46
|
-
version_requirements: *
|
46
|
+
version_requirements: *19896760
|
47
47
|
description: Retrieve schedule from Polytechnique de Montreal and exports it to different
|
48
48
|
formats(only google calendar is suported at this time)
|
49
49
|
email: charles.briere@polymtl.ca
|