Skip to content

Commit 4f637ba

Browse files
Merge pull request #85 from crowdin/feature/api-updates
API Updates : Glossaries
2 parents dcc0c16 + 0b149b3 commit 4f637ba

19 files changed

+789
-5
lines changed

src/Crowdin.Api/Glossaries/AddTermRequest.cs

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11

2+
using System;
23
using JetBrains.Annotations;
34
using Newtonsoft.Json;
45

@@ -25,6 +26,25 @@ public class AddTermRequest
2526
[JsonProperty("partOfSpeech")]
2627
public PartOfSpeech? PartOfSpeech { get; set; }
2728

29+
[JsonProperty("status")]
30+
public TermStatus? Status { get; set; }
31+
32+
[JsonProperty("type")]
33+
public TermType? Type { get; set; }
34+
35+
[JsonProperty("gender")]
36+
public TermGender? Gender { get; set; }
37+
38+
[JsonProperty("note")]
39+
public string? Note { get; set; }
40+
41+
[JsonProperty("url")]
42+
public string? Url { get; set; }
43+
44+
[JsonProperty("conceptId")]
45+
public int? ConceptId { get; set; }
46+
47+
[Obsolete]
2848
[JsonProperty("translationOfTermId")]
2949
public int? TranslationOfTermId { get; set; }
3050
}
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+

2+
using System;
3+
using JetBrains.Annotations;
4+
using Newtonsoft.Json;
5+
6+
namespace Crowdin.Api.Glossaries
7+
{
8+
[PublicAPI]
9+
public class Concept
10+
{
11+
[JsonProperty("id")]
12+
public int Id { get; set; }
13+
14+
[JsonProperty("userId")]
15+
public int UserId { get; set; }
16+
17+
[JsonProperty("glossaryId")]
18+
public int GlossaryId { get; set; }
19+
20+
[JsonProperty("subject")]
21+
public string Subject { get; set; }
22+
23+
[JsonProperty("definition")]
24+
public string Definition { get; set; }
25+
26+
[JsonProperty("note")]
27+
public string Note { get; set; }
28+
29+
[JsonProperty("url")]
30+
public string Url { get; set; }
31+
32+
[JsonProperty("figure")]
33+
public string Figure { get; set; }
34+
35+
[JsonProperty("languagesDetails")]
36+
public ConceptLanguageDetails[] LanguagesDetails { get; set; }
37+
38+
[JsonProperty("createdAt")]
39+
public DateTimeOffset CreatedAt { get; set; }
40+
41+
[JsonProperty("updatedAt")]
42+
public DateTimeOffset? UpdatedAt { get; set; }
43+
}
44+
}
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+

2+
using System;
3+
using JetBrains.Annotations;
4+
using Newtonsoft.Json;
5+
6+
namespace Crowdin.Api.Glossaries
7+
{
8+
[PublicAPI]
9+
public class ConceptLanguageDetails
10+
{
11+
[JsonProperty("languageId")]
12+
public string LanguageId { get; set; }
13+
14+
[JsonProperty("userId")]
15+
public int UserId { get; set; }
16+
17+
[JsonProperty("definition")]
18+
public string Definition { get; set; }
19+
20+
[JsonProperty("note")]
21+
public string Note { get; set; }
22+
23+
[JsonProperty("createdAt")]
24+
public DateTimeOffset CreatedAt { get; set; }
25+
26+
[JsonProperty("updatedAt")]
27+
public DateTimeOffset? UpdatedAt { get; set; }
28+
}
29+
}
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+

2+
using JetBrains.Annotations;
3+
using Newtonsoft.Json;
4+
5+
namespace Crowdin.Api.Glossaries
6+
{
7+
[PublicAPI]
8+
public class ConceptLanguageDetailsForm
9+
{
10+
[JsonProperty("languageId")]
11+
public string LanguageId { get; set; }
12+
13+
[JsonProperty("definition")]
14+
public string Definition { get; set; }
15+
16+
[JsonProperty("note")]
17+
public string Note { get; set; }
18+
}
19+
}

src/Crowdin.Api/Glossaries/ExportGlossaryRequest.cs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11

2+
using System.Collections.Generic;
23
using JetBrains.Annotations;
34
using Newtonsoft.Json;
45

@@ -9,5 +10,8 @@ public class ExportGlossaryRequest
910
{
1011
[JsonProperty("format")]
1112
public GlossaryFormat Format { get; set; }
13+
14+
[JsonProperty("exportFields")]
15+
public ICollection<GlossaryExportFieldId> ExportFields { get; set; }
1216
}
1317
}

src/Crowdin.Api/Glossaries/GlossariesApiExecutor.cs

Lines changed: 74 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -190,10 +190,10 @@ public async Task<GlossaryImportStatus> CheckGlossaryImportStatus(int glossaryId
190190
[PublicAPI]
191191
public Task<ResponseList<Term>> ListTerms(
192192
int glossaryId, int? userId = null, string? languageId = null,
193-
int? translationOfTermId = null, int limit = 25, int offset = 0)
193+
int? translationOfTermId = null, int? conceptId = null, int limit = 25, int offset = 0)
194194
{
195195
return ListTerms(glossaryId,
196-
new TermsListParams(limit, offset, userId, languageId, translationOfTermId));
196+
new TermsListParams(limit, offset, userId, languageId, translationOfTermId, conceptId));
197197
}
198198

199199
/// <summary>
@@ -228,12 +228,15 @@ public async Task<Term> AddTerm(int glossaryId, AddTermRequest request)
228228
/// <a href="https://support.crowdin.com/enterprise/api/#operation/api.glossaries.terms.deleteMany">Crowdin Enterprise API</a>
229229
/// </summary>
230230
[PublicAPI]
231-
public async Task ClearGlossary(int glossaryId, string? languageId = null, int? translationOfTermId = null)
231+
public async Task ClearGlossary(
232+
int glossaryId, string? languageId = null,
233+
int? conceptId = null, int? translationOfTermId = null)
232234
{
233235
string url = FormUrl_Terms(glossaryId);
234236

235237
var queryParams = new Dictionary<string, string>();
236238
queryParams.AddParamIfPresent("languageId", languageId);
239+
queryParams.AddParamIfPresent("conceptId", conceptId);
237240
queryParams.AddParamIfPresent("translationOfTermId", translationOfTermId);
238241

239242
HttpStatusCode statusCode = await _apiClient.SendDeleteRequest(url, queryParams);
@@ -279,6 +282,64 @@ public async Task<Term> EditTerm(int glossaryId, int termId, IEnumerable<TermPat
279282
return _jsonParser.ParseResponseObject<Term>(result.JsonObject);
280283
}
281284

285+
#endregion
286+
287+
#region Concepts
288+
289+
/// <summary>
290+
/// List terms. Documentation:
291+
/// <a href="https://developer.crowdin.com/api/v2/#operation/api.glossaries.concepts.getMany">Crowdin API</a>
292+
/// <a href="https://developer.crowdin.com/enterprise/api/v2/#operation/api.glossaries.concepts.getMany">Crowdin Enterprise API</a>
293+
/// </summary>
294+
[PublicAPI]
295+
public async Task<ResponseList<Concept>> ListConcepts(int glossaryId, int limit = 25, int offset = 0)
296+
{
297+
string url = FormUrl_Concepts(glossaryId);
298+
IDictionary<string, string> queryParams = Utils.CreateQueryParamsFromPaging(limit, offset);
299+
300+
CrowdinApiResult result = await _apiClient.SendGetRequest(url, queryParams);
301+
return _jsonParser.ParseResponseList<Concept>(result.JsonObject);
302+
}
303+
304+
/// <summary>
305+
/// List terms. Documentation:
306+
/// <a href="https://developer.crowdin.com/api/v2/#operation/api.glossaries.concepts.get">Crowdin API</a>
307+
/// <a href="https://developer.crowdin.com/enterprise/api/v2/#operation/api.glossaries.concepts.get">Crowdin Enterprise API</a>
308+
/// </summary>
309+
[PublicAPI]
310+
public async Task<Concept> GetConcept(int glossaryId, int conceptId)
311+
{
312+
string url = FormUrl_ConceptId(glossaryId, conceptId);
313+
CrowdinApiResult result = await _apiClient.SendGetRequest(url);
314+
return _jsonParser.ParseResponseObject<Concept>(result.JsonObject);
315+
}
316+
317+
/// <summary>
318+
/// List terms. Documentation:
319+
/// <a href="https://developer.crowdin.com/api/v2/#operation/api.glossaries.concepts.put">Crowdin API</a>
320+
/// <a href="https://developer.crowdin.com/enterprise/api/v2/#operation/api.glossaries.concepts.put">Crowdin Enterprise API</a>
321+
/// </summary>
322+
[PublicAPI]
323+
public async Task<Concept> UpdateConcept(int glossaryId, int conceptId, UpdateConceptRequest request)
324+
{
325+
string url = FormUrl_ConceptId(glossaryId, conceptId);
326+
CrowdinApiResult result = await _apiClient.SendPutRequest(url, request);
327+
return _jsonParser.ParseResponseObject<Concept>(result.JsonObject);
328+
}
329+
330+
/// <summary>
331+
/// List terms. Documentation:
332+
/// <a href="https://developer.crowdin.com/api/v2/#operation/api.glossaries.concepts.delete">Crowdin API</a>
333+
/// <a href="https://developer.crowdin.com/enterprise/api/v2/#operation/api.glossaries.concepts.delete">Crowdin Enterprise API</a>
334+
/// </summary>
335+
[PublicAPI]
336+
public async Task DeleteConcept(int glossaryId, int conceptId)
337+
{
338+
string url = FormUrl_ConceptId(glossaryId, conceptId);
339+
HttpStatusCode statusCode = await _apiClient.SendDeleteRequest(url);
340+
Utils.ThrowIfStatusNot204(statusCode, $"Concept {conceptId} removal failed");
341+
}
342+
282343
#endregion
283344

284345
#region Helper methods
@@ -298,6 +359,16 @@ private static string FormUrl_TermId(int glossaryId, int termId)
298359
return $"{BaseUrl}/{glossaryId}/terms/{termId}";
299360
}
300361

362+
private static string FormUrl_Concepts(int glossaryId)
363+
{
364+
return $"{BaseUrl}/{glossaryId}/concepts";
365+
}
366+
367+
private static string FormUrl_ConceptId(int glossaryId, int conceptId)
368+
{
369+
return $"{BaseUrl}/{glossaryId}/concepts/{conceptId}";
370+
}
371+
301372
#endregion
302373
}
303374
}
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+

2+
using System.ComponentModel;
3+
using JetBrains.Annotations;
4+
5+
namespace Crowdin.Api.Glossaries
6+
{
7+
[PublicAPI]
8+
public enum GlossaryExportFieldId
9+
{
10+
[Description("term")]
11+
Term,
12+
13+
[Description("description")]
14+
Description,
15+
16+
[Description("partOfSpeech")]
17+
PartOfSpeech,
18+
19+
[Description("type")]
20+
Type,
21+
22+
[Description("status")]
23+
Status,
24+
25+
[Description("gender")]
26+
Gender,
27+
28+
[Description("note")]
29+
Note,
30+
31+
[Description("url")]
32+
Url
33+
}
34+
}

src/Crowdin.Api/Glossaries/GlossaryFormat.cs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,9 @@ public enum GlossaryFormat
1010
[Description("tbx")]
1111
Tbx,
1212

13+
[Description("tbx_v3")]
14+
TbxV3,
15+
1316
[Description("csv")]
1417
Csv,
1518

src/Crowdin.Api/Glossaries/Term.cs

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,24 @@ public class Term
2929
[JsonProperty("partOfSpeech")]
3030
public PartOfSpeech PartOfSpeech { get; set; }
3131

32+
[JsonProperty("status")]
33+
public TermStatus Status { get; set; }
34+
35+
[JsonProperty("type")]
36+
public TermType Type { get; set; }
37+
38+
[JsonProperty("gender")]
39+
public TermGender Gender { get; set; }
40+
41+
[JsonProperty("note")]
42+
public string Note { get; set; }
43+
44+
[JsonProperty("url")]
45+
public string Url { get; set; }
46+
47+
[JsonProperty("conceptId")]
48+
public int? ConceptId { get; set; }
49+
3250
[JsonProperty("lemma")]
3351
public string Lemma { get; set; }
3452

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+

2+
using System.ComponentModel;
3+
using JetBrains.Annotations;
4+
5+
namespace Crowdin.Api.Glossaries
6+
{
7+
[PublicAPI]
8+
public enum TermGender
9+
{
10+
[Description("masculine")]
11+
Masculine,
12+
13+
[Description("feminine")]
14+
Feminine,
15+
16+
[Description("neuter")]
17+
Neuter,
18+
19+
[Description("other")]
20+
Other
21+
}
22+
}

0 commit comments

Comments
 (0)