Skip to content
This repository
Browse code

Examples and help patches, small bugfixes.

  • Loading branch information...
commit 3872a382c5d310c56d25a4886d33dce50b14498f 1 parent ab64480
Thomas Mayer authored
1  Makefile
@@ -266,6 +266,7 @@ all: $(SOURCES:.c=.$(EXTENSION)) $(SHARED_LIB)
266 266
 %.$(EXTENSION): %.o $(SHARED_LIB)
267 267
 	$(CC) $(ALL_LDFLAGS) -o "$*.$(EXTENSION)" "$*.o"  $(ALL_LIBS) $(SHARED_LIB)
268 268
 	chmod a-x "$*.$(EXTENSION)"
  269
+	chmod a-x "$(SHARED_LIB)"
269 270
 
270 271
 # this links everything into a single binary file
271 272
 $(LIBRARY_NAME): $(SOURCES:.c=.o) $(LIBRARY_NAME).o lib$(LIBRARY_NAME).o
2  examples/purest-json-test.pd
... ...
@@ -1,4 +1,4 @@
1  
-#N canvas 61 51 1002 589 10;
  1
+#N canvas 59 51 1002 589 10;
2 2
 #X declare -lib purest_json;
3 3
 #X msg 9 38 url http://127.0.0.1:5984/;
4 4
 #X obj 363 136 json-encode;
70  examples/statistics.pd
... ...
@@ -1,4 +1,4 @@
1  
-#N canvas 395 51 964 694 10;
  1
+#N canvas 393 51 964 694 10;
2 2
 #X declare -lib purest_json;
3 3
 #X obj 143 145 version;
4 4
 #X obj 104 94 bng 15 250 50 0 empty empty Warning:_Clicking_here_will_send_data_about_your_Pd_version_to_an_open_databas*
@@ -12,13 +12,13 @@
12 12
 #X msg 207 271 add distribution \$1;
13 13
 #X msg 228 295 add compilation-date \$1;
14 14
 #X msg 247 319 add compilation-time \$1;
15  
-#X obj 104 540 print raw-return;
  15
+#X obj 18 540 print raw-return;
16 16
 #X obj 6 484 print command;
17  
-#X text 452 482 Parameter 1: Base Url;
18  
-#X text 452 470 Using 4 parameters to get authentication cookie:;
19  
-#X text 452 493 Parameter 2: Path to Login;
20  
-#X text 452 516 Parameter 4: Password;
21  
-#X text 452 505 Parameter 3: Username;
  17
+#X text 488 482 Parameter 1: Base Url;
  18
+#X text 488 470 Using 4 parameters to get authentication cookie:;
  19
+#X text 488 493 Parameter 2: Path to Login;
  20
+#X text 488 516 Parameter 4: Password;
  21
+#X text 488 505 Parameter 3: Username;
22 22
 #X text 200 143 We get version information about Puredata for the statistics
23 23
 ;
24 24
 #X text 184 382 We create a JSON object from the version information
@@ -28,30 +28,27 @@ The example sends data to a BigCouch instance hosted by http://cloudant.com/.
28 28
 ;
29 29
 #X text 26 43 The data will only include information from the output
30 30
 of [version] \, and nothing else.;
31  
-#X obj 413 568 print status-information;
  31
+#X obj 449 555 print status-information;
32 32
 #X obj 104 119 t b b;
33 33
 #X text 240 445 We store the data;
34  
-#X obj 104 473 rest-json http://ix.residuum.org/ login.php puredata
35  
-statistics;
36 34
 #X msg 104 424 PUT statistics.php \$1;
37 35
 #X text 682 55 Different possibilities for authentication:;
38 36
 #N canvas 44 51 511 356 init 0;
39 37
 #X obj 32 281 print;
40 38
 #X text 31 51 Set base url \, login path \, username and password on
41 39
 initialization;
42  
-#X obj 32 220 rest-json https://residuum.cloudant.com/ _session nownestortedidirevinesti
43  
-dBukE2WR07A7PtE8FIXECl8c;
44 40
 #X msg 71 157 GET purest-json-stat/_design/statistics/_view/usage_by_distribution?group=true
45 41
 ;
46 42
 #X msg 32 85 GET purest-json-stat/_design/statistics/_view/usage_by_version?group=true
47 43
 ;
48  
-#X connect 2 0 0 0;
49  
-#X connect 3 0 2 0;
50  
-#X connect 4 0 2 0;
  44
+#X obj 32 220 rest https://residuum.cloudant.com/ _session nownestortedidirevinesti
  45
+dBukE2WR07A7PtE8FIXECl8c;
  46
+#X connect 2 0 4 0;
  47
+#X connect 3 0 4 0;
  48
+#X connect 4 0 0 0;
51 49
 #X restore 684 74 pd init with parameters;
52  
-#N canvas 571 65 493 359 use 0;
  50
+#N canvas 567 61 493 359 use 0;
53 51
 #X obj 41 280 print;
54  
-#X obj 41 227 rest-json;
55 52
 #X text 21 42 Use the url method to set the parameters;
56 53
 #X msg 22 66 url https://residuum.cloudant.com/ _session nownestortedidirevinesti
57 54
 dBukE2WR07A7PtE8FIXECl8c;
@@ -59,13 +56,13 @@ dBukE2WR07A7PtE8FIXECl8c;
59 56
 ;
60 57
 #X msg 63 110 GET purest-json-stat/_design/statistics/_view/usage_by_version?group=true
61 58
 ;
62  
-#X connect 1 0 0 0;
63  
-#X connect 3 0 1 0;
64  
-#X connect 4 0 1 0;
65  
-#X connect 5 0 1 0;
  59
+#X obj 41 227 rest;
  60
+#X connect 2 0 5 0;
  61
+#X connect 3 0 5 0;
  62
+#X connect 4 0 5 0;
  63
+#X connect 5 0 0 0;
66 64
 #X restore 685 99 pd use url method;
67  
-#N canvas 233 403 538 332 basic 0;
68  
-#X obj 43 267 rest-json;
  65
+#N canvas 229 399 538 332 basic 0;
69 66
 #X obj 43 294 print;
70 67
 #X msg 43 89 GET https://nownestortedidirevinesti:dBukE2WR07A7PtE8FIXECl8c@residuum.cloudant.com/purest-json-stat/_design/statistics/_view/usage_by_version?group=true
71 68
 ;
@@ -74,22 +71,27 @@ dBukE2WR07A7PtE8FIXECl8c;
74 71
 #X text 39 27 Other possibilities for basic HTTP authentication: send
75 72
 the username and password seperated by a colon (:) after the specification
76 73
 of the protocol \, followed by an at sign (@) and the url.;
77  
-#X connect 0 0 1 0;
78  
-#X connect 2 0 0 0;
79  
-#X connect 3 0 0 0;
  74
+#X obj 43 267 rest;
  75
+#X connect 1 0 4 0;
  76
+#X connect 2 0 4 0;
  77
+#X connect 4 0 0 0;
80 78
 #X restore 685 124 pd basic http authentication;
81  
-#N canvas 795 401 493 359 basic 0;
  79
+#N canvas 791 397 493 359 basic 0;
82 80
 #X obj 34 269 print;
83 81
 #X text 29 38 The trick with : and @ also works for the base url.;
84 82
 #X msg 77 101 GET usage_by_distribution?group=true;
85 83
 #X msg 34 64 GET usage_by_version?group=true;
86  
-#X obj 34 144 rest-json https://nownestortedidirevinesti:dBukE2WR07A7PtE8FIXECl8c@residuum.cloudant.com/purest-json-stat/_design/statistics/_view/
  84
+#X obj 34 144 rest https://nownestortedidirevinesti:dBukE2WR07A7PtE8FIXECl8c@residuum.cloudant.com/purest-json-stat/_design/statistics/_view/
87 85
 ;
88 86
 #X connect 2 0 4 0;
89 87
 #X connect 3 0 4 0;
90 88
 #X connect 4 0 0 0;
91 89
 #X restore 685 148 pd basic http authentication in base url;
92 90
 #X obj 25 583 import purest_json;
  91
+#X obj 104 473 rest http://ix.residuum.org/ login.php puredata statistics
  92
+;
  93
+#X obj 159 531 json-decode;
  94
+#X obj 159 577 print json-data;
93 95
 #X connect 0 0 2 0;
94 96
 #X connect 1 0 23 0;
95 97
 #X connect 2 0 3 0;
@@ -102,13 +104,15 @@ of the protocol \, followed by an at sign (@) and the url.;
102 104
 #X connect 4 0 6 0;
103 105
 #X connect 5 0 6 0;
104 106
 #X connect 6 0 7 0;
105  
-#X connect 6 0 26 0;
  107
+#X connect 6 0 25 0;
106 108
 #X connect 8 0 6 0;
107 109
 #X connect 9 0 6 0;
108 110
 #X connect 10 0 6 0;
109 111
 #X connect 23 0 6 0;
110 112
 #X connect 23 1 0 0;
111  
-#X connect 25 0 11 0;
112  
-#X connect 25 2 22 0;
113  
-#X connect 26 0 12 0;
114  
-#X connect 26 0 25 0;
  113
+#X connect 25 0 12 0;
  114
+#X connect 25 0 32 0;
  115
+#X connect 32 0 11 0;
  116
+#X connect 32 0 33 0;
  117
+#X connect 32 1 22 0;
  118
+#X connect 33 0 34 0;
126  examples/the-sound-of-money.pd
... ...
@@ -1,69 +1,73 @@
1  
-#N canvas 448 51 756 544 10;
  1
+#N canvas 446 51 756 644 10;
2 2
 #X declare -lib zexy -lib purest_json;
3  
-#X obj 156 36 rest-json;
4  
-#X obj 188 462 dac~;
5  
-#X obj 193 173 fifop;
6  
-#X msg 349 111 stop;
7  
-#X obj 195 382 *~ 0;
8  
-#X msg 368 327 0;
9  
-#X msg 406 329 1;
  3
+#X obj 188 521 dac~;
  4
+#X obj 193 232 fifop;
  5
+#X msg 349 170 stop;
  6
+#X obj 195 441 *~ 0;
  7
+#X msg 368 386 0;
  8
+#X msg 406 388 1;
10 9
 #X obj 12 99 print original-data;
11  
-#X obj 193 288 phasor~ 100;
12  
-#X obj 194 348 bp~ 200 5;
13  
-#X obj 193 201 t f f;
14  
-#X obj 253 146 metro 500;
15  
-#X obj 193 314 -~ 0.5;
16  
-#X obj 193 258 line \$1 20;
17  
-#X obj 266 259 line \$1 20;
  10
+#X obj 193 347 phasor~ 100;
  11
+#X obj 194 407 bp~ 200 5;
  12
+#X obj 193 260 t f f;
  13
+#X obj 253 205 metro 500;
  14
+#X obj 193 373 -~ 0.5;
  15
+#X obj 193 317 line \$1 20;
  16
+#X obj 266 318 line \$1 20;
18 17
 #X msg 156 -44 GET http://api.scraperwiki.com/api/1.0/datastore/sqlite?format=jsondict&name=daily_bitcoin_prices&query=select%20datetime(Date%2C%20%22unixepoch%22)%20as%20date%2C%20USD%2C%20EUR%20from%20swdata
19 18
 ;
20  
-#X obj 156 64 list trim;
21  
-#X obj 156 90 route EUR USD;
22  
-#X obj 253 91 spigot 1;
23  
-#X obj 349 259 t b b b;
24  
-#X obj 253 113 t b b b;
25  
-#X msg 348 50 0;
26  
-#X msg 388 50 1;
27  
-#X text 392 84 start metro only once \, as each json object from the
  19
+#X obj 156 123 list trim;
  20
+#X obj 156 149 route EUR USD;
  21
+#X obj 253 150 spigot 1;
  22
+#X obj 349 318 t b b b;
  23
+#X obj 253 172 t b b b;
  24
+#X msg 348 109 0;
  25
+#X msg 388 109 1;
  26
+#X text 392 143 start metro only once \, as each json object from the
28 27
 array outputs a bang at the right outlet of rest-json;
29  
-#X text 400 171 use a fifo buffer for the values (from zexy);
30  
-#X obj 266 232 * 20;
31  
-#X obj 193 230 * 10;
32  
-#X obj 19 241 import zexy purest_json;
33  
-#X obj 196 406 *~ 0;
34  
-#X obj 492 242 vsl 15 128 0 1 0 0 empty empty volume 0 -9 0 10 -262144
  28
+#X text 400 230 use a fifo buffer for the values (from zexy);
  29
+#X obj 266 291 * 20;
  30
+#X obj 193 289 * 10;
  31
+#X obj 19 300 import zexy purest_json;
  32
+#X obj 196 465 *~ 0;
  33
+#X obj 492 301 vsl 15 128 0 1 0 0 empty empty volume 0 -9 0 10 -262144
35 34
 -1 -1 0 1;
36  
-#X connect 0 0 7 0;
37  
-#X connect 0 0 16 0;
38  
-#X connect 0 1 18 0;
  35
+#X obj 156 36 rest;
  36
+#X obj 156 71 json-decode;
  37
+#X obj 31 183 print decoded-data;
  38
+#X connect 1 0 9 0;
  39
+#X connect 1 1 18 0;
39 40
 #X connect 2 0 10 0;
40  
-#X connect 2 1 19 0;
41  
-#X connect 3 0 11 0;
42  
-#X connect 4 0 28 0;
43  
-#X connect 5 0 4 1;
44  
-#X connect 6 0 4 1;
45  
-#X connect 8 0 12 0;
46  
-#X connect 9 0 4 0;
47  
-#X connect 10 0 26 0;
48  
-#X connect 10 1 25 0;
49  
-#X connect 11 0 2 0;
50  
-#X connect 12 0 9 0;
51  
-#X connect 13 0 8 0;
52  
-#X connect 14 0 9 1;
53  
-#X connect 15 0 0 0;
54  
-#X connect 16 0 17 0;
55  
-#X connect 17 1 2 0;
56  
-#X connect 18 0 20 0;
57  
-#X connect 19 0 3 0;
  41
+#X connect 3 0 27 0;
  42
+#X connect 4 0 3 1;
  43
+#X connect 5 0 3 1;
  44
+#X connect 7 0 11 0;
  45
+#X connect 8 0 3 0;
  46
+#X connect 9 0 25 0;
  47
+#X connect 9 1 24 0;
  48
+#X connect 10 0 1 0;
  49
+#X connect 11 0 8 0;
  50
+#X connect 12 0 7 0;
  51
+#X connect 13 0 8 1;
  52
+#X connect 14 0 29 0;
  53
+#X connect 15 0 16 0;
  54
+#X connect 16 1 1 0;
  55
+#X connect 17 0 19 0;
  56
+#X connect 18 0 2 0;
  57
+#X connect 18 1 4 0;
  58
+#X connect 18 2 21 0;
  59
+#X connect 19 0 10 0;
58 60
 #X connect 19 1 5 0;
59  
-#X connect 19 2 22 0;
60  
-#X connect 20 0 11 0;
61  
-#X connect 20 1 6 0;
62  
-#X connect 20 2 21 0;
63  
-#X connect 21 0 18 1;
64  
-#X connect 22 0 18 1;
65  
-#X connect 25 0 14 0;
66  
-#X connect 26 0 13 0;
67  
-#X connect 28 0 1 1;
68  
-#X connect 28 0 1 0;
69  
-#X connect 29 0 28 1;
  61
+#X connect 19 2 20 0;
  62
+#X connect 20 0 17 1;
  63
+#X connect 21 0 17 1;
  64
+#X connect 24 0 13 0;
  65
+#X connect 25 0 12 0;
  66
+#X connect 27 0 0 1;
  67
+#X connect 27 0 0 0;
  68
+#X connect 28 0 27 1;
  69
+#X connect 29 0 6 0;
  70
+#X connect 29 0 30 0;
  71
+#X connect 30 0 15 0;
  72
+#X connect 30 0 31 0;
  73
+#X connect 30 1 17 0;
80  examples/twitter-visualization.pd
... ...
@@ -1,21 +1,20 @@
1  
-#N canvas 434 51 756 544 10;
  1
+#N canvas 432 51 756 544 10;
2 2
 #X declare -lib gem -lib purest_json;
3  
-#X obj 156 85 rest-json;
4 3
 #X obj 12 148 print original-data;
5  
-#X obj 156 113 list trim;
  4
+#X obj 156 126 list trim;
6 5
 #X msg 156 51 GET http://search.twitter.com/search.json?q=%23puredata
7 6
 ;
8  
-#X obj 156 142 route results;
9  
-#X obj 156 169 l2s;
10  
-#X obj 156 192 json-decode;
  7
+#X obj 156 155 route results;
  8
+#X obj 156 182 l2s;
  9
+#X obj 156 205 json-decode;
11 10
 #X obj 50 228 print results;
12  
-#X obj 156 218 list trim;
13  
-#X obj 156 275 l2s;
14  
-#X obj 214 276 l2s;
15  
-#X obj 123 307 symbol;
16  
-#X obj 169 334 pack s s;
  11
+#X obj 156 231 list trim;
  12
+#X obj 156 288 l2s;
  13
+#X obj 214 289 l2s;
  14
+#X obj 123 320 symbol;
  15
+#X obj 169 347 pack s s;
17 16
 #X obj 53 371 print packed;
18  
-#X obj 156 242 route from_user text;
  17
+#X obj 156 255 route from_user text;
19 18
 #X obj 487 231 gemwin;
20 19
 #X obj 487 122 tgl 15 0 empty empty empty 17 7 0 10 -262144 -1 -1 0
21 20
 1;
@@ -39,35 +38,38 @@
39 38
 ;
40 39
 #X obj 343 367 t b a;
41 40
 #X obj 528 46 import gem purest_json;
42  
-#X connect 0 0 1 0;
43  
-#X connect 0 0 2 0;
44  
-#X connect 2 0 4 0;
45  
-#X connect 3 0 0 0;
  41
+#X obj 156 78 rest;
  42
+#X obj 156 102 json-decode;
  43
+#X connect 1 0 3 0;
  44
+#X connect 2 0 34 0;
  45
+#X connect 3 0 4 0;
46 46
 #X connect 4 0 5 0;
47 47
 #X connect 5 0 6 0;
48  
-#X connect 6 0 7 0;
49  
-#X connect 6 0 8 0;
50  
-#X connect 6 1 11 0;
51  
-#X connect 8 0 14 0;
  48
+#X connect 5 0 7 0;
  49
+#X connect 5 1 10 0;
  50
+#X connect 7 0 13 0;
  51
+#X connect 8 0 10 1;
52 52
 #X connect 9 0 11 1;
53  
-#X connect 10 0 12 1;
  53
+#X connect 10 0 11 0;
54 54
 #X connect 11 0 12 0;
55  
-#X connect 12 0 13 0;
56  
-#X connect 12 0 21 0;
57  
-#X connect 14 0 9 0;
58  
-#X connect 14 1 10 0;
59  
-#X connect 16 0 18 0;
60  
-#X connect 17 0 15 0;
61  
-#X connect 18 0 15 0;
62  
-#X connect 18 1 17 0;
63  
-#X connect 20 0 19 0;
64  
-#X connect 21 0 26 1;
65  
-#X connect 22 0 28 0;
66  
-#X connect 23 0 33 0;
  55
+#X connect 11 0 20 0;
  56
+#X connect 13 0 8 0;
  57
+#X connect 13 1 9 0;
  58
+#X connect 15 0 17 0;
  59
+#X connect 16 0 14 0;
  60
+#X connect 17 0 14 0;
  61
+#X connect 17 1 16 0;
  62
+#X connect 19 0 18 0;
  63
+#X connect 20 0 25 1;
  64
+#X connect 21 0 27 0;
  65
+#X connect 22 0 32 0;
  66
+#X connect 23 0 22 0;
67 67
 #X connect 24 0 23 0;
68  
-#X connect 25 0 24 0;
69  
-#X connect 26 0 20 0;
70  
-#X connect 27 0 26 0;
71  
-#X connect 28 0 19 0;
72  
-#X connect 33 0 27 0;
73  
-#X connect 33 1 19 0;
  68
+#X connect 25 0 19 0;
  69
+#X connect 26 0 25 0;
  70
+#X connect 27 0 18 0;
  71
+#X connect 32 0 26 0;
  72
+#X connect 32 1 18 0;
  73
+#X connect 34 0 0 0;
  74
+#X connect 34 0 35 0;
  75
+#X connect 35 0 1 0;
2  json-decode.c
@@ -6,7 +6,7 @@
6 6
 
7 7
 static t_class *json_decode_class;
8 8
 
9  
-void json0x2ddecode_setup(void) {
  9
+void setup_json0x2ddecode(void) {
10 10
 	json_decode_class = class_new(gensym("json-decode"), (t_newmethod)json_decode_new,
11 11
 			0, sizeof(t_json_decode), 0, A_GIMME, 0);
12 12
 	class_addsymbol(json_decode_class, (t_method)json_decode_string);
2  json-encode.c
@@ -40,7 +40,7 @@ static json_object *create_object(char *value) {
40 40
 	return object;
41 41
 }
42 42
 
43  
-void json0x2dencode_setup(void) {
  43
+void setup_json0x2dencode(void) {
44 44
 	json_encode_class = class_new(gensym("json-encode"), (t_newmethod)json_encode_new,
45 45
 			(t_method)json_encode_free, sizeof(t_json_encode), 0, A_GIMME, 0);
46 46
 	class_addbang(json_encode_class, (t_method)json_encode_bang);
36  oauth-help.pd
... ...
@@ -0,0 +1,36 @@
  1
+#N canvas 180 176 952 389 10;
  2
+#X declare -lib purest_json;
  3
+#X obj 457 -40 import purest_json;
  4
+#X obj 19 -60 oauth;
  5
+#X text 57 -61 - object for HTTP communication with OAUTH webservices
  6
+;
  7
+#X text 17 -33 [oauth] is an object for communication with OAUTH enbabled
  8
+webservices that return JSON data. Request methods GET and POST are
  9
+available.;
  10
+#X text 17 3 All requests are issued with [REQUEST_METHOD URL DATA(
  11
+where REQUEST_METHOD is the uppercase verb of the method \, URL is
  12
+the relative server path \, and DATA are url parameters to add to the
  13
+url. For creating the data \, see;
  14
+#X obj 21 58 urlparams;
  15
+#X text 18 90 HTTP requests are asynchronous. While [oauth] waits for
  16
+the webservice to return data \, the object is locked and does not
  17
+allow other methods.;
  18
+#X text 18 128 Set the base url \, consumer key and secret (client
  19
+credentials) \, and optionally access token and secret (token credentials)
  20
+at creation or use [url( message.;
  21
+#X obj 20 174 oauth http://example.com/ CLIENTKEY CLIENTSECRET ACCESSTOKEN
  22
+ACCESSSECRET;
  23
+#X text 455 -14 The second output of [oauth] will output status data
  24
+of the request.;
  25
+#X msg 486 99 GET /echo_api.php?method=foo&bar=baz;
  26
+#X msg 504 144 POST /echo_api.php?method=foo&bar=baz;
  27
+#X obj 452 194 oauth;
  28
+#X obj 503 238 print status;
  29
+#X obj 414 233 print data;
  30
+#X msg 452 53 url http/term.ie/example key secret requestkey requestsecret
  31
+;
  32
+#X connect 10 0 12 0;
  33
+#X connect 11 0 12 0;
  34
+#X connect 12 0 14 0;
  35
+#X connect 12 1 13 0;
  36
+#X connect 15 0 12 0;
19  oauth.c
@@ -12,16 +12,17 @@ static void *execute_oauth_request(void *thread_args) {
12 12
 	char *postargs = NULL;
13 13
 	char *reply = NULL;
14 14
 	t_atom http_status_data[3];
  15
+		
  16
+	if (x->parameters) {
  17
+		if (strchr(x->complete_url, '?')) {
  18
+			strcat(x->complete_url, "&");
  19
+		} else {
  20
+			strcat(x->complete_url, "?");
  21
+		}
  22
+		strcat(x->complete_url, x->parameters);
  23
+	}
15 24
 
16 25
 	if (strcmp(x->request_type, "POST") == 0) {
17  
-		if (x->parameters) {
18  
-			if (strchr(x->complete_url, '?')) {
19  
-				strcat(x->complete_url, "&");
20  
-			} else {
21  
-				strcat(x->complete_url, "?");
22  
-			}
23  
-			strcat(x->complete_url, x->parameters);
24  
-		}
25 26
 		req_url = oauth_sign_url2(x->complete_url, &postargs, OA_HMAC, NULL, 
26 27
 				x->oauth.client_key, x->oauth.client_secret, 
27 28
 				x->oauth.token_key, x->oauth.token_secret);
@@ -143,7 +144,7 @@ void oauth_command(t_oauth *x, t_symbol *selector, int argcount, t_atom *argvec)
143 144
 	if(x->is_data_locked) {
144 145
 		post("oauth object is performing request and locked");
145 146
 	} else {
146  
-		memset(x->request_type, 0x00, 7);
  147
+		memset(x->request_type, 0x00, 5);
147 148
 		memset(x->parameters, 0x00, MAXPDSTRING);
148 149
 		memset(x->complete_url, 0x00, MAXPDSTRING);
149 150
 		switch (argcount) {
4  purest_json.c
@@ -6,7 +6,7 @@ void purest_json_setup(void) {
6 6
 	post("Get the latest source from https://github.com/residuum/PuRestJson");
7 7
 	rest_setup();
8 8
 	oauth_setup();
9  
-	json0x2dencode_setup();
10  
-	json0x2ddecode_setup();
  9
+	setup_json0x2dencode();
  10
+	setup_json0x2ddecode();
11 11
 	urlparams_setup();
12 12
 }
8  purest_json.h
@@ -52,7 +52,6 @@ typedef struct oauth {
52 52
 	char base_url[MAXPDSTRING];
53 53
 	/* authentication*/
54 54
 	struct {
55  
-		char request_type[5]; /*GET or POST*/
56 55
 		char client_key[MAXPDSTRING];
57 56
 		char client_secret[MAXPDSTRING];
58 57
 		char token_key[MAXPDSTRING];
@@ -60,7 +59,7 @@ typedef struct oauth {
60 59
 	} oauth;
61 60
 	t_atom *out;
62 61
 	/* threading */
63  
-	char request_type[7]; /*One of GET, PUT, POST; DELETE*/
  62
+	char request_type[5]; /*GET or POST*/
64 63
 	char parameters[MAXPDSTRING];
65 64
 	char complete_url[MAXPDSTRING];
66 65
 	short is_data_locked;
@@ -102,8 +101,9 @@ void *oauth_new(t_symbol *selector, int argcount, t_atom *argvec);
102 101
 
103 102
 void oauth_command(t_oauth *x, t_symbol *selector, int argcount, t_atom *argvec); 
104 103
 void oauth_url(t_oauth *x, t_symbol *selector, int argcount, t_atom *argvec);
  104
+
105 105
 /* [json-encode] */
106  
-void json0x2dencode_setup(void);
  106
+void setup_json0x2dencode(void);
107 107
 void *json_encode_new(t_symbol *selector, int argcount, t_atom *argvec);
108 108
 void json_encode_free(t_json_encode *x, t_symbol *selector, int argcount, t_atom *argvec);
109 109
 
@@ -113,7 +113,7 @@ void json_encode_array_add(t_json_encode *x, t_symbol *selector, int argcount, t
113 113
 void json_encode_clear(t_json_encode *x, t_symbol *selector, int argcount, t_atom *argvec);
114 114
 
115 115
 /* [json-decode] */
116  
-void json0x2ddecode_setup(void);
  116
+void setup_json0x2ddecode(void);
117 117
 void *json_decode_new(t_symbol *selector, int argcount, t_atom *argvec);
118 118
 
119 119
 void json_decode_string(t_json_decode *x, t_symbol *data);
246  rest-help.pd
... ...
@@ -0,0 +1,246 @@
  1
+#N canvas 361 74 952 532 10;
  2
+#X declare -lib purest_json;
  3
+#N canvas 256 52 853 470 CouchDB-basics 0;
  4
+#X text 416 71 CRUD documents:;
  5
+#X text 15 10 Basic CRUD methods for databases and individual documents
  6
+are done with three HTTP methods: PUT \, GET and DELETE. PUT is used
  7
+for creating and updating data \, GET is used for retrieving data \,
  8
+while DELETE is used for deleting data. This is best explained with
  9
+some examples:;
  10
+#X text 15 74 CRUD databases:;
  11
+#X text 15 93 PUT http://localhost:5984/pd-test;
  12
+#X text 14 105 This will create a database "pd-test" on the server
  13
+localhost. If the operation is successful \, CouchDB will return a
  14
+JSON object starting with a key of "ok" and a message as value for
  15
+that key. If creating the database is not possible \, you will get
  16
+a key "error" and the reason for the failure as its value.;
  17
+#X text 15 178 GET http://localhost:5984/pd-test;
  18
+#X text 15 191 This will get some info on the database \, including
  19
+the count of stored documents as "doc_count". If getting the database
  20
+is not possible you will receive a key "error" and the reason for the
  21
+failure as its value.;
  22
+#X text 15 242 DELETE http://localhost:5984/pd-test;
  23
+#X text 15 258 This will delete the database if possible. BEWARE: You
  24
+won't get prompted for confirmation \, CouchDB will delete the database
  25
+without any warning including all stored documents. This will return
  26
+"ok" or "error" as a key.;
  27
+#X text 416 116 This will create or update a document with the ID "object-name"
  28
+in the database "pd-test". The database must be created first. If a
  29
+document with the ID "object-name" already exists \, you must include
  30
+the revision \, that you can get with the GET method (see below). On
  31
+error CouchDB will return a key of "error" and the reason for the error
  32
+as its value. Data for the object must be provided as JSON data in
  33
+the request header.;
  34
+#X text 416 208 GET http://localhost:5984/pd-test/object-name;
  35
+#X text 417 222 This will retrieve the document "object-name" from
  36
+the database "pd-test". This will return the document as a JSON object
  37
+\, including the ID with the key "_id" and the revision code with the
  38
+key "_rev". The latter value is needed for updating or deleting the
  39
+object from the table to prevent concurrent updates.;
  40
+#X text 417 292 DELETE http://localhost:5984/pd-test/object-name;
  41
+#X text 418 311 This will delete the document if possible. You will
  42
+need to provide the revision for the document. You will receive data
  43
+with a key of "ok" or "error" and information as value.;
  44
+#X text 416 91 PUT http://localhost:5984/pd-test/object-name data-as-json-string
  45
+;
  46
+#X text 15 362 All these request \, PUT \, GET and DELETE can be done
  47
+with [rest-json] \, you can even issue POST requests to a CouchDB server.
  48
+If you want to do complex data operations on a CouchDB \, please refer
  49
+to the manual: http://guide.couchdb.org/;
  50
+#X restore 20 236 pd CouchDB-basics;
  51
+#N canvas 194 51 932 709 couchdb 0;
  52
+#X msg 603 26 bang;
  53
+#X msg 59 19 url http://localhost:5984/;
  54
+#X obj 171 279 list trim;
  55
+#X obj 170 310 route error ok;
  56
+#X msg 179 377 0;
  57
+#X obj 261 266 t b b;
  58
+#X msg 261 293 1;
  59
+#X text 99 359 Close signal flow on error;
  60
+#X obj 55 427 print error message;
  61
+#X text 320 301 Reopen signal flow after each object.;
  62
+#X obj 210 335 print OK message;
  63
+#N canvas 574 80 450 345 create-sequencer-data 0;
  64
+#X obj 32 12 inlet;
  65
+#X obj 32 291 outlet;
  66
+#X obj 62 222 + 1;
  67
+#X obj 32 253 pack f s;
  68
+#X obj 32 166 json-encode;
  69
+#X msg 32 84 add pitch 440 \, add duration 2000 \, bang \, clear \,
  70
+add pitch 880 \, add duration 1000 \, bang \, clear \, add pitch 440
  71
+\, add duration 1000 \, bang \, clear \, add pitch 1320 \, add duration
  72
+500 \, bang \, clear \, add pitch 880 \, add duration 2000 \, bang
  73
+\, clear;
  74
+#X obj 32 193 t b a;
  75
+#X obj 32 222 0;
  76
+#X obj 32 49 t b b;
  77
+#X msg 110 166 0;
  78
+#X connect 0 0 8 0;
  79
+#X connect 2 0 7 1;
  80
+#X connect 3 0 1 0;
  81
+#X connect 4 0 6 0;
  82
+#X connect 5 0 4 0;
  83
+#X connect 6 0 7 0;
  84
+#X connect 6 1 3 1;
  85
+#X connect 7 0 2 0;
  86
+#X connect 7 0 3 0;
  87
+#X connect 8 0 5 0;
  88
+#X connect 8 1 9 0;
  89
+#X connect 9 0 7 1;
  90
+#X restore 603 53 pd create-sequencer-data;
  91
+#X text 58 -2 1 Sets the base URL.;
  92
+#X text 243 -6 2 Creates database pd-test on server with base URL.
  93
+If you do not set the base URL \, then you can also issue this command
  94
+with [PUT http://localhost:5984/pd-test/(;
  95
+#X text 600 -2 3 Creates some sequencer data and stores the data in
  96
+pd-test. Objects contain "pitch" and "duration".;
  97
+#X text 45 93 4 Start sequencer and get first object;
  98
+#X obj 46 140 f;
  99
+#X obj 74 142 + 1;
  100
+#X obj 316 386 route pitch duration;
  101
+#X obj 288 418 pack f f f;
  102
+#X obj 216 494 unpack f f f;
  103
+#X obj 285 520 del;
  104
+#X obj 26 294 print data;
  105
+#X text 602 131 5 Get database pd-test;
  106
+#X text 606 175 6 Delete database pd-test;
  107
+#X msg 603 154 GET pdtest;
  108
+#X msg 248 35 PUT pdtest;
  109
+#X msg 603 77 PUT pdtest/\$1 \$2;
  110
+#X msg 608 193 DELETE pdtest;
  111
+#X msg 46 169 GET pdtest/\$1;
  112
+#X text 58 -37 This example will create a database and store values
  113
+to be used by a simple sequencer.;
  114
+#X msg 46 112 0;
  115
+#X obj 216 463 spigot 1;
  116
+#X obj 295 107 spigot;
  117
+#X obj 328 73 tgl 15 0 empty empty empty 17 7 0 10 -262144 -1 -1 0
  118
+1;
  119
+#X obj 603 102 print Put command;
  120
+#X obj 139 332 t b a b;
  121
+#X text 275 57 toggle only when using sequencer;
  122
+#X msg 32 366 0;
  123
+#X text 4 343 restart GET sequence;
  124
+#X obj 250 540 osc~;
  125
+#X obj 311 587 *~ 0;
  126
+#X obj 311 613 dac~;
  127
+#X obj 171 250 json-decode;
  128
+#X obj 171 217 rest;
  129
+#X connect 0 0 11 0;
  130
+#X connect 1 0 44 0;
  131
+#X connect 2 0 3 0;
  132
+#X connect 3 0 36 0;
  133
+#X connect 3 1 10 0;
  134
+#X connect 3 2 18 0;
  135
+#X connect 4 0 32 1;
  136
+#X connect 5 0 6 0;
  137
+#X connect 5 1 19 0;
  138
+#X connect 6 0 32 1;
  139
+#X connect 11 0 27 0;
  140
+#X connect 16 0 17 0;
  141
+#X connect 16 0 29 0;
  142
+#X connect 17 0 16 1;
  143
+#X connect 18 0 19 1;
  144
+#X connect 18 1 19 2;
  145
+#X connect 19 0 32 0;
  146
+#X connect 20 1 40 0;
  147
+#X connect 20 2 21 0;
  148
+#X connect 21 0 33 0;
  149
+#X connect 25 0 44 0;
  150
+#X connect 26 0 44 0;
  151
+#X connect 27 0 35 0;
  152
+#X connect 27 0 44 0;
  153
+#X connect 28 0 44 0;
  154
+#X connect 29 0 44 0;
  155
+#X connect 31 0 16 0;
  156
+#X connect 32 0 20 0;
  157
+#X connect 33 0 16 0;
  158
+#X connect 34 0 33 1;
  159
+#X connect 34 0 41 1;
  160
+#X connect 36 0 38 0;
  161
+#X connect 36 1 8 0;
  162
+#X connect 36 2 4 0;
  163
+#X connect 38 0 33 0;
  164
+#X connect 40 0 41 0;
  165
+#X connect 41 0 42 0;
  166
+#X connect 41 0 42 1;
  167
+#X connect 43 0 2 0;
  168
+#X connect 43 1 5 0;
  169
+#X connect 44 0 22 0;
  170
+#X connect 44 0 43 0;
  171
+#X restore 19 310 pd couchdb;
  172
+#X msg 497 124 GET http://search.twitter.com/search.json?q=%23puredata
  173
+;
  174
+#X msg 474 64 GET https://ajax.googleapis.com/ajax/services/search/web?v=2.0&q=puredata
  175
+;
  176
+#X msg 458 10 GET https://github.com/api/v2/json/commits/list/residuum/PuRestJson/master
  177
+;
  178
+#X text 55 -59 - object for HTTP communication with REST webservices
  179
+;
  180
+#X text 19 217 An example for a RESTful interface is CouchDB:;
  181
+#X text 17 -3 All requests are issued with [REQUEST_METHOD URL DATA(
  182
+where REQUEST_METHOD is the uppercase verb of the method \, URL is
  183
+the request URL \, or the relative server path \, if [url( or initialization
  184
+is used \, and DATA is the upload data for PUT or post data for POST.
  185
+;
  186
+#X text 17 261 Here is a complex example for using [rest-json] to communicate
  187
+with CouchDB. It uses GET \, POST and DELETE request methods. You will
  188
+need to have a local installation of CouchDB.;
  189
+#X obj 458 248 print data;
  190
+#X text 18 99 Set the base url at creation or use [url( message. An
  191
+empty url message will clean a previous set base url. You can also
  192
+use four parameters for the [url( message to use basic cookie authentication
  193
+\, see below.;
  194
+#X text 18 344 Using cookie authentication with rest-json;
  195
+#N canvas 498 76 443 465 cookie-auth 0;
  196
+#X text 35 12 Basic cookie authentication is possible with [rest-json]
  197
+\, as long as the service uses some guidelines \, that are adopted
  198
+from CouchDB.;
  199
+#X text 34 91 This will try to log you in on creation. It will call
  200
+the url http://example.com/login-page and post username=myusername&password=mypass
  201
+to the page.;
  202
+#X text 34 128 When this returns a cookie \, the cookie will be saved
  203
+and included in every request \, as long as the base url does not change.
  204
+;
  205
+#X text 35 168 Please keep in mind \, that passwords in Pd patches
  206
+are stored in plain text \, especially when you use code hosting services.
  207
+Better store your passwords in a seperate file or application and use
  208
+[textfile] or OSC for getting the data.;
  209
+#X msg 40 313 url http://example.com/ login-page myusername mypass
  210
+;
  211
+#X text 39 254 This;
  212
+#X text 39 293 is the same as this after clicking the [url( message
  213
+;
  214
+#X text 38 374 To clear your stored authentication cookie \, send a
  215
+[url( message with no additional parameters \, or with only one parameter.
  216
+The latter will send only the base url \, but will not try to log you
  217
+in.;
  218
+#X obj 37 66 rest http://example.com/ login-page myusername mypass
  219
+;
  220
+#X obj 40 273 rest http://example.com/ login-page myusername mypass
  221
+;
  222
+#X obj 40 347 rest;
  223
+#X connect 4 0 10 0;
  224
+#X restore 19 362 pd cookie-auth;
  225
+#X obj 540 248 print status;
  226
+#X msg 499 188 GET http://search.twitter.com/wrongsearch.json?q=%23puredata
  227
+;
  228
+#X obj 457 -40 import purest_json;
  229
+#X obj 19 -60 rest;
  230
+#X text 17 -33 [rest] is an object for communication with REST services.
  231
+Request methods GET \, POST \, PUT and DELETE are available.;
  232
+#X text 18 61 HTTP requests are asynchronous. Do not expect a request
  233
+to return data immediately. While one request is processed \, the object
  234
+id blocked.;
  235
+#X obj 20 158 rest http://localhost:5984/;
  236
+#X text 18 188 The second outlet will output status information of
  237
+the request;
  238
+#X obj 458 216 rest;
  239
+#X text 497 170 This will give you an error message on the second outlet
  240
+;
  241
+#X connect 2 0 21 0;
  242
+#X connect 3 0 21 0;
  243
+#X connect 4 0 21 0;
  244
+#X connect 14 0 21 0;
  245
+#X connect 21 0 9 0;
  246
+#X connect 21 1 13 0;
281  rest-json-help.pd
... ...
@@ -1,279 +1,10 @@
1  
-#N canvas 363 76 952 532 10;
  1
+#N canvas 361 74 521 255 10;
  2
+#X declare -lib purest_json;
2 3
 #X declare -lib purest_json;
3  
-#N canvas 258 54 853 470 CouchDB-basics 0;
4  
-#X text 416 71 CRUD documents:;
5  
-#X text 15 10 Basic CRUD methods for databases and individual documents
6  
-are done with three HTTP methods: PUT \, GET and DELETE. PUT is used
7  
-for creating and updating data \, GET is used for retrieving data \,
8  
-while DELETE is used for deleting data. This is best explained with
9  
-some examples:;
10  
-#X text 15 74 CRUD databases:;
11  
-#X text 15 93 PUT http://localhost:5984/pd-test;
12  
-#X text 14 105 This will create a database "pd-test" on the server
13  
-localhost. If the operation is successful \, CouchDB will return a
14  
-JSON object starting with a key of "ok" and a message as value for
15  
-that key. If creating the database is not possible \, you will get
16  
-a key "error" and the reason for the failure as its value.;
17  
-#X text 15 178 GET http://localhost:5984/pd-test;
18  
-#X text 15 191 This will get some info on the database \, including
19  
-the count of stored documents as "doc_count". If getting the database
20  
-is not possible you will receive a key "error" and the reason for the
21  
-failure as its value.;
22  
-#X text 15 242 DELETE http://localhost:5984/pd-test;
23  
-#X text 15 258 This will delete the database if possible. BEWARE: You
24  
-won't get prompted for confirmation \, CouchDB will delete the database
25  
-without any warning including all stored documents. This will return
26  
-"ok" or "error" as a key.;
27  
-#X text 416 116 This will create or update a document with the ID "object-name"
28  
-in the database "pd-test". The database must be created first. If a
29  
-document with the ID "object-name" already exists \, you must include
30  
-the revision \, that you can get with the GET method (see below). On
31  
-error CouchDB will return a key of "error" and the reason for the error
32  
-as its value. Data for the object must be provided as JSON data in
33  
-the request header.;
34  
-#X text 416 208 GET http://localhost:5984/pd-test/object-name;
35  
-#X text 417 222 This will retrieve the document "object-name" from
36  
-the database "pd-test". This will return the document as a JSON object
37  
-\, including the ID with the key "_id" and the revision code with the
38  
-key "_rev". The latter value is needed for updating or deleting the
39  
-object from the table to prevent concurrent updates.;
40  
-#X text 417 292 DELETE http://localhost:5984/pd-test/object-name;
41  
-#X text 418 311 This will delete the document if possible. You will
42  
-need to provide the revision for the document. You will receive data
43  
-with a key of "ok" or "error" and information as value.;
44  
-#X text 416 91 PUT http://localhost:5984/pd-test/object-name data-as-json-string
45  
-;
46  
-#X text 15 362 All these request \, PUT \, GET and DELETE can be done
47  
-with [rest-json] \, you can even issue POST requests to a CouchDB server.
48  
-If you want to do complex data operations on a CouchDB \, please refer
49  
-to the manual: http://guide.couchdb.org/;
50  
-#X restore 20 277 pd CouchDB-basics;
51  
-#X obj 21 211 json-decode;
52  
-#X obj 20 158 rest-json http://localhost:5984/;
53 4
 #X obj 19 -60 rest-json;
54  
-#N canvas 196 0 932 709 couchdb 0;
55  
-#X msg 603 26 bang;
56  
-#X msg 59 19 url http://localhost:5984/;
57  
-#X obj 171 279 list trim;
58  
-#X obj 170 310 route error ok;
59  
-#X msg 179 377 0;
60  
-#X obj 261 266 t b b;
61  
-#X msg 261 293 1;
62  
-#X text 99 359 Close signal flow on error;
63  
-#X obj 55 427 print error message;
64  
-#X text 320 301 Reopen signal flow after each object.;
65  
-#X obj 210 335 print OK message;
66  
-#N canvas 576 82 450 345 create-sequencer-data 0;
67  
-#X obj 32 12 inlet;
68  
-#X obj 32 291 outlet;
69  
-#X obj 62 222 + 1;
70  
-#X obj 32 253 pack f s;
71  
-#X obj 32 166 json-encode;
72  
-#X msg 32 84 add pitch 440 \, add duration 2000 \, bang \, clear \,
73  
-add pitch 880 \, add duration 1000 \, bang \, clear \, add pitch 440
74  
-\, add duration 1000 \, bang \, clear \, add pitch 1320 \, add duration
75  
-500 \, bang \, clear \, add pitch 880 \, add duration 2000 \, bang
76  
-\, clear;
77  
-#X obj 32 193 t b a;
78  
-#X obj 32 222 0;
79  
-#X obj 32 49 t b b;
80  
-#X msg 110 166 0;
81  
-#X connect 0 0 8 0;
82  
-#X connect 2 0 7 1;
83  
-#X connect 3 0 1 0;
84  
-#X connect 4 0 6 0;
85  
-#X connect 5 0 4 0;
86  
-#X connect 6 0 7 0;
87  
-#X connect 6 1 3 1;
88  
-#X connect 7 0 2 0;
89  
-#X connect 7 0 3 0;
90  
-#X connect 8 0 5 0;
91  
-#X connect 8 1 9 0;
92  
-#X connect 9 0 7 1;
93  
-#X restore 603 53 pd create-sequencer-data;
94  
-#X text 58 -2 1 Sets the base URL.;
95  
-#X text 243 -6 2 Creates database pd-test on server with base URL.
96  
-If you do not set the base URL \, then you can also issue this command
97  
-with [PUT http://localhost:5984/pd-test/(;
98  
-#X text 600 -2 3 Creates some sequencer data and stores the data in
99  
-pd-test. Objects contain "pitch" and "duration".;
100  
-#X text 45 93 4 Start sequencer and get first object;
101  
-#X obj 46 140 f;
102  
-#X obj 74 142 + 1;
103  
-#X obj 316 386 route pitch duration;
104  
-#X obj 288 418 pack f f f;
105  
-#X obj 216 494 unpack f f f;
106  
-#X obj 285 520 del;
107  
-#X text 343 446 first inlet of pack is not used. The reason for that
108  
-is explained in the help patch for;
109  
-#X obj 539 462 json-decode;
110  
-#X obj 26 294 print data;
111  
-#X text 602 131 5 Get database pd-test;
112  
-#X text 606 175 6 Delete database pd-test;
113  
-#X msg 603 154 GET pdtest;
114  
-#X msg 248 35 PUT pdtest;
115  
-#X msg 603 77 PUT pdtest/\$1 \$2;
116  
-#X msg 608 193 DELETE pdtest;
117  
-#X msg 46 169 GET pdtest/\$1;
118  
-#X text 58 -37 This example will create a database and store values
119  
-to be used by a simple sequencer.;
120  
-#X msg 46 112 0;
121  
-#X obj 216 463 spigot 1;
122  
-#X obj 295 107 spigot;
123  
-#X obj 328 73 tgl 15 0 empty empty empty 17 7 0 10 -262144 -1 -1 0
124  
-1;
125  
-#X obj 603 102 print Put command;
126  
-#X obj 139 332 t b a b;
127  
-#X text 275 57 toggle only when using sequencer;
128  
-#X msg 32 366 0;
129  
-#X text 4 343 restart GET sequence;
130  
-#X obj 171 244 rest-json;
131  
-#X obj 250 540 osc~;
132  
-#X obj 311 587 *~ 0;
133  
-#X obj 311 613 dac~;
134  
-#X connect 0 0 11 0;
135  
-#X connect 1 0 42 0;
136  
-#X connect 2 0 3 0;
137  
-#X connect 3 0 38 0;
138  
-#X connect 3 1 10 0;
139  
-#X connect 3 2 18 0;
140  
-#X connect 4 0 34 1;
141  
-#X connect 5 0 6 0;
142  
-#X connect 5 1 19 0;
143  
-#X connect 6 0 34 1;
144  
-#X connect 11 0 29 0;
145  
-#X connect 16 0 17 0;
146  
-#X connect 16 0 31 0;
147  
-#X connect 17 0 16 1;
148  
-#X connect 18 0 19 1;
149  
-#X connect 18 1 19 2;
150  
-#X connect 19 0 34 0;
151  
-#X connect 20 1 43 0;
152  
-#X connect 20 2 21 0;
153  
-#X connect 21 0 35 0;
154  
-#X connect 27 0 42 0;
155  
-#X connect 28 0 42 0;
156  
-#X connect 29 0 37 0;
157  
-#X connect 29 0 42 0;
158  
-#X connect 30 0 42 0;
159  
-#X connect 31 0 42 0;
160  
-#X connect 33 0 16 0;
161  
-#X connect 34 0 20 0;
162  
-#X connect 35 0 16 0;
163  
-#X connect 36 0 35 1;
164  
-#X connect 36 0 44 1;
165  
-#X connect 38 0 40 0;
166  
-#X connect 38 1 8 0;
167  
-#X connect 38 2 4 0;
168  
-#X connect 40 0 35 0;
169  
-#X connect 42 0 2 0;
170  
-#X connect 42 0 24 0;
171  
-#X connect 42 1 5 0;
172  
-#X connect 43 0 44 0;
173  
-#X connect 44 0 45 0;
174  
-#X connect 44 0 45 1;
175  
-#X restore 19 351 pd couchdb;
176  
-#X obj 458 216 rest-json;
177  
-#X msg 497 124 GET http://search.twitter.com/search.json?q=%23puredata
178  
-;
179  
-#X msg 474 64 GET https://ajax.googleapis.com/ajax/services/search/web?v=2.0&q=puredata
180  
-;
181  
-#X msg 458 10 GET https://github.com/api/v2/json/commits/list/residuum/PuRestJson/master
182  
-;
183 5
 #X text 76 -59 - object for HTTP communication with REST webservices
184 6
 ;
185  
-#X text 19 258 An example for a RESTful interface is CouchDB:;
186  
-#X text 17 -33 [rest-json] is an object for communication with REST
187  
-services that return JSON data. Request methods GET \, POST \, PUT
188  
-and DELETE are available.;
189  
-#X text 17 4 All requests are issued with [REQUEST_METHOD URL DATA(
190  
-where REQUEST_METHOD is the uppercase verb of the method \, URL is
191  
-the request URL \, or the relative server path \, if [url( or initialization
192  
-is used \, and DATA is the upload data for PUT or post data for POST.
193  
-;
194  
-#X text 17 302 Here is a complex example for using [rest-json] to communicate
195  
-with CouchDB. It uses GET \, POST and DELETE request methods. You will
196  
-need to have a local installation of CouchDB.;
197  
-#X text 18 61 HTTP requests are asynchronous. Do not expect two subsequent
198  
-requests to arrive in the same order as sending them. [rest-json] does
199  
-all its work in separate threads.;
200  
-#X obj 458 248 print data;
201  
-#X text 18 99 Set the base url at creation or use [url( message. An
202  
-empty url message will clean a previous set base url. You can also
203  
-use four parameters for the [url( message to use basic cookie authentication
204  
-\, see below.;
205  
-#N canvas 498 76 619 521 OAUTH 0;
206  
-#X obj -18 383 rest-json;
207  
-#X msg -18 129 oauth http/term.ie/example key secret requestkey requestsecret
208  
-;
209  
-#X text -23 15 The oauth message needs five parameters: the base url
210  
-of the REST service \, consumer key \, consumer secret \, access token
211  
-\, and access token secret.;
212  
-#X text -23 54 For the terminology \, see http://hueniverse.com/oauth/guide/terminology/
213  
-;
214  
-#X obj 33 427 print oauth-status;
215  
-#X text -23 84 The OAUTH test server does not return JSON data \, so
216  
-only the status is relevant \, see http://term.ie/oauth/example/;
217  
-#X text 23 185 After setting oauth \, only GET and POST requests are
218  
-possible.;
219  
-#X msg 25 223 GET /echo_api.php?method=foo&bar=baz;
220  
-#X msg 40 255 POST /echo_api.php?method=foo&bar=baz;
221  
-#X msg 50 289 PUT /echo_api.php?method=foo&bar=baz;
222  
-#X msg 62 354 url;
223  
-#X text 62 322 To reset [rest-json] and disable oauth \, just send
224  
-[url( to the object;
225  
-#X connect 0 2 4 0;
226  
-#X connect 1 0 0 0;
227  
-#X connect 7 0 0 0;
228  
-#X connect 8 0 0 0;
229  
-#X connect 9 0 0 0;
230  
-#X connect 10 0 0 0;
231  
-#X restore 462 390 pd OAUTH;
232  
-#X text 18 385 Using cookie authentication with rest-json;
233  
-#N canvas 500 78 443 465 cookie-auth 0;
234  
-#X obj 40 347 rest-json;
235  
-#X text 35 12 Basic cookie authentication is possible with [rest-json]
236  
-\, as long as the service uses some guidelines \, that are adopted
237  
-from CouchDB.;
238  
-#X obj 37 66 rest-json http://example.com/ login-page myusername mypass
239  
-;
240  
-#X text 34 91 This will try to log you in on creation. It will call
241  
-the url http://example.com/login-page and post username=myusername&password=mypass
242  
-to the page.;
243  
-#X text 34 128 When this returns a cookie \, the cookie will be saved
244  
-and included in every request \, as long as the base url does not change.
245  
-;
246  
-#X text 35 168 Please keep in mind \, that passwords in Pd patches
247  
-are stored in plain text \, especially when you use code hosting services.
248  
-Better store your passwords in a seperate file or application and use
249  
-[textfile] or OSC for getting the data.;
250  
-#X obj 40 273 rest-json http://example.com/ login-page myusername mypass
251  
-;
252  
-#X msg 40 313 url http://example.com/ login-page myusername mypass
253  
-;
254  
-#X text 39 254 This;
255  
-#X text 39 293 is the same as this after clicking the [url( message
256  
-;
257  
-#X text 38 374 To clear your stored authentication cookie \, send a
258  
-[url( message with no additional parameters \, or with only one parameter.
259  
-The latter will send only the base url \, but will not try to log you
260  
-in.;
261  
-#X connect 7 0 0 0;
262  
-#X restore 19 403 pd cookie-auth;
263  
-#X text 18 184 [rest-json] gets data as JSON objects \, output on the
264  
-first two outlets is the same as;
265  
-#X text 18 229 The third outlet will output status information of the
266  
-request;
267  
-#X obj 537 248 print done;
268  
-#X obj 608 248 print status;
269  
-#X text 497 170 This will give you an error on the third outlet;
270  
-#X msg 499 188 GET http://search.twitter.com/wrongsearch.json?q=%23puredata
271  
-;
272  
-#X obj 457 -40 import purest_json;
273  
-#X connect 5 0 15 0;
274  
-#X connect 5 1 22 0;
275  
-#X connect 5 2 23 0;
276  
-#X connect 6 0 5 0;
277  
-#X connect 7 0 5 0;
278  
-#X connect 8 0 5 0;
279  
-#X connect 25 0 5 0;
  7
+#X obj 20 14 import purest_json;
  8
+#X text 19 -29 Basically a wrapper around [rest] and [json-decode].
  9
+It is an abstraction necessary because of some refactoring to privide
  10
+the functionality of the original object.;

0 notes on commit 3872a38

Please sign in to comment.
Something went wrong with that request. Please try again.