src/models/Image.js
/**
* Model representing a image.
*/
class ImageModel {
/**
* @param {Object} response - JSON formatted response of a single image
* @param {String} response.url - A url to the raw image
* @param {String} response.fullscreen - A url to the fullscreen image
* @param {String} response.fullscreen.url - A url to the fullscreen image
* @param {String} response.fullscreen_hd - A url to the fullscreen_hd image
* @param {String} response.fullscreen_hd.url - A url to the fullscreen_hd image
* @param {String} response.main - A url to the main image
* @param {String} response.main.url - A url to the main image
* @param {String} response.main_hd - A url to the main_hd image
* @param {String} response.main_hd.url - A url to the main_hd image
* @param {String} response.small - A url to the small image
* @param {String} response.small.url - A url to the small image
* @param {String} response.small_hd - A url to the small_hd image
* @param {String} response.small_hd.url - A url to the small_hd image
*/
constructor(response = {}) {
const _response = response.data || response; // if json api is passed in directly
const attributes = _response.attributes || _response; // if json api is passed in directly
if (_response.id) {
/** @type {Number} */
this.id = parseInt(_response.id, 10);
}
/** @type {String} */
this.url = attributes.url;
if (attributes.fullscreen) {
/** @type {String} */
this.fullscreen = attributes.fullscreen.url;
}
if (attributes.fullscreen_hd) {
/** @type {String} */
this.fullscreenHd = attributes.fullscreen_hd.url;
}
if (attributes.main) {
/** @type {String} */
this.main = attributes.main.url;
}
if (attributes.main_hd) {
/** @type {String} */
this.mainHd = attributes.main_hd.url;
}
if (attributes.small) {
/** @type {String} */
this.small = attributes.small.url;
}
if (attributes.small_hd) {
/** @type {String} */
this.smallHd = attributes.small_hd.url;
}
if (attributes.thumb) {
/** @type {String} */
this.thumb = attributes.thumb.url;
}
}
}
export default ImageModel;