diff options
-rw-r--r-- | Cask | 2 | ||||
-rw-r--r-- | lisp/mastodon-http.el | 43 | ||||
-rw-r--r-- | lisp/mastodon-profile.el | 3 | ||||
-rw-r--r-- | lisp/mastodon-search.el | 34 | ||||
-rw-r--r-- | lisp/mastodon.el | 3 |
5 files changed, 47 insertions, 38 deletions
@@ -4,6 +4,8 @@ (package-file "lisp/mastodon.el") (files "lisp/*.el") +(depends-on "seq") + (development (depends-on "ert-runner") (depends-on "el-mock") diff --git a/lisp/mastodon-http.el b/lisp/mastodon-http.el index 8a7499f..3b31668 100644 --- a/lisp/mastodon-http.el +++ b/lisp/mastodon-http.el @@ -3,7 +3,7 @@ ;; Copyright (C) 2017-2019 Johnson Denen ;; Author: Johnson Denen <johnson.denen@gmail.com> ;; Version: 0.9.0 -;; Package-Requires: ((emacs "24.4")) +;; Package-Requires: ((emacs "24.4") (request "0.2.0")) ;; Homepage: https://github.com/jdenen/mastodon.el ;; This file is not part of GNU Emacs. @@ -33,7 +33,12 @@ (require 'request) ; for attachments upload (defvar mastodon-instance-url) +(defvar mastodon-toot--media-attachment-ids) +(defvar mastodon-toot--media-attachment-filenames) + (autoload 'mastodon-auth--access-token "mastodon-auth") +(autoload 'mastodon-toot--update-status-fields "mastodon-toot") + (defvar mastodon-http--api-version "v1") @@ -132,6 +137,37 @@ Pass response buffer to CALLBACK function." (kill-buffer) (json-read-from-string json-string))) +;; http functions for search: +(defun mastodon-http--process-json-search () + "Process JSON returned by a search query to the server." + (goto-char (point-min)) + (re-search-forward "^$" nil 'move) + (let ((json-string + (decode-coding-string + (buffer-substring-no-properties (point) (point-max)) + 'utf-8))) + (kill-buffer) + (json-read-from-string json-string))) + +(defun mastodon-http--get-search-json (url query) + "Make GET request to URL, searching for QUERY and return JSON response." + (let ((buffer (mastodon-http--get-search url query))) + (with-current-buffer buffer + (mastodon-http--process-json-search)))) + +(defun mastodon-http--get-search (base-url query) + "Make GET request to BASE-URL, searching for QUERY. + +Pass response buffer to CALLBACK function." + (let ((url-request-method "GET") + (url (concat base-url "?q=" (url-hexify-string query))) + (url-request-extra-headers + `(("Authorization" . ,(concat "Bearer " + (mastodon-auth--access-token)))))) + (if (< (cdr (func-arity 'url-retrieve-synchronously)) 4) + (url-retrieve-synchronously url) + (url-retrieve-synchronously url nil nil mastodon-http--timeout)))) + ;; Asynchronous functions (defun mastodon-http--get-async (url &optional callback &rest cbargs) @@ -173,7 +209,7 @@ Authorization header is included by default unless UNAUTHENTICED-P is non-nil." ;; TODO: test for curl first? (defun mastodon-http--post-media-attachment (url filename caption) - "Make a POST request to upload file FILENAME with CAPTION to the server's media URL. + "Make POST request to upload FILENAME with CAPTION to the server's media URL. The upload is asynchronous. On succeeding, `mastodon-toot--media-attachment-ids' is set to the id(s) of the item uploaded, `mastodon-toot--media-attachments' is set to t, and `mastodon-toot--update-status-fields' is run." (let* ((file (file-name-nondirectory filename)) @@ -204,8 +240,7 @@ The upload is asynchronous. On succeeding, `mastodon-toot--media-attachment-ids' (mastodon-toot--update-status-fields))))) :error (cl-function (lambda (&key error-thrown &allow-other-keys) - (message "Got error: %s" error-thrown))) - ))) + (message "Got error: %s" error-thrown)))))) (pcase (request-response-status-code response) (200 (request-response-data response)) diff --git a/lisp/mastodon-profile.el b/lisp/mastodon-profile.el index 9d4793c..e007343 100644 --- a/lisp/mastodon-profile.el +++ b/lisp/mastodon-profile.el @@ -3,7 +3,7 @@ ;; Copyright (C) 2017-2019 Johnson Denen ;; Author: Johnson Denen <johnson.denen@gmail.com> ;; Version: 0.7.2 -;; Package-Requires: ((emacs "24.4")) +;; Package-Requires: ((emacs "24.4") (seq "1.8")) ;; Homepage: https://github.com/jdenen/mastodon.el ;; This file is not part of GNU Emacs. @@ -49,6 +49,7 @@ (autoload 'mastodon-tl--timeline "mastodon-tl.el") (autoload 'mastodon-tl--as-string "mastodon-tl.el") (autoload 'mastodon-tl--toot-id "mastodon-tl") +(autoload 'mastodon-tl--toot "mastodon-tl") (defvar mastodon-instance-url) (defvar mastodon-tl--buffer-spec) diff --git a/lisp/mastodon-search.el b/lisp/mastodon-search.el index 408b887..90158a1 100644 --- a/lisp/mastodon-search.el +++ b/lisp/mastodon-search.el @@ -1,4 +1,4 @@ -;;; mastodon-search.el --- search functions for mastodon.el -*- lexical-binding: t -*- +;;; mastodon-search.el --- Search functions for mastodon.el -*- lexical-binding: t -*- ;; Copyright (C) 2017-2019 Johnson Denen ;; Author: Johnson Denen <johnson.denen@gmail.com>, martyhiatt <mousebot@riseup.net> @@ -37,6 +37,7 @@ (autoload 'mastodon-tl--render-text "mastodon-tl") (autoload 'mastodon-tl--as-string "mastodon-tl") (autoload 'mastodon-auth--access-token "mastodon-auth") +(autoload 'mastodon-http--get-search-json "mastodon-http") (defvar mastodon-instance-url) (defvar mastodon-tl--link-keymap) @@ -143,36 +144,5 @@ This allows us to access the full account etc. details and to render them proper (json (mastodon-http--get-json url))) json)) -;; http functions for search: -(defun mastodon-http--process-json-search () - "Process JSON returned by a search query to the server." - (goto-char (point-min)) - (re-search-forward "^$" nil 'move) - (let ((json-string - (decode-coding-string - (buffer-substring-no-properties (point) (point-max)) - 'utf-8))) - (kill-buffer) - (json-read-from-string json-string))) - -(defun mastodon-http--get-search-json (url query) - "Make GET request to URL, searching for QUERY and return JSON response." - (let ((buffer (mastodon-http--get-search url query))) - (with-current-buffer buffer - (mastodon-http--process-json-search)))) - -(defun mastodon-http--get-search (base-url query) - "Make GET request to BASE-URL, searching for QUERY. - -Pass response buffer to CALLBACK function." - (let ((url-request-method "GET") - (url (concat base-url "?q=" (url-hexify-string query))) - (url-request-extra-headers - `(("Authorization" . ,(concat "Bearer " - (mastodon-auth--access-token)))))) - (if (< (cdr (func-arity 'url-retrieve-synchronously)) 4) - (url-retrieve-synchronously url) - (url-retrieve-synchronously url nil nil mastodon-http--timeout)))) - (provide 'mastodon-search) ;;; mastodon-search.el ends here diff --git a/lisp/mastodon.el b/lisp/mastodon.el index f6635c0..37876f6 100644 --- a/lisp/mastodon.el +++ b/lisp/mastodon.el @@ -3,7 +3,7 @@ ;; Copyright (C) 2017-2019 Johnson Denen ;; Author: Johnson Denen <johnson.denen@gmail.com> ;; Version: 0.9.0 -;; Package-Requires: ((emacs "24.4")) +;; Package-Requires: ((emacs "24.4") (request "0.2.0") (seq "1.8")) ;; Homepage: https://github.com/jdenen/mastodon.el ;; This file is not part of GNU Emacs. @@ -32,6 +32,7 @@ ;;; Code: (declare-function discover-add-context-menu "discover") (declare-function emojify-mode "emojify") +(declare-function request "request") (autoload 'special-mode "simple") (autoload 'mastodon-tl--get-federated-timeline "mastodon-tl") (autoload 'mastodon-tl--get-home-timeline "mastodon-tl") |