@@ -4,9 +4,8 @@ module PlaceCalendar
44 class Google < Interface
55 def initialize (
66 @file_path : String ,
7+ @scopes : String | Array (String ),
78 @domain : String ,
8- @calendar_scope : String = " https://www.googleapis.com/auth/calendar" ,
9- @directory_scope : String = " https://www.googleapis.com/auth/admin.directory.user.readonly" ,
109 @sub : String = " " ,
1110 @user_agent : String = " PlaceOS"
1211 )
@@ -17,20 +16,19 @@ module PlaceCalendar
1716 def initialize (
1817 @issuer : String ,
1918 @signing_key : String ,
19+ @scopes : String | Array (String ),
2020 @domain : String ,
21- @calendar_scope : String = " https://www.googleapis.com/auth/calendar" ,
22- @directory_scope : String = " https://www.googleapis.com/auth/admin.directory.user.readonly" ,
2321 @sub : String = " " ,
2422 @user_agent : String = " PlaceOS"
2523 )
2624 @file_path = " "
2725 end
2826
29- def auth (scope, sub = @sub ) : ::Google ::FileAuth | ::Google ::Auth
27+ def auth (sub = @sub ) : ::Google ::FileAuth | ::Google ::Auth
3028 if @file_path .empty?
31- ::Google ::Auth .new(issuer: @issuer , signing_key: @signing_key , scopes: scope , sub: sub, user_agent: @user_agent )
29+ ::Google ::Auth .new(issuer: @issuer , signing_key: @signing_key , scopes: @scopes , sub: sub, user_agent: @user_agent )
3230 else
33- ::Google ::FileAuth .new(file_path: @file_path , scopes: scope , sub: sub, user_agent: @user_agent )
31+ ::Google ::FileAuth .new(file_path: @file_path , scopes: @scopes , sub: sub, user_agent: @user_agent )
3432 end
3533 rescue ex : ::Google ::Exception
3634 handle_google_exception(ex)
@@ -128,19 +126,19 @@ module PlaceCalendar
128126 end
129127
130128 def directory : ::Google ::Directory
131- @directory ||= ::Google ::Directory .new(auth: auth( @directory_scope ) , domain: @domain )
129+ @directory ||= ::Google ::Directory .new(auth: auth, domain: @domain )
132130 end
133131
134132 def calendar (sub = @sub )
135- @calendar ||= ::Google ::Calendar .new(auth: auth(@calendar_scope , sub))
133+ @calendar ||= ::Google ::Calendar .new(auth: auth(sub))
136134 end
137135
138136 private def handle_google_exception (ex : ::Google ::Exception )
139137 raise PlaceCalendar ::Exception .new(ex.http_status, ex.http_body, ex.message)
140138 end
141139
142140 private def drive_files (sub = @sub )
143- @drive_files ||= ::Google ::Files .new(auth: auth(" https://www.googleapis.com/auth/drive.file " , sub))
141+ @drive_files ||= ::Google ::Files .new(auth: auth(sub))
144142 end
145143
146144 private def event_params (event , calendar_id )
0 commit comments