import OlapicStreamsHandler from 'olapic-devkit/src/core/entities/stream/stream.handler.js'
OlapicStreamsHandler
Extends:
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 |
entityFromJSON(json: Object): OlapicStreamEntity It parses a raw API JSON information and returns a stream entity. |
|
public static |
extractEntities(obj: Object): Array 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 |
|
public static |
getStreamBaseImage(stream: *): Promise<OlapicMediaEntity, Error> Gets a stream base image as a media entity. |
|
public static |
Gets an Olapic stream by its unique ID. |
|
public static |
getStreamByUrl(url: String): Promise<OlapicStreamEntity, Error> Gets an Olapic stream by its API url. |
|
public static |
getStreamCoverImage(stream: *): Promise<OlapicMediaEntity, Error> Gets a stream cover image as a media entity. |
Inherited Summary
From class OlapicEntitiesHandler | ||
public static get |
DevKit: OlapicDevKit: * A quick shortcut to get access to the DevKit singleton. |
|
public static |
getFormsFromObject(obj: Object): Object This will be used when creating an entity to parse any list of action forms and returns them with a better format. |
|
public static |
getResourcesFromObject(obj: Object): Object 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:
Name | Type | Attribute | Description |
json | Object | The raw API JSON object to parse. |
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:
Name | Type | Attribute | Description |
obj | Object | The API response with the array. |
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:
Name | Type | Attribute | Description |
stream | * |
Return:
Promise<OlapicMediaEntity, Error> | A promise with the media entity or an |
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:
Name | Type | Attribute | Description |
ID | Number | The stream ID. |
Return:
Promise<OlapicStreamEntity, Error> | The stream entity or an |
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:
Name | Type | Attribute | Description |
url | String | The Olapic API url for the stream. |
Return:
Promise<OlapicStreamEntity, Error> | The stream entity or an |
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:
Name | Type | Attribute | Description |
stream | * |
Return:
Promise<OlapicMediaEntity, Error> | A promise with the media entity or an |
Example:
OlapicStreamsHandler.getStreamCoverImage(streamEntity).then((media) => {
console.log(media.get('caption'));
});