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 response
ChakramResponse 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 pathParts
string <repeatable>
URL path component.
Returns:
The full URL.
- Type
- string
-
<static> login(options)
-
Log in as any user.
Parameters:
Name Type Description options
Object Login options.
Properties
Name Type Description username
string Username of the user to log in as.
password
string Password of the user to log in as.
version
string API version to use to log in.
xthorn
string 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 options
Object Refresh options.
Properties
Name Type Description version
string API version to do the refresh request on.
token
string The refresh token of the user you wish to refresh.
xthorn
string 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 chakramMethod
function Chakram request method to call.
args
Array Arguments to call the chakram request method with. The last member of the array must be a
params
-like object.options
Object Additional configuration options.
Properties
Name Type Description refreshToken
string Refresh token to use if you have to do a refresh.
afterRefresh
function Additional tasks to be performed after a refresh occurs. Passed the chakram response object from the refresh.
retryVersion
string API version to make the retry request on. Non-retry requests are made on whatever version is specified by
args
.xthorn
string 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