diff options
Diffstat (limited to 'lisp')
| -rw-r--r-- | lisp/mastodon-auth.el | 29 | ||||
| -rw-r--r-- | lisp/mastodon-http.el | 38 | ||||
| -rw-r--r-- | lisp/mastodon-toot.el | 18 | ||||
| -rw-r--r-- | lisp/mastodon.el | 17 | 
4 files changed, 82 insertions, 20 deletions
| diff --git a/lisp/mastodon-auth.el b/lisp/mastodon-auth.el index d01f687..2d11d46 100644 --- a/lisp/mastodon-auth.el +++ b/lisp/mastodon-auth.el @@ -1,8 +1,22 @@ +;;; mastodon-auth.el --- Auth functions for mastodon.el + +;;; Commentary: + +;; mastodon.el is an Emacs client for Mastodon, the federated microblogging +;; social network. It is very much a work-in-progress, but it is a labor of +;; love. + +;; mastodon-auth.el supports authorizing and authenticating with Mastodon. + +;;; Code: + +(require 'plstore)  (require 'mastodon)  (require 'mastodon-http)  (defgroup mastodon-auth nil    "Authenticate with Mastodon." +  :prefix "mastodon-auth-"    :group 'mastodon)  (defvar mastodon--client-app-plist nil) @@ -21,7 +35,7 @@ STATUS is passed by `url-retrieve'."                                                         ,(gethash "client_secret" client-data)))))))  (defun mastodon--register-client-app () -  "Adds `:client_id' and `client_secret' to `mastodon--client-plist'." +  "Add `:client_id' and `client_secret' to `mastodon--client-plist'."    (mastodon--http-post (mastodon--api-for "apps")                         'mastodon--register-client-app-triage                         '(("client_name" . "mastodon.el") @@ -29,13 +43,13 @@ STATUS is passed by `url-retrieve'."                           ("scopes" . "read write follow"))))  (defun mastodon--register-and-return-client-app () -  "Registers `mastodon' with an instance. Returns `mastodon--client-app-plist'." +  "Register `mastodon' with an instance. Return `mastodon--client-app-plist'."    (progn      (mastodon--register-client-app)      mastodon--client-app-plist))  (defun mastodon--store-client-id-and-secret () -  "Stores `:client_id' and `:client_secret' in a plstore." +  "Store `:client_id' and `:client_secret' in a plstore."    (let ((client-plist (mastodon--register-and-return-client-app))          (plstore (plstore-open mastodon-token-file)))      (plstore-put plstore "mastodon" `(:client_id @@ -47,7 +61,7 @@ STATUS is passed by `url-retrieve'."      client-plist))  (defun mastodon--client-app () -  "Returns `mastodon--client-app-plist'. +  "Return `mastodon--client-app-plist'.  If not set, retrieves client data from `mastodon-token-file'.  If no data can be found in the token file, registers the app and stores its data via `mastodon--store-client-id-and-secret'." @@ -75,9 +89,9 @@ STATUS is passed by `url-retrieve'."                                          mastodon--api-token-string)))))  (defun mastodon--get-access-token () -  "Retrieves access token from instance. Authenticates with email address and password. +  "Retrieve access token from instance. -Email address and password are not stored." +Authenticates with email address and password. Neither are not stored."    (mastodon--http-post (concat mastodon-instance-url "/oauth/token")                         'mastodon--get-access-token-triage                         `(("client_id" . ,(plist-get (mastodon--client-app) :client_id)) @@ -88,7 +102,7 @@ Email address and password are not stored."                           ("scope" . "read write follow"))))  (defun mastodon--access-token () -  "Returns `mastodon--api-token-string'. +  "Return `mastodon--api-token-string'.  If not set, retrieves token with `mastodon--get-access-token'."    (if mastodon--api-token-string @@ -101,3 +115,4 @@ If not set, retrieves token with `mastodon--get-access-token'."        mastodon--api-token-string)))  (provide 'mastodon-auth) +;;; mastodon-auth.el ends here diff --git a/lisp/mastodon-http.el b/lisp/mastodon-http.el index f8cb60d..9dbad6f 100644 --- a/lisp/mastodon-http.el +++ b/lisp/mastodon-http.el @@ -1,13 +1,32 @@ +;;; mastodon-http.el --- HTTP request/response functions for mastodon.el + +;;; Commentary: + +;; mastodon.el is an Emacs client for Mastodon, the federated microblogging +;; social network. It is very much a work-in-progress, but it is a labor of +;; love. + +;; mastodon-http.el provides HTTP request/response functions. + +;;; Code: +  (require 'mastodon) +(require 'json) + +(defgroup mastodon-http nil +  "HTTP requests and responses for Mastodon." +  :prefix "mastodon-http-" +  :group 'mastodon)  (defun mastodon--api-for (endpoint) -  "Returns Mastondon API URL for ENDPOINT." +  "Return Mastondon API URL for ENDPOINT."    (concat mastodon-instance-url "/api/" mastodon--api-version "/" endpoint))  (defun mastodon--http-post (url callback args &optional headers) -  "Sends ARGS to URL as a POST request. +  "Make POST request to URL. -Response buffer is passed to the CALLBACK function." +Response buffer is passed to CALLBACK function. +ARGS and HEADERS alist arguments are part of the POST request."    (let ((url-request-method "POST")          (url-request-extra-headers           (append '(("Content-Type" . "application/x-www-form-urlencoded")) headers)) @@ -26,34 +45,34 @@ Response buffer is passed to the CALLBACK function."      (buffer-substring-no-properties (point-min) (point-max))))  (defun mastodon--response-body-substring (pattern) -  "Returns substring matching PATTERN from `mastodon--response-buffer'." +  "Return substring matching PATTERN from `mastodon--response-buffer'."    (let ((resp (mastodon--response-buffer)))      (progn        (string-match pattern resp)        (match-string 0 resp))))  (defun mastodon--response-match-p (pattern) -  "Returns non-nil if `mastodon--response-buffer' matches PATTERN." +  "Return non-nil if `mastodon--response-buffer' matches PATTERN."    (let ((resp (mastodon--response-buffer)))      (string-match-p pattern resp)))  (defun mastodon--response-status-p () -  "Returns non-nil if `mastodon--response-buffer' has an HTTP Response Status-Line." +  "Return non-nil if `mastodon--response-buffer' has an HTTP Response Status-Line."    (when (mastodon--response-match-p "^HTTP/1.*$") t))  (defun mastodon--response-json () -  "Returns string of JSON response body from `mastodon--response-buffer'." +  "Return string of JSON response body from `mastodon--response-buffer'."    (mastodon--response-body-substring "\{.*\}"))  (defun mastodon--response-code () -  "Returns HTTP Response Status Code from `mastodon--response-buffer'." +  "Return HTTP Response Status Code from `mastodon--response-buffer'."    (let* ((status-line (mastodon--response-body-substring "^HTTP/1.*$")))      (progn        (string-match "[0-9][0-9][0-9]" status-line)        (match-string 0 status-line))))  (defun mastodon--json-hash-table () -  "Reads JSON from `mastodon--response-json' into a hash table." +  "Read JSON from `mastodon--response-json' into a hash table."    (let ((json-object-type 'hash-table)          (json-array-type 'list)          (json-key-type 'string)) @@ -74,3 +93,4 @@ If response code is not 2XX, switches to the response buffer created by `url-ret      (switch-to-buffer (current-buffer))))  (provide 'mastodon-http) +;;; mastodon-http.el ends here diff --git a/lisp/mastodon-toot.el b/lisp/mastodon-toot.el index 7744cdd..60ab2db 100644 --- a/lisp/mastodon-toot.el +++ b/lisp/mastodon-toot.el @@ -1,8 +1,21 @@ +;;; mastodon-toot.el --- Minor mode for sending Mastodon toots + +;;; Commentary: + +;; mastodon.el is an Emacs client for Mastodon, the federated microblogging +;; social network. It is very much a work-in-progress, but it is a labor of +;; love. + +;; mastodon-toot.el supports POSTing status data to Mastodon. + +;;; Code: +  (require 'mastodon-auth)  (require 'mastodon-http)  (defgroup mastodon-toot nil    "Capture Mastodon toots." +  :prefix "mastodon-toot-"    :group 'mastodon)  (defun mastodon-toot--send-triage (status) @@ -13,7 +26,7 @@ STATUS is passed by `url-retrieve'."                                    (lambda () (switch-to-buffer (current-buffer))))) ;; FIXME  (defun mastodon-toot--send () -  "Kills new-toot buffer/window and POSTs contents to the Mastodon instance." +  "Kill new-toot buffer/window and POST contents to the Mastodon instance."    (interactive)    (let ((toot (buffer-string))          (endpoint (mastodon--api-for "statuses"))) @@ -27,7 +40,7 @@ STATUS is passed by `url-retrieve'."                                                    (mastodon--access-token))))))))  (defun mastodon-toot--cancel () -  "Kills new-toot buffer/window. Does not POST content to Mastodon." +  "Kill new-toot buffer/window. Does not POST content to Mastodon."    (interactive)    (kill-buffer-and-window)) @@ -45,3 +58,4 @@ STATUS is passed by `url-retrieve'."    :global nil)  (provide 'mastodon-toot) +;;; mastodon-toot.el ends here diff --git a/lisp/mastodon.el b/lisp/mastodon.el index 2c68951..e69e10d 100644 --- a/lisp/mastodon.el +++ b/lisp/mastodon.el @@ -1,5 +1,17 @@ +;;; mastodon.el -- Mastodon client for Emacs + +;;; Commentary: + +;; mastodon.el is an Emacs client for Mastodon, the federated microblogging +;; social network. It is very much a work-in-progress, but it is a labor of +;; love. + +;;; Code: +  (defgroup mastodon nil -  "Interface with Mastodon.") +  "Interface with Mastodon." +  :prefix "mastodon-" +  :group 'external)  (defcustom mastodon-instance-url "https://mastodon.social"    "Base URL for the Masto instance from which you toot." @@ -15,7 +27,7 @@  ;;;###autoload  (defun mastodon-toot () -  "Updates a Mastodon instance with new toot. Content is captured in a new buffer." +  "Update a Mastodon instance with new toot. Content is captured in a new buffer."    (interactive)    (progn      (require 'mastodon-toot) @@ -31,3 +43,4 @@      (mastodon--store-client-id-and-secret)))  (provide 'mastodon) +;;; mastodon.el ends here | 
