apify-client
Version:
Apify API client for JavaScript
86 lines • 2.73 kB
JavaScript
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.ApiClient = void 0;
/** @private */
class ApiClient {
constructor(options) {
Object.defineProperty(this, "id", {
enumerable: true,
configurable: true,
writable: true,
value: void 0
});
Object.defineProperty(this, "safeId", {
enumerable: true,
configurable: true,
writable: true,
value: void 0
});
Object.defineProperty(this, "baseUrl", {
enumerable: true,
configurable: true,
writable: true,
value: void 0
});
Object.defineProperty(this, "resourcePath", {
enumerable: true,
configurable: true,
writable: true,
value: void 0
});
Object.defineProperty(this, "url", {
enumerable: true,
configurable: true,
writable: true,
value: void 0
});
Object.defineProperty(this, "apifyClient", {
enumerable: true,
configurable: true,
writable: true,
value: void 0
});
Object.defineProperty(this, "httpClient", {
enumerable: true,
configurable: true,
writable: true,
value: void 0
});
Object.defineProperty(this, "params", {
enumerable: true,
configurable: true,
writable: true,
value: void 0
});
const { baseUrl, apifyClient, httpClient, resourcePath, id, params = {} } = options;
this.id = id;
this.safeId = id && this._toSafeId(id);
this.baseUrl = baseUrl;
this.resourcePath = resourcePath;
this.url = id ? `${baseUrl}/${resourcePath}/${this.safeId}` : `${baseUrl}/${resourcePath}`;
this.apifyClient = apifyClient;
this.httpClient = httpClient;
this.params = params;
}
_subResourceOptions(moreOptions) {
const baseOptions = {
baseUrl: this._url(),
apifyClient: this.apifyClient,
httpClient: this.httpClient,
params: this._params(),
};
return { ...baseOptions, ...moreOptions };
}
_url(path) {
return path ? `${this.url}/${path}` : this.url;
}
_params(endpointParams) {
return { ...this.params, ...endpointParams };
}
_toSafeId(id) {
// The id has the format `username/actor-name`, so we only need to replace the first `/`.
return id.replace('/', '~');
}
}
exports.ApiClient = ApiClient;
//# sourceMappingURL=api_client.js.map