Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions src/Crowdin.Api/SourceFiles/AddAssetReferenceRequest.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
using JetBrains.Annotations;
using Newtonsoft.Json;

namespace Crowdin.Api.SourceFiles
{
[PublicAPI]
public class AddAssetReferenceRequest
{
[JsonProperty("storageId")]
public long StorageId { get; set; }

[JsonProperty("name")]
public string Name { get; set; }
}
}
29 changes: 29 additions & 0 deletions src/Crowdin.Api/SourceFiles/AssetReference.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
using Crowdin.Api.Users;
using JetBrains.Annotations;
using Newtonsoft.Json;
using System;

namespace Crowdin.Api.SourceFiles
{
[PublicAPI]
public class AssetReference
{
[JsonProperty("id")]
public int Id { get; set; }

[JsonProperty("name")]
public string Name { get; set; }

[JsonProperty("url")]
public string Url { get; set; }

[JsonProperty("user")]
public User User { get; set; }

[JsonProperty("createdAt")]
public DateTimeOffset CreatedAt { get; set; }

[JsonProperty("mimeType")]
public string MimeType { get; set; }
}
}
16 changes: 16 additions & 0 deletions src/Crowdin.Api/SourceFiles/ISourceFilesApiExecutor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -110,5 +110,21 @@ Task<ResponseList<ReviewedStringBuild>> ListReviewedSourceFilesBuilds(
Task<DownloadLink> DownloadReviewedSourceFiles(long projectId, long buildId);

#endregion

#region Asset References

Task<ResponseList<AssetReference>> ListAssetReferences(
long projectId,
long fileId,
int limit = 25,
int offset = 0);

Task<AssetReference> AddAssetReference(long projectId, long fileId, AddAssetReferenceRequest request);

Task<AssetReference> GetAssetReference(long projectId, long fileId, long referenceId);

Task DeleteAssetReference(long projectId, long fileId, long referenceId);

#endregion
}
}
73 changes: 72 additions & 1 deletion src/Crowdin.Api/SourceFiles/SourceFilesApiExecutor.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@


using System;
using System.Collections.Generic;
using System.Linq;
Expand Down Expand Up @@ -467,5 +467,76 @@ public async Task<DownloadLink> DownloadReviewedSourceFiles(long projectId, long
}

#endregion

#region File References

/// <summary>
/// List asset references. Documentation:
/// <a href="https://support.crowdin.com/api/v2/#operation/api.projects.files.references.getMany">Crowdin API</a>
/// <a href="https://support.crowdin.com/enterprise/api/#operation/api.projects.files.references.getMany">Crowdin Enterprise API</a>
/// </summary>
[PublicAPI]
public async Task<ResponseList<AssetReference>> ListAssetReferences(long projectId, long fileId, int limit = 25, int offset = 0)
{
string url = FormUrl_FileReferences(projectId, fileId);
IDictionary<string, string> queryParams = Utils.CreateQueryParamsFromPaging(limit, offset);
CrowdinApiResult result = await _apiClient.SendGetRequest(url, queryParams);
return _jsonParser.ParseResponseList<AssetReference>(result.JsonObject);
}

/// <summary>
/// Add asset reference. Documentation:
/// <a href="https://support.crowdin.com/api/v2/#operation/api.projects.files.references.post">Crowdin API</a>
/// <a href="https://support.crowdin.com/enterprise/api/#operation/api.projects.files.references.post">Crowdin Enterprise API</a>
/// </summary>
Copy link

Copilot AI Oct 28, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Missing [PublicAPI] attribute for consistency with other public methods in this class like ListAssetReferences.

Suggested change
/// </summary>
/// </summary>
[PublicAPI]

Copilot uses AI. Check for mistakes.
[PublicAPI]
public async Task<AssetReference> AddAssetReference(long projectId, long fileId, AddAssetReferenceRequest request)
{
string url = FormUrl_FileReferences(projectId, fileId);
CrowdinApiResult result = await _apiClient.SendPostRequest(url, request);
return _jsonParser.ParseResponseObject<AssetReference>(result.JsonObject);
}

/// <summary>
/// Get asset reference. Documentation:
/// <a href="https://support.crowdin.com/api/v2/#operation/api.projects.files.references.get">Crowdin API</a>
/// <a href="https://support.crowdin.com/enterprise/api/#operation/api.projects.files.references.get">Crowdin Enterprise API</a>
/// </summary>
Copy link

Copilot AI Oct 28, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Missing [PublicAPI] attribute for consistency with other public methods in this class like ListAssetReferences.

Suggested change
/// </summary>
/// </summary>
[PublicAPI]

Copilot uses AI. Check for mistakes.
[PublicAPI]
public async Task<AssetReference> GetAssetReference(long projectId, long fileId, long referenceId)
{
string url = FormUrl_FileReferences_ReferenceId(projectId, fileId, referenceId);
CrowdinApiResult result = await _apiClient.SendGetRequest(url);
return _jsonParser.ParseResponseObject<AssetReference>(result.JsonObject);
}

/// <summary>
/// Delete asset reference. Documentation:
/// <a href="https://support.crowdin.com/api/v2/#operation/api.projects.files.references.delete">Crowdin API</a>
/// <a href="https://support.crowdin.com/enterprise/api/#operation/api.projects.files.references.delete">Crowdin Enterprise API</a>
/// </summary>
Copy link

Copilot AI Oct 28, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Missing [PublicAPI] attribute for consistency with other public methods in this class like ListAssetReferences.

Suggested change
/// </summary>
/// </summary>
[PublicAPI]

Copilot uses AI. Check for mistakes.
[PublicAPI]
public async Task DeleteAssetReference(long projectId, long fileId, long referenceId)
{
string url = FormUrl_FileReferences_ReferenceId(projectId, fileId, referenceId);
HttpStatusCode statusCode = await _apiClient.SendDeleteRequest(url);
Utils.ThrowIfStatusNot204(statusCode, $"File reference {referenceId} removal failed");
}

#region Helper methods

private static string FormUrl_FileReferences(long projectId, long fileId)
{
return $"/projects/{projectId}/files/{fileId}/references";
}

private static string FormUrl_FileReferences_ReferenceId(long projectId, long fileId, long referenceId)
{
return $"/projects/{projectId}/files/{fileId}/references/{referenceId}";
}

#endregion

#endregion
}
}
Loading
Loading