OlapicDevKit
The main singleton for the DevKit project. It handles the first connection to to the API and
stores the customer information.
To have access to this object, you should always call .getInstance()
. If you try to
instantiate it with the new
keyword it will throw an error.
Example:
let instance = OlapicDevKit.getInstance();
Static Method Summary
Static Public Methods | ||
public static |
getInstance(APIKey: string): OlapicDevKit Gets the singleton instance, and optionally sets a new API key. |
Member Summary
Public Members | ||
public set |
APIKey: * Set the Olapic customer API key. |
|
public get |
APIKey: * Get the Olapic customer API key. |
|
public |
The Olapic API entry point. |
|
public set |
APIVersion: * Set the Olapic API version to use. |
|
public get |
APIVersion: * Get the Olapic API version. |
|
public |
A flag to know if the instance is connected and has the customer information. |
|
public |
The connected customer information. |
|
public |
The rest client that makes the requests to the API. |
Method Summary
Public Methods | ||
public |
Connects DevKit to the API and returns the customer entity. |
|
public |
Disconnect DevKit from the current customer. |
|
public |
getEndpoint(endpoint: string, parameters: Object): string Get one of the endpoints for the Olapic API. |
Static Public Methods
public static getInstance(APIKey: string): OlapicDevKit source
Gets the singleton instance, and optionally sets a new API key.
Params:
Name | Type | Attribute | Description |
APIKey | string |
|
The Olapic customer API key. |
Example:
let instance = OlapicDevKit.getInstance();
Public Members
public connected: boolean source
A flag to know if the instance is connected and has the customer information.
Public Methods
public connect(widgetInstance: string): Promise<Object, Error> source
Connects DevKit to the API and returns the customer entity.
Params:
Name | Type | Attribute | Description |
widgetInstance | string |
|
A widget instance ID so the connection will also retrieve a widget entity. |
Return:
Promise<Object, Error> | If the widget instance is specified, it will return an Object with the keys customer and widget, otherwise, it will return a customer entity. |
Example:
.connect(widgetID).then((response) => {
let {customer, widget} = response;
});
public getEndpoint(endpoint: string, parameters: Object): string source
Get one of the endpoints for the Olapic API.
Example:
// Returns .../category/12
.getEndpoint('categoryByID', { ID: 12 });
// Returns .../widgets/abc
.getEndpoint('widgetByHash', { hash: 'abc' });
// Returns .../widgets/settings/12
.getEndpoint('widgetSettingsByID', { ID: 12 });
// Returns .../customers/12
.getEndpoint('customerByID', { ID: 12 });
// Returns .../media/12
.getEndpoint('mediaByID', { ID: 12 });
// Returns .../streams/12
.getEndpoint('streamByID', { ID: 12 });
// Returns .../users/12
.getEndpoint('userByID', { ID: 12 });
// Returns .../customers/12/instagram_users/olapic
.getEndpoint('instagramUserForCustomer', { ID: 12, username: 'olapic'});