Created
February 11, 2020 05:54
-
-
Save naduma/2abae98d28c363d05fb3d1038fe37f1c to your computer and use it in GitHub Desktop.
memoroux API利用 elisp
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
; 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