Created
March 1, 2010 01:13
-
-
Save dleslie/317986 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
(require 'gist) | |
(require 'tumblr) | |
(require 'http-post-simple) | |
(defun tumblr-gist-region (begin end &optional private) | |
"Post the current region as a new paste in a blog post" | |
(interactive "r\nP") | |
(gist-region begin end private 'tumblr-gist-callback)) | |
(defun tumblr-gist-callback (status) | |
(let* ((url-max-redirections 5) | |
(url-request-method "GET") | |
(location (concat (cadr status) ".pibb")) | |
(gist-buffer (url-retrieve-synchronously location))) | |
(message "Fetched %s" location) | |
(with-current-buffer gist-buffer | |
(search-forward-regexp "\n\n") | |
(delete-region (point-min) (point)) | |
(set-buffer-modified-p nil) | |
(let* ((content (buffer-substring (point-min) (point-max))) | |
(fixed-content (replace-regexp-in-string | |
"\\(<pre>\\|</pre>\\)" "" | |
content)) | |
(title (read-string "Post title: ")) | |
(tags (read-string "Post tags: "))) | |
(tumblr-gist-send-post title tags fixed-content))))) | |
(defun tumblr-gist-send-post (title tags body) | |
"Slightly more detailed variant on the 'tumblr send-post function" | |
(http-post-simple tumblr-post-url (list (cons 'email tumblr-email) | |
(cons 'password tumblr-password) | |
(cons 'type tumblr-default-type) | |
(cons 'title title) | |
(cons 'tags tags) | |
(cons 'slug title) | |
(cons 'private "0") | |
(cons 'body body)) | |
'utf-8)) | |
(provide 'tumblr-gist) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment