Created
March 1, 2010 01:17
-
-
Save dleslie/317990 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
;; Copyright 2010 Dan Leslie <[email protected]> | |
;; You can redistribute it and/or modify it under the terms of the GNU | |
;; General Public License as published by the Free Software Foundation; | |
;; either version 3, or at your option any later version. | |
(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