Created
January 10, 2010 18:42
-
-
Save troter/273673 to your computer and use it in GitHub Desktop.
Post im.kayac.com
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
;;; im-kayac.el --- Post im.kayac.com | |
;;; test code | |
;; - 認証なし | |
;; (setq im-kayac-username "username") | |
;; (setq im-kayac-authorization-type nil) | |
;; | |
;; - パスワード | |
;; (setq im-kayac-username "username") | |
;; (setq im-kayac-password "password") | |
;; (setq im-kayac-authorization-type 'password) | |
;; | |
;; - 秘密鍵 | |
;; (setq im-kayac-username "username") | |
;; (setq im-kayac-password "SecretKey") | |
;; (setq im-kayac-authorization-type 'secretkey) | |
;; | |
;; - post | |
;; (im-kayac-post "Hello World!" "http://im.kayac.com/") | |
;;(auto-install-from-emacswiki "http-post-simple.el") | |
;;(auto-install-from-url "http://cvs.savannah.gnu.org/viewvc/*checkout*/emacs/lisp/json.el?root=emacs") | |
(require 'http-post-simple) | |
(require 'json) | |
(defvar im-kayac-username nil) | |
(defvar im-kayac-password nil) | |
(defvar im-kayac-authorization-type nil) | |
(defun im-kayac-post (message &optional handler) | |
(interactive "smessage: ") | |
(let* ((fields `((message . ,message) | |
(handler . ,(im-kayac-get-handler-params handler)) | |
(password . ,(im-kayac-get-passowrd-params)) | |
(sig . ,(im-kayac-get-signiure-params message)))) | |
(http-result (http-post-simple (im-kayac-get-post-url) fields)) | |
(im-result (json-read-from-string (car http-result))) | |
(result-message (concat (cdr-safe (assq 'error im-result)) | |
(cdr-safe (assq 'result im-result))))) | |
(message "im.kayac.com %s" result-message))) | |
(defun im-kayac-get-post-url () | |
(format "http://im.kayac.com/api/post/%s" im-kayac-username)) | |
(defun im-kayac-get-handler-params (handler) | |
(or handler "")) | |
(defun im-kayac-get-passowrd-params () | |
(if (eq 'password im-kayac-authorization-type) | |
im-kayac-password | |
"")) | |
(defun im-kayac-get-signiure-params (message) | |
(if (eq 'secretkey im-kayac-authorization-type) | |
(im-kayac-make-signiture message) | |
"")) | |
(defun im-kayac-make-signiture (message) | |
(sha1 (concat message im-kayac-password))) | |
(provide 'im-kayac) | |
;;; im-kayac.el ends here |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment