Skip to content

Commit 7ffdbc8

Browse files
authored
Merge pull request #94 from fllprbt/master
feature: add callback url to job params
2 parents 8c0775a + b454cf1 commit 7ffdbc8

10 files changed

+112
-33
lines changed

Diff for: api/files/index.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ export class SmartlingFilesApi extends SmartlingBaseApi {
5656
): Promise<string> {
5757
return await this.makeRequest(
5858
"get",
59-
`${this.entrypoint}/${projectId}/locales/all/file`,
59+
`${this.entrypoint}/${projectId}/locales/all/file/zip`,
6060
Object.assign(params.export(), { fileUri }),
6161
true
6262
);
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,3 @@
11
import { DownloadFileParameters } from "./download-file-parameters";
22

3-
4-
export class DownloadFileAllTranslationsParameters extends DownloadFileParameters {
5-
setZipFileName(fileName: string): DownloadFileAllTranslationsParameters {
6-
this.set("zipFileName", fileName);
7-
return this;
8-
}
9-
}
3+
export class DownloadFileAllTranslationsParameters extends DownloadFileParameters {}

Diff for: api/job-batches/dto/batch-list-item-dto.ts

+14
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
import { BatchStatus } from "../params/batch-status";
2+
import { BatchDto } from "./batch-dto";
3+
4+
interface BatchListItemDto extends BatchDto {
5+
status: BatchStatus;
6+
authorized: boolean;
7+
translationJobUid: string;
8+
projectId: string;
9+
createdDate: Date
10+
modifiedDate: Date
11+
12+
}
13+
14+
export { BatchListItemDto };

Diff for: api/job-batches/index.ts

+13
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,9 @@ import { BatchStatusDto } from "./dto/batch-status-dto";
88
import { BatchDto } from "./dto/batch-dto";
99
import { CancelBatchFileParameters } from "./params/cancel-batch-file-parameters";
1010
import { RegisterBatchFileParameters } from "./params/register-batch-file-parameters";
11+
import { BatchListItemDto } from "./dto/batch-list-item-dto";
12+
import { SmartlingListResponse } from "../http/smartling-list-response";
13+
import { ListBatchesParameters } from "./params/list-batches-parameters";
1114

1215
export class SmartlingJobBatchesApi extends SmartlingBaseApi {
1316
constructor(smartlingApiBaseUrl: string, authApi: SmartlingAuthApi, logger: Logger) {
@@ -82,4 +85,14 @@ export class SmartlingJobBatchesApi extends SmartlingBaseApi {
8285
`${this.entrypoint}/${projectId}/batches/${batchUid}`
8386
);
8487
}
88+
89+
async listBatches(projectId: string, params: ListBatchesParameters
90+
): Promise<SmartlingListResponse<BatchListItemDto>> {
91+
return await this.makeRequest(
92+
"get",
93+
`${this.entrypoint}/${projectId}/batches`,
94+
params.export()
95+
96+
);
97+
}
8598
}

Diff for: api/job-batches/params/list-batches-parameters.ts

+41
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
import { BaseParameters } from "../../parameters/index";
2+
import { Order } from "../../parameters/order";
3+
import { BatchStatus } from "./batch-status";
4+
5+
export class ListBatchesParameters extends BaseParameters {
6+
setTranslationJobUid(uid: string): ListBatchesParameters {
7+
this.set("translationJobUid", uid);
8+
9+
return this;
10+
}
11+
12+
setLimit(limit: number): ListBatchesParameters {
13+
if (limit > 0) {
14+
this.set("limit", limit);
15+
}
16+
17+
return this;
18+
}
19+
20+
setOffset(offset: number): ListBatchesParameters {
21+
if (offset >= 0) {
22+
this.set("offset", offset);
23+
}
24+
25+
return this;
26+
}
27+
28+
setStatus(status: BatchStatus): ListBatchesParameters {
29+
this.set("status", status);
30+
31+
return this;
32+
}
33+
34+
setSort(field: "createdDate" | "status", order: Order): ListBatchesParameters {
35+
this.set("sortBy", field);
36+
this.set("sortDirection", order.toLowerCase());
37+
38+
return this;
39+
}
40+
}
41+

Diff for: api/jobs/params/create-job-parameters.ts

+6
Original file line numberDiff line numberDiff line change
@@ -37,4 +37,10 @@ export class CreateJobParameters extends BaseParameters {
3737

3838
return this;
3939
}
40+
41+
setCallbackUrl(callbackUrl: string): CreateJobParameters {
42+
this.set("callbackUrl", callbackUrl);
43+
44+
return this;
45+
}
4046
}

Diff for: index.ts

+2
Original file line numberDiff line numberDiff line change
@@ -30,13 +30,15 @@ export * from "./api/job-batches/dto/batch-dto";
3030
export * from "./api/job-batches/dto/batch-item-dto";
3131
export * from "./api/job-batches/dto/batch-locale-dto";
3232
export * from "./api/job-batches/dto/batch-status-dto";
33+
export * from "./api/job-batches/dto/batch-list-item-dto";
3334
export * from "./api/job-batches/params/create-batch-parameters";
3435
export * from "./api/job-batches/params/upload-batch-file-parameters";
3536
export * from "./api/job-batches/params/process-batch-action-parameters";
3637
export * from "./api/job-batches/params/cancel-batch-file-parameters";
3738
export * from "./api/job-batches/params/register-batch-file-parameters";
3839
export * from "./api/job-batches/params/batch-action";
3940
export * from "./api/job-batches/params/batch-status";
41+
export * from "./api/job-batches/params/list-batches-parameters";
4042
export * from "./api/job-batches/params/batch-item-status";
4143
export * from "./api/jobs/index";
4244
export * from "./api/jobs/dto/base-job-dto";

Diff for: test/files.spec.ts

+1-23
Original file line numberDiff line numberDiff line change
@@ -202,29 +202,7 @@ describe("SmartlingFilesApi class tests.", () => {
202202
sinon.assert.calledOnce(filesApiFetchStub);
203203
sinon.assert.calledWithExactly(
204204
filesApiFetchStub,
205-
`https://test.com/files-api/v2/projects/${projectId}/locales/all/file?retrievalType=published&debugMode=1&fileUri=testFileUri`,
206-
{
207-
headers: {
208-
Authorization: "test_token_type test_access_token",
209-
"Content-Type": "application/json",
210-
"User-Agent": "test_user_agent"
211-
},
212-
method: "get"
213-
}
214-
);
215-
});
216-
217-
it("Download file with zip's name set", async () => {
218-
const zipFileName = "translations-2.zip";
219-
params.setZipFileName(zipFileName);
220-
221-
222-
await filesApi.downloadFileAllTranslations(projectId, fileUri, params);
223-
224-
sinon.assert.calledOnce(filesApiFetchStub);
225-
sinon.assert.calledWithExactly(
226-
filesApiFetchStub,
227-
`https://test.com/files-api/v2/projects/${projectId}/locales/all/file?zipFileName=${zipFileName}&fileUri=testFileUri`,
205+
`https://test.com/files-api/v2/projects/${projectId}/locales/all/file/zip?retrievalType=published&debugMode=1&fileUri=testFileUri`,
228206
{
229207
headers: {
230208
Authorization: "test_token_type test_access_token",

Diff for: test/job-batches.spec.ts

+30
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,9 @@ import { FileType } from "../api/files/params/file-type";
1010
import { CancelBatchFileParameters } from "../api/job-batches/params/cancel-batch-file-parameters";
1111
import { RegisterBatchFileParameters } from "../api/job-batches/params/register-batch-file-parameters";
1212
import { streamToString } from "./stream-to-string";
13+
import { ListBatchesParameters } from "../api/job-batches/params/list-batches-parameters";
14+
import { Order } from "../api/parameters/order";
15+
import { BatchStatus } from "../api/job-batches/params/batch-status";
1316

1417
describe("SmartlingJobBatchesAPI class tests.", () => {
1518
const projectId = "testProjectId";
@@ -229,5 +232,32 @@ describe("SmartlingJobBatchesAPI class tests.", () => {
229232
}
230233
);
231234
});
235+
236+
it("List batches", async () => {
237+
const params = new ListBatchesParameters();
238+
const sortByParam = "status";
239+
params
240+
.setTranslationJobUid(jobUid)
241+
.setLimit(100)
242+
.setOffset(10)
243+
.setStatus(BatchStatus.COMPLETED)
244+
.setSort(sortByParam, Order.ASC);
245+
246+
await jobBatchesApi.listBatches(projectId, params);
247+
248+
sinon.assert.calledOnce(jobBatchesApiFetchStub);
249+
sinon.assert.calledWithExactly(
250+
jobBatchesApiFetchStub,
251+
`https://test.com/job-batches-api/v2/projects/${projectId}/batches?translationJobUid=${jobUid}&limit=100&offset=10&status=${BatchStatus.COMPLETED}&sortBy=${sortByParam}&sortDirection=${(Order.ASC).toLowerCase()}`,
252+
{
253+
method: "get",
254+
headers: {
255+
Authorization: "test_token_type test_access_token",
256+
"Content-Type": "application/json",
257+
"User-Agent": "test_user_agent"
258+
}
259+
}
260+
);
261+
});
232262
});
233263
});

Diff for: test/jobs.spec.ts

+3-2
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,8 @@ describe("SmartlingJobsAPI class tests.", () => {
5252
.setName("Test job")
5353
.setDescription("Test job description")
5454
.setDueDate(new Date("2100-12-31T22:00:00.000Z"))
55-
.setTargetLocaleIds(["pt-PT"]);
55+
.setTargetLocaleIds(["pt-PT"])
56+
.setCallbackUrl("testCallbackUrl");
5657

5758

5859
await jobApi.createJob(projectId, params);
@@ -62,7 +63,7 @@ describe("SmartlingJobsAPI class tests.", () => {
6263
jobServiceApiFetchStub,
6364
`https://test.com/jobs-api/v3/projects/${projectId}/jobs`,
6465
{
65-
body: "{\"jobName\":\"Test job\",\"description\":\"Test job description\",\"dueDate\":\"2100-12-31T22:00:00.000Z\",\"targetLocaleIds\":[\"pt-PT\"]}",
66+
body: "{\"jobName\":\"Test job\",\"description\":\"Test job description\",\"dueDate\":\"2100-12-31T22:00:00.000Z\",\"targetLocaleIds\":[\"pt-PT\"],\"callbackUrl\":\"testCallbackUrl\"}",
6667
headers: {
6768
Authorization: "test_token_type test_access_token",
6869
"Content-Type": "application/json",

0 commit comments

Comments
 (0)