Browse files

Messed up, started over and added support for states

  • Loading branch information...
1 parent 0c1c713 commit c412e3b8b0b85fffd70fe08bb3e08adc41c74854 @jozip jozip committed Oct 19, 2010
Showing with 74 additions and 42 deletions.
  1. +74 −42 tumble.el
116 tumble.el
@@ -5,6 +5,7 @@
;; Author: Federico Builes <>
;; Contributors:
;; Quildreen Motta <>
+;; Johan Persson <>
;; Created: 1 Dec 2008
;; Version: 1.2
;; Keywords: tumblr
@@ -112,6 +113,18 @@
(setq tumble-group nil) ; uncomment to use a group.
(setq tumble-format "markdown") ; you can change this to html
(setq tumble-api-url "")
+(setq tumble-states (list "published" "draft")) ; supported states
+(defun tumble-state-from-partial-string (st)
+ (let ((state (car tumble-states)))
+ (if (string= st "")
+ state
+ (progn
+ (mapc `(lambda (x)
+ (if (string-match (concat "^" ,st) x)
+ (setq state x)))
+ tumble-states)
+ state))))
(defun tumble-login ()
"Ask the user for his Tumblr credentials"
@@ -130,77 +143,87 @@
(setq tumble-group nil))
-(defun tumble-text-from-region (min max title)
+(defun tumble-text-from-region (min max title state)
"Post the current region as a text in Tumblr"
- (interactive "r \nsTitle: ")
- (tumble-post-text title (tumble-region-text)))
+ (interactive "r \nsTitle: \nsState (published or draft): ")
+ (tumble-post-text title (tumble-region-text)
+ (tumble-state-from-partial-string state)))
-(defun tumble-text-from-buffer (title)
+(defun tumble-text-from-buffer (title state)
"Post the current buffer as a text in Tumblr"
- (interactive "sTitle: ")
- (tumble-text-from-region (point-min) (point-max) title))
+ (interactive "sTitle: \nsState (published or draft): ")
+ (tumble-text-from-region (point-min) (point-max) title
+ (tumble-state-from-partial-string state)))
-(defun tumble-quote-from-region (min max source)
+(defun tumble-quote-from-region (min max source state)
"Post a region as a quote in Tumblr"
- (interactive "r \nsSource (optional): " )
+ (interactive "r \nsSource (optional): \nsState (published or draft): " )
(list (cons 'type "quote")
(cons 'quote (tumble-region-text))
- (cons 'source source))))
+ (cons 'source source)
+ (cons 'state (tumble-state-from-partial-string state)))))
-(defun tumble-link-with-description (min max name url)
+(defun tumble-link-with-description (min max name url state)
"Posts a Tumblr link using the region as the description"
- (interactive "r \nsName (optional): \nsLink: ")
- (tumble-post-link name url (tumble-region-text)))
+ (interactive "r \nsName (optional): \nsLink: \nsState (published or draft): ")
+ (tumble-post-link name url (tumble-region-text)
+ (tumble-state-from-partial-string state)))
-(defun tumble-link (name url)
+(defun tumble-link (name url state)
"Posts a Tumblr link without description"
- (interactive "sName (optional): \nsLink: ")
- (tumble-post-link name url ""))
+ (interactive "sName (optional): \nsLink: \nsState (published or draft): ")
+ (tumble-post-link name url ""
+ (tumble-state-from-partial-string state)))
-(defun tumble-chat-from-region (min max title)
+(defun tumble-chat-from-region (min max title state)
"Posts a chat to Tumblr using the current region"
- (interactive "r \nsTitle (optional): ")
- (tumble-post-chat title (tumble-region-text)))
+ (interactive "r \nsTitle (optional): \nsState (published or draft): ")
+ (tumble-post-chat title (tumble-region-text)
+ (tumble-state-from-partial-string state)))
-(defun tumble-chat-from-buffer (title)
+(defun tumble-chat-from-buffer (title state)
"Posts a chat to Tumblr using the current buffer"
- (interactive "sTitle (optional): ")
- (tumble-chat-from-region (point-min) (point-max) title))
+ (interactive "sTitle (optional): \nsState (published or draft): ")
+ (tumble-chat-from-region (point-min) (point-max) title
+ (tumble-state-from-partial-string state)))
-(defun tumble-photo-from-url (source caption url)
+(defun tumble-photo-from-url (source caption url state)
"Posts a photo to Tumblr using an URL as the source"
- (interactive "sURL: \nsCaption (optional): \nsLink (optional): ")
- (tumble-post-photo source caption url))
+ (interactive "sURL: \nsCaption (optional): \nsLink (optional): \nsState (published or draft): ")
+ (tumble-post-photo source caption url
+ (tumble-state-from-partial-string state)))
-(defun tumble-photo-from-file (filename caption url)
+(defun tumble-photo-from-file (filename caption url state)
"Posts a local photo to Tumblr"
- (interactive "fPhoto: \nsCaption (optional): \nsLink (optional): ")
+ (interactive "fPhoto: \nsCaption (optional): \nsLink (optional): \nsState (published or draft): ")
(let* ((file-format (format "image/%s" (file-name-extension filename))) ; hack
(data (tumble-file-data filename))
(request (list (cons 'type "photo")
(cons 'caption caption)
- (cons 'click-through-url url))))
+ (cons 'click-through-url url)
+ (cons 'state (tumble-state-from-partial-string state)))))
(tumble-multipart-http-post request
-(defun tumble-audio (filename caption)
+(defun tumble-audio (filename caption state)
"Posts an audio file to Tumblr"
- (interactive "fAudio: \nsCaption (optional): ")
+ (interactive "fAudio: \nsCaption (optional): \nsState (published or draft): ")
(let* ((data (tumble-file-data filename))
(request (list (cons 'type "audio")
- (cons 'caption caption))))
+ (cons 'caption caption)
+ (cons 'state (tumble-state-from-partial-string state)))))
(tumble-multipart-http-post request
@@ -213,45 +236,54 @@
;; interactive dies with unquoted strings such as YouTube embed codes
;; so we call (read-string) directly.
(let* ((embed (read-string "Source (embed): "))
- (caption (read-string "Caption (optional): ")))
- (tumble-post-video embed caption)))
+ (caption (read-string "Caption (optional): "))
+ (state (read-string "State (published or draft): ")))
+ (tumble-post-video embed caption (tumble-state-from-partial-string state))))
-(defun tumble-post-text (title body)
+(defun tumble-post-text (title body state)
"Posts a new text to a tumblelog"
(list (cons 'type "regular")
(cons 'title title)
- (cons 'body body))))
+ (cons 'body body)
+ (cons 'state state))))
-(defun tumble-post-chat (title chat)
+(defun tumble-post-chat (title chat state)
"Posts a new chat to a tumblelog"
+ (tumble-change-state state)
(list (cons 'type "conversation")
(cons 'title title)
- (cons 'conversation chat))))
+ (cons 'conversation chat)
+ (cons 'state state))))
-(defun tumble-post-link (name url description)
+(defun tumble-post-link (name url description state)
"Posts a link to a tumblelog"
+ (tumble-change-state state)
(list (cons 'type "link")
(cons 'name name)
(cons 'url url)
- (cons 'description description))))
+ (cons 'description description)
+ (cons 'state state))))
-(defun tumble-post-photo (source caption url)
+(defun tumble-post-photo (source caption url state)
"Posts a photo to a tumblelog"
+ (tumble-change-state state)
(list (cons 'type "photo")
(cons 'source source)
(cons 'caption caption)
- (cons 'click-through-url url))))
+ (cons 'click-through-url url)
+ (cons 'state state))))
-(defun tumble-post-video (embed caption)
+(defun tumble-post-video (embed caption state)
"Embeds a video in a tumblelog"
(list (cons 'type "video")
(cons 'embed embed)
- (cons 'caption caption))))
+ (cons 'caption caption)
+ (cons 'state state))))
(defun tumble-default-headers ()
"Generic Tumblr headers"

0 comments on commit c412e3b

Please sign in to comment.