Home Reference Source Repository
public class | source

OlapicStreamsHandler

Extends:

OlapicEntitiesHandler → OlapicStreamsHandler

The entities handler for the Olapic streams in DevKit. It's basically a set of static methods used to create and obtain streams entities from the API or DevKit itself. It also allows you to acces streams resources, as the cover and base image, from the API.

Static Method Summary

Static Public Methods
public static

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

public static

When requesting a collection of entities, the API response contains an array instead of an object, so this method will loop the array, create entities using .entityFromJSON() and return a new array of entities.

public static

Gets a stream base image as a media entity.

public static

Gets an Olapic stream by its unique ID.

public static

Gets an Olapic stream by its API url.

public static

Gets a stream cover image as a media entity.

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): OlapicStreamEntity source

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

Params:

NameTypeAttributeDescription
json Object

The raw API JSON object to parse.

Return:

OlapicStreamEntity

The entity created from the JSON information.

Example:

let JSONInfo = {
    metadata: {},
    data: {
        name: 'My Stream',
    },
};
let stream = OlapicStreamsHandler.entityFromJSON(JSONInfo);
// It will log 'My Stream'
console.log(stream.get('name'));

public static extractEntities(obj: Object): Array source

When requesting a collection of entities, the API response contains an array instead of an object, so this method will loop the array, create entities using .entityFromJSON() and return a new array of entities.

Params:

NameTypeAttributeDescription
obj Object

The API response with the array.

Return:

Array

A list of parsed entities.

Example:

let JSONInfo = {
    metadata: {},
    data: {
        _embedded: {
            stream: [
                {
                    name: 'Stream One',
                },
                {
                    name: 'Stream Two',
                }
            ],
        },
    },
};
let entities = OlapicStreamsHandler.extractEntities(JSONInfo);
// It will log 'Stream One'
console.log(entities[0].get('name'));

public static getStreamBaseImage(stream: *): Promise<OlapicMediaEntity, Error> source

Gets a stream base image as a media entity.

Params:

NameTypeAttributeDescription
stream *

Return:

Promise<OlapicMediaEntity, Error>

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

Example:

OlapicStreamsHandler.getStreamBaseImage(streamEntity).then((media) => {
    console.log(media.get('caption'));
});

public static getStreamByID(ID: Number): Promise<OlapicStreamEntity, Error> source

Gets an Olapic stream by its unique ID.

Params:

NameTypeAttributeDescription
ID Number

The stream ID.

Return:

Promise<OlapicStreamEntity, Error>

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

Example:

OlapicStreamsHandler.getStreamByID(12)
.then((stream) => {
    console.log('Stream: ', stream);
});

public static getStreamByUrl(url: String): Promise<OlapicStreamEntity, Error> source

Gets an Olapic stream by its API url.

Params:

NameTypeAttributeDescription
url String

The Olapic API url for the stream.

Return:

Promise<OlapicStreamEntity, Error>

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

Example:

OlapicStreamsHandler.getStreamByUrl('http://...')
.then((stream) => {
    console.log('Stream: ', stream);
});

public static getStreamCoverImage(stream: *): Promise<OlapicMediaEntity, Error> source

Gets a stream cover image as a media entity.

Params:

NameTypeAttributeDescription
stream *

Return:

Promise<OlapicMediaEntity, Error>

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

Example:

OlapicStreamsHandler.getStreamCoverImage(streamEntity).then((media) => {
    console.log(media.get('caption'));
});