Client
Client is a static class that is used for setting system wide information about connection, device, and general SDK settings.
Test:
- [unit] Client should handle unauthorized request
- [unit] Client exists
- [unit] Client.instance() should not allow the creation of the instance
- [unit] Client.instance() should return the instance of client
- [unit] Client should throw an error if instantiated with a non-string baseurl
- [unit] Client should construct an instance instantiated with baseurl
- [unit] Client should have a fetch method
- [unit] Client should throw an error on fetch when data is not present in put call
Static Member Summary
Static Public Members | ||
public static |
|
|
public static get |
Get the instance of the client |
Constructor Summary
Public Constructor | ||
public |
constructor(enforcer: Symbol) Constructor |
Member Summary
Public Members | ||
public get |
Gets the apiBaseUrl |
|
public set |
apiBaseUrl(url: String): String Sets the apiBaseUrl for passing on to following request |
|
public get |
Gets the authToken |
|
public set |
Sets the authToken for passing on to following request |
|
public get |
Gets the configuration information |
|
public set |
Sets the configuration for Clinical6 |
|
public set |
Sets the device for Clinical6, includes strings technology, version, uuid, and pushId |
|
public get |
Gets the device for Clinical6, includes strings technology, version, uuid, and pushId |
|
public get |
Gets the mobileApplicationKey |
|
public set |
mobileApplicationKey(mobileApplicationKey: String): String Sets the mobileApplicationKey for passing on to following request |
|
public set |
Sets promise error handler |
|
public get |
Gets promise error handler |
|
public set |
Set settings |
|
public get |
|
|
public set |
storageUtility(storageUtility: StorageUtility): StorageUtility Provides a way to override the way that Storage is storing |
|
public get |
Gets the user |
|
public set |
Sets the user for passing on to following request |
Private Members | ||
private |
_activeRequests: any[] |
|
private |
|
|
private |
|
|
private |
|
|
private |
|
Method Summary
Public Methods | ||
public |
Aborts all or filtered active XMLHttpRequests from clinical6 |
|
public |
Prepare and Fetch HTTP request to API |
|
public |
Prepare and Fetch HTTP request to API with more customization |
|
public |
Fetches from either store or from the network |
|
public |
reset() Resets user data and Authentication information |
Static Public Members
Public Constructors
Public Members
public set apiBaseUrl(url: String): String source
Sets the apiBaseUrl for passing on to following request
public set authToken(authToken: String): String source
Sets the authToken for passing on to following request
public get config: Object source
Gets the configuration information
Properties:
Name | Type | Attribute | Description |
config.apiBaseUrl | String | url |
|
config.authToken | String | some random string |
|
config.mobileApplicationKey | String | mobile application key |
|
config.track | Object | object to trigger Analytics tracking |
|
config.track.flows | Boolean | Log flows to Analytics |
|
config.track.gps | Boolean | Track GPS |
public set config(data: Object): Object source
Sets the configuration for Clinical6
Properties:
Name | Type | Attribute | Description |
config.apiBaseUrl | String | url |
|
config.authToken | String | some random string |
|
config.mobileApplicationKey | String | mobile application key |
|
config.track | Object | object to trigger Analytics tracking |
|
config.track.flows | Boolean | Log flows to Analytics |
|
config.track.gps | Boolean | Track GPS |
public set device(device: Device): Device source
Sets the device for Clinical6, includes strings technology, version, uuid, and pushId
public get device: Device source
Gets the device for Clinical6, includes strings technology, version, uuid, and pushId
public set mobileApplicationKey(mobileApplicationKey: String): String source
Sets the mobileApplicationKey for passing on to following request
public get storageUtility: StorageUtility source
public set storageUtility(storageUtility: StorageUtility): StorageUtility source
Provides a way to override the way that Storage is storing
Private Members
private _activeRequests: any[] source
private _storageUtility: StorageUtility source
Public Methods
public abort(filter: Function) source
Aborts all or filtered active XMLHttpRequests from clinical6
Params:
Name | Type | Attribute | Description |
filter | Function | Allow developers to filter which ones to abort |
Example:
import { clinical6 } from 'clinical6';
clinical6.Client.abort();
clinical6.Client.abort(r => r.url === '/v3/badges' && r.method === 'PATCH'); // stop updating badges
public fetch(url: String, method: String, data: Object, headers: Object): Promise source
Prepare and Fetch HTTP request to API
Params:
Name | Type | Attribute | Description |
url | String |
|
Path to the endpoint starting with '/' |
method | String |
|
HTTP Method (DELETE|GET|POST|PUT) |
data | Object |
|
JSON payload, required on POST and PUT calls. |
headers | Object |
|
Key/Value list of headers. Defaults to |
public http(json: Object): Promise source
Prepare and Fetch HTTP request to API with more customization
Params:
Name | Type | Attribute | Description |
json | Object | Object containing connection information |
|
json.url | String |
|
Path to the endpoint starting with '/' |
json.method | String |
|
HTTP Method (DELETE|GET|POST|PUT) |
json.data | Object |
|
JSON payload, required on POST and PUT calls. |
json.headers | Object |
|
Key/Value list of headers. Defaults to |
public request(cacheKey: String, fetchPromise: Promise<any>, options: Object): Promise<any> source
Fetches from either store or from the network
Params:
Name | Type | Attribute | Description |
cacheKey | String | The data type or key for cache / storage |
|
fetchPromise | Promise<any> | The promise expecting a fetch call |
|
options | Object | Expected options |
|
options.mode | Number |
|
The cache mode (e.g. 'networkFirst'). Defaults to whatever is in Client.cacheMode. |
options.id | Number |
|
The id for a specific item |
options.resolve | Function |
|
Function that resolves the data to the calling application. Default will use data directly from fetch response. |
options.store | Function |
|
Function that returns data to be stored. Default will use data directly from fetch response. |
options.key | Function |
|
The key used for the hash id in storage. |