OlapicRestClient
Handles all the connections between DevKit and the Olapic API.
This class is instantiated by the DevKit singletion and saved on the rest
property.
See:
Constructor Summary
Public Constructor | ||
public |
Rest client class constructor. |
Member Summary
Public Members | ||
public |
A flag to determine if it should show debug messages on the console. |
|
public |
A flag to determine if the urls on the pre cache should be cleaned from the Olapic CDN sharding pattern. |
|
public |
This object will store all the pre cache entries using their urls as key. |
|
public |
A list of the embedded properties that can be pre cached. |
|
public |
An extra validation for the embedded properties that can be pre cached. |
|
public |
A flag to determine if the pre cache it's enabled. |
|
public |
For the pre cache to be executed after a request, the endpoint has to match this expression. |
|
public |
A list of entities which names will be replaced when they are retrieved from the pre cache. |
|
public |
A regex used to remove the sharding pattern from the pre cache urls. |
Method Summary
Public Methods | ||
public |
cleanCache(): Array Removes all the entries from the pre cache. |
|
public |
Makes a GET request to the API. |
|
public |
Get access to the fetch object that the rest client uses for every request to the API. |
|
public |
Get the value of one of the editable options. |
|
public |
Gets a list of base headers to be included on every request. |
|
public |
Gets a list of base parameters that are included on every request query string. |
|
public |
Makes a POST request to the API. |
|
public |
setFetchObject(obj: Object) Set a fetch object to be used for the API requests. |
|
public |
Change the value of one of th editable options of the class. |
|
public |
setOptions(options: Object): void A shortcut to call {setOption} for a list of options. |
|
public |
setRequestBaseHeaders(headers: Object) Sets a list of headers to be included on every request. |
|
public |
setRequestBaseQuery(query: Object) Sets a list of parameters to be included on every request query string. |
|
public |
This method is for when the embedded properties are used from the raw response and should be removed from the pre cache. |
Public Constructors
Public Members
public filterSharding: boolean source
A flag to determine if the urls on the pre cache should be cleaned from the Olapic CDN sharding pattern.
public preCache: Object source
This object will store all the pre cache entries using their urls as key.
public preCacheEmbeddedProperties: Array source
A list of the embedded properties that can be pre cached.
public preCacheEmbeddedPropertiesPerEndpoint: Object source
An extra validation for the embedded properties that can be pre cached. This is optional, and if a property is listed, the main endpoint (where the request was made) should match against the specified expression.
Example:
.preCacheEmbeddedPropertiesPerEndpoint = {
'streams:all': /\/media\/[0-9]+\?/g,
}
public preCacheEndpoints: RegExp source
For the pre cache to be executed after a request, the endpoint has to match this expression.
Public Methods
public get(url: string, query: Object, headers: Object): Promise<Object, Error> source
Makes a GET request to the API.
Example:
.get('/media/12', {auth_token: 'abc'}).then((response) => {
console.log(response);
});
public getFetchObject(): Object source
Get access to the fetch object that the rest client uses for every request to the API.
Return:
Object | If no object was injected with {setFetchObject}, it will return the native
|
public getOption(name: string): * source
Get the value of one of the editable options.
Params:
Name | Type | Attribute | Description |
name | string | The option name. |
Return:
* | The option value. |
TODO:
- Remove this and replace the editable options with simple properties and/or getters and setters.
public getRequestBaseHeaders(): Object source
Gets a list of base headers to be included on every request.
public getRequestBaseQuery(): Object source
Gets a list of base parameters that are included on every request query string.
public post(url: string, data: Object, query: Object, headers: Object): Promise<Object, Error> source
Makes a POST request to the API.
Example:
.post('/media/12/report', {reason: '...'}, {auth_token: 'abc'}).then((response) => {
console.log(response);
});
public setFetchObject(obj: Object) source
Set a fetch object to be used for the API requests. This is intended to inject a stub that can be used for unit testing.
Params:
Name | Type | Attribute | Description |
obj | Object | The new fetch object. |
public setOption(name: string, value: *, append: boolean): * source
Change the value of one of th editable options of the class.
Return:
* |
TODO:
- Remove this and replace the editable options with simple properties and/or getters and setters.
public setOptions(options: Object): void source
A shortcut to call {setOption} for a list of options.
Params:
Name | Type | Attribute | Description |
options | Object | A dictionary with the options to edit and their values. |
Return:
void |
Example:
.setOptions({
option1: 'value1',
option2: 'value2',
});
TODO:
- Remove this and replace the editable options with simple properties and/or getters and setters.
public setRequestBaseHeaders(headers: Object) source
Sets a list of headers to be included on every request.
Params:
Name | Type | Attribute | Description |
headers | Object |
|
A list of headers and their values. |