This is a node.js library that provides access to the One Platform RPC API.
Usage
var rpc = ;rpc;
API
rpc.call
Make a single call to the RPC API.
rpc.call(auth, procedure, arguments, callback)
auth
may be a 40 character client key (e.g.'0808160000000000000000000000000000000000'
), or an auth object (e.g.{cik: '0808160000000000000000000000000000000000', client_key: 'e208160000000000000000000000000000000000'}
). See the RPC documentation for details.procedure
is the procedure name, e.g.'read'
or'info'
.arguments
is a list of arguments to pass the call. These are specific to<procedure>
. See the RPC documentation for a list of procedures and arguments.callback
is a function that takes three parameters:err
is null if the call was made successfully (no HTTP or RPC general error). If the call failed,err
contains the error message.rpcresponse
contains a list containing a single RPC response.httpresponse
is the response object.
Example
var rpc = ;rpc; // output: response: status: 'ok' result: client: '0808160000000000000000000000000000000000' 'c138cc0000000000000000000000000000000000' 'fdc8160000000000000000000000000000000000' dataport: '7e5c6f0000000000000000000000000000000000'
rpc.callMulti
Make multiple calls to the RPC API.
rpc.callMulti(auth, calls, callback)
auth
may be a 40 character client key (e.g.'0808160000000000000000000000000000000000'
), or an auth object (e.g.{cik: '0808160000000000000000000000000000000000', client_key: 'e208160000000000000000000000000000000000'}
). See the RPC documentation for details.calls
is a list of calls like this:{procedure: <procedure>, arguments: <arguments>}
. See the RPC documentation for a list of procedures and arguments.callback
is a function is called when the call completes. It takes three parameters:err
is null if the call was made successfully (no HTTP or RPC general error). If the call failed,err
contains the error message.rpcresponse
contains a list of RPC responses.httpresponse
is the response object.
Example
// get listing and info in one requestrpc; // output:response: id: 0 status: 'ok' result: client: '0808160000000000000000000000000000000000' 'c138cc0000000000000000000000000000000000' 'fdc8160000000000000000000000000000000000' dataport: '7e5c6f0000000000000000000000000000000000' id: 1 status: 'ok' result: basic: modified: 1374553089 subscribers: 0 type: 'client' status: 'activated'
rpc.tree
Return the RIDs of all descendants of a client.
rpc.tree(auth, options, callback)
-
auth
may be a 40 character client key (e.g.'0808160000000000000000000000000000000000'
), or an auth object (e.g.{cik: '0808160000000000000000000000000000000000', client_key: 'e208160000000000000000000000000000000000'}
). See the RPC documentation for details. -
options
is an object with the following keys, all optional:-
depth
stop at a given depth from the root client (if omitted, depth is not limited) -
visit
function to call for each resource visited. It is called withrid
,type
, anddepth
parameters. -
types
list of type strings. Options are 'dataport', 'datarule', 'dispatch'. If omitted, visits only clients. -
info
if non-null, calls info on each resource with the specified options, e.g.,{basic: true}
. May also be a function called withrid
,type
, anddepth
parameters for each resource. If a function, it should return null or info options for that resource.
-
-
callback
is a function is called when the call completes. It takes the following parameters:-
err
is null if the call succeeded. If the call failed,err
contains the error message. -
tree
is the tree. If the call failed, it is undefined.
-
Example
rpc; // outputdatarule depth:0 depth:1 depth:1 depth:1 "rid": "30e8a54ef29e55415b444ed72a961be4ea0ec270" "type": "client" "children": "rid": "0affc14ebdf520587b6957170ec6af06b7b6ca2a" "type": "dataport" "rid": "cbf6f7731ed8ae0285b2e8f9b437356544332679" "type": "dataport" "rid": "a0ebc3d703c94e9b37bb4a2796e447334d7ffea2" "type": "datarule" "info": "basic": "modified": 1422061952 "subscribers": 0 "type": "client" "status": "activated"
rpc.batch
Make a lot of RPC calls, splitting the calls into evenly sized chunks to avoid timeouts and calling in parallel to go fast.
rpc.batch(auth, calls, options, callback)
-
auth
is an RPC auth object or CIK string -
calls
is an array of call objects like this:{procedure: <procedure>, arguments: <args>}
-
options
are:-
chunkSize
is the number of calls per request -
parallelLimit
is the maximum number of concurrent requests to run in parallel
-
rpc.walk
Walk the object returned by tree()
.
rpc.walk(tree, visit);
-
tree
is the object returned by calling tree() -
calls
visit(resource, depth, parentRID)
on each resource. For the root resource, parentRID is undefined.
rpc.setOptions
Set options for connecting to the One Platform.
rpc.setOptions(\<options\>)
<options>
contains one or more options to update. Default options are as follows:
{
host: 'm2.exosite.com',
path: '/api:v1/rpc/process',
agent: 'node-onep',
https: true,
port: 443,
strictSSL: true
}
You may also specify timeout
in milliseconds, which defaults to the default for the request module.
Tests
$ cp test/config-template.js test/config.js
$ mocha
By default the tests run against the mock 1P server. To make them run against production 1P, modify test/config.js with a production CIK and turn off using the mock server.