Skip to content

Allow API call cancellation with CancellationTokens #35

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Aug 27, 2024
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
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
9 changes: 8 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
## Ignore Visual Studio temporary files, build results, and
## files generated by popular Visual Studio add-ons.
##
## Get latest from https://github.com/github/gitignore/blob/main/VisualStudio.gitignore
## Get latest from `dotnet new gitignore`

# dotenv files
.env

# User-specific files
*.rsuser
Expand Down Expand Up @@ -399,6 +402,7 @@ FodyWeavers.xsd

# JetBrains Rider
*.sln.iml
.idea

##
## Visual studio for Mac
Expand Down Expand Up @@ -475,3 +479,6 @@ $RECYCLE.BIN/

# Windows shortcuts
*.lnk

# Vim temporary swap files
*.swp
1 change: 1 addition & 0 deletions src/Merge.Client.Test/Merge.Client.Test.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
<PackageReference Include="NUnit3TestAdapter" Version="4.4.2"/>
<PackageReference Include="NUnit.Analyzers" Version="3.6.1"/>
<PackageReference Include="coverlet.collector" Version="3.2.0"/>
<PackageReference Include="WireMock.Net" Version="1.5.60" />
<PackageReference Include="FluentAssertions.Json" Version="6.1.0" />
</ItemGroup>

Expand Down
20 changes: 10 additions & 10 deletions src/Merge.Client.sln
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@ Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio Version 17
VisualStudioVersion = 17.0.31903.59
MinimumVisualStudioVersion = 10.0.40219.1
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Merge.Client", "Merge.Client\Merge.Client.csproj", "{5940579A-1D95-4B3E-9CC6-F5D30AB2D95A}"
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Merge.Client", "Merge.Client\Merge.Client.csproj", "{FC3BB5C9-688E-4EF8-82DF-ACA00A7A6052}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Merge.Client.Test", "Merge.Client.Test\Merge.Client.Test.csproj", "{6F36DC9B-1D6D-4BD7-B202-6ED89700FAF1}"
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Merge.Client.Test", "Merge.Client.Test\Merge.Client.Test.csproj", "{F421D601-C723-4774-A58A-7E4A3E74E3FB}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Expand All @@ -16,13 +16,13 @@ Global
HideSolutionNode = FALSE
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{5940579A-1D95-4B3E-9CC6-F5D30AB2D95A}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{5940579A-1D95-4B3E-9CC6-F5D30AB2D95A}.Debug|Any CPU.Build.0 = Debug|Any CPU
{5940579A-1D95-4B3E-9CC6-F5D30AB2D95A}.Release|Any CPU.ActiveCfg = Release|Any CPU
{5940579A-1D95-4B3E-9CC6-F5D30AB2D95A}.Release|Any CPU.Build.0 = Release|Any CPU
{6F36DC9B-1D6D-4BD7-B202-6ED89700FAF1}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{6F36DC9B-1D6D-4BD7-B202-6ED89700FAF1}.Debug|Any CPU.Build.0 = Debug|Any CPU
{6F36DC9B-1D6D-4BD7-B202-6ED89700FAF1}.Release|Any CPU.ActiveCfg = Release|Any CPU
{6F36DC9B-1D6D-4BD7-B202-6ED89700FAF1}.Release|Any CPU.Build.0 = Release|Any CPU
{FC3BB5C9-688E-4EF8-82DF-ACA00A7A6052}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{FC3BB5C9-688E-4EF8-82DF-ACA00A7A6052}.Debug|Any CPU.Build.0 = Debug|Any CPU
{FC3BB5C9-688E-4EF8-82DF-ACA00A7A6052}.Release|Any CPU.ActiveCfg = Release|Any CPU
{FC3BB5C9-688E-4EF8-82DF-ACA00A7A6052}.Release|Any CPU.Build.0 = Release|Any CPU
{F421D601-C723-4774-A58A-7E4A3E74E3FB}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{F421D601-C723-4774-A58A-7E4A3E74E3FB}.Debug|Any CPU.Build.0 = Debug|Any CPU
{F421D601-C723-4774-A58A-7E4A3E74E3FB}.Release|Any CPU.ActiveCfg = Release|Any CPU
{F421D601-C723-4774-A58A-7E4A3E74E3FB}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
EndGlobal
16 changes: 13 additions & 3 deletions src/Merge.Client/Accounting/AccountDetails/AccountDetailsClient.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using System.Net.Http;
using System.Text.Json;
using System.Threading;
using Merge.Client.Core;

#nullable enable
Expand All @@ -18,16 +19,25 @@ internal AccountDetailsClient(RawClient client)
/// <summary>
/// Get details for a linked account.
/// </summary>
public async Task<AccountDetails> RetrieveAsync(RequestOptions? options = null)
/// <example>
/// <code>
/// await client.Accounting.AccountDetails.RetrieveAsync();
/// </code>
/// </example>
public async Task<AccountDetails> RetrieveAsync(
RequestOptions? options = null,
CancellationToken cancellationToken = default
)
{
var response = await _client.MakeRequestAsync(
new RawClient.JsonApiRequest
{
BaseUrl = _client.Options.BaseUrl,
Method = HttpMethod.Get,
Path = "accounting/v1/account-details",
Options = options
}
Options = options,
},
cancellationToken
);
var responseBody = await response.Raw.Content.ReadAsStringAsync();
if (response.StatusCode is >= 200 and < 400)
Expand Down
14 changes: 11 additions & 3 deletions src/Merge.Client/Accounting/AccountToken/AccountTokenClient.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using System.Net.Http;
using System.Text.Json;
using System.Threading;
using Merge.Client.Core;

#nullable enable
Expand All @@ -18,9 +19,15 @@ internal AccountTokenClient(RawClient client)
/// <summary>
/// Returns the account token for the end user with the provided public token.
/// </summary>
/// <example>
/// <code>
/// await client.Accounting.AccountToken.RetrieveAsync("public_token");
/// </code>
/// </example>
public async Task<AccountToken> RetrieveAsync(
string publicToken,
RequestOptions? options = null
RequestOptions? options = null,
CancellationToken cancellationToken = default
)
{
var response = await _client.MakeRequestAsync(
Expand All @@ -29,8 +36,9 @@ public async Task<AccountToken> RetrieveAsync(
BaseUrl = _client.Options.BaseUrl,
Method = HttpMethod.Get,
Path = $"accounting/v1/account-token/{publicToken}",
Options = options
}
Options = options,
},
cancellationToken
);
var responseBody = await response.Raw.Content.ReadAsStringAsync();
if (response.StatusCode is >= 200 and < 400)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using System.Net.Http;
using System.Text.Json;
using System.Threading;
using Merge.Client.Core;

#nullable enable
Expand All @@ -18,12 +19,18 @@ internal AccountingPeriodsClient(RawClient client)
/// <summary>
/// Returns a list of `AccountingPeriod` objects.
/// </summary>
/// <example>
/// <code>
/// await client.Accounting.AccountingPeriods.ListAsync(new AccountingPeriodsListRequest());
/// </code>
/// </example>
public async Task<PaginatedAccountingPeriodList> ListAsync(
AccountingPeriodsListRequest request,
RequestOptions? options = null
RequestOptions? options = null,
CancellationToken cancellationToken = default
)
{
var _query = new Dictionary<string, object>() { };
var _query = new Dictionary<string, object>();
if (request.Cursor != null)
{
_query["cursor"] = request.Cursor;
Expand All @@ -47,8 +54,9 @@ public async Task<PaginatedAccountingPeriodList> ListAsync(
Method = HttpMethod.Get,
Path = "accounting/v1/accounting-periods",
Query = _query,
Options = options
}
Options = options,
},
cancellationToken
);
var responseBody = await response.Raw.Content.ReadAsStringAsync();
if (response.StatusCode is >= 200 and < 400)
Expand All @@ -73,13 +81,22 @@ public async Task<PaginatedAccountingPeriodList> ListAsync(
/// <summary>
/// Returns an `AccountingPeriod` object with the given `id`.
/// </summary>
/// <example>
/// <code>
/// await client.Accounting.AccountingPeriods.RetrieveAsync(
/// "id",
/// new AccountingPeriodsRetrieveRequest()
/// );
/// </code>
/// </example>
public async Task<AccountingPeriod> RetrieveAsync(
string id,
AccountingPeriodsRetrieveRequest request,
RequestOptions? options = null
RequestOptions? options = null,
CancellationToken cancellationToken = default
)
{
var _query = new Dictionary<string, object>() { };
var _query = new Dictionary<string, object>();
if (request.IncludeRemoteData != null)
{
_query["include_remote_data"] = request.IncludeRemoteData.ToString();
Expand All @@ -91,8 +108,9 @@ public async Task<AccountingPeriod> RetrieveAsync(
Method = HttpMethod.Get,
Path = $"accounting/v1/accounting-periods/{id}",
Query = _query,
Options = options
}
Options = options,
},
cancellationToken
);
var responseBody = await response.Raw.Content.ReadAsStringAsync();
if (response.StatusCode is >= 200 and < 400)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
using Merge.Client.Core;

#nullable enable

namespace Merge.Client.Accounting;

public record AccountingPeriodsListRequest
Expand All @@ -21,4 +25,9 @@ public record AccountingPeriodsListRequest
/// Number of results to return per page.
/// </summary>
public int? PageSize { get; set; }

public override string ToString()
{
return JsonUtils.Serialize(this);
}
}
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
using Merge.Client.Core;

#nullable enable

namespace Merge.Client.Accounting;

public record AccountingPeriodsRetrieveRequest
Expand All @@ -6,4 +10,9 @@ public record AccountingPeriodsRetrieveRequest
/// Whether to include the original data Merge fetched from the third-party to produce these models.
/// </summary>
public bool? IncludeRemoteData { get; set; }

public override string ToString()
{
return JsonUtils.Serialize(this);
}
}
Loading
Loading