baasic-sdk-javascript
Version:
JavaScript SDK provides core functionality for building web and mobile applications on [Baasic](http://www.baasic.com/).
189 lines (188 loc) • 9.96 kB
JavaScript
"use strict";
/* globals module */
/**
* @module mediaGalleryClient
* @description Media Gallery Client provides Baasic route templates which can be expanded to Baasic REST URIs. Various services can use Baasic Media Gallery Route Service to obtain needed routes while other routes will be obtained through HAL. By convention, all route services use the same function names as their corresponding services.
*/
Object.defineProperty(exports, "__esModule", { value: true });
var tslib_1 = require("tslib");
var inversify_1 = require("inversify");
;
var httpApi_1 = require("../../httpApi");
var _1 = require("./");
var MediaGalleryClient = /** @class */ (function () {
function MediaGalleryClient(mediaGalleryRoute, apiClient, mediaGalleryBatchClient, mediaGalleryFileStreamClient, mediaGalleryInstanceFilesClient, mediaGallerySettingsClient) {
this.mediaGalleryRoute = mediaGalleryRoute;
this.apiClient = apiClient;
this.mediaGalleryBatchClient = mediaGalleryBatchClient;
this.mediaGalleryFileStreamClient = mediaGalleryFileStreamClient;
this.mediaGalleryInstanceFilesClient = mediaGalleryInstanceFilesClient;
this.mediaGallerySettingsClient = mediaGallerySettingsClient;
}
Object.defineProperty(MediaGalleryClient.prototype, "routeDefinition", {
get: function () {
return this.mediaGalleryRoute;
},
enumerable: true,
configurable: true
});
Object.defineProperty(MediaGalleryClient.prototype, "streams", {
get: function () {
return this.mediaGalleryFileStreamClient;
},
enumerable: true,
configurable: true
});
Object.defineProperty(MediaGalleryClient.prototype, "batch", {
get: function () {
return this.mediaGalleryBatchClient;
},
enumerable: true,
configurable: true
});
Object.defineProperty(MediaGalleryClient.prototype, "files", {
get: function () {
return this.mediaGalleryInstanceFilesClient;
},
enumerable: true,
configurable: true
});
/**
* Returns a promise that is resolved once the find action has been performed. Success response returns a list of media gallery resources matching the given criteria.
* @method
* @param options Query resource options object.
* @returns A promise that is resolved once the find action has been performed.
* @example mediaGalleryClient.find({
pageNumber : 1,
pageSize : 10,
orderBy : '<field>',
orderDirection : '<asc|desc>',
search : '<search-phrase>',
ids: '1,2,5',
from: '',
to: ''
})
.then(function (collection) {
// perform success action here
},
function (response, status, headers, config) {
// perform error handling here
});
**/
MediaGalleryClient.prototype.find = function (options) {
return this.apiClient.get(this.routeDefinition.find(options));
};
/**
* Returns a promise that is resolved once the get action has been performed. Success response returns requested media gallery resource.
* @method
* @param id Media gallery id which uniquely identifies media gallery resource that needs to be retrieved.
* @param options Query resource options object.
* @returns A promise that is resolved once the get action has been performed.
* @example mediaGalleryClient.get('<media-gallery-id>')
.then(function (data) {
// perform success action here
},
function (response, status, headers, config) {
// perform error handling here
});
**/
MediaGalleryClient.prototype.get = function (id, options) {
return this.apiClient.get(this.routeDefinition.get(id, options));
};
/**
* Returns a promise that is resolved once the update media gallery action has been performed; this action will update a media gallery resource if successfully completed. This route uses HAL enabled objects to obtain routes and therefore it doesn't apply `mediaGalleryRoute` route template. Here is an example of how a route can be obtained from HAL enabled objects:
* ```
* let params = modelMapper.updateParams(mediaGalleryEntry);
* let uri = params['model'].links('put').href;
* ```
* @method
* @param data A media gallery object used to update specified media gallery resource.
* @returns A promise that is resolved once the update media gallery action has been performed.
* @example // mediaGalleryEntry is a media gallery resource previously fetched using get action.
mediaGalleryEntry.description = '<description>';
mediaGalleryClient.update(mediaGalleryEntry)
.then(function (data) {
// perform success action here
},
function (response, status, headers, config) {
// perform error handling here
});
**/
MediaGalleryClient.prototype.update = function (data) {
return this.apiClient.put(this.routeDefinition.update(data), this.routeDefinition.updateParams(data));
};
/**
* Returns a promise that is resolved once the remove action has been performed. This action will remove one media gallery resources from the system if successfully completed. Specified media gallery and all accompanying derived resources will be removed from the system. This route uses HAL enabled objects to obtain routes and therefore it doesn't apply baasicMediaGalleryRouteService route template. Here is an example of how a route can be obtained from HAL enabled objects:
* ```
* let params = modelMapper.removeParams(mediaGalleryEntry);
* let uri = params['id'].links('delete').href;
* ```
* @method
* @param id Media gallery id used to delete specific Media gallery resource from the system.
* @example // id is a media gallery resource id previously fetched using get action. The following action will remove the original media gallery resource and all accompanying derived media gallery resources.
mediaGalleryClient.remove(id)
.then(function (data) {
// perform success action here
},
function (response, status, headers, config) {
// perform error handling here
});
**/
MediaGalleryClient.prototype.remove = function (id) {
return this.apiClient.delete(this.routeDefinition.delete(id));
};
/**
* Returns a promise that is resolved once the create media gallery action has been performed; this action creates a new media gallery.
* @method
* @param data Media Gallery object.
* @returns A promise that is resolved once the create media gallery action has been performed.
* @example mediaGalleryClient.create(mediaGallery)
.then(function (data) {
// perform success action here
},
function (response, status, headers, config) {
// perform error handling here
});
**/
MediaGalleryClient.prototype.create = function (data) {
return this.apiClient.post(this.routeDefinition.create(data), this.routeDefinition.createParams(data));
};
/**
* Returns a promise that is resolved once the purge action has been performed. This action will remove all media gallery resources from the system if successfully completed.
* @method
* @example // Remove original media gallery resources
mediaGalleryClient.purge()
.then(function (data) {
// perform success action here
},
function (response, status, headers, config) {
// perform error handling here
});
**/
MediaGalleryClient.prototype.purge = function () {
return this.apiClient.delete(this.routeDefinition.purge());
};
MediaGalleryClient = tslib_1.__decorate([
inversify_1.injectable(),
tslib_1.__param(0, inversify_1.inject(_1.TYPES.MediaGalleryRoute)),
tslib_1.__param(1, inversify_1.inject(httpApi_1.httpTYPES.ApiClient)),
tslib_1.__param(2, inversify_1.inject(_1.TYPES.MediaGalleryBatchClient)),
tslib_1.__param(3, inversify_1.inject(_1.TYPES.MediaGalleryFileStreamClient)),
tslib_1.__param(4, inversify_1.inject(_1.TYPES.MediaGalleryInstanceFilesClient)),
tslib_1.__param(5, inversify_1.inject(_1.TYPES.MediaGallerySettingsClient)),
tslib_1.__metadata("design:paramtypes", [_1.MediaGalleryRoute,
httpApi_1.ApiClient,
_1.MediaGalleryBatchClient,
_1.MediaGalleryFileStreamClient,
_1.MediaGalleryInstanceFilesClient,
_1.MediaGallerySettingsClient])
], MediaGalleryClient);
return MediaGalleryClient;
}());
exports.MediaGalleryClient = MediaGalleryClient;
/**
* @overview
***Notes:**
- Refer to the [REST API documentation](http://dev.baasic.com/api/reference/home) for detailed information about available Baasic REST API end-points.
- All end-point objects are transformed by the associated route service.
*/