Skip to content

Instantly share code, notes, and snippets.

@naduma
Created February 11, 2020 05:54
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save naduma/2abae98d28c363d05fb3d1038fe37f1c to your computer and use it in GitHub Desktop.
Save naduma/2abae98d28c363d05fb3d1038fe37f1c to your computer and use it in GitHub Desktop.
memoroux API利用 elisp
; memorux.el
(require 'json)
(defcustom memoroux-url nil
"memoroux url (e.g. https://memoroux.herokuapp.com)"
:type 'string :group 'memoroux)
(defcustom memoroux-username nil
"memoroux basic auth username"
:type 'string :group 'memoroux)
(defcustom memoroux-password nil
"memoroux basic auth password"
:type 'string :group 'memoroux)
(defun mrx ()
(interactive)
(let ((url-request-method "POST")
(url-request-extra-headers
(cons '("Content-Type" . "application/json")
(unless (null memoroux-username)
(let* ((credentials (concat
memoroux-username ":" memoroux-password))
(auth-value (base64-encode-string
(encode-coding-string credentials
'raw-text) t)))
(list (cons "Authorization" (concat "Basic " auth-value)))))))
(url-request-data
(encode-coding-string
(json-encode-alist `((id . ,(md5 (buffer-file-name)))
(content . ,(buffer-string))
(type . "html")))
'utf-8))
(url (concat memoroux-url "/convert")))
(switch-to-buffer
(url-retrieve-synchronously url))
(goto-char (point-min))
(re-search-forward "\n\n")
(princ (concat memoroux-url
(assoc-default
'url
(json-read-from-string
(buffer-substring-no-properties (point) (point-max))))))
(kill-buffer (current-buffer))))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment