Skip to content

Commit

Permalink
show (Liked) in the header of posts we like.
Browse files Browse the repository at this point in the history
  • Loading branch information
gcr committed Sep 10, 2012
1 parent 3fc9a82 commit 48c5121
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 3 deletions.
18 changes: 17 additions & 1 deletion tumblesocks-api.el
Expand Up @@ -122,6 +122,22 @@ error if the error code is not in the 200 category."
(cons (cons (intern (substring (symbol-name key) 1)) value)
(tumblesocks-plist-to-alist rest)))))

(defun tumblesocks-api-http-oauth-get (url params)
"Post to an API-key-authenticated Tumblr API endpoint (url),
using the given POST parameters (params, a keyword plist).
This function will return the response as JSON, or will signal an
error if the error code is not in the 200 category."
(with-current-buffer (oauth-url-retrieve
tumblesocks-token
(concat url "?api_key=" tumblesocks-consumer-key
(mapconcat
'(lambda (x)
(concat "&" (url-hexify-string (format "%s" (car x)))
"=" (url-hexify-string (format "%s" (cdr x)))))
(tumblesocks-plist-to-alist params) "")))
(tumblesocks-api-process-response)))

(defun tumblesocks-api-http-apikey-get (url params)
"Post to an API-key-authenticated Tumblr API endpoint (url),
using the given POST parameters (params, a keyword plist).
Expand Down Expand Up @@ -280,7 +296,7 @@ the returned JSON."
(and reblog_info `(:reblog_info ,reblog_info))
(and notes_info `(:notes_info ,notes_info))
(and filter `(:filter ,filter)))))
(tumblesocks-api-http-apikey-get
(tumblesocks-api-http-oauth-get
(tumblesocks-api-url "/blog/"
tumblesocks-blog
"/posts"
Expand Down
10 changes: 8 additions & 2 deletions tumblesocks-view.el
Expand Up @@ -20,6 +20,7 @@
(define-key tumblesocks-view-mode-map "s" 'tumblesocks-view-posts-tagged)
(define-key tumblesocks-view-mode-map "r" 'tumblesocks-view-reblog-post-at-point)
(define-key tumblesocks-view-mode-map (kbd "RET") 'tumblesocks-view-post-at-point)
(define-key tumblesocks-view-mode-map (kbd "SPC") 'forward-page)
(define-key tumblesocks-view-mode-map "b" 'tumblesocks-view-blog)
(define-key tumblesocks-view-mode-map "d" 'tumblesocks-view-delete-post-at-point)
(define-key tumblesocks-view-mode-map "e" 'tumblesocks-view-edit-post-at-point)
Expand Down Expand Up @@ -280,7 +281,7 @@ blogdata to be filtered with the 'text' filter.)"
This function internally dispatches to other functions that are
better suited to inserting each post."
(tumblesocks-bind-plist-keys post
(blog_name id post_url type date reblog_key tags liked note_count
(blog_name id post_url type date reblog_key tags liked note_count liked
;; For photo posts:
photos caption width
;; For quote posts:
Expand Down Expand Up @@ -326,6 +327,8 @@ better suited to inserting each post."
(when (and note_count (> note_count 0))
(insert " (" (format "%d" note_count) " note"
(if (= 1 note_count) "" "s") ")"))
(when liked
(insert " (Liked)"))
(insert "\n")
(when verbose
(insert
Expand Down Expand Up @@ -563,7 +566,10 @@ You can browse around, edit, and delete posts from here.
(tumblesocks-api-user-like post_id reblog_key)
(message "Liked this post."))
(tumblesocks-api-user-unlike post_id reblog_key)
(message "Unliked this post.")))))
(message "Unliked this post."))
(let ((pos (point)))
(tumblesocks-view-refresh)
(goto-char pos)))))

(defun tumblesocks-view-posts-tagged (tag)
"Search for posts with the given tag."
Expand Down

0 comments on commit 48c5121

Please sign in to comment.