Skip to content

Instantly share code, notes, and snippets.

@kanru
Created March 4, 2012 15:05
Show Gist options
  • Save kanru/1973417 to your computer and use it in GitHub Desktop.
Save kanru/1973417 to your computer and use it in GitHub Desktop.
Plurk Client
;;;; plurk.lisp --- Plurk Client
;;; Copyright (C) 2012 Kan-Ru Chen
;;; Author(s): Kan-Ru Chen <[email protected]>
;;; Permission is hereby granted, free of charge, to any person obtaining a
;;; copy of this software and associated documentation files (the "Software"),
;;; to deal in the Software without restriction, including without limitation
;;; the rights to use, copy, modify, merge, publish, distribute, sublicense,
;;; and/or sell copies of the Software, and to permit persons to whom the
;;; Software is furnished to do so, subject to the following conditions:
;;; The above copyright notice and this permission notice shall be included in
;;; all copies or substantial portions of the Software.
;;; THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
;;; IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
;;; FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
;;; AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
;;; LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
;;; FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
;;; DEALINGS IN THE SOFTWARE.
;;;; Commentary:
;;; Use plurk old API to post to plurk.
;;;; Code:
(asdf:oos 'asdf:load-op :drakma)
(asdf:oos 'asdf:load-op :external-program)
(defpackage :plurk
(:use :cl :drakma :external-program)
(:export #:main))
(in-package :plurk)
(defparameter *plurk-id* "")
(defparameter *plurk-pw* "")
(defparameter *plurk-key* "")
(defparameter *plurk-secure-api* "https://www.plurk.com/API")
(defparameter *plurk-api* "http://www.plurk.com/API")
(defparameter *drakma-default-external-format* :UTF-8)
(defun plurk-login ()
(let ((session (make-instance 'cookie-jar)))
(http-request (concatenate 'string *plurk-secure-api* "/Users/login")
:method :post
:parameters `(("username" . ,*plurk-id*)
("password" . ,*plurk-pw*)
("api_key" . ,*plurk-key*))
:cookie-jar session)
session))
(defun plurk-add (session message)
(http-request (concatenate 'string *plurk-api* "/Timeline/plurkAdd")
:method :post
:parameters `(("content" . ,message)
("qualifier" . "share")
("lang" . "en")
("api_key" . ,*plurk-key*))
:cookie-jar session))
(defun plurk (message)
(let ((session (plurk-login)))
(plurk-add session message)))
(defun main (args)
(let ((message (cadr args)))
(if message
(plurk message)
(plurk (with-output-to-string (fortune)
(run "fortune" '("-n" "140" "-s")
:output fortune))))))
;;; plurk.lisp ends here
;;; Local Variables:
;;; mode: lisp
;;; End:
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment