Home Reference Source Repository
public class | source

OlapicCustomersHandler

Extends:

OlapicEntitiesHandler → OlapicCustomersHandler

The entities handler for the Olapic customers in DevKit.

Static Method Summary

Static Public Methods
public static

Creates a new user to upload media for a customer.

public static

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

public static

Gets an Olapic customer by its unique ID.

public static

Gets an Olapic customer by its API url.

public static

Gets a user to upload media for a customer.

public static

Searchs for a customer category based on its tag key.

public static

Searchs for a customer stream based on its tag key.

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 createUserForCustomer(customer: OlapicCustomerEntity, name: String, email: String): Promise<OlapicUserEntity, Error> source

Creates a new user to upload media for a customer.

Params:

NameTypeAttributeDescription
customer OlapicCustomerEntity

The customer entity for which the user will be created.

name String

The new user name.

email String

The new user email address.

Return:

Promise<OlapicUserEntity, Error>

A promise with the user entity or an Error object if something goes wrong.

Example:

OlapicCustomersHandler.createUserForCustomer(customerEntity, 'myName', '[email protected]')
.then((user) => {
    console.log(user.get('name'));
});

public static entityFromJSON(json: Object): OlapicCustomerEntity source

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

Params:

NameTypeAttributeDescription
json Object

The raw API JSON object to parse.

Return:

OlapicCustomerEntity

The entity created from the JSON information.

Example:

let JSONInfo = {
    metadata: {},
    data: {
        name: 'Olapic Customer',
    },
};
let customer = OlapicCustomersHandler.entityFromJSON(JSONInfo);
// It will log 'Olapic Customer'
console.log(customer.get('name'));

public static getCustomerByID(ID: Number): Promise<OlapicCustomerEntity, Error> source

Gets an Olapic customer by its unique ID.

Params:

NameTypeAttributeDescription
ID Number

The customer ID.

Return:

Promise<OlapicCustomerEntity, Error>

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

Example:

OlapicCustomersHandler.getCustomerByID(12)
.then((customer) => {
    console.log('Customer: ', customer);
});

public static getCustomerByUrl(url: String): Promise<OlapicCustomerEntity, Error> source

Gets an Olapic customer by its API url.

Params:

NameTypeAttributeDescription
url String

The Olapic API url for the customer.

Return:

Promise<OlapicCustomerEntity, Error>

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

Example:

OlapicCustomersHandler.getCustomerByUrl('http://...')
.then((customer) => {
    console.log('Customer: ', customer);
});

public static getUserFromCustomer(customer: OlapicCustomerEntity): Promise<OlapicUserEntity, Error> source

Gets a user to upload media for a customer.

Params:

NameTypeAttributeDescription
customer OlapicCustomerEntity

The customer entity for which the user will be obtained.

Return:

Promise<OlapicUserEntity, Error>

A promise with the user entity or an Error object if something goes wrong.

Example:

OlapicCustomersHandler.getUserFromCustomer(customerEntity)
.then((user) {
    console.log(user.get('name'));
});

public static searchCategoryFromCustomer(customer: OlapicCustomerEntity, tag: String): Promise<OlapicCategoryEntity, Error> source

Searchs for a customer category based on its tag key.

Params:

NameTypeAttributeDescription
customer OlapicCustomerEntity

The customer owner of the category.

tag String

The category tag key.

Return:

Promise<OlapicCategoryEntity, Error>

A promise with the catgory entity or an Error object if something goes wrong.

Example:

OlapicCustomersHandler.searchCategoryFromCustomer(customerEntity, 'shoes')
.then((category) => {
    console.log(category.get('name'));
});

public static searchStreamFromCustomer(customer: OlapicCustomerEntity, tag: String): Promise<OlapicStreamEntity, Error> source

Searchs for a customer stream based on its tag key.

Params:

NameTypeAttributeDescription
customer OlapicCustomerEntity

The customer owner of the stream.

tag String

The stream tag key.

Return:

Promise<OlapicStreamEntity, Error>

A promise with the stream entity or an Error object if something goes wrong.

Example:

OlapicCustomersHandler.searchStreamFromCustomer(customerEntity, 'shoes').then((stream) => {
    console.log(stream.get('name'));
});