ZipsceneRPCClient Class
This class passes jsonrpc requests to a server. It will authenticate with a username and password. It will refresh an accessToken when it expires.
Constructor
ZipsceneRPCClient
(
-
settings
Parameters:
-
settingsObject- settings object for authentication and sever set up
-
serverString- the server location to make requests
-
authServerString- the server to authenticate with when different from the server to make requests on.
-
emailString- The email address to authenticate with.
-
usernameString- Alias for 'email'
-
passwordString- the password to authenticate with
-
userNamespaceIdString- The user namespace the authenticated user belongs to.
-
accessTokenString- the accessToken to use to make requests
-
routeVersionNumber- Version of RPC endpoint to use
-
logRequestsBoolean- If true, log requests and responses to stderr
Item Index
Methods
authenticate
(
-
expired
This function tries to set the access token before making requests.
Parameters:
-
expiredBoolean- If this is called because of an expired access token, set this flag.
createBearerHeader
(
-
accessToken
This takes the current accessToken and turns it in to the Bearer Authorization token
Parameters:
-
accessTokenString- the access token
getUrl
(
-
[options={}]
Construct the URL to which JSONRPC requests will be placed.
Parameters:
-
[options={}]Object optional-
[auth=false]Boolean optional- Returns the auth server URL instead of the main server.
-
request
(
Promise
-
method -
params -
[opts] -
[id=requestCounter++]
Makes a request to the json-rpc service, handling authentication if necessary
Parameters:
-
methodString- the api method to call, in dot notation
-
paramsObject- the params for this api method
-
[opts]Object optional-
[exHeaders]Object optional- Object containing additional headers to use for the request.
-
[maxRetries]Number optional- Number of times to retry the req
-
[noReauth]Boolean optional- Throw token_expired errors instead of reauthenticating.
-
-
[id=requestCounter++]Number optional- the id to use for the request
Returns:
Promise:
- resolves with the response that contains an object { error, result, id }
requestRaw
(
Readable
-
method -
params -
opts -
[id=requestCounter++]
Make a request to an endpoint that returns streaming data rather than the standard JSONRPC format. Data will be returned as a plain data stream.
Parameters:
-
methodString- the api method to call
-
paramsObject- the params for this api method
-
optsObject -
[id=requestCounter++]Number optional- the id to use for the request
Returns:
Readable:
requestStream
(
zstreams.PassThrough
-
method -
params -
opts -
[id=requestCounter++]
Make a request to an endpoint that returns streaming data rather than the standard JSONRPC format. Data will be returned as a readable zstream of parsed objects.
Parameters:
-
methodString- the api method to call
-
paramsObject- the params for this api method
-
optsObject -
[id=requestCounter++]Number optional- the id to use for the request
Returns:
zstreams.PassThrough:
- returns a passthrough stream that will recieve data when the request comes back.
