Home Reference Source Repository
import OlapicDevKit from 'OlapicDevKit-ES6/src/core/devkit.js'
public class | source

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

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

Set the Olapic API version to use.

public get

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

connect(widgetInstance: string): Promise<Object, Error>

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:

NameTypeAttributeDescription
APIKey string
  • optional
  • default: null

The Olapic customer API key.

Return:

OlapicDevKit

The singleton instance of OlapicDevKit.

Example:

let instance = OlapicDevKit.getInstance();

Public Members

public set APIKey: * source

Set the Olapic customer API key.

public get APIKey: * source

Get the Olapic customer API key.

public APIUrl: string source

The Olapic API entry point.

public set APIVersion: * source

Set the Olapic API version to use.

public get APIVersion: * source

Get the Olapic API version.

public connected: boolean source

A flag to know if the instance is connected and has the customer information.

public customer: OlapicCustomerEntity source

The connected customer information.

See:

public rest: OlapicRestClient source

The rest client that makes the requests to the API.

See:

Public Methods

public connect(widgetInstance: string): Promise<Object, Error> source

Connects DevKit to the API and returns the customer entity.

Params:

NameTypeAttributeDescription
widgetInstance string
  • optional
  • default: null

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;
});

See:

public disconnect() source

Disconnect DevKit from the current customer.

public getEndpoint(endpoint: string, parameters: Object): string source

Get one of the endpoints for the Olapic API.

Params:

NameTypeAttributeDescription
endpoint string

The endpoint name.

parameters Object
  • optional
  • default: {}

A list of required parameters for the endpoint.

Return:

string

The generated API endpoint.

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'});