Manual Reference Source Test
import Client from 'clinical6/src/Client.js'
public class | source

Client

Client is a static class that is used for setting system wide information about connection, device, and general SDK settings.

Test:

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

Sets the apiBaseUrl for passing on to following request

public get

Gets the authToken

public set

authToken(authToken: String): String

Sets the authToken for passing on to following request

public get

Gets the configuration information

public set

config(data: Object): Object

Sets the configuration for Clinical6

public set

device(device: Device): Device

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

onError(reject: Function)

Sets promise error handler

public get

Gets promise error handler

public set

settings(settings: Object): Object

Set settings

public get
public set

Provides a way to override the way that Storage is storing

public get

Gets the user

public set

user(user: User): User

Sets the user for passing on to following request

Private Members
private
private
private
private
private

Method Summary

Public Methods
public

abort(filter: Function)

Aborts all or filtered active XMLHttpRequests from clinical6

public

fetch(url: String, method: String, data: Object, headers: Object): Promise

Prepare and Fetch HTTP request to API

public

http(json: Object): Promise

Prepare and Fetch HTTP request to API with more customization

public

request(cacheKey: String, fetchPromise: Promise<any>, options: Object): Promise<any>

Fetches from either store or from the network

public

reset()

Resets user data and Authentication information

Static Public Members

public static [clientSingleton]: Client source

public static get instance: Object source

Get the instance of the client

Public Constructors

public constructor(enforcer: Symbol) source

Constructor

Params:

NameTypeAttributeDescription
enforcer Symbol

Public Members

public get apiBaseUrl: String source

Gets the apiBaseUrl

public set apiBaseUrl(url: String): String source

Sets the apiBaseUrl for passing on to following request

public get authToken: String source

Gets the authToken

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:

NameTypeAttributeDescription
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:

NameTypeAttributeDescription
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 get mobileApplicationKey: String source

Gets the mobileApplicationKey

public set mobileApplicationKey(mobileApplicationKey: String): String source

Sets the mobileApplicationKey for passing on to following request

public set onError(reject: Function) source

Sets promise error handler

public get onError: Function source

Gets promise error handler

public set settings(settings: Object): Object source

Set settings

public get storageUtility: StorageUtility source

public set storageUtility(storageUtility: StorageUtility): StorageUtility source

Provides a way to override the way that Storage is storing

public get user: User source

Gets the user

public set user(user: User): User source

Sets the user for passing on to following request

Private Members

private _activeRequests: any[] source

private _config: Object source

private _device: Device source

private _storageUtility: StorageUtility source

private _user: User source

Public Methods

public abort(filter: Function) source

Aborts all or filtered active XMLHttpRequests from clinical6

Params:

NameTypeAttributeDescription
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:

NameTypeAttributeDescription
url String
  • nullable: false

Path to the endpoint starting with '/'

method String
  • optional
  • nullable: true

HTTP Method (DELETE|GET|POST|PUT)

data Object
  • optional
  • nullable: true

JSON payload, required on POST and PUT calls.

headers Object
  • optional
  • nullable: true

Key/Value list of headers. Defaults to { Accept: 'application/json', 'Content-Type': 'application/json' }

Return:

Promise

Resolves on HTTP 200. Rejects on all else.

public http(json: Object): Promise source

Prepare and Fetch HTTP request to API with more customization

Params:

NameTypeAttributeDescription
json Object

Object containing connection information

json.url String
  • nullable: false

Path to the endpoint starting with '/'

json.method String
  • optional
  • nullable: true

HTTP Method (DELETE|GET|POST|PUT)

json.data Object
  • optional
  • nullable: true

JSON payload, required on POST and PUT calls.

json.headers Object
  • optional
  • nullable: true

Key/Value list of headers. Defaults to { Accept: 'application/json', 'Content-Type': 'application/json' }

Return:

Promise

Resolves on HTTP 200. Rejects on all else.

public request(cacheKey: String, fetchPromise: Promise<any>, options: Object): Promise<any> source

Fetches from either store or from the network

Params:

NameTypeAttributeDescription
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
  • optional

The cache mode (e.g. 'networkFirst'). Defaults to whatever is in Client.cacheMode.

options.id Number
  • optional

The id for a specific item

options.resolve Function
  • optional

Function that resolves the data to the calling application. Default will use data directly from fetch response.

options.store Function
  • optional

Function that returns data to be stored. Default will use data directly from fetch response.

options.key Function
  • optional

The key used for the hash id in storage.

Return:

Promise<any>

Promise indicating success or failure

public reset() source

Resets user data and Authentication information