Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Fetching contributors…

Cannot retrieve contributors at this time

404 lines (403 sloc) 16.222 kB
#N canvas 333 51 1005 658 10;
#X declare -lib purest_json;
#X msg 451 -18 GET https://ajax.googleapis.com/ajax/services/search/web?v=2.0&q=puredata
;
#X text 55 -59 - object for HTTP communication with REST webservices
;
#X text 20 190 All requests are issued with [REQUEST_METHOD URL DATA(
where REQUEST_METHOD is the uppercase verb of the method \, URL is
the request URL \, or the relative server path \, if [url( or initialization
is used \, and DATA is the upload data for PUT or post data for POST.
;
#X obj 450 422 print data;
#X obj 532 422 print status;
#X obj 450 -52 import purest_json;
#X obj 19 -60 rest;
#X text 19 23 [rest] is an object for communication with REST services.
Request methods GET \, POST \, PUT and DELETE are available.;
#X text 19 249 HTTP requests are asynchronous. Do not expect a request
to return data immediately. While one request is processed \, the object
id blocked.;
#X obj 450 390 rest;
#X text 481 38 By default \, requests do not timeout. To set a maximal
time in milliseconds \, set a value with [timeout( message. To clear
the value and return to the default \, use an empty [timeout( message.
;
#X msg 484 92 timeout 2000;
#X msg 573 91 timeout;
#X msg 600 332 sslcheck 0;
#X msg 675 332 sslcheck 1;
#X obj 19 -36 oauth;
#X text 57 -37 - object for HTTP communication with OAuth webservices
;
#X text 19 50 [oauth] is an object for communication with OAUTH enbabled
webservices that return JSON data. Request methods GET and POST are
available.;
#N canvas 156 118 814 342 oauth-specific 0;
#X text 27 7 Set the base url \, consumer key and secret (client credentials)
\, and optionally access token and secret (token credentials) at creation
or use [url( message.;
#X obj 29 53 oauth http://example.com/ CLIENTKEY CLIENTSECRET ACCESSTOKEN
ACCESSSECRET;
#X msg 31 205 method PLAINTEXT;
#X obj 31 304 oauth;
#X msg 82 234 method HMAC;
#X msg 91 262 method RSA privatekey;
#N canvas 79 81 913 619 RSA 0;
#X msg -89 318 GET /echo_api.php?method=foo&bar=baz;
#X msg -92 361 POST /echo_api.php?method=foo&bar=baz;
#X obj -128 409 oauth;
#X obj -166 448 print data-rsa;
#X obj -46 445 print status-rsa;
#X msg -106 -47 method RSA -----BEGIN PRIVATE KEY----- MIICdgIBADANBgkqhkiG9w0BAQEFAASCAmAwggJcAgEAAoGBALRiMLAh9iimur8V
A7qVvdqxevEuUkW4K+2KdMXmnQbG9Aa7k7eBjK1S+0LYmVjPKlJGNXHDGuy5Fw/d 7rjVJ0BLB+ubPK8iA/Tw3hLQgXMRRGRXXCn8ikfuQfjUS1uZSatdLB81mydBETlJ
hI6GH4twrbDJCR2Bwy/XWXgqgGRzAgMBAAECgYBYWVtleUzavkbrPjy0T5FMou8H X9u2AC2ry8vD/l7cqedtwMPp9k7TubgNFo+NGvKsl2ynyprOZR1xjQ7WgrgVB+mm
uScOM/5HVceFuGRDhYTCObE+y1kxRloNYXnx3ei1zbeYLPCHdhxRYW7T0qcynNmw rn05/KO2RLjgQNalsQJBANeA3Q4Nugqy4QBUCEC09SqylT2K9FrrItqL2QKc9v0Z
zO2uwllCbg0dwpVuYPYXYvikNHHg+aCWF+VXsb9rpPsCQQDWR9TT4ORdzoj+Nccn qkMsDmzt0EfNaAOwHOmVJ2RVBspPcxt5iN4HI7HNeG6U5YsFBb+/GZbgfBT3kpNG
WPTpAkBI+gFhjfJvRw38n3g/+UeAkwMI2TJQS4n8+hid0uus3/zOjDySH3XHCUno cn1xOJAyZODBo47E+67R4jV1/gzbAkEAklJaspRPXP877NssM5nAZMU0/O/NGCZ+
3jPgDUno6WbJn5cqm8MqWhW1xGkImgRk+fkDBquiq4gPiT898jusgQJAd5Zrr6Q8 AO/0isr/3aa6O6NLQxISLKcPDk2NOccAfS/xOtfOz4sJYM3+Bs4Io9+dZGSDCA54
Lw03eHTNQghS0A== -----END PRIVATE KEY-----;
#X msg -142 -95 url http://term.ie/oauth/example key this_is_ignored
accesskey this_is_ignored;
#X text 191 -98 You need to set client secret and access secret with
the [url( message or as arguments for [oauth] \, but these will be
ignored with the RSA key;
#X connect 0 0 2 0;
#X connect 1 0 2 0;
#X connect 2 0 3 0;
#X connect 2 1 4 0;
#X connect 5 0 2 0;
#X connect 6 0 2 0;
#X restore 333 190 pd RSA;
#X text 29 135 The method message will set the OAUTH signature method.
Default is HMAC (HMAC-SHA1). For RSA (RSA-SHA1) you have to submit
your private key. If your version of liboauth does not support RSA-SHA1
signatures \, you will receive an error message.;
#X text 439 12 The second output of [oauth] will output status data
of the request.;
#X msg 470 95 GET /echo_api.php?method=foo&bar=baz;
#X msg 488 140 POST /echo_api.php?method=foo&bar=baz;
#X obj 444 182 oauth;
#X obj 495 226 print status;
#X obj 406 221 print data;
#X msg 436 49 url http://term.ie/oauth/example key secret accesskey
accesssecret;
#X connect 2 0 3 0;
#X connect 4 0 3 0;
#X connect 5 0 3 0;
#X connect 9 0 11 0;
#X connect 10 0 11 0;
#X connect 11 0 13 0;
#X connect 11 1 12 0;
#X connect 14 0 11 0;
#X restore 195 320 pd oauth-specific;
#X text 19 -2 Most methods work the same for [rest] and [oauth] \,
only some methods differ. The differences are outlined below.;
#X text 20 100 All requests are issued with [REQUEST_METHOD URL DATA(
where REQUEST_METHOD is the uppercase verb of the method \, URL is
the relative server path \, and DATA are url parameters to add to the
url. For creating the data \, see;
#X obj 23 154 urlparams;
#N canvas 151 64 441 365 rest-specific 0;
#N canvas 498 76 443 465 cookie-auth 0;
#X text 35 12 Basic cookie authentication is possible with [rest-json]
\, as long as the service uses some guidelines \, that are adopted
from CouchDB.;
#X text 34 91 This will try to log you in on creation. It will call
the url http://example.com/login-page and post username=myusername&password=mypass
to the page.;
#X text 34 128 When this returns a cookie \, the cookie will be saved
and included in every request \, as long as the base url does not change.
;
#X text 35 168 Please keep in mind \, that passwords in Pd patches
are stored in plain text \, especially when you use code hosting services.
Better store your passwords in a seperate file or application and use
[textfile] or OSC for getting the data.;
#X msg 40 313 url http://example.com/ login-page myusername mypass
;
#X text 39 254 This;
#X text 39 293 is the same as this after clicking the [url( message
;
#X text 38 374 To clear your stored authentication cookie \, send a
[url( message with no additional parameters \, or with only one parameter.
The latter will send only the base url \, but will not try to log you
in.;
#X obj 37 66 rest http://example.com/ login-page myusername mypass
;
#X obj 40 273 rest http://example.com/ login-page myusername mypass
;
#X obj 40 347 rest;
#X connect 4 0 10 0;
#X restore 38 293 pd cookie-auth;
#X text 37 275 Using cookie authentication with [rest];
#N canvas 256 52 853 470 CouchDB-basics 0;
#X text 416 71 CRUD documents:;
#X text 15 10 Basic CRUD methods for databases and individual documents
are done with three HTTP methods: PUT \, GET and DELETE. PUT is used
for creating and updating data \, GET is used for retrieving data \,
while DELETE is used for deleting data. This is best explained with
some examples:;
#X text 15 74 CRUD databases:;
#X text 15 93 PUT http://localhost:5984/pd-test;
#X text 14 105 This will create a database "pd-test" on the server
localhost. If the operation is successful \, CouchDB will return a
JSON object starting with a key of "ok" and a message as value for
that key. If creating the database is not possible \, you will get
a key "error" and the reason for the failure as its value.;
#X text 15 178 GET http://localhost:5984/pd-test;
#X text 15 191 This will get some info on the database \, including
the count of stored documents as "doc_count". If getting the database
is not possible you will receive a key "error" and the reason for the
failure as its value.;
#X text 15 242 DELETE http://localhost:5984/pd-test;
#X text 15 258 This will delete the database if possible. BEWARE: You
won't get prompted for confirmation \, CouchDB will delete the database
without any warning including all stored documents. This will return
"ok" or "error" as a key.;
#X text 416 116 This will create or update a document with the ID "object-name"
in the database "pd-test". The database must be created first. If a
document with the ID "object-name" already exists \, you must include
the revision \, that you can get with the GET method (see below). On
error CouchDB will return a key of "error" and the reason for the error
as its value. Data for the object must be provided as JSON data in
the request header.;
#X text 416 208 GET http://localhost:5984/pd-test/object-name;
#X text 417 222 This will retrieve the document "object-name" from
the database "pd-test". This will return the document as a JSON object
\, including the ID with the key "_id" and the revision code with the
key "_rev". The latter value is needed for updating or deleting the
object from the table to prevent concurrent updates.;
#X text 417 292 DELETE http://localhost:5984/pd-test/object-name;
#X text 418 311 This will delete the document if possible. You will
need to provide the revision for the document. You will receive data
with a key of "ok" or "error" and information as value.;
#X text 416 91 PUT http://localhost:5984/pd-test/object-name data-as-json-string
;
#X text 15 362 All these request \, PUT \, GET and DELETE can be done
with [rest-json] \, you can even issue POST requests to a CouchDB server.
If you want to do complex data operations on a CouchDB \, please refer
to the manual: http://guide.couchdb.org/;
#X restore 39 167 pd CouchDB-basics;
#N canvas 192 51 932 709 couchdb 0;
#X msg 603 26 bang;
#X msg 59 19 url http://localhost:5984/;
#X obj 171 279 list trim;
#X obj 170 310 route error ok;
#X msg 179 377 0;
#X obj 261 266 t b b;
#X msg 261 293 1;
#X text 99 359 Close signal flow on error;
#X obj 55 427 print error message;
#X text 320 301 Reopen signal flow after each object.;
#X obj 210 335 print OK message;
#N canvas 574 80 450 345 create-sequencer-data 0;
#X obj 32 12 inlet;
#X obj 32 291 outlet;
#X obj 62 222 + 1;
#X obj 32 253 pack f s;
#X obj 32 166 json-encode;
#X msg 32 84 add pitch 440 \, add duration 2000 \, bang \, clear \,
add pitch 880 \, add duration 1000 \, bang \, clear \, add pitch 440
\, add duration 1000 \, bang \, clear \, add pitch 1320 \, add duration
500 \, bang \, clear \, add pitch 880 \, add duration 2000 \, bang
\, clear;
#X obj 32 193 t b a;
#X obj 32 222 0;
#X obj 32 49 t b b;
#X msg 110 166 0;
#X connect 0 0 8 0;
#X connect 2 0 7 1;
#X connect 3 0 1 0;
#X connect 4 0 6 0;
#X connect 5 0 4 0;
#X connect 6 0 7 0;
#X connect 6 1 3 1;
#X connect 7 0 2 0;
#X connect 7 0 3 0;
#X connect 8 0 5 0;
#X connect 8 1 9 0;
#X connect 9 0 7 1;
#X restore 603 53 pd create-sequencer-data;
#X text 58 -2 1 Sets the base URL.;
#X text 243 -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 600 -2 3 Creates some sequencer data and stores the data in
pd-test. Objects contain "pitch" and "duration".;
#X text 45 93 4 Start sequencer and get first object;
#X obj 46 140 f;
#X obj 74 142 + 1;
#X obj 316 386 route pitch duration;
#X obj 288 418 pack f f f;
#X obj 216 494 unpack f f f;
#X obj 285 520 del;
#X obj 26 294 print data;
#X text 602 131 5 Get database pd-test;
#X text 606 175 6 Delete database pd-test;
#X msg 603 154 GET pdtest;
#X msg 248 35 PUT pdtest;
#X msg 603 77 PUT pdtest/\$1 \$2;
#X msg 608 193 DELETE pdtest;
#X msg 46 169 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 46 112 0;
#X obj 216 463 spigot 1;
#X obj 295 107 spigot;
#X obj 328 73 tgl 15 0 empty empty empty 17 7 0 10 -262144 -1 -1 0
1;
#X obj 603 102 print Put command;
#X obj 139 332 t b a b;
#X text 275 57 toggle only when using sequencer;
#X msg 32 366 0;
#X text 4 343 restart GET sequence;
#X obj 250 540 osc~;
#X obj 311 587 *~ 0;
#X obj 311 613 dac~;
#X obj 171 250 json-decode;
#X obj 171 217 rest;
#X connect 0 0 11 0;
#X connect 1 0 44 0;
#X connect 2 0 3 0;
#X connect 3 0 36 0;
#X connect 3 1 10 0;
#X connect 3 2 18 0;
#X connect 4 0 32 1;
#X connect 5 0 6 0;
#X connect 5 1 19 0;
#X connect 6 0 32 1;
#X connect 11 0 27 0;
#X connect 16 0 17 0;
#X connect 16 0 29 0;
#X connect 17 0 16 1;
#X connect 18 0 19 1;
#X connect 18 1 19 2;
#X connect 19 0 32 0;
#X connect 20 1 40 0;
#X connect 20 2 21 0;
#X connect 21 0 33 0;
#X connect 25 0 44 0;
#X connect 26 0 44 0;
#X connect 27 0 35 0;
#X connect 27 0 44 0;
#X connect 28 0 44 0;
#X connect 29 0 44 0;
#X connect 31 0 16 0;
#X connect 32 0 20 0;
#X connect 33 0 16 0;
#X connect 34 0 33 1;
#X connect 34 0 41 1;
#X connect 36 0 38 0;
#X connect 36 1 8 0;
#X connect 36 2 4 0;
#X connect 38 0 33 0;
#X connect 40 0 41 0;
#X connect 41 0 42 0;
#X connect 41 0 42 1;
#X connect 43 0 2 0;
#X connect 43 1 5 0;
#X connect 44 0 22 0;
#X connect 44 0 43 0;
#X restore 38 241 pd couchdb;
#X text 38 148 An example for a RESTful interface is CouchDB:;
#X text 36 192 Here is a complex example for using [rest-json] to communicate
with CouchDB. It uses GET \, POST and DELETE request methods. You will
need to have a local installation of CouchDB.;
#X obj 39 101 rest http://localhost:5984/;
#X text 37 120 The second outlet will output status information of
the request.;
#X text 37 30 Set the base url at creation or use [url( message. An
empty url message will clean a previous set base url. The number of
possible parameters for [rest] and [oauth] differ. You can also use
four parameters for the [url( message to use basic cookie authentication
\, see below.;
#X restore 21 319 pd rest-specific;
#X text 594 289 By default correct SSL host is checked. Disable check
by sending sslcheck with a value to 0 \, reenable checking by setting
the value to 1;
#N canvas 116 151 628 451 headers 0;
#X obj 76 359 print data;
#X obj 158 359 print status;
#X obj 76 327 rest;
#X msg 191 226 GET https://api.github.com/repos/residuum/PuRestJson/contents/Makefile
;
#X msg 74 52 header Accept: application/json;
#X msg 126 100 header User-Agent: My User Agent;
#X text 71 0 You can set arbitrary HTTP headers with the [header( message.
;
#X text 125 80 Github requires User-Agent header;
#X text 184 150 To clear HTTP headers \, issue [header_clear(;
#X msg 182 172 header_clear;
#X text 71 22 Some webservices return different data types for different
values of Accept: headers;
#X connect 2 0 0 0;
#X connect 2 1 1 0;
#X connect 3 0 2 0;
#X connect 4 0 2 0;
#X connect 5 0 2 0;
#X connect 9 0 2 0;
#X restore 21 293 pd headers;
#X msg 634 169 cancel;
#X text 637 202 Use this request to test cancelling and timeout: it
will wait for 10 seconds before returning data.;
#X msg 641 232 GET http://ix.residuum.org/pd/sleep_example.php;
#N canvas 389 256 641 345 cancel 0;
#X obj 105 -51 print data;
#X obj 187 -51 print status;
#X obj 105 -83 rest;
#X msg 159 -165 cancel;
#X obj 303 -213 t b b;
#X obj 303 -242 bng 15 250 50 0 empty empty empty 17 7 0 10 -262144
-1 -1;
#X msg 105 -130 GET http://ix.residuum.org/pd/sleep_example.php;
#X obj 105 -220 t b b;
#X obj 105 -249 bng 15 250 50 0 empty empty empty 17 7 0 10 -262144
-1 -1;
#X text 79 -311 This won't always work \, as another thread will have
to be signalled and must clean up.;
#X text 277 -277 By experimentation \, I have found out that a delay
of 10ms is sufficient on my system (TM).;
#X obj 277 -168 del 10;
#X connect 2 0 0 0;
#X connect 2 1 1 0;
#X connect 3 0 2 0;
#X connect 4 0 11 0;
#X connect 4 1 3 0;
#X connect 5 0 4 0;
#X connect 6 0 2 0;
#X connect 7 0 6 0;
#X connect 7 1 3 0;
#X connect 8 0 7 0;
#X connect 11 0 6 0;
#X restore 718 168 pd cancel;
#X text 630 95 Experimental: You can cancel a currently executed request
by issuing [cancel(. If data has been returned already \, but is not
output \, or output only partially \, outputting the data will still
be completed. Note \, that cancelling the call may take some time \,
so do not try to issue a new request immediately. See;
#N canvas 366 182 631 378 download-to-file 0;
#X obj 77 247 rest;
#X msg 119 106 GET https://ajax.googleapis.com/ajax/services/search/web?v=2.0&q=puredata
;
#X msg 77 39 write /tmp/test.json;
#X msg 172 192 write;
#X obj 48 297 print data;
#X obj 133 297 print done;
#X text 74 20 Set the location \, where the file should be saved;
#X text 117 86 Downloaded data will write it to the file;
#X text 170 172 Clear the location;
#X connect 0 0 4 0;
#X connect 0 1 5 0;
#X connect 1 0 0 0;
#X connect 2 0 0 0;
#X connect 3 0 0 0;
#X restore 21 360 pd download-to-file;
#X connect 0 0 9 0;
#X connect 9 0 3 0;
#X connect 9 1 4 0;
#X connect 11 0 9 0;
#X connect 12 0 9 0;
#X connect 13 0 9 0;
#X connect 14 0 9 0;
#X connect 25 0 9 0;
#X connect 27 0 9 0;
Jump to Line
Something went wrong with that request. Please try again.