Skip to content
This repository has been archived by the owner on Mar 28, 2019. It is now read-only.

Commit

Permalink
More features
Browse files Browse the repository at this point in the history
- https support
- support alternative servers (e.g. a sandbox server)
- JSON encoded tag values
  • Loading branch information
hdurer committed Aug 22, 2009
1 parent 3c2daa5 commit 67e8e69
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 12 deletions.
2 changes: 1 addition & 1 deletion cl-fluiddb.asd
Expand Up @@ -18,6 +18,6 @@ diagnostic output.")

:serial t
:version #.*cl-fluiddb-version*
:depends-on (:cl-json :drakma)
:depends-on (:cl-json :drakma :flexi-streams)
:components ((:file "defpackage")
(:file "fluiddb")))
1 change: 1 addition & 0 deletions defpackage.lisp
Expand Up @@ -5,6 +5,7 @@
(:export

;; variables
#:*use-https*
#:*credentials*
#:*proxy-server*
#:*proxy-credentials*
Expand Down
38 changes: 27 additions & 11 deletions fluiddb.lisp
@@ -1,5 +1,11 @@
(in-package #:cl-fluiddb)

(defvar *server-url* "fluiddb.fluidinfo.com/"
"Base URL (without the http:// or https:// protocol bit) for the server to call")

(defvar *use-https* t
"Flag whether to use HTTPS or just HTTP")

(defvar *connection* nil
"A store for any existing connection to the server that can be re-used")

Expand Down Expand Up @@ -39,33 +45,42 @@ This might allow FluidInfo to better monitor what app is using their service")
Set want-json to nil if you do not want only application/json back (e.g. to get payload of a tag).
We inspect the return data and convert it to a lisp data structure if it is json"
(let ((drakma:*drakma-default-external-format* :utf-8))
(let ((drakma:*drakma-default-external-format* :utf-8)
(url (concatenate 'string
(if *use-https* "https://" "http://")
*server-url*
url))
(body-data (if (and body-data (stringp body-data))
;; convert to UTF-8 as my Drakma version get lenght wrong otherwise
(flexi-streams:string-to-octets body-data :external-format :utf-8)
body-data))
(additional-headers `(("accept-encoding" . "base64")
,@(if want-json
'((:accept . "application/json"))))))
(multiple-value-bind (raw-response code headers url stream should-close status-text)
(handler-case
(drakma:http-request (concatenate 'string "http://fluiddb.fluidinfo.com/" url)
(drakma:http-request url
:parameters query-data
:method method
:close nil :keep-alive t
:stream *connection*
:content body-data
:content-type content-type
:additional-headers (if want-json
'((:accept . "application/json")))
:additional-headers additional-headers
:user-agent *user-agent*
:basic-authorization *credentials*
:proxy *proxy-server*
:proxy-basic-authorization *proxy-credentials*)
(error () ;; assume a stale file handle and just re-try with a fresh one
(setf *connection* nil)
(drakma:http-request (concatenate 'string "http://fluiddb.fluidinfo.com/" url)
(drakma:http-request (concatenate 'string *server-url* url)
:parameters query-data
:method method
:close nil :keep-alive t
:stream nil
:content body-data
:content-type content-type
:additional-headers (if want-json
'((:accept . "application/json")))
:additional-headers additional-headers
:user-agent *user-agent*
:basic-authorization *credentials*
:proxy *proxy-server*
Expand Down Expand Up @@ -152,15 +167,16 @@ We inspect the return data and convert it to a lisp data structure if it is json
(when about (list "about" about)))
:method :post))

(defun get-object-tag-value (id tag)
(defun get-object-tag-value (id tag &key want-json)
(send-request (concatenate 'string "objects/" id "/" tag)
:want-json nil))
:query-data (when want-json '(("format" . "json")))
:want-json (to-boolean want-json)))

(defun set-object-tag-value (id tag content content-type)
(defun set-object-tag-value (id tag content &optional content-type)
(send-request (concatenate 'string "objects/" id "/" tag)
:method :put
:body-data content
:content-type content-type))
:content-type (or content-type "application/json")))


;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
Expand Down

0 comments on commit 67e8e69

Please sign in to comment.