Skip to content

Commit

Permalink
api updates (#75)
Browse files Browse the repository at this point in the history
* api updates

* version increment
  • Loading branch information
yevheniyJ authored Aug 3, 2020
1 parent c3b5a7c commit 48a1296
Show file tree
Hide file tree
Showing 16 changed files with 139 additions and 26 deletions.
2 changes: 1 addition & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@crowdin/crowdin-api-client",
"version": "1.8.12",
"version": "1.8.13",
"description": "JavaScript library for Crowdin API v2.",
"main": "out/index.js",
"types": "out/index.d.ts",
Expand Down
5 changes: 0 additions & 5 deletions src/glossaries/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -207,17 +207,12 @@ export namespace GlossariesModel {

export interface GlossaryExportStatusAttribute {
format: string;
organizationId: number;
glossaryId: number;
}

export interface GlossaryImportStatusAttribute {
storageId: number;
scheme: any;
firstLineContainsHeader: boolean;
organizationId: number;
userId: number;
glossaryId: number;
}

export interface GlossaryFile {
Expand Down
19 changes: 19 additions & 0 deletions src/issues/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,9 +52,28 @@ export namespace IssuesModel {
text: string;
userId: number;
stringId: number;
user: User;
string: string;
languageId: string;
type: Type;
status: Status;
createdAt: string;
}

export interface User {
id: number;
username: string;
fullName: string;
avatarUrl: string;
}

export interface String {
id: number;
text: string;
type: string;
hasPlurals: boolean;
isIcu: boolean;
context: string;
fileId: number;
}
}
4 changes: 1 addition & 3 deletions src/reports/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { CrowdinApi, ResponseObject, DownloadLink, Status } from '../core';
import { CrowdinApi, DownloadLink, ResponseObject, Status } from '../core';

export class Reports extends CrowdinApi {
/**
Expand Down Expand Up @@ -42,8 +42,6 @@ export namespace ReportsModel {
}

export interface ReportStatusAttributes {
organizationId: number;
projectId: number;
format: Format;
reportName: string;
schema: any;
Expand Down
1 change: 1 addition & 0 deletions src/sourceFiles/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -384,6 +384,7 @@ export namespace SourceFilesModel {
revisionId: number;
status: string;
priority: Priority;
path: string;
importOptions: SpreadsheetImportOptions | XmlImportOptions | OtherImportOptions;
exportOptions: GeneralExportOptions | PropertyExportOptions;
createdAt: string;
Expand Down
5 changes: 4 additions & 1 deletion src/stringTranslations/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ export class StringTranslations extends CrowdinApi {
* @param translationId translation identifier
* @param limit maximum number of items to retrieve (default 25)
* @param offset starting offset in the collection (default 0)
* @param fileId file identifier
*/
listTranslationApprovals(
projectId: number,
Expand All @@ -16,11 +17,13 @@ export class StringTranslations extends CrowdinApi {
translationId?: number,
limit?: number,
offset?: number,
fileId?: number,
): Promise<ResponseList<StringTranslationsModel.Approval>> {
let url = `${this.url}/projects/${projectId}/approvals`;
url = this.addQueryParam(url, 'stringId', stringId);
url = this.addQueryParam(url, 'languageId', languageId);
url = this.addQueryParam(url, 'translationId', translationId);
url = this.addQueryParam(url, 'fileId', fileId);
return this.getList(url, limit, offset);
}

Expand Down Expand Up @@ -154,7 +157,7 @@ export class StringTranslations extends CrowdinApi {
translationId: number,
): Promise<ResponseObject<StringTranslationsModel.StringTranslation>> {
const url = `${this.url}/projects/${projectId}/translations/${translationId}/restore`;
return this.post(url, undefined, this.defaultConfig());
return this.put(url, undefined, this.defaultConfig());
}

/**
Expand Down
9 changes: 7 additions & 2 deletions src/tasks/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { BooleanInt, CrowdinApi, PatchRequest, ResponseList, ResponseObject } from '../core';
import { BooleanInt, CrowdinApi, DownloadLink, PatchRequest, ResponseList, ResponseObject } from '../core';

export class Tasks extends CrowdinApi {
/**
Expand Down Expand Up @@ -27,6 +27,11 @@ export class Tasks extends CrowdinApi {
return this.post(url, request, this.defaultConfig());
}

exportTaskStrings(projectId: number, taskId: number): Promise<ResponseObject<DownloadLink>> {
const url = `${this.url}/projects/${projectId}/tasks/${taskId}/exports`;
return this.post(url, undefined, this.defaultConfig());
}

/**
* @param projectId project identifier
* @param taskId task identifier
Expand Down Expand Up @@ -120,7 +125,7 @@ export namespace TasksModel {
}

export interface CreateTaskRequest {
workflowStepId: number;
workflowStepId?: number;
status?: Status;
title: string;
description?: string;
Expand Down
12 changes: 8 additions & 4 deletions src/translationMemory/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,14 @@ export class TranslationMemory extends CrowdinApi {
return this.patch(url, request, this.defaultConfig());
}

/**
* @param tmId tm identifier
*/
clearTm(tmId: number): Promise<void> {
const url = `${this.url}/tms/${tmId}/segments`;
return this.delete(url, this.defaultConfig());
}

/**
* @param tmId tm identifier
* @param exportId export identifier
Expand Down Expand Up @@ -143,17 +151,13 @@ export namespace TranslationMemoryModel {
sourceLanguageId: string;
targetLanguageId: string;
format: string;
tmId: number;
userId: number;
}

export interface ImportTranslationMemoryAttribute {
tmId: number;
storageId: number;
firstLineContainsHeader: number;
scheme: Scheme;
organizationId: number;
userId: number;
}

export enum Format {
Expand Down
2 changes: 1 addition & 1 deletion src/translationStatus/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ export class TranslationStatus extends CrowdinApi {
validation?: TranslationStatusModel.Validation,
languageIds?: string,
): Promise<ResponseList<TranslationStatusModel.QaCheck>> {
let url = `${this.url}/projects/${projectId}/qa-check`;
let url = `${this.url}/projects/${projectId}/qa-checks`;
url = this.addQueryParam(url, 'category', category);
url = this.addQueryParam(url, 'validation', validation);
url = this.addQueryParam(url, 'languageIds', languageIds);
Expand Down
35 changes: 31 additions & 4 deletions src/translations/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -104,10 +104,22 @@ export class Translations extends CrowdinApi {
projectId: number,
languageId: string,
request: TranslationsModel.UploadTranslationRequest,
): Promise<void> {
): Promise<ResponseObject<TranslationsModel.UploadTranslationResponse>> {
const url = `${this.url}/projects/${projectId}/translations/${languageId}`;
return this.post(url, request, this.defaultConfig());
}

/**
* @param projectId project identifier
* @param request request body
*/
exportProjectTranslation(
projectId: number,
request: TranslationsModel.ExportProjectTranslationRequest,
): Promise<ResponseObject<DownloadLink>> {
const url = `${this.url}/projects/${projectId}/translations/exports`;
return this.post(url, request, this.defaultConfig());
}
}

export namespace TranslationsModel {
Expand Down Expand Up @@ -140,9 +152,6 @@ export namespace TranslationsModel {
duplicateTranslations: boolean;
translateUntranslatedOnly: boolean;
translateWithPerfectMatchOnly: boolean;
organizationId: number;
projectId: number;
userId: number;
}

export enum Method {
Expand Down Expand Up @@ -204,4 +213,22 @@ export namespace TranslationsModel {
autoApproveImported?: boolean;
markAddedTranslationsAsDone?: boolean;
}

export interface UploadTranslationResponse {
projectId: number;
storageId: number;
languageId: string;
fileId: number;
}

export interface ExportProjectTranslationRequest {
targetLanguageId: string;
format?: string;
branchIds?: number[];
directoryIds?: number[];
fileIds?: number[];
skipUntranslatedStrings?: boolean;
skipUntranslatedFiles?: boolean;
exportWithMinApprovalsCount?: number;
}
}
2 changes: 1 addition & 1 deletion tests/stringTranslations/api.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,7 @@ describe('String Translations API', () => {
},
})
.reply(200)
.post(`/projects/${projectId}/translations/${translationId}/restore`, undefined, {
.put(`/projects/${projectId}/translations/${translationId}/restore`, undefined, {
reqheaders: {
Authorization: `Bearer ${api.token}`,
},
Expand Down
17 changes: 17 additions & 0 deletions tests/tasks/api.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ describe('Tasks API', () => {
const workflowStepId = 40;
const type = TasksModel.Type.TRANSLATE;

const link = 'test.com';

const limit = 25;

beforeAll(() => {
Expand Down Expand Up @@ -57,6 +59,16 @@ describe('Tasks API', () => {
id: taskId,
},
})
.post(`/projects/${projectId}/tasks/${taskId}/exports`, undefined, {
reqheaders: {
Authorization: `Bearer ${api.token}`,
},
})
.reply(200, {
data: {
url: link,
},
})
.get(`/projects/${projectId}/tasks/${taskId}`, undefined, {
reqheaders: {
Authorization: `Bearer ${api.token}`,
Expand Down Expand Up @@ -157,6 +169,11 @@ describe('Tasks API', () => {
expect(task.data.id).toBe(taskId);
});

it('Export task strings', async () => {
const res = await api.exportTaskStrings(projectId, taskId);
expect(res.data.url).toBe(link);
});

it('Get task', async () => {
const task = await api.getTask(projectId, taskId);
expect(task.data.id).toBe(taskId);
Expand Down
10 changes: 10 additions & 0 deletions tests/translationMemory/api.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,12 @@ describe('Translation Memory API', () => {
name: name,
},
})
.delete(`/tms/${tmId}/segments`, undefined, {
reqheaders: {
Authorization: `Bearer ${api.token}`,
},
})
.reply(200)
.get(`/tms/${tmId}/exports/${exportId}/download`, undefined, {
reqheaders: {
Authorization: `Bearer ${api.token}`,
Expand Down Expand Up @@ -197,6 +203,10 @@ describe('Translation Memory API', () => {
expect(tm.data.name).toBe(name);
});

it('Clear TM', async () => {
await api.clearTm(tmId);
});

it('Download TM', async () => {
const link = await api.downloadTm(tmId, exportId);
expect(link.data.url).toBe(url);
Expand Down
2 changes: 1 addition & 1 deletion tests/translationStatus/api.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ describe('Translation Status API', () => {
limit: limit,
},
})
.get(`/projects/${projectId}/qa-check`, undefined, {
.get(`/projects/${projectId}/qa-checks`, undefined, {
reqheaders: {
Authorization: `Bearer ${api.token}`,
},
Expand Down
38 changes: 36 additions & 2 deletions tests/translations/api.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,30 @@ describe('Translations API', () => {
},
},
)
.reply(200);
.reply(200, {
data: {
fileId,
storageId,
languageId,
projectId,
},
})
.post(
`/projects/${projectId}/translations/exports`,
{
targetLanguageId: languageId,
},
{
reqheaders: {
Authorization: `Bearer ${api.token}`,
},
},
)
.reply(200, {
data: {
url: url,
},
});
});

afterAll(() => {
Expand Down Expand Up @@ -188,9 +211,20 @@ describe('Translations API', () => {
});

it('Upload Translation', async () => {
await api.uploadTranslation(projectId, languageId, {
const res = await api.uploadTranslation(projectId, languageId, {
storageId: storageId,
fileId: fileId,
});
expect(res.data.fileId).toBe(fileId);
expect(res.data.languageId).toBe(languageId);
expect(res.data.projectId).toBe(projectId);
expect(res.data.storageId).toBe(storageId);
});

it('Export Project Translation', async () => {
const res = await api.exportProjectTranslation(projectId, {
targetLanguageId: languageId,
});
expect(res.data.url).toBe(url);
});
});

0 comments on commit 48a1296

Please sign in to comment.