]> gitweb.factorcode.org Git - factor.git/commitdiff
Work on couchdb in progress. Added http-delete, http-trace, refactored some of http...
authorAlex Chapman <chapman.alex@gmail.com>
Mon, 13 Oct 2008 06:01:29 +0000 (17:01 +1100)
committerAlex Chapman <chapman.alex@gmail.com>
Mon, 13 Oct 2008 06:01:29 +0000 (17:01 +1100)
basis/http/client/client.factor
extra/couchdb/couchdb.factor

index ef53e138acaa379dcb6d1db9060b8ba693ebb551..675258c79dc824a6b215105da847062d1d4e5736 100644 (file)
@@ -175,10 +175,14 @@ M: download-failed error.
     [ [ % ] with-http-request ] B{ } make
     over content-charset>> decode ;
 
+: <client-request> ( url -- request )
+    <request> swap >url ensure-port >>url ;
+
+: <client-data-request> ( data url -- request )
+    <client-request> swap >>post-data ;
+
 : <get-request> ( url -- request )
-    <request>
-        "GET" >>method
-        swap >url ensure-port >>url ;
+    <client-request> "GET" >>method ;
 
 : http-get ( url -- response data )
     <get-request> http-request ;
@@ -186,6 +190,18 @@ M: download-failed error.
 : with-http-get ( url quot -- response )
     [ <get-request> ] dip with-http-request ; inline
 
+: <delete-request> ( url -- request )
+    <client-request> "DELETE" >>method ;
+
+: http-delete ( url -- response data )
+    <delete-request> http-request ;
+
+: <trace-request> ( url -- request )
+    <client-request> "TRACE" >>method ;
+
+: http-trace ( url -- response data )
+    <trace-request> http-request ;
+
 : download-name ( url -- name )
     present file-name "?" split1 drop "/" ?tail drop ;
 
@@ -196,16 +212,13 @@ M: download-failed error.
     dup download-name download-to ;
 
 : <post-request> ( post-data url -- request )
-    <request>
-        "POST" >>method
-        swap >url ensure-port >>url
-        swap >>post-data ;
+    <client-data-request> "POST" >>method ;
 
 : http-post ( post-data url -- response data )
     <post-request> http-request ;
 
 : <put-request> ( data url -- request )
-    <post-request> "PUT" >>method ;
+    <client-data-request> "PUT" >>method ;
 
 : http-put ( data url -- response data )
     <put-request> http-request ;
index 7e1d97e78670779284a30dd6c197ce8cf8e70a16..7c656e175ee6505a5396901786479a52fb8e9d55 100644 (file)
@@ -1,14 +1,16 @@
 ! Copyright (C) 2008 Alex Chapman
 ! See http://factorcode.org/license.txt for BSD license.
-USING: accessors arrays assocs continuations debugger http.client io json.reader json.writer kernel sequences strings ;
+USING: accessors arrays assocs continuations debugger http.client io json.reader json.writer kernel sequences strings urls ;
 IN: couchdb
 
-TUPLE: server { base string initial: "http://localhost:5984" } ;
+TUPLE: db < url { url url initial: URL" http://localhost:5984" } ;
+C: <db> db
 
-TUPLE: db { server server } { name string } ;
+! : <default-db> 
 
+: set-db-name ( db name 
 : db-path ( db -- path )
-    [ server>> base>> ] [ name>> ] bi "/" swap 3array concat ;
+    [ url>> ] [ name>> ] bi "/" swap 3array concat ;
 
 TUPLE: couchdb-error { data assoc } ;
 C: <couchdb-error> couchdb-error
@@ -41,3 +43,6 @@ USE: prettyprint
     (create-db) [ drop ] [
         <couchdb-error> dup db-exists-error? [ drop ] [ throw ] if
     ] if ;
+
+: delete-db ( db -- )
+