Skip to content

Commit

Permalink
feat: add runs() and builds() top level endpoints (#468)
Browse files Browse the repository at this point in the history
Closes #296
  • Loading branch information
foxt451 authored Feb 16, 2024
1 parent 0408407 commit 252d2ac
Show file tree
Hide file tree
Showing 7 changed files with 232 additions and 209 deletions.
33 changes: 17 additions & 16 deletions src/apify_client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import { RequestInterceptorFunction } from './interceptors';
import { ActorClient } from './resource_clients/actor';
import { ActorCollectionClient } from './resource_clients/actor_collection';
import { BuildClient } from './resource_clients/build';
// import { BuildCollectionClient } from './resource_clients/build_collection';
import { BuildCollectionClient } from './resource_clients/build_collection';
import { DatasetClient } from './resource_clients/dataset';
import { DatasetCollectionClient } from './resource_clients/dataset_collection';
import { KeyValueStoreClient } from './resource_clients/key_value_store';
Expand All @@ -17,7 +17,7 @@ import { LogClient } from './resource_clients/log';
import { RequestQueueClient, RequestQueueUserOptions } from './resource_clients/request_queue';
import { RequestQueueCollectionClient } from './resource_clients/request_queue_collection';
import { RunClient } from './resource_clients/run';
// import { RunCollectionClient } from './resource_clients/run_collection';
import { RunCollectionClient } from './resource_clients/run_collection';
import { ScheduleClient } from './resource_clients/schedule';
import { ScheduleCollectionClient } from './resource_clients/schedule_collection';
import { StoreCollectionClient } from './resource_clients/store_collection';
Expand Down Expand Up @@ -107,13 +107,12 @@ export class ApifyClient {
});
}

// TODO we don't have this endpoint yet
// /**
// * @return {BuildCollectionClient}
// */
// builds() {
// return new BuildCollectionClient(this._options());
// }
/**
* https://docs.apify.com/api/v2#/reference/actor-builds/build-collection
*/
builds(): BuildCollectionClient {
return new BuildCollectionClient(this._options());
}

/**
* https://docs.apify.com/api/v2#/reference/actor-builds/build-object
Expand Down Expand Up @@ -203,13 +202,15 @@ export class ApifyClient {
return new RequestQueueClient(apiClientOptions, options);
}

// TODO we don't have this endpoint yet
// /**
// * @return {RunCollectionClient}
// */
// runs() {
// return new RunCollectionClient(this._options());
// }
/**
* https://docs.apify.com/api/v2#/reference/actor-runs/run-collection
*/
runs(): RunCollectionClient {
return new RunCollectionClient({
...this._options(),
resourcePath: 'actor-runs',
});
}

/**
* https://docs.apify.com/api/v2#/reference/actor-runs/run-object-and-its-storages
Expand Down
4 changes: 2 additions & 2 deletions src/resource_clients/build_collection.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
import ow from 'ow';

import { Build } from './build';
import { ApiClientOptions } from '../base/api_client';
import { ApiClientOptionsWithOptionalResourcePath } from '../base/api_client';
import { ResourceCollectionClient } from '../base/resource_collection_client';
import { PaginatedList } from '../utils';

export class BuildCollectionClient extends ResourceCollectionClient {
/**
* @hidden
*/
constructor(options: ApiClientOptions) {
constructor(options: ApiClientOptionsWithOptionalResourcePath) {
super({
...options,
resourcePath: options.resourcePath || 'actor-builds',
Expand Down
4 changes: 2 additions & 2 deletions src/resource_clients/run_collection.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,15 @@ import { ACT_JOB_STATUSES } from '@apify/consts';
import ow from 'ow';

import { ActorRunListItem } from './actor';
import { ApiClientSubResourceOptions } from '../base/api_client';
import { ApiClientOptionsWithOptionalResourcePath } from '../base/api_client';
import { ResourceCollectionClient } from '../base/resource_collection_client';
import { PaginatedList } from '../utils';

export class RunCollectionClient extends ResourceCollectionClient {
/**
* @hidden
*/
constructor(options: ApiClientSubResourceOptions) {
constructor(options: ApiClientOptionsWithOptionalResourcePath) {
super({
resourcePath: 'runs',
...options,
Expand Down
2 changes: 1 addition & 1 deletion test/builds.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ describe('Build methods', () => {
});

describe('builds()', () => {
test.skip('list() works', async () => {
test('list() works', async () => {
const query = {
limit: 5,
offset: 3,
Expand Down
1 change: 1 addition & 0 deletions test/mock_server/routes/builds.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ const { addRoutes } = require('./add_routes');
const builds = express.Router();

const ROUTES = [
{ id: 'list-builds', method: 'GET', path: '/' },
{ id: 'get-build', method: 'GET', path: '/:buildId', type: 'responseJsonMock' },
{ id: 'abort-build', method: 'POST', path: '/:buildId/abort' },
{ id: 'build-log', method: 'GET', path: '/:buildId/log', type: 'text' },
Expand Down
1 change: 1 addition & 0 deletions test/mock_server/routes/runs.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ const { addRoutes } = require('./add_routes');
const runs = express.Router();

const ROUTES = [
{ id: 'list-runs', method: 'GET', path: '/' },
{ id: 'get-run', method: 'GET', path: '/:runId', type: 'responseJsonMock' },
{ id: 'abort-run', method: 'POST', path: '/:runId/abort' },
{ id: 'metamorph-run', method: 'POST', path: '/:runId/metamorph' },
Expand Down
Loading

0 comments on commit 252d2ac

Please sign in to comment.