Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update connect.py #5

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 9 additions & 8 deletions connect.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
import httplib2
from oauth2client.file import Storage

from oauth2client.client import SignedJwtAssertionCredentials
from django.conf import settings

from apiclient.discovery import build

class Connection(object):
Expand All @@ -13,14 +12,16 @@ def get_service(self):
return self.service

else:
http = httplib2.Http()
storage = Storage(settings.GCALSYNC_CREDENTIALS)

credentials = storage.get()
if credentials is None or credentials.invalid == True:
credentials = SignedJwtAssertionCredentials(settings.GCALSYNC_CREDENTIALS_EMAIL, settings.GCALSYNC_CREDENTIALS_KEY, scope="https://www.googleapis.com/auth/calendar")
storage.put(credentials)
else:
credentials.refresh(http)

http = httplib2.Http()
http = credentials.authorize(http)

self.service = build(serviceName='calendar', version='v3', http=http,
developerKey=settings.GCALSYNC_APIKEY)

return self.service
self.service = build("calendar", "v3", http=http)
return self.service