Home Reference Source Repository
public class | source

OlapicWidgetsHandler

Extends:

OlapicEntitiesHandler → OlapicWidgetsHandler

The entities handler for the Olapic widgets in DevKit. It's basically a set of static methods used to create and obtain widgets from the API or DevKit itself.

Static Method Summary

Static Public Methods
public static

It parses a raw API JSON information and returns a widget entity.

public static

Gets an Olapic widget settings by its unique ID.

public static

Gets an Olapic widget settings by its API url.

public static

Gets the widget selected category.

public static

Gets an Olapic widget by its unique hash.

public static

Gets an Olapic widget by its API url.

public static

Gets the settings for a widget.

public static

Gets a widget selected stream.

Inherited Summary

From class OlapicEntitiesHandler
public static get

A quick shortcut to get access to the DevKit singleton.

public static

This will be used when creating an entity to parse any list of action forms and returns them with a better format.

public static

This will be used when creating an entity to parse any list of linked entities and returns them with a better format.

Static Public Methods

public static entityFromJSON(json: Object): OlapicWidgetEntity source

It parses a raw API JSON information and returns a widget entity.

Params:

NameTypeAttributeDescription
json Object

The raw API JSON object to parse.

Return:

OlapicWidgetEntity

The entity created from the JSON information.

Example:

let JSONInfo = {
    metadata: {},
    data: {
        name: 'My Widget',
    },
};
let widget = OlapicWidgetsHandler.entityFromJSON(JSONInfo);
// It will log 'My Widget'
console.log(widget.get('name'));

public static getSettingsByID(ID: String): Promise<Object, Error> source

Gets an Olapic widget settings by its unique ID.

Params:

NameTypeAttributeDescription
ID String

The settings ID.

Return:

Promise<Object, Error>

The widget settings or an Error object if something goes wrong.

Example:

OlapicWidgetsHandler.getSettingsByID(12)
.then((settings) => {
    console.log('Settings: ', settings);
});

public static getSettingsByUrl(url: String): Promise<Object, Error> source

Gets an Olapic widget settings by its API url.

Params:

NameTypeAttributeDescription
url String

The Olapic API url for the widget settings.

Return:

Promise<Object, Error>

The widget settings or an Error object if something goes wrong.

Example:

OlapicWidgetsHandler.getSettingsByUrl('http://...')
.then((settings) => {
    console.log('Settings: ', settings);
});

public static getWidgetCategory(widget: *): Promise<OlapicCategoryEntity, Error> source

Gets the widget selected category.

Params:

NameTypeAttributeDescription
widget *

Return:

Promise<OlapicCategoryEntity, Error>

It will return an category entity or an Error object if something goes wrong or there's no category associated to the wiget.

Example:

OlapicWidgetsHandler.getWidgetCategory(widgetEntity).then((category) => {
    console.log(category.get('name'));
});

public static getWidgetInstanceByHash(hash: String): Promise<OlapicWidgetEntity, Error> source

Gets an Olapic widget by its unique hash.

Params:

NameTypeAttributeDescription
hash String

The Olapic widget unique hash.

Return:

Promise<OlapicWidgetEntity, Error>

The widget entity or an Error object if something goes wrong.

Example:

OlapicWidgetsHandler.getWidgetInstanceByHash('abc')
.then((widget) => {
    console.log('Widget: ', widget);
});

public static getWidgetInstanceByUrl(url: String): Promise<OlapicWidgetEntity, Error> source

Gets an Olapic widget by its API url.

Params:

NameTypeAttributeDescription
url String

The Olapic API url for the widget.

Return:

Promise<OlapicWidgetEntity, Error>

The widget entity or an Error object if something goes wrong.

Example:

OlapicWidgetsHandler.getWidgetInstanceByUrl('http://...')
.then((widget) => {
    console.log('Widget: ', widget);
});

public static getWidgetSettings(widget: OlapicWidgetEntity): Promise<Object, Error> source

Gets the settings for a widget.

Params:

NameTypeAttributeDescription
widget OlapicWidgetEntity

The widget entity for which the settings are for.

Return:

Promise<Object, Error>

It will return an object with all the widget settings, or an Error object in case something goes wrong.

public static getWidgetStream(widget: *): Promise<OlapicStreamEntity, Error> source

Gets a widget selected stream.

Params:

NameTypeAttributeDescription
widget *

Return:

Promise<OlapicStreamEntity, Error>

It will return an stream entity or an Error object if something goes wrong or there's no stream associated to the widget.

Example:

OlapicWidgetsHandler.getWidgetStream(widgetEntity).then((stream) => {
    console.log(stream.get('name'));
});