Home Reference Source Repository
public class | source

OlapicMediaHandler

Extends:

OlapicEntitiesHandler → OlapicMediaHandler

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

Static Method Summary

Static Public Methods
public static

It parses a raw API JSON information and returns a media 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 an Olapic media by its unique ID.

public static

Gets an Olapic media by its API url.

public static

Gets the user that uploaded a media.

public static

Gets all the categories related to this media.

public static

Gets all the streams related to a media.

public static

Report a media to be removed.

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

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

Params:

NameTypeAttributeDescription
json Object

The raw API JSON object to parse.

Return:

OlapicMediaEntity

The entity created from the JSON information.

Example:

const JSONInfo = {
    metadata: {},
    data: {
        caption: 'My Pic!',
    },
};
const media = OlapicMediaHandler.entityFromJSON(JSONInfo);
// It will log 'My Pic!'
console.log(media.get('caption'));

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: {
            media: [
                {
                    caption: 'Photo One',
                },
                {
                    caption: 'Photo Two',
                }
            ],
        },
    },
};
let entities = OlapicMediaHandler.extractEntities(JSONInfo);
// It will log 'Photo One'
console.log(entities[0].get('caption'));

public static getMediaByID(ID: Number): Promise<OlapicMediaEntity, Error> source

Gets an Olapic media by its unique ID.

Params:

NameTypeAttributeDescription
ID Number

The media ID.

Return:

Promise<OlapicMediaEntity, Error>

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

Example:

OlapicMediaHandler.getMediaByID(12)
.then((media) => {
    console.log('Media: ', media);
});

public static getMediaByUrl(url: String): Promise<OlapicMediaEntity, Error> source

Gets an Olapic media by its API url.

Params:

NameTypeAttributeDescription
url String

The Olapic API url for the media.

Return:

Promise<OlapicMediaEntity, Error>

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

Example:

OlapicMediaHandler.getMediaByUrl('http://...')
.then((media) => {
    console.log('Media: ', media);
});

public static getMediaUser(media: OlapicMediaEntity): Promise<OlapicUserEntity, Error> source

Gets the user that uploaded a media.

Params:

NameTypeAttributeDescription
media OlapicMediaEntity

The target media entity.

Return:

Promise<OlapicUserEntity, Error>

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

Example:

OlapicMediaHandler.getMediaUser(mediaEntity).then((user) => {
    console.log(user.get('name'));
});

public static getRelatedCategoriesFromMedia(media: OlapicMediaEntity): Promise<Array, Error> source

Gets all the categories related to this media.

Params:

NameTypeAttributeDescription
media OlapicMediaEntity

The target media entity.

Return:

Promise<Array, Error>

A list of related categories or an Error object if something goes wrong.

Example:

OlapicMediaHandler.getRelatedCategoriesFromMedia(mediaEntity).then((categories) => {
    console.log('Categories: ', categories);
});

public static getRelatedStreamsFromMedia(media: OlapicMediaEntity): Promise<Array, Error> source

Gets all the streams related to a media.

Params:

NameTypeAttributeDescription
media OlapicMediaEntity

The target media entity.

Return:

Promise<Array, Error>

A list of related streams or an Error object if something goes wrong.

Example:

OlapicMediaHandler.getRelatedStreamsFromMedia(mediaEntity).then((streams) => {
    console.log('Streams: ', streams);
});

public static reportMedia(media: OlapicMediaEntity, email: String, reason: String): Promise<Object, Error> source

Report a media to be removed.

Params:

NameTypeAttributeDescription
media OlapicMediaEntity

The target media entity.

email String

The email address of the person reporting the media.

reason String

The reason the media should be taken down.

Return:

Promise<Object, Error>

A response object from the API if the media was successfully reported, or an Error object if something went wrong.

TODO:

  • Improve the response for when the media was successfully to something more than just the API response.