Skip to content
Browse files

Reimplement `twittering-tinyurl-get' without url library.

* twittering-mode.el: Reimplement `twittering-tinyurl-get' with
`twittering-send-http-request'.
(twittering-url-wrapper): removed.
(twittering-url-insert-file-contents): removed.
(twittering-url-retrieve-synchronously): removed.
(twittering-tinyurl-get): reimplemented with
`twittering-send-http-request'. In addition, the query parameter
is correcly encoded by `twittering-percent-encode'.
  • Loading branch information...
1 parent ea9d9cd commit a7ce942dc7499a8b8f989e809217f1eb73464e58 @cvmat cvmat committed Jan 29, 2011
Showing with 38 additions and 33 deletions.
  1. +11 −0 ChangeLog
  2. +27 −33 twittering-mode.el
View
11 ChangeLog
@@ -1,3 +1,14 @@
+2011-01-29 Tadashi MATSUO <tad@mymail.twin.jp>
+
+ * twittering-mode.el: Reimplement `twittering-tinyurl-get' with
+ `twittering-send-http-request'.
+ (twittering-url-wrapper): removed.
+ (twittering-url-insert-file-contents): removed.
+ (twittering-url-retrieve-synchronously): removed.
+ (twittering-tinyurl-get): reimplemented with
+ `twittering-send-http-request'. In addition, the query parameter
+ is correcly encoded by `twittering-percent-encode'.
+
2011-01-23 Tadashi MATSUO <tad@mymail.twin.jp>
* test/test-twittering-mode.el: Add some tests for the format
View
60 twittering-mode.el
@@ -775,25 +775,6 @@ SCHEME must be \"http\" or \"https\"."
(defvar twittering-url-show-status nil
"*Whether to show a running total of bytes transferred.")
-(defun twittering-url-wrapper (func &rest args)
- (let ((url-proxy-services
- (when twittering-proxy-use
- (twittering-url-proxy-services)))
- (url-show-status twittering-url-show-status))
- (if (eq func 'url-retrieve)
- (let ((buffer (apply func args)))
- (when (buffer-live-p buffer)
- (with-current-buffer buffer
- (set (make-local-variable 'url-show-status)
- twittering-url-show-status)))
- buffer)
- (apply func args))))
-
-(defun twittering-url-insert-file-contents (url)
- (twittering-url-wrapper 'url-insert-file-contents url))
-
-(defun twittering-url-retrieve-synchronously (url)
- (twittering-url-wrapper 'url-retrieve-synchronously url))
;;;;
;;;; CA certificate
@@ -2916,25 +2897,38 @@ BEG and END mean a region that had been modified."
;;;;
(defun twittering-tinyurl-get (longurl)
- "Tinyfy LONGURL."
- (let ((api (cdr (assoc twittering-tinyurl-service
- twittering-tinyurl-services-map))))
+ "Shorten LONGURL with the service specified by `twittering-tinyurl-service'."
+ (let* ((api (cdr (assoc twittering-tinyurl-service
+ twittering-tinyurl-services-map)))
+ (uri (concat api (twittering-percent-encode longurl))))
(unless api
(error "Invalid `twittering-tinyurl-service'. try one of %s"
(mapconcat (lambda (x)
(symbol-name (car x)))
twittering-tinyurl-services-map ", ")))
- (if longurl
- (let ((buffer
- (twittering-url-retrieve-synchronously (concat api longurl))))
- (with-current-buffer buffer
- (goto-char (point-min))
- (prog1
- (if (search-forward-regexp "\n\r?\n\\([^\n\r]*\\)" nil t)
- (match-string-no-properties 1)
- (error "TinyURL failed: %s" longurl))
- (kill-buffer buffer))))
- nil)))
+ (let ((request (twittering-make-http-request-from-uri "GET" nil uri))
+ (additional-info `((longurl . ,longurl))))
+ (lexical-let ((result 'queried))
+ (twittering-send-http-request
+ request additional-info
+ (lambda (proc status connection-info header-info)
+ (let ((status-line (cdr (assq 'status-line header-info)))
+ (status-code (cdr (assq 'status-code header-info))))
+ (case-string
+ status-code
+ (("200")
+ (setq result (buffer-string))
+ nil)
+ (t
+ (setq result nil)
+ (format "Response: %s" status-line)))))
+ (lambda (proc status connection-info)
+ (when (and (memq status '(nil closed exit failed signal))
+ (eq result 'queried))
+ (setq result nil))))
+ (while (eq result 'queried)
+ (sit-for 0.1))
+ result))))
(defun twittering-tinyurl-replace-at-point ()
"Replace the url at point with a tiny version."

0 comments on commit a7ce942

Please sign in to comment.
Something went wrong with that request. Please try again.