summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--exitter.el50
1 files changed, 37 insertions, 13 deletions
diff --git a/exitter.el b/exitter.el
index 3a06490..8dde97d 100644
--- a/exitter.el
+++ b/exitter.el
@@ -48,11 +48,16 @@
(defvar exitter-username nil)
(defvar exitter-password nil)
(defvar exitter-email nil)
+(defvar exitter-oauth-token nil)
+(defvar exitter-oauth-token-secret nil)
+(defvar exitter-oauth-token-ctime nil)
+
+(defvar exitter-debug nil)
;;; for debugging
-;; (setq request-message-level 'blather)
-;;; disable
-;; (setq request-message-level -1)
+(if exitter-debug
+ (setq request-message-level 'blather)
+ (setq request-message-level -1))
(defun exitter-get-access-token ()
(let ((oauth-consumer-key-secret
@@ -78,7 +83,7 @@
)))
(defun exitter-get-guest-token ()
- (message "entering exitter-get-guest-token")
+ (when exitter-debug (message "entering exitter-get-guest-token"))
(request exitter-url-activate
:headers `(("Authorization" . ,(format "Bearer %s" exitter-access-token)))
:parser 'json-read
@@ -92,7 +97,7 @@
))
(defun exitter-login-flow-token (guest-token)
- (message "entering exitter-login-flow-token")
+ (when exitter-debug (message "entering exitter-login-flow-token"))
(let ((headers `(,@exitter-init-headers
("Authorization" . ,(format "Bearer %s" exitter-access-token))
("X-Guest-Token" . ,guest-token)
@@ -140,8 +145,9 @@
)))
(defun exitter-find-subtask (data subtask-id)
- (message "entering exitter-find-subtask")
- (message "subtask-id: %s" subtask-id)
+ (when exitter-debug
+ (message "entering exitter-find-subtask")
+ (message "subtask-id: %s" subtask-id))
(seq-find
(lambda (subtask)
(equal (alist-get 'subtask_id subtask) subtask-id))
@@ -151,7 +157,7 @@
(message "Got error: %S" error-thrown))
(defun exitter-enter-username (flow-token headers)
- (message "entering exitter-enter-username")
+ (when exitter-debug (message "entering exitter-enter-username"))
(request exitter-url-task
:params '(("lang" . "en"))
:headers headers
@@ -184,7 +190,7 @@
(defun exitter-enter-password (flow-token headers)
- (message "entering exitter-enter-password")
+ (when exitter-debug (message "entering exitter-enter-password"))
(request exitter-url-task
:params '(("lang" . "en"))
:headers headers
@@ -199,15 +205,27 @@
:parser 'json-read
:success (cl-function
(lambda (&key data &allow-other-keys)
- (print data)
- ))
+ (cond
+ ((exitter-find-subtask data "LoginSuccessSubtask")
+ (message "LoginSuccessSubtask")
+ (let* ((subtask
+ (print (exitter-find-subtask data "LoginSuccessSubtask")))
+ (open-account (alist-get 'open_account subtask)))
+ (setq exitter-oauth-token
+ (alist-get 'oauth_token open-account)
+ exitter-oauth-token-secret
+ (alist-get 'oauth_token_secret open-account)
+ exitter-oauth-token-ctime
+ (format-time-string "%Y-%m-%d %a %H:%M:%S"
+ (current-time)))))
+ (t (message "Cannot find any matching subtasks"))) ))
:error
(cl-function (lambda (&rest args &key error-thrown &allow-other-keys)
(message "Got error: %S" error-thrown)))
))
(defun exitter-enter-email (flow-token headers)
- (message "entering exitter-enter-email")
+ (when exitter-debug (message "entering exitter-enter-email"))
(request exitter-url-task
:params '(("lang" . "en"))
:headers headers
@@ -222,7 +240,13 @@
:parser 'json-read
:success (cl-function
(lambda (&key data &allow-other-keys)
- (print data)
+ (let ((new-flow-token
+ (alist-get 'flow_token data)))
+ (cond
+ ((exitter-find-subtask data "LoginEnterPassword")
+ (message "LoginEnterPassword")
+ (exitter-enter-password new-flow-token headers))
+ (t (message "Cannot find any matching subtasks"))))
))
:error
(cl-function (lambda (&rest args &key error-thrown &allow-other-keys)