Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Renamed library to purest_json;

Renamed [couchdb] to [rest-json]
  • Loading branch information...
commit 4596bdf268e37e37cc6e0178fb091791a3c8ba0a 1 parent a588c37
@residuum authored
View
22 Makefile
@@ -7,31 +7,31 @@ FLAGS_MINGW = -Wall -static -ansi -O2
LIB_LINUX = -lcurl -ljson
LIB_MINGW = -lcurl -ljson
-COUCHPDB_LINUX = bin/couchpdb.pd_linux
-COUCHPDB_MINGW = bin/couchpdb.dll
+PUREST_JSON_LINUX = bin/purest_json.pd_linux
+PUREST_JSON_MINGW = bin/purest_json.dll
PD_EXE = pdextended
PDINCLUDE = -I../../../diverse/Pd-0.42.5-extended/pd/src
-COUCHPDB_SRC = src/couchpdb.c
+PUREST_JSON_SRC = src/purest_json.c
-default: couchpdb-linux
+default: purest-json-linux
-all: couchpdb-linux couchpdb-mingw doc
+all: purest-json-linux purest-json-mingw doc
-couchpdb-test: couchpdb
- $(PD_EXE) -stderr -lib bin/couchpdb couchpdb-test.pd
+purest-json-test: purest-json-linux
+ $(PD_EXE) -stderr -lib bin/purest_json purest-json-test.pd
-couchpdb-linux:
- $(CC_LINUX) $(FLAGS_LINUX) $(LIB_LINUX) $(PDINCLUDE) $(COUCHPDB_SRC) -o $(COUCHPDB_LINUX)
+purest-json-linux:
+ $(CC_LINUX) $(FLAGS_LINUX) $(LIB_LINUX) $(PDINCLUDE) $(PUREST_JSON_SRC) -o $(PUREST_JSON_LINUX)
-couchpdb-mingw:
+purest-json-mingw:
PATH=/usr/local/mingw/bin:$(PATH)
CPATH=/usr/local/mingw/include
LD_LIBRARY_PATH=/usr/local/mingw/lib
PKG_CONFIG_DIR=/usr/local/mingw/lib/pkgconfig
- $(CC_MINGW) $(FLAGS_MINGW) $(LIB_MINGW) $(PDINCLUDE) $(COUCHPDB_SRC) -o $(COUCHPDB_MINGW)
+ $(CC_MINGW) $(FLAGS_MINGW) $(LIB_MINGW) $(PDINCLUDE) $(PUREST_JSON_SRC) -o $(PUREST_JSON_MINGW)
doc:
doxygen Doxyfile
View
77 bin/json-help.pd
@@ -1,4 +1,4 @@
-#N canvas 0 0 994 514 10;
+#N canvas 0 0 994 506 10;
#X obj 566 321 json-encode;
#X obj 566 390 json-decode;
#X obj 47 -14 json-encode;
@@ -10,15 +10,6 @@ add adds a new key/value pair to the internally stored object. clear
clears the internally stored object. bang outputs the stored object
as a JSON string. If you call add with a value that is already a JSON
string \, then the object will be added as a nested object.;
-#X text 47 118 [json-decode] will accept a JSON string at its input
-and will output the decoded object as a series of lists of key/value
-pairs. Boolean values of TRUE/FALSE will be translated to 1 or 0 \,
-float and integer values will be output as floats. Json-decode will
-try to convert string values to floats \, and if that fails \, will
-output them as symbols. Nested objects and arrays will not be output.
-After the object is fully parsed \, the right outlet will issue a bang
-\, so that you can differenciate between subsequent objects. The messages
-will come as list key value.;
#X msg 548 57 add id 1;
#X text 545 24 Will add key id and value of 1 to object;
#X msg 590 87 add name Residuum;
@@ -30,7 +21,7 @@ JSON object;
#X text 651 202 adding a different value will overwrite the previously
stored one;
#X msg 363 271 clear;
-#X text 359 251 This will clear the object;
+#X text 359 252 This will clear the object;
#X text 696 263 output the value;
#X msg 697 282 bang;
#X obj 656 391 print JSON string;
@@ -64,7 +55,7 @@ stored one;
#X connect 9 2 2 0;
#X connect 12 0 1 0;
#X connect 12 1 4 0;
-#X restore 45 426 pd nested-objects;
+#X restore 57 429 pd nested-objects;
#X obj 697 427 print decoding done;
#X obj 566 427 print decoded values;
#X obj 566 348 t a a;
@@ -133,16 +124,56 @@ JSON object is fully decoded.;
#X connect 23 0 11 0;
#X connect 24 0 0 0;
#X connect 25 0 0 0;
-#X restore 161 427 pd about-decoded-json-strings;
-#X connect 0 0 24 0;
-#X connect 1 0 23 0;
-#X connect 1 1 22 0;
-#X connect 8 0 0 0;
+#X restore 173 430 pd about-decoded-json-strings;
+#X text 46 114 [json-decode] will accept a JSON string at its input
+and will output the decoded object as a series of lists of key/value
+pairs. Boolean values of TRUE/FALSE will be translated to 1 or 0 \,
+float and integer values will be output as floats. Json-decode will
+try to convert string values to floats \, and if that fails \, will
+output them as symbols \, nested objects and arrays are output as strings
+\, that can be parsed. After the object is fully parsed \, the right
+outlet will issue a bang \, so that you can differenciate between subsequent
+objects. The messages will come as list key value.;
+#N canvas 0 0 450 465 json-arrays 0;
+#X obj 42 73 json-encode;
+#X msg 42 33 clear \, array storage textfile \, array storage couchdb
+\, array storage array \, bang;
+#X obj 42 154 json-decode;
+#X obj 42 112 t a a;
+#X text 49 11 This will construct a json array.;
+#X obj 42 191 list trim;
+#X obj 42 224 route storage;
+#X obj 42 255 l2s;
+#X obj 43 313 json-decode;
+#X obj 43 280 t a a;
+#X obj 128 313 print JSON array string;
+#X obj 132 155 print JSON object string;
+#X obj 106 349 print array member done;
+#X obj 43 374 print decoded;
+#X connect 0 0 3 0;
+#X connect 1 0 0 0;
+#X connect 2 0 5 0;
+#X connect 3 0 2 0;
+#X connect 3 1 11 0;
+#X connect 5 0 6 0;
+#X connect 6 0 7 0;
+#X connect 7 0 9 0;
+#X connect 8 0 13 0;
+#X connect 8 1 12 0;
+#X connect 9 0 8 0;
+#X connect 9 1 10 0;
+#X restore 364 430 pd json-arrays;
+#X text 46 232 [json-decode] treats json arrays as a series of objects.
+;
+#X connect 0 0 23 0;
+#X connect 1 0 22 0;
+#X connect 1 1 21 0;
+#X connect 7 0 0 0;
+#X connect 9 0 0 0;
#X connect 10 0 0 0;
-#X connect 11 0 0 0;
+#X connect 12 0 0 0;
#X connect 13 0 0 0;
-#X connect 14 0 0 0;
-#X connect 16 0 0 0;
-#X connect 19 0 0 0;
-#X connect 24 0 1 0;
-#X connect 24 1 20 0;
+#X connect 15 0 0 0;
+#X connect 18 0 0 0;
+#X connect 23 0 1 0;
+#X connect 23 1 19 0;
View
196 bin/couchdb-help.pd → bin/rest-json-help.pd
@@ -1,6 +1,4 @@
-#N canvas 0 0 1163 709 10;
-#X obj 20 -60 couchdb;
-#X obj 630 310 couchdb;
+#N canvas 600 218 704 421 10;
#X text 76 -59 - object for communicating with a CouchDB;
#N canvas 260 56 853 470 CouchDB-basics 0;
#X text 416 71 CRUD documents:;
@@ -64,19 +62,28 @@ layout \, even when stored in the same table.;
#X text 17 61 RESTful interface means \, that all operations are done
with HTTP requests \, depending on the request methods \, different
actions are performed on databases and documents.;
-#X msg 666 88 bang;
-#X obj 17 188 couchdb http://localhost:5984/;
-#X msg 422 -9 url http://localhost:5984/;
-#X obj 630 345 list trim;
-#X obj 629 376 route error ok;
-#X msg 638 443 0;
-#X obj 720 332 t b b;
-#X msg 720 359 1;
-#X text 558 425 Close signal flow on error;
-#X obj 514 493 print error message;
-#X text 779 367 Reopen signal flow after each object.;
-#X obj 669 401 print OK message;
#X text 16 171 Set the base url at creation or use [url( message;
+#X obj 17 243 json-decode;
+#X text 18 286 When OAUTH is implemented \, you will find infos about
+it here;
+#X text 15 226 [couchdb] gets data as JSON objects \, output is the
+same as;
+#X text 17 109 For more infos on how to create \, retrieve \, update
+and delete (CRUD) data \, see:;
+#X obj 17 188 rest-json http://localhost:5984/;
+#X obj 19 -60 rest-json;
+#N canvas 0 0 811 709 couchdb 0;
+#X msg 303 116 bang;
+#X msg 59 19 url http://localhost:5984/;
+#X obj 267 373 list trim;
+#X obj 266 404 route error ok;
+#X msg 275 471 0;
+#X obj 357 360 t b b;
+#X msg 357 387 1;
+#X text 195 453 Close signal flow on error;
+#X obj 151 521 print error message;
+#X text 416 395 Reopen signal flow after each object.;
+#X obj 306 429 print OK message;
#N canvas 576 82 450 511 create-sequencer-data 0;
#X obj 32 12 inlet;
#X obj 103 349 outlet;
@@ -99,85 +106,92 @@ add pitch 880 \, add duration 1000 \, bang \, clear \, add pitch 440
#X connect 6 1 3 1;
#X connect 7 0 2 0;
#X connect 7 0 3 0;
-#X restore 666 115 pd create-sequencer-data;
-#X text 421 -30 1 Sets the base URL.;
-#X text 604 -34 2 Creates database pd-test on server with base URL.
+#X restore 303 143 pd create-sequencer-data;
+#X text 58 -2 1 Sets the base URL.;
+#X text 241 -6 2 Creates database pd-test on server with base URL.
If you do not set the base URL \, then you can also issue this command
with [PUT http://localhost:5984/pd-test/(;
-#X text 663 60 3 Creates some sequencer data and stores the data in
+#X text 300 88 3 Creates some sequencer data and stores the data in
pd-test. Objects contain "pitch" and "duration".;
-#X text 709 191 4 Start sequencer and get first object;
-#X obj 710 238 f;
-#X obj 738 240 + 1;
-#X obj 775 452 route pitch duration;
-#X obj 747 484 pack f f f;
-#X obj 675 560 unpack f f f;
-#X obj 744 593 del;
-#X floatatom 709 595 5 0 0 0 - - -;
-#X text 802 512 first inlet of pack is not used. The reason for that
+#X text 346 219 4 Start sequencer and get first object;
+#X obj 347 266 f;
+#X obj 375 268 + 1;
+#X obj 412 480 route pitch duration;
+#X obj 384 512 pack f f f;
+#X obj 312 588 unpack f f f;
+#X obj 381 621 del;
+#X floatatom 346 623 5 0 0 0 - - -;
+#X text 439 540 first inlet of pack is not used. The reason for that
is explained in the help patch for;
-#X obj 998 528 json-decode;
-#X obj 17 243 json-decode;
-#X obj 485 360 print data;
-#X text 424 174 5 Get database pd-test;
-#X text 382 251 6 Delete database pd-test;
-#X msg 425 197 GET pdtest;
-#X msg 609 30 PUT pdtest;
-#X msg 666 139 PUT pdtest/\$1 \$2;
-#X msg 384 269 DELETE pdtest;
-#X msg 710 267 GET pdtest/\$1;
-#X text 18 286 When OAUTH is implemented \, you will find infos about
-it here;
-#X text 421 -65 This example will create a database and store values
+#X obj 635 556 json-decode;
+#X obj 122 388 print data;
+#X text 61 202 5 Get database pd-test;
+#X text 19 279 6 Delete database pd-test;
+#X msg 62 225 GET pdtest;
+#X msg 246 58 PUT pdtest;
+#X msg 303 167 PUT pdtest/\$1 \$2;
+#X msg 21 297 DELETE pdtest;
+#X msg 347 295 GET pdtest/\$1;
+#X text 58 -37 This example will create a database and store values
to be used by a simple sequencer.;
-#X msg 710 210 0;
-#X obj 675 529 spigot 1;
-#X obj 969 203 spigot;
-#X obj 1002 169 tgl 15 0 empty empty empty 17 7 0 10 -262144 -1 -1
-0 1;
-#X obj 666 164 print Put command;
-#X obj 598 398 t b a b;
-#X text 949 153 toggle only when using sequencer;
-#X msg 491 432 0;
-#X text 463 409 restart GET sequence;
-#X text 15 226 [couchdb] gets data as JSON objects \, output is the
-same as;
-#X text 17 109 For more infos on how to create \, retrieve \, update
-and delete (CRUD) data \, see:;
-#X connect 1 0 12 0;
-#X connect 1 0 37 0;
-#X connect 1 1 15 0;
-#X connect 9 0 22 0;
-#X connect 11 0 1 0;
-#X connect 12 0 13 0;
-#X connect 13 0 52 0;
-#X connect 13 1 20 0;
-#X connect 13 2 29 0;
-#X connect 14 0 48 1;
+#X msg 347 238 0;
+#X obj 312 557 spigot 1;
+#X obj 606 231 spigot;
+#X obj 639 197 tgl 15 0 empty empty empty 17 7 0 10 -262144 -1 -1 0
+1;
+#X obj 303 192 print Put command;
+#X obj 235 426 t b a b;
+#X text 586 181 toggle only when using sequencer;
+#X msg 128 460 0;
+#X text 100 437 restart GET sequence;
+#X obj 267 338 rest-json;
+#X connect 0 0 11 0;
+#X connect 1 0 43 0;
+#X connect 2 0 3 0;
+#X connect 3 0 39 0;
+#X connect 3 1 10 0;
+#X connect 3 2 18 0;
+#X connect 4 0 35 1;
+#X connect 5 0 6 0;
+#X connect 5 1 19 0;
+#X connect 6 0 35 1;
+#X connect 11 0 30 0;
+#X connect 16 0 17 0;
+#X connect 16 0 32 0;
+#X connect 17 0 16 1;
+#X connect 18 0 19 1;
+#X connect 18 1 19 2;
+#X connect 19 0 35 0;
+#X connect 20 1 22 0;
+#X connect 20 2 21 0;
+#X connect 21 0 36 0;
+#X connect 28 0 43 0;
+#X connect 29 0 43 0;
+#X connect 30 0 38 0;
+#X connect 30 0 43 0;
+#X connect 31 0 43 0;
+#X connect 32 0 43 0;
+#X connect 34 0 16 0;
+#X connect 35 0 20 0;
+#X connect 36 0 16 0;
+#X connect 37 0 36 1;
+#X connect 39 0 41 0;
+#X connect 39 1 8 0;
+#X connect 39 2 4 0;
+#X connect 41 0 36 0;
+#X connect 43 0 2 0;
+#X connect 43 0 25 0;
+#X connect 43 1 5 0;
+#X restore 25 379 pd couchdb;
+#X obj 458 216 rest-json;
+#X obj 457 300 print data;
+#X text 24 343 Here is a complex example for using [rest-json] to communicate
+with CouchDB. It uses GET \, POST and DELETE request methods. [rest-json]
+also supports POST requests.;
+#X msg 337 89 GET http://search.twitter.com/search.json?q=%23puredata
+;
+#X msg 346 129 GET https://ajax.googleapis.com/ajax/services/search/web?v=2.0&q=puredata
+;
#X connect 15 0 16 0;
-#X connect 15 1 30 0;
-#X connect 16 0 48 1;
-#X connect 22 0 42 0;
-#X connect 27 0 28 0;
-#X connect 27 0 44 0;
-#X connect 28 0 27 1;
-#X connect 29 0 30 1;
-#X connect 29 1 30 2;
-#X connect 30 0 48 0;
-#X connect 31 1 33 0;
-#X connect 31 2 32 0;
-#X connect 32 0 49 0;
-#X connect 40 0 1 0;
-#X connect 41 0 1 0;
-#X connect 42 0 1 0;
-#X connect 42 0 51 0;
-#X connect 43 0 1 0;
-#X connect 44 0 1 0;
-#X connect 47 0 27 0;
-#X connect 48 0 31 0;
-#X connect 49 0 27 0;
-#X connect 50 0 49 1;
-#X connect 52 0 54 0;
-#X connect 52 1 18 0;
-#X connect 52 2 14 0;
-#X connect 54 0 49 0;
+#X connect 18 0 15 0;
+#X connect 19 0 15 0;
View
100 couchpdb-test.pd
@@ -1,100 +0,0 @@
-#N canvas 43 32 985 691 10;
-#X obj 154 306 couchdb;
-#X msg 129 46 url http://127.0.0.1:5984/;
-#X obj 658 499 couchdb http://127.0.0.1:5984/;
-#X obj 368 88 json-encode;
-#X msg 586 87 bang;
-#X msg 701 77 clear;
-#X obj 546 190 print json-encoded data;
-#X obj 363 126 t a a;
-#X obj 513 265 json-decode;
-#X obj 520 317 print decode json data;
-#X msg 340 5 add value 440;
-#X obj 132 617 line;
-#X floatatom 132 663 5 0 0 0 - - -;
-#X obj 131 564 pack f f f;
-#X msg 131 592 \$1 \, \$2 \$3;
-#X msg 576 3 add start 10;
-#X obj 171 535 unpack f;
-#X obj 233 538 unpack f;
-#X obj 94 536 unpack f;
-#X obj 169 353 list trim;
-#X obj 46 389 t b b b b;
-#X obj 361 543 print id;
-#X obj 98 515 f;
-#X obj 175 514 f;
-#X obj 237 517 f;
-#X msg 765 30 add name first note;
-#X obj 328 459 print name;
-#X msg 442 5 add duration 1000;
-#X msg 686 -1 add name wrong name;
-#X obj 139 392 route start value duration _id name on;
-#X obj 464 452 f;
-#X msg 717 210 add on TRUE;
-#X msg 167 84 PUT test;
-#X msg 190 125 GET test;
-#X msg 238 267 DELETE test;
-#X obj 309 314 print couchdb return;
-#X msg 222 199 GET test/1;
-#X msg 213 172 PUT test/1 \$1;
-#X msg 658 450 GET _uuids?count=4;
-#X obj 658 567 route uuids;
-#X obj 658 537 list trim;
-#X obj 658 620 json-decode;
-#X obj 777 653 print array-done;
-#X obj 658 653 print array-decode;
-#X obj 658 592 l2s;
-#X msg 780 91 array var yabba;
-#X msg 782 112 array var dabba;
-#X msg 788 140 array var doo;
-#X connect 0 0 19 0;
-#X connect 0 0 35 0;
-#X connect 0 1 20 0;
-#X connect 1 0 0 0;
-#X connect 2 0 40 0;
-#X connect 3 0 7 0;
-#X connect 4 0 3 0;
-#X connect 5 0 3 0;
-#X connect 7 0 37 0;
-#X connect 7 0 8 0;
-#X connect 7 1 6 0;
-#X connect 8 0 9 0;
-#X connect 10 0 3 0;
-#X connect 11 0 12 0;
-#X connect 13 0 14 0;
-#X connect 14 0 11 0;
-#X connect 15 0 3 0;
-#X connect 16 0 13 1;
-#X connect 17 0 13 2;
-#X connect 18 0 13 0;
-#X connect 19 0 29 0;
-#X connect 20 0 22 0;
-#X connect 20 1 23 0;
-#X connect 20 2 24 0;
-#X connect 22 0 18 0;
-#X connect 23 0 16 0;
-#X connect 24 0 17 0;
-#X connect 25 0 3 0;
-#X connect 27 0 3 0;
-#X connect 28 0 3 0;
-#X connect 29 0 22 1;
-#X connect 29 1 23 1;
-#X connect 29 2 24 1;
-#X connect 29 3 21 0;
-#X connect 29 4 26 0;
-#X connect 29 5 30 0;
-#X connect 31 0 3 0;
-#X connect 32 0 0 0;
-#X connect 33 0 0 0;
-#X connect 34 0 0 0;
-#X connect 36 0 0 0;
-#X connect 37 0 0 0;
-#X connect 38 0 2 0;
-#X connect 39 0 44 0;
-#X connect 40 0 39 0;
-#X connect 41 0 43 0;
-#X connect 41 1 42 0;
-#X connect 44 0 41 0;
-#X connect 45 0 3 0;
-#X connect 46 0 3 0;
-#X connect 47 0 3 0;
View
109 purest-json-test.pd
@@ -0,0 +1,109 @@
+#N canvas 43 32 985 691 10;
+#X msg 129 46 url http://127.0.0.1:5984/;
+#X obj 368 88 json-encode;
+#X msg 586 87 bang;
+#X msg 701 77 clear;
+#X obj 546 190 print json-encoded data;
+#X obj 363 126 t a a;
+#X obj 513 265 json-decode;
+#X obj 520 317 print decode json data;
+#X msg 340 5 add value 440;
+#X obj 132 617 line;
+#X floatatom 132 663 5 0 0 0 - - -;
+#X obj 131 564 pack f f f;
+#X msg 131 592 \$1 \, \$2 \$3;
+#X msg 576 3 add start 10;
+#X obj 171 535 unpack f;
+#X obj 233 538 unpack f;
+#X obj 94 536 unpack f;
+#X obj 169 353 list trim;
+#X obj 46 389 t b b b b;
+#X obj 361 543 print id;
+#X obj 98 515 f;
+#X obj 175 514 f;
+#X obj 237 517 f;
+#X msg 765 30 add name first note;
+#X obj 328 459 print name;
+#X msg 442 5 add duration 1000;
+#X msg 686 -1 add name wrong name;
+#X obj 139 392 route start value duration _id name on;
+#X obj 464 452 f;
+#X msg 717 210 add on TRUE;
+#X msg 167 84 PUT test;
+#X msg 190 125 GET test;
+#X msg 238 267 DELETE test;
+#X obj 309 314 print couchdb return;
+#X msg 222 199 GET test/1;
+#X msg 213 172 PUT test/1 \$1;
+#X msg 513 444 GET _uuids?count=4;
+#X obj 513 561 route uuids;
+#X obj 513 531 list trim;
+#X obj 513 614 json-decode;
+#X obj 632 647 print array-done;
+#X obj 513 647 print array-decode;
+#X obj 513 586 l2s;
+#X msg 780 91 array var yabba;
+#X msg 782 112 array var dabba;
+#X msg 788 140 array var doo;
+#X obj 154 306 rest-json;
+#X obj 513 493 rest-json http://127.0.0.1:5984/;
+#X obj 870 451 rest-json;
+#X obj 869 535 print data;
+#X msg 749 324 GET http://search.twitter.com/search.json?q=%23puredata
+;
+#X msg 758 364 GET https://ajax.googleapis.com/ajax/services/search/web?v=2.0&q=puredata
+;
+#X connect 0 0 46 0;
+#X connect 1 0 5 0;
+#X connect 2 0 1 0;
+#X connect 3 0 1 0;
+#X connect 5 0 35 0;
+#X connect 5 0 6 0;
+#X connect 5 1 4 0;
+#X connect 6 0 7 0;
+#X connect 8 0 1 0;
+#X connect 9 0 10 0;
+#X connect 11 0 12 0;
+#X connect 12 0 9 0;
+#X connect 13 0 1 0;
+#X connect 14 0 11 1;
+#X connect 15 0 11 2;
+#X connect 16 0 11 0;
+#X connect 17 0 27 0;
+#X connect 18 0 20 0;
+#X connect 18 1 21 0;
+#X connect 18 2 22 0;
+#X connect 20 0 16 0;
+#X connect 21 0 14 0;
+#X connect 22 0 15 0;
+#X connect 23 0 1 0;
+#X connect 25 0 1 0;
+#X connect 26 0 1 0;
+#X connect 27 0 20 1;
+#X connect 27 1 21 1;
+#X connect 27 2 22 1;
+#X connect 27 3 19 0;
+#X connect 27 4 24 0;
+#X connect 27 5 28 0;
+#X connect 29 0 1 0;
+#X connect 30 0 46 0;
+#X connect 31 0 46 0;
+#X connect 32 0 46 0;
+#X connect 34 0 46 0;
+#X connect 35 0 46 0;
+#X connect 36 0 47 0;
+#X connect 37 0 42 0;
+#X connect 38 0 37 0;
+#X connect 39 0 41 0;
+#X connect 39 1 40 0;
+#X connect 42 0 39 0;
+#X connect 43 0 1 0;
+#X connect 44 0 1 0;
+#X connect 45 0 1 0;
+#X connect 46 0 17 0;
+#X connect 46 0 33 0;
+#X connect 46 1 18 0;
+#X connect 47 0 38 0;
+#X connect 48 0 49 0;
+#X connect 50 0 48 0;
+#X connect 51 0 48 0;
View
4 src/json.c
@@ -10,7 +10,7 @@ void setup_json_encoder(void) {
class_addmethod(json_encode_class, (t_method)json_encode_add, gensym("add"), A_GIMME, 0);
class_addmethod(json_encode_class, (t_method)json_encode_array_add, gensym("array"), A_GIMME, 0);
class_addmethod(json_encode_class, (t_method)json_encode_clear, gensym("clear"), A_GIMME, 0);
- class_sethelpsymbol(json_encode_class, gensym("json-help"));
+ class_sethelpsymbol(json_encode_class, gensym("json"));
}
/**
@@ -242,7 +242,7 @@ void setup_json_decoder(void) {
json_decode_class = class_new(gensym("json-decode"), (t_newmethod)json_decode_new,
0, sizeof(t_json_decode), 0, A_GIMME, 0);
class_addsymbol(json_decode_class, (t_method)json_decode_string);
- class_sethelpsymbol(json_decode_class, gensym("json-help"));
+ class_sethelpsymbol(json_decode_class, gensym("json"));
}
/**
View
12 src/couchpdb.c → src/purest_json.c
@@ -1,12 +1,12 @@
-#include "couchpdb.h"
-#include "couchdb.c"
+#include "purest_json.h"
+#include "rest.c"
#include "json.c"
-void couchpdb_setup(void) {
- post("CouchPdb version 0.1: A library for connecting to CouchDB and encoding and decoding JSON data from Puredata.");
+void purest_json_setup(void) {
+ post("PuREST JSON version 0.2: A library for executing HTTP queries and encoding and decoding JSON data from Puredata.");
post("(c) Thomas Mayer (Residuum) 2011");
- post("Get the latest source from https://github.com/residuum/CouchPdb");
- setup_couchdb();
+ post("Get the latest source from https://github.com/residuum/PuRestJson");
+ setup_rest();
setup_json_encoder();
setup_json_decoder();
}
View
28 src/couchpdb.h → src/purest_json.h
@@ -6,8 +6,8 @@
#include <curl/curl.h>
#include <json/json.h>
-#define MAX_ARRAY_SIZE 128
-#define MAX_STRING_SIZE 512
+#define MAX_ARRAY_SIZE 256
+#define MAX_STRING_SIZE 2048
typedef struct memory_struct {
char *memory;
@@ -20,13 +20,13 @@ typedef struct key_value_pair{
short is_array;
} t_key_value_pair;
-typedef struct couchdb {
+typedef struct rest {
t_object x_ob;
t_outlet *done_outlet;
int out_count;
char couch_url[MAX_STRING_SIZE];
t_atom out[MAX_ARRAY_SIZE];
-} t_couchdb;
+} t_rest;
typedef struct json_encode {
t_object x_ob;
@@ -39,19 +39,19 @@ typedef struct json_decode {
t_outlet *done_outlet;
} t_json_decode;
-/* couchdb */
-t_class *couchdb_class;
-void setup_couchdb(void);
-void *couchdb_new(t_symbol *selector, int argcount, t_atom *argvec);
+/* rest */
+t_class *rest_class;
+void setup_rest(void);
+void *rest_new(t_symbol *selector, int argcount, t_atom *argvec);
-void couchdb_command(t_couchdb *x, t_symbol *selector, int argcount, t_atom *argvec);
-void couchdb_oauth(t_couchdb *x, t_symbol *selector, int argcount, t_atom *argvec);
-void couchdb_url(t_couchdb *x, t_symbol *selector, int argcount, t_atom *argvec);
+void rest_command(t_rest *x, t_symbol *selector, int argcount, t_atom *argvec);
+void rest_oauth(t_rest *x, t_symbol *selector, int argcount, t_atom *argvec);
+void rest_url(t_rest *x, t_symbol *selector, int argcount, t_atom *argvec);
static size_t write_memory_callback(void *ptr, size_t size, size_t nmemb, void *data);
static size_t read_memory_callback(void *ptr, size_t size, size_t nmemb, void *data);
-void test_connection(char *couch_url, t_couchdb *x);
-void execute_couchdb(char *couch_url, char *request_type, char *database, char *parameters, t_couchdb *x);
+void test_connection(char *couch_url, t_rest *x);
+void execute_rest(char *couch_url, char *request_type, char *database, char *parameters, t_rest *x);
/* json-encode */
t_class *json_encode_class;
@@ -74,6 +74,6 @@ void json_decode_string(t_json_decode *x, t_symbol *data);
void output_json(json_object *jobj, t_outlet *data_outlet, t_outlet *done_outlet);
/* general */
-void couchpdb_setup(void);
+void purest_json_setup(void);
char *remove_backslashes(char *source_string);
int str_ccmp(const char *s1, const char *s2);
View
48 src/couchdb.c → src/rest.c
@@ -1,26 +1,26 @@
/**
- * Setup couchdb
+ * Setup rest
*
- * Performs setup of couchdb object, initializes methods for inlet
+ * Performs setup of rest object, initializes methods for inlet
*/
-void setup_couchdb(void) {
- couchdb_class = class_new(gensym("couchdb"), (t_newmethod)couchdb_new,
- 0, sizeof(t_couchdb), 0, A_GIMME, 0);
- class_addmethod(couchdb_class, (t_method)couchdb_oauth, gensym("oauth"), A_GIMME, 0);
- class_addmethod(couchdb_class, (t_method)couchdb_url, gensym("url"), A_GIMME, 0);
- class_addmethod(couchdb_class, (t_method)couchdb_command, gensym("PUT"), A_GIMME, 0);
- class_addmethod(couchdb_class, (t_method)couchdb_command, gensym("GET"), A_GIMME, 0);
- class_addmethod(couchdb_class, (t_method)couchdb_command, gensym("DELETE"), A_GIMME, 0);
- class_addmethod(couchdb_class, (t_method)couchdb_command, gensym("POST"), A_GIMME, 0);
- class_sethelpsymbol(couchdb_class, gensym("couchdb-help"));
+void setup_rest(void) {
+ rest_class = class_new(gensym("rest-json"), (t_newmethod)rest_new,
+ 0, sizeof(t_rest), 0, A_GIMME, 0);
+ class_addmethod(rest_class, (t_method)rest_oauth, gensym("oauth"), A_GIMME, 0);
+ class_addmethod(rest_class, (t_method)rest_url, gensym("url"), A_GIMME, 0);
+ class_addmethod(rest_class, (t_method)rest_command, gensym("PUT"), A_GIMME, 0);
+ class_addmethod(rest_class, (t_method)rest_command, gensym("GET"), A_GIMME, 0);
+ class_addmethod(rest_class, (t_method)rest_command, gensym("DELETE"), A_GIMME, 0);
+ class_addmethod(rest_class, (t_method)rest_command, gensym("POST"), A_GIMME, 0);
+ class_sethelpsymbol(rest_class, gensym("rest-json"));
}
/**
- * Performs couchdb method
+ * Performs rest method
*
- * Executes a couchdb command
+ * Executes a rest command
*/
-void couchdb_command(t_couchdb *x, t_symbol *selector, int argcount, t_atom *argvec) {
+void rest_command(t_rest *x, t_symbol *selector, int argcount, t_atom *argvec) {
char *request_type;
char database[MAX_STRING_SIZE];
char parameter[MAX_STRING_SIZE];
@@ -33,16 +33,16 @@ void couchdb_command(t_couchdb *x, t_symbol *selector, int argcount, t_atom *arg
if (argcount > 1) {
atom_string(argvec + 1, parameter, MAX_STRING_SIZE);
}
- execute_couchdb(x->couch_url, request_type, database, parameter, x);
+ execute_rest(x->couch_url, request_type, database, parameter, x);
break;
}
}
-void couchdb_oauth(t_couchdb *x, t_symbol *selector, int argcount, t_atom *argvec) {
+void rest_oauth(t_rest *x, t_symbol *selector, int argcount, t_atom *argvec) {
error("OAUTH not implemented yet.");
}
-void couchdb_url(t_couchdb *x, t_symbol *selector, int argcount, t_atom *argvec) {
+void rest_url(t_rest *x, t_symbol *selector, int argcount, t_atom *argvec) {
switch (argcount) {
case 1:
if (argvec[0].a_type != A_SYMBOL) {
@@ -60,8 +60,8 @@ void couchdb_url(t_couchdb *x, t_symbol *selector, int argcount, t_atom *argvec)
}
}
-void *couchdb_new(t_symbol *selector, int argcount, t_atom *argvec) {
- t_couchdb *x = (t_couchdb *)pd_new(couchdb_class);
+void *rest_new(t_symbol *selector, int argcount, t_atom *argvec) {
+ t_rest *x = (t_rest *)pd_new(rest_class);
switch (argcount) {
case 1:
if (argvec[0].a_type != A_SYMBOL) {
@@ -82,7 +82,7 @@ void *couchdb_new(t_symbol *selector, int argcount, t_atom *argvec) {
return (void *)x;
}
-void test_connection(char *couch_url, t_couchdb *x) {
+void test_connection(char *couch_url, t_rest *x) {
CURL *curl_handle;
CURLcode result;
t_memory_struct chunk;
@@ -111,7 +111,7 @@ void test_connection(char *couch_url, t_couchdb *x) {
}
}
-void execute_couchdb(char *couch_url, char *request_type, char *database, char *parameters, t_couchdb *x){
+void execute_rest(char *couch_url, char *request_type, char *database, char *parameters, t_rest *x){
char real_url[strlen(couch_url) + strlen(database)];
char *cleaned_parameters = remove_backslashes(parameters);
CURL *curl_handle;
@@ -145,8 +145,12 @@ void execute_couchdb(char *couch_url, char *request_type, char *database, char *
result = curl_easy_perform(curl_handle);
if (result == CURLE_OK) {
/* Parse JSON */
+ post("Before parsing");
+ post("%s", out_memory.memory);
json_object *jobj = json_tokener_parse(out_memory.memory);
+ post("After parsing");
output_json(jobj, x->x_ob.ob_outlet, x->done_outlet);
+ post("After output");
/* Free memory */
if (out_memory.memory) {
free(out_memory.memory);
Please sign in to comment.
Something went wrong with that request. Please try again.