松尾です。
> 前半部分の修正は、呼び出し元でも変更が必要だと思うのですが、
> それが含まれていないような気がします。
確かにそうでした。すみません。
現在のsearch-mode branchのHEADに対するパッチを添付します。
関数 twittering-get-status-from-http-response を追加して
spec 毎の status 抽出方法の違いを隠蔽して timeline の取得に
対する sentinel を一本化しています。
ところで、そろそろsearch-mode branchの機能自体を mainline に
取り込んでも良いんじゃないかと思ってるんですが、どうでしょうか。
普段使いには問題ないのですが、既知の問題とかあったりします?
---
松尾 直志 <[email protected]>
>From 1f77cda77621016fa6eba919ba2520c9eab0105e Mon Sep 17 00:00:00 2001
From: Tadashi MATSUO <[email protected]>
Date: Tue, 2 Feb 2010 02:00:53 +0900
Subject: [PATCH] `twittering-http-get-default-sentinel' supports "search" spec.
* twittering-mode.el (twittering-http-get-default-sentinel): use
`twittering-get-status-from-http-response'.
(twittering-get-status-from-http-response): new function for
extracting statuses from HTTP response.
(twittering-get-tweets): use
`twittering-http-get-default-sentinel' for the "search" timeline
spec.
(twittering-http-get-search-sentinel): removed.
---
ChangeLog | 11 ++++++
twittering-mode.el | 100 +++++++++++++++------------------------------------
2 files changed, 41 insertions(+), 70 deletions(-)
diff --git a/ChangeLog b/ChangeLog
index fa8ccc9..22175fa 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,14 @@
+2010-02-02 Tadashi MATSUO <[email protected]>
+
+ * twittering-mode.el (twittering-http-get-default-sentinel): use
+ `twittering-get-status-from-http-response'.
+ (twittering-get-status-from-http-response): new function for
+ extracting statuses from HTTP response.
+ (twittering-get-tweets): use
+ `twittering-http-get-default-sentinel' for the "search" timeline
+ spec.
+ (twittering-http-get-search-sentinel): removed.
+
2010-01-31 Tadashi MATSUO <[email protected]>
* twittering-mode.el (twittering-http-get-default-sentinel):
diff --git a/twittering-mode.el b/twittering-mode.el
index 2981543..2fddd86 100644
--- a/twittering-mode.el
+++ b/twittering-mode.el
@@ -1535,32 +1535,30 @@ Available keywords:
(defun twittering-http-get-default-sentinel (temp-buffer noninteractive proc
stat &optional suc-msg)
(debug-printf "get-default-sentinel: proc=%s stat=%s" proc stat)
(unwind-protect
- (let* ((header (twittering-get-response-header temp-buffer))
- (body (twittering-get-response-body temp-buffer))
+ (let* ((spec (twittering-get-timeline-spec-from-process proc))
+ (spec-string (twittering-timeline-spec-to-string spec))
+ (requested-spec
+ (twittering-string-to-timeline-spec
+ twittering-last-requested-timeline-spec-string))
+ (header (twittering-get-response-header temp-buffer))
+ (statuses
+ (twittering-get-status-from-http-response spec temp-buffer))
(header-is-valid
(string-match twittering-http-status-line-regexp header))
(status-line (and header-is-valid
(match-string-no-properties 1 header)))
(status (and header-is-valid
- (match-string-no-properties 2 header)))
- (spec (twittering-get-timeline-spec-from-process proc))
- (spec-string (twittering-timeline-spec-to-string spec))
- (requested-spec
- (twittering-string-to-timeline-spec
- twittering-last-requested-timeline-spec-string)))
+ (match-string-no-properties 2 header))))
(twittering-release-process proc)
(cond
- ((and header-is-valid body (equal spec requested-spec))
+ ((and header-is-valid statuses (equal spec requested-spec))
(case-string
status
(("200")
- (let* ((reversed-statuses
- (twittering-xmltree-to-status body))
- (statuses (reverse reversed-statuses)))
- (setq twittering-new-tweets-count
- (count t (mapcar
- #'twittering-cache-status-datum
- statuses))))
+ (setq twittering-new-tweets-count
+ (count t (mapcar
+ #'twittering-cache-status-datum
+ statuses)))
(setq twittering-timeline-data
(sort twittering-timeline-data
(lambda (status1 status2)
@@ -1593,59 +1591,6 @@ Available keywords:
(kill-buffer temp-buffer)))
)
-(defun twittering-http-get-search-sentinel (temp-buffer noninteractive proc
stat &optional suc-msg)
- (debug-printf "get-search-sentinel: proc=%s stat=%s" proc stat)
- (unwind-protect
- (let ((header (twittering-get-response-header temp-buffer))
- (body (twittering-get-response-body-string temp-buffer))
- (status-line nil)
- (status nil))
- (if (string-match twittering-http-status-line-regexp header)
- (when body
- (setq status-line (match-string-no-properties 1 header))
- (setq status (match-string-no-properties 2 header))
- (case-string
- status
- (("200")
- (let ((statuses (twittering-json-to-status
- (json-read-from-string body))))
- (setq twittering-new-tweets-count
- (count t (mapcar
- #'twittering-cache-status-datum
- (reverse statuses)))))
- (setq twittering-timeline-data
- (sort twittering-timeline-data
- (lambda (status1 status2)
- (let ((created-at1
- (twittering-created-at-to-seconds
- (cdr (assoc 'created-at status1))))
- (created-at2
- (twittering-created-at-to-seconds
- (cdr (assoc 'created-at status2)))))
- (> created-at1 created-at2)))))
- (if (and (> twittering-new-tweets-count 0)
- noninteractive)
- (run-hooks 'twittering-new-tweets-hook))
- (let ((same-timeline
- (equal twittering-last-retrieved-timeline-spec-string
- twittering-last-requested-timeline-spec-string)))
- (setq twittering-last-retrieved-timeline-spec-string
- twittering-last-requested-timeline-spec-string)
- (twittering-render-timeline same-timeline))
- (twittering-add-timeline-history)
- (when (and (twittering-buffer-active-p)
- twittering-notify-successful-http-get)
- (message (if suc-msg suc-msg "Success: Get."))))
- (t (when (twittering-buffer-active-p)
- (message "Response: %s" status-line)))))
- (when (twittering-buffer-active-p)
- (message "Failure: Bad http response.")))
- )
- ;; unwindforms
- (when (and (not twittering-debug-mode) (buffer-live-p temp-buffer))
- (kill-buffer temp-buffer)))
- )
-
(defun twittering-http-get-list-index-sentinel (temp-buffer noninteractive
proc stat &optional suc-msg)
(debug-printf "get-list-index-sentinel: proc=%s stat=%s" proc stat)
(unwind-protect
@@ -1765,6 +1710,21 @@ Return nil when parse failed.
(error "Failure: invalid HTTP response"))
)))
+(defun twittering-get-status-from-http-response (spec buffer)
+ "Exract statuses from HTTP response, and return a list.
+Return nil when parse failed.
+`buffer' may be a buffer or the name of an existing buffer. "
+ (cond
+ ((eq 'search (car spec))
+ (let ((body-string (twittering-get-response-body-string buffer)))
+ (when body-string
+ (let ((json-data (json-read-from-string body-string)))
+ (reverse (twittering-json-to-status json-data))))))
+ (t
+ (let ((body (twittering-get-response-body buffer)))
+ (when body
+ (reverse (twittering-xmltree-to-status body)))))))
+
(defun twittering-cache-status-datum (status-datum &optional data-var)
"Cache status datum into data-var(default twittering-timeline-data)
If STATUS-DATUM is already in DATA-VAR, return nil. If not, return t."
@@ -2600,7 +2560,7 @@ variable `twittering-status-format'"
(add-to-list 'parameters `("max_id" . ,id)))
(twittering-http-get host method
noninteractive parameters
- 'twittering-http-get-search-sentinel
+ 'twittering-http-get-default-sentinel
"json"))
(t
(add-to-list 'parameters
--
1.5.6.5
------------------------------------------------------------------------------
The Planet: dedicated and managed hosting, cloud storage, colocation
Stay online with enterprise data centers and the best network in the business
Choose flexible plans and management services without long-term contracts
Personal 24x7 support from experience hosting pros just a phone call away.
http://p.sf.net/sfu/theplanet-com
_______________________________________________
twmode-users mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/twmode-users