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

use oauth2 lib and remove deferred dependency #14

Closed
wants to merge 16 commits into from
28 changes: 18 additions & 10 deletions org-gcal.el
Original file line number Diff line number Diff line change
Expand Up @@ -130,10 +130,15 @@ Predicate functions take an event, and if they return nil the

(defun rgc-cb (b cal skip-export)
(interactive)
(search-forward "\n\n")
(let ((json-object-type 'plist))
(org-gcal--sync cal (json-read) skip-export)))

(defun rgc-cb-sync (b cal skip-export)
(interactive)
(with-current-buffer b
(let ((json-object-type 'plist))
(org-gcal--sync cal (json-read) skip-export))))

;;;###autoload
(defun org-gcal-sync (&optional skip-export)
"Import events from calendars.
Expand All @@ -147,15 +152,18 @@ to non-nil to inhibit notifications."
(find-file-noselect (cdr i))
(org-gcal--archive-old-event))))
(dolist (cal org-gcal-file-alist)
(let ((b (oauth2-url-retrieve
(org-gcal-auth)
(format "%s?%s"
(format org-gcal-events-url (first cal))
(format "singleEvents=True&orderBy=startTime&timeMin=%s&timeMax=%s"
(org-gcal--subtract-time)
(org-gcal--add-time)))
'rgc-cb
(list cal skip-export)))))))
(make-thread (lambda ()
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Emacs 26.1 only ?

Just an idea, but how about carrying extra variables as
symbol-plist of calendar-id or something ?

Copy link
Owner Author

@kidd kidd Jul 25, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nah, the make-thread was just a crazy test. I guess this branch is turning into an 'experimental' branch. sorry for the confusion.

I don't fully get you on the plist for the calendar-id. What would it solve?

The remaining problem here is that:

  • oauth2.el doesn't refresh the token automatically if used asynchronously.
  • using synchronous requests works, but for multiple calendars it can become a little sluggish.
  • as an "extra" annoyance, oauth2 uses plstore, and it looks like you have to enter the passphrase to decrypt the data of the tokens way to often and way too many times. This gives a shitty experience also.

I've been looking at google-contacts.el, calfw.el, and other similar packages and all of them have hacks around those. I'll revert the thread thing, but not sure what's the next thing to try :(. Feel free to throw ideas in.

(let ((b (oauth2-url-retrieve-synchronously
(org-gcal-auth)
(format "%s?%s"
(format org-gcal-events-url (first cal))
(format "singleEvents=True&orderBy=startTime&timeMin=%s&timeMax=%s"
(org-gcal--subtract-time)
(org-gcal--add-time)))
;; 'rgc-cb
;; (list cal skip-export)
)))
(rgc-cb-sync b cal skip-export))))))

(defun org-gcal--sync (x data &optional skip-export)
"An X. Also data."
Expand Down