import { WebApiClient, PathSegment } from './web-api-client' /** * @export * @abstract * @class Resource * @implements {PathSegment} */ export abstract class Resource implements PathSegment { protected _client: WebApiClient; protected _path: string; /** * Creates an instance of Resource. * @param {string} basePath * @param {WebApiClient} client * * @memberOf Resource */ constructor(basePath: string, client: WebApiClient) { this._client = client; this._path = basePath; } /** * Returns the associated WebApiClient * @returns {WebApiClient} * * @memberOf Resource */ getClient(): WebApiClient { return this._client; } /** * Returns current URL path * @returns {string} * * @memberOf Resource */ getPath(): string { return this._path; } /** * @protected * @param {string} appendix * @returns {string} * * @memberOf Resource */ protected pathAppendedWith(appendix: string): string { if (appendix == null) { return this._path } return this._path + "/" + appendix; } /** * @protected * @param {any=} params * @returns {Promise} * * @memberOf Resource */ protected _get(params?: any): Promise { return this._client.callApi(this.getPath(), "GET", params); } /** * @protected * @param {string} pathSuffix * @param {any=} params * @returns {Promise} * * @memberOf Resource */ protected _getWithSuffix(pathSuffix: string, params?: any): Promise { return this._client.callApi(this.getPath() + "/" + pathSuffix, "GET", params); } }