Skip to content

Commit

Permalink
v1.11.3 Deploy (Attachment get and Download)
Browse files Browse the repository at this point in the history
  • Loading branch information
rwjdk committed Nov 2, 2024
1 parent 104a477 commit a78e0b1
Show file tree
Hide file tree
Showing 4 changed files with 57 additions and 1 deletion.
7 changes: 7 additions & 0 deletions Changelog.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,13 @@
# Changelog
*Below is the version history of [TrelloDotNet](https://github.com/rwjdk/TrelloDotNet) (An wrapper of the Trello API)*

## 1.11.3 (3rd of November 2024)
#### TrelloClient
- Added [GetAttachmentOnCardAsync](https://github.com/rwjdk/TrelloDotNet/wiki/GetAttachmentOnCardAsync)
- Added [DownloadAttachment](https://github.com/rwjdk/TrelloDotNet/wiki/DownloadAttachment) [Via Ids or URL]

<hr/>

## 1.11.2 (9th of October 2024)
#### TrelloClient
- `GetBoardOptions` now have Filter options (All, Open, Closed or Starred boards)
Expand Down
4 changes: 4 additions & 0 deletions src/TrelloDotNet/Control/ApiRequestController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ internal class ApiRequestController
private readonly string _token;
private readonly TrelloClient _client;

internal HttpClient HttpClient => _httpClient;

internal ApiRequestController(HttpClient httpClient, string apiKey, string token, TrelloClient client)
{
_httpClient = httpClient;
Expand All @@ -29,6 +31,8 @@ internal ApiRequestController(HttpClient httpClient, string apiKey, string token

public string Token => _token;

public string ApiKey => _apiKey;

internal async Task<T> Get<T>(string suffix, CancellationToken cancellationToken, params QueryParameter[] parameters)
{
string json = await Get(suffix, cancellationToken, 0, parameters);
Expand Down
45 changes: 45 additions & 0 deletions src/TrelloDotNet/TrelloClient.Attachments.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
using System;
using System.Collections.Generic;
using System.IO;
using System.Net.Http.Headers;
using System.Threading;
using System.Threading.Tasks;
using TrelloDotNet.Control;
Expand Down Expand Up @@ -31,6 +33,17 @@ public async Task DeleteAttachmentOnCardAsync(string cardId, string attachmentId
await _apiRequestController.Delete(GetUrlBuilder.GetAttachmentOnCard(cardId, attachmentId), cancellationToken, 0);
}

/// <summary>
/// Get an Attachments on a card
/// </summary>
/// <param name="cardId">Id of the Card</param>
/// <param name="attachmentId">Id of Attachment</param>
/// <param name="cancellationToken">Cancellation Token</param>
public async Task<Attachment> GetAttachmentOnCardAsync(string cardId, string attachmentId, CancellationToken cancellationToken = default)
{
return await _apiRequestController.Get<Attachment>(GetUrlBuilder.GetAttachmentOnCard(cardId, attachmentId), cancellationToken);
}

/// <summary>
/// Add an Attachment to a Card
/// </summary>
Expand Down Expand Up @@ -88,5 +101,37 @@ public async Task<Attachment> AddAttachmentToCardAsync(string cardId, Attachment

return await _apiRequestController.PostWithAttachmentFileUpload<Attachment>($"{UrlPaths.Cards}/{cardId}/attachments", attachmentFileUpload, cancellationToken, parameters.ToArray());
}

/// <summary>
/// Download an Attachment
/// </summary>
/// <param name="cardId">Id of the Card</param>
/// <param name="attachmentId">Id of Attachment</param>
/// <param name="cancellationToken">Cancellation Token</param>
/// <returns></returns>
public async Task<Stream> DownloadAttachment(string cardId, string attachmentId, CancellationToken cancellationToken = default)
{
Attachment attachment = await GetAttachmentOnCardAsync(cardId, attachmentId, cancellationToken);
return await DownloadAttachment(attachment.Url, cancellationToken);
}

/// <summary>
/// Download an Attachment
/// </summary>
/// <param name="url">URL of the attachment</param>
/// <param name="cancellationToken">Cancellation Token</param>
/// <returns></returns>
public async Task<Stream> DownloadAttachment(string url, CancellationToken cancellationToken = default)
{
try
{
_apiRequestController.HttpClient.DefaultRequestHeaders.Authorization = AuthenticationHeaderValue.Parse($"OAuth oauth_consumer_key=\"{_apiRequestController.ApiKey}\", oauth_token=\"{_apiRequestController.Token}\"");
return await _apiRequestController.HttpClient.GetStreamAsync(url);
}
finally
{
_apiRequestController.HttpClient.DefaultRequestHeaders.Authorization = null;
}
}
}
}
2 changes: 1 addition & 1 deletion src/TrelloDotNet/TrelloDotNet.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
<PackageProjectUrl>https://github.com/rwjdk/TrelloDotNet/wiki</PackageProjectUrl>
<PackageIcon>trello.png</PackageIcon>
<PackageTags>trello api rest .NET dotNet crud wrapper webhook automation</PackageTags>
<Version>1.11.2</Version>
<Version>1.11.3</Version>
<Company>RWJDK</Company>
<PublishRepositoryUrl>true</PublishRepositoryUrl>
<IncludeSymbols>true</IncludeSymbols>
Expand Down

0 comments on commit a78e0b1

Please sign in to comment.