import OlapicMediaHandler from 'OlapicDevKit-ES6/src/core/entities/media/media.handler.js'
OlapicMediaHandler
Extends:
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 |
entityFromJSON(json: Object): OlapicMediaEntity It parses a raw API JSON information and returns a media 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 |
getMediaByID(ID: Number): Promise<OlapicMediaEntity, Error> Gets an Olapic media by its unique ID. |
|
public static |
getMediaByUrl(url: String): Promise<OlapicMediaEntity, Error> Gets an Olapic media by its API url. |
|
public static |
getMediaUser(media: OlapicMediaEntity): Promise<OlapicUserEntity, Error> Gets the user that uploaded a media. |
|
public static |
Gets all the categories related to this media. |
|
public static |
getRelatedStreamsFromMedia(media: OlapicMediaEntity): Promise<Array, Error> Gets all the streams related to a media. |
|
public static |
reportMedia(media: OlapicMediaEntity, email: String, reason: String): Promise<Object, Error> Report a media to be removed. |
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): OlapicMediaEntity source
It parses a raw API JSON information and returns a media entity.
Params:
Name | Type | Attribute | Description |
json | Object | The raw API JSON object to parse. |
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:
Name | Type | Attribute | Description |
obj | Object | The API response with the array. |
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:
Name | Type | Attribute | Description |
ID | Number | The media ID. |
Return:
Promise<OlapicMediaEntity, Error> | The media entity or an |
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:
Name | Type | Attribute | Description |
url | String | The Olapic API url for the media. |
Return:
Promise<OlapicMediaEntity, Error> | The media entity or an |
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:
Name | Type | Attribute | Description |
media | OlapicMediaEntity | The target media entity. |
Return:
Promise<OlapicUserEntity, Error> | A promise with the user entity or an |
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:
Name | Type | Attribute | Description |
media | OlapicMediaEntity | The target media entity. |
Return:
Promise<Array, Error> | A list of related categories or an |
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:
Name | Type | Attribute | Description |
media | OlapicMediaEntity | The target media entity. |
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:
Name | Type | Attribute | Description |
media | OlapicMediaEntity | The target media entity. |
|
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 |
TODO:
- Improve the response for when the media was successfully to something more than just the API response.