Thorn-private utility functions.
Methods
-
<static> assertSaneResponse(response)
-
Ensure that a Chakram response object is sane before using it. Throws an error if the response is unreasonable.
Parameters:
Name Type Description responseChakramResponse Object to check.
-
<static> constructUrl(pathParts)
-
Construct a URL relative to the base URL. Each argument is joined with a
/.Parameters:
Name Type Argument Description pathPartsstring <repeatable>
URL path component.
Returns:
The full URL.
- Type
- string
-
<static> login(options)
-
Log in as any user.
Parameters:
Name Type Description optionsObject Login options.
Properties
Name Type Description usernamestring Username of the user to log in as.
passwordstring Password of the user to log in as.
versionstring API version to use to log in.
xthornstring Value of the X-Thorn header.
Returns:
Promise that resolves to the result of the login request.
- Type
- ChakramPromise
-
<static> refresh(options)
-
Refresh the user with the given refresh token.
Parameters:
Name Type Description optionsObject Refresh options.
Properties
Name Type Description versionstring API version to do the refresh request on.
tokenstring The refresh token of the user you wish to refresh.
xthornstring Value of the X-Thorn header.
Returns:
A promise which resolves to the Chakram refresh response.
- Type
- ChakramPromise
-
<static> wrapRequest(chakramMethod, args, options)
-
Tries a request. If it fails because of HTTP 401, do a refresh and then try again. If it fails because of some other HTTP status code, throw an exception.
Parameters:
Name Type Description chakramMethodfunction Chakram request method to call.
argsArray Arguments to call the chakram request method with. The last member of the array must be a
params-like object.optionsObject Additional configuration options.
Properties
Name Type Description refreshTokenstring Refresh token to use if you have to do a refresh.
afterRefreshfunction Additional tasks to be performed after a refresh occurs. Passed the chakram response object from the refresh.
retryVersionstring API version to make the retry request on. Non-retry requests are made on whatever version is specified by
args.xthornstring Value of the X-Thorn header.
Returns:
A promise resolving to the result of the request. If the first try failed, it will resolve to the result of the second, whether it succeeded or not.
- Type
- ChakramPromise