Permalink
Browse files

Add `bit.ly' and `j.mp' as URL shortening services.

Thanks to Lars Gregori.

* twittering-mode.el: Add `bit.ly' and `j.mp' as URL shortening
services. Thanks to Lars Gregori.
(twittering-tinyurl-services-map): add entries for `bit.ly' and
`j.mp'.
(twittering-bitly-login): new variable.
(twittering-bitly-api-key): new variable.
(twittering-make-http-request-for-bitly): new function.
  • Loading branch information...
1 parent bb8ae41 commit a59a29109c0eaa2e97c6daa5659d84b042f6b0e5 @cvmat cvmat committed Jan 29, 2011
Showing with 59 additions and 8 deletions.
  1. +8 −0 ChangeLog
  2. +10 −3 NEWS
  3. +11 −3 NEWS.ja
  4. +30 −2 twittering-mode.el
View
@@ -25,6 +25,14 @@
* twittering-mode.el: Add `goo.gl' as a URL shortening service.
(twittering-tinyurl-services-map): add an entry for `goo.gl'.
+ * twittering-mode.el: Add `bit.ly' and `j.mp' as URL shortening
+ services. Thanks to Lars Gregori.
+ (twittering-tinyurl-services-map): add entries for `bit.ly' and
+ `j.mp'.
+ (twittering-bitly-login): new variable.
+ (twittering-bitly-api-key): new variable.
+ (twittering-make-http-request-for-bitly): new function.
+
2011-01-23 Tadashi MATSUO <tad@mymail.twin.jp>
* test/test-twittering-mode.el: Add some tests for the format
View
13 NEWS
@@ -111,11 +111,18 @@
posted. This is because it is impossible to retrieve the time when a
tweet was favorited. At most, 20 favorites can be retrieved. Backward
retrieval of more previous favorites is not supported yet.
-* Support for `goo.gl' and `is.gd' as URL shortening service.
- You can use `goo.gl' and `is.gd' as URL shortening service by the following.
+* Support for new URL shortening services.
+ You can use `bit.ly', `goo.gl', `is.gd' or `j.mp' as URL shortening
+ service by the following.
+ (setq twittering-tinyurl-service 'bit.ly) ;; for bit.ly
(setq twittering-tinyurl-service 'goo.gl) ;; for goo.gl
(setq twittering-tinyurl-service 'is.gd) ;; for is.gd
- Thanks to Michael Kohl.
+ (setq twittering-tinyurl-service 'j.mp) ;; for j.mp
+ To use `bit.ly' or `j.mp', you need to configure `twittering-bitly-login'
+ and `twittering-bitly-api-key' according to your account as follows.
+ (setq twittering-bitly-login "YOUR-LOGIN-NAME")
+ (setq twittering-bitly-api-key "YOUR-API-KEY")
+ Thanks to Michael Kohl and Lars Gregori.
* ...
### Bug fixes
View
14 NEWS.ja
@@ -113,11 +113,19 @@
投稿時刻の順に表示されるので注意してください。これは「お気に入り」に
登録した時刻を取得する方法がないためです。また、取得できる「お気に入
り」は最大20件です。より過去にさかのぼっての取得は未対応です。
-* 短縮URL生成サービス`goo.gl', `is.gd'に対応
- 下記の設定で短縮URL生成に`goo.gl'や`is.gd'を使うようになります。
+* 新たにいくつかの短縮URL生成サービスに対応
+ 新たに`bit.ly', `goo.gl', `is.gd', `j.mp'に対応しました。下記のような
+ 設定で有効にできます。
+ (setq twittering-tinyurl-service 'bit.ly) ;; bit.lyの場合
(setq twittering-tinyurl-service 'goo.gl) ;; goo.glの場合
(setq twittering-tinyurl-service 'is.gd) ;; is.gdの場合
- Thanks to Michael Kohl.
+ (setq twittering-tinyurl-service 'j.mp) ;; j.mpの場合
+ `bit.ly'や`j.mp'を使うにはお持ちのアカウントに応じて下記のように
+ `twittering-bitly-login'と`twittering-bitly-api-key'を設定しておく必要が
+ あります。
+ (setq twittering-bitly-login "YOUR-LOGIN-NAME")
+ (setq twittering-bitly-api-key "YOUR-API-KEY")
+ Thanks to Michael Kohl and Lars Gregori.
* ...
### バグ修正
View
@@ -120,10 +120,13 @@ The upper limit is `twittering-max-number-of-tweets-on-retrieval'.")
(defvar twittering-tinyurl-service 'tinyurl
"*The service to shorten URI.
-This must be one of key symbols of `twittering-tinyurl-services-map'.")
+This must be one of key symbols of `twittering-tinyurl-services-map'.
+To use 'bit.ly or 'j.mp, you have to configure `twittering-bitly-login' and
+`twittering-bitly-api-key'.")
(defvar twittering-tinyurl-services-map
- '((goo.gl
+ '((bit.ly twittering-make-http-request-for-bitly)
+ (goo.gl
(lambda (service longurl)
(twittering-make-http-request-from-uri
"POST" '(("Content-Type" . "application/json"))
@@ -134,6 +137,7 @@ This must be one of key symbols of `twittering-tinyurl-services-map'.")
reply)
(match-string 1 reply))))
(is.gd . "http://is.gd/create.php?format=simple&url=")
+ (j.mp twittering-make-http-request-for-bitly)
(tinyurl . "http://tinyurl.com/api-create.php?url=")
(toly
(lambda (service longurl)
@@ -162,6 +166,11 @@ If the second element is a function, it is called as `(funcall
THE-SECOND-ELEMENT service-symbol HTTP-reply-string)' and its result is used
as a shortened URL.")
+(defvar twittering-bitly-login nil
+ "*The login name for URL shortening service bit.ly and j.mp.")
+(defvar twittering-bitly-api-key nil
+ "*The API key for URL shortening service bit.ly and j.mp.")
+
(defvar twittering-mode-map (make-sparse-keymap))
(defvar twittering-mode-menu-on-uri-map (make-sparse-keymap "Twittering Mode"))
(defvar twittering-mode-on-uri-map (make-sparse-keymap))
@@ -3003,6 +3012,25 @@ BEG and END mean a region that had been modified."
(delete-region (point-min) (point-max))
(insert url)))))))
+(defun twittering-make-http-request-for-bitly (service longurl)
+ "Make a HTTP request for URL shortening service bit.ly or j.mp.
+Before calling this, you have to configure `twittering-bitly-login' and
+`twittering-bitly-api-key'."
+ (let* ((query-string
+ (mapconcat
+ (lambda (entry)
+ (concat (car entry) "=" (cdr entry)))
+ `(("login" . ,twittering-bitly-login)
+ ("apiKey" . ,twittering-bitly-api-key)
+ ("format" . "txt")
+ ("longUrl" . ,(twittering-percent-encode longurl)))
+ "&"))
+ (prefix
+ (cdr (assq service '((bit.ly . "http://api.bit.ly/v3/shorten?")
+ (j.mp . "http://api.j.mp/v3/shorten?")))))
+ (uri (concat prefix query-string)))
+ (twittering-make-http-request-from-uri "GET" nil uri)))
+
;;;;
;;;; Timeline spec
;;;;

0 comments on commit a59a291

Please sign in to comment.