diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index b38a83b3..390fd873 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -24,6 +24,28 @@ jobs: - name: Build Release run: dotnet build src -c Release /p:ContinuousIntegrationBuild=true + unit-tests: + runs-on: ubuntu-latest + + steps: + - name: Checkout repo + uses: actions/checkout@v3 + + - uses: actions/checkout@master + + - name: Setup .NET + uses: actions/setup-dotnet@v1 + with: + dotnet-version: 8.x + + - name: Install tools + run: | + dotnet tool restore + + - name: Run Tests + run: | + dotnet test src + publish: needs: [compile] diff --git a/src/Merge.Client.Test/Merge.Client.Test.csproj b/src/Merge.Client.Test/Merge.Client.Test.csproj index 7115984e..72d7067e 100644 --- a/src/Merge.Client.Test/Merge.Client.Test.csproj +++ b/src/Merge.Client.Test/Merge.Client.Test.csproj @@ -1,7 +1,7 @@ - net7.0 + net8.0 enable enable diff --git a/src/Merge.Client.Test/TestClient.cs b/src/Merge.Client.Test/TestClient.cs index db3abedc..80f1e36c 100644 --- a/src/Merge.Client.Test/TestClient.cs +++ b/src/Merge.Client.Test/TestClient.cs @@ -1,3 +1,8 @@ +using NUnit.Framework; + +#nullable enable + namespace Merge.Client.Test; +[TestFixture] public class TestClient { } diff --git a/src/Merge.Client.sln b/src/Merge.Client.sln index de410bf2..5055de51 100644 --- a/src/Merge.Client.sln +++ b/src/Merge.Client.sln @@ -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", "{8D54A66D-E9D5-417E-9BE5-8FEF3F7F660F}" +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Merge.Client", "Merge.Client\Merge.Client.csproj", "{A3AE9724-FD51-4511-A208-1362EEC3D897}" EndProject -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Merge.Client.Test", "Merge.Client.Test\Merge.Client.Test.csproj", "{ECDC139A-E6BD-4FDD-9966-4F7EE068A1A8}" +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Merge.Client.Test", "Merge.Client.Test\Merge.Client.Test.csproj", "{2EEEB8C2-2D58-4A75-81DB-241CB40746BF}" EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution @@ -16,13 +16,13 @@ Global HideSolutionNode = FALSE EndGlobalSection GlobalSection(ProjectConfigurationPlatforms) = postSolution - {8D54A66D-E9D5-417E-9BE5-8FEF3F7F660F}.Debug|Any CPU.ActiveCfg = Debug|Any CPU - {8D54A66D-E9D5-417E-9BE5-8FEF3F7F660F}.Debug|Any CPU.Build.0 = Debug|Any CPU - {8D54A66D-E9D5-417E-9BE5-8FEF3F7F660F}.Release|Any CPU.ActiveCfg = Release|Any CPU - {8D54A66D-E9D5-417E-9BE5-8FEF3F7F660F}.Release|Any CPU.Build.0 = Release|Any CPU - {ECDC139A-E6BD-4FDD-9966-4F7EE068A1A8}.Debug|Any CPU.ActiveCfg = Debug|Any CPU - {ECDC139A-E6BD-4FDD-9966-4F7EE068A1A8}.Debug|Any CPU.Build.0 = Debug|Any CPU - {ECDC139A-E6BD-4FDD-9966-4F7EE068A1A8}.Release|Any CPU.ActiveCfg = Release|Any CPU - {ECDC139A-E6BD-4FDD-9966-4F7EE068A1A8}.Release|Any CPU.Build.0 = Release|Any CPU + {A3AE9724-FD51-4511-A208-1362EEC3D897}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {A3AE9724-FD51-4511-A208-1362EEC3D897}.Debug|Any CPU.Build.0 = Debug|Any CPU + {A3AE9724-FD51-4511-A208-1362EEC3D897}.Release|Any CPU.ActiveCfg = Release|Any CPU + {A3AE9724-FD51-4511-A208-1362EEC3D897}.Release|Any CPU.Build.0 = Release|Any CPU + {2EEEB8C2-2D58-4A75-81DB-241CB40746BF}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {2EEEB8C2-2D58-4A75-81DB-241CB40746BF}.Debug|Any CPU.Build.0 = Debug|Any CPU + {2EEEB8C2-2D58-4A75-81DB-241CB40746BF}.Release|Any CPU.ActiveCfg = Release|Any CPU + {2EEEB8C2-2D58-4A75-81DB-241CB40746BF}.Release|Any CPU.Build.0 = Release|Any CPU EndGlobalSection EndGlobal diff --git a/src/Merge.Client/Accounting/AccountDetails/AccountDetailsClient.cs b/src/Merge.Client/Accounting/AccountDetails/AccountDetailsClient.cs index 7c26b411..8e6344f6 100644 --- a/src/Merge.Client/Accounting/AccountDetails/AccountDetailsClient.cs +++ b/src/Merge.Client/Accounting/AccountDetails/AccountDetailsClient.cs @@ -1,6 +1,6 @@ +using System.Net.Http; using System.Text.Json; -using Merge.Client; -using Merge.Client.Accounting; +using Merge.Client.Core; #nullable enable @@ -18,20 +18,34 @@ public AccountDetailsClient(RawClient client) /// /// Get details for a linked account. /// - public async Task RetrieveAsync() + public async Task RetrieveAsync(RequestOptions? options = null) { var response = await _client.MakeRequestAsync( new RawClient.JsonApiRequest { + BaseUrl = _client.Options.BaseUrl, Method = HttpMethod.Get, - Path = "accounting/v1/account-details" + Path = "accounting/v1/account-details", + Options = options } ); - string responseBody = await response.Raw.Content.ReadAsStringAsync(); - if (response.StatusCode >= 200 && response.StatusCode < 400) + var responseBody = await response.Raw.Content.ReadAsStringAsync(); + if (response.StatusCode is >= 200 and < 400) { - return JsonSerializer.Deserialize(responseBody); + try + { + return JsonUtils.Deserialize(responseBody)!; + } + catch (JsonException e) + { + throw new MergeException("Failed to deserialize response", e); + } } - throw new Exception(responseBody); + + throw new MergeApiException( + $"Error with status code {response.StatusCode}", + response.StatusCode, + JsonUtils.Deserialize(responseBody) + ); } } diff --git a/src/Merge.Client/Accounting/AccountToken/AccountTokenClient.cs b/src/Merge.Client/Accounting/AccountToken/AccountTokenClient.cs index fe1cfa42..afe1d2df 100644 --- a/src/Merge.Client/Accounting/AccountToken/AccountTokenClient.cs +++ b/src/Merge.Client/Accounting/AccountToken/AccountTokenClient.cs @@ -1,6 +1,6 @@ +using System.Net.Http; using System.Text.Json; -using Merge.Client; -using Merge.Client.Accounting; +using Merge.Client.Core; #nullable enable @@ -18,20 +18,37 @@ public AccountTokenClient(RawClient client) /// /// Returns the account token for the end user with the provided public token. /// - public async Task RetrieveAsync(string publicToken) + public async Task RetrieveAsync( + string publicToken, + RequestOptions? options = null + ) { var response = await _client.MakeRequestAsync( new RawClient.JsonApiRequest { + BaseUrl = _client.Options.BaseUrl, Method = HttpMethod.Get, - Path = $"accounting/v1/account-token/{publicToken}" + Path = $"accounting/v1/account-token/{publicToken}", + Options = options } ); - string responseBody = await response.Raw.Content.ReadAsStringAsync(); - if (response.StatusCode >= 200 && response.StatusCode < 400) + var responseBody = await response.Raw.Content.ReadAsStringAsync(); + if (response.StatusCode is >= 200 and < 400) { - return JsonSerializer.Deserialize(responseBody); + try + { + return JsonUtils.Deserialize(responseBody)!; + } + catch (JsonException e) + { + throw new MergeException("Failed to deserialize response", e); + } } - throw new Exception(responseBody); + + throw new MergeApiException( + $"Error with status code {response.StatusCode}", + response.StatusCode, + JsonUtils.Deserialize(responseBody) + ); } } diff --git a/src/Merge.Client/Accounting/AccountingClient.cs b/src/Merge.Client/Accounting/AccountingClient.cs index eaa4d52a..1d336394 100644 --- a/src/Merge.Client/Accounting/AccountingClient.cs +++ b/src/Merge.Client/Accounting/AccountingClient.cs @@ -1,5 +1,4 @@ -using Merge.Client; -using Merge.Client.Accounting; +using Merge.Client.Core; #nullable enable diff --git a/src/Merge.Client/Accounting/AccountingPeriods/AccountingPeriodsClient.cs b/src/Merge.Client/Accounting/AccountingPeriods/AccountingPeriodsClient.cs index 3e984e0f..2cd65fc9 100644 --- a/src/Merge.Client/Accounting/AccountingPeriods/AccountingPeriodsClient.cs +++ b/src/Merge.Client/Accounting/AccountingPeriods/AccountingPeriodsClient.cs @@ -1,6 +1,6 @@ +using System.Net.Http; using System.Text.Json; -using Merge.Client; -using Merge.Client.Accounting; +using Merge.Client.Core; #nullable enable @@ -18,7 +18,10 @@ public AccountingPeriodsClient(RawClient client) /// /// Returns a list of `AccountingPeriod` objects. /// - public async Task ListAsync(AccountingPeriodsListRequest request) + public async Task ListAsync( + AccountingPeriodsListRequest request, + RequestOptions? options = null + ) { var _query = new Dictionary() { }; if (request.Cursor != null) @@ -40,17 +43,31 @@ public async Task ListAsync(AccountingPeriodsList var response = await _client.MakeRequestAsync( new RawClient.JsonApiRequest { + BaseUrl = _client.Options.BaseUrl, Method = HttpMethod.Get, Path = "accounting/v1/accounting-periods", - Query = _query + Query = _query, + Options = options } ); - string responseBody = await response.Raw.Content.ReadAsStringAsync(); - if (response.StatusCode >= 200 && response.StatusCode < 400) + var responseBody = await response.Raw.Content.ReadAsStringAsync(); + if (response.StatusCode is >= 200 and < 400) { - return JsonSerializer.Deserialize(responseBody); + try + { + return JsonUtils.Deserialize(responseBody)!; + } + catch (JsonException e) + { + throw new MergeException("Failed to deserialize response", e); + } } - throw new Exception(responseBody); + + throw new MergeApiException( + $"Error with status code {response.StatusCode}", + response.StatusCode, + JsonUtils.Deserialize(responseBody) + ); } /// @@ -58,7 +75,8 @@ public async Task ListAsync(AccountingPeriodsList /// public async Task RetrieveAsync( string id, - AccountingPeriodsRetrieveRequest request + AccountingPeriodsRetrieveRequest request, + RequestOptions? options = null ) { var _query = new Dictionary() { }; @@ -69,16 +87,30 @@ AccountingPeriodsRetrieveRequest request var response = await _client.MakeRequestAsync( new RawClient.JsonApiRequest { + BaseUrl = _client.Options.BaseUrl, Method = HttpMethod.Get, Path = $"accounting/v1/accounting-periods/{id}", - Query = _query + Query = _query, + Options = options } ); - string responseBody = await response.Raw.Content.ReadAsStringAsync(); - if (response.StatusCode >= 200 && response.StatusCode < 400) + var responseBody = await response.Raw.Content.ReadAsStringAsync(); + if (response.StatusCode is >= 200 and < 400) { - return JsonSerializer.Deserialize(responseBody); + try + { + return JsonUtils.Deserialize(responseBody)!; + } + catch (JsonException e) + { + throw new MergeException("Failed to deserialize response", e); + } } - throw new Exception(responseBody); + + throw new MergeApiException( + $"Error with status code {response.StatusCode}", + response.StatusCode, + JsonUtils.Deserialize(responseBody) + ); } } diff --git a/src/Merge.Client/Accounting/AccountingPeriods/Requests/AccountingPeriodsListRequest.cs b/src/Merge.Client/Accounting/AccountingPeriods/Requests/AccountingPeriodsListRequest.cs index 3b4f5920..f3008796 100644 --- a/src/Merge.Client/Accounting/AccountingPeriods/Requests/AccountingPeriodsListRequest.cs +++ b/src/Merge.Client/Accounting/AccountingPeriods/Requests/AccountingPeriodsListRequest.cs @@ -1,24 +1,24 @@ namespace Merge.Client.Accounting; -public class AccountingPeriodsListRequest +public record AccountingPeriodsListRequest { /// /// The pagination cursor value. /// - public string? Cursor { get; init; } + public string? Cursor { get; set; } /// /// Whether to include data that was marked as deleted by third party webhooks. /// - public bool? IncludeDeletedData { get; init; } + public bool? IncludeDeletedData { get; set; } /// /// Whether to include the original data Merge fetched from the third-party to produce these models. /// - public bool? IncludeRemoteData { get; init; } + public bool? IncludeRemoteData { get; set; } /// /// Number of results to return per page. /// - public int? PageSize { get; init; } + public int? PageSize { get; set; } } diff --git a/src/Merge.Client/Accounting/AccountingPeriods/Requests/AccountingPeriodsRetrieveRequest.cs b/src/Merge.Client/Accounting/AccountingPeriods/Requests/AccountingPeriodsRetrieveRequest.cs index d7fa2717..8fe02492 100644 --- a/src/Merge.Client/Accounting/AccountingPeriods/Requests/AccountingPeriodsRetrieveRequest.cs +++ b/src/Merge.Client/Accounting/AccountingPeriods/Requests/AccountingPeriodsRetrieveRequest.cs @@ -1,9 +1,9 @@ namespace Merge.Client.Accounting; -public class AccountingPeriodsRetrieveRequest +public record AccountingPeriodsRetrieveRequest { /// /// Whether to include the original data Merge fetched from the third-party to produce these models. /// - public bool? IncludeRemoteData { get; init; } + public bool? IncludeRemoteData { get; set; } } diff --git a/src/Merge.Client/Accounting/Accounts/AccountsClient.cs b/src/Merge.Client/Accounting/Accounts/AccountsClient.cs index d57aff15..fbddbece 100644 --- a/src/Merge.Client/Accounting/Accounts/AccountsClient.cs +++ b/src/Merge.Client/Accounting/Accounts/AccountsClient.cs @@ -1,6 +1,6 @@ +using System.Net.Http; using System.Text.Json; -using Merge.Client; -using Merge.Client.Accounting; +using Merge.Client.Core; #nullable enable @@ -18,7 +18,10 @@ public AccountsClient(RawClient client) /// /// Returns a list of `Account` objects. /// - public async Task ListAsync(AccountsListRequest request) + public async Task ListAsync( + AccountsListRequest request, + RequestOptions? options = null + ) { var _query = new Dictionary() { }; if (request.CompanyId != null) @@ -27,11 +30,13 @@ public async Task ListAsync(AccountsListRequest request) } if (request.CreatedAfter != null) { - _query["created_after"] = request.CreatedAfter.Value.ToString("o0"); + _query["created_after"] = request.CreatedAfter.Value.ToString(Constants.DateTimeFormat); } if (request.CreatedBefore != null) { - _query["created_before"] = request.CreatedBefore.Value.ToString("o0"); + _query["created_before"] = request.CreatedBefore.Value.ToString( + Constants.DateTimeFormat + ); } if (request.Cursor != null) { @@ -51,11 +56,15 @@ public async Task ListAsync(AccountsListRequest request) } if (request.ModifiedAfter != null) { - _query["modified_after"] = request.ModifiedAfter.Value.ToString("o0"); + _query["modified_after"] = request.ModifiedAfter.Value.ToString( + Constants.DateTimeFormat + ); } if (request.ModifiedBefore != null) { - _query["modified_before"] = request.ModifiedBefore.Value.ToString("o0"); + _query["modified_before"] = request.ModifiedBefore.Value.ToString( + Constants.DateTimeFormat + ); } if (request.PageSize != null) { @@ -76,23 +85,40 @@ public async Task ListAsync(AccountsListRequest request) var response = await _client.MakeRequestAsync( new RawClient.JsonApiRequest { + BaseUrl = _client.Options.BaseUrl, Method = HttpMethod.Get, Path = "accounting/v1/accounts", - Query = _query + Query = _query, + Options = options } ); - string responseBody = await response.Raw.Content.ReadAsStringAsync(); - if (response.StatusCode >= 200 && response.StatusCode < 400) + var responseBody = await response.Raw.Content.ReadAsStringAsync(); + if (response.StatusCode is >= 200 and < 400) { - return JsonSerializer.Deserialize(responseBody); + try + { + return JsonUtils.Deserialize(responseBody)!; + } + catch (JsonException e) + { + throw new MergeException("Failed to deserialize response", e); + } } - throw new Exception(responseBody); + + throw new MergeApiException( + $"Error with status code {response.StatusCode}", + response.StatusCode, + JsonUtils.Deserialize(responseBody) + ); } /// /// Creates an `Account` object with the given values. /// - public async Task CreateAsync(AccountEndpointRequest request) + public async Task CreateAsync( + AccountEndpointRequest request, + RequestOptions? options = null + ) { var _query = new Dictionary() { }; if (request.IsDebugMode != null) @@ -106,23 +132,41 @@ public async Task CreateAsync(AccountEndpointRequest request) var response = await _client.MakeRequestAsync( new RawClient.JsonApiRequest { + BaseUrl = _client.Options.BaseUrl, Method = HttpMethod.Post, Path = "accounting/v1/accounts", - Query = _query + Query = _query, + Options = options } ); - string responseBody = await response.Raw.Content.ReadAsStringAsync(); - if (response.StatusCode >= 200 && response.StatusCode < 400) + var responseBody = await response.Raw.Content.ReadAsStringAsync(); + if (response.StatusCode is >= 200 and < 400) { - return JsonSerializer.Deserialize(responseBody); + try + { + return JsonUtils.Deserialize(responseBody)!; + } + catch (JsonException e) + { + throw new MergeException("Failed to deserialize response", e); + } } - throw new Exception(responseBody); + + throw new MergeApiException( + $"Error with status code {response.StatusCode}", + response.StatusCode, + JsonUtils.Deserialize(responseBody) + ); } /// /// Returns an `Account` object with the given `id`. /// - public async Task RetrieveAsync(string id, AccountsRetrieveRequest request) + public async Task RetrieveAsync( + string id, + AccountsRetrieveRequest request, + RequestOptions? options = null + ) { var _query = new Dictionary() { }; if (request.Expand != null) @@ -144,36 +188,64 @@ public async Task RetrieveAsync(string id, AccountsRetrieveRequest requ var response = await _client.MakeRequestAsync( new RawClient.JsonApiRequest { + BaseUrl = _client.Options.BaseUrl, Method = HttpMethod.Get, Path = $"accounting/v1/accounts/{id}", - Query = _query + Query = _query, + Options = options } ); - string responseBody = await response.Raw.Content.ReadAsStringAsync(); - if (response.StatusCode >= 200 && response.StatusCode < 400) + var responseBody = await response.Raw.Content.ReadAsStringAsync(); + if (response.StatusCode is >= 200 and < 400) { - return JsonSerializer.Deserialize(responseBody); + try + { + return JsonUtils.Deserialize(responseBody)!; + } + catch (JsonException e) + { + throw new MergeException("Failed to deserialize response", e); + } } - throw new Exception(responseBody); + + throw new MergeApiException( + $"Error with status code {response.StatusCode}", + response.StatusCode, + JsonUtils.Deserialize(responseBody) + ); } /// /// Returns metadata for `Account` POSTs. /// - public async Task MetaPostRetrieveAsync() + public async Task MetaPostRetrieveAsync(RequestOptions? options = null) { var response = await _client.MakeRequestAsync( new RawClient.JsonApiRequest { + BaseUrl = _client.Options.BaseUrl, Method = HttpMethod.Get, - Path = "accounting/v1/accounts/meta/post" + Path = "accounting/v1/accounts/meta/post", + Options = options } ); - string responseBody = await response.Raw.Content.ReadAsStringAsync(); - if (response.StatusCode >= 200 && response.StatusCode < 400) + var responseBody = await response.Raw.Content.ReadAsStringAsync(); + if (response.StatusCode is >= 200 and < 400) { - return JsonSerializer.Deserialize(responseBody); + try + { + return JsonUtils.Deserialize(responseBody)!; + } + catch (JsonException e) + { + throw new MergeException("Failed to deserialize response", e); + } } - throw new Exception(responseBody); + + throw new MergeApiException( + $"Error with status code {response.StatusCode}", + response.StatusCode, + JsonUtils.Deserialize(responseBody) + ); } } diff --git a/src/Merge.Client/Accounting/Accounts/Requests/AccountEndpointRequest.cs b/src/Merge.Client/Accounting/Accounts/Requests/AccountEndpointRequest.cs index 17cb746d..41ae6f38 100644 --- a/src/Merge.Client/Accounting/Accounts/Requests/AccountEndpointRequest.cs +++ b/src/Merge.Client/Accounting/Accounts/Requests/AccountEndpointRequest.cs @@ -1,20 +1,16 @@ -using Merge.Client.Accounting; - -#nullable enable - namespace Merge.Client.Accounting; -public class AccountEndpointRequest +public record AccountEndpointRequest { /// /// Whether to include debug fields (such as log file links) in the response. /// - public bool? IsDebugMode { get; init; } + public bool? IsDebugMode { get; set; } /// /// Whether or not third-party updates should be run asynchronously. /// - public bool? RunAsync { get; init; } + public bool? RunAsync { get; set; } - public AccountRequest Model { get; init; } + public required AccountRequest Model { get; set; } } diff --git a/src/Merge.Client/Accounting/Accounts/Requests/AccountsListRequest.cs b/src/Merge.Client/Accounting/Accounts/Requests/AccountsListRequest.cs index 9146b23a..14419f66 100644 --- a/src/Merge.Client/Accounting/Accounts/Requests/AccountsListRequest.cs +++ b/src/Merge.Client/Accounting/Accounts/Requests/AccountsListRequest.cs @@ -1,73 +1,69 @@ -using Merge.Client.Accounting; - -#nullable enable - namespace Merge.Client.Accounting; -public class AccountsListRequest +public record AccountsListRequest { /// /// If provided, will only return accounts for this company. /// - public string? CompanyId { get; init; } + public string? CompanyId { get; set; } /// /// If provided, will only return objects created after this datetime. /// - public DateTime? CreatedAfter { get; init; } + public DateTime? CreatedAfter { get; set; } /// /// If provided, will only return objects created before this datetime. /// - public DateTime? CreatedBefore { get; init; } + public DateTime? CreatedBefore { get; set; } /// /// The pagination cursor value. /// - public string? Cursor { get; init; } + public string? Cursor { get; set; } /// /// Which relations should be returned in expanded form. Multiple relation names should be comma separated without spaces. /// - public string? Expand { get; init; } + public string? Expand { get; set; } /// /// Whether to include data that was marked as deleted by third party webhooks. /// - public bool? IncludeDeletedData { get; init; } + public bool? IncludeDeletedData { get; set; } /// /// Whether to include the original data Merge fetched from the third-party to produce these models. /// - public bool? IncludeRemoteData { get; init; } + public bool? IncludeRemoteData { get; set; } /// /// If provided, only objects synced by Merge after this date time will be returned. /// - public DateTime? ModifiedAfter { get; init; } + public DateTime? ModifiedAfter { get; set; } /// /// If provided, only objects synced by Merge before this date time will be returned. /// - public DateTime? ModifiedBefore { get; init; } + public DateTime? ModifiedBefore { get; set; } /// /// Number of results to return per page. /// - public int? PageSize { get; init; } + public int? PageSize { get; set; } /// /// Deprecated. Use show_enum_origins. /// - public AccountsListRequestRemoteFields? RemoteFields { get; init; } + public AccountsListRequestRemoteFields? RemoteFields { get; set; } /// /// The API provider's ID for the given object. /// - public string? RemoteId { get; init; } + public string? RemoteId { get; set; } /// /// A comma separated list of enum field names for which you'd like the original values to be returned, instead of Merge's normalized enum values. [Learn more](https://help.merge.dev/en/articles/8950958-show_enum_origins-query-parameter) /// - public AccountsListRequestShowEnumOrigins? ShowEnumOrigins { get; init; } + public AccountsListRequestShowEnumOrigins? ShowEnumOrigins { get; set; } } diff --git a/src/Merge.Client/Accounting/Accounts/Requests/AccountsRetrieveRequest.cs b/src/Merge.Client/Accounting/Accounts/Requests/AccountsRetrieveRequest.cs index f0471292..0d26c41c 100644 --- a/src/Merge.Client/Accounting/Accounts/Requests/AccountsRetrieveRequest.cs +++ b/src/Merge.Client/Accounting/Accounts/Requests/AccountsRetrieveRequest.cs @@ -1,28 +1,24 @@ -using Merge.Client.Accounting; - -#nullable enable - namespace Merge.Client.Accounting; -public class AccountsRetrieveRequest +public record AccountsRetrieveRequest { /// /// Which relations should be returned in expanded form. Multiple relation names should be comma separated without spaces. /// - public string? Expand { get; init; } + public string? Expand { get; set; } /// /// Whether to include the original data Merge fetched from the third-party to produce these models. /// - public bool? IncludeRemoteData { get; init; } + public bool? IncludeRemoteData { get; set; } /// /// Deprecated. Use show_enum_origins. /// - public AccountsRetrieveRequestRemoteFields? RemoteFields { get; init; } + public AccountsRetrieveRequestRemoteFields? RemoteFields { get; set; } /// /// A comma separated list of enum field names for which you'd like the original values to be returned, instead of Merge's normalized enum values. [Learn more](https://help.merge.dev/en/articles/8950958-show_enum_origins-query-parameter) /// - public AccountsRetrieveRequestShowEnumOrigins? ShowEnumOrigins { get; init; } + public AccountsRetrieveRequestShowEnumOrigins? ShowEnumOrigins { get; set; } } diff --git a/src/Merge.Client/Accounting/Accounts/Types/AccountsListRequestRemoteFields.cs b/src/Merge.Client/Accounting/Accounts/Types/AccountsListRequestRemoteFields.cs index 2f8a2753..c487b764 100644 --- a/src/Merge.Client/Accounting/Accounts/Types/AccountsListRequestRemoteFields.cs +++ b/src/Merge.Client/Accounting/Accounts/Types/AccountsListRequestRemoteFields.cs @@ -1,6 +1,5 @@ using System.Runtime.Serialization; using System.Text.Json.Serialization; -using Merge.Client.Accounting; using Merge.Client.Core; #nullable enable diff --git a/src/Merge.Client/Accounting/Accounts/Types/AccountsListRequestShowEnumOrigins.cs b/src/Merge.Client/Accounting/Accounts/Types/AccountsListRequestShowEnumOrigins.cs index cf75e37a..4c55c912 100644 --- a/src/Merge.Client/Accounting/Accounts/Types/AccountsListRequestShowEnumOrigins.cs +++ b/src/Merge.Client/Accounting/Accounts/Types/AccountsListRequestShowEnumOrigins.cs @@ -1,6 +1,5 @@ using System.Runtime.Serialization; using System.Text.Json.Serialization; -using Merge.Client.Accounting; using Merge.Client.Core; #nullable enable diff --git a/src/Merge.Client/Accounting/Accounts/Types/AccountsRetrieveRequestRemoteFields.cs b/src/Merge.Client/Accounting/Accounts/Types/AccountsRetrieveRequestRemoteFields.cs index 524b8f81..056bb043 100644 --- a/src/Merge.Client/Accounting/Accounts/Types/AccountsRetrieveRequestRemoteFields.cs +++ b/src/Merge.Client/Accounting/Accounts/Types/AccountsRetrieveRequestRemoteFields.cs @@ -1,6 +1,5 @@ using System.Runtime.Serialization; using System.Text.Json.Serialization; -using Merge.Client.Accounting; using Merge.Client.Core; #nullable enable diff --git a/src/Merge.Client/Accounting/Accounts/Types/AccountsRetrieveRequestShowEnumOrigins.cs b/src/Merge.Client/Accounting/Accounts/Types/AccountsRetrieveRequestShowEnumOrigins.cs index 65f4e15a..ce5ee6b8 100644 --- a/src/Merge.Client/Accounting/Accounts/Types/AccountsRetrieveRequestShowEnumOrigins.cs +++ b/src/Merge.Client/Accounting/Accounts/Types/AccountsRetrieveRequestShowEnumOrigins.cs @@ -1,6 +1,5 @@ using System.Runtime.Serialization; using System.Text.Json.Serialization; -using Merge.Client.Accounting; using Merge.Client.Core; #nullable enable diff --git a/src/Merge.Client/Accounting/Addresses/AddressesClient.cs b/src/Merge.Client/Accounting/Addresses/AddressesClient.cs index 70b8a2d0..3056f10d 100644 --- a/src/Merge.Client/Accounting/Addresses/AddressesClient.cs +++ b/src/Merge.Client/Accounting/Addresses/AddressesClient.cs @@ -1,6 +1,6 @@ +using System.Net.Http; using System.Text.Json; -using Merge.Client; -using Merge.Client.Accounting; +using Merge.Client.Core; #nullable enable @@ -18,7 +18,11 @@ public AddressesClient(RawClient client) /// /// Returns an `Address` object with the given `id`. /// - public async Task
RetrieveAsync(string id, AddressesRetrieveRequest request) + public async Task
RetrieveAsync( + string id, + AddressesRetrieveRequest request, + RequestOptions? options = null + ) { var _query = new Dictionary() { }; if (request.IncludeRemoteData != null) @@ -36,16 +40,30 @@ public async Task
RetrieveAsync(string id, AddressesRetrieveRequest req var response = await _client.MakeRequestAsync( new RawClient.JsonApiRequest { + BaseUrl = _client.Options.BaseUrl, Method = HttpMethod.Get, Path = $"accounting/v1/addresses/{id}", - Query = _query + Query = _query, + Options = options } ); - string responseBody = await response.Raw.Content.ReadAsStringAsync(); - if (response.StatusCode >= 200 && response.StatusCode < 400) + var responseBody = await response.Raw.Content.ReadAsStringAsync(); + if (response.StatusCode is >= 200 and < 400) { - return JsonSerializer.Deserialize
(responseBody); + try + { + return JsonUtils.Deserialize
(responseBody)!; + } + catch (JsonException e) + { + throw new MergeException("Failed to deserialize response", e); + } } - throw new Exception(responseBody); + + throw new MergeApiException( + $"Error with status code {response.StatusCode}", + response.StatusCode, + JsonUtils.Deserialize(responseBody) + ); } } diff --git a/src/Merge.Client/Accounting/Addresses/Requests/AddressesRetrieveRequest.cs b/src/Merge.Client/Accounting/Addresses/Requests/AddressesRetrieveRequest.cs index aa658aa7..49e97c47 100644 --- a/src/Merge.Client/Accounting/Addresses/Requests/AddressesRetrieveRequest.cs +++ b/src/Merge.Client/Accounting/Addresses/Requests/AddressesRetrieveRequest.cs @@ -1,19 +1,19 @@ namespace Merge.Client.Accounting; -public class AddressesRetrieveRequest +public record AddressesRetrieveRequest { /// /// Whether to include the original data Merge fetched from the third-party to produce these models. /// - public bool? IncludeRemoteData { get; init; } + public bool? IncludeRemoteData { get; set; } /// /// Deprecated. Use show_enum_origins. /// - public string? RemoteFields { get; init; } + public string? RemoteFields { get; set; } /// /// A comma separated list of enum field names for which you'd like the original values to be returned, instead of Merge's normalized enum values. [Learn more](https://help.merge.dev/en/articles/8950958-show_enum_origins-query-parameter) /// - public string? ShowEnumOrigins { get; init; } + public string? ShowEnumOrigins { get; set; } } diff --git a/src/Merge.Client/Accounting/AsyncPassthrough/AsyncPassthroughClient.cs b/src/Merge.Client/Accounting/AsyncPassthrough/AsyncPassthroughClient.cs index e5e43567..7a1a3919 100644 --- a/src/Merge.Client/Accounting/AsyncPassthrough/AsyncPassthroughClient.cs +++ b/src/Merge.Client/Accounting/AsyncPassthrough/AsyncPassthroughClient.cs @@ -1,6 +1,6 @@ +using System.Net.Http; using System.Text.Json; -using Merge.Client; -using Merge.Client.Accounting; +using Merge.Client.Core; #nullable enable @@ -18,41 +18,75 @@ public AsyncPassthroughClient(RawClient client) /// /// Asynchronously pull data from an endpoint not currently supported by Merge. /// - public async Task CreateAsync(DataPassthroughRequest request) + public async Task CreateAsync( + DataPassthroughRequest request, + RequestOptions? options = null + ) { var response = await _client.MakeRequestAsync( new RawClient.JsonApiRequest { + BaseUrl = _client.Options.BaseUrl, Method = HttpMethod.Post, Path = "accounting/v1/async-passthrough", - Body = request + Body = request, + Options = options } ); - string responseBody = await response.Raw.Content.ReadAsStringAsync(); - if (response.StatusCode >= 200 && response.StatusCode < 400) + var responseBody = await response.Raw.Content.ReadAsStringAsync(); + if (response.StatusCode is >= 200 and < 400) { - return JsonSerializer.Deserialize(responseBody); + try + { + return JsonUtils.Deserialize(responseBody)!; + } + catch (JsonException e) + { + throw new MergeException("Failed to deserialize response", e); + } } - throw new Exception(responseBody); + + throw new MergeApiException( + $"Error with status code {response.StatusCode}", + response.StatusCode, + JsonUtils.Deserialize(responseBody) + ); } /// /// Retrieves data from earlier async-passthrough POST request /// - public async Task RetrieveAsync(string asyncPassthroughReceiptId) + public async Task RetrieveAsync( + string asyncPassthroughReceiptId, + RequestOptions? options = null + ) { var response = await _client.MakeRequestAsync( new RawClient.JsonApiRequest { + BaseUrl = _client.Options.BaseUrl, Method = HttpMethod.Get, - Path = $"accounting/v1/async-passthrough/{asyncPassthroughReceiptId}" + Path = $"accounting/v1/async-passthrough/{asyncPassthroughReceiptId}", + Options = options } ); - string responseBody = await response.Raw.Content.ReadAsStringAsync(); - if (response.StatusCode >= 200 && response.StatusCode < 400) + var responseBody = await response.Raw.Content.ReadAsStringAsync(); + if (response.StatusCode is >= 200 and < 400) { - return JsonSerializer.Deserialize(responseBody); + try + { + return JsonUtils.Deserialize(responseBody)!; + } + catch (JsonException e) + { + throw new MergeException("Failed to deserialize response", e); + } } - throw new Exception(responseBody); + + throw new MergeApiException( + $"Error with status code {response.StatusCode}", + response.StatusCode, + JsonUtils.Deserialize(responseBody) + ); } } diff --git a/src/Merge.Client/Accounting/Attachments/AttachmentsClient.cs b/src/Merge.Client/Accounting/Attachments/AttachmentsClient.cs index e40f00f7..e9ec7ce6 100644 --- a/src/Merge.Client/Accounting/Attachments/AttachmentsClient.cs +++ b/src/Merge.Client/Accounting/Attachments/AttachmentsClient.cs @@ -1,6 +1,6 @@ +using System.Net.Http; using System.Text.Json; -using Merge.Client; -using Merge.Client.Accounting; +using Merge.Client.Core; #nullable enable @@ -18,7 +18,10 @@ public AttachmentsClient(RawClient client) /// /// Returns a list of `AccountingAttachment` objects. /// - public async Task ListAsync(AttachmentsListRequest request) + public async Task ListAsync( + AttachmentsListRequest request, + RequestOptions? options = null + ) { var _query = new Dictionary() { }; if (request.CompanyId != null) @@ -27,11 +30,13 @@ public async Task ListAsync(AttachmentsListRe } if (request.CreatedAfter != null) { - _query["created_after"] = request.CreatedAfter.Value.ToString("o0"); + _query["created_after"] = request.CreatedAfter.Value.ToString(Constants.DateTimeFormat); } if (request.CreatedBefore != null) { - _query["created_before"] = request.CreatedBefore.Value.ToString("o0"); + _query["created_before"] = request.CreatedBefore.Value.ToString( + Constants.DateTimeFormat + ); } if (request.Cursor != null) { @@ -47,11 +52,15 @@ public async Task ListAsync(AttachmentsListRe } if (request.ModifiedAfter != null) { - _query["modified_after"] = request.ModifiedAfter.Value.ToString("o0"); + _query["modified_after"] = request.ModifiedAfter.Value.ToString( + Constants.DateTimeFormat + ); } if (request.ModifiedBefore != null) { - _query["modified_before"] = request.ModifiedBefore.Value.ToString("o0"); + _query["modified_before"] = request.ModifiedBefore.Value.ToString( + Constants.DateTimeFormat + ); } if (request.PageSize != null) { @@ -64,24 +73,39 @@ public async Task ListAsync(AttachmentsListRe var response = await _client.MakeRequestAsync( new RawClient.JsonApiRequest { + BaseUrl = _client.Options.BaseUrl, Method = HttpMethod.Get, Path = "accounting/v1/attachments", - Query = _query + Query = _query, + Options = options } ); - string responseBody = await response.Raw.Content.ReadAsStringAsync(); - if (response.StatusCode >= 200 && response.StatusCode < 400) + var responseBody = await response.Raw.Content.ReadAsStringAsync(); + if (response.StatusCode is >= 200 and < 400) { - return JsonSerializer.Deserialize(responseBody); + try + { + return JsonUtils.Deserialize(responseBody)!; + } + catch (JsonException e) + { + throw new MergeException("Failed to deserialize response", e); + } } - throw new Exception(responseBody); + + throw new MergeApiException( + $"Error with status code {response.StatusCode}", + response.StatusCode, + JsonUtils.Deserialize(responseBody) + ); } /// /// Creates an `AccountingAttachment` object with the given values. /// public async Task CreateAsync( - AccountingAttachmentEndpointRequest request + AccountingAttachmentEndpointRequest request, + RequestOptions? options = null ) { var _query = new Dictionary() { }; @@ -96,17 +120,31 @@ AccountingAttachmentEndpointRequest request var response = await _client.MakeRequestAsync( new RawClient.JsonApiRequest { + BaseUrl = _client.Options.BaseUrl, Method = HttpMethod.Post, Path = "accounting/v1/attachments", - Query = _query + Query = _query, + Options = options } ); - string responseBody = await response.Raw.Content.ReadAsStringAsync(); - if (response.StatusCode >= 200 && response.StatusCode < 400) + var responseBody = await response.Raw.Content.ReadAsStringAsync(); + if (response.StatusCode is >= 200 and < 400) { - return JsonSerializer.Deserialize(responseBody); + try + { + return JsonUtils.Deserialize(responseBody)!; + } + catch (JsonException e) + { + throw new MergeException("Failed to deserialize response", e); + } } - throw new Exception(responseBody); + + throw new MergeApiException( + $"Error with status code {response.StatusCode}", + response.StatusCode, + JsonUtils.Deserialize(responseBody) + ); } /// @@ -114,7 +152,8 @@ AccountingAttachmentEndpointRequest request /// public async Task RetrieveAsync( string id, - AttachmentsRetrieveRequest request + AttachmentsRetrieveRequest request, + RequestOptions? options = null ) { var _query = new Dictionary() { }; @@ -125,36 +164,64 @@ AttachmentsRetrieveRequest request var response = await _client.MakeRequestAsync( new RawClient.JsonApiRequest { + BaseUrl = _client.Options.BaseUrl, Method = HttpMethod.Get, Path = $"accounting/v1/attachments/{id}", - Query = _query + Query = _query, + Options = options } ); - string responseBody = await response.Raw.Content.ReadAsStringAsync(); - if (response.StatusCode >= 200 && response.StatusCode < 400) + var responseBody = await response.Raw.Content.ReadAsStringAsync(); + if (response.StatusCode is >= 200 and < 400) { - return JsonSerializer.Deserialize(responseBody); + try + { + return JsonUtils.Deserialize(responseBody)!; + } + catch (JsonException e) + { + throw new MergeException("Failed to deserialize response", e); + } } - throw new Exception(responseBody); + + throw new MergeApiException( + $"Error with status code {response.StatusCode}", + response.StatusCode, + JsonUtils.Deserialize(responseBody) + ); } /// /// Returns metadata for `AccountingAttachment` POSTs. /// - public async Task MetaPostRetrieveAsync() + public async Task MetaPostRetrieveAsync(RequestOptions? options = null) { var response = await _client.MakeRequestAsync( new RawClient.JsonApiRequest { + BaseUrl = _client.Options.BaseUrl, Method = HttpMethod.Get, - Path = "accounting/v1/attachments/meta/post" + Path = "accounting/v1/attachments/meta/post", + Options = options } ); - string responseBody = await response.Raw.Content.ReadAsStringAsync(); - if (response.StatusCode >= 200 && response.StatusCode < 400) + var responseBody = await response.Raw.Content.ReadAsStringAsync(); + if (response.StatusCode is >= 200 and < 400) { - return JsonSerializer.Deserialize(responseBody); + try + { + return JsonUtils.Deserialize(responseBody)!; + } + catch (JsonException e) + { + throw new MergeException("Failed to deserialize response", e); + } } - throw new Exception(responseBody); + + throw new MergeApiException( + $"Error with status code {response.StatusCode}", + response.StatusCode, + JsonUtils.Deserialize(responseBody) + ); } } diff --git a/src/Merge.Client/Accounting/Attachments/Requests/AccountingAttachmentEndpointRequest.cs b/src/Merge.Client/Accounting/Attachments/Requests/AccountingAttachmentEndpointRequest.cs index 55691934..13d73c0a 100644 --- a/src/Merge.Client/Accounting/Attachments/Requests/AccountingAttachmentEndpointRequest.cs +++ b/src/Merge.Client/Accounting/Attachments/Requests/AccountingAttachmentEndpointRequest.cs @@ -1,20 +1,16 @@ -using Merge.Client.Accounting; - -#nullable enable - namespace Merge.Client.Accounting; -public class AccountingAttachmentEndpointRequest +public record AccountingAttachmentEndpointRequest { /// /// Whether to include debug fields (such as log file links) in the response. /// - public bool? IsDebugMode { get; init; } + public bool? IsDebugMode { get; set; } /// /// Whether or not third-party updates should be run asynchronously. /// - public bool? RunAsync { get; init; } + public bool? RunAsync { get; set; } - public AccountingAttachmentRequest Model { get; init; } + public required AccountingAttachmentRequest Model { get; set; } } diff --git a/src/Merge.Client/Accounting/Attachments/Requests/AttachmentsListRequest.cs b/src/Merge.Client/Accounting/Attachments/Requests/AttachmentsListRequest.cs index 4b558a6c..241d5567 100644 --- a/src/Merge.Client/Accounting/Attachments/Requests/AttachmentsListRequest.cs +++ b/src/Merge.Client/Accounting/Attachments/Requests/AttachmentsListRequest.cs @@ -1,54 +1,54 @@ namespace Merge.Client.Accounting; -public class AttachmentsListRequest +public record AttachmentsListRequest { /// /// If provided, will only return accounting attachments for this company. /// - public string? CompanyId { get; init; } + public string? CompanyId { get; set; } /// /// If provided, will only return objects created after this datetime. /// - public DateTime? CreatedAfter { get; init; } + public DateTime? CreatedAfter { get; set; } /// /// If provided, will only return objects created before this datetime. /// - public DateTime? CreatedBefore { get; init; } + public DateTime? CreatedBefore { get; set; } /// /// The pagination cursor value. /// - public string? Cursor { get; init; } + public string? Cursor { get; set; } /// /// Whether to include data that was marked as deleted by third party webhooks. /// - public bool? IncludeDeletedData { get; init; } + public bool? IncludeDeletedData { get; set; } /// /// Whether to include the original data Merge fetched from the third-party to produce these models. /// - public bool? IncludeRemoteData { get; init; } + public bool? IncludeRemoteData { get; set; } /// /// If provided, only objects synced by Merge after this date time will be returned. /// - public DateTime? ModifiedAfter { get; init; } + public DateTime? ModifiedAfter { get; set; } /// /// If provided, only objects synced by Merge before this date time will be returned. /// - public DateTime? ModifiedBefore { get; init; } + public DateTime? ModifiedBefore { get; set; } /// /// Number of results to return per page. /// - public int? PageSize { get; init; } + public int? PageSize { get; set; } /// /// The API provider's ID for the given object. /// - public string? RemoteId { get; init; } + public string? RemoteId { get; set; } } diff --git a/src/Merge.Client/Accounting/Attachments/Requests/AttachmentsRetrieveRequest.cs b/src/Merge.Client/Accounting/Attachments/Requests/AttachmentsRetrieveRequest.cs index a5a4700a..a95b6aef 100644 --- a/src/Merge.Client/Accounting/Attachments/Requests/AttachmentsRetrieveRequest.cs +++ b/src/Merge.Client/Accounting/Attachments/Requests/AttachmentsRetrieveRequest.cs @@ -1,9 +1,9 @@ namespace Merge.Client.Accounting; -public class AttachmentsRetrieveRequest +public record AttachmentsRetrieveRequest { /// /// Whether to include the original data Merge fetched from the third-party to produce these models. /// - public bool? IncludeRemoteData { get; init; } + public bool? IncludeRemoteData { get; set; } } diff --git a/src/Merge.Client/Accounting/AuditTrail/AuditTrailClient.cs b/src/Merge.Client/Accounting/AuditTrail/AuditTrailClient.cs index bbb83d62..1d7c526b 100644 --- a/src/Merge.Client/Accounting/AuditTrail/AuditTrailClient.cs +++ b/src/Merge.Client/Accounting/AuditTrail/AuditTrailClient.cs @@ -1,6 +1,6 @@ +using System.Net.Http; using System.Text.Json; -using Merge.Client; -using Merge.Client.Accounting; +using Merge.Client.Core; #nullable enable @@ -18,7 +18,10 @@ public AuditTrailClient(RawClient client) /// /// Gets a list of audit trail events. /// - public async Task ListAsync(AuditTrailListRequest request) + public async Task ListAsync( + AuditTrailListRequest request, + RequestOptions? options = null + ) { var _query = new Dictionary() { }; if (request.Cursor != null) @@ -48,16 +51,30 @@ public async Task ListAsync(AuditTrailListRequest re var response = await _client.MakeRequestAsync( new RawClient.JsonApiRequest { + BaseUrl = _client.Options.BaseUrl, Method = HttpMethod.Get, Path = "accounting/v1/audit-trail", - Query = _query + Query = _query, + Options = options } ); - string responseBody = await response.Raw.Content.ReadAsStringAsync(); - if (response.StatusCode >= 200 && response.StatusCode < 400) + var responseBody = await response.Raw.Content.ReadAsStringAsync(); + if (response.StatusCode is >= 200 and < 400) { - return JsonSerializer.Deserialize(responseBody); + try + { + return JsonUtils.Deserialize(responseBody)!; + } + catch (JsonException e) + { + throw new MergeException("Failed to deserialize response", e); + } } - throw new Exception(responseBody); + + throw new MergeApiException( + $"Error with status code {response.StatusCode}", + response.StatusCode, + JsonUtils.Deserialize(responseBody) + ); } } diff --git a/src/Merge.Client/Accounting/AuditTrail/Requests/AuditTrailListRequest.cs b/src/Merge.Client/Accounting/AuditTrail/Requests/AuditTrailListRequest.cs index c0a5f488..580a9c34 100644 --- a/src/Merge.Client/Accounting/AuditTrail/Requests/AuditTrailListRequest.cs +++ b/src/Merge.Client/Accounting/AuditTrail/Requests/AuditTrailListRequest.cs @@ -1,34 +1,34 @@ namespace Merge.Client.Accounting; -public class AuditTrailListRequest +public record AuditTrailListRequest { /// /// The pagination cursor value. /// - public string? Cursor { get; init; } + public string? Cursor { get; set; } /// /// If included, will only include audit trail events that occurred before this time /// - public string? EndDate { get; init; } + public string? EndDate { get; set; } /// /// If included, will only include events with the given event type. Possible values include: `CREATED_REMOTE_PRODUCTION_API_KEY`, `DELETED_REMOTE_PRODUCTION_API_KEY`, `CREATED_TEST_API_KEY`, `DELETED_TEST_API_KEY`, `REGENERATED_PRODUCTION_API_KEY`, `INVITED_USER`, `TWO_FACTOR_AUTH_ENABLED`, `TWO_FACTOR_AUTH_DISABLED`, `DELETED_LINKED_ACCOUNT`, `CREATED_DESTINATION`, `DELETED_DESTINATION`, `CHANGED_DESTINATION`, `CHANGED_SCOPES`, `CHANGED_PERSONAL_INFORMATION`, `CHANGED_ORGANIZATION_SETTINGS`, `ENABLED_INTEGRATION`, `DISABLED_INTEGRATION`, `ENABLED_CATEGORY`, `DISABLED_CATEGORY`, `CHANGED_PASSWORD`, `RESET_PASSWORD`, `ENABLED_REDACT_UNMAPPED_DATA_FOR_ORGANIZATION`, `ENABLED_REDACT_UNMAPPED_DATA_FOR_LINKED_ACCOUNT`, `DISABLED_REDACT_UNMAPPED_DATA_FOR_ORGANIZATION`, `DISABLED_REDACT_UNMAPPED_DATA_FOR_LINKED_ACCOUNT`, `CREATED_INTEGRATION_WIDE_FIELD_MAPPING`, `CREATED_LINKED_ACCOUNT_FIELD_MAPPING`, `CHANGED_INTEGRATION_WIDE_FIELD_MAPPING`, `CHANGED_LINKED_ACCOUNT_FIELD_MAPPING`, `DELETED_INTEGRATION_WIDE_FIELD_MAPPING`, `DELETED_LINKED_ACCOUNT_FIELD_MAPPING`, `FORCED_LINKED_ACCOUNT_RESYNC`, `MUTED_ISSUE`, `GENERATED_MAGIC_LINK`, `ENABLED_MERGE_WEBHOOK`, `DISABLED_MERGE_WEBHOOK`, `MERGE_WEBHOOK_TARGET_CHANGED` /// - public string? EventType { get; init; } + public string? EventType { get; set; } /// /// Number of results to return per page. /// - public int? PageSize { get; init; } + public int? PageSize { get; set; } /// /// If included, will only include audit trail events that occurred after this time /// - public string? StartDate { get; init; } + public string? StartDate { get; set; } /// /// If provided, this will return events associated with the specified user email. Please note that the email address reflects the user's email at the time of the event, and may not be their current email. /// - public string? UserEmail { get; init; } + public string? UserEmail { get; set; } } diff --git a/src/Merge.Client/Accounting/AvailableActions/AvailableActionsClient.cs b/src/Merge.Client/Accounting/AvailableActions/AvailableActionsClient.cs index 9475fb25..07c918d8 100644 --- a/src/Merge.Client/Accounting/AvailableActions/AvailableActionsClient.cs +++ b/src/Merge.Client/Accounting/AvailableActions/AvailableActionsClient.cs @@ -1,6 +1,6 @@ +using System.Net.Http; using System.Text.Json; -using Merge.Client; -using Merge.Client.Accounting; +using Merge.Client.Core; #nullable enable @@ -18,20 +18,34 @@ public AvailableActionsClient(RawClient client) /// /// Returns a list of models and actions available for an account. /// - public async Task RetrieveAsync() + public async Task RetrieveAsync(RequestOptions? options = null) { var response = await _client.MakeRequestAsync( new RawClient.JsonApiRequest { + BaseUrl = _client.Options.BaseUrl, Method = HttpMethod.Get, - Path = "accounting/v1/available-actions" + Path = "accounting/v1/available-actions", + Options = options } ); - string responseBody = await response.Raw.Content.ReadAsStringAsync(); - if (response.StatusCode >= 200 && response.StatusCode < 400) + var responseBody = await response.Raw.Content.ReadAsStringAsync(); + if (response.StatusCode is >= 200 and < 400) { - return JsonSerializer.Deserialize(responseBody); + try + { + return JsonUtils.Deserialize(responseBody)!; + } + catch (JsonException e) + { + throw new MergeException("Failed to deserialize response", e); + } } - throw new Exception(responseBody); + + throw new MergeApiException( + $"Error with status code {response.StatusCode}", + response.StatusCode, + JsonUtils.Deserialize(responseBody) + ); } } diff --git a/src/Merge.Client/Accounting/BalanceSheets/BalanceSheetsClient.cs b/src/Merge.Client/Accounting/BalanceSheets/BalanceSheetsClient.cs index 00b3dd48..d2eb2675 100644 --- a/src/Merge.Client/Accounting/BalanceSheets/BalanceSheetsClient.cs +++ b/src/Merge.Client/Accounting/BalanceSheets/BalanceSheetsClient.cs @@ -1,6 +1,6 @@ +using System.Net.Http; using System.Text.Json; -using Merge.Client; -using Merge.Client.Accounting; +using Merge.Client.Core; #nullable enable @@ -18,7 +18,10 @@ public BalanceSheetsClient(RawClient client) /// /// Returns a list of `BalanceSheet` objects. /// - public async Task ListAsync(BalanceSheetsListRequest request) + public async Task ListAsync( + BalanceSheetsListRequest request, + RequestOptions? options = null + ) { var _query = new Dictionary() { }; if (request.CompanyId != null) @@ -27,11 +30,13 @@ public async Task ListAsync(BalanceSheetsListRequest } if (request.CreatedAfter != null) { - _query["created_after"] = request.CreatedAfter.Value.ToString("o0"); + _query["created_after"] = request.CreatedAfter.Value.ToString(Constants.DateTimeFormat); } if (request.CreatedBefore != null) { - _query["created_before"] = request.CreatedBefore.Value.ToString("o0"); + _query["created_before"] = request.CreatedBefore.Value.ToString( + Constants.DateTimeFormat + ); } if (request.Cursor != null) { @@ -51,11 +56,15 @@ public async Task ListAsync(BalanceSheetsListRequest } if (request.ModifiedAfter != null) { - _query["modified_after"] = request.ModifiedAfter.Value.ToString("o0"); + _query["modified_after"] = request.ModifiedAfter.Value.ToString( + Constants.DateTimeFormat + ); } if (request.ModifiedBefore != null) { - _query["modified_before"] = request.ModifiedBefore.Value.ToString("o0"); + _query["modified_before"] = request.ModifiedBefore.Value.ToString( + Constants.DateTimeFormat + ); } if (request.PageSize != null) { @@ -68,23 +77,41 @@ public async Task ListAsync(BalanceSheetsListRequest var response = await _client.MakeRequestAsync( new RawClient.JsonApiRequest { + BaseUrl = _client.Options.BaseUrl, Method = HttpMethod.Get, Path = "accounting/v1/balance-sheets", - Query = _query + Query = _query, + Options = options } ); - string responseBody = await response.Raw.Content.ReadAsStringAsync(); - if (response.StatusCode >= 200 && response.StatusCode < 400) + var responseBody = await response.Raw.Content.ReadAsStringAsync(); + if (response.StatusCode is >= 200 and < 400) { - return JsonSerializer.Deserialize(responseBody); + try + { + return JsonUtils.Deserialize(responseBody)!; + } + catch (JsonException e) + { + throw new MergeException("Failed to deserialize response", e); + } } - throw new Exception(responseBody); + + throw new MergeApiException( + $"Error with status code {response.StatusCode}", + response.StatusCode, + JsonUtils.Deserialize(responseBody) + ); } /// /// Returns a `BalanceSheet` object with the given `id`. /// - public async Task RetrieveAsync(string id, BalanceSheetsRetrieveRequest request) + public async Task RetrieveAsync( + string id, + BalanceSheetsRetrieveRequest request, + RequestOptions? options = null + ) { var _query = new Dictionary() { }; if (request.Expand != null) @@ -98,16 +125,30 @@ public async Task RetrieveAsync(string id, BalanceSheetsRetrieveRe var response = await _client.MakeRequestAsync( new RawClient.JsonApiRequest { + BaseUrl = _client.Options.BaseUrl, Method = HttpMethod.Get, Path = $"accounting/v1/balance-sheets/{id}", - Query = _query + Query = _query, + Options = options } ); - string responseBody = await response.Raw.Content.ReadAsStringAsync(); - if (response.StatusCode >= 200 && response.StatusCode < 400) + var responseBody = await response.Raw.Content.ReadAsStringAsync(); + if (response.StatusCode is >= 200 and < 400) { - return JsonSerializer.Deserialize(responseBody); + try + { + return JsonUtils.Deserialize(responseBody)!; + } + catch (JsonException e) + { + throw new MergeException("Failed to deserialize response", e); + } } - throw new Exception(responseBody); + + throw new MergeApiException( + $"Error with status code {response.StatusCode}", + response.StatusCode, + JsonUtils.Deserialize(responseBody) + ); } } diff --git a/src/Merge.Client/Accounting/BalanceSheets/Requests/BalanceSheetsListRequest.cs b/src/Merge.Client/Accounting/BalanceSheets/Requests/BalanceSheetsListRequest.cs index 8e4ca474..1368f500 100644 --- a/src/Merge.Client/Accounting/BalanceSheets/Requests/BalanceSheetsListRequest.cs +++ b/src/Merge.Client/Accounting/BalanceSheets/Requests/BalanceSheetsListRequest.cs @@ -1,59 +1,59 @@ namespace Merge.Client.Accounting; -public class BalanceSheetsListRequest +public record BalanceSheetsListRequest { /// /// If provided, will only return balance sheets for this company. /// - public string? CompanyId { get; init; } + public string? CompanyId { get; set; } /// /// If provided, will only return objects created after this datetime. /// - public DateTime? CreatedAfter { get; init; } + public DateTime? CreatedAfter { get; set; } /// /// If provided, will only return objects created before this datetime. /// - public DateTime? CreatedBefore { get; init; } + public DateTime? CreatedBefore { get; set; } /// /// The pagination cursor value. /// - public string? Cursor { get; init; } + public string? Cursor { get; set; } /// /// Which relations should be returned in expanded form. Multiple relation names should be comma separated without spaces. /// - public string? Expand { get; init; } + public string? Expand { get; set; } /// /// Whether to include data that was marked as deleted by third party webhooks. /// - public bool? IncludeDeletedData { get; init; } + public bool? IncludeDeletedData { get; set; } /// /// Whether to include the original data Merge fetched from the third-party to produce these models. /// - public bool? IncludeRemoteData { get; init; } + public bool? IncludeRemoteData { get; set; } /// /// If provided, only objects synced by Merge after this date time will be returned. /// - public DateTime? ModifiedAfter { get; init; } + public DateTime? ModifiedAfter { get; set; } /// /// If provided, only objects synced by Merge before this date time will be returned. /// - public DateTime? ModifiedBefore { get; init; } + public DateTime? ModifiedBefore { get; set; } /// /// Number of results to return per page. /// - public int? PageSize { get; init; } + public int? PageSize { get; set; } /// /// The API provider's ID for the given object. /// - public string? RemoteId { get; init; } + public string? RemoteId { get; set; } } diff --git a/src/Merge.Client/Accounting/BalanceSheets/Requests/BalanceSheetsRetrieveRequest.cs b/src/Merge.Client/Accounting/BalanceSheets/Requests/BalanceSheetsRetrieveRequest.cs index 9d7aa257..70e757a4 100644 --- a/src/Merge.Client/Accounting/BalanceSheets/Requests/BalanceSheetsRetrieveRequest.cs +++ b/src/Merge.Client/Accounting/BalanceSheets/Requests/BalanceSheetsRetrieveRequest.cs @@ -1,14 +1,14 @@ namespace Merge.Client.Accounting; -public class BalanceSheetsRetrieveRequest +public record BalanceSheetsRetrieveRequest { /// /// Which relations should be returned in expanded form. Multiple relation names should be comma separated without spaces. /// - public string? Expand { get; init; } + public string? Expand { get; set; } /// /// Whether to include the original data Merge fetched from the third-party to produce these models. /// - public bool? IncludeRemoteData { get; init; } + public bool? IncludeRemoteData { get; set; } } diff --git a/src/Merge.Client/Accounting/CashFlowStatements/CashFlowStatementsClient.cs b/src/Merge.Client/Accounting/CashFlowStatements/CashFlowStatementsClient.cs index ce1f1599..f10f4faa 100644 --- a/src/Merge.Client/Accounting/CashFlowStatements/CashFlowStatementsClient.cs +++ b/src/Merge.Client/Accounting/CashFlowStatements/CashFlowStatementsClient.cs @@ -1,6 +1,6 @@ +using System.Net.Http; using System.Text.Json; -using Merge.Client; -using Merge.Client.Accounting; +using Merge.Client.Core; #nullable enable @@ -19,7 +19,8 @@ public CashFlowStatementsClient(RawClient client) /// Returns a list of `CashFlowStatement` objects. /// public async Task ListAsync( - CashFlowStatementsListRequest request + CashFlowStatementsListRequest request, + RequestOptions? options = null ) { var _query = new Dictionary() { }; @@ -29,11 +30,13 @@ CashFlowStatementsListRequest request } if (request.CreatedAfter != null) { - _query["created_after"] = request.CreatedAfter.Value.ToString("o0"); + _query["created_after"] = request.CreatedAfter.Value.ToString(Constants.DateTimeFormat); } if (request.CreatedBefore != null) { - _query["created_before"] = request.CreatedBefore.Value.ToString("o0"); + _query["created_before"] = request.CreatedBefore.Value.ToString( + Constants.DateTimeFormat + ); } if (request.Cursor != null) { @@ -53,11 +56,15 @@ CashFlowStatementsListRequest request } if (request.ModifiedAfter != null) { - _query["modified_after"] = request.ModifiedAfter.Value.ToString("o0"); + _query["modified_after"] = request.ModifiedAfter.Value.ToString( + Constants.DateTimeFormat + ); } if (request.ModifiedBefore != null) { - _query["modified_before"] = request.ModifiedBefore.Value.ToString("o0"); + _query["modified_before"] = request.ModifiedBefore.Value.ToString( + Constants.DateTimeFormat + ); } if (request.PageSize != null) { @@ -70,17 +77,31 @@ CashFlowStatementsListRequest request var response = await _client.MakeRequestAsync( new RawClient.JsonApiRequest { + BaseUrl = _client.Options.BaseUrl, Method = HttpMethod.Get, Path = "accounting/v1/cash-flow-statements", - Query = _query + Query = _query, + Options = options } ); - string responseBody = await response.Raw.Content.ReadAsStringAsync(); - if (response.StatusCode >= 200 && response.StatusCode < 400) + var responseBody = await response.Raw.Content.ReadAsStringAsync(); + if (response.StatusCode is >= 200 and < 400) { - return JsonSerializer.Deserialize(responseBody); + try + { + return JsonUtils.Deserialize(responseBody)!; + } + catch (JsonException e) + { + throw new MergeException("Failed to deserialize response", e); + } } - throw new Exception(responseBody); + + throw new MergeApiException( + $"Error with status code {response.StatusCode}", + response.StatusCode, + JsonUtils.Deserialize(responseBody) + ); } /// @@ -88,7 +109,8 @@ CashFlowStatementsListRequest request /// public async Task RetrieveAsync( string id, - CashFlowStatementsRetrieveRequest request + CashFlowStatementsRetrieveRequest request, + RequestOptions? options = null ) { var _query = new Dictionary() { }; @@ -103,16 +125,30 @@ CashFlowStatementsRetrieveRequest request var response = await _client.MakeRequestAsync( new RawClient.JsonApiRequest { + BaseUrl = _client.Options.BaseUrl, Method = HttpMethod.Get, Path = $"accounting/v1/cash-flow-statements/{id}", - Query = _query + Query = _query, + Options = options } ); - string responseBody = await response.Raw.Content.ReadAsStringAsync(); - if (response.StatusCode >= 200 && response.StatusCode < 400) + var responseBody = await response.Raw.Content.ReadAsStringAsync(); + if (response.StatusCode is >= 200 and < 400) { - return JsonSerializer.Deserialize(responseBody); + try + { + return JsonUtils.Deserialize(responseBody)!; + } + catch (JsonException e) + { + throw new MergeException("Failed to deserialize response", e); + } } - throw new Exception(responseBody); + + throw new MergeApiException( + $"Error with status code {response.StatusCode}", + response.StatusCode, + JsonUtils.Deserialize(responseBody) + ); } } diff --git a/src/Merge.Client/Accounting/CashFlowStatements/Requests/CashFlowStatementsListRequest.cs b/src/Merge.Client/Accounting/CashFlowStatements/Requests/CashFlowStatementsListRequest.cs index c9115777..d38ff15c 100644 --- a/src/Merge.Client/Accounting/CashFlowStatements/Requests/CashFlowStatementsListRequest.cs +++ b/src/Merge.Client/Accounting/CashFlowStatements/Requests/CashFlowStatementsListRequest.cs @@ -1,59 +1,59 @@ namespace Merge.Client.Accounting; -public class CashFlowStatementsListRequest +public record CashFlowStatementsListRequest { /// /// If provided, will only return cash flow statements for this company. /// - public string? CompanyId { get; init; } + public string? CompanyId { get; set; } /// /// If provided, will only return objects created after this datetime. /// - public DateTime? CreatedAfter { get; init; } + public DateTime? CreatedAfter { get; set; } /// /// If provided, will only return objects created before this datetime. /// - public DateTime? CreatedBefore { get; init; } + public DateTime? CreatedBefore { get; set; } /// /// The pagination cursor value. /// - public string? Cursor { get; init; } + public string? Cursor { get; set; } /// /// Which relations should be returned in expanded form. Multiple relation names should be comma separated without spaces. /// - public string? Expand { get; init; } + public string? Expand { get; set; } /// /// Whether to include data that was marked as deleted by third party webhooks. /// - public bool? IncludeDeletedData { get; init; } + public bool? IncludeDeletedData { get; set; } /// /// Whether to include the original data Merge fetched from the third-party to produce these models. /// - public bool? IncludeRemoteData { get; init; } + public bool? IncludeRemoteData { get; set; } /// /// If provided, only objects synced by Merge after this date time will be returned. /// - public DateTime? ModifiedAfter { get; init; } + public DateTime? ModifiedAfter { get; set; } /// /// If provided, only objects synced by Merge before this date time will be returned. /// - public DateTime? ModifiedBefore { get; init; } + public DateTime? ModifiedBefore { get; set; } /// /// Number of results to return per page. /// - public int? PageSize { get; init; } + public int? PageSize { get; set; } /// /// The API provider's ID for the given object. /// - public string? RemoteId { get; init; } + public string? RemoteId { get; set; } } diff --git a/src/Merge.Client/Accounting/CashFlowStatements/Requests/CashFlowStatementsRetrieveRequest.cs b/src/Merge.Client/Accounting/CashFlowStatements/Requests/CashFlowStatementsRetrieveRequest.cs index 4ee951a7..56976943 100644 --- a/src/Merge.Client/Accounting/CashFlowStatements/Requests/CashFlowStatementsRetrieveRequest.cs +++ b/src/Merge.Client/Accounting/CashFlowStatements/Requests/CashFlowStatementsRetrieveRequest.cs @@ -1,14 +1,14 @@ namespace Merge.Client.Accounting; -public class CashFlowStatementsRetrieveRequest +public record CashFlowStatementsRetrieveRequest { /// /// Which relations should be returned in expanded form. Multiple relation names should be comma separated without spaces. /// - public string? Expand { get; init; } + public string? Expand { get; set; } /// /// Whether to include the original data Merge fetched from the third-party to produce these models. /// - public bool? IncludeRemoteData { get; init; } + public bool? IncludeRemoteData { get; set; } } diff --git a/src/Merge.Client/Accounting/CompanyInfo/CompanyInfoClient.cs b/src/Merge.Client/Accounting/CompanyInfo/CompanyInfoClient.cs index 58326778..cbf0ce9f 100644 --- a/src/Merge.Client/Accounting/CompanyInfo/CompanyInfoClient.cs +++ b/src/Merge.Client/Accounting/CompanyInfo/CompanyInfoClient.cs @@ -1,6 +1,6 @@ +using System.Net.Http; using System.Text.Json; -using Merge.Client; -using Merge.Client.Accounting; +using Merge.Client.Core; #nullable enable @@ -18,16 +18,21 @@ public CompanyInfoClient(RawClient client) /// /// Returns a list of `CompanyInfo` objects. /// - public async Task ListAsync(CompanyInfoListRequest request) + public async Task ListAsync( + CompanyInfoListRequest request, + RequestOptions? options = null + ) { var _query = new Dictionary() { }; if (request.CreatedAfter != null) { - _query["created_after"] = request.CreatedAfter.Value.ToString("o0"); + _query["created_after"] = request.CreatedAfter.Value.ToString(Constants.DateTimeFormat); } if (request.CreatedBefore != null) { - _query["created_before"] = request.CreatedBefore.Value.ToString("o0"); + _query["created_before"] = request.CreatedBefore.Value.ToString( + Constants.DateTimeFormat + ); } if (request.Cursor != null) { @@ -47,11 +52,15 @@ public async Task ListAsync(CompanyInfoListRequest req } if (request.ModifiedAfter != null) { - _query["modified_after"] = request.ModifiedAfter.Value.ToString("o0"); + _query["modified_after"] = request.ModifiedAfter.Value.ToString( + Constants.DateTimeFormat + ); } if (request.ModifiedBefore != null) { - _query["modified_before"] = request.ModifiedBefore.Value.ToString("o0"); + _query["modified_before"] = request.ModifiedBefore.Value.ToString( + Constants.DateTimeFormat + ); } if (request.PageSize != null) { @@ -64,23 +73,41 @@ public async Task ListAsync(CompanyInfoListRequest req var response = await _client.MakeRequestAsync( new RawClient.JsonApiRequest { + BaseUrl = _client.Options.BaseUrl, Method = HttpMethod.Get, Path = "accounting/v1/company-info", - Query = _query + Query = _query, + Options = options } ); - string responseBody = await response.Raw.Content.ReadAsStringAsync(); - if (response.StatusCode >= 200 && response.StatusCode < 400) + var responseBody = await response.Raw.Content.ReadAsStringAsync(); + if (response.StatusCode is >= 200 and < 400) { - return JsonSerializer.Deserialize(responseBody); + try + { + return JsonUtils.Deserialize(responseBody)!; + } + catch (JsonException e) + { + throw new MergeException("Failed to deserialize response", e); + } } - throw new Exception(responseBody); + + throw new MergeApiException( + $"Error with status code {response.StatusCode}", + response.StatusCode, + JsonUtils.Deserialize(responseBody) + ); } /// /// Returns a `CompanyInfo` object with the given `id`. /// - public async Task RetrieveAsync(string id, CompanyInfoRetrieveRequest request) + public async Task RetrieveAsync( + string id, + CompanyInfoRetrieveRequest request, + RequestOptions? options = null + ) { var _query = new Dictionary() { }; if (request.Expand != null) @@ -94,16 +121,30 @@ public async Task RetrieveAsync(string id, CompanyInfoRetrieveReque var response = await _client.MakeRequestAsync( new RawClient.JsonApiRequest { + BaseUrl = _client.Options.BaseUrl, Method = HttpMethod.Get, Path = $"accounting/v1/company-info/{id}", - Query = _query + Query = _query, + Options = options } ); - string responseBody = await response.Raw.Content.ReadAsStringAsync(); - if (response.StatusCode >= 200 && response.StatusCode < 400) + var responseBody = await response.Raw.Content.ReadAsStringAsync(); + if (response.StatusCode is >= 200 and < 400) { - return JsonSerializer.Deserialize(responseBody); + try + { + return JsonUtils.Deserialize(responseBody)!; + } + catch (JsonException e) + { + throw new MergeException("Failed to deserialize response", e); + } } - throw new Exception(responseBody); + + throw new MergeApiException( + $"Error with status code {response.StatusCode}", + response.StatusCode, + JsonUtils.Deserialize(responseBody) + ); } } diff --git a/src/Merge.Client/Accounting/CompanyInfo/Requests/CompanyInfoListRequest.cs b/src/Merge.Client/Accounting/CompanyInfo/Requests/CompanyInfoListRequest.cs index d65f3fc8..8f4da390 100644 --- a/src/Merge.Client/Accounting/CompanyInfo/Requests/CompanyInfoListRequest.cs +++ b/src/Merge.Client/Accounting/CompanyInfo/Requests/CompanyInfoListRequest.cs @@ -1,58 +1,54 @@ -using Merge.Client.Accounting; - -#nullable enable - namespace Merge.Client.Accounting; -public class CompanyInfoListRequest +public record CompanyInfoListRequest { /// /// If provided, will only return objects created after this datetime. /// - public DateTime? CreatedAfter { get; init; } + public DateTime? CreatedAfter { get; set; } /// /// If provided, will only return objects created before this datetime. /// - public DateTime? CreatedBefore { get; init; } + public DateTime? CreatedBefore { get; set; } /// /// The pagination cursor value. /// - public string? Cursor { get; init; } + public string? Cursor { get; set; } /// /// Which relations should be returned in expanded form. Multiple relation names should be comma separated without spaces. /// - public CompanyInfoListRequestExpand? Expand { get; init; } + public CompanyInfoListRequestExpand? Expand { get; set; } /// /// Whether to include data that was marked as deleted by third party webhooks. /// - public bool? IncludeDeletedData { get; init; } + public bool? IncludeDeletedData { get; set; } /// /// Whether to include the original data Merge fetched from the third-party to produce these models. /// - public bool? IncludeRemoteData { get; init; } + public bool? IncludeRemoteData { get; set; } /// /// If provided, only objects synced by Merge after this date time will be returned. /// - public DateTime? ModifiedAfter { get; init; } + public DateTime? ModifiedAfter { get; set; } /// /// If provided, only objects synced by Merge before this date time will be returned. /// - public DateTime? ModifiedBefore { get; init; } + public DateTime? ModifiedBefore { get; set; } /// /// Number of results to return per page. /// - public int? PageSize { get; init; } + public int? PageSize { get; set; } /// /// The API provider's ID for the given object. /// - public string? RemoteId { get; init; } + public string? RemoteId { get; set; } } diff --git a/src/Merge.Client/Accounting/CompanyInfo/Requests/CompanyInfoRetrieveRequest.cs b/src/Merge.Client/Accounting/CompanyInfo/Requests/CompanyInfoRetrieveRequest.cs index 84618676..698a34db 100644 --- a/src/Merge.Client/Accounting/CompanyInfo/Requests/CompanyInfoRetrieveRequest.cs +++ b/src/Merge.Client/Accounting/CompanyInfo/Requests/CompanyInfoRetrieveRequest.cs @@ -1,18 +1,14 @@ -using Merge.Client.Accounting; - -#nullable enable - namespace Merge.Client.Accounting; -public class CompanyInfoRetrieveRequest +public record CompanyInfoRetrieveRequest { /// /// Which relations should be returned in expanded form. Multiple relation names should be comma separated without spaces. /// - public CompanyInfoRetrieveRequestExpand? Expand { get; init; } + public CompanyInfoRetrieveRequestExpand? Expand { get; set; } /// /// Whether to include the original data Merge fetched from the third-party to produce these models. /// - public bool? IncludeRemoteData { get; init; } + public bool? IncludeRemoteData { get; set; } } diff --git a/src/Merge.Client/Accounting/CompanyInfo/Types/CompanyInfoListRequestExpand.cs b/src/Merge.Client/Accounting/CompanyInfo/Types/CompanyInfoListRequestExpand.cs index 6e3e66ef..82a9ded7 100644 --- a/src/Merge.Client/Accounting/CompanyInfo/Types/CompanyInfoListRequestExpand.cs +++ b/src/Merge.Client/Accounting/CompanyInfo/Types/CompanyInfoListRequestExpand.cs @@ -1,6 +1,5 @@ using System.Runtime.Serialization; using System.Text.Json.Serialization; -using Merge.Client.Accounting; using Merge.Client.Core; #nullable enable diff --git a/src/Merge.Client/Accounting/CompanyInfo/Types/CompanyInfoRetrieveRequestExpand.cs b/src/Merge.Client/Accounting/CompanyInfo/Types/CompanyInfoRetrieveRequestExpand.cs index 9cc493a4..858c10b8 100644 --- a/src/Merge.Client/Accounting/CompanyInfo/Types/CompanyInfoRetrieveRequestExpand.cs +++ b/src/Merge.Client/Accounting/CompanyInfo/Types/CompanyInfoRetrieveRequestExpand.cs @@ -1,6 +1,5 @@ using System.Runtime.Serialization; using System.Text.Json.Serialization; -using Merge.Client.Accounting; using Merge.Client.Core; #nullable enable diff --git a/src/Merge.Client/Accounting/Contacts/ContactsClient.cs b/src/Merge.Client/Accounting/Contacts/ContactsClient.cs index cdd91a5e..d0a3e04e 100644 --- a/src/Merge.Client/Accounting/Contacts/ContactsClient.cs +++ b/src/Merge.Client/Accounting/Contacts/ContactsClient.cs @@ -1,6 +1,6 @@ +using System.Net.Http; using System.Text.Json; -using Merge.Client; -using Merge.Client.Accounting; +using Merge.Client.Core; #nullable enable @@ -18,7 +18,10 @@ public ContactsClient(RawClient client) /// /// Returns a list of `Contact` objects. /// - public async Task ListAsync(ContactsListRequest request) + public async Task ListAsync( + ContactsListRequest request, + RequestOptions? options = null + ) { var _query = new Dictionary() { }; if (request.CompanyId != null) @@ -27,11 +30,13 @@ public async Task ListAsync(ContactsListRequest request) } if (request.CreatedAfter != null) { - _query["created_after"] = request.CreatedAfter.Value.ToString("o0"); + _query["created_after"] = request.CreatedAfter.Value.ToString(Constants.DateTimeFormat); } if (request.CreatedBefore != null) { - _query["created_before"] = request.CreatedBefore.Value.ToString("o0"); + _query["created_before"] = request.CreatedBefore.Value.ToString( + Constants.DateTimeFormat + ); } if (request.Cursor != null) { @@ -59,11 +64,15 @@ public async Task ListAsync(ContactsListRequest request) } if (request.ModifiedAfter != null) { - _query["modified_after"] = request.ModifiedAfter.Value.ToString("o0"); + _query["modified_after"] = request.ModifiedAfter.Value.ToString( + Constants.DateTimeFormat + ); } if (request.ModifiedBefore != null) { - _query["modified_before"] = request.ModifiedBefore.Value.ToString("o0"); + _query["modified_before"] = request.ModifiedBefore.Value.ToString( + Constants.DateTimeFormat + ); } if (request.PageSize != null) { @@ -84,23 +93,40 @@ public async Task ListAsync(ContactsListRequest request) var response = await _client.MakeRequestAsync( new RawClient.JsonApiRequest { + BaseUrl = _client.Options.BaseUrl, Method = HttpMethod.Get, Path = "accounting/v1/contacts", - Query = _query + Query = _query, + Options = options } ); - string responseBody = await response.Raw.Content.ReadAsStringAsync(); - if (response.StatusCode >= 200 && response.StatusCode < 400) + var responseBody = await response.Raw.Content.ReadAsStringAsync(); + if (response.StatusCode is >= 200 and < 400) { - return JsonSerializer.Deserialize(responseBody); + try + { + return JsonUtils.Deserialize(responseBody)!; + } + catch (JsonException e) + { + throw new MergeException("Failed to deserialize response", e); + } } - throw new Exception(responseBody); + + throw new MergeApiException( + $"Error with status code {response.StatusCode}", + response.StatusCode, + JsonUtils.Deserialize(responseBody) + ); } /// /// Creates a `Contact` object with the given values. /// - public async Task CreateAsync(ContactEndpointRequest request) + public async Task CreateAsync( + ContactEndpointRequest request, + RequestOptions? options = null + ) { var _query = new Dictionary() { }; if (request.IsDebugMode != null) @@ -114,23 +140,41 @@ public async Task CreateAsync(ContactEndpointRequest request) var response = await _client.MakeRequestAsync( new RawClient.JsonApiRequest { + BaseUrl = _client.Options.BaseUrl, Method = HttpMethod.Post, Path = "accounting/v1/contacts", - Query = _query + Query = _query, + Options = options } ); - string responseBody = await response.Raw.Content.ReadAsStringAsync(); - if (response.StatusCode >= 200 && response.StatusCode < 400) + var responseBody = await response.Raw.Content.ReadAsStringAsync(); + if (response.StatusCode is >= 200 and < 400) { - return JsonSerializer.Deserialize(responseBody); + try + { + return JsonUtils.Deserialize(responseBody)!; + } + catch (JsonException e) + { + throw new MergeException("Failed to deserialize response", e); + } } - throw new Exception(responseBody); + + throw new MergeApiException( + $"Error with status code {response.StatusCode}", + response.StatusCode, + JsonUtils.Deserialize(responseBody) + ); } /// /// Returns a `Contact` object with the given `id`. /// - public async Task RetrieveAsync(string id, ContactsRetrieveRequest request) + public async Task RetrieveAsync( + string id, + ContactsRetrieveRequest request, + RequestOptions? options = null + ) { var _query = new Dictionary() { }; if (request.Expand != null) @@ -152,36 +196,64 @@ public async Task RetrieveAsync(string id, ContactsRetrieveRequest requ var response = await _client.MakeRequestAsync( new RawClient.JsonApiRequest { + BaseUrl = _client.Options.BaseUrl, Method = HttpMethod.Get, Path = $"accounting/v1/contacts/{id}", - Query = _query + Query = _query, + Options = options } ); - string responseBody = await response.Raw.Content.ReadAsStringAsync(); - if (response.StatusCode >= 200 && response.StatusCode < 400) + var responseBody = await response.Raw.Content.ReadAsStringAsync(); + if (response.StatusCode is >= 200 and < 400) { - return JsonSerializer.Deserialize(responseBody); + try + { + return JsonUtils.Deserialize(responseBody)!; + } + catch (JsonException e) + { + throw new MergeException("Failed to deserialize response", e); + } } - throw new Exception(responseBody); + + throw new MergeApiException( + $"Error with status code {response.StatusCode}", + response.StatusCode, + JsonUtils.Deserialize(responseBody) + ); } /// /// Returns metadata for `Contact` POSTs. /// - public async Task MetaPostRetrieveAsync() + public async Task MetaPostRetrieveAsync(RequestOptions? options = null) { var response = await _client.MakeRequestAsync( new RawClient.JsonApiRequest { + BaseUrl = _client.Options.BaseUrl, Method = HttpMethod.Get, - Path = "accounting/v1/contacts/meta/post" + Path = "accounting/v1/contacts/meta/post", + Options = options } ); - string responseBody = await response.Raw.Content.ReadAsStringAsync(); - if (response.StatusCode >= 200 && response.StatusCode < 400) + var responseBody = await response.Raw.Content.ReadAsStringAsync(); + if (response.StatusCode is >= 200 and < 400) { - return JsonSerializer.Deserialize(responseBody); + try + { + return JsonUtils.Deserialize(responseBody)!; + } + catch (JsonException e) + { + throw new MergeException("Failed to deserialize response", e); + } } - throw new Exception(responseBody); + + throw new MergeApiException( + $"Error with status code {response.StatusCode}", + response.StatusCode, + JsonUtils.Deserialize(responseBody) + ); } } diff --git a/src/Merge.Client/Accounting/Contacts/Requests/ContactEndpointRequest.cs b/src/Merge.Client/Accounting/Contacts/Requests/ContactEndpointRequest.cs index 51da2002..8d677c4c 100644 --- a/src/Merge.Client/Accounting/Contacts/Requests/ContactEndpointRequest.cs +++ b/src/Merge.Client/Accounting/Contacts/Requests/ContactEndpointRequest.cs @@ -1,20 +1,16 @@ -using Merge.Client.Accounting; - -#nullable enable - namespace Merge.Client.Accounting; -public class ContactEndpointRequest +public record ContactEndpointRequest { /// /// Whether to include debug fields (such as log file links) in the response. /// - public bool? IsDebugMode { get; init; } + public bool? IsDebugMode { get; set; } /// /// Whether or not third-party updates should be run asynchronously. /// - public bool? RunAsync { get; init; } + public bool? RunAsync { get; set; } - public ContactRequest Model { get; init; } + public required ContactRequest Model { get; set; } } diff --git a/src/Merge.Client/Accounting/Contacts/Requests/ContactsListRequest.cs b/src/Merge.Client/Accounting/Contacts/Requests/ContactsListRequest.cs index 144c84d8..92d6b940 100644 --- a/src/Merge.Client/Accounting/Contacts/Requests/ContactsListRequest.cs +++ b/src/Merge.Client/Accounting/Contacts/Requests/ContactsListRequest.cs @@ -1,83 +1,79 @@ -using Merge.Client.Accounting; - -#nullable enable - namespace Merge.Client.Accounting; -public class ContactsListRequest +public record ContactsListRequest { /// /// If provided, will only return contacts for this company. /// - public string? CompanyId { get; init; } + public string? CompanyId { get; set; } /// /// If provided, will only return objects created after this datetime. /// - public DateTime? CreatedAfter { get; init; } + public DateTime? CreatedAfter { get; set; } /// /// If provided, will only return objects created before this datetime. /// - public DateTime? CreatedBefore { get; init; } + public DateTime? CreatedBefore { get; set; } /// /// The pagination cursor value. /// - public string? Cursor { get; init; } + public string? Cursor { get; set; } /// /// Which relations should be returned in expanded form. Multiple relation names should be comma separated without spaces. /// - public ContactsListRequestExpand? Expand { get; init; } + public ContactsListRequestExpand? Expand { get; set; } /// /// Whether to include data that was marked as deleted by third party webhooks. /// - public bool? IncludeDeletedData { get; init; } + public bool? IncludeDeletedData { get; set; } /// /// Whether to include the original data Merge fetched from the third-party to produce these models. /// - public bool? IncludeRemoteData { get; init; } + public bool? IncludeRemoteData { get; set; } /// /// If provided, will only return Contacts that are denoted as customers. /// - public string? IsCustomer { get; init; } + public string? IsCustomer { get; set; } /// /// If provided, will only return Contacts that are denoted as suppliers. /// - public string? IsSupplier { get; init; } + public string? IsSupplier { get; set; } /// /// If provided, only objects synced by Merge after this date time will be returned. /// - public DateTime? ModifiedAfter { get; init; } + public DateTime? ModifiedAfter { get; set; } /// /// If provided, only objects synced by Merge before this date time will be returned. /// - public DateTime? ModifiedBefore { get; init; } + public DateTime? ModifiedBefore { get; set; } /// /// Number of results to return per page. /// - public int? PageSize { get; init; } + public int? PageSize { get; set; } /// /// Deprecated. Use show_enum_origins. /// - public string? RemoteFields { get; init; } + public string? RemoteFields { get; set; } /// /// The API provider's ID for the given object. /// - public string? RemoteId { get; init; } + public string? RemoteId { get; set; } /// /// A comma separated list of enum field names for which you'd like the original values to be returned, instead of Merge's normalized enum values. [Learn more](https://help.merge.dev/en/articles/8950958-show_enum_origins-query-parameter) /// - public string? ShowEnumOrigins { get; init; } + public string? ShowEnumOrigins { get; set; } } diff --git a/src/Merge.Client/Accounting/Contacts/Requests/ContactsRetrieveRequest.cs b/src/Merge.Client/Accounting/Contacts/Requests/ContactsRetrieveRequest.cs index 70954d74..bccc3190 100644 --- a/src/Merge.Client/Accounting/Contacts/Requests/ContactsRetrieveRequest.cs +++ b/src/Merge.Client/Accounting/Contacts/Requests/ContactsRetrieveRequest.cs @@ -1,28 +1,24 @@ -using Merge.Client.Accounting; - -#nullable enable - namespace Merge.Client.Accounting; -public class ContactsRetrieveRequest +public record ContactsRetrieveRequest { /// /// Which relations should be returned in expanded form. Multiple relation names should be comma separated without spaces. /// - public ContactsRetrieveRequestExpand? Expand { get; init; } + public ContactsRetrieveRequestExpand? Expand { get; set; } /// /// Whether to include the original data Merge fetched from the third-party to produce these models. /// - public bool? IncludeRemoteData { get; init; } + public bool? IncludeRemoteData { get; set; } /// /// Deprecated. Use show_enum_origins. /// - public string? RemoteFields { get; init; } + public string? RemoteFields { get; set; } /// /// A comma separated list of enum field names for which you'd like the original values to be returned, instead of Merge's normalized enum values. [Learn more](https://help.merge.dev/en/articles/8950958-show_enum_origins-query-parameter) /// - public string? ShowEnumOrigins { get; init; } + public string? ShowEnumOrigins { get; set; } } diff --git a/src/Merge.Client/Accounting/Contacts/Types/ContactsListRequestExpand.cs b/src/Merge.Client/Accounting/Contacts/Types/ContactsListRequestExpand.cs index 189bc367..9e41ee83 100644 --- a/src/Merge.Client/Accounting/Contacts/Types/ContactsListRequestExpand.cs +++ b/src/Merge.Client/Accounting/Contacts/Types/ContactsListRequestExpand.cs @@ -1,6 +1,5 @@ using System.Runtime.Serialization; using System.Text.Json.Serialization; -using Merge.Client.Accounting; using Merge.Client.Core; #nullable enable diff --git a/src/Merge.Client/Accounting/Contacts/Types/ContactsRetrieveRequestExpand.cs b/src/Merge.Client/Accounting/Contacts/Types/ContactsRetrieveRequestExpand.cs index 6d3e7a61..563e7d97 100644 --- a/src/Merge.Client/Accounting/Contacts/Types/ContactsRetrieveRequestExpand.cs +++ b/src/Merge.Client/Accounting/Contacts/Types/ContactsRetrieveRequestExpand.cs @@ -1,6 +1,5 @@ using System.Runtime.Serialization; using System.Text.Json.Serialization; -using Merge.Client.Accounting; using Merge.Client.Core; #nullable enable diff --git a/src/Merge.Client/Accounting/CreditNotes/CreditNotesClient.cs b/src/Merge.Client/Accounting/CreditNotes/CreditNotesClient.cs index bf4b8e46..a6a31747 100644 --- a/src/Merge.Client/Accounting/CreditNotes/CreditNotesClient.cs +++ b/src/Merge.Client/Accounting/CreditNotes/CreditNotesClient.cs @@ -1,6 +1,6 @@ +using System.Net.Http; using System.Text.Json; -using Merge.Client; -using Merge.Client.Accounting; +using Merge.Client.Core; #nullable enable @@ -18,7 +18,10 @@ public CreditNotesClient(RawClient client) /// /// Returns a list of `CreditNote` objects. /// - public async Task ListAsync(CreditNotesListRequest request) + public async Task ListAsync( + CreditNotesListRequest request, + RequestOptions? options = null + ) { var _query = new Dictionary() { }; if (request.CompanyId != null) @@ -27,11 +30,13 @@ public async Task ListAsync(CreditNotesListRequest requ } if (request.CreatedAfter != null) { - _query["created_after"] = request.CreatedAfter.Value.ToString("o0"); + _query["created_after"] = request.CreatedAfter.Value.ToString(Constants.DateTimeFormat); } if (request.CreatedBefore != null) { - _query["created_before"] = request.CreatedBefore.Value.ToString("o0"); + _query["created_before"] = request.CreatedBefore.Value.ToString( + Constants.DateTimeFormat + ); } if (request.Cursor != null) { @@ -51,11 +56,15 @@ public async Task ListAsync(CreditNotesListRequest requ } if (request.ModifiedAfter != null) { - _query["modified_after"] = request.ModifiedAfter.Value.ToString("o0"); + _query["modified_after"] = request.ModifiedAfter.Value.ToString( + Constants.DateTimeFormat + ); } if (request.ModifiedBefore != null) { - _query["modified_before"] = request.ModifiedBefore.Value.ToString("o0"); + _query["modified_before"] = request.ModifiedBefore.Value.ToString( + Constants.DateTimeFormat + ); } if (request.PageSize != null) { @@ -75,32 +84,54 @@ public async Task ListAsync(CreditNotesListRequest requ } if (request.TransactionDateAfter != null) { - _query["transaction_date_after"] = request.TransactionDateAfter.Value.ToString("o0"); + _query["transaction_date_after"] = request.TransactionDateAfter.Value.ToString( + Constants.DateTimeFormat + ); } if (request.TransactionDateBefore != null) { - _query["transaction_date_before"] = request.TransactionDateBefore.Value.ToString("o0"); + _query["transaction_date_before"] = request.TransactionDateBefore.Value.ToString( + Constants.DateTimeFormat + ); } var response = await _client.MakeRequestAsync( new RawClient.JsonApiRequest { + BaseUrl = _client.Options.BaseUrl, Method = HttpMethod.Get, Path = "accounting/v1/credit-notes", - Query = _query + Query = _query, + Options = options } ); - string responseBody = await response.Raw.Content.ReadAsStringAsync(); - if (response.StatusCode >= 200 && response.StatusCode < 400) + var responseBody = await response.Raw.Content.ReadAsStringAsync(); + if (response.StatusCode is >= 200 and < 400) { - return JsonSerializer.Deserialize(responseBody); + try + { + return JsonUtils.Deserialize(responseBody)!; + } + catch (JsonException e) + { + throw new MergeException("Failed to deserialize response", e); + } } - throw new Exception(responseBody); + + throw new MergeApiException( + $"Error with status code {response.StatusCode}", + response.StatusCode, + JsonUtils.Deserialize(responseBody) + ); } /// /// Returns a `CreditNote` object with the given `id`. /// - public async Task RetrieveAsync(string id, CreditNotesRetrieveRequest request) + public async Task RetrieveAsync( + string id, + CreditNotesRetrieveRequest request, + RequestOptions? options = null + ) { var _query = new Dictionary() { }; if (request.Expand != null) @@ -122,16 +153,30 @@ public async Task RetrieveAsync(string id, CreditNotesRetrieveReques var response = await _client.MakeRequestAsync( new RawClient.JsonApiRequest { + BaseUrl = _client.Options.BaseUrl, Method = HttpMethod.Get, Path = $"accounting/v1/credit-notes/{id}", - Query = _query + Query = _query, + Options = options } ); - string responseBody = await response.Raw.Content.ReadAsStringAsync(); - if (response.StatusCode >= 200 && response.StatusCode < 400) + var responseBody = await response.Raw.Content.ReadAsStringAsync(); + if (response.StatusCode is >= 200 and < 400) { - return JsonSerializer.Deserialize(responseBody); + try + { + return JsonUtils.Deserialize(responseBody)!; + } + catch (JsonException e) + { + throw new MergeException("Failed to deserialize response", e); + } } - throw new Exception(responseBody); + + throw new MergeApiException( + $"Error with status code {response.StatusCode}", + response.StatusCode, + JsonUtils.Deserialize(responseBody) + ); } } diff --git a/src/Merge.Client/Accounting/CreditNotes/Requests/CreditNotesListRequest.cs b/src/Merge.Client/Accounting/CreditNotes/Requests/CreditNotesListRequest.cs index 3601abcb..13f9f8e9 100644 --- a/src/Merge.Client/Accounting/CreditNotes/Requests/CreditNotesListRequest.cs +++ b/src/Merge.Client/Accounting/CreditNotes/Requests/CreditNotesListRequest.cs @@ -1,83 +1,79 @@ -using Merge.Client.Accounting; - -#nullable enable - namespace Merge.Client.Accounting; -public class CreditNotesListRequest +public record CreditNotesListRequest { /// /// If provided, will only return credit notes for this company. /// - public string? CompanyId { get; init; } + public string? CompanyId { get; set; } /// /// If provided, will only return objects created after this datetime. /// - public DateTime? CreatedAfter { get; init; } + public DateTime? CreatedAfter { get; set; } /// /// If provided, will only return objects created before this datetime. /// - public DateTime? CreatedBefore { get; init; } + public DateTime? CreatedBefore { get; set; } /// /// The pagination cursor value. /// - public string? Cursor { get; init; } + public string? Cursor { get; set; } /// /// Which relations should be returned in expanded form. Multiple relation names should be comma separated without spaces. /// - public CreditNotesListRequestExpand? Expand { get; init; } + public CreditNotesListRequestExpand? Expand { get; set; } /// /// Whether to include data that was marked as deleted by third party webhooks. /// - public bool? IncludeDeletedData { get; init; } + public bool? IncludeDeletedData { get; set; } /// /// Whether to include the original data Merge fetched from the third-party to produce these models. /// - public bool? IncludeRemoteData { get; init; } + public bool? IncludeRemoteData { get; set; } /// /// If provided, only objects synced by Merge after this date time will be returned. /// - public DateTime? ModifiedAfter { get; init; } + public DateTime? ModifiedAfter { get; set; } /// /// If provided, only objects synced by Merge before this date time will be returned. /// - public DateTime? ModifiedBefore { get; init; } + public DateTime? ModifiedBefore { get; set; } /// /// Number of results to return per page. /// - public int? PageSize { get; init; } + public int? PageSize { get; set; } /// /// Deprecated. Use show_enum_origins. /// - public CreditNotesListRequestRemoteFields? RemoteFields { get; init; } + public CreditNotesListRequestRemoteFields? RemoteFields { get; set; } /// /// The API provider's ID for the given object. /// - public string? RemoteId { get; init; } + public string? RemoteId { get; set; } /// /// A comma separated list of enum field names for which you'd like the original values to be returned, instead of Merge's normalized enum values. [Learn more](https://help.merge.dev/en/articles/8950958-show_enum_origins-query-parameter) /// - public CreditNotesListRequestShowEnumOrigins? ShowEnumOrigins { get; init; } + public CreditNotesListRequestShowEnumOrigins? ShowEnumOrigins { get; set; } /// /// If provided, will only return objects created after this datetime. /// - public DateTime? TransactionDateAfter { get; init; } + public DateTime? TransactionDateAfter { get; set; } /// /// If provided, will only return objects created before this datetime. /// - public DateTime? TransactionDateBefore { get; init; } + public DateTime? TransactionDateBefore { get; set; } } diff --git a/src/Merge.Client/Accounting/CreditNotes/Requests/CreditNotesRetrieveRequest.cs b/src/Merge.Client/Accounting/CreditNotes/Requests/CreditNotesRetrieveRequest.cs index 84b06fd4..9024d37d 100644 --- a/src/Merge.Client/Accounting/CreditNotes/Requests/CreditNotesRetrieveRequest.cs +++ b/src/Merge.Client/Accounting/CreditNotes/Requests/CreditNotesRetrieveRequest.cs @@ -1,28 +1,24 @@ -using Merge.Client.Accounting; - -#nullable enable - namespace Merge.Client.Accounting; -public class CreditNotesRetrieveRequest +public record CreditNotesRetrieveRequest { /// /// Which relations should be returned in expanded form. Multiple relation names should be comma separated without spaces. /// - public CreditNotesRetrieveRequestExpand? Expand { get; init; } + public CreditNotesRetrieveRequestExpand? Expand { get; set; } /// /// Whether to include the original data Merge fetched from the third-party to produce these models. /// - public bool? IncludeRemoteData { get; init; } + public bool? IncludeRemoteData { get; set; } /// /// Deprecated. Use show_enum_origins. /// - public CreditNotesRetrieveRequestRemoteFields? RemoteFields { get; init; } + public CreditNotesRetrieveRequestRemoteFields? RemoteFields { get; set; } /// /// A comma separated list of enum field names for which you'd like the original values to be returned, instead of Merge's normalized enum values. [Learn more](https://help.merge.dev/en/articles/8950958-show_enum_origins-query-parameter) /// - public CreditNotesRetrieveRequestShowEnumOrigins? ShowEnumOrigins { get; init; } + public CreditNotesRetrieveRequestShowEnumOrigins? ShowEnumOrigins { get; set; } } diff --git a/src/Merge.Client/Accounting/CreditNotes/Types/CreditNotesListRequestExpand.cs b/src/Merge.Client/Accounting/CreditNotes/Types/CreditNotesListRequestExpand.cs index f17300c7..674c3b5d 100644 --- a/src/Merge.Client/Accounting/CreditNotes/Types/CreditNotesListRequestExpand.cs +++ b/src/Merge.Client/Accounting/CreditNotes/Types/CreditNotesListRequestExpand.cs @@ -1,6 +1,5 @@ using System.Runtime.Serialization; using System.Text.Json.Serialization; -using Merge.Client.Accounting; using Merge.Client.Core; #nullable enable diff --git a/src/Merge.Client/Accounting/CreditNotes/Types/CreditNotesListRequestRemoteFields.cs b/src/Merge.Client/Accounting/CreditNotes/Types/CreditNotesListRequestRemoteFields.cs index 07662ba5..004d2d2e 100644 --- a/src/Merge.Client/Accounting/CreditNotes/Types/CreditNotesListRequestRemoteFields.cs +++ b/src/Merge.Client/Accounting/CreditNotes/Types/CreditNotesListRequestRemoteFields.cs @@ -1,6 +1,5 @@ using System.Runtime.Serialization; using System.Text.Json.Serialization; -using Merge.Client.Accounting; using Merge.Client.Core; #nullable enable diff --git a/src/Merge.Client/Accounting/CreditNotes/Types/CreditNotesListRequestShowEnumOrigins.cs b/src/Merge.Client/Accounting/CreditNotes/Types/CreditNotesListRequestShowEnumOrigins.cs index 85ec1d73..b19739d4 100644 --- a/src/Merge.Client/Accounting/CreditNotes/Types/CreditNotesListRequestShowEnumOrigins.cs +++ b/src/Merge.Client/Accounting/CreditNotes/Types/CreditNotesListRequestShowEnumOrigins.cs @@ -1,6 +1,5 @@ using System.Runtime.Serialization; using System.Text.Json.Serialization; -using Merge.Client.Accounting; using Merge.Client.Core; #nullable enable diff --git a/src/Merge.Client/Accounting/CreditNotes/Types/CreditNotesRetrieveRequestExpand.cs b/src/Merge.Client/Accounting/CreditNotes/Types/CreditNotesRetrieveRequestExpand.cs index e1ded587..638ac392 100644 --- a/src/Merge.Client/Accounting/CreditNotes/Types/CreditNotesRetrieveRequestExpand.cs +++ b/src/Merge.Client/Accounting/CreditNotes/Types/CreditNotesRetrieveRequestExpand.cs @@ -1,6 +1,5 @@ using System.Runtime.Serialization; using System.Text.Json.Serialization; -using Merge.Client.Accounting; using Merge.Client.Core; #nullable enable diff --git a/src/Merge.Client/Accounting/CreditNotes/Types/CreditNotesRetrieveRequestRemoteFields.cs b/src/Merge.Client/Accounting/CreditNotes/Types/CreditNotesRetrieveRequestRemoteFields.cs index 1d7e7f12..71ea6f0c 100644 --- a/src/Merge.Client/Accounting/CreditNotes/Types/CreditNotesRetrieveRequestRemoteFields.cs +++ b/src/Merge.Client/Accounting/CreditNotes/Types/CreditNotesRetrieveRequestRemoteFields.cs @@ -1,6 +1,5 @@ using System.Runtime.Serialization; using System.Text.Json.Serialization; -using Merge.Client.Accounting; using Merge.Client.Core; #nullable enable diff --git a/src/Merge.Client/Accounting/CreditNotes/Types/CreditNotesRetrieveRequestShowEnumOrigins.cs b/src/Merge.Client/Accounting/CreditNotes/Types/CreditNotesRetrieveRequestShowEnumOrigins.cs index 05f76a49..f6c607c4 100644 --- a/src/Merge.Client/Accounting/CreditNotes/Types/CreditNotesRetrieveRequestShowEnumOrigins.cs +++ b/src/Merge.Client/Accounting/CreditNotes/Types/CreditNotesRetrieveRequestShowEnumOrigins.cs @@ -1,6 +1,5 @@ using System.Runtime.Serialization; using System.Text.Json.Serialization; -using Merge.Client.Accounting; using Merge.Client.Core; #nullable enable diff --git a/src/Merge.Client/Accounting/DeleteAccount/DeleteAccountClient.cs b/src/Merge.Client/Accounting/DeleteAccount/DeleteAccountClient.cs index 62eae1ab..abe48d90 100644 --- a/src/Merge.Client/Accounting/DeleteAccount/DeleteAccountClient.cs +++ b/src/Merge.Client/Accounting/DeleteAccount/DeleteAccountClient.cs @@ -1,4 +1,5 @@ -using Merge.Client; +using System.Net.Http; +using Merge.Client.Core; #nullable enable @@ -16,14 +17,26 @@ public DeleteAccountClient(RawClient client) /// /// Delete a linked account. /// - public async void DeleteAsync() + public async Task DeleteAsync(RequestOptions? options = null) { var response = await _client.MakeRequestAsync( new RawClient.JsonApiRequest { + BaseUrl = _client.Options.BaseUrl, Method = HttpMethod.Post, - Path = "accounting/v1/delete-account" + Path = "accounting/v1/delete-account", + Options = options } ); + if (response.StatusCode is >= 200 and < 400) + { + return; + } + var responseBody = await response.Raw.Content.ReadAsStringAsync(); + throw new MergeApiException( + $"Error with status code {response.StatusCode}", + response.StatusCode, + JsonUtils.Deserialize(responseBody) + ); } } diff --git a/src/Merge.Client/Accounting/Expenses/ExpensesClient.cs b/src/Merge.Client/Accounting/Expenses/ExpensesClient.cs index ade4e39e..ded67934 100644 --- a/src/Merge.Client/Accounting/Expenses/ExpensesClient.cs +++ b/src/Merge.Client/Accounting/Expenses/ExpensesClient.cs @@ -1,6 +1,6 @@ +using System.Net.Http; using System.Text.Json; -using Merge.Client; -using Merge.Client.Accounting; +using Merge.Client.Core; #nullable enable @@ -18,7 +18,10 @@ public ExpensesClient(RawClient client) /// /// Returns a list of `Expense` objects. /// - public async Task ListAsync(ExpensesListRequest request) + public async Task ListAsync( + ExpensesListRequest request, + RequestOptions? options = null + ) { var _query = new Dictionary() { }; if (request.CompanyId != null) @@ -27,11 +30,13 @@ public async Task ListAsync(ExpensesListRequest request) } if (request.CreatedAfter != null) { - _query["created_after"] = request.CreatedAfter.Value.ToString("o0"); + _query["created_after"] = request.CreatedAfter.Value.ToString(Constants.DateTimeFormat); } if (request.CreatedBefore != null) { - _query["created_before"] = request.CreatedBefore.Value.ToString("o0"); + _query["created_before"] = request.CreatedBefore.Value.ToString( + Constants.DateTimeFormat + ); } if (request.Cursor != null) { @@ -51,11 +56,15 @@ public async Task ListAsync(ExpensesListRequest request) } if (request.ModifiedAfter != null) { - _query["modified_after"] = request.ModifiedAfter.Value.ToString("o0"); + _query["modified_after"] = request.ModifiedAfter.Value.ToString( + Constants.DateTimeFormat + ); } if (request.ModifiedBefore != null) { - _query["modified_before"] = request.ModifiedBefore.Value.ToString("o0"); + _query["modified_before"] = request.ModifiedBefore.Value.ToString( + Constants.DateTimeFormat + ); } if (request.PageSize != null) { @@ -67,32 +76,53 @@ public async Task ListAsync(ExpensesListRequest request) } if (request.TransactionDateAfter != null) { - _query["transaction_date_after"] = request.TransactionDateAfter.Value.ToString("o0"); + _query["transaction_date_after"] = request.TransactionDateAfter.Value.ToString( + Constants.DateTimeFormat + ); } if (request.TransactionDateBefore != null) { - _query["transaction_date_before"] = request.TransactionDateBefore.Value.ToString("o0"); + _query["transaction_date_before"] = request.TransactionDateBefore.Value.ToString( + Constants.DateTimeFormat + ); } var response = await _client.MakeRequestAsync( new RawClient.JsonApiRequest { + BaseUrl = _client.Options.BaseUrl, Method = HttpMethod.Get, Path = "accounting/v1/expenses", - Query = _query + Query = _query, + Options = options } ); - string responseBody = await response.Raw.Content.ReadAsStringAsync(); - if (response.StatusCode >= 200 && response.StatusCode < 400) + var responseBody = await response.Raw.Content.ReadAsStringAsync(); + if (response.StatusCode is >= 200 and < 400) { - return JsonSerializer.Deserialize(responseBody); + try + { + return JsonUtils.Deserialize(responseBody)!; + } + catch (JsonException e) + { + throw new MergeException("Failed to deserialize response", e); + } } - throw new Exception(responseBody); + + throw new MergeApiException( + $"Error with status code {response.StatusCode}", + response.StatusCode, + JsonUtils.Deserialize(responseBody) + ); } /// /// Creates an `Expense` object with the given values. /// - public async Task CreateAsync(ExpenseEndpointRequest request) + public async Task CreateAsync( + ExpenseEndpointRequest request, + RequestOptions? options = null + ) { var _query = new Dictionary() { }; if (request.IsDebugMode != null) @@ -106,23 +136,41 @@ public async Task CreateAsync(ExpenseEndpointRequest request) var response = await _client.MakeRequestAsync( new RawClient.JsonApiRequest { + BaseUrl = _client.Options.BaseUrl, Method = HttpMethod.Post, Path = "accounting/v1/expenses", - Query = _query + Query = _query, + Options = options } ); - string responseBody = await response.Raw.Content.ReadAsStringAsync(); - if (response.StatusCode >= 200 && response.StatusCode < 400) + var responseBody = await response.Raw.Content.ReadAsStringAsync(); + if (response.StatusCode is >= 200 and < 400) { - return JsonSerializer.Deserialize(responseBody); + try + { + return JsonUtils.Deserialize(responseBody)!; + } + catch (JsonException e) + { + throw new MergeException("Failed to deserialize response", e); + } } - throw new Exception(responseBody); + + throw new MergeApiException( + $"Error with status code {response.StatusCode}", + response.StatusCode, + JsonUtils.Deserialize(responseBody) + ); } /// /// Returns an `Expense` object with the given `id`. /// - public async Task RetrieveAsync(string id, ExpensesRetrieveRequest request) + public async Task RetrieveAsync( + string id, + ExpensesRetrieveRequest request, + RequestOptions? options = null + ) { var _query = new Dictionary() { }; if (request.Expand != null) @@ -136,36 +184,64 @@ public async Task RetrieveAsync(string id, ExpensesRetrieveRequest requ var response = await _client.MakeRequestAsync( new RawClient.JsonApiRequest { + BaseUrl = _client.Options.BaseUrl, Method = HttpMethod.Get, Path = $"accounting/v1/expenses/{id}", - Query = _query + Query = _query, + Options = options } ); - string responseBody = await response.Raw.Content.ReadAsStringAsync(); - if (response.StatusCode >= 200 && response.StatusCode < 400) + var responseBody = await response.Raw.Content.ReadAsStringAsync(); + if (response.StatusCode is >= 200 and < 400) { - return JsonSerializer.Deserialize(responseBody); + try + { + return JsonUtils.Deserialize(responseBody)!; + } + catch (JsonException e) + { + throw new MergeException("Failed to deserialize response", e); + } } - throw new Exception(responseBody); + + throw new MergeApiException( + $"Error with status code {response.StatusCode}", + response.StatusCode, + JsonUtils.Deserialize(responseBody) + ); } /// /// Returns metadata for `Expense` POSTs. /// - public async Task MetaPostRetrieveAsync() + public async Task MetaPostRetrieveAsync(RequestOptions? options = null) { var response = await _client.MakeRequestAsync( new RawClient.JsonApiRequest { + BaseUrl = _client.Options.BaseUrl, Method = HttpMethod.Get, - Path = "accounting/v1/expenses/meta/post" + Path = "accounting/v1/expenses/meta/post", + Options = options } ); - string responseBody = await response.Raw.Content.ReadAsStringAsync(); - if (response.StatusCode >= 200 && response.StatusCode < 400) + var responseBody = await response.Raw.Content.ReadAsStringAsync(); + if (response.StatusCode is >= 200 and < 400) { - return JsonSerializer.Deserialize(responseBody); + try + { + return JsonUtils.Deserialize(responseBody)!; + } + catch (JsonException e) + { + throw new MergeException("Failed to deserialize response", e); + } } - throw new Exception(responseBody); + + throw new MergeApiException( + $"Error with status code {response.StatusCode}", + response.StatusCode, + JsonUtils.Deserialize(responseBody) + ); } } diff --git a/src/Merge.Client/Accounting/Expenses/Requests/ExpenseEndpointRequest.cs b/src/Merge.Client/Accounting/Expenses/Requests/ExpenseEndpointRequest.cs index aa612e7a..5941b40c 100644 --- a/src/Merge.Client/Accounting/Expenses/Requests/ExpenseEndpointRequest.cs +++ b/src/Merge.Client/Accounting/Expenses/Requests/ExpenseEndpointRequest.cs @@ -1,20 +1,16 @@ -using Merge.Client.Accounting; - -#nullable enable - namespace Merge.Client.Accounting; -public class ExpenseEndpointRequest +public record ExpenseEndpointRequest { /// /// Whether to include debug fields (such as log file links) in the response. /// - public bool? IsDebugMode { get; init; } + public bool? IsDebugMode { get; set; } /// /// Whether or not third-party updates should be run asynchronously. /// - public bool? RunAsync { get; init; } + public bool? RunAsync { get; set; } - public ExpenseRequest Model { get; init; } + public required ExpenseRequest Model { get; set; } } diff --git a/src/Merge.Client/Accounting/Expenses/Requests/ExpensesListRequest.cs b/src/Merge.Client/Accounting/Expenses/Requests/ExpensesListRequest.cs index 75e9fb06..8f9dd83e 100644 --- a/src/Merge.Client/Accounting/Expenses/Requests/ExpensesListRequest.cs +++ b/src/Merge.Client/Accounting/Expenses/Requests/ExpensesListRequest.cs @@ -1,73 +1,69 @@ -using Merge.Client.Accounting; - -#nullable enable - namespace Merge.Client.Accounting; -public class ExpensesListRequest +public record ExpensesListRequest { /// /// If provided, will only return expenses for this company. /// - public string? CompanyId { get; init; } + public string? CompanyId { get; set; } /// /// If provided, will only return objects created after this datetime. /// - public DateTime? CreatedAfter { get; init; } + public DateTime? CreatedAfter { get; set; } /// /// If provided, will only return objects created before this datetime. /// - public DateTime? CreatedBefore { get; init; } + public DateTime? CreatedBefore { get; set; } /// /// The pagination cursor value. /// - public string? Cursor { get; init; } + public string? Cursor { get; set; } /// /// Which relations should be returned in expanded form. Multiple relation names should be comma separated without spaces. /// - public ExpensesListRequestExpand? Expand { get; init; } + public ExpensesListRequestExpand? Expand { get; set; } /// /// Whether to include data that was marked as deleted by third party webhooks. /// - public bool? IncludeDeletedData { get; init; } + public bool? IncludeDeletedData { get; set; } /// /// Whether to include the original data Merge fetched from the third-party to produce these models. /// - public bool? IncludeRemoteData { get; init; } + public bool? IncludeRemoteData { get; set; } /// /// If provided, only objects synced by Merge after this date time will be returned. /// - public DateTime? ModifiedAfter { get; init; } + public DateTime? ModifiedAfter { get; set; } /// /// If provided, only objects synced by Merge before this date time will be returned. /// - public DateTime? ModifiedBefore { get; init; } + public DateTime? ModifiedBefore { get; set; } /// /// Number of results to return per page. /// - public int? PageSize { get; init; } + public int? PageSize { get; set; } /// /// The API provider's ID for the given object. /// - public string? RemoteId { get; init; } + public string? RemoteId { get; set; } /// /// If provided, will only return objects created after this datetime. /// - public DateTime? TransactionDateAfter { get; init; } + public DateTime? TransactionDateAfter { get; set; } /// /// If provided, will only return objects created before this datetime. /// - public DateTime? TransactionDateBefore { get; init; } + public DateTime? TransactionDateBefore { get; set; } } diff --git a/src/Merge.Client/Accounting/Expenses/Requests/ExpensesRetrieveRequest.cs b/src/Merge.Client/Accounting/Expenses/Requests/ExpensesRetrieveRequest.cs index 9bb29b74..5e941e55 100644 --- a/src/Merge.Client/Accounting/Expenses/Requests/ExpensesRetrieveRequest.cs +++ b/src/Merge.Client/Accounting/Expenses/Requests/ExpensesRetrieveRequest.cs @@ -1,18 +1,14 @@ -using Merge.Client.Accounting; - -#nullable enable - namespace Merge.Client.Accounting; -public class ExpensesRetrieveRequest +public record ExpensesRetrieveRequest { /// /// Which relations should be returned in expanded form. Multiple relation names should be comma separated without spaces. /// - public ExpensesRetrieveRequestExpand? Expand { get; init; } + public ExpensesRetrieveRequestExpand? Expand { get; set; } /// /// Whether to include the original data Merge fetched from the third-party to produce these models. /// - public bool? IncludeRemoteData { get; init; } + public bool? IncludeRemoteData { get; set; } } diff --git a/src/Merge.Client/Accounting/Expenses/Types/ExpensesListRequestExpand.cs b/src/Merge.Client/Accounting/Expenses/Types/ExpensesListRequestExpand.cs index 66db7711..c39b21bd 100644 --- a/src/Merge.Client/Accounting/Expenses/Types/ExpensesListRequestExpand.cs +++ b/src/Merge.Client/Accounting/Expenses/Types/ExpensesListRequestExpand.cs @@ -1,6 +1,5 @@ using System.Runtime.Serialization; using System.Text.Json.Serialization; -using Merge.Client.Accounting; using Merge.Client.Core; #nullable enable diff --git a/src/Merge.Client/Accounting/Expenses/Types/ExpensesRetrieveRequestExpand.cs b/src/Merge.Client/Accounting/Expenses/Types/ExpensesRetrieveRequestExpand.cs index f1cfa247..8a276eb7 100644 --- a/src/Merge.Client/Accounting/Expenses/Types/ExpensesRetrieveRequestExpand.cs +++ b/src/Merge.Client/Accounting/Expenses/Types/ExpensesRetrieveRequestExpand.cs @@ -1,6 +1,5 @@ using System.Runtime.Serialization; using System.Text.Json.Serialization; -using Merge.Client.Accounting; using Merge.Client.Core; #nullable enable diff --git a/src/Merge.Client/Accounting/FieldMapping/FieldMappingClient.cs b/src/Merge.Client/Accounting/FieldMapping/FieldMappingClient.cs index f83096eb..6dc13006 100644 --- a/src/Merge.Client/Accounting/FieldMapping/FieldMappingClient.cs +++ b/src/Merge.Client/Accounting/FieldMapping/FieldMappingClient.cs @@ -1,6 +1,6 @@ +using System.Net.Http; using System.Text.Json; -using Merge.Client; -using Merge.Client.Accounting; +using Merge.Client.Core; #nullable enable @@ -18,64 +18,112 @@ public FieldMappingClient(RawClient client) /// /// Get all Field Mappings for this Linked Account. Field Mappings are mappings between third-party Remote Fields and user defined Merge fields. [Learn more](https://docs.merge.dev/supplemental-data/field-mappings/overview/). /// - public async Task FieldMappingsRetrieveAsync() + public async Task FieldMappingsRetrieveAsync( + RequestOptions? options = null + ) { var response = await _client.MakeRequestAsync( new RawClient.JsonApiRequest { + BaseUrl = _client.Options.BaseUrl, Method = HttpMethod.Get, - Path = "accounting/v1/field-mappings" + Path = "accounting/v1/field-mappings", + Options = options } ); - string responseBody = await response.Raw.Content.ReadAsStringAsync(); - if (response.StatusCode >= 200 && response.StatusCode < 400) + var responseBody = await response.Raw.Content.ReadAsStringAsync(); + if (response.StatusCode is >= 200 and < 400) { - return JsonSerializer.Deserialize(responseBody); + try + { + return JsonUtils.Deserialize(responseBody)!; + } + catch (JsonException e) + { + throw new MergeException("Failed to deserialize response", e); + } } - throw new Exception(responseBody); + + throw new MergeApiException( + $"Error with status code {response.StatusCode}", + response.StatusCode, + JsonUtils.Deserialize(responseBody) + ); } /// /// Create new Field Mappings that will be available after the next scheduled sync. This will cause the next sync for this Linked Account to sync **ALL** data from start. /// public async Task FieldMappingsCreateAsync( - CreateFieldMappingRequest request + CreateFieldMappingRequest request, + RequestOptions? options = null ) { var response = await _client.MakeRequestAsync( new RawClient.JsonApiRequest { + BaseUrl = _client.Options.BaseUrl, Method = HttpMethod.Post, Path = "accounting/v1/field-mappings", - Body = request + Body = request, + Options = options } ); - string responseBody = await response.Raw.Content.ReadAsStringAsync(); - if (response.StatusCode >= 200 && response.StatusCode < 400) + var responseBody = await response.Raw.Content.ReadAsStringAsync(); + if (response.StatusCode is >= 200 and < 400) { - return JsonSerializer.Deserialize(responseBody); + try + { + return JsonUtils.Deserialize(responseBody)!; + } + catch (JsonException e) + { + throw new MergeException("Failed to deserialize response", e); + } } - throw new Exception(responseBody); + + throw new MergeApiException( + $"Error with status code {response.StatusCode}", + response.StatusCode, + JsonUtils.Deserialize(responseBody) + ); } /// /// Deletes Field Mappings for a Linked Account. All data related to this Field Mapping will be deleted and these changes will be reflected after the next scheduled sync. This will cause the next sync for this Linked Account to sync **ALL** data from start. /// - public async Task FieldMappingsDestroyAsync(string fieldMappingId) + public async Task FieldMappingsDestroyAsync( + string fieldMappingId, + RequestOptions? options = null + ) { var response = await _client.MakeRequestAsync( new RawClient.JsonApiRequest { + BaseUrl = _client.Options.BaseUrl, Method = HttpMethod.Delete, - Path = $"accounting/v1/field-mappings/{fieldMappingId}" + Path = $"accounting/v1/field-mappings/{fieldMappingId}", + Options = options } ); - string responseBody = await response.Raw.Content.ReadAsStringAsync(); - if (response.StatusCode >= 200 && response.StatusCode < 400) + var responseBody = await response.Raw.Content.ReadAsStringAsync(); + if (response.StatusCode is >= 200 and < 400) { - return JsonSerializer.Deserialize(responseBody); + try + { + return JsonUtils.Deserialize(responseBody)!; + } + catch (JsonException e) + { + throw new MergeException("Failed to deserialize response", e); + } } - throw new Exception(responseBody); + + throw new MergeApiException( + $"Error with status code {response.StatusCode}", + response.StatusCode, + JsonUtils.Deserialize(responseBody) + ); } /// @@ -83,30 +131,46 @@ public async Task FieldMappingsDestroyAsync(string /// public async Task FieldMappingsPartialUpdateAsync( string fieldMappingId, - PatchedEditFieldMappingRequest request + PatchedEditFieldMappingRequest request, + RequestOptions? options = null ) { var response = await _client.MakeRequestAsync( new RawClient.JsonApiRequest { - Method = HttpMethod.Patch, + BaseUrl = _client.Options.BaseUrl, + Method = HttpMethodExtensions.Patch, Path = $"accounting/v1/field-mappings/{fieldMappingId}", - Body = request + Body = request, + Options = options } ); - string responseBody = await response.Raw.Content.ReadAsStringAsync(); - if (response.StatusCode >= 200 && response.StatusCode < 400) + var responseBody = await response.Raw.Content.ReadAsStringAsync(); + if (response.StatusCode is >= 200 and < 400) { - return JsonSerializer.Deserialize(responseBody); + try + { + return JsonUtils.Deserialize(responseBody)!; + } + catch (JsonException e) + { + throw new MergeException("Failed to deserialize response", e); + } } - throw new Exception(responseBody); + + throw new MergeApiException( + $"Error with status code {response.StatusCode}", + response.StatusCode, + JsonUtils.Deserialize(responseBody) + ); } /// /// Get all remote fields for a Linked Account. Remote fields are third-party fields that are accessible after initial sync if remote_data is enabled. You can use remote fields to override existing Merge fields or map a new Merge field. [Learn more](https://docs.merge.dev/supplemental-data/field-mappings/overview/). /// public async Task RemoteFieldsRetrieveAsync( - RemoteFieldsRetrieveRequest request + RemoteFieldsRetrieveRequest request, + RequestOptions? options = null ) { var _query = new Dictionary() { }; @@ -121,36 +185,66 @@ RemoteFieldsRetrieveRequest request var response = await _client.MakeRequestAsync( new RawClient.JsonApiRequest { + BaseUrl = _client.Options.BaseUrl, Method = HttpMethod.Get, Path = "accounting/v1/remote-fields", - Query = _query + Query = _query, + Options = options } ); - string responseBody = await response.Raw.Content.ReadAsStringAsync(); - if (response.StatusCode >= 200 && response.StatusCode < 400) + var responseBody = await response.Raw.Content.ReadAsStringAsync(); + if (response.StatusCode is >= 200 and < 400) { - return JsonSerializer.Deserialize(responseBody); + try + { + return JsonUtils.Deserialize(responseBody)!; + } + catch (JsonException e) + { + throw new MergeException("Failed to deserialize response", e); + } } - throw new Exception(responseBody); + + throw new MergeApiException( + $"Error with status code {response.StatusCode}", + response.StatusCode, + JsonUtils.Deserialize(responseBody) + ); } /// /// Get all organization-wide Target Fields, this will not include any Linked Account specific Target Fields. Organization-wide Target Fields are additional fields appended to the Merge Common Model for all Linked Accounts in a category. [Learn more](https://docs.merge.dev/supplemental-data/field-mappings/target-fields/). /// - public async Task TargetFieldsRetrieveAsync() + public async Task TargetFieldsRetrieveAsync( + RequestOptions? options = null + ) { var response = await _client.MakeRequestAsync( new RawClient.JsonApiRequest { + BaseUrl = _client.Options.BaseUrl, Method = HttpMethod.Get, - Path = "accounting/v1/target-fields" + Path = "accounting/v1/target-fields", + Options = options } ); - string responseBody = await response.Raw.Content.ReadAsStringAsync(); - if (response.StatusCode >= 200 && response.StatusCode < 400) + var responseBody = await response.Raw.Content.ReadAsStringAsync(); + if (response.StatusCode is >= 200 and < 400) { - return JsonSerializer.Deserialize(responseBody); + try + { + return JsonUtils.Deserialize(responseBody)!; + } + catch (JsonException e) + { + throw new MergeException("Failed to deserialize response", e); + } } - throw new Exception(responseBody); + + throw new MergeApiException( + $"Error with status code {response.StatusCode}", + response.StatusCode, + JsonUtils.Deserialize(responseBody) + ); } } diff --git a/src/Merge.Client/Accounting/FieldMapping/Requests/CreateFieldMappingRequest.cs b/src/Merge.Client/Accounting/FieldMapping/Requests/CreateFieldMappingRequest.cs index dcf1c000..ab753d95 100644 --- a/src/Merge.Client/Accounting/FieldMapping/Requests/CreateFieldMappingRequest.cs +++ b/src/Merge.Client/Accounting/FieldMapping/Requests/CreateFieldMappingRequest.cs @@ -4,41 +4,41 @@ namespace Merge.Client.Accounting; -public class CreateFieldMappingRequest +public record CreateFieldMappingRequest { /// /// The name of the target field you want this remote field to map to. /// [JsonPropertyName("target_field_name")] - public string TargetFieldName { get; init; } + public required string TargetFieldName { get; set; } /// /// The description of the target field you want this remote field to map to. /// [JsonPropertyName("target_field_description")] - public string TargetFieldDescription { get; init; } + public required string TargetFieldDescription { get; set; } /// /// The field traversal path of the remote field listed when you hit the GET /remote-fields endpoint. /// [JsonPropertyName("remote_field_traversal_path")] - public IEnumerable RemoteFieldTraversalPath { get; init; } + public IEnumerable RemoteFieldTraversalPath { get; set; } = new List(); /// /// The method of the remote endpoint where the remote field is coming from. /// [JsonPropertyName("remote_method")] - public string RemoteMethod { get; init; } + public required string RemoteMethod { get; set; } /// /// The path of the remote endpoint where the remote field is coming from. /// [JsonPropertyName("remote_url_path")] - public string RemoteUrlPath { get; init; } + public required string RemoteUrlPath { get; set; } /// /// The name of the Common Model that the remote field corresponds to in a given category. /// [JsonPropertyName("common_model_name")] - public string CommonModelName { get; init; } + public required string CommonModelName { get; set; } } diff --git a/src/Merge.Client/Accounting/FieldMapping/Requests/PatchedEditFieldMappingRequest.cs b/src/Merge.Client/Accounting/FieldMapping/Requests/PatchedEditFieldMappingRequest.cs index 6c5a244f..76dcf581 100644 --- a/src/Merge.Client/Accounting/FieldMapping/Requests/PatchedEditFieldMappingRequest.cs +++ b/src/Merge.Client/Accounting/FieldMapping/Requests/PatchedEditFieldMappingRequest.cs @@ -4,23 +4,23 @@ namespace Merge.Client.Accounting; -public class PatchedEditFieldMappingRequest +public record PatchedEditFieldMappingRequest { /// /// The field traversal path of the remote field listed when you hit the GET /remote-fields endpoint. /// [JsonPropertyName("remote_field_traversal_path")] - public IEnumerable? RemoteFieldTraversalPath { get; init; } + public IEnumerable? RemoteFieldTraversalPath { get; set; } /// /// The method of the remote endpoint where the remote field is coming from. /// [JsonPropertyName("remote_method")] - public string? RemoteMethod { get; init; } + public string? RemoteMethod { get; set; } /// /// The path of the remote endpoint where the remote field is coming from. /// [JsonPropertyName("remote_url_path")] - public string? RemoteUrlPath { get; init; } + public string? RemoteUrlPath { get; set; } } diff --git a/src/Merge.Client/Accounting/FieldMapping/Requests/RemoteFieldsRetrieveRequest.cs b/src/Merge.Client/Accounting/FieldMapping/Requests/RemoteFieldsRetrieveRequest.cs index 172102b2..2eeb8bba 100644 --- a/src/Merge.Client/Accounting/FieldMapping/Requests/RemoteFieldsRetrieveRequest.cs +++ b/src/Merge.Client/Accounting/FieldMapping/Requests/RemoteFieldsRetrieveRequest.cs @@ -1,14 +1,14 @@ namespace Merge.Client.Accounting; -public class RemoteFieldsRetrieveRequest +public record RemoteFieldsRetrieveRequest { /// /// A comma seperated list of Common Model names. If included, will only return Remote Fields for those Common Models. /// - public string? CommonModels { get; init; } + public string? CommonModels { get; set; } /// /// If true, will include example values, where available, for remote fields in the 3rd party platform. These examples come from active data from your customers. /// - public string? IncludeExampleValues { get; init; } + public string? IncludeExampleValues { get; set; } } diff --git a/src/Merge.Client/Accounting/ForceResync/ForceResyncClient.cs b/src/Merge.Client/Accounting/ForceResync/ForceResyncClient.cs index 00e59577..a92e019b 100644 --- a/src/Merge.Client/Accounting/ForceResync/ForceResyncClient.cs +++ b/src/Merge.Client/Accounting/ForceResync/ForceResyncClient.cs @@ -1,6 +1,6 @@ +using System.Net.Http; using System.Text.Json; -using Merge.Client; -using Merge.Client.Accounting; +using Merge.Client.Core; #nullable enable @@ -18,20 +18,36 @@ public ForceResyncClient(RawClient client) /// /// Force re-sync of all models. This is available for all organizations via the dashboard. Force re-sync is also available programmatically via API for monthly, quarterly, and highest sync frequency customers on the Launch, Professional, or Enterprise plans. Doing so will consume a sync credit for the relevant linked account. /// - public async Task> SyncStatusResyncCreateAsync() + public async Task> SyncStatusResyncCreateAsync( + RequestOptions? options = null + ) { var response = await _client.MakeRequestAsync( new RawClient.JsonApiRequest { + BaseUrl = _client.Options.BaseUrl, Method = HttpMethod.Post, - Path = "accounting/v1/sync-status/resync" + Path = "accounting/v1/sync-status/resync", + Options = options } ); - string responseBody = await response.Raw.Content.ReadAsStringAsync(); - if (response.StatusCode >= 200 && response.StatusCode < 400) + var responseBody = await response.Raw.Content.ReadAsStringAsync(); + if (response.StatusCode is >= 200 and < 400) { - return JsonSerializer.Deserialize>(responseBody); + try + { + return JsonUtils.Deserialize>(responseBody)!; + } + catch (JsonException e) + { + throw new MergeException("Failed to deserialize response", e); + } } - throw new Exception(responseBody); + + throw new MergeApiException( + $"Error with status code {response.StatusCode}", + response.StatusCode, + JsonUtils.Deserialize(responseBody) + ); } } diff --git a/src/Merge.Client/Accounting/GenerateKey/GenerateKeyClient.cs b/src/Merge.Client/Accounting/GenerateKey/GenerateKeyClient.cs index 607e1b81..042a0ed3 100644 --- a/src/Merge.Client/Accounting/GenerateKey/GenerateKeyClient.cs +++ b/src/Merge.Client/Accounting/GenerateKey/GenerateKeyClient.cs @@ -1,6 +1,6 @@ +using System.Net.Http; using System.Text.Json; -using Merge.Client; -using Merge.Client.Accounting; +using Merge.Client.Core; #nullable enable @@ -18,21 +18,38 @@ public GenerateKeyClient(RawClient client) /// /// Create a remote key. /// - public async Task CreateAsync(GenerateRemoteKeyRequest request) + public async Task CreateAsync( + GenerateRemoteKeyRequest request, + RequestOptions? options = null + ) { var response = await _client.MakeRequestAsync( new RawClient.JsonApiRequest { + BaseUrl = _client.Options.BaseUrl, Method = HttpMethod.Post, Path = "accounting/v1/generate-key", - Body = request + Body = request, + Options = options } ); - string responseBody = await response.Raw.Content.ReadAsStringAsync(); - if (response.StatusCode >= 200 && response.StatusCode < 400) + var responseBody = await response.Raw.Content.ReadAsStringAsync(); + if (response.StatusCode is >= 200 and < 400) { - return JsonSerializer.Deserialize(responseBody); + try + { + return JsonUtils.Deserialize(responseBody)!; + } + catch (JsonException e) + { + throw new MergeException("Failed to deserialize response", e); + } } - throw new Exception(responseBody); + + throw new MergeApiException( + $"Error with status code {response.StatusCode}", + response.StatusCode, + JsonUtils.Deserialize(responseBody) + ); } } diff --git a/src/Merge.Client/Accounting/GenerateKey/Requests/GenerateRemoteKeyRequest.cs b/src/Merge.Client/Accounting/GenerateKey/Requests/GenerateRemoteKeyRequest.cs index 01b6f2b5..7f7bec6c 100644 --- a/src/Merge.Client/Accounting/GenerateKey/Requests/GenerateRemoteKeyRequest.cs +++ b/src/Merge.Client/Accounting/GenerateKey/Requests/GenerateRemoteKeyRequest.cs @@ -4,11 +4,11 @@ namespace Merge.Client.Accounting; -public class GenerateRemoteKeyRequest +public record GenerateRemoteKeyRequest { /// /// The name of the remote key /// [JsonPropertyName("name")] - public string Name { get; init; } + public required string Name { get; set; } } diff --git a/src/Merge.Client/Accounting/IncomeStatements/IncomeStatementsClient.cs b/src/Merge.Client/Accounting/IncomeStatements/IncomeStatementsClient.cs index 1c5be94b..073b5a5f 100644 --- a/src/Merge.Client/Accounting/IncomeStatements/IncomeStatementsClient.cs +++ b/src/Merge.Client/Accounting/IncomeStatements/IncomeStatementsClient.cs @@ -1,6 +1,6 @@ +using System.Net.Http; using System.Text.Json; -using Merge.Client; -using Merge.Client.Accounting; +using Merge.Client.Core; #nullable enable @@ -18,7 +18,10 @@ public IncomeStatementsClient(RawClient client) /// /// Returns a list of `IncomeStatement` objects. /// - public async Task ListAsync(IncomeStatementsListRequest request) + public async Task ListAsync( + IncomeStatementsListRequest request, + RequestOptions? options = null + ) { var _query = new Dictionary() { }; if (request.CompanyId != null) @@ -27,11 +30,13 @@ public async Task ListAsync(IncomeStatementsListRe } if (request.CreatedAfter != null) { - _query["created_after"] = request.CreatedAfter.Value.ToString("o0"); + _query["created_after"] = request.CreatedAfter.Value.ToString(Constants.DateTimeFormat); } if (request.CreatedBefore != null) { - _query["created_before"] = request.CreatedBefore.Value.ToString("o0"); + _query["created_before"] = request.CreatedBefore.Value.ToString( + Constants.DateTimeFormat + ); } if (request.Cursor != null) { @@ -51,11 +56,15 @@ public async Task ListAsync(IncomeStatementsListRe } if (request.ModifiedAfter != null) { - _query["modified_after"] = request.ModifiedAfter.Value.ToString("o0"); + _query["modified_after"] = request.ModifiedAfter.Value.ToString( + Constants.DateTimeFormat + ); } if (request.ModifiedBefore != null) { - _query["modified_before"] = request.ModifiedBefore.Value.ToString("o0"); + _query["modified_before"] = request.ModifiedBefore.Value.ToString( + Constants.DateTimeFormat + ); } if (request.PageSize != null) { @@ -68,17 +77,31 @@ public async Task ListAsync(IncomeStatementsListRe var response = await _client.MakeRequestAsync( new RawClient.JsonApiRequest { + BaseUrl = _client.Options.BaseUrl, Method = HttpMethod.Get, Path = "accounting/v1/income-statements", - Query = _query + Query = _query, + Options = options } ); - string responseBody = await response.Raw.Content.ReadAsStringAsync(); - if (response.StatusCode >= 200 && response.StatusCode < 400) + var responseBody = await response.Raw.Content.ReadAsStringAsync(); + if (response.StatusCode is >= 200 and < 400) { - return JsonSerializer.Deserialize(responseBody); + try + { + return JsonUtils.Deserialize(responseBody)!; + } + catch (JsonException e) + { + throw new MergeException("Failed to deserialize response", e); + } } - throw new Exception(responseBody); + + throw new MergeApiException( + $"Error with status code {response.StatusCode}", + response.StatusCode, + JsonUtils.Deserialize(responseBody) + ); } /// @@ -86,7 +109,8 @@ public async Task ListAsync(IncomeStatementsListRe /// public async Task RetrieveAsync( string id, - IncomeStatementsRetrieveRequest request + IncomeStatementsRetrieveRequest request, + RequestOptions? options = null ) { var _query = new Dictionary() { }; @@ -101,16 +125,30 @@ IncomeStatementsRetrieveRequest request var response = await _client.MakeRequestAsync( new RawClient.JsonApiRequest { + BaseUrl = _client.Options.BaseUrl, Method = HttpMethod.Get, Path = $"accounting/v1/income-statements/{id}", - Query = _query + Query = _query, + Options = options } ); - string responseBody = await response.Raw.Content.ReadAsStringAsync(); - if (response.StatusCode >= 200 && response.StatusCode < 400) + var responseBody = await response.Raw.Content.ReadAsStringAsync(); + if (response.StatusCode is >= 200 and < 400) { - return JsonSerializer.Deserialize(responseBody); + try + { + return JsonUtils.Deserialize(responseBody)!; + } + catch (JsonException e) + { + throw new MergeException("Failed to deserialize response", e); + } } - throw new Exception(responseBody); + + throw new MergeApiException( + $"Error with status code {response.StatusCode}", + response.StatusCode, + JsonUtils.Deserialize(responseBody) + ); } } diff --git a/src/Merge.Client/Accounting/IncomeStatements/Requests/IncomeStatementsListRequest.cs b/src/Merge.Client/Accounting/IncomeStatements/Requests/IncomeStatementsListRequest.cs index a02927c2..c481a4d8 100644 --- a/src/Merge.Client/Accounting/IncomeStatements/Requests/IncomeStatementsListRequest.cs +++ b/src/Merge.Client/Accounting/IncomeStatements/Requests/IncomeStatementsListRequest.cs @@ -1,59 +1,59 @@ namespace Merge.Client.Accounting; -public class IncomeStatementsListRequest +public record IncomeStatementsListRequest { /// /// If provided, will only return income statements for this company. /// - public string? CompanyId { get; init; } + public string? CompanyId { get; set; } /// /// If provided, will only return objects created after this datetime. /// - public DateTime? CreatedAfter { get; init; } + public DateTime? CreatedAfter { get; set; } /// /// If provided, will only return objects created before this datetime. /// - public DateTime? CreatedBefore { get; init; } + public DateTime? CreatedBefore { get; set; } /// /// The pagination cursor value. /// - public string? Cursor { get; init; } + public string? Cursor { get; set; } /// /// Which relations should be returned in expanded form. Multiple relation names should be comma separated without spaces. /// - public string? Expand { get; init; } + public string? Expand { get; set; } /// /// Whether to include data that was marked as deleted by third party webhooks. /// - public bool? IncludeDeletedData { get; init; } + public bool? IncludeDeletedData { get; set; } /// /// Whether to include the original data Merge fetched from the third-party to produce these models. /// - public bool? IncludeRemoteData { get; init; } + public bool? IncludeRemoteData { get; set; } /// /// If provided, only objects synced by Merge after this date time will be returned. /// - public DateTime? ModifiedAfter { get; init; } + public DateTime? ModifiedAfter { get; set; } /// /// If provided, only objects synced by Merge before this date time will be returned. /// - public DateTime? ModifiedBefore { get; init; } + public DateTime? ModifiedBefore { get; set; } /// /// Number of results to return per page. /// - public int? PageSize { get; init; } + public int? PageSize { get; set; } /// /// The API provider's ID for the given object. /// - public string? RemoteId { get; init; } + public string? RemoteId { get; set; } } diff --git a/src/Merge.Client/Accounting/IncomeStatements/Requests/IncomeStatementsRetrieveRequest.cs b/src/Merge.Client/Accounting/IncomeStatements/Requests/IncomeStatementsRetrieveRequest.cs index 33df0b69..84c9a0fa 100644 --- a/src/Merge.Client/Accounting/IncomeStatements/Requests/IncomeStatementsRetrieveRequest.cs +++ b/src/Merge.Client/Accounting/IncomeStatements/Requests/IncomeStatementsRetrieveRequest.cs @@ -1,14 +1,14 @@ namespace Merge.Client.Accounting; -public class IncomeStatementsRetrieveRequest +public record IncomeStatementsRetrieveRequest { /// /// Which relations should be returned in expanded form. Multiple relation names should be comma separated without spaces. /// - public string? Expand { get; init; } + public string? Expand { get; set; } /// /// Whether to include the original data Merge fetched from the third-party to produce these models. /// - public bool? IncludeRemoteData { get; init; } + public bool? IncludeRemoteData { get; set; } } diff --git a/src/Merge.Client/Accounting/Invoices/InvoicesClient.cs b/src/Merge.Client/Accounting/Invoices/InvoicesClient.cs index 692f127e..fc5613d8 100644 --- a/src/Merge.Client/Accounting/Invoices/InvoicesClient.cs +++ b/src/Merge.Client/Accounting/Invoices/InvoicesClient.cs @@ -1,6 +1,6 @@ +using System.Net.Http; using System.Text.Json; -using Merge.Client; -using Merge.Client.Accounting; +using Merge.Client.Core; #nullable enable @@ -18,7 +18,10 @@ public InvoicesClient(RawClient client) /// /// Returns a list of `Invoice` objects. /// - public async Task ListAsync(InvoicesListRequest request) + public async Task ListAsync( + InvoicesListRequest request, + RequestOptions? options = null + ) { var _query = new Dictionary() { }; if (request.CompanyId != null) @@ -31,11 +34,13 @@ public async Task ListAsync(InvoicesListRequest request) } if (request.CreatedAfter != null) { - _query["created_after"] = request.CreatedAfter.Value.ToString("o0"); + _query["created_after"] = request.CreatedAfter.Value.ToString(Constants.DateTimeFormat); } if (request.CreatedBefore != null) { - _query["created_before"] = request.CreatedBefore.Value.ToString("o0"); + _query["created_before"] = request.CreatedBefore.Value.ToString( + Constants.DateTimeFormat + ); } if (request.Cursor != null) { @@ -55,19 +60,27 @@ public async Task ListAsync(InvoicesListRequest request) } if (request.IssueDateAfter != null) { - _query["issue_date_after"] = request.IssueDateAfter.Value.ToString("o0"); + _query["issue_date_after"] = request.IssueDateAfter.Value.ToString( + Constants.DateTimeFormat + ); } if (request.IssueDateBefore != null) { - _query["issue_date_before"] = request.IssueDateBefore.Value.ToString("o0"); + _query["issue_date_before"] = request.IssueDateBefore.Value.ToString( + Constants.DateTimeFormat + ); } if (request.ModifiedAfter != null) { - _query["modified_after"] = request.ModifiedAfter.Value.ToString("o0"); + _query["modified_after"] = request.ModifiedAfter.Value.ToString( + Constants.DateTimeFormat + ); } if (request.ModifiedBefore != null) { - _query["modified_before"] = request.ModifiedBefore.Value.ToString("o0"); + _query["modified_before"] = request.ModifiedBefore.Value.ToString( + Constants.DateTimeFormat + ); } if (request.PageSize != null) { @@ -92,23 +105,40 @@ public async Task ListAsync(InvoicesListRequest request) var response = await _client.MakeRequestAsync( new RawClient.JsonApiRequest { + BaseUrl = _client.Options.BaseUrl, Method = HttpMethod.Get, Path = "accounting/v1/invoices", - Query = _query + Query = _query, + Options = options } ); - string responseBody = await response.Raw.Content.ReadAsStringAsync(); - if (response.StatusCode >= 200 && response.StatusCode < 400) + var responseBody = await response.Raw.Content.ReadAsStringAsync(); + if (response.StatusCode is >= 200 and < 400) { - return JsonSerializer.Deserialize(responseBody); + try + { + return JsonUtils.Deserialize(responseBody)!; + } + catch (JsonException e) + { + throw new MergeException("Failed to deserialize response", e); + } } - throw new Exception(responseBody); + + throw new MergeApiException( + $"Error with status code {response.StatusCode}", + response.StatusCode, + JsonUtils.Deserialize(responseBody) + ); } /// /// Creates an `Invoice` object with the given values. /// - public async Task CreateAsync(InvoiceEndpointRequest request) + public async Task CreateAsync( + InvoiceEndpointRequest request, + RequestOptions? options = null + ) { var _query = new Dictionary() { }; if (request.IsDebugMode != null) @@ -122,23 +152,41 @@ public async Task CreateAsync(InvoiceEndpointRequest request) var response = await _client.MakeRequestAsync( new RawClient.JsonApiRequest { + BaseUrl = _client.Options.BaseUrl, Method = HttpMethod.Post, Path = "accounting/v1/invoices", - Query = _query + Query = _query, + Options = options } ); - string responseBody = await response.Raw.Content.ReadAsStringAsync(); - if (response.StatusCode >= 200 && response.StatusCode < 400) + var responseBody = await response.Raw.Content.ReadAsStringAsync(); + if (response.StatusCode is >= 200 and < 400) { - return JsonSerializer.Deserialize(responseBody); + try + { + return JsonUtils.Deserialize(responseBody)!; + } + catch (JsonException e) + { + throw new MergeException("Failed to deserialize response", e); + } } - throw new Exception(responseBody); + + throw new MergeApiException( + $"Error with status code {response.StatusCode}", + response.StatusCode, + JsonUtils.Deserialize(responseBody) + ); } /// /// Returns an `Invoice` object with the given `id`. /// - public async Task RetrieveAsync(string id, InvoicesRetrieveRequest request) + public async Task RetrieveAsync( + string id, + InvoicesRetrieveRequest request, + RequestOptions? options = null + ) { var _query = new Dictionary() { }; if (request.Expand != null) @@ -160,17 +208,31 @@ public async Task RetrieveAsync(string id, InvoicesRetrieveRequest requ var response = await _client.MakeRequestAsync( new RawClient.JsonApiRequest { + BaseUrl = _client.Options.BaseUrl, Method = HttpMethod.Get, Path = $"accounting/v1/invoices/{id}", - Query = _query + Query = _query, + Options = options } ); - string responseBody = await response.Raw.Content.ReadAsStringAsync(); - if (response.StatusCode >= 200 && response.StatusCode < 400) + var responseBody = await response.Raw.Content.ReadAsStringAsync(); + if (response.StatusCode is >= 200 and < 400) { - return JsonSerializer.Deserialize(responseBody); + try + { + return JsonUtils.Deserialize(responseBody)!; + } + catch (JsonException e) + { + throw new MergeException("Failed to deserialize response", e); + } } - throw new Exception(responseBody); + + throw new MergeApiException( + $"Error with status code {response.StatusCode}", + response.StatusCode, + JsonUtils.Deserialize(responseBody) + ); } /// @@ -178,7 +240,8 @@ public async Task RetrieveAsync(string id, InvoicesRetrieveRequest requ /// public async Task PartialUpdateAsync( string id, - PatchedInvoiceEndpointRequest request + PatchedInvoiceEndpointRequest request, + RequestOptions? options = null ) { var _query = new Dictionary() { }; @@ -193,56 +256,101 @@ PatchedInvoiceEndpointRequest request var response = await _client.MakeRequestAsync( new RawClient.JsonApiRequest { - Method = HttpMethod.Patch, + BaseUrl = _client.Options.BaseUrl, + Method = HttpMethodExtensions.Patch, Path = $"accounting/v1/invoices/{id}", - Query = _query + Query = _query, + Options = options } ); - string responseBody = await response.Raw.Content.ReadAsStringAsync(); - if (response.StatusCode >= 200 && response.StatusCode < 400) + var responseBody = await response.Raw.Content.ReadAsStringAsync(); + if (response.StatusCode is >= 200 and < 400) { - return JsonSerializer.Deserialize(responseBody); + try + { + return JsonUtils.Deserialize(responseBody)!; + } + catch (JsonException e) + { + throw new MergeException("Failed to deserialize response", e); + } } - throw new Exception(responseBody); + + throw new MergeApiException( + $"Error with status code {response.StatusCode}", + response.StatusCode, + JsonUtils.Deserialize(responseBody) + ); } /// /// Returns metadata for `Invoice` PATCHs. /// - public async Task MetaPatchRetrieveAsync(string id) + public async Task MetaPatchRetrieveAsync( + string id, + RequestOptions? options = null + ) { var response = await _client.MakeRequestAsync( new RawClient.JsonApiRequest { + BaseUrl = _client.Options.BaseUrl, Method = HttpMethod.Get, - Path = $"accounting/v1/invoices/meta/patch/{id}" + Path = $"accounting/v1/invoices/meta/patch/{id}", + Options = options } ); - string responseBody = await response.Raw.Content.ReadAsStringAsync(); - if (response.StatusCode >= 200 && response.StatusCode < 400) + var responseBody = await response.Raw.Content.ReadAsStringAsync(); + if (response.StatusCode is >= 200 and < 400) { - return JsonSerializer.Deserialize(responseBody); + try + { + return JsonUtils.Deserialize(responseBody)!; + } + catch (JsonException e) + { + throw new MergeException("Failed to deserialize response", e); + } } - throw new Exception(responseBody); + + throw new MergeApiException( + $"Error with status code {response.StatusCode}", + response.StatusCode, + JsonUtils.Deserialize(responseBody) + ); } /// /// Returns metadata for `Invoice` POSTs. /// - public async Task MetaPostRetrieveAsync() + public async Task MetaPostRetrieveAsync(RequestOptions? options = null) { var response = await _client.MakeRequestAsync( new RawClient.JsonApiRequest { + BaseUrl = _client.Options.BaseUrl, Method = HttpMethod.Get, - Path = "accounting/v1/invoices/meta/post" + Path = "accounting/v1/invoices/meta/post", + Options = options } ); - string responseBody = await response.Raw.Content.ReadAsStringAsync(); - if (response.StatusCode >= 200 && response.StatusCode < 400) + var responseBody = await response.Raw.Content.ReadAsStringAsync(); + if (response.StatusCode is >= 200 and < 400) { - return JsonSerializer.Deserialize(responseBody); + try + { + return JsonUtils.Deserialize(responseBody)!; + } + catch (JsonException e) + { + throw new MergeException("Failed to deserialize response", e); + } } - throw new Exception(responseBody); + + throw new MergeApiException( + $"Error with status code {response.StatusCode}", + response.StatusCode, + JsonUtils.Deserialize(responseBody) + ); } } diff --git a/src/Merge.Client/Accounting/Invoices/Requests/InvoiceEndpointRequest.cs b/src/Merge.Client/Accounting/Invoices/Requests/InvoiceEndpointRequest.cs index 3acb225f..413e94e7 100644 --- a/src/Merge.Client/Accounting/Invoices/Requests/InvoiceEndpointRequest.cs +++ b/src/Merge.Client/Accounting/Invoices/Requests/InvoiceEndpointRequest.cs @@ -1,20 +1,16 @@ -using Merge.Client.Accounting; - -#nullable enable - namespace Merge.Client.Accounting; -public class InvoiceEndpointRequest +public record InvoiceEndpointRequest { /// /// Whether to include debug fields (such as log file links) in the response. /// - public bool? IsDebugMode { get; init; } + public bool? IsDebugMode { get; set; } /// /// Whether or not third-party updates should be run asynchronously. /// - public bool? RunAsync { get; init; } + public bool? RunAsync { get; set; } - public InvoiceRequest Model { get; init; } + public required InvoiceRequest Model { get; set; } } diff --git a/src/Merge.Client/Accounting/Invoices/Requests/InvoicesListRequest.cs b/src/Merge.Client/Accounting/Invoices/Requests/InvoicesListRequest.cs index fcddbe64..06e9ca1a 100644 --- a/src/Merge.Client/Accounting/Invoices/Requests/InvoicesListRequest.cs +++ b/src/Merge.Client/Accounting/Invoices/Requests/InvoicesListRequest.cs @@ -1,90 +1,86 @@ -using Merge.Client.Accounting; - -#nullable enable - namespace Merge.Client.Accounting; -public class InvoicesListRequest +public record InvoicesListRequest { /// /// If provided, will only return invoices for this company. /// - public string? CompanyId { get; init; } + public string? CompanyId { get; set; } /// /// If provided, will only return invoices for this contact. /// - public string? ContactId { get; init; } + public string? ContactId { get; set; } /// /// If provided, will only return objects created after this datetime. /// - public DateTime? CreatedAfter { get; init; } + public DateTime? CreatedAfter { get; set; } /// /// If provided, will only return objects created before this datetime. /// - public DateTime? CreatedBefore { get; init; } + public DateTime? CreatedBefore { get; set; } /// /// The pagination cursor value. /// - public string? Cursor { get; init; } + public string? Cursor { get; set; } /// /// Which relations should be returned in expanded form. Multiple relation names should be comma separated without spaces. /// - public InvoicesListRequestExpand? Expand { get; init; } + public InvoicesListRequestExpand? Expand { get; set; } /// /// Whether to include data that was marked as deleted by third party webhooks. /// - public bool? IncludeDeletedData { get; init; } + public bool? IncludeDeletedData { get; set; } /// /// Whether to include the original data Merge fetched from the third-party to produce these models. /// - public bool? IncludeRemoteData { get; init; } + public bool? IncludeRemoteData { get; set; } /// /// If provided, will only return objects created after this datetime. /// - public DateTime? IssueDateAfter { get; init; } + public DateTime? IssueDateAfter { get; set; } /// /// If provided, will only return objects created before this datetime. /// - public DateTime? IssueDateBefore { get; init; } + public DateTime? IssueDateBefore { get; set; } /// /// If provided, only objects synced by Merge after this date time will be returned. /// - public DateTime? ModifiedAfter { get; init; } + public DateTime? ModifiedAfter { get; set; } /// /// If provided, only objects synced by Merge before this date time will be returned. /// - public DateTime? ModifiedBefore { get; init; } + public DateTime? ModifiedBefore { get; set; } /// /// Number of results to return per page. /// - public int? PageSize { get; init; } + public int? PageSize { get; set; } /// /// Deprecated. Use show_enum_origins. /// - public string? RemoteFields { get; init; } + public string? RemoteFields { get; set; } /// /// The API provider's ID for the given object. /// - public string? RemoteId { get; init; } + public string? RemoteId { get; set; } /// /// A comma separated list of enum field names for which you'd like the original values to be returned, instead of Merge's normalized enum values. [Learn more](https://help.merge.dev/en/articles/8950958-show_enum_origins-query-parameter) /// - public string? ShowEnumOrigins { get; init; } + public string? ShowEnumOrigins { get; set; } /// /// If provided, will only return Invoices with this type @@ -92,5 +88,5 @@ public class InvoicesListRequest /// - `ACCOUNTS_RECEIVABLE` - ACCOUNTS_RECEIVABLE /// - `ACCOUNTS_PAYABLE` - ACCOUNTS_PAYABLE /// - public InvoicesListRequestType? Type { get; init; } + public InvoicesListRequestType? Type { get; set; } } diff --git a/src/Merge.Client/Accounting/Invoices/Requests/InvoicesRetrieveRequest.cs b/src/Merge.Client/Accounting/Invoices/Requests/InvoicesRetrieveRequest.cs index 7aa10692..7ca62083 100644 --- a/src/Merge.Client/Accounting/Invoices/Requests/InvoicesRetrieveRequest.cs +++ b/src/Merge.Client/Accounting/Invoices/Requests/InvoicesRetrieveRequest.cs @@ -1,28 +1,24 @@ -using Merge.Client.Accounting; - -#nullable enable - namespace Merge.Client.Accounting; -public class InvoicesRetrieveRequest +public record InvoicesRetrieveRequest { /// /// Which relations should be returned in expanded form. Multiple relation names should be comma separated without spaces. /// - public InvoicesRetrieveRequestExpand? Expand { get; init; } + public InvoicesRetrieveRequestExpand? Expand { get; set; } /// /// Whether to include the original data Merge fetched from the third-party to produce these models. /// - public bool? IncludeRemoteData { get; init; } + public bool? IncludeRemoteData { get; set; } /// /// Deprecated. Use show_enum_origins. /// - public string? RemoteFields { get; init; } + public string? RemoteFields { get; set; } /// /// A comma separated list of enum field names for which you'd like the original values to be returned, instead of Merge's normalized enum values. [Learn more](https://help.merge.dev/en/articles/8950958-show_enum_origins-query-parameter) /// - public string? ShowEnumOrigins { get; init; } + public string? ShowEnumOrigins { get; set; } } diff --git a/src/Merge.Client/Accounting/Invoices/Requests/PatchedInvoiceEndpointRequest.cs b/src/Merge.Client/Accounting/Invoices/Requests/PatchedInvoiceEndpointRequest.cs index 00038980..8fdba43d 100644 --- a/src/Merge.Client/Accounting/Invoices/Requests/PatchedInvoiceEndpointRequest.cs +++ b/src/Merge.Client/Accounting/Invoices/Requests/PatchedInvoiceEndpointRequest.cs @@ -1,20 +1,16 @@ -using Merge.Client.Accounting; - -#nullable enable - namespace Merge.Client.Accounting; -public class PatchedInvoiceEndpointRequest +public record PatchedInvoiceEndpointRequest { /// /// Whether to include debug fields (such as log file links) in the response. /// - public bool? IsDebugMode { get; init; } + public bool? IsDebugMode { get; set; } /// /// Whether or not third-party updates should be run asynchronously. /// - public bool? RunAsync { get; init; } + public bool? RunAsync { get; set; } - public InvoiceRequest Model { get; init; } + public required InvoiceRequest Model { get; set; } } diff --git a/src/Merge.Client/Accounting/Invoices/Types/InvoicesListRequestExpand.cs b/src/Merge.Client/Accounting/Invoices/Types/InvoicesListRequestExpand.cs index b836e35f..22e98794 100644 --- a/src/Merge.Client/Accounting/Invoices/Types/InvoicesListRequestExpand.cs +++ b/src/Merge.Client/Accounting/Invoices/Types/InvoicesListRequestExpand.cs @@ -1,6 +1,5 @@ using System.Runtime.Serialization; using System.Text.Json.Serialization; -using Merge.Client.Accounting; using Merge.Client.Core; #nullable enable diff --git a/src/Merge.Client/Accounting/Invoices/Types/InvoicesListRequestType.cs b/src/Merge.Client/Accounting/Invoices/Types/InvoicesListRequestType.cs index b917d4ed..383f6dde 100644 --- a/src/Merge.Client/Accounting/Invoices/Types/InvoicesListRequestType.cs +++ b/src/Merge.Client/Accounting/Invoices/Types/InvoicesListRequestType.cs @@ -1,6 +1,5 @@ using System.Runtime.Serialization; using System.Text.Json.Serialization; -using Merge.Client.Accounting; using Merge.Client.Core; #nullable enable diff --git a/src/Merge.Client/Accounting/Invoices/Types/InvoicesRetrieveRequestExpand.cs b/src/Merge.Client/Accounting/Invoices/Types/InvoicesRetrieveRequestExpand.cs index ccc59c14..b2c7bcc7 100644 --- a/src/Merge.Client/Accounting/Invoices/Types/InvoicesRetrieveRequestExpand.cs +++ b/src/Merge.Client/Accounting/Invoices/Types/InvoicesRetrieveRequestExpand.cs @@ -1,6 +1,5 @@ using System.Runtime.Serialization; using System.Text.Json.Serialization; -using Merge.Client.Accounting; using Merge.Client.Core; #nullable enable diff --git a/src/Merge.Client/Accounting/Issues/IssuesClient.cs b/src/Merge.Client/Accounting/Issues/IssuesClient.cs index f5ca8204..0936cc04 100644 --- a/src/Merge.Client/Accounting/Issues/IssuesClient.cs +++ b/src/Merge.Client/Accounting/Issues/IssuesClient.cs @@ -1,6 +1,6 @@ +using System.Net.Http; using System.Text.Json; -using Merge.Client; -using Merge.Client.Accounting; +using Merge.Client.Core; #nullable enable @@ -18,7 +18,10 @@ public IssuesClient(RawClient client) /// /// Gets issues. /// - public async Task ListAsync(IssuesListRequest request) + public async Task ListAsync( + IssuesListRequest request, + RequestOptions? options = null + ) { var _query = new Dictionary() { }; if (request.AccountToken != null) @@ -40,13 +43,13 @@ public async Task ListAsync(IssuesListRequest request) if (request.FirstIncidentTimeAfter != null) { _query["first_incident_time_after"] = request.FirstIncidentTimeAfter.Value.ToString( - "o0" + Constants.DateTimeFormat ); } if (request.FirstIncidentTimeBefore != null) { _query["first_incident_time_before"] = request.FirstIncidentTimeBefore.Value.ToString( - "o0" + Constants.DateTimeFormat ); } if (request.IncludeMuted != null) @@ -59,12 +62,14 @@ public async Task ListAsync(IssuesListRequest request) } if (request.LastIncidentTimeAfter != null) { - _query["last_incident_time_after"] = request.LastIncidentTimeAfter.Value.ToString("o0"); + _query["last_incident_time_after"] = request.LastIncidentTimeAfter.Value.ToString( + Constants.DateTimeFormat + ); } if (request.LastIncidentTimeBefore != null) { _query["last_incident_time_before"] = request.LastIncidentTimeBefore.Value.ToString( - "o0" + Constants.DateTimeFormat ); } if (request.PageSize != null) @@ -82,36 +87,64 @@ public async Task ListAsync(IssuesListRequest request) var response = await _client.MakeRequestAsync( new RawClient.JsonApiRequest { + BaseUrl = _client.Options.BaseUrl, Method = HttpMethod.Get, Path = "accounting/v1/issues", - Query = _query + Query = _query, + Options = options } ); - string responseBody = await response.Raw.Content.ReadAsStringAsync(); - if (response.StatusCode >= 200 && response.StatusCode < 400) + var responseBody = await response.Raw.Content.ReadAsStringAsync(); + if (response.StatusCode is >= 200 and < 400) { - return JsonSerializer.Deserialize(responseBody); + try + { + return JsonUtils.Deserialize(responseBody)!; + } + catch (JsonException e) + { + throw new MergeException("Failed to deserialize response", e); + } } - throw new Exception(responseBody); + + throw new MergeApiException( + $"Error with status code {response.StatusCode}", + response.StatusCode, + JsonUtils.Deserialize(responseBody) + ); } /// /// Get a specific issue. /// - public async Task RetrieveAsync(string id) + public async Task RetrieveAsync(string id, RequestOptions? options = null) { var response = await _client.MakeRequestAsync( new RawClient.JsonApiRequest { + BaseUrl = _client.Options.BaseUrl, Method = HttpMethod.Get, - Path = $"accounting/v1/issues/{id}" + Path = $"accounting/v1/issues/{id}", + Options = options } ); - string responseBody = await response.Raw.Content.ReadAsStringAsync(); - if (response.StatusCode >= 200 && response.StatusCode < 400) + var responseBody = await response.Raw.Content.ReadAsStringAsync(); + if (response.StatusCode is >= 200 and < 400) { - return JsonSerializer.Deserialize(responseBody); + try + { + return JsonUtils.Deserialize(responseBody)!; + } + catch (JsonException e) + { + throw new MergeException("Failed to deserialize response", e); + } } - throw new Exception(responseBody); + + throw new MergeApiException( + $"Error with status code {response.StatusCode}", + response.StatusCode, + JsonUtils.Deserialize(responseBody) + ); } } diff --git a/src/Merge.Client/Accounting/Issues/Requests/IssuesListRequest.cs b/src/Merge.Client/Accounting/Issues/Requests/IssuesListRequest.cs index 13efd5c1..a9f2614d 100644 --- a/src/Merge.Client/Accounting/Issues/Requests/IssuesListRequest.cs +++ b/src/Merge.Client/Accounting/Issues/Requests/IssuesListRequest.cs @@ -1,61 +1,57 @@ -using Merge.Client.Accounting; - -#nullable enable - namespace Merge.Client.Accounting; -public class IssuesListRequest +public record IssuesListRequest { - public string? AccountToken { get; init; } + public string? AccountToken { get; set; } /// /// The pagination cursor value. /// - public string? Cursor { get; init; } + public string? Cursor { get; set; } /// /// If included, will only include issues whose most recent action occurred before this time /// - public string? EndDate { get; init; } + public string? EndDate { get; set; } - public string? EndUserOrganizationName { get; init; } + public string? EndUserOrganizationName { get; set; } /// /// If provided, will only return issues whose first incident time was after this datetime. /// - public DateTime? FirstIncidentTimeAfter { get; init; } + public DateTime? FirstIncidentTimeAfter { get; set; } /// /// If provided, will only return issues whose first incident time was before this datetime. /// - public DateTime? FirstIncidentTimeBefore { get; init; } + public DateTime? FirstIncidentTimeBefore { get; set; } /// /// If true, will include muted issues /// - public string? IncludeMuted { get; init; } + public string? IncludeMuted { get; set; } - public string? IntegrationName { get; init; } + public string? IntegrationName { get; set; } /// /// If provided, will only return issues whose last incident time was after this datetime. /// - public DateTime? LastIncidentTimeAfter { get; init; } + public DateTime? LastIncidentTimeAfter { get; set; } /// /// If provided, will only return issues whose last incident time was before this datetime. /// - public DateTime? LastIncidentTimeBefore { get; init; } + public DateTime? LastIncidentTimeBefore { get; set; } /// /// Number of results to return per page. /// - public int? PageSize { get; init; } + public int? PageSize { get; set; } /// /// If included, will only include issues whose most recent action occurred after this time /// - public string? StartDate { get; init; } + public string? StartDate { get; set; } /// /// Status of the issue. Options: ('ONGOING', 'RESOLVED') @@ -63,5 +59,5 @@ public class IssuesListRequest /// - `ONGOING` - ONGOING /// - `RESOLVED` - RESOLVED /// - public IssuesListRequestStatus? Status { get; init; } + public IssuesListRequestStatus? Status { get; set; } } diff --git a/src/Merge.Client/Accounting/Issues/Types/IssuesListRequestStatus.cs b/src/Merge.Client/Accounting/Issues/Types/IssuesListRequestStatus.cs index 10469239..3a3fc0b5 100644 --- a/src/Merge.Client/Accounting/Issues/Types/IssuesListRequestStatus.cs +++ b/src/Merge.Client/Accounting/Issues/Types/IssuesListRequestStatus.cs @@ -1,6 +1,5 @@ using System.Runtime.Serialization; using System.Text.Json.Serialization; -using Merge.Client.Accounting; using Merge.Client.Core; #nullable enable diff --git a/src/Merge.Client/Accounting/Items/ItemsClient.cs b/src/Merge.Client/Accounting/Items/ItemsClient.cs index 8792ad50..0147f9bd 100644 --- a/src/Merge.Client/Accounting/Items/ItemsClient.cs +++ b/src/Merge.Client/Accounting/Items/ItemsClient.cs @@ -1,6 +1,6 @@ +using System.Net.Http; using System.Text.Json; -using Merge.Client; -using Merge.Client.Accounting; +using Merge.Client.Core; #nullable enable @@ -18,7 +18,10 @@ public ItemsClient(RawClient client) /// /// Returns a list of `Item` objects. /// - public async Task ListAsync(ItemsListRequest request) + public async Task ListAsync( + ItemsListRequest request, + RequestOptions? options = null + ) { var _query = new Dictionary() { }; if (request.CompanyId != null) @@ -27,11 +30,13 @@ public async Task ListAsync(ItemsListRequest request) } if (request.CreatedAfter != null) { - _query["created_after"] = request.CreatedAfter.Value.ToString("o0"); + _query["created_after"] = request.CreatedAfter.Value.ToString(Constants.DateTimeFormat); } if (request.CreatedBefore != null) { - _query["created_before"] = request.CreatedBefore.Value.ToString("o0"); + _query["created_before"] = request.CreatedBefore.Value.ToString( + Constants.DateTimeFormat + ); } if (request.Cursor != null) { @@ -51,11 +56,15 @@ public async Task ListAsync(ItemsListRequest request) } if (request.ModifiedAfter != null) { - _query["modified_after"] = request.ModifiedAfter.Value.ToString("o0"); + _query["modified_after"] = request.ModifiedAfter.Value.ToString( + Constants.DateTimeFormat + ); } if (request.ModifiedBefore != null) { - _query["modified_before"] = request.ModifiedBefore.Value.ToString("o0"); + _query["modified_before"] = request.ModifiedBefore.Value.ToString( + Constants.DateTimeFormat + ); } if (request.PageSize != null) { @@ -76,23 +85,41 @@ public async Task ListAsync(ItemsListRequest request) var response = await _client.MakeRequestAsync( new RawClient.JsonApiRequest { + BaseUrl = _client.Options.BaseUrl, Method = HttpMethod.Get, Path = "accounting/v1/items", - Query = _query + Query = _query, + Options = options } ); - string responseBody = await response.Raw.Content.ReadAsStringAsync(); - if (response.StatusCode >= 200 && response.StatusCode < 400) + var responseBody = await response.Raw.Content.ReadAsStringAsync(); + if (response.StatusCode is >= 200 and < 400) { - return JsonSerializer.Deserialize(responseBody); + try + { + return JsonUtils.Deserialize(responseBody)!; + } + catch (JsonException e) + { + throw new MergeException("Failed to deserialize response", e); + } } - throw new Exception(responseBody); + + throw new MergeApiException( + $"Error with status code {response.StatusCode}", + response.StatusCode, + JsonUtils.Deserialize(responseBody) + ); } /// /// Returns an `Item` object with the given `id`. /// - public async Task RetrieveAsync(string id, ItemsRetrieveRequest request) + public async Task RetrieveAsync( + string id, + ItemsRetrieveRequest request, + RequestOptions? options = null + ) { var _query = new Dictionary() { }; if (request.Expand != null) @@ -114,16 +141,30 @@ public async Task RetrieveAsync(string id, ItemsRetrieveRequest request) var response = await _client.MakeRequestAsync( new RawClient.JsonApiRequest { + BaseUrl = _client.Options.BaseUrl, Method = HttpMethod.Get, Path = $"accounting/v1/items/{id}", - Query = _query + Query = _query, + Options = options } ); - string responseBody = await response.Raw.Content.ReadAsStringAsync(); - if (response.StatusCode >= 200 && response.StatusCode < 400) + var responseBody = await response.Raw.Content.ReadAsStringAsync(); + if (response.StatusCode is >= 200 and < 400) { - return JsonSerializer.Deserialize(responseBody); + try + { + return JsonUtils.Deserialize(responseBody)!; + } + catch (JsonException e) + { + throw new MergeException("Failed to deserialize response", e); + } } - throw new Exception(responseBody); + + throw new MergeApiException( + $"Error with status code {response.StatusCode}", + response.StatusCode, + JsonUtils.Deserialize(responseBody) + ); } } diff --git a/src/Merge.Client/Accounting/Items/Requests/ItemsListRequest.cs b/src/Merge.Client/Accounting/Items/Requests/ItemsListRequest.cs index ff6e9d67..33618123 100644 --- a/src/Merge.Client/Accounting/Items/Requests/ItemsListRequest.cs +++ b/src/Merge.Client/Accounting/Items/Requests/ItemsListRequest.cs @@ -1,73 +1,69 @@ -using Merge.Client.Accounting; - -#nullable enable - namespace Merge.Client.Accounting; -public class ItemsListRequest +public record ItemsListRequest { /// /// If provided, will only return items for this company. /// - public string? CompanyId { get; init; } + public string? CompanyId { get; set; } /// /// If provided, will only return objects created after this datetime. /// - public DateTime? CreatedAfter { get; init; } + public DateTime? CreatedAfter { get; set; } /// /// If provided, will only return objects created before this datetime. /// - public DateTime? CreatedBefore { get; init; } + public DateTime? CreatedBefore { get; set; } /// /// The pagination cursor value. /// - public string? Cursor { get; init; } + public string? Cursor { get; set; } /// /// Which relations should be returned in expanded form. Multiple relation names should be comma separated without spaces. /// - public ItemsListRequestExpand? Expand { get; init; } + public ItemsListRequestExpand? Expand { get; set; } /// /// Whether to include data that was marked as deleted by third party webhooks. /// - public bool? IncludeDeletedData { get; init; } + public bool? IncludeDeletedData { get; set; } /// /// Whether to include the original data Merge fetched from the third-party to produce these models. /// - public bool? IncludeRemoteData { get; init; } + public bool? IncludeRemoteData { get; set; } /// /// If provided, only objects synced by Merge after this date time will be returned. /// - public DateTime? ModifiedAfter { get; init; } + public DateTime? ModifiedAfter { get; set; } /// /// If provided, only objects synced by Merge before this date time will be returned. /// - public DateTime? ModifiedBefore { get; init; } + public DateTime? ModifiedBefore { get; set; } /// /// Number of results to return per page. /// - public int? PageSize { get; init; } + public int? PageSize { get; set; } /// /// Deprecated. Use show_enum_origins. /// - public string? RemoteFields { get; init; } + public string? RemoteFields { get; set; } /// /// The API provider's ID for the given object. /// - public string? RemoteId { get; init; } + public string? RemoteId { get; set; } /// /// A comma separated list of enum field names for which you'd like the original values to be returned, instead of Merge's normalized enum values. [Learn more](https://help.merge.dev/en/articles/8950958-show_enum_origins-query-parameter) /// - public string? ShowEnumOrigins { get; init; } + public string? ShowEnumOrigins { get; set; } } diff --git a/src/Merge.Client/Accounting/Items/Requests/ItemsRetrieveRequest.cs b/src/Merge.Client/Accounting/Items/Requests/ItemsRetrieveRequest.cs index 6e8f239f..936e91c7 100644 --- a/src/Merge.Client/Accounting/Items/Requests/ItemsRetrieveRequest.cs +++ b/src/Merge.Client/Accounting/Items/Requests/ItemsRetrieveRequest.cs @@ -1,28 +1,24 @@ -using Merge.Client.Accounting; - -#nullable enable - namespace Merge.Client.Accounting; -public class ItemsRetrieveRequest +public record ItemsRetrieveRequest { /// /// Which relations should be returned in expanded form. Multiple relation names should be comma separated without spaces. /// - public ItemsRetrieveRequestExpand? Expand { get; init; } + public ItemsRetrieveRequestExpand? Expand { get; set; } /// /// Whether to include the original data Merge fetched from the third-party to produce these models. /// - public bool? IncludeRemoteData { get; init; } + public bool? IncludeRemoteData { get; set; } /// /// Deprecated. Use show_enum_origins. /// - public string? RemoteFields { get; init; } + public string? RemoteFields { get; set; } /// /// A comma separated list of enum field names for which you'd like the original values to be returned, instead of Merge's normalized enum values. [Learn more](https://help.merge.dev/en/articles/8950958-show_enum_origins-query-parameter) /// - public string? ShowEnumOrigins { get; init; } + public string? ShowEnumOrigins { get; set; } } diff --git a/src/Merge.Client/Accounting/Items/Types/ItemsListRequestExpand.cs b/src/Merge.Client/Accounting/Items/Types/ItemsListRequestExpand.cs index 95426bfe..677d6473 100644 --- a/src/Merge.Client/Accounting/Items/Types/ItemsListRequestExpand.cs +++ b/src/Merge.Client/Accounting/Items/Types/ItemsListRequestExpand.cs @@ -1,6 +1,5 @@ using System.Runtime.Serialization; using System.Text.Json.Serialization; -using Merge.Client.Accounting; using Merge.Client.Core; #nullable enable diff --git a/src/Merge.Client/Accounting/Items/Types/ItemsRetrieveRequestExpand.cs b/src/Merge.Client/Accounting/Items/Types/ItemsRetrieveRequestExpand.cs index 062222aa..1428a469 100644 --- a/src/Merge.Client/Accounting/Items/Types/ItemsRetrieveRequestExpand.cs +++ b/src/Merge.Client/Accounting/Items/Types/ItemsRetrieveRequestExpand.cs @@ -1,6 +1,5 @@ using System.Runtime.Serialization; using System.Text.Json.Serialization; -using Merge.Client.Accounting; using Merge.Client.Core; #nullable enable diff --git a/src/Merge.Client/Accounting/JournalEntries/JournalEntriesClient.cs b/src/Merge.Client/Accounting/JournalEntries/JournalEntriesClient.cs index f105597d..437cc2db 100644 --- a/src/Merge.Client/Accounting/JournalEntries/JournalEntriesClient.cs +++ b/src/Merge.Client/Accounting/JournalEntries/JournalEntriesClient.cs @@ -1,6 +1,6 @@ +using System.Net.Http; using System.Text.Json; -using Merge.Client; -using Merge.Client.Accounting; +using Merge.Client.Core; #nullable enable @@ -18,7 +18,10 @@ public JournalEntriesClient(RawClient client) /// /// Returns a list of `JournalEntry` objects. /// - public async Task ListAsync(JournalEntriesListRequest request) + public async Task ListAsync( + JournalEntriesListRequest request, + RequestOptions? options = null + ) { var _query = new Dictionary() { }; if (request.CompanyId != null) @@ -27,11 +30,13 @@ public async Task ListAsync(JournalEntriesListRequest } if (request.CreatedAfter != null) { - _query["created_after"] = request.CreatedAfter.Value.ToString("o0"); + _query["created_after"] = request.CreatedAfter.Value.ToString(Constants.DateTimeFormat); } if (request.CreatedBefore != null) { - _query["created_before"] = request.CreatedBefore.Value.ToString("o0"); + _query["created_before"] = request.CreatedBefore.Value.ToString( + Constants.DateTimeFormat + ); } if (request.Cursor != null) { @@ -51,11 +56,15 @@ public async Task ListAsync(JournalEntriesListRequest } if (request.ModifiedAfter != null) { - _query["modified_after"] = request.ModifiedAfter.Value.ToString("o0"); + _query["modified_after"] = request.ModifiedAfter.Value.ToString( + Constants.DateTimeFormat + ); } if (request.ModifiedBefore != null) { - _query["modified_before"] = request.ModifiedBefore.Value.ToString("o0"); + _query["modified_before"] = request.ModifiedBefore.Value.ToString( + Constants.DateTimeFormat + ); } if (request.PageSize != null) { @@ -67,32 +76,53 @@ public async Task ListAsync(JournalEntriesListRequest } if (request.TransactionDateAfter != null) { - _query["transaction_date_after"] = request.TransactionDateAfter.Value.ToString("o0"); + _query["transaction_date_after"] = request.TransactionDateAfter.Value.ToString( + Constants.DateTimeFormat + ); } if (request.TransactionDateBefore != null) { - _query["transaction_date_before"] = request.TransactionDateBefore.Value.ToString("o0"); + _query["transaction_date_before"] = request.TransactionDateBefore.Value.ToString( + Constants.DateTimeFormat + ); } var response = await _client.MakeRequestAsync( new RawClient.JsonApiRequest { + BaseUrl = _client.Options.BaseUrl, Method = HttpMethod.Get, Path = "accounting/v1/journal-entries", - Query = _query + Query = _query, + Options = options } ); - string responseBody = await response.Raw.Content.ReadAsStringAsync(); - if (response.StatusCode >= 200 && response.StatusCode < 400) + var responseBody = await response.Raw.Content.ReadAsStringAsync(); + if (response.StatusCode is >= 200 and < 400) { - return JsonSerializer.Deserialize(responseBody); + try + { + return JsonUtils.Deserialize(responseBody)!; + } + catch (JsonException e) + { + throw new MergeException("Failed to deserialize response", e); + } } - throw new Exception(responseBody); + + throw new MergeApiException( + $"Error with status code {response.StatusCode}", + response.StatusCode, + JsonUtils.Deserialize(responseBody) + ); } /// /// Creates a `JournalEntry` object with the given values. /// - public async Task CreateAsync(JournalEntryEndpointRequest request) + public async Task CreateAsync( + JournalEntryEndpointRequest request, + RequestOptions? options = null + ) { var _query = new Dictionary() { }; if (request.IsDebugMode != null) @@ -106,23 +136,41 @@ public async Task CreateAsync(JournalEntryEndpointRequest var response = await _client.MakeRequestAsync( new RawClient.JsonApiRequest { + BaseUrl = _client.Options.BaseUrl, Method = HttpMethod.Post, Path = "accounting/v1/journal-entries", - Query = _query + Query = _query, + Options = options } ); - string responseBody = await response.Raw.Content.ReadAsStringAsync(); - if (response.StatusCode >= 200 && response.StatusCode < 400) + var responseBody = await response.Raw.Content.ReadAsStringAsync(); + if (response.StatusCode is >= 200 and < 400) { - return JsonSerializer.Deserialize(responseBody); + try + { + return JsonUtils.Deserialize(responseBody)!; + } + catch (JsonException e) + { + throw new MergeException("Failed to deserialize response", e); + } } - throw new Exception(responseBody); + + throw new MergeApiException( + $"Error with status code {response.StatusCode}", + response.StatusCode, + JsonUtils.Deserialize(responseBody) + ); } /// /// Returns a `JournalEntry` object with the given `id`. /// - public async Task RetrieveAsync(string id, JournalEntriesRetrieveRequest request) + public async Task RetrieveAsync( + string id, + JournalEntriesRetrieveRequest request, + RequestOptions? options = null + ) { var _query = new Dictionary() { }; if (request.Expand != null) @@ -136,36 +184,64 @@ public async Task RetrieveAsync(string id, JournalEntriesRetrieveR var response = await _client.MakeRequestAsync( new RawClient.JsonApiRequest { + BaseUrl = _client.Options.BaseUrl, Method = HttpMethod.Get, Path = $"accounting/v1/journal-entries/{id}", - Query = _query + Query = _query, + Options = options } ); - string responseBody = await response.Raw.Content.ReadAsStringAsync(); - if (response.StatusCode >= 200 && response.StatusCode < 400) + var responseBody = await response.Raw.Content.ReadAsStringAsync(); + if (response.StatusCode is >= 200 and < 400) { - return JsonSerializer.Deserialize(responseBody); + try + { + return JsonUtils.Deserialize(responseBody)!; + } + catch (JsonException e) + { + throw new MergeException("Failed to deserialize response", e); + } } - throw new Exception(responseBody); + + throw new MergeApiException( + $"Error with status code {response.StatusCode}", + response.StatusCode, + JsonUtils.Deserialize(responseBody) + ); } /// /// Returns metadata for `JournalEntry` POSTs. /// - public async Task MetaPostRetrieveAsync() + public async Task MetaPostRetrieveAsync(RequestOptions? options = null) { var response = await _client.MakeRequestAsync( new RawClient.JsonApiRequest { + BaseUrl = _client.Options.BaseUrl, Method = HttpMethod.Get, - Path = "accounting/v1/journal-entries/meta/post" + Path = "accounting/v1/journal-entries/meta/post", + Options = options } ); - string responseBody = await response.Raw.Content.ReadAsStringAsync(); - if (response.StatusCode >= 200 && response.StatusCode < 400) + var responseBody = await response.Raw.Content.ReadAsStringAsync(); + if (response.StatusCode is >= 200 and < 400) { - return JsonSerializer.Deserialize(responseBody); + try + { + return JsonUtils.Deserialize(responseBody)!; + } + catch (JsonException e) + { + throw new MergeException("Failed to deserialize response", e); + } } - throw new Exception(responseBody); + + throw new MergeApiException( + $"Error with status code {response.StatusCode}", + response.StatusCode, + JsonUtils.Deserialize(responseBody) + ); } } diff --git a/src/Merge.Client/Accounting/JournalEntries/Requests/JournalEntriesListRequest.cs b/src/Merge.Client/Accounting/JournalEntries/Requests/JournalEntriesListRequest.cs index 696f0d09..45456946 100644 --- a/src/Merge.Client/Accounting/JournalEntries/Requests/JournalEntriesListRequest.cs +++ b/src/Merge.Client/Accounting/JournalEntries/Requests/JournalEntriesListRequest.cs @@ -1,73 +1,69 @@ -using Merge.Client.Accounting; - -#nullable enable - namespace Merge.Client.Accounting; -public class JournalEntriesListRequest +public record JournalEntriesListRequest { /// /// If provided, will only return journal entries for this company. /// - public string? CompanyId { get; init; } + public string? CompanyId { get; set; } /// /// If provided, will only return objects created after this datetime. /// - public DateTime? CreatedAfter { get; init; } + public DateTime? CreatedAfter { get; set; } /// /// If provided, will only return objects created before this datetime. /// - public DateTime? CreatedBefore { get; init; } + public DateTime? CreatedBefore { get; set; } /// /// The pagination cursor value. /// - public string? Cursor { get; init; } + public string? Cursor { get; set; } /// /// Which relations should be returned in expanded form. Multiple relation names should be comma separated without spaces. /// - public JournalEntriesListRequestExpand? Expand { get; init; } + public JournalEntriesListRequestExpand? Expand { get; set; } /// /// Whether to include data that was marked as deleted by third party webhooks. /// - public bool? IncludeDeletedData { get; init; } + public bool? IncludeDeletedData { get; set; } /// /// Whether to include the original data Merge fetched from the third-party to produce these models. /// - public bool? IncludeRemoteData { get; init; } + public bool? IncludeRemoteData { get; set; } /// /// If provided, only objects synced by Merge after this date time will be returned. /// - public DateTime? ModifiedAfter { get; init; } + public DateTime? ModifiedAfter { get; set; } /// /// If provided, only objects synced by Merge before this date time will be returned. /// - public DateTime? ModifiedBefore { get; init; } + public DateTime? ModifiedBefore { get; set; } /// /// Number of results to return per page. /// - public int? PageSize { get; init; } + public int? PageSize { get; set; } /// /// The API provider's ID for the given object. /// - public string? RemoteId { get; init; } + public string? RemoteId { get; set; } /// /// If provided, will only return objects created after this datetime. /// - public DateTime? TransactionDateAfter { get; init; } + public DateTime? TransactionDateAfter { get; set; } /// /// If provided, will only return objects created before this datetime. /// - public DateTime? TransactionDateBefore { get; init; } + public DateTime? TransactionDateBefore { get; set; } } diff --git a/src/Merge.Client/Accounting/JournalEntries/Requests/JournalEntriesRetrieveRequest.cs b/src/Merge.Client/Accounting/JournalEntries/Requests/JournalEntriesRetrieveRequest.cs index 9eaa22b6..a13fd764 100644 --- a/src/Merge.Client/Accounting/JournalEntries/Requests/JournalEntriesRetrieveRequest.cs +++ b/src/Merge.Client/Accounting/JournalEntries/Requests/JournalEntriesRetrieveRequest.cs @@ -1,18 +1,14 @@ -using Merge.Client.Accounting; - -#nullable enable - namespace Merge.Client.Accounting; -public class JournalEntriesRetrieveRequest +public record JournalEntriesRetrieveRequest { /// /// Which relations should be returned in expanded form. Multiple relation names should be comma separated without spaces. /// - public JournalEntriesRetrieveRequestExpand? Expand { get; init; } + public JournalEntriesRetrieveRequestExpand? Expand { get; set; } /// /// Whether to include the original data Merge fetched from the third-party to produce these models. /// - public bool? IncludeRemoteData { get; init; } + public bool? IncludeRemoteData { get; set; } } diff --git a/src/Merge.Client/Accounting/JournalEntries/Requests/JournalEntryEndpointRequest.cs b/src/Merge.Client/Accounting/JournalEntries/Requests/JournalEntryEndpointRequest.cs index fdc5856f..8db67a69 100644 --- a/src/Merge.Client/Accounting/JournalEntries/Requests/JournalEntryEndpointRequest.cs +++ b/src/Merge.Client/Accounting/JournalEntries/Requests/JournalEntryEndpointRequest.cs @@ -1,20 +1,16 @@ -using Merge.Client.Accounting; - -#nullable enable - namespace Merge.Client.Accounting; -public class JournalEntryEndpointRequest +public record JournalEntryEndpointRequest { /// /// Whether to include debug fields (such as log file links) in the response. /// - public bool? IsDebugMode { get; init; } + public bool? IsDebugMode { get; set; } /// /// Whether or not third-party updates should be run asynchronously. /// - public bool? RunAsync { get; init; } + public bool? RunAsync { get; set; } - public JournalEntryRequest Model { get; init; } + public required JournalEntryRequest Model { get; set; } } diff --git a/src/Merge.Client/Accounting/JournalEntries/Types/JournalEntriesListRequestExpand.cs b/src/Merge.Client/Accounting/JournalEntries/Types/JournalEntriesListRequestExpand.cs index 933fa6bd..fe29e3d8 100644 --- a/src/Merge.Client/Accounting/JournalEntries/Types/JournalEntriesListRequestExpand.cs +++ b/src/Merge.Client/Accounting/JournalEntries/Types/JournalEntriesListRequestExpand.cs @@ -1,6 +1,5 @@ using System.Runtime.Serialization; using System.Text.Json.Serialization; -using Merge.Client.Accounting; using Merge.Client.Core; #nullable enable diff --git a/src/Merge.Client/Accounting/JournalEntries/Types/JournalEntriesRetrieveRequestExpand.cs b/src/Merge.Client/Accounting/JournalEntries/Types/JournalEntriesRetrieveRequestExpand.cs index 5cfc390b..e16f190a 100644 --- a/src/Merge.Client/Accounting/JournalEntries/Types/JournalEntriesRetrieveRequestExpand.cs +++ b/src/Merge.Client/Accounting/JournalEntries/Types/JournalEntriesRetrieveRequestExpand.cs @@ -1,6 +1,5 @@ using System.Runtime.Serialization; using System.Text.Json.Serialization; -using Merge.Client.Accounting; using Merge.Client.Core; #nullable enable diff --git a/src/Merge.Client/Accounting/LinkToken/LinkTokenClient.cs b/src/Merge.Client/Accounting/LinkToken/LinkTokenClient.cs index 0b7756cb..5d287809 100644 --- a/src/Merge.Client/Accounting/LinkToken/LinkTokenClient.cs +++ b/src/Merge.Client/Accounting/LinkToken/LinkTokenClient.cs @@ -1,6 +1,6 @@ +using System.Net.Http; using System.Text.Json; -using Merge.Client; -using Merge.Client.Accounting; +using Merge.Client.Core; #nullable enable @@ -18,21 +18,38 @@ public LinkTokenClient(RawClient client) /// /// Creates a link token to be used when linking a new end user. /// - public async Task CreateAsync(EndUserDetailsRequest request) + public async Task CreateAsync( + EndUserDetailsRequest request, + RequestOptions? options = null + ) { var response = await _client.MakeRequestAsync( new RawClient.JsonApiRequest { + BaseUrl = _client.Options.BaseUrl, Method = HttpMethod.Post, Path = "accounting/v1/link-token", - Body = request + Body = request, + Options = options } ); - string responseBody = await response.Raw.Content.ReadAsStringAsync(); - if (response.StatusCode >= 200 && response.StatusCode < 400) + var responseBody = await response.Raw.Content.ReadAsStringAsync(); + if (response.StatusCode is >= 200 and < 400) { - return JsonSerializer.Deserialize(responseBody); + try + { + return JsonUtils.Deserialize(responseBody)!; + } + catch (JsonException e) + { + throw new MergeException("Failed to deserialize response", e); + } } - throw new Exception(responseBody); + + throw new MergeApiException( + $"Error with status code {response.StatusCode}", + response.StatusCode, + JsonUtils.Deserialize(responseBody) + ); } } diff --git a/src/Merge.Client/Accounting/LinkToken/Requests/EndUserDetailsRequest.cs b/src/Merge.Client/Accounting/LinkToken/Requests/EndUserDetailsRequest.cs index 247fee5a..21151392 100644 --- a/src/Merge.Client/Accounting/LinkToken/Requests/EndUserDetailsRequest.cs +++ b/src/Merge.Client/Accounting/LinkToken/Requests/EndUserDetailsRequest.cs @@ -1,59 +1,58 @@ using System.Text.Json.Serialization; -using Merge.Client.Accounting; #nullable enable namespace Merge.Client.Accounting; -public class EndUserDetailsRequest +public record EndUserDetailsRequest { /// /// Your end user's email address. This is purely for identification purposes - setting this value will not cause any emails to be sent. /// [JsonPropertyName("end_user_email_address")] - public string EndUserEmailAddress { get; init; } + public required string EndUserEmailAddress { get; set; } /// /// Your end user's organization. /// [JsonPropertyName("end_user_organization_name")] - public string EndUserOrganizationName { get; init; } + public required string EndUserOrganizationName { get; set; } /// /// This unique identifier typically represents the ID for your end user in your product's database. This value must be distinct from other Linked Accounts' unique identifiers. /// [JsonPropertyName("end_user_origin_id")] - public string EndUserOriginId { get; init; } + public required string EndUserOriginId { get; set; } /// /// The integration categories to show in Merge Link. /// [JsonPropertyName("categories")] - public IEnumerable Categories { get; init; } + public IEnumerable Categories { get; set; } = new List(); /// /// The slug of a specific pre-selected integration for this linking flow token. For examples of slugs, see https://docs.merge.dev/guides/merge-link/single-integration/. /// [JsonPropertyName("integration")] - public string? Integration { get; init; } + public string? Integration { get; set; } /// /// An integer number of minutes between [30, 720 or 10080 if for a Magic Link URL] for how long this token is valid. Defaults to 30. /// [JsonPropertyName("link_expiry_mins")] - public int? LinkExpiryMins { get; init; } + public int? LinkExpiryMins { get; set; } /// /// Whether to generate a Magic Link URL. Defaults to false. For more information on Magic Link, see https://merge.dev/blog/integrations-fast-say-hello-to-magic-link. /// [JsonPropertyName("should_create_magic_link_url")] - public bool? ShouldCreateMagicLinkUrl { get; init; } + public bool? ShouldCreateMagicLinkUrl { get; set; } /// /// An array of objects to specify the models and fields that will be disabled for a given Linked Account. Each object uses model_id, enabled_actions, and disabled_fields to specify the model, method, and fields that are scoped for a given Linked Account. /// [JsonPropertyName("common_models")] - public IEnumerable? CommonModels { get; init; } + public IEnumerable? CommonModels { get; set; } /// /// When creating a Link Token, you can set permissions for Common Models that will apply to the account that is going to be linked. Any model or field not specified in link token payload will default to existing settings. @@ -62,17 +61,17 @@ public class EndUserDetailsRequest public Dictionary< string, IEnumerable? - >? CategoryCommonModelScopes { get; init; } + >? CategoryCommonModelScopes { get; set; } /// /// The language code for the language to localize Merge Link to. /// [JsonPropertyName("language")] - public string? Language { get; init; } + public string? Language { get; set; } /// /// A JSON object containing integration-specific configuration options. /// [JsonPropertyName("integration_specific_config")] - public Dictionary? IntegrationSpecificConfig { get; init; } + public Dictionary? IntegrationSpecificConfig { get; set; } } diff --git a/src/Merge.Client/Accounting/LinkedAccounts/LinkedAccountsClient.cs b/src/Merge.Client/Accounting/LinkedAccounts/LinkedAccountsClient.cs index e4dec16f..89d82fd6 100644 --- a/src/Merge.Client/Accounting/LinkedAccounts/LinkedAccountsClient.cs +++ b/src/Merge.Client/Accounting/LinkedAccounts/LinkedAccountsClient.cs @@ -1,6 +1,6 @@ +using System.Net.Http; using System.Text.Json; -using Merge.Client; -using Merge.Client.Accounting; +using Merge.Client.Core; #nullable enable @@ -19,7 +19,8 @@ public LinkedAccountsClient(RawClient client) /// List linked accounts for your organization. /// public async Task ListAsync( - LinkedAccountsListRequest request + LinkedAccountsListRequest request, + RequestOptions? options = null ) { var _query = new Dictionary() { }; @@ -78,16 +79,30 @@ LinkedAccountsListRequest request var response = await _client.MakeRequestAsync( new RawClient.JsonApiRequest { + BaseUrl = _client.Options.BaseUrl, Method = HttpMethod.Get, Path = "accounting/v1/linked-accounts", - Query = _query + Query = _query, + Options = options } ); - string responseBody = await response.Raw.Content.ReadAsStringAsync(); - if (response.StatusCode >= 200 && response.StatusCode < 400) + var responseBody = await response.Raw.Content.ReadAsStringAsync(); + if (response.StatusCode is >= 200 and < 400) { - return JsonSerializer.Deserialize(responseBody); + try + { + return JsonUtils.Deserialize(responseBody)!; + } + catch (JsonException e) + { + throw new MergeException("Failed to deserialize response", e); + } } - throw new Exception(responseBody); + + throw new MergeApiException( + $"Error with status code {response.StatusCode}", + response.StatusCode, + JsonUtils.Deserialize(responseBody) + ); } } diff --git a/src/Merge.Client/Accounting/LinkedAccounts/Requests/LinkedAccountsListRequest.cs b/src/Merge.Client/Accounting/LinkedAccounts/Requests/LinkedAccountsListRequest.cs index 027ba05f..db0ffafc 100644 --- a/src/Merge.Client/Accounting/LinkedAccounts/Requests/LinkedAccountsListRequest.cs +++ b/src/Merge.Client/Accounting/LinkedAccounts/Requests/LinkedAccountsListRequest.cs @@ -1,10 +1,6 @@ -using Merge.Client.Accounting; - -#nullable enable - namespace Merge.Client.Accounting; -public class LinkedAccountsListRequest +public record LinkedAccountsListRequest { /// /// Options: `accounting`, `ats`, `crm`, `filestorage`, `hris`, `mktg`, `ticketing` @@ -17,62 +13,62 @@ public class LinkedAccountsListRequest /// - `mktg` - mktg /// - `filestorage` - filestorage /// - public LinkedAccountsListRequestCategory? Category { get; init; } + public LinkedAccountsListRequestCategory? Category { get; set; } /// /// The pagination cursor value. /// - public string? Cursor { get; init; } + public string? Cursor { get; set; } /// /// If provided, will only return linked accounts associated with the given email address. /// - public string? EndUserEmailAddress { get; init; } + public string? EndUserEmailAddress { get; set; } /// /// If provided, will only return linked accounts associated with the given organization name. /// - public string? EndUserOrganizationName { get; init; } + public string? EndUserOrganizationName { get; set; } /// /// If provided, will only return linked accounts associated with the given origin ID. /// - public string? EndUserOriginId { get; init; } + public string? EndUserOriginId { get; set; } /// /// Comma-separated list of EndUser origin IDs, making it possible to specify multiple EndUsers at once. /// - public string? EndUserOriginIds { get; init; } + public string? EndUserOriginIds { get; set; } - public string? Id { get; init; } + public string? Id { get; set; } /// /// Comma-separated list of LinkedAccount IDs, making it possible to specify multiple LinkedAccounts at once. /// - public string? Ids { get; init; } + public string? Ids { get; set; } /// /// If `true`, will include complete production duplicates of the account specified by the `id` query parameter in the response. `id` must be for a complete production linked account. /// - public bool? IncludeDuplicates { get; init; } + public bool? IncludeDuplicates { get; set; } /// /// If provided, will only return linked accounts associated with the given integration name. /// - public string? IntegrationName { get; init; } + public string? IntegrationName { get; set; } /// /// If included, will only include test linked accounts. If not included, will only include non-test linked accounts. /// - public string? IsTestAccount { get; init; } + public string? IsTestAccount { get; set; } /// /// Number of results to return per page. /// - public int? PageSize { get; init; } + public int? PageSize { get; set; } /// /// Filter by status. Options: `COMPLETE`, `INCOMPLETE`, `RELINK_NEEDED` /// - public string? Status { get; init; } + public string? Status { get; set; } } diff --git a/src/Merge.Client/Accounting/LinkedAccounts/Types/LinkedAccountsListRequestCategory.cs b/src/Merge.Client/Accounting/LinkedAccounts/Types/LinkedAccountsListRequestCategory.cs index 3cd777ce..bb11b49c 100644 --- a/src/Merge.Client/Accounting/LinkedAccounts/Types/LinkedAccountsListRequestCategory.cs +++ b/src/Merge.Client/Accounting/LinkedAccounts/Types/LinkedAccountsListRequestCategory.cs @@ -1,6 +1,5 @@ using System.Runtime.Serialization; using System.Text.Json.Serialization; -using Merge.Client.Accounting; using Merge.Client.Core; #nullable enable diff --git a/src/Merge.Client/Accounting/Passthrough/PassthroughClient.cs b/src/Merge.Client/Accounting/Passthrough/PassthroughClient.cs index 22c45efa..bf43445e 100644 --- a/src/Merge.Client/Accounting/Passthrough/PassthroughClient.cs +++ b/src/Merge.Client/Accounting/Passthrough/PassthroughClient.cs @@ -1,6 +1,6 @@ +using System.Net.Http; using System.Text.Json; -using Merge.Client; -using Merge.Client.Accounting; +using Merge.Client.Core; #nullable enable @@ -18,21 +18,38 @@ public PassthroughClient(RawClient client) /// /// Pull data from an endpoint not currently supported by Merge. /// - public async Task CreateAsync(DataPassthroughRequest request) + public async Task CreateAsync( + DataPassthroughRequest request, + RequestOptions? options = null + ) { var response = await _client.MakeRequestAsync( new RawClient.JsonApiRequest { + BaseUrl = _client.Options.BaseUrl, Method = HttpMethod.Post, Path = "accounting/v1/passthrough", - Body = request + Body = request, + Options = options } ); - string responseBody = await response.Raw.Content.ReadAsStringAsync(); - if (response.StatusCode >= 200 && response.StatusCode < 400) + var responseBody = await response.Raw.Content.ReadAsStringAsync(); + if (response.StatusCode is >= 200 and < 400) { - return JsonSerializer.Deserialize(responseBody); + try + { + return JsonUtils.Deserialize(responseBody)!; + } + catch (JsonException e) + { + throw new MergeException("Failed to deserialize response", e); + } } - throw new Exception(responseBody); + + throw new MergeApiException( + $"Error with status code {response.StatusCode}", + response.StatusCode, + JsonUtils.Deserialize(responseBody) + ); } } diff --git a/src/Merge.Client/Accounting/Payments/PaymentsClient.cs b/src/Merge.Client/Accounting/Payments/PaymentsClient.cs index d9595579..f181d2c4 100644 --- a/src/Merge.Client/Accounting/Payments/PaymentsClient.cs +++ b/src/Merge.Client/Accounting/Payments/PaymentsClient.cs @@ -1,6 +1,6 @@ +using System.Net.Http; using System.Text.Json; -using Merge.Client; -using Merge.Client.Accounting; +using Merge.Client.Core; #nullable enable @@ -18,7 +18,10 @@ public PaymentsClient(RawClient client) /// /// Returns a list of `Payment` objects. /// - public async Task ListAsync(PaymentsListRequest request) + public async Task ListAsync( + PaymentsListRequest request, + RequestOptions? options = null + ) { var _query = new Dictionary() { }; if (request.AccountId != null) @@ -35,11 +38,13 @@ public async Task ListAsync(PaymentsListRequest request) } if (request.CreatedAfter != null) { - _query["created_after"] = request.CreatedAfter.Value.ToString("o0"); + _query["created_after"] = request.CreatedAfter.Value.ToString(Constants.DateTimeFormat); } if (request.CreatedBefore != null) { - _query["created_before"] = request.CreatedBefore.Value.ToString("o0"); + _query["created_before"] = request.CreatedBefore.Value.ToString( + Constants.DateTimeFormat + ); } if (request.Cursor != null) { @@ -59,11 +64,15 @@ public async Task ListAsync(PaymentsListRequest request) } if (request.ModifiedAfter != null) { - _query["modified_after"] = request.ModifiedAfter.Value.ToString("o0"); + _query["modified_after"] = request.ModifiedAfter.Value.ToString( + Constants.DateTimeFormat + ); } if (request.ModifiedBefore != null) { - _query["modified_before"] = request.ModifiedBefore.Value.ToString("o0"); + _query["modified_before"] = request.ModifiedBefore.Value.ToString( + Constants.DateTimeFormat + ); } if (request.PageSize != null) { @@ -75,32 +84,53 @@ public async Task ListAsync(PaymentsListRequest request) } if (request.TransactionDateAfter != null) { - _query["transaction_date_after"] = request.TransactionDateAfter.Value.ToString("o0"); + _query["transaction_date_after"] = request.TransactionDateAfter.Value.ToString( + Constants.DateTimeFormat + ); } if (request.TransactionDateBefore != null) { - _query["transaction_date_before"] = request.TransactionDateBefore.Value.ToString("o0"); + _query["transaction_date_before"] = request.TransactionDateBefore.Value.ToString( + Constants.DateTimeFormat + ); } var response = await _client.MakeRequestAsync( new RawClient.JsonApiRequest { + BaseUrl = _client.Options.BaseUrl, Method = HttpMethod.Get, Path = "accounting/v1/payments", - Query = _query + Query = _query, + Options = options } ); - string responseBody = await response.Raw.Content.ReadAsStringAsync(); - if (response.StatusCode >= 200 && response.StatusCode < 400) + var responseBody = await response.Raw.Content.ReadAsStringAsync(); + if (response.StatusCode is >= 200 and < 400) { - return JsonSerializer.Deserialize(responseBody); + try + { + return JsonUtils.Deserialize(responseBody)!; + } + catch (JsonException e) + { + throw new MergeException("Failed to deserialize response", e); + } } - throw new Exception(responseBody); + + throw new MergeApiException( + $"Error with status code {response.StatusCode}", + response.StatusCode, + JsonUtils.Deserialize(responseBody) + ); } /// /// Creates a `Payment` object with the given values. /// - public async Task CreateAsync(PaymentEndpointRequest request) + public async Task CreateAsync( + PaymentEndpointRequest request, + RequestOptions? options = null + ) { var _query = new Dictionary() { }; if (request.IsDebugMode != null) @@ -114,23 +144,41 @@ public async Task CreateAsync(PaymentEndpointRequest request) var response = await _client.MakeRequestAsync( new RawClient.JsonApiRequest { + BaseUrl = _client.Options.BaseUrl, Method = HttpMethod.Post, Path = "accounting/v1/payments", - Query = _query + Query = _query, + Options = options } ); - string responseBody = await response.Raw.Content.ReadAsStringAsync(); - if (response.StatusCode >= 200 && response.StatusCode < 400) + var responseBody = await response.Raw.Content.ReadAsStringAsync(); + if (response.StatusCode is >= 200 and < 400) { - return JsonSerializer.Deserialize(responseBody); + try + { + return JsonUtils.Deserialize(responseBody)!; + } + catch (JsonException e) + { + throw new MergeException("Failed to deserialize response", e); + } } - throw new Exception(responseBody); + + throw new MergeApiException( + $"Error with status code {response.StatusCode}", + response.StatusCode, + JsonUtils.Deserialize(responseBody) + ); } /// /// Returns a `Payment` object with the given `id`. /// - public async Task RetrieveAsync(string id, PaymentsRetrieveRequest request) + public async Task RetrieveAsync( + string id, + PaymentsRetrieveRequest request, + RequestOptions? options = null + ) { var _query = new Dictionary() { }; if (request.Expand != null) @@ -144,17 +192,31 @@ public async Task RetrieveAsync(string id, PaymentsRetrieveRequest requ var response = await _client.MakeRequestAsync( new RawClient.JsonApiRequest { + BaseUrl = _client.Options.BaseUrl, Method = HttpMethod.Get, Path = $"accounting/v1/payments/{id}", - Query = _query + Query = _query, + Options = options } ); - string responseBody = await response.Raw.Content.ReadAsStringAsync(); - if (response.StatusCode >= 200 && response.StatusCode < 400) + var responseBody = await response.Raw.Content.ReadAsStringAsync(); + if (response.StatusCode is >= 200 and < 400) { - return JsonSerializer.Deserialize(responseBody); + try + { + return JsonUtils.Deserialize(responseBody)!; + } + catch (JsonException e) + { + throw new MergeException("Failed to deserialize response", e); + } } - throw new Exception(responseBody); + + throw new MergeApiException( + $"Error with status code {response.StatusCode}", + response.StatusCode, + JsonUtils.Deserialize(responseBody) + ); } /// @@ -162,7 +224,8 @@ public async Task RetrieveAsync(string id, PaymentsRetrieveRequest requ /// public async Task PartialUpdateAsync( string id, - PatchedPaymentEndpointRequest request + PatchedPaymentEndpointRequest request, + RequestOptions? options = null ) { var _query = new Dictionary() { }; @@ -177,56 +240,101 @@ PatchedPaymentEndpointRequest request var response = await _client.MakeRequestAsync( new RawClient.JsonApiRequest { - Method = HttpMethod.Patch, + BaseUrl = _client.Options.BaseUrl, + Method = HttpMethodExtensions.Patch, Path = $"accounting/v1/payments/{id}", - Query = _query + Query = _query, + Options = options } ); - string responseBody = await response.Raw.Content.ReadAsStringAsync(); - if (response.StatusCode >= 200 && response.StatusCode < 400) + var responseBody = await response.Raw.Content.ReadAsStringAsync(); + if (response.StatusCode is >= 200 and < 400) { - return JsonSerializer.Deserialize(responseBody); + try + { + return JsonUtils.Deserialize(responseBody)!; + } + catch (JsonException e) + { + throw new MergeException("Failed to deserialize response", e); + } } - throw new Exception(responseBody); + + throw new MergeApiException( + $"Error with status code {response.StatusCode}", + response.StatusCode, + JsonUtils.Deserialize(responseBody) + ); } /// /// Returns metadata for `Payment` PATCHs. /// - public async Task MetaPatchRetrieveAsync(string id) + public async Task MetaPatchRetrieveAsync( + string id, + RequestOptions? options = null + ) { var response = await _client.MakeRequestAsync( new RawClient.JsonApiRequest { + BaseUrl = _client.Options.BaseUrl, Method = HttpMethod.Get, - Path = $"accounting/v1/payments/meta/patch/{id}" + Path = $"accounting/v1/payments/meta/patch/{id}", + Options = options } ); - string responseBody = await response.Raw.Content.ReadAsStringAsync(); - if (response.StatusCode >= 200 && response.StatusCode < 400) + var responseBody = await response.Raw.Content.ReadAsStringAsync(); + if (response.StatusCode is >= 200 and < 400) { - return JsonSerializer.Deserialize(responseBody); + try + { + return JsonUtils.Deserialize(responseBody)!; + } + catch (JsonException e) + { + throw new MergeException("Failed to deserialize response", e); + } } - throw new Exception(responseBody); + + throw new MergeApiException( + $"Error with status code {response.StatusCode}", + response.StatusCode, + JsonUtils.Deserialize(responseBody) + ); } /// /// Returns metadata for `Payment` POSTs. /// - public async Task MetaPostRetrieveAsync() + public async Task MetaPostRetrieveAsync(RequestOptions? options = null) { var response = await _client.MakeRequestAsync( new RawClient.JsonApiRequest { + BaseUrl = _client.Options.BaseUrl, Method = HttpMethod.Get, - Path = "accounting/v1/payments/meta/post" + Path = "accounting/v1/payments/meta/post", + Options = options } ); - string responseBody = await response.Raw.Content.ReadAsStringAsync(); - if (response.StatusCode >= 200 && response.StatusCode < 400) + var responseBody = await response.Raw.Content.ReadAsStringAsync(); + if (response.StatusCode is >= 200 and < 400) { - return JsonSerializer.Deserialize(responseBody); + try + { + return JsonUtils.Deserialize(responseBody)!; + } + catch (JsonException e) + { + throw new MergeException("Failed to deserialize response", e); + } } - throw new Exception(responseBody); + + throw new MergeApiException( + $"Error with status code {response.StatusCode}", + response.StatusCode, + JsonUtils.Deserialize(responseBody) + ); } } diff --git a/src/Merge.Client/Accounting/Payments/Requests/PatchedPaymentEndpointRequest.cs b/src/Merge.Client/Accounting/Payments/Requests/PatchedPaymentEndpointRequest.cs index 10772971..e5938f8e 100644 --- a/src/Merge.Client/Accounting/Payments/Requests/PatchedPaymentEndpointRequest.cs +++ b/src/Merge.Client/Accounting/Payments/Requests/PatchedPaymentEndpointRequest.cs @@ -1,20 +1,16 @@ -using Merge.Client.Accounting; - -#nullable enable - namespace Merge.Client.Accounting; -public class PatchedPaymentEndpointRequest +public record PatchedPaymentEndpointRequest { /// /// Whether to include debug fields (such as log file links) in the response. /// - public bool? IsDebugMode { get; init; } + public bool? IsDebugMode { get; set; } /// /// Whether or not third-party updates should be run asynchronously. /// - public bool? RunAsync { get; init; } + public bool? RunAsync { get; set; } - public PatchedPaymentRequest Model { get; init; } + public required PatchedPaymentRequest Model { get; set; } } diff --git a/src/Merge.Client/Accounting/Payments/Requests/PaymentEndpointRequest.cs b/src/Merge.Client/Accounting/Payments/Requests/PaymentEndpointRequest.cs index 85121305..243ad1e1 100644 --- a/src/Merge.Client/Accounting/Payments/Requests/PaymentEndpointRequest.cs +++ b/src/Merge.Client/Accounting/Payments/Requests/PaymentEndpointRequest.cs @@ -1,20 +1,16 @@ -using Merge.Client.Accounting; - -#nullable enable - namespace Merge.Client.Accounting; -public class PaymentEndpointRequest +public record PaymentEndpointRequest { /// /// Whether to include debug fields (such as log file links) in the response. /// - public bool? IsDebugMode { get; init; } + public bool? IsDebugMode { get; set; } /// /// Whether or not third-party updates should be run asynchronously. /// - public bool? RunAsync { get; init; } + public bool? RunAsync { get; set; } - public PaymentRequest Model { get; init; } + public required PaymentRequest Model { get; set; } } diff --git a/src/Merge.Client/Accounting/Payments/Requests/PaymentsListRequest.cs b/src/Merge.Client/Accounting/Payments/Requests/PaymentsListRequest.cs index 0e9eda2f..83220401 100644 --- a/src/Merge.Client/Accounting/Payments/Requests/PaymentsListRequest.cs +++ b/src/Merge.Client/Accounting/Payments/Requests/PaymentsListRequest.cs @@ -1,83 +1,79 @@ -using Merge.Client.Accounting; - -#nullable enable - namespace Merge.Client.Accounting; -public class PaymentsListRequest +public record PaymentsListRequest { /// /// If provided, will only return payments for this account. /// - public string? AccountId { get; init; } + public string? AccountId { get; set; } /// /// If provided, will only return payments for this company. /// - public string? CompanyId { get; init; } + public string? CompanyId { get; set; } /// /// If provided, will only return payments for this contact. /// - public string? ContactId { get; init; } + public string? ContactId { get; set; } /// /// If provided, will only return objects created after this datetime. /// - public DateTime? CreatedAfter { get; init; } + public DateTime? CreatedAfter { get; set; } /// /// If provided, will only return objects created before this datetime. /// - public DateTime? CreatedBefore { get; init; } + public DateTime? CreatedBefore { get; set; } /// /// The pagination cursor value. /// - public string? Cursor { get; init; } + public string? Cursor { get; set; } /// /// Which relations should be returned in expanded form. Multiple relation names should be comma separated without spaces. /// - public PaymentsListRequestExpand? Expand { get; init; } + public PaymentsListRequestExpand? Expand { get; set; } /// /// Whether to include data that was marked as deleted by third party webhooks. /// - public bool? IncludeDeletedData { get; init; } + public bool? IncludeDeletedData { get; set; } /// /// Whether to include the original data Merge fetched from the third-party to produce these models. /// - public bool? IncludeRemoteData { get; init; } + public bool? IncludeRemoteData { get; set; } /// /// If provided, only objects synced by Merge after this date time will be returned. /// - public DateTime? ModifiedAfter { get; init; } + public DateTime? ModifiedAfter { get; set; } /// /// If provided, only objects synced by Merge before this date time will be returned. /// - public DateTime? ModifiedBefore { get; init; } + public DateTime? ModifiedBefore { get; set; } /// /// Number of results to return per page. /// - public int? PageSize { get; init; } + public int? PageSize { get; set; } /// /// The API provider's ID for the given object. /// - public string? RemoteId { get; init; } + public string? RemoteId { get; set; } /// /// If provided, will only return objects created after this datetime. /// - public DateTime? TransactionDateAfter { get; init; } + public DateTime? TransactionDateAfter { get; set; } /// /// If provided, will only return objects created before this datetime. /// - public DateTime? TransactionDateBefore { get; init; } + public DateTime? TransactionDateBefore { get; set; } } diff --git a/src/Merge.Client/Accounting/Payments/Requests/PaymentsRetrieveRequest.cs b/src/Merge.Client/Accounting/Payments/Requests/PaymentsRetrieveRequest.cs index 087d0efe..4fe797f0 100644 --- a/src/Merge.Client/Accounting/Payments/Requests/PaymentsRetrieveRequest.cs +++ b/src/Merge.Client/Accounting/Payments/Requests/PaymentsRetrieveRequest.cs @@ -1,18 +1,14 @@ -using Merge.Client.Accounting; - -#nullable enable - namespace Merge.Client.Accounting; -public class PaymentsRetrieveRequest +public record PaymentsRetrieveRequest { /// /// Which relations should be returned in expanded form. Multiple relation names should be comma separated without spaces. /// - public PaymentsRetrieveRequestExpand? Expand { get; init; } + public PaymentsRetrieveRequestExpand? Expand { get; set; } /// /// Whether to include the original data Merge fetched from the third-party to produce these models. /// - public bool? IncludeRemoteData { get; init; } + public bool? IncludeRemoteData { get; set; } } diff --git a/src/Merge.Client/Accounting/Payments/Types/PaymentsListRequestExpand.cs b/src/Merge.Client/Accounting/Payments/Types/PaymentsListRequestExpand.cs index 977d071e..a99a67eb 100644 --- a/src/Merge.Client/Accounting/Payments/Types/PaymentsListRequestExpand.cs +++ b/src/Merge.Client/Accounting/Payments/Types/PaymentsListRequestExpand.cs @@ -1,6 +1,5 @@ using System.Runtime.Serialization; using System.Text.Json.Serialization; -using Merge.Client.Accounting; using Merge.Client.Core; #nullable enable diff --git a/src/Merge.Client/Accounting/Payments/Types/PaymentsRetrieveRequestExpand.cs b/src/Merge.Client/Accounting/Payments/Types/PaymentsRetrieveRequestExpand.cs index 99bb88a4..5da5f1c2 100644 --- a/src/Merge.Client/Accounting/Payments/Types/PaymentsRetrieveRequestExpand.cs +++ b/src/Merge.Client/Accounting/Payments/Types/PaymentsRetrieveRequestExpand.cs @@ -1,6 +1,5 @@ using System.Runtime.Serialization; using System.Text.Json.Serialization; -using Merge.Client.Accounting; using Merge.Client.Core; #nullable enable diff --git a/src/Merge.Client/Accounting/PhoneNumbers/PhoneNumbersClient.cs b/src/Merge.Client/Accounting/PhoneNumbers/PhoneNumbersClient.cs index cdc47dfc..202e95da 100644 --- a/src/Merge.Client/Accounting/PhoneNumbers/PhoneNumbersClient.cs +++ b/src/Merge.Client/Accounting/PhoneNumbers/PhoneNumbersClient.cs @@ -1,6 +1,6 @@ +using System.Net.Http; using System.Text.Json; -using Merge.Client; -using Merge.Client.Accounting; +using Merge.Client.Core; #nullable enable @@ -20,7 +20,8 @@ public PhoneNumbersClient(RawClient client) /// public async Task RetrieveAsync( string id, - PhoneNumbersRetrieveRequest request + PhoneNumbersRetrieveRequest request, + RequestOptions? options = null ) { var _query = new Dictionary() { }; @@ -31,16 +32,30 @@ PhoneNumbersRetrieveRequest request var response = await _client.MakeRequestAsync( new RawClient.JsonApiRequest { + BaseUrl = _client.Options.BaseUrl, Method = HttpMethod.Get, Path = $"accounting/v1/phone-numbers/{id}", - Query = _query + Query = _query, + Options = options } ); - string responseBody = await response.Raw.Content.ReadAsStringAsync(); - if (response.StatusCode >= 200 && response.StatusCode < 400) + var responseBody = await response.Raw.Content.ReadAsStringAsync(); + if (response.StatusCode is >= 200 and < 400) { - return JsonSerializer.Deserialize(responseBody); + try + { + return JsonUtils.Deserialize(responseBody)!; + } + catch (JsonException e) + { + throw new MergeException("Failed to deserialize response", e); + } } - throw new Exception(responseBody); + + throw new MergeApiException( + $"Error with status code {response.StatusCode}", + response.StatusCode, + JsonUtils.Deserialize(responseBody) + ); } } diff --git a/src/Merge.Client/Accounting/PhoneNumbers/Requests/PhoneNumbersRetrieveRequest.cs b/src/Merge.Client/Accounting/PhoneNumbers/Requests/PhoneNumbersRetrieveRequest.cs index 944d074d..878ba4bf 100644 --- a/src/Merge.Client/Accounting/PhoneNumbers/Requests/PhoneNumbersRetrieveRequest.cs +++ b/src/Merge.Client/Accounting/PhoneNumbers/Requests/PhoneNumbersRetrieveRequest.cs @@ -1,9 +1,9 @@ namespace Merge.Client.Accounting; -public class PhoneNumbersRetrieveRequest +public record PhoneNumbersRetrieveRequest { /// /// Whether to include the original data Merge fetched from the third-party to produce these models. /// - public bool? IncludeRemoteData { get; init; } + public bool? IncludeRemoteData { get; set; } } diff --git a/src/Merge.Client/Accounting/PurchaseOrders/PurchaseOrdersClient.cs b/src/Merge.Client/Accounting/PurchaseOrders/PurchaseOrdersClient.cs index 70fafa93..b32c6400 100644 --- a/src/Merge.Client/Accounting/PurchaseOrders/PurchaseOrdersClient.cs +++ b/src/Merge.Client/Accounting/PurchaseOrders/PurchaseOrdersClient.cs @@ -1,6 +1,6 @@ +using System.Net.Http; using System.Text.Json; -using Merge.Client; -using Merge.Client.Accounting; +using Merge.Client.Core; #nullable enable @@ -18,7 +18,10 @@ public PurchaseOrdersClient(RawClient client) /// /// Returns a list of `PurchaseOrder` objects. /// - public async Task ListAsync(PurchaseOrdersListRequest request) + public async Task ListAsync( + PurchaseOrdersListRequest request, + RequestOptions? options = null + ) { var _query = new Dictionary() { }; if (request.CompanyId != null) @@ -27,11 +30,13 @@ public async Task ListAsync(PurchaseOrdersListReques } if (request.CreatedAfter != null) { - _query["created_after"] = request.CreatedAfter.Value.ToString("o0"); + _query["created_after"] = request.CreatedAfter.Value.ToString(Constants.DateTimeFormat); } if (request.CreatedBefore != null) { - _query["created_before"] = request.CreatedBefore.Value.ToString("o0"); + _query["created_before"] = request.CreatedBefore.Value.ToString( + Constants.DateTimeFormat + ); } if (request.Cursor != null) { @@ -51,19 +56,27 @@ public async Task ListAsync(PurchaseOrdersListReques } if (request.IssueDateAfter != null) { - _query["issue_date_after"] = request.IssueDateAfter.Value.ToString("o0"); + _query["issue_date_after"] = request.IssueDateAfter.Value.ToString( + Constants.DateTimeFormat + ); } if (request.IssueDateBefore != null) { - _query["issue_date_before"] = request.IssueDateBefore.Value.ToString("o0"); + _query["issue_date_before"] = request.IssueDateBefore.Value.ToString( + Constants.DateTimeFormat + ); } if (request.ModifiedAfter != null) { - _query["modified_after"] = request.ModifiedAfter.Value.ToString("o0"); + _query["modified_after"] = request.ModifiedAfter.Value.ToString( + Constants.DateTimeFormat + ); } if (request.ModifiedBefore != null) { - _query["modified_before"] = request.ModifiedBefore.Value.ToString("o0"); + _query["modified_before"] = request.ModifiedBefore.Value.ToString( + Constants.DateTimeFormat + ); } if (request.PageSize != null) { @@ -84,23 +97,40 @@ public async Task ListAsync(PurchaseOrdersListReques var response = await _client.MakeRequestAsync( new RawClient.JsonApiRequest { + BaseUrl = _client.Options.BaseUrl, Method = HttpMethod.Get, Path = "accounting/v1/purchase-orders", - Query = _query + Query = _query, + Options = options } ); - string responseBody = await response.Raw.Content.ReadAsStringAsync(); - if (response.StatusCode >= 200 && response.StatusCode < 400) + var responseBody = await response.Raw.Content.ReadAsStringAsync(); + if (response.StatusCode is >= 200 and < 400) { - return JsonSerializer.Deserialize(responseBody); + try + { + return JsonUtils.Deserialize(responseBody)!; + } + catch (JsonException e) + { + throw new MergeException("Failed to deserialize response", e); + } } - throw new Exception(responseBody); + + throw new MergeApiException( + $"Error with status code {response.StatusCode}", + response.StatusCode, + JsonUtils.Deserialize(responseBody) + ); } /// /// Creates a `PurchaseOrder` object with the given values. /// - public async Task CreateAsync(PurchaseOrderEndpointRequest request) + public async Task CreateAsync( + PurchaseOrderEndpointRequest request, + RequestOptions? options = null + ) { var _query = new Dictionary() { }; if (request.IsDebugMode != null) @@ -114,23 +144,41 @@ public async Task CreateAsync(PurchaseOrderEndpointReques var response = await _client.MakeRequestAsync( new RawClient.JsonApiRequest { + BaseUrl = _client.Options.BaseUrl, Method = HttpMethod.Post, Path = "accounting/v1/purchase-orders", - Query = _query + Query = _query, + Options = options } ); - string responseBody = await response.Raw.Content.ReadAsStringAsync(); - if (response.StatusCode >= 200 && response.StatusCode < 400) + var responseBody = await response.Raw.Content.ReadAsStringAsync(); + if (response.StatusCode is >= 200 and < 400) { - return JsonSerializer.Deserialize(responseBody); + try + { + return JsonUtils.Deserialize(responseBody)!; + } + catch (JsonException e) + { + throw new MergeException("Failed to deserialize response", e); + } } - throw new Exception(responseBody); + + throw new MergeApiException( + $"Error with status code {response.StatusCode}", + response.StatusCode, + JsonUtils.Deserialize(responseBody) + ); } /// /// Returns a `PurchaseOrder` object with the given `id`. /// - public async Task RetrieveAsync(string id, PurchaseOrdersRetrieveRequest request) + public async Task RetrieveAsync( + string id, + PurchaseOrdersRetrieveRequest request, + RequestOptions? options = null + ) { var _query = new Dictionary() { }; if (request.Expand != null) @@ -152,36 +200,64 @@ public async Task RetrieveAsync(string id, PurchaseOrdersRetrieve var response = await _client.MakeRequestAsync( new RawClient.JsonApiRequest { + BaseUrl = _client.Options.BaseUrl, Method = HttpMethod.Get, Path = $"accounting/v1/purchase-orders/{id}", - Query = _query + Query = _query, + Options = options } ); - string responseBody = await response.Raw.Content.ReadAsStringAsync(); - if (response.StatusCode >= 200 && response.StatusCode < 400) + var responseBody = await response.Raw.Content.ReadAsStringAsync(); + if (response.StatusCode is >= 200 and < 400) { - return JsonSerializer.Deserialize(responseBody); + try + { + return JsonUtils.Deserialize(responseBody)!; + } + catch (JsonException e) + { + throw new MergeException("Failed to deserialize response", e); + } } - throw new Exception(responseBody); + + throw new MergeApiException( + $"Error with status code {response.StatusCode}", + response.StatusCode, + JsonUtils.Deserialize(responseBody) + ); } /// /// Returns metadata for `PurchaseOrder` POSTs. /// - public async Task MetaPostRetrieveAsync() + public async Task MetaPostRetrieveAsync(RequestOptions? options = null) { var response = await _client.MakeRequestAsync( new RawClient.JsonApiRequest { + BaseUrl = _client.Options.BaseUrl, Method = HttpMethod.Get, - Path = "accounting/v1/purchase-orders/meta/post" + Path = "accounting/v1/purchase-orders/meta/post", + Options = options } ); - string responseBody = await response.Raw.Content.ReadAsStringAsync(); - if (response.StatusCode >= 200 && response.StatusCode < 400) + var responseBody = await response.Raw.Content.ReadAsStringAsync(); + if (response.StatusCode is >= 200 and < 400) { - return JsonSerializer.Deserialize(responseBody); + try + { + return JsonUtils.Deserialize(responseBody)!; + } + catch (JsonException e) + { + throw new MergeException("Failed to deserialize response", e); + } } - throw new Exception(responseBody); + + throw new MergeApiException( + $"Error with status code {response.StatusCode}", + response.StatusCode, + JsonUtils.Deserialize(responseBody) + ); } } diff --git a/src/Merge.Client/Accounting/PurchaseOrders/Requests/PurchaseOrderEndpointRequest.cs b/src/Merge.Client/Accounting/PurchaseOrders/Requests/PurchaseOrderEndpointRequest.cs index 3058eeac..d955e537 100644 --- a/src/Merge.Client/Accounting/PurchaseOrders/Requests/PurchaseOrderEndpointRequest.cs +++ b/src/Merge.Client/Accounting/PurchaseOrders/Requests/PurchaseOrderEndpointRequest.cs @@ -1,20 +1,16 @@ -using Merge.Client.Accounting; - -#nullable enable - namespace Merge.Client.Accounting; -public class PurchaseOrderEndpointRequest +public record PurchaseOrderEndpointRequest { /// /// Whether to include debug fields (such as log file links) in the response. /// - public bool? IsDebugMode { get; init; } + public bool? IsDebugMode { get; set; } /// /// Whether or not third-party updates should be run asynchronously. /// - public bool? RunAsync { get; init; } + public bool? RunAsync { get; set; } - public PurchaseOrderRequest Model { get; init; } + public required PurchaseOrderRequest Model { get; set; } } diff --git a/src/Merge.Client/Accounting/PurchaseOrders/Requests/PurchaseOrdersListRequest.cs b/src/Merge.Client/Accounting/PurchaseOrders/Requests/PurchaseOrdersListRequest.cs index 898b44c0..9844f6f4 100644 --- a/src/Merge.Client/Accounting/PurchaseOrders/Requests/PurchaseOrdersListRequest.cs +++ b/src/Merge.Client/Accounting/PurchaseOrders/Requests/PurchaseOrdersListRequest.cs @@ -1,83 +1,79 @@ -using Merge.Client.Accounting; - -#nullable enable - namespace Merge.Client.Accounting; -public class PurchaseOrdersListRequest +public record PurchaseOrdersListRequest { /// /// If provided, will only return purchase orders for this company. /// - public string? CompanyId { get; init; } + public string? CompanyId { get; set; } /// /// If provided, will only return objects created after this datetime. /// - public DateTime? CreatedAfter { get; init; } + public DateTime? CreatedAfter { get; set; } /// /// If provided, will only return objects created before this datetime. /// - public DateTime? CreatedBefore { get; init; } + public DateTime? CreatedBefore { get; set; } /// /// The pagination cursor value. /// - public string? Cursor { get; init; } + public string? Cursor { get; set; } /// /// Which relations should be returned in expanded form. Multiple relation names should be comma separated without spaces. /// - public PurchaseOrdersListRequestExpand? Expand { get; init; } + public PurchaseOrdersListRequestExpand? Expand { get; set; } /// /// Whether to include data that was marked as deleted by third party webhooks. /// - public bool? IncludeDeletedData { get; init; } + public bool? IncludeDeletedData { get; set; } /// /// Whether to include the original data Merge fetched from the third-party to produce these models. /// - public bool? IncludeRemoteData { get; init; } + public bool? IncludeRemoteData { get; set; } /// /// If provided, will only return objects created after this datetime. /// - public DateTime? IssueDateAfter { get; init; } + public DateTime? IssueDateAfter { get; set; } /// /// If provided, will only return objects created before this datetime. /// - public DateTime? IssueDateBefore { get; init; } + public DateTime? IssueDateBefore { get; set; } /// /// If provided, only objects synced by Merge after this date time will be returned. /// - public DateTime? ModifiedAfter { get; init; } + public DateTime? ModifiedAfter { get; set; } /// /// If provided, only objects synced by Merge before this date time will be returned. /// - public DateTime? ModifiedBefore { get; init; } + public DateTime? ModifiedBefore { get; set; } /// /// Number of results to return per page. /// - public int? PageSize { get; init; } + public int? PageSize { get; set; } /// /// Deprecated. Use show_enum_origins. /// - public string? RemoteFields { get; init; } + public string? RemoteFields { get; set; } /// /// The API provider's ID for the given object. /// - public string? RemoteId { get; init; } + public string? RemoteId { get; set; } /// /// A comma separated list of enum field names for which you'd like the original values to be returned, instead of Merge's normalized enum values. [Learn more](https://help.merge.dev/en/articles/8950958-show_enum_origins-query-parameter) /// - public string? ShowEnumOrigins { get; init; } + public string? ShowEnumOrigins { get; set; } } diff --git a/src/Merge.Client/Accounting/PurchaseOrders/Requests/PurchaseOrdersRetrieveRequest.cs b/src/Merge.Client/Accounting/PurchaseOrders/Requests/PurchaseOrdersRetrieveRequest.cs index 2e2256e5..abdfe499 100644 --- a/src/Merge.Client/Accounting/PurchaseOrders/Requests/PurchaseOrdersRetrieveRequest.cs +++ b/src/Merge.Client/Accounting/PurchaseOrders/Requests/PurchaseOrdersRetrieveRequest.cs @@ -1,28 +1,24 @@ -using Merge.Client.Accounting; - -#nullable enable - namespace Merge.Client.Accounting; -public class PurchaseOrdersRetrieveRequest +public record PurchaseOrdersRetrieveRequest { /// /// Which relations should be returned in expanded form. Multiple relation names should be comma separated without spaces. /// - public PurchaseOrdersRetrieveRequestExpand? Expand { get; init; } + public PurchaseOrdersRetrieveRequestExpand? Expand { get; set; } /// /// Whether to include the original data Merge fetched from the third-party to produce these models. /// - public bool? IncludeRemoteData { get; init; } + public bool? IncludeRemoteData { get; set; } /// /// Deprecated. Use show_enum_origins. /// - public string? RemoteFields { get; init; } + public string? RemoteFields { get; set; } /// /// A comma separated list of enum field names for which you'd like the original values to be returned, instead of Merge's normalized enum values. [Learn more](https://help.merge.dev/en/articles/8950958-show_enum_origins-query-parameter) /// - public string? ShowEnumOrigins { get; init; } + public string? ShowEnumOrigins { get; set; } } diff --git a/src/Merge.Client/Accounting/PurchaseOrders/Types/PurchaseOrdersListRequestExpand.cs b/src/Merge.Client/Accounting/PurchaseOrders/Types/PurchaseOrdersListRequestExpand.cs index 359ded3b..28ecabcc 100644 --- a/src/Merge.Client/Accounting/PurchaseOrders/Types/PurchaseOrdersListRequestExpand.cs +++ b/src/Merge.Client/Accounting/PurchaseOrders/Types/PurchaseOrdersListRequestExpand.cs @@ -1,6 +1,5 @@ using System.Runtime.Serialization; using System.Text.Json.Serialization; -using Merge.Client.Accounting; using Merge.Client.Core; #nullable enable diff --git a/src/Merge.Client/Accounting/PurchaseOrders/Types/PurchaseOrdersRetrieveRequestExpand.cs b/src/Merge.Client/Accounting/PurchaseOrders/Types/PurchaseOrdersRetrieveRequestExpand.cs index 40c4066c..a700e7f4 100644 --- a/src/Merge.Client/Accounting/PurchaseOrders/Types/PurchaseOrdersRetrieveRequestExpand.cs +++ b/src/Merge.Client/Accounting/PurchaseOrders/Types/PurchaseOrdersRetrieveRequestExpand.cs @@ -1,6 +1,5 @@ using System.Runtime.Serialization; using System.Text.Json.Serialization; -using Merge.Client.Accounting; using Merge.Client.Core; #nullable enable diff --git a/src/Merge.Client/Accounting/RegenerateKey/RegenerateKeyClient.cs b/src/Merge.Client/Accounting/RegenerateKey/RegenerateKeyClient.cs index 9e6b0e60..0b47457c 100644 --- a/src/Merge.Client/Accounting/RegenerateKey/RegenerateKeyClient.cs +++ b/src/Merge.Client/Accounting/RegenerateKey/RegenerateKeyClient.cs @@ -1,6 +1,6 @@ +using System.Net.Http; using System.Text.Json; -using Merge.Client; -using Merge.Client.Accounting; +using Merge.Client.Core; #nullable enable @@ -18,21 +18,38 @@ public RegenerateKeyClient(RawClient client) /// /// Exchange remote keys. /// - public async Task CreateAsync(RemoteKeyForRegenerationRequest request) + public async Task CreateAsync( + RemoteKeyForRegenerationRequest request, + RequestOptions? options = null + ) { var response = await _client.MakeRequestAsync( new RawClient.JsonApiRequest { + BaseUrl = _client.Options.BaseUrl, Method = HttpMethod.Post, Path = "accounting/v1/regenerate-key", - Body = request + Body = request, + Options = options } ); - string responseBody = await response.Raw.Content.ReadAsStringAsync(); - if (response.StatusCode >= 200 && response.StatusCode < 400) + var responseBody = await response.Raw.Content.ReadAsStringAsync(); + if (response.StatusCode is >= 200 and < 400) { - return JsonSerializer.Deserialize(responseBody); + try + { + return JsonUtils.Deserialize(responseBody)!; + } + catch (JsonException e) + { + throw new MergeException("Failed to deserialize response", e); + } } - throw new Exception(responseBody); + + throw new MergeApiException( + $"Error with status code {response.StatusCode}", + response.StatusCode, + JsonUtils.Deserialize(responseBody) + ); } } diff --git a/src/Merge.Client/Accounting/RegenerateKey/Requests/RemoteKeyForRegenerationRequest.cs b/src/Merge.Client/Accounting/RegenerateKey/Requests/RemoteKeyForRegenerationRequest.cs index 16fbf276..6e473f9e 100644 --- a/src/Merge.Client/Accounting/RegenerateKey/Requests/RemoteKeyForRegenerationRequest.cs +++ b/src/Merge.Client/Accounting/RegenerateKey/Requests/RemoteKeyForRegenerationRequest.cs @@ -4,11 +4,11 @@ namespace Merge.Client.Accounting; -public class RemoteKeyForRegenerationRequest +public record RemoteKeyForRegenerationRequest { /// /// The name of the remote key /// [JsonPropertyName("name")] - public string Name { get; init; } + public required string Name { get; set; } } diff --git a/src/Merge.Client/Accounting/Scopes/Requests/LinkedAccountCommonModelScopeDeserializerRequest.cs b/src/Merge.Client/Accounting/Scopes/Requests/LinkedAccountCommonModelScopeDeserializerRequest.cs index 324f5fc0..99cf40bf 100644 --- a/src/Merge.Client/Accounting/Scopes/Requests/LinkedAccountCommonModelScopeDeserializerRequest.cs +++ b/src/Merge.Client/Accounting/Scopes/Requests/LinkedAccountCommonModelScopeDeserializerRequest.cs @@ -1,15 +1,15 @@ using System.Text.Json.Serialization; -using Merge.Client.Accounting; #nullable enable namespace Merge.Client.Accounting; -public class LinkedAccountCommonModelScopeDeserializerRequest +public record LinkedAccountCommonModelScopeDeserializerRequest { /// /// The common models you want to update the scopes for /// [JsonPropertyName("common_models")] - public IEnumerable CommonModels { get; init; } + public IEnumerable CommonModels { get; set; } = + new List(); } diff --git a/src/Merge.Client/Accounting/Scopes/ScopesClient.cs b/src/Merge.Client/Accounting/Scopes/ScopesClient.cs index 0750e4ee..9f886a49 100644 --- a/src/Merge.Client/Accounting/Scopes/ScopesClient.cs +++ b/src/Merge.Client/Accounting/Scopes/ScopesClient.cs @@ -1,6 +1,6 @@ +using System.Net.Http; using System.Text.Json; -using Merge.Client; -using Merge.Client.Accounting; +using Merge.Client.Core; #nullable enable @@ -18,63 +18,110 @@ public ScopesClient(RawClient client) /// /// Get the default permissions for Merge Common Models and fields across all Linked Accounts of a given category. [Learn more](https://help.merge.dev/en/articles/8828211-common-model-and-field-scopes). /// - public async Task DefaultScopesRetrieveAsync() + public async Task DefaultScopesRetrieveAsync( + RequestOptions? options = null + ) { var response = await _client.MakeRequestAsync( new RawClient.JsonApiRequest { + BaseUrl = _client.Options.BaseUrl, Method = HttpMethod.Get, - Path = "accounting/v1/default-scopes" + Path = "accounting/v1/default-scopes", + Options = options } ); - string responseBody = await response.Raw.Content.ReadAsStringAsync(); - if (response.StatusCode >= 200 && response.StatusCode < 400) + var responseBody = await response.Raw.Content.ReadAsStringAsync(); + if (response.StatusCode is >= 200 and < 400) { - return JsonSerializer.Deserialize(responseBody); + try + { + return JsonUtils.Deserialize(responseBody)!; + } + catch (JsonException e) + { + throw new MergeException("Failed to deserialize response", e); + } } - throw new Exception(responseBody); + + throw new MergeApiException( + $"Error with status code {response.StatusCode}", + response.StatusCode, + JsonUtils.Deserialize(responseBody) + ); } /// /// Get all available permissions for Merge Common Models and fields for a single Linked Account. [Learn more](https://help.merge.dev/en/articles/8828211-common-model-and-field-scopes). /// - public async Task LinkedAccountScopesRetrieveAsync() + public async Task LinkedAccountScopesRetrieveAsync( + RequestOptions? options = null + ) { var response = await _client.MakeRequestAsync( new RawClient.JsonApiRequest { + BaseUrl = _client.Options.BaseUrl, Method = HttpMethod.Get, - Path = "accounting/v1/linked-account-scopes" + Path = "accounting/v1/linked-account-scopes", + Options = options } ); - string responseBody = await response.Raw.Content.ReadAsStringAsync(); - if (response.StatusCode >= 200 && response.StatusCode < 400) + var responseBody = await response.Raw.Content.ReadAsStringAsync(); + if (response.StatusCode is >= 200 and < 400) { - return JsonSerializer.Deserialize(responseBody); + try + { + return JsonUtils.Deserialize(responseBody)!; + } + catch (JsonException e) + { + throw new MergeException("Failed to deserialize response", e); + } } - throw new Exception(responseBody); + + throw new MergeApiException( + $"Error with status code {response.StatusCode}", + response.StatusCode, + JsonUtils.Deserialize(responseBody) + ); } /// /// Update permissions for any Common Model or field for a single Linked Account. Any Scopes not set in this POST request will inherit the default Scopes. [Learn more](https://help.merge.dev/en/articles/8828211-common-model-and-field-scopes) /// public async Task LinkedAccountScopesCreateAsync( - LinkedAccountCommonModelScopeDeserializerRequest request + LinkedAccountCommonModelScopeDeserializerRequest request, + RequestOptions? options = null ) { var response = await _client.MakeRequestAsync( new RawClient.JsonApiRequest { + BaseUrl = _client.Options.BaseUrl, Method = HttpMethod.Post, Path = "accounting/v1/linked-account-scopes", - Body = request + Body = request, + Options = options } ); - string responseBody = await response.Raw.Content.ReadAsStringAsync(); - if (response.StatusCode >= 200 && response.StatusCode < 400) + var responseBody = await response.Raw.Content.ReadAsStringAsync(); + if (response.StatusCode is >= 200 and < 400) { - return JsonSerializer.Deserialize(responseBody); + try + { + return JsonUtils.Deserialize(responseBody)!; + } + catch (JsonException e) + { + throw new MergeException("Failed to deserialize response", e); + } } - throw new Exception(responseBody); + + throw new MergeApiException( + $"Error with status code {response.StatusCode}", + response.StatusCode, + JsonUtils.Deserialize(responseBody) + ); } } diff --git a/src/Merge.Client/Accounting/SyncStatus/Requests/SyncStatusListRequest.cs b/src/Merge.Client/Accounting/SyncStatus/Requests/SyncStatusListRequest.cs index 9a5b206f..ec6ded18 100644 --- a/src/Merge.Client/Accounting/SyncStatus/Requests/SyncStatusListRequest.cs +++ b/src/Merge.Client/Accounting/SyncStatus/Requests/SyncStatusListRequest.cs @@ -1,14 +1,14 @@ namespace Merge.Client.Accounting; -public class SyncStatusListRequest +public record SyncStatusListRequest { /// /// The pagination cursor value. /// - public string? Cursor { get; init; } + public string? Cursor { get; set; } /// /// Number of results to return per page. /// - public int? PageSize { get; init; } + public int? PageSize { get; set; } } diff --git a/src/Merge.Client/Accounting/SyncStatus/SyncStatusClient.cs b/src/Merge.Client/Accounting/SyncStatus/SyncStatusClient.cs index c431be4a..f95c9375 100644 --- a/src/Merge.Client/Accounting/SyncStatus/SyncStatusClient.cs +++ b/src/Merge.Client/Accounting/SyncStatus/SyncStatusClient.cs @@ -1,6 +1,6 @@ +using System.Net.Http; using System.Text.Json; -using Merge.Client; -using Merge.Client.Accounting; +using Merge.Client.Core; #nullable enable @@ -18,7 +18,10 @@ public SyncStatusClient(RawClient client) /// /// Get syncing status. Possible values: `DISABLED`, `DONE`, `FAILED`, `PARTIALLY_SYNCED`, `PAUSED`, `SYNCING`. Learn more about sync status in our [Help Center](https://help.merge.dev/en/articles/8184193-merge-sync-statuses). /// - public async Task ListAsync(SyncStatusListRequest request) + public async Task ListAsync( + SyncStatusListRequest request, + RequestOptions? options = null + ) { var _query = new Dictionary() { }; if (request.Cursor != null) @@ -32,16 +35,30 @@ public async Task ListAsync(SyncStatusListRequest reque var response = await _client.MakeRequestAsync( new RawClient.JsonApiRequest { + BaseUrl = _client.Options.BaseUrl, Method = HttpMethod.Get, Path = "accounting/v1/sync-status", - Query = _query + Query = _query, + Options = options } ); - string responseBody = await response.Raw.Content.ReadAsStringAsync(); - if (response.StatusCode >= 200 && response.StatusCode < 400) + var responseBody = await response.Raw.Content.ReadAsStringAsync(); + if (response.StatusCode is >= 200 and < 400) { - return JsonSerializer.Deserialize(responseBody); + try + { + return JsonUtils.Deserialize(responseBody)!; + } + catch (JsonException e) + { + throw new MergeException("Failed to deserialize response", e); + } } - throw new Exception(responseBody); + + throw new MergeApiException( + $"Error with status code {response.StatusCode}", + response.StatusCode, + JsonUtils.Deserialize(responseBody) + ); } } diff --git a/src/Merge.Client/Accounting/TaxRates/Requests/TaxRatesListRequest.cs b/src/Merge.Client/Accounting/TaxRates/Requests/TaxRatesListRequest.cs index 6e83cdc8..7a5e16b6 100644 --- a/src/Merge.Client/Accounting/TaxRates/Requests/TaxRatesListRequest.cs +++ b/src/Merge.Client/Accounting/TaxRates/Requests/TaxRatesListRequest.cs @@ -1,59 +1,59 @@ namespace Merge.Client.Accounting; -public class TaxRatesListRequest +public record TaxRatesListRequest { /// /// If provided, will only return tax rates for this company. /// - public string? CompanyId { get; init; } + public string? CompanyId { get; set; } /// /// If provided, will only return objects created after this datetime. /// - public DateTime? CreatedAfter { get; init; } + public DateTime? CreatedAfter { get; set; } /// /// If provided, will only return objects created before this datetime. /// - public DateTime? CreatedBefore { get; init; } + public DateTime? CreatedBefore { get; set; } /// /// The pagination cursor value. /// - public string? Cursor { get; init; } + public string? Cursor { get; set; } /// /// Which relations should be returned in expanded form. Multiple relation names should be comma separated without spaces. /// - public string? Expand { get; init; } + public string? Expand { get; set; } /// /// Whether to include data that was marked as deleted by third party webhooks. /// - public bool? IncludeDeletedData { get; init; } + public bool? IncludeDeletedData { get; set; } /// /// Whether to include the original data Merge fetched from the third-party to produce these models. /// - public bool? IncludeRemoteData { get; init; } + public bool? IncludeRemoteData { get; set; } /// /// If provided, only objects synced by Merge after this date time will be returned. /// - public DateTime? ModifiedAfter { get; init; } + public DateTime? ModifiedAfter { get; set; } /// /// If provided, only objects synced by Merge before this date time will be returned. /// - public DateTime? ModifiedBefore { get; init; } + public DateTime? ModifiedBefore { get; set; } /// /// Number of results to return per page. /// - public int? PageSize { get; init; } + public int? PageSize { get; set; } /// /// The API provider's ID for the given object. /// - public string? RemoteId { get; init; } + public string? RemoteId { get; set; } } diff --git a/src/Merge.Client/Accounting/TaxRates/Requests/TaxRatesRetrieveRequest.cs b/src/Merge.Client/Accounting/TaxRates/Requests/TaxRatesRetrieveRequest.cs index c866feb4..5572dc83 100644 --- a/src/Merge.Client/Accounting/TaxRates/Requests/TaxRatesRetrieveRequest.cs +++ b/src/Merge.Client/Accounting/TaxRates/Requests/TaxRatesRetrieveRequest.cs @@ -1,14 +1,14 @@ namespace Merge.Client.Accounting; -public class TaxRatesRetrieveRequest +public record TaxRatesRetrieveRequest { /// /// Which relations should be returned in expanded form. Multiple relation names should be comma separated without spaces. /// - public string? Expand { get; init; } + public string? Expand { get; set; } /// /// Whether to include the original data Merge fetched from the third-party to produce these models. /// - public bool? IncludeRemoteData { get; init; } + public bool? IncludeRemoteData { get; set; } } diff --git a/src/Merge.Client/Accounting/TaxRates/TaxRatesClient.cs b/src/Merge.Client/Accounting/TaxRates/TaxRatesClient.cs index f1019f96..c8460518 100644 --- a/src/Merge.Client/Accounting/TaxRates/TaxRatesClient.cs +++ b/src/Merge.Client/Accounting/TaxRates/TaxRatesClient.cs @@ -1,6 +1,6 @@ +using System.Net.Http; using System.Text.Json; -using Merge.Client; -using Merge.Client.Accounting; +using Merge.Client.Core; #nullable enable @@ -18,7 +18,10 @@ public TaxRatesClient(RawClient client) /// /// Returns a list of `TaxRate` objects. /// - public async Task ListAsync(TaxRatesListRequest request) + public async Task ListAsync( + TaxRatesListRequest request, + RequestOptions? options = null + ) { var _query = new Dictionary() { }; if (request.CompanyId != null) @@ -27,11 +30,13 @@ public async Task ListAsync(TaxRatesListRequest request) } if (request.CreatedAfter != null) { - _query["created_after"] = request.CreatedAfter.Value.ToString("o0"); + _query["created_after"] = request.CreatedAfter.Value.ToString(Constants.DateTimeFormat); } if (request.CreatedBefore != null) { - _query["created_before"] = request.CreatedBefore.Value.ToString("o0"); + _query["created_before"] = request.CreatedBefore.Value.ToString( + Constants.DateTimeFormat + ); } if (request.Cursor != null) { @@ -51,11 +56,15 @@ public async Task ListAsync(TaxRatesListRequest request) } if (request.ModifiedAfter != null) { - _query["modified_after"] = request.ModifiedAfter.Value.ToString("o0"); + _query["modified_after"] = request.ModifiedAfter.Value.ToString( + Constants.DateTimeFormat + ); } if (request.ModifiedBefore != null) { - _query["modified_before"] = request.ModifiedBefore.Value.ToString("o0"); + _query["modified_before"] = request.ModifiedBefore.Value.ToString( + Constants.DateTimeFormat + ); } if (request.PageSize != null) { @@ -68,23 +77,41 @@ public async Task ListAsync(TaxRatesListRequest request) var response = await _client.MakeRequestAsync( new RawClient.JsonApiRequest { + BaseUrl = _client.Options.BaseUrl, Method = HttpMethod.Get, Path = "accounting/v1/tax-rates", - Query = _query + Query = _query, + Options = options } ); - string responseBody = await response.Raw.Content.ReadAsStringAsync(); - if (response.StatusCode >= 200 && response.StatusCode < 400) + var responseBody = await response.Raw.Content.ReadAsStringAsync(); + if (response.StatusCode is >= 200 and < 400) { - return JsonSerializer.Deserialize(responseBody); + try + { + return JsonUtils.Deserialize(responseBody)!; + } + catch (JsonException e) + { + throw new MergeException("Failed to deserialize response", e); + } } - throw new Exception(responseBody); + + throw new MergeApiException( + $"Error with status code {response.StatusCode}", + response.StatusCode, + JsonUtils.Deserialize(responseBody) + ); } /// /// Returns a `TaxRate` object with the given `id`. /// - public async Task RetrieveAsync(string id, TaxRatesRetrieveRequest request) + public async Task RetrieveAsync( + string id, + TaxRatesRetrieveRequest request, + RequestOptions? options = null + ) { var _query = new Dictionary() { }; if (request.Expand != null) @@ -98,16 +125,30 @@ public async Task RetrieveAsync(string id, TaxRatesRetrieveRequest requ var response = await _client.MakeRequestAsync( new RawClient.JsonApiRequest { + BaseUrl = _client.Options.BaseUrl, Method = HttpMethod.Get, Path = $"accounting/v1/tax-rates/{id}", - Query = _query + Query = _query, + Options = options } ); - string responseBody = await response.Raw.Content.ReadAsStringAsync(); - if (response.StatusCode >= 200 && response.StatusCode < 400) + var responseBody = await response.Raw.Content.ReadAsStringAsync(); + if (response.StatusCode is >= 200 and < 400) { - return JsonSerializer.Deserialize(responseBody); + try + { + return JsonUtils.Deserialize(responseBody)!; + } + catch (JsonException e) + { + throw new MergeException("Failed to deserialize response", e); + } } - throw new Exception(responseBody); + + throw new MergeApiException( + $"Error with status code {response.StatusCode}", + response.StatusCode, + JsonUtils.Deserialize(responseBody) + ); } } diff --git a/src/Merge.Client/Accounting/TrackingCategories/Requests/TrackingCategoriesListRequest.cs b/src/Merge.Client/Accounting/TrackingCategories/Requests/TrackingCategoriesListRequest.cs index 93cf69c4..8818b9e2 100644 --- a/src/Merge.Client/Accounting/TrackingCategories/Requests/TrackingCategoriesListRequest.cs +++ b/src/Merge.Client/Accounting/TrackingCategories/Requests/TrackingCategoriesListRequest.cs @@ -1,69 +1,69 @@ namespace Merge.Client.Accounting; -public class TrackingCategoriesListRequest +public record TrackingCategoriesListRequest { /// /// If provided, will only return tracking categories for this company. /// - public string? CompanyId { get; init; } + public string? CompanyId { get; set; } /// /// If provided, will only return objects created after this datetime. /// - public DateTime? CreatedAfter { get; init; } + public DateTime? CreatedAfter { get; set; } /// /// If provided, will only return objects created before this datetime. /// - public DateTime? CreatedBefore { get; init; } + public DateTime? CreatedBefore { get; set; } /// /// The pagination cursor value. /// - public string? Cursor { get; init; } + public string? Cursor { get; set; } /// /// Which relations should be returned in expanded form. Multiple relation names should be comma separated without spaces. /// - public string? Expand { get; init; } + public string? Expand { get; set; } /// /// Whether to include data that was marked as deleted by third party webhooks. /// - public bool? IncludeDeletedData { get; init; } + public bool? IncludeDeletedData { get; set; } /// /// Whether to include the original data Merge fetched from the third-party to produce these models. /// - public bool? IncludeRemoteData { get; init; } + public bool? IncludeRemoteData { get; set; } /// /// If provided, only objects synced by Merge after this date time will be returned. /// - public DateTime? ModifiedAfter { get; init; } + public DateTime? ModifiedAfter { get; set; } /// /// If provided, only objects synced by Merge before this date time will be returned. /// - public DateTime? ModifiedBefore { get; init; } + public DateTime? ModifiedBefore { get; set; } /// /// Number of results to return per page. /// - public int? PageSize { get; init; } + public int? PageSize { get; set; } /// /// Deprecated. Use show_enum_origins. /// - public string? RemoteFields { get; init; } + public string? RemoteFields { get; set; } /// /// The API provider's ID for the given object. /// - public string? RemoteId { get; init; } + public string? RemoteId { get; set; } /// /// A comma separated list of enum field names for which you'd like the original values to be returned, instead of Merge's normalized enum values. [Learn more](https://help.merge.dev/en/articles/8950958-show_enum_origins-query-parameter) /// - public string? ShowEnumOrigins { get; init; } + public string? ShowEnumOrigins { get; set; } } diff --git a/src/Merge.Client/Accounting/TrackingCategories/Requests/TrackingCategoriesRetrieveRequest.cs b/src/Merge.Client/Accounting/TrackingCategories/Requests/TrackingCategoriesRetrieveRequest.cs index 59c36c19..51c05160 100644 --- a/src/Merge.Client/Accounting/TrackingCategories/Requests/TrackingCategoriesRetrieveRequest.cs +++ b/src/Merge.Client/Accounting/TrackingCategories/Requests/TrackingCategoriesRetrieveRequest.cs @@ -1,24 +1,24 @@ namespace Merge.Client.Accounting; -public class TrackingCategoriesRetrieveRequest +public record TrackingCategoriesRetrieveRequest { /// /// Which relations should be returned in expanded form. Multiple relation names should be comma separated without spaces. /// - public string? Expand { get; init; } + public string? Expand { get; set; } /// /// Whether to include the original data Merge fetched from the third-party to produce these models. /// - public bool? IncludeRemoteData { get; init; } + public bool? IncludeRemoteData { get; set; } /// /// Deprecated. Use show_enum_origins. /// - public string? RemoteFields { get; init; } + public string? RemoteFields { get; set; } /// /// A comma separated list of enum field names for which you'd like the original values to be returned, instead of Merge's normalized enum values. [Learn more](https://help.merge.dev/en/articles/8950958-show_enum_origins-query-parameter) /// - public string? ShowEnumOrigins { get; init; } + public string? ShowEnumOrigins { get; set; } } diff --git a/src/Merge.Client/Accounting/TrackingCategories/TrackingCategoriesClient.cs b/src/Merge.Client/Accounting/TrackingCategories/TrackingCategoriesClient.cs index 70f03ece..4748e61b 100644 --- a/src/Merge.Client/Accounting/TrackingCategories/TrackingCategoriesClient.cs +++ b/src/Merge.Client/Accounting/TrackingCategories/TrackingCategoriesClient.cs @@ -1,6 +1,6 @@ +using System.Net.Http; using System.Text.Json; -using Merge.Client; -using Merge.Client.Accounting; +using Merge.Client.Core; #nullable enable @@ -19,7 +19,8 @@ public TrackingCategoriesClient(RawClient client) /// Returns a list of `TrackingCategory` objects. /// public async Task ListAsync( - TrackingCategoriesListRequest request + TrackingCategoriesListRequest request, + RequestOptions? options = null ) { var _query = new Dictionary() { }; @@ -29,11 +30,13 @@ TrackingCategoriesListRequest request } if (request.CreatedAfter != null) { - _query["created_after"] = request.CreatedAfter.Value.ToString("o0"); + _query["created_after"] = request.CreatedAfter.Value.ToString(Constants.DateTimeFormat); } if (request.CreatedBefore != null) { - _query["created_before"] = request.CreatedBefore.Value.ToString("o0"); + _query["created_before"] = request.CreatedBefore.Value.ToString( + Constants.DateTimeFormat + ); } if (request.Cursor != null) { @@ -53,11 +56,15 @@ TrackingCategoriesListRequest request } if (request.ModifiedAfter != null) { - _query["modified_after"] = request.ModifiedAfter.Value.ToString("o0"); + _query["modified_after"] = request.ModifiedAfter.Value.ToString( + Constants.DateTimeFormat + ); } if (request.ModifiedBefore != null) { - _query["modified_before"] = request.ModifiedBefore.Value.ToString("o0"); + _query["modified_before"] = request.ModifiedBefore.Value.ToString( + Constants.DateTimeFormat + ); } if (request.PageSize != null) { @@ -78,17 +85,31 @@ TrackingCategoriesListRequest request var response = await _client.MakeRequestAsync( new RawClient.JsonApiRequest { + BaseUrl = _client.Options.BaseUrl, Method = HttpMethod.Get, Path = "accounting/v1/tracking-categories", - Query = _query + Query = _query, + Options = options } ); - string responseBody = await response.Raw.Content.ReadAsStringAsync(); - if (response.StatusCode >= 200 && response.StatusCode < 400) + var responseBody = await response.Raw.Content.ReadAsStringAsync(); + if (response.StatusCode is >= 200 and < 400) { - return JsonSerializer.Deserialize(responseBody); + try + { + return JsonUtils.Deserialize(responseBody)!; + } + catch (JsonException e) + { + throw new MergeException("Failed to deserialize response", e); + } } - throw new Exception(responseBody); + + throw new MergeApiException( + $"Error with status code {response.StatusCode}", + response.StatusCode, + JsonUtils.Deserialize(responseBody) + ); } /// @@ -96,7 +117,8 @@ TrackingCategoriesListRequest request /// public async Task RetrieveAsync( string id, - TrackingCategoriesRetrieveRequest request + TrackingCategoriesRetrieveRequest request, + RequestOptions? options = null ) { var _query = new Dictionary() { }; @@ -119,16 +141,30 @@ TrackingCategoriesRetrieveRequest request var response = await _client.MakeRequestAsync( new RawClient.JsonApiRequest { + BaseUrl = _client.Options.BaseUrl, Method = HttpMethod.Get, Path = $"accounting/v1/tracking-categories/{id}", - Query = _query + Query = _query, + Options = options } ); - string responseBody = await response.Raw.Content.ReadAsStringAsync(); - if (response.StatusCode >= 200 && response.StatusCode < 400) + var responseBody = await response.Raw.Content.ReadAsStringAsync(); + if (response.StatusCode is >= 200 and < 400) { - return JsonSerializer.Deserialize(responseBody); + try + { + return JsonUtils.Deserialize(responseBody)!; + } + catch (JsonException e) + { + throw new MergeException("Failed to deserialize response", e); + } } - throw new Exception(responseBody); + + throw new MergeApiException( + $"Error with status code {response.StatusCode}", + response.StatusCode, + JsonUtils.Deserialize(responseBody) + ); } } diff --git a/src/Merge.Client/Accounting/Transactions/Requests/TransactionsListRequest.cs b/src/Merge.Client/Accounting/Transactions/Requests/TransactionsListRequest.cs index 9d55ed25..2c30363b 100644 --- a/src/Merge.Client/Accounting/Transactions/Requests/TransactionsListRequest.cs +++ b/src/Merge.Client/Accounting/Transactions/Requests/TransactionsListRequest.cs @@ -1,73 +1,69 @@ -using Merge.Client.Accounting; - -#nullable enable - namespace Merge.Client.Accounting; -public class TransactionsListRequest +public record TransactionsListRequest { /// /// If provided, will only return accounting transactions for this company. /// - public string? CompanyId { get; init; } + public string? CompanyId { get; set; } /// /// If provided, will only return objects created after this datetime. /// - public DateTime? CreatedAfter { get; init; } + public DateTime? CreatedAfter { get; set; } /// /// If provided, will only return objects created before this datetime. /// - public DateTime? CreatedBefore { get; init; } + public DateTime? CreatedBefore { get; set; } /// /// The pagination cursor value. /// - public string? Cursor { get; init; } + public string? Cursor { get; set; } /// /// Which relations should be returned in expanded form. Multiple relation names should be comma separated without spaces. /// - public TransactionsListRequestExpand? Expand { get; init; } + public TransactionsListRequestExpand? Expand { get; set; } /// /// Whether to include data that was marked as deleted by third party webhooks. /// - public bool? IncludeDeletedData { get; init; } + public bool? IncludeDeletedData { get; set; } /// /// Whether to include the original data Merge fetched from the third-party to produce these models. /// - public bool? IncludeRemoteData { get; init; } + public bool? IncludeRemoteData { get; set; } /// /// If provided, only objects synced by Merge after this date time will be returned. /// - public DateTime? ModifiedAfter { get; init; } + public DateTime? ModifiedAfter { get; set; } /// /// If provided, only objects synced by Merge before this date time will be returned. /// - public DateTime? ModifiedBefore { get; init; } + public DateTime? ModifiedBefore { get; set; } /// /// Number of results to return per page. /// - public int? PageSize { get; init; } + public int? PageSize { get; set; } /// /// The API provider's ID for the given object. /// - public string? RemoteId { get; init; } + public string? RemoteId { get; set; } /// /// If provided, will only return objects created after this datetime. /// - public DateTime? TransactionDateAfter { get; init; } + public DateTime? TransactionDateAfter { get; set; } /// /// If provided, will only return objects created before this datetime. /// - public DateTime? TransactionDateBefore { get; init; } + public DateTime? TransactionDateBefore { get; set; } } diff --git a/src/Merge.Client/Accounting/Transactions/Requests/TransactionsRetrieveRequest.cs b/src/Merge.Client/Accounting/Transactions/Requests/TransactionsRetrieveRequest.cs index c7419abb..cf27597a 100644 --- a/src/Merge.Client/Accounting/Transactions/Requests/TransactionsRetrieveRequest.cs +++ b/src/Merge.Client/Accounting/Transactions/Requests/TransactionsRetrieveRequest.cs @@ -1,18 +1,14 @@ -using Merge.Client.Accounting; - -#nullable enable - namespace Merge.Client.Accounting; -public class TransactionsRetrieveRequest +public record TransactionsRetrieveRequest { /// /// Which relations should be returned in expanded form. Multiple relation names should be comma separated without spaces. /// - public TransactionsRetrieveRequestExpand? Expand { get; init; } + public TransactionsRetrieveRequestExpand? Expand { get; set; } /// /// Whether to include the original data Merge fetched from the third-party to produce these models. /// - public bool? IncludeRemoteData { get; init; } + public bool? IncludeRemoteData { get; set; } } diff --git a/src/Merge.Client/Accounting/Transactions/TransactionsClient.cs b/src/Merge.Client/Accounting/Transactions/TransactionsClient.cs index 60c67187..08c7618d 100644 --- a/src/Merge.Client/Accounting/Transactions/TransactionsClient.cs +++ b/src/Merge.Client/Accounting/Transactions/TransactionsClient.cs @@ -1,6 +1,6 @@ +using System.Net.Http; using System.Text.Json; -using Merge.Client; -using Merge.Client.Accounting; +using Merge.Client.Core; #nullable enable @@ -18,7 +18,10 @@ public TransactionsClient(RawClient client) /// /// Returns a list of `Transaction` objects. /// - public async Task ListAsync(TransactionsListRequest request) + public async Task ListAsync( + TransactionsListRequest request, + RequestOptions? options = null + ) { var _query = new Dictionary() { }; if (request.CompanyId != null) @@ -27,11 +30,13 @@ public async Task ListAsync(TransactionsListRequest re } if (request.CreatedAfter != null) { - _query["created_after"] = request.CreatedAfter.Value.ToString("o0"); + _query["created_after"] = request.CreatedAfter.Value.ToString(Constants.DateTimeFormat); } if (request.CreatedBefore != null) { - _query["created_before"] = request.CreatedBefore.Value.ToString("o0"); + _query["created_before"] = request.CreatedBefore.Value.ToString( + Constants.DateTimeFormat + ); } if (request.Cursor != null) { @@ -51,11 +56,15 @@ public async Task ListAsync(TransactionsListRequest re } if (request.ModifiedAfter != null) { - _query["modified_after"] = request.ModifiedAfter.Value.ToString("o0"); + _query["modified_after"] = request.ModifiedAfter.Value.ToString( + Constants.DateTimeFormat + ); } if (request.ModifiedBefore != null) { - _query["modified_before"] = request.ModifiedBefore.Value.ToString("o0"); + _query["modified_before"] = request.ModifiedBefore.Value.ToString( + Constants.DateTimeFormat + ); } if (request.PageSize != null) { @@ -67,32 +76,54 @@ public async Task ListAsync(TransactionsListRequest re } if (request.TransactionDateAfter != null) { - _query["transaction_date_after"] = request.TransactionDateAfter.Value.ToString("o0"); + _query["transaction_date_after"] = request.TransactionDateAfter.Value.ToString( + Constants.DateTimeFormat + ); } if (request.TransactionDateBefore != null) { - _query["transaction_date_before"] = request.TransactionDateBefore.Value.ToString("o0"); + _query["transaction_date_before"] = request.TransactionDateBefore.Value.ToString( + Constants.DateTimeFormat + ); } var response = await _client.MakeRequestAsync( new RawClient.JsonApiRequest { + BaseUrl = _client.Options.BaseUrl, Method = HttpMethod.Get, Path = "accounting/v1/transactions", - Query = _query + Query = _query, + Options = options } ); - string responseBody = await response.Raw.Content.ReadAsStringAsync(); - if (response.StatusCode >= 200 && response.StatusCode < 400) + var responseBody = await response.Raw.Content.ReadAsStringAsync(); + if (response.StatusCode is >= 200 and < 400) { - return JsonSerializer.Deserialize(responseBody); + try + { + return JsonUtils.Deserialize(responseBody)!; + } + catch (JsonException e) + { + throw new MergeException("Failed to deserialize response", e); + } } - throw new Exception(responseBody); + + throw new MergeApiException( + $"Error with status code {response.StatusCode}", + response.StatusCode, + JsonUtils.Deserialize(responseBody) + ); } /// /// Returns a `Transaction` object with the given `id`. /// - public async Task RetrieveAsync(string id, TransactionsRetrieveRequest request) + public async Task RetrieveAsync( + string id, + TransactionsRetrieveRequest request, + RequestOptions? options = null + ) { var _query = new Dictionary() { }; if (request.Expand != null) @@ -106,16 +137,30 @@ public async Task RetrieveAsync(string id, TransactionsRetrieveRequ var response = await _client.MakeRequestAsync( new RawClient.JsonApiRequest { + BaseUrl = _client.Options.BaseUrl, Method = HttpMethod.Get, Path = $"accounting/v1/transactions/{id}", - Query = _query + Query = _query, + Options = options } ); - string responseBody = await response.Raw.Content.ReadAsStringAsync(); - if (response.StatusCode >= 200 && response.StatusCode < 400) + var responseBody = await response.Raw.Content.ReadAsStringAsync(); + if (response.StatusCode is >= 200 and < 400) { - return JsonSerializer.Deserialize(responseBody); + try + { + return JsonUtils.Deserialize(responseBody)!; + } + catch (JsonException e) + { + throw new MergeException("Failed to deserialize response", e); + } } - throw new Exception(responseBody); + + throw new MergeApiException( + $"Error with status code {response.StatusCode}", + response.StatusCode, + JsonUtils.Deserialize(responseBody) + ); } } diff --git a/src/Merge.Client/Accounting/Transactions/Types/TransactionsListRequestExpand.cs b/src/Merge.Client/Accounting/Transactions/Types/TransactionsListRequestExpand.cs index 36261437..6ba5ec5a 100644 --- a/src/Merge.Client/Accounting/Transactions/Types/TransactionsListRequestExpand.cs +++ b/src/Merge.Client/Accounting/Transactions/Types/TransactionsListRequestExpand.cs @@ -1,6 +1,5 @@ using System.Runtime.Serialization; using System.Text.Json.Serialization; -using Merge.Client.Accounting; using Merge.Client.Core; #nullable enable diff --git a/src/Merge.Client/Accounting/Transactions/Types/TransactionsRetrieveRequestExpand.cs b/src/Merge.Client/Accounting/Transactions/Types/TransactionsRetrieveRequestExpand.cs index 7c35037b..372d78d0 100644 --- a/src/Merge.Client/Accounting/Transactions/Types/TransactionsRetrieveRequestExpand.cs +++ b/src/Merge.Client/Accounting/Transactions/Types/TransactionsRetrieveRequestExpand.cs @@ -1,6 +1,5 @@ using System.Runtime.Serialization; using System.Text.Json.Serialization; -using Merge.Client.Accounting; using Merge.Client.Core; #nullable enable diff --git a/src/Merge.Client/Accounting/Types/Account.cs b/src/Merge.Client/Accounting/Types/Account.cs index 8cf0c4f9..2732d710 100644 --- a/src/Merge.Client/Accounting/Types/Account.cs +++ b/src/Merge.Client/Accounting/Types/Account.cs @@ -1,44 +1,43 @@ using System.Text.Json.Serialization; -using Merge.Client.Accounting; #nullable enable namespace Merge.Client.Accounting; -public class Account +public record Account { [JsonPropertyName("id")] - public string? Id { get; init; } + public string? Id { get; set; } /// /// The third-party API ID of the matching object. /// [JsonPropertyName("remote_id")] - public string? RemoteId { get; init; } + public string? RemoteId { get; set; } /// /// The datetime that this object was created by Merge. /// [JsonPropertyName("created_at")] - public DateTime? CreatedAt { get; init; } + public DateTime? CreatedAt { get; set; } /// /// The datetime that this object was modified by Merge. /// [JsonPropertyName("modified_at")] - public DateTime? ModifiedAt { get; init; } + public DateTime? ModifiedAt { get; set; } /// /// The account's name. /// [JsonPropertyName("name")] - public string? Name { get; init; } + public string? Name { get; set; } /// /// The account's description. /// [JsonPropertyName("description")] - public string? Description { get; init; } + public string? Description { get; set; } /// /// The account's broadest grouping. @@ -50,13 +49,13 @@ public class Account /// - `REVENUE` - REVENUE /// [JsonPropertyName("classification")] - public ClassificationEnum? Classification { get; init; } + public ClassificationEnum? Classification { get; set; } /// /// The account's type is a narrower and more specific grouping within the account's classification. /// [JsonPropertyName("type")] - public string? Type { get; init; } + public string? Type { get; set; } /// /// The account's status. @@ -66,13 +65,13 @@ public class Account /// - `INACTIVE` - INACTIVE /// [JsonPropertyName("status")] - public AccountStatusEnum? Status { get; init; } + public AccountStatusEnum? Status { get; set; } /// /// The account's current balance. /// [JsonPropertyName("current_balance")] - public double? CurrentBalance { get; init; } + public double? CurrentBalance { get; set; } /// /// The account's currency. @@ -385,35 +384,35 @@ public class Account /// - `ZWL` - Zimbabwean Dollar (2009) /// [JsonPropertyName("currency")] - public CurrencyEnum? Currency { get; init; } + public CurrencyEnum? Currency { get; set; } /// /// The account's number. /// [JsonPropertyName("account_number")] - public string? AccountNumber { get; init; } + public string? AccountNumber { get; set; } /// /// ID of the parent account. /// [JsonPropertyName("parent_account")] - public string? ParentAccount { get; init; } + public string? ParentAccount { get; set; } /// /// The company the account belongs to. /// [JsonPropertyName("company")] - public string? Company { get; init; } + public string? Company { get; set; } /// /// Indicates whether or not this object has been deleted in the third party platform. /// [JsonPropertyName("remote_was_deleted")] - public bool? RemoteWasDeleted { get; init; } + public bool? RemoteWasDeleted { get; set; } [JsonPropertyName("field_mappings")] - public Dictionary? FieldMappings { get; init; } + public Dictionary? FieldMappings { get; set; } [JsonPropertyName("remote_data")] - public IEnumerable? RemoteData { get; init; } + public IEnumerable? RemoteData { get; set; } } diff --git a/src/Merge.Client/Accounting/Types/AccountDetails.cs b/src/Merge.Client/Accounting/Types/AccountDetails.cs index 718f2978..75c0b23f 100644 --- a/src/Merge.Client/Accounting/Types/AccountDetails.cs +++ b/src/Merge.Client/Accounting/Types/AccountDetails.cs @@ -1,45 +1,44 @@ using System.Text.Json.Serialization; -using Merge.Client.Accounting; #nullable enable namespace Merge.Client.Accounting; -public class AccountDetails +public record AccountDetails { [JsonPropertyName("id")] - public string? Id { get; init; } + public string? Id { get; set; } [JsonPropertyName("integration")] - public string? Integration { get; init; } + public string? Integration { get; set; } [JsonPropertyName("integration_slug")] - public string? IntegrationSlug { get; init; } + public string? IntegrationSlug { get; set; } [JsonPropertyName("category")] - public CategoryEnum? Category { get; init; } + public CategoryEnum? Category { get; set; } [JsonPropertyName("end_user_origin_id")] - public string? EndUserOriginId { get; init; } + public string? EndUserOriginId { get; set; } [JsonPropertyName("end_user_organization_name")] - public string? EndUserOrganizationName { get; init; } + public string? EndUserOrganizationName { get; set; } [JsonPropertyName("end_user_email_address")] - public string? EndUserEmailAddress { get; init; } + public string? EndUserEmailAddress { get; set; } [JsonPropertyName("status")] - public string? Status { get; init; } + public string? Status { get; set; } [JsonPropertyName("webhook_listener_url")] - public string? WebhookListenerUrl { get; init; } + public string? WebhookListenerUrl { get; set; } /// /// Whether a Production Linked Account's credentials match another existing Production Linked Account. This field is `null` for Test Linked Accounts, incomplete Production Linked Accounts, and ignored duplicate Production Linked Account sets. /// [JsonPropertyName("is_duplicate")] - public bool? IsDuplicate { get; init; } + public bool? IsDuplicate { get; set; } [JsonPropertyName("account_type")] - public string? AccountType { get; init; } + public string? AccountType { get; set; } } diff --git a/src/Merge.Client/Accounting/Types/AccountDetailsAndActions.cs b/src/Merge.Client/Accounting/Types/AccountDetailsAndActions.cs index 2a84a46e..70ddfc91 100644 --- a/src/Merge.Client/Accounting/Types/AccountDetailsAndActions.cs +++ b/src/Merge.Client/Accounting/Types/AccountDetailsAndActions.cs @@ -1,51 +1,50 @@ using System.Text.Json.Serialization; -using Merge.Client.Accounting; #nullable enable namespace Merge.Client.Accounting; -public class AccountDetailsAndActions +public record AccountDetailsAndActions { [JsonPropertyName("id")] - public string Id { get; init; } + public required string Id { get; set; } [JsonPropertyName("category")] - public CategoryEnum? Category { get; init; } + public CategoryEnum? Category { get; set; } [JsonPropertyName("status")] - public AccountDetailsAndActionsStatusEnum Status { get; init; } + public required AccountDetailsAndActionsStatusEnum Status { get; set; } [JsonPropertyName("status_detail")] - public string? StatusDetail { get; init; } + public string? StatusDetail { get; set; } [JsonPropertyName("end_user_origin_id")] - public string? EndUserOriginId { get; init; } + public string? EndUserOriginId { get; set; } [JsonPropertyName("end_user_organization_name")] - public string EndUserOrganizationName { get; init; } + public required string EndUserOrganizationName { get; set; } [JsonPropertyName("end_user_email_address")] - public string EndUserEmailAddress { get; init; } + public required string EndUserEmailAddress { get; set; } /// /// The tenant or domain the customer has provided access to. /// [JsonPropertyName("subdomain")] - public string? Subdomain { get; init; } + public string? Subdomain { get; set; } [JsonPropertyName("webhook_listener_url")] - public string WebhookListenerUrl { get; init; } + public required string WebhookListenerUrl { get; set; } /// /// Whether a Production Linked Account's credentials match another existing Production Linked Account. This field is `null` for Test Linked Accounts, incomplete Production Linked Accounts, and ignored duplicate Production Linked Account sets. /// [JsonPropertyName("is_duplicate")] - public bool? IsDuplicate { get; init; } + public bool? IsDuplicate { get; set; } [JsonPropertyName("integration")] - public AccountDetailsAndActionsIntegration? Integration { get; init; } + public AccountDetailsAndActionsIntegration? Integration { get; set; } [JsonPropertyName("account_type")] - public string AccountType { get; init; } + public required string AccountType { get; set; } } diff --git a/src/Merge.Client/Accounting/Types/AccountDetailsAndActionsIntegration.cs b/src/Merge.Client/Accounting/Types/AccountDetailsAndActionsIntegration.cs index 9821c68f..5f430f77 100644 --- a/src/Merge.Client/Accounting/Types/AccountDetailsAndActionsIntegration.cs +++ b/src/Merge.Client/Accounting/Types/AccountDetailsAndActionsIntegration.cs @@ -1,33 +1,32 @@ using System.Text.Json.Serialization; -using Merge.Client.Accounting; #nullable enable namespace Merge.Client.Accounting; -public class AccountDetailsAndActionsIntegration +public record AccountDetailsAndActionsIntegration { [JsonPropertyName("name")] - public string Name { get; init; } + public required string Name { get; set; } [JsonPropertyName("categories")] - public IEnumerable Categories { get; init; } + public IEnumerable Categories { get; set; } = new List(); [JsonPropertyName("image")] - public string? Image { get; init; } + public string? Image { get; set; } [JsonPropertyName("square_image")] - public string? SquareImage { get; init; } + public string? SquareImage { get; set; } [JsonPropertyName("color")] - public string Color { get; init; } + public required string Color { get; set; } [JsonPropertyName("slug")] - public string Slug { get; init; } + public required string Slug { get; set; } [JsonPropertyName("passthrough_available")] - public bool PassthroughAvailable { get; init; } + public required bool PassthroughAvailable { get; set; } [JsonPropertyName("available_model_operations")] - public IEnumerable? AvailableModelOperations { get; init; } + public IEnumerable? AvailableModelOperations { get; set; } } diff --git a/src/Merge.Client/Accounting/Types/AccountDetailsAndActionsStatusEnum.cs b/src/Merge.Client/Accounting/Types/AccountDetailsAndActionsStatusEnum.cs index 814a0e43..815593fe 100644 --- a/src/Merge.Client/Accounting/Types/AccountDetailsAndActionsStatusEnum.cs +++ b/src/Merge.Client/Accounting/Types/AccountDetailsAndActionsStatusEnum.cs @@ -1,6 +1,5 @@ using System.Runtime.Serialization; using System.Text.Json.Serialization; -using Merge.Client.Accounting; using Merge.Client.Core; #nullable enable diff --git a/src/Merge.Client/Accounting/Types/AccountIntegration.cs b/src/Merge.Client/Accounting/Types/AccountIntegration.cs index 68ee44e9..06942e93 100644 --- a/src/Merge.Client/Accounting/Types/AccountIntegration.cs +++ b/src/Merge.Client/Accounting/Types/AccountIntegration.cs @@ -1,60 +1,59 @@ using System.Text.Json.Serialization; -using Merge.Client.Accounting; #nullable enable namespace Merge.Client.Accounting; -public class AccountIntegration +public record AccountIntegration { /// /// Company name. /// [JsonPropertyName("name")] - public string Name { get; init; } + public required string Name { get; set; } /// /// Category or categories this integration belongs to. Multiple categories should be comma separated, i.e. [ats, hris]. /// [JsonPropertyName("categories")] - public IEnumerable? Categories { get; init; } + public IEnumerable? Categories { get; set; } /// /// Company logo in rectangular shape. Upload an image with a clear background. /// [JsonPropertyName("image")] - public string? Image { get; init; } + public string? Image { get; set; } /// /// Company logo in square shape. Upload an image with a white background. /// [JsonPropertyName("square_image")] - public string? SquareImage { get; init; } + public string? SquareImage { get; set; } /// /// The color of this integration used for buttons and text throughout the app and landing pages. Choose a darker, saturated color. /// [JsonPropertyName("color")] - public string? Color { get; init; } + public string? Color { get; set; } [JsonPropertyName("slug")] - public string? Slug { get; init; } + public string? Slug { get; set; } /// /// Mapping of API endpoints to documentation urls for support. Example: {'GET': [['/common-model-scopes', 'https://docs.merge.dev/accounting/common-model-scopes/#common_model_scopes_retrieve'],['/common-model-actions', 'https://docs.merge.dev/accounting/common-model-actions/#common_model_actions_retrieve']], 'POST': []} /// [JsonPropertyName("api_endpoints_to_documentation_urls")] - public Dictionary? ApiEndpointsToDocumentationUrls { get; init; } + public Dictionary? ApiEndpointsToDocumentationUrls { get; set; } /// /// Setup guide URL for third party webhook creation. Exposed in Merge Docs. /// [JsonPropertyName("webhook_setup_guide_url")] - public string? WebhookSetupGuideUrl { get; init; } + public string? WebhookSetupGuideUrl { get; set; } /// /// Category or categories this integration is in beta status for. /// [JsonPropertyName("category_beta_status")] - public Dictionary? CategoryBetaStatus { get; init; } + public Dictionary? CategoryBetaStatus { get; set; } } diff --git a/src/Merge.Client/Accounting/Types/AccountRequest.cs b/src/Merge.Client/Accounting/Types/AccountRequest.cs index 7b7e4910..05776440 100644 --- a/src/Merge.Client/Accounting/Types/AccountRequest.cs +++ b/src/Merge.Client/Accounting/Types/AccountRequest.cs @@ -1,23 +1,22 @@ using System.Text.Json.Serialization; -using Merge.Client.Accounting; #nullable enable namespace Merge.Client.Accounting; -public class AccountRequest +public record AccountRequest { /// /// The account's name. /// [JsonPropertyName("name")] - public string? Name { get; init; } + public string? Name { get; set; } /// /// The account's description. /// [JsonPropertyName("description")] - public string? Description { get; init; } + public string? Description { get; set; } /// /// The account's broadest grouping. @@ -29,13 +28,13 @@ public class AccountRequest /// - `REVENUE` - REVENUE /// [JsonPropertyName("classification")] - public ClassificationEnum? Classification { get; init; } + public ClassificationEnum? Classification { get; set; } /// /// The account's type is a narrower and more specific grouping within the account's classification. /// [JsonPropertyName("type")] - public string? Type { get; init; } + public string? Type { get; set; } /// /// The account's status. @@ -45,13 +44,13 @@ public class AccountRequest /// - `INACTIVE` - INACTIVE /// [JsonPropertyName("status")] - public AccountStatusEnum? Status { get; init; } + public AccountStatusEnum? Status { get; set; } /// /// The account's current balance. /// [JsonPropertyName("current_balance")] - public double? CurrentBalance { get; init; } + public double? CurrentBalance { get; set; } /// /// The account's currency. @@ -364,29 +363,29 @@ public class AccountRequest /// - `ZWL` - Zimbabwean Dollar (2009) /// [JsonPropertyName("currency")] - public CurrencyEnum? Currency { get; init; } + public CurrencyEnum? Currency { get; set; } /// /// The account's number. /// [JsonPropertyName("account_number")] - public string? AccountNumber { get; init; } + public string? AccountNumber { get; set; } /// /// ID of the parent account. /// [JsonPropertyName("parent_account")] - public string? ParentAccount { get; init; } + public string? ParentAccount { get; set; } /// /// The company the account belongs to. /// [JsonPropertyName("company")] - public string? Company { get; init; } + public string? Company { get; set; } [JsonPropertyName("integration_params")] - public Dictionary? IntegrationParams { get; init; } + public Dictionary? IntegrationParams { get; set; } [JsonPropertyName("linked_account_params")] - public Dictionary? LinkedAccountParams { get; init; } + public Dictionary? LinkedAccountParams { get; set; } } diff --git a/src/Merge.Client/Accounting/Types/AccountResponse.cs b/src/Merge.Client/Accounting/Types/AccountResponse.cs index ec551661..9a98ec02 100644 --- a/src/Merge.Client/Accounting/Types/AccountResponse.cs +++ b/src/Merge.Client/Accounting/Types/AccountResponse.cs @@ -1,21 +1,22 @@ using System.Text.Json.Serialization; -using Merge.Client.Accounting; #nullable enable namespace Merge.Client.Accounting; -public class AccountResponse +public record AccountResponse { [JsonPropertyName("model")] - public Account Model { get; init; } + public required Account Model { get; set; } [JsonPropertyName("warnings")] - public IEnumerable Warnings { get; init; } + public IEnumerable Warnings { get; set; } = + new List(); [JsonPropertyName("errors")] - public IEnumerable Errors { get; init; } + public IEnumerable Errors { get; set; } = + new List(); [JsonPropertyName("logs")] - public IEnumerable? Logs { get; init; } + public IEnumerable? Logs { get; set; } } diff --git a/src/Merge.Client/Accounting/Types/AccountStatusEnum.cs b/src/Merge.Client/Accounting/Types/AccountStatusEnum.cs index 6ab9d6cc..3fca0796 100644 --- a/src/Merge.Client/Accounting/Types/AccountStatusEnum.cs +++ b/src/Merge.Client/Accounting/Types/AccountStatusEnum.cs @@ -1,6 +1,5 @@ using System.Runtime.Serialization; using System.Text.Json.Serialization; -using Merge.Client.Accounting; using Merge.Client.Core; #nullable enable diff --git a/src/Merge.Client/Accounting/Types/AccountToken.cs b/src/Merge.Client/Accounting/Types/AccountToken.cs index c180ce6e..f92e11ae 100644 --- a/src/Merge.Client/Accounting/Types/AccountToken.cs +++ b/src/Merge.Client/Accounting/Types/AccountToken.cs @@ -1,15 +1,14 @@ using System.Text.Json.Serialization; -using Merge.Client.Accounting; #nullable enable namespace Merge.Client.Accounting; -public class AccountToken +public record AccountToken { [JsonPropertyName("account_token")] - public string AccountToken_ { get; init; } + public required string AccountToken_ { get; set; } [JsonPropertyName("integration")] - public AccountIntegration Integration { get; init; } + public required AccountIntegration Integration { get; set; } } diff --git a/src/Merge.Client/Accounting/Types/AccountingAttachment.cs b/src/Merge.Client/Accounting/Types/AccountingAttachment.cs index abbb40f9..c040b401 100644 --- a/src/Merge.Client/Accounting/Types/AccountingAttachment.cs +++ b/src/Merge.Client/Accounting/Types/AccountingAttachment.cs @@ -1,60 +1,59 @@ using System.Text.Json.Serialization; -using Merge.Client.Accounting; #nullable enable namespace Merge.Client.Accounting; -public class AccountingAttachment +public record AccountingAttachment { [JsonPropertyName("id")] - public string? Id { get; init; } + public string? Id { get; set; } /// /// The third-party API ID of the matching object. /// [JsonPropertyName("remote_id")] - public string? RemoteId { get; init; } + public string? RemoteId { get; set; } /// /// The datetime that this object was created by Merge. /// [JsonPropertyName("created_at")] - public DateTime? CreatedAt { get; init; } + public DateTime? CreatedAt { get; set; } /// /// The datetime that this object was modified by Merge. /// [JsonPropertyName("modified_at")] - public DateTime? ModifiedAt { get; init; } + public DateTime? ModifiedAt { get; set; } /// /// The attachment's name. /// [JsonPropertyName("file_name")] - public string? FileName { get; init; } + public string? FileName { get; set; } /// /// The attachment's url. /// [JsonPropertyName("file_url")] - public string? FileUrl { get; init; } + public string? FileUrl { get; set; } /// /// The company the accounting attachment belongs to. /// [JsonPropertyName("company")] - public string? Company { get; init; } + public string? Company { get; set; } /// /// Indicates whether or not this object has been deleted in the third party platform. /// [JsonPropertyName("remote_was_deleted")] - public bool? RemoteWasDeleted { get; init; } + public bool? RemoteWasDeleted { get; set; } [JsonPropertyName("field_mappings")] - public Dictionary? FieldMappings { get; init; } + public Dictionary? FieldMappings { get; set; } [JsonPropertyName("remote_data")] - public IEnumerable? RemoteData { get; init; } + public IEnumerable? RemoteData { get; set; } } diff --git a/src/Merge.Client/Accounting/Types/AccountingAttachmentRequest.cs b/src/Merge.Client/Accounting/Types/AccountingAttachmentRequest.cs index 4084a447..a4702a32 100644 --- a/src/Merge.Client/Accounting/Types/AccountingAttachmentRequest.cs +++ b/src/Merge.Client/Accounting/Types/AccountingAttachmentRequest.cs @@ -4,29 +4,29 @@ namespace Merge.Client.Accounting; -public class AccountingAttachmentRequest +public record AccountingAttachmentRequest { /// /// The attachment's name. /// [JsonPropertyName("file_name")] - public string? FileName { get; init; } + public string? FileName { get; set; } /// /// The attachment's url. /// [JsonPropertyName("file_url")] - public string? FileUrl { get; init; } + public string? FileUrl { get; set; } /// /// The company the accounting attachment belongs to. /// [JsonPropertyName("company")] - public string? Company { get; init; } + public string? Company { get; set; } [JsonPropertyName("integration_params")] - public Dictionary? IntegrationParams { get; init; } + public Dictionary? IntegrationParams { get; set; } [JsonPropertyName("linked_account_params")] - public Dictionary? LinkedAccountParams { get; init; } + public Dictionary? LinkedAccountParams { get; set; } } diff --git a/src/Merge.Client/Accounting/Types/AccountingAttachmentResponse.cs b/src/Merge.Client/Accounting/Types/AccountingAttachmentResponse.cs index 0192807e..3e3eb3d3 100644 --- a/src/Merge.Client/Accounting/Types/AccountingAttachmentResponse.cs +++ b/src/Merge.Client/Accounting/Types/AccountingAttachmentResponse.cs @@ -1,21 +1,22 @@ using System.Text.Json.Serialization; -using Merge.Client.Accounting; #nullable enable namespace Merge.Client.Accounting; -public class AccountingAttachmentResponse +public record AccountingAttachmentResponse { [JsonPropertyName("model")] - public AccountingAttachment Model { get; init; } + public required AccountingAttachment Model { get; set; } [JsonPropertyName("warnings")] - public IEnumerable Warnings { get; init; } + public IEnumerable Warnings { get; set; } = + new List(); [JsonPropertyName("errors")] - public IEnumerable Errors { get; init; } + public IEnumerable Errors { get; set; } = + new List(); [JsonPropertyName("logs")] - public IEnumerable? Logs { get; init; } + public IEnumerable? Logs { get; set; } } diff --git a/src/Merge.Client/Accounting/Types/AccountingPeriod.cs b/src/Merge.Client/Accounting/Types/AccountingPeriod.cs index 28f45471..03cd27ab 100644 --- a/src/Merge.Client/Accounting/Types/AccountingPeriod.cs +++ b/src/Merge.Client/Accounting/Types/AccountingPeriod.cs @@ -1,45 +1,44 @@ using System.Text.Json.Serialization; -using Merge.Client.Accounting; #nullable enable namespace Merge.Client.Accounting; -public class AccountingPeriod +public record AccountingPeriod { [JsonPropertyName("id")] - public string? Id { get; init; } + public string? Id { get; set; } /// /// The datetime that this object was created by Merge. /// [JsonPropertyName("created_at")] - public DateTime? CreatedAt { get; init; } + public DateTime? CreatedAt { get; set; } /// /// The datetime that this object was modified by Merge. /// [JsonPropertyName("modified_at")] - public DateTime? ModifiedAt { get; init; } + public DateTime? ModifiedAt { get; set; } /// /// Beginning date of the period /// [JsonPropertyName("start_date")] - public DateTime? StartDate { get; init; } + public DateTime? StartDate { get; set; } /// /// End date of the period /// [JsonPropertyName("end_date")] - public DateTime? EndDate { get; init; } + public DateTime? EndDate { get; set; } [JsonPropertyName("status")] - public AccountingPeriodStatusEnum? Status { get; init; } + public AccountingPeriodStatusEnum? Status { get; set; } /// /// Name of the accounting period. /// [JsonPropertyName("name")] - public string? Name { get; init; } + public string? Name { get; set; } } diff --git a/src/Merge.Client/Accounting/Types/AccountingPeriodStatusEnum.cs b/src/Merge.Client/Accounting/Types/AccountingPeriodStatusEnum.cs index 83fabffe..993e313b 100644 --- a/src/Merge.Client/Accounting/Types/AccountingPeriodStatusEnum.cs +++ b/src/Merge.Client/Accounting/Types/AccountingPeriodStatusEnum.cs @@ -1,6 +1,5 @@ using System.Runtime.Serialization; using System.Text.Json.Serialization; -using Merge.Client.Accounting; using Merge.Client.Core; #nullable enable diff --git a/src/Merge.Client/Accounting/Types/AccountingPhoneNumber.cs b/src/Merge.Client/Accounting/Types/AccountingPhoneNumber.cs index bb31731d..ca9722b6 100644 --- a/src/Merge.Client/Accounting/Types/AccountingPhoneNumber.cs +++ b/src/Merge.Client/Accounting/Types/AccountingPhoneNumber.cs @@ -4,29 +4,29 @@ namespace Merge.Client.Accounting; -public class AccountingPhoneNumber +public record AccountingPhoneNumber { /// /// The datetime that this object was created by Merge. /// [JsonPropertyName("created_at")] - public DateTime? CreatedAt { get; init; } + public DateTime? CreatedAt { get; set; } /// /// The datetime that this object was modified by Merge. /// [JsonPropertyName("modified_at")] - public DateTime? ModifiedAt { get; init; } + public DateTime? ModifiedAt { get; set; } /// /// The phone number. /// [JsonPropertyName("number")] - public string? Number { get; init; } + public string? Number { get; set; } /// /// The phone number's type. /// [JsonPropertyName("type")] - public string? Type { get; init; } + public string? Type { get; set; } } diff --git a/src/Merge.Client/Accounting/Types/AccountingPhoneNumberRequest.cs b/src/Merge.Client/Accounting/Types/AccountingPhoneNumberRequest.cs index aa8b6782..1fcd72c1 100644 --- a/src/Merge.Client/Accounting/Types/AccountingPhoneNumberRequest.cs +++ b/src/Merge.Client/Accounting/Types/AccountingPhoneNumberRequest.cs @@ -4,23 +4,23 @@ namespace Merge.Client.Accounting; -public class AccountingPhoneNumberRequest +public record AccountingPhoneNumberRequest { /// /// The phone number. /// [JsonPropertyName("number")] - public string? Number { get; init; } + public string? Number { get; set; } /// /// The phone number's type. /// [JsonPropertyName("type")] - public string? Type { get; init; } + public string? Type { get; set; } [JsonPropertyName("integration_params")] - public Dictionary? IntegrationParams { get; init; } + public Dictionary? IntegrationParams { get; set; } [JsonPropertyName("linked_account_params")] - public Dictionary? LinkedAccountParams { get; init; } + public Dictionary? LinkedAccountParams { get; set; } } diff --git a/src/Merge.Client/Accounting/Types/Address.cs b/src/Merge.Client/Accounting/Types/Address.cs index 3094bd65..068e5bf6 100644 --- a/src/Merge.Client/Accounting/Types/Address.cs +++ b/src/Merge.Client/Accounting/Types/Address.cs @@ -1,23 +1,22 @@ using System.Text.Json.Serialization; -using Merge.Client.Accounting; #nullable enable namespace Merge.Client.Accounting; -public class Address +public record Address { /// /// The datetime that this object was created by Merge. /// [JsonPropertyName("created_at")] - public DateTime? CreatedAt { get; init; } + public DateTime? CreatedAt { get; set; } /// /// The datetime that this object was modified by Merge. /// [JsonPropertyName("modified_at")] - public DateTime? ModifiedAt { get; init; } + public DateTime? ModifiedAt { get; set; } /// /// The address type. @@ -26,34 +25,34 @@ public class Address /// - `SHIPPING` - SHIPPING /// [JsonPropertyName("type")] - public AddressTypeEnum? Type { get; init; } + public AddressTypeEnum? Type { get; set; } /// /// Line 1 of the address's street. /// [JsonPropertyName("street_1")] - public string? Street1 { get; init; } + public string? Street1 { get; set; } /// /// Line 2 of the address's street. /// [JsonPropertyName("street_2")] - public string? Street2 { get; init; } + public string? Street2 { get; set; } /// /// The address's city. /// [JsonPropertyName("city")] - public string? City { get; init; } + public string? City { get; set; } [JsonPropertyName("state")] - public object? State { get; init; } + public object? State { get; set; } /// /// The address's state or region. /// [JsonPropertyName("country_subdivision")] - public string? CountrySubdivision { get; init; } + public string? CountrySubdivision { get; set; } /// /// The address's country. @@ -309,11 +308,11 @@ public class Address /// - `ZW` - Zimbabwe /// [JsonPropertyName("country")] - public CountryEnum? Country { get; init; } + public CountryEnum? Country { get; set; } /// /// The address's zip code. /// [JsonPropertyName("zip_code")] - public string? ZipCode { get; init; } + public string? ZipCode { get; set; } } diff --git a/src/Merge.Client/Accounting/Types/AddressRequest.cs b/src/Merge.Client/Accounting/Types/AddressRequest.cs index 4944ae3f..7985d935 100644 --- a/src/Merge.Client/Accounting/Types/AddressRequest.cs +++ b/src/Merge.Client/Accounting/Types/AddressRequest.cs @@ -1,11 +1,10 @@ using System.Text.Json.Serialization; -using Merge.Client.Accounting; #nullable enable namespace Merge.Client.Accounting; -public class AddressRequest +public record AddressRequest { /// /// The address type. @@ -14,31 +13,31 @@ public class AddressRequest /// - `SHIPPING` - SHIPPING /// [JsonPropertyName("type")] - public AddressTypeEnum? Type { get; init; } + public AddressTypeEnum? Type { get; set; } /// /// Line 1 of the address's street. /// [JsonPropertyName("street_1")] - public string? Street1 { get; init; } + public string? Street1 { get; set; } /// /// Line 2 of the address's street. /// [JsonPropertyName("street_2")] - public string? Street2 { get; init; } + public string? Street2 { get; set; } /// /// The address's city. /// [JsonPropertyName("city")] - public string? City { get; init; } + public string? City { get; set; } /// /// The address's state or region. /// [JsonPropertyName("country_subdivision")] - public string? CountrySubdivision { get; init; } + public string? CountrySubdivision { get; set; } /// /// The address's country. @@ -294,17 +293,17 @@ public class AddressRequest /// - `ZW` - Zimbabwe /// [JsonPropertyName("country")] - public CountryEnum? Country { get; init; } + public CountryEnum? Country { get; set; } /// /// The address's zip code. /// [JsonPropertyName("zip_code")] - public string? ZipCode { get; init; } + public string? ZipCode { get; set; } [JsonPropertyName("integration_params")] - public Dictionary? IntegrationParams { get; init; } + public Dictionary? IntegrationParams { get; set; } [JsonPropertyName("linked_account_params")] - public Dictionary? LinkedAccountParams { get; init; } + public Dictionary? LinkedAccountParams { get; set; } } diff --git a/src/Merge.Client/Accounting/Types/AddressTypeEnum.cs b/src/Merge.Client/Accounting/Types/AddressTypeEnum.cs index 8fb5ef65..69754762 100644 --- a/src/Merge.Client/Accounting/Types/AddressTypeEnum.cs +++ b/src/Merge.Client/Accounting/Types/AddressTypeEnum.cs @@ -1,6 +1,5 @@ using System.Runtime.Serialization; using System.Text.Json.Serialization; -using Merge.Client.Accounting; using Merge.Client.Core; #nullable enable diff --git a/src/Merge.Client/Accounting/Types/AdvancedMetadata.cs b/src/Merge.Client/Accounting/Types/AdvancedMetadata.cs index a323e1e7..f2a76420 100644 --- a/src/Merge.Client/Accounting/Types/AdvancedMetadata.cs +++ b/src/Merge.Client/Accounting/Types/AdvancedMetadata.cs @@ -4,23 +4,23 @@ namespace Merge.Client.Accounting; -public class AdvancedMetadata +public record AdvancedMetadata { [JsonPropertyName("id")] - public string Id { get; init; } + public required string Id { get; set; } [JsonPropertyName("display_name")] - public string? DisplayName { get; init; } + public string? DisplayName { get; set; } [JsonPropertyName("description")] - public string? Description { get; init; } + public string? Description { get; set; } [JsonPropertyName("is_required")] - public bool? IsRequired { get; init; } + public bool? IsRequired { get; set; } [JsonPropertyName("is_custom")] - public bool? IsCustom { get; init; } + public bool? IsCustom { get; set; } [JsonPropertyName("field_choices")] - public IEnumerable? FieldChoices { get; init; } + public IEnumerable? FieldChoices { get; set; } } diff --git a/src/Merge.Client/Accounting/Types/AsyncPassthroughReciept.cs b/src/Merge.Client/Accounting/Types/AsyncPassthroughReciept.cs index 8ff5ed36..3eb061ad 100644 --- a/src/Merge.Client/Accounting/Types/AsyncPassthroughReciept.cs +++ b/src/Merge.Client/Accounting/Types/AsyncPassthroughReciept.cs @@ -4,8 +4,8 @@ namespace Merge.Client.Accounting; -public class AsyncPassthroughReciept +public record AsyncPassthroughReciept { [JsonPropertyName("async_passthrough_receipt_id")] - public string AsyncPassthroughReceiptId { get; init; } + public required string AsyncPassthroughReceiptId { get; set; } } diff --git a/src/Merge.Client/Accounting/Types/AuditLogEvent.cs b/src/Merge.Client/Accounting/Types/AuditLogEvent.cs index 72077ded..e69d4ce4 100644 --- a/src/Merge.Client/Accounting/Types/AuditLogEvent.cs +++ b/src/Merge.Client/Accounting/Types/AuditLogEvent.cs @@ -1,26 +1,25 @@ using System.Text.Json.Serialization; -using Merge.Client.Accounting; #nullable enable namespace Merge.Client.Accounting; -public class AuditLogEvent +public record AuditLogEvent { [JsonPropertyName("id")] - public string? Id { get; init; } + public string? Id { get; set; } /// /// The User's full name at the time of this Event occurring. /// [JsonPropertyName("user_name")] - public string? UserName { get; init; } + public string? UserName { get; set; } /// /// The User's email at the time of this Event occurring. /// [JsonPropertyName("user_email")] - public string? UserEmail { get; init; } + public string? UserEmail { get; set; } /// /// Designates the role of the user (or SYSTEM/API if action not taken by a user) at the time of this Event occurring. @@ -33,10 +32,10 @@ public class AuditLogEvent /// - `MERGE_TEAM` - MERGE_TEAM /// [JsonPropertyName("role")] - public RoleEnum Role { get; init; } + public required RoleEnum Role { get; set; } [JsonPropertyName("ip_address")] - public string IpAddress { get; init; } + public required string IpAddress { get; set; } /// /// Designates the type of event that occurred. @@ -80,11 +79,11 @@ public class AuditLogEvent /// - `MERGE_WEBHOOK_TARGET_CHANGED` - MERGE_WEBHOOK_TARGET_CHANGED /// [JsonPropertyName("event_type")] - public EventTypeEnum EventType { get; init; } + public required EventTypeEnum EventType { get; set; } [JsonPropertyName("event_description")] - public string EventDescription { get; init; } + public required string EventDescription { get; set; } [JsonPropertyName("created_at")] - public DateTime? CreatedAt { get; init; } + public DateTime? CreatedAt { get; set; } } diff --git a/src/Merge.Client/Accounting/Types/AvailableActions.cs b/src/Merge.Client/Accounting/Types/AvailableActions.cs index 18e92475..afb31c5d 100644 --- a/src/Merge.Client/Accounting/Types/AvailableActions.cs +++ b/src/Merge.Client/Accounting/Types/AvailableActions.cs @@ -1,18 +1,17 @@ using System.Text.Json.Serialization; -using Merge.Client.Accounting; #nullable enable namespace Merge.Client.Accounting; -public class AvailableActions +public record AvailableActions { [JsonPropertyName("integration")] - public AccountIntegration Integration { get; init; } + public required AccountIntegration Integration { get; set; } [JsonPropertyName("passthrough_available")] - public bool PassthroughAvailable { get; init; } + public required bool PassthroughAvailable { get; set; } [JsonPropertyName("available_model_operations")] - public IEnumerable? AvailableModelOperations { get; init; } + public IEnumerable? AvailableModelOperations { get; set; } } diff --git a/src/Merge.Client/Accounting/Types/BalanceSheet.cs b/src/Merge.Client/Accounting/Types/BalanceSheet.cs index 63ffa446..b9db0669 100644 --- a/src/Merge.Client/Accounting/Types/BalanceSheet.cs +++ b/src/Merge.Client/Accounting/Types/BalanceSheet.cs @@ -1,5 +1,4 @@ using System.Text.Json.Serialization; -using Merge.Client.Accounting; using Merge.Client.Core; using OneOf; @@ -7,34 +6,34 @@ namespace Merge.Client.Accounting; -public class BalanceSheet +public record BalanceSheet { [JsonPropertyName("id")] - public string? Id { get; init; } + public string? Id { get; set; } /// /// The third-party API ID of the matching object. /// [JsonPropertyName("remote_id")] - public string? RemoteId { get; init; } + public string? RemoteId { get; set; } /// /// The datetime that this object was created by Merge. /// [JsonPropertyName("created_at")] - public DateTime? CreatedAt { get; init; } + public DateTime? CreatedAt { get; set; } /// /// The datetime that this object was modified by Merge. /// [JsonPropertyName("modified_at")] - public DateTime? ModifiedAt { get; init; } + public DateTime? ModifiedAt { get; set; } /// /// The balance sheet's name. /// [JsonPropertyName("name")] - public string? Name { get; init; } + public string? Name { get; set; } /// /// The balance sheet's currency. @@ -347,51 +346,51 @@ public class BalanceSheet /// - `ZWL` - Zimbabwean Dollar (2009) /// [JsonPropertyName("currency")] - public CurrencyEnum? Currency { get; init; } + public CurrencyEnum? Currency { get; set; } /// /// `Company` object for the given `BalanceSheet` object. /// [JsonPropertyName("company")] [JsonConverter(typeof(OneOfSerializer>))] - public OneOf? Company { get; init; } + public OneOf? Company { get; set; } /// /// The balance sheet's date. The balance sheet data will reflect the company's financial position this point in time. /// [JsonPropertyName("date")] - public DateTime? Date { get; init; } + public DateTime? Date { get; set; } /// /// The balance sheet's net assets. /// [JsonPropertyName("net_assets")] - public double? NetAssets { get; init; } + public double? NetAssets { get; set; } [JsonPropertyName("assets")] - public IEnumerable? Assets { get; init; } + public IEnumerable? Assets { get; set; } [JsonPropertyName("liabilities")] - public IEnumerable? Liabilities { get; init; } + public IEnumerable? Liabilities { get; set; } [JsonPropertyName("equity")] - public IEnumerable? Equity { get; init; } + public IEnumerable? Equity { get; set; } /// /// The time that balance sheet was generated by the accounting system. /// [JsonPropertyName("remote_generated_at")] - public DateTime? RemoteGeneratedAt { get; init; } + public DateTime? RemoteGeneratedAt { get; set; } /// /// Indicates whether or not this object has been deleted in the third party platform. /// [JsonPropertyName("remote_was_deleted")] - public bool? RemoteWasDeleted { get; init; } + public bool? RemoteWasDeleted { get; set; } [JsonPropertyName("field_mappings")] - public Dictionary? FieldMappings { get; init; } + public Dictionary? FieldMappings { get; set; } [JsonPropertyName("remote_data")] - public IEnumerable? RemoteData { get; init; } + public IEnumerable? RemoteData { get; set; } } diff --git a/src/Merge.Client/Accounting/Types/CashFlowStatement.cs b/src/Merge.Client/Accounting/Types/CashFlowStatement.cs index 799c6389..5550fd2f 100644 --- a/src/Merge.Client/Accounting/Types/CashFlowStatement.cs +++ b/src/Merge.Client/Accounting/Types/CashFlowStatement.cs @@ -1,5 +1,4 @@ using System.Text.Json.Serialization; -using Merge.Client.Accounting; using Merge.Client.Core; using OneOf; @@ -7,34 +6,34 @@ namespace Merge.Client.Accounting; -public class CashFlowStatement +public record CashFlowStatement { [JsonPropertyName("id")] - public string? Id { get; init; } + public string? Id { get; set; } /// /// The third-party API ID of the matching object. /// [JsonPropertyName("remote_id")] - public string? RemoteId { get; init; } + public string? RemoteId { get; set; } /// /// The datetime that this object was created by Merge. /// [JsonPropertyName("created_at")] - public DateTime? CreatedAt { get; init; } + public DateTime? CreatedAt { get; set; } /// /// The datetime that this object was modified by Merge. /// [JsonPropertyName("modified_at")] - public DateTime? ModifiedAt { get; init; } + public DateTime? ModifiedAt { get; set; } /// /// The cash flow statement's name. /// [JsonPropertyName("name")] - public string? Name { get; init; } + public string? Name { get; set; } /// /// The cash flow statement's currency. @@ -347,63 +346,63 @@ public class CashFlowStatement /// - `ZWL` - Zimbabwean Dollar (2009) /// [JsonPropertyName("currency")] - public CurrencyEnum? Currency { get; init; } + public CurrencyEnum? Currency { get; set; } /// /// The company the cash flow statement belongs to. /// [JsonPropertyName("company")] [JsonConverter(typeof(OneOfSerializer>))] - public OneOf? Company { get; init; } + public OneOf? Company { get; set; } /// /// The cash flow statement's start period. /// [JsonPropertyName("start_period")] - public DateTime? StartPeriod { get; init; } + public DateTime? StartPeriod { get; set; } /// /// The cash flow statement's end period. /// [JsonPropertyName("end_period")] - public DateTime? EndPeriod { get; init; } + public DateTime? EndPeriod { get; set; } /// /// Cash and cash equivalents at the beginning of the cash flow statement's period. /// [JsonPropertyName("cash_at_beginning_of_period")] - public double? CashAtBeginningOfPeriod { get; init; } + public double? CashAtBeginningOfPeriod { get; set; } /// /// Cash and cash equivalents at the beginning of the cash flow statement's period. /// [JsonPropertyName("cash_at_end_of_period")] - public double? CashAtEndOfPeriod { get; init; } + public double? CashAtEndOfPeriod { get; set; } [JsonPropertyName("operating_activities")] - public IEnumerable? OperatingActivities { get; init; } + public IEnumerable? OperatingActivities { get; set; } [JsonPropertyName("investing_activities")] - public IEnumerable? InvestingActivities { get; init; } + public IEnumerable? InvestingActivities { get; set; } [JsonPropertyName("financing_activities")] - public IEnumerable? FinancingActivities { get; init; } + public IEnumerable? FinancingActivities { get; set; } /// /// The time that cash flow statement was generated by the accounting system. /// [JsonPropertyName("remote_generated_at")] - public DateTime? RemoteGeneratedAt { get; init; } + public DateTime? RemoteGeneratedAt { get; set; } /// /// Indicates whether or not this object has been deleted in the third party platform. /// [JsonPropertyName("remote_was_deleted")] - public bool? RemoteWasDeleted { get; init; } + public bool? RemoteWasDeleted { get; set; } [JsonPropertyName("field_mappings")] - public Dictionary? FieldMappings { get; init; } + public Dictionary? FieldMappings { get; set; } [JsonPropertyName("remote_data")] - public IEnumerable? RemoteData { get; init; } + public IEnumerable? RemoteData { get; set; } } diff --git a/src/Merge.Client/Accounting/Types/CategoriesEnum.cs b/src/Merge.Client/Accounting/Types/CategoriesEnum.cs index 429c9522..78b24749 100644 --- a/src/Merge.Client/Accounting/Types/CategoriesEnum.cs +++ b/src/Merge.Client/Accounting/Types/CategoriesEnum.cs @@ -1,6 +1,5 @@ using System.Runtime.Serialization; using System.Text.Json.Serialization; -using Merge.Client.Accounting; using Merge.Client.Core; #nullable enable diff --git a/src/Merge.Client/Accounting/Types/CategoryEnum.cs b/src/Merge.Client/Accounting/Types/CategoryEnum.cs index c6f4ae7a..0e13574a 100644 --- a/src/Merge.Client/Accounting/Types/CategoryEnum.cs +++ b/src/Merge.Client/Accounting/Types/CategoryEnum.cs @@ -1,6 +1,5 @@ using System.Runtime.Serialization; using System.Text.Json.Serialization; -using Merge.Client.Accounting; using Merge.Client.Core; #nullable enable diff --git a/src/Merge.Client/Accounting/Types/CategoryTypeEnum.cs b/src/Merge.Client/Accounting/Types/CategoryTypeEnum.cs index f1114711..b2e7dc00 100644 --- a/src/Merge.Client/Accounting/Types/CategoryTypeEnum.cs +++ b/src/Merge.Client/Accounting/Types/CategoryTypeEnum.cs @@ -1,6 +1,5 @@ using System.Runtime.Serialization; using System.Text.Json.Serialization; -using Merge.Client.Accounting; using Merge.Client.Core; #nullable enable diff --git a/src/Merge.Client/Accounting/Types/ClassificationEnum.cs b/src/Merge.Client/Accounting/Types/ClassificationEnum.cs index 74fe62db..5a52ce96 100644 --- a/src/Merge.Client/Accounting/Types/ClassificationEnum.cs +++ b/src/Merge.Client/Accounting/Types/ClassificationEnum.cs @@ -1,6 +1,5 @@ using System.Runtime.Serialization; using System.Text.Json.Serialization; -using Merge.Client.Accounting; using Merge.Client.Core; #nullable enable diff --git a/src/Merge.Client/Accounting/Types/CommonModelScopeApi.cs b/src/Merge.Client/Accounting/Types/CommonModelScopeApi.cs index 2fe5de03..c346c8dc 100644 --- a/src/Merge.Client/Accounting/Types/CommonModelScopeApi.cs +++ b/src/Merge.Client/Accounting/Types/CommonModelScopeApi.cs @@ -1,15 +1,15 @@ using System.Text.Json.Serialization; -using Merge.Client.Accounting; #nullable enable namespace Merge.Client.Accounting; -public class CommonModelScopeApi +public record CommonModelScopeApi { /// /// The common models you want to update the scopes for /// [JsonPropertyName("common_models")] - public IEnumerable CommonModels { get; init; } + public IEnumerable CommonModels { get; set; } = + new List(); } diff --git a/src/Merge.Client/Accounting/Types/CommonModelScopesBodyRequest.cs b/src/Merge.Client/Accounting/Types/CommonModelScopesBodyRequest.cs index 4ed719b7..337e29a4 100644 --- a/src/Merge.Client/Accounting/Types/CommonModelScopesBodyRequest.cs +++ b/src/Merge.Client/Accounting/Types/CommonModelScopesBodyRequest.cs @@ -1,18 +1,18 @@ using System.Text.Json.Serialization; -using Merge.Client.Accounting; #nullable enable namespace Merge.Client.Accounting; -public class CommonModelScopesBodyRequest +public record CommonModelScopesBodyRequest { [JsonPropertyName("model_id")] - public string ModelId { get; init; } + public required string ModelId { get; set; } [JsonPropertyName("enabled_actions")] - public IEnumerable EnabledActions { get; init; } + public IEnumerable EnabledActions { get; set; } = + new List(); [JsonPropertyName("disabled_fields")] - public IEnumerable DisabledFields { get; init; } + public IEnumerable DisabledFields { get; set; } = new List(); } diff --git a/src/Merge.Client/Accounting/Types/CompanyInfo.cs b/src/Merge.Client/Accounting/Types/CompanyInfo.cs index 932f644a..c507a5ed 100644 --- a/src/Merge.Client/Accounting/Types/CompanyInfo.cs +++ b/src/Merge.Client/Accounting/Types/CompanyInfo.cs @@ -1,62 +1,61 @@ using System.Text.Json.Serialization; -using Merge.Client.Accounting; #nullable enable namespace Merge.Client.Accounting; -public class CompanyInfo +public record CompanyInfo { [JsonPropertyName("id")] - public string? Id { get; init; } + public string? Id { get; set; } /// /// The third-party API ID of the matching object. /// [JsonPropertyName("remote_id")] - public string? RemoteId { get; init; } + public string? RemoteId { get; set; } /// /// The datetime that this object was created by Merge. /// [JsonPropertyName("created_at")] - public DateTime? CreatedAt { get; init; } + public DateTime? CreatedAt { get; set; } /// /// The datetime that this object was modified by Merge. /// [JsonPropertyName("modified_at")] - public DateTime? ModifiedAt { get; init; } + public DateTime? ModifiedAt { get; set; } /// /// The company's name. /// [JsonPropertyName("name")] - public string? Name { get; init; } + public string? Name { get; set; } /// /// The company's legal name. /// [JsonPropertyName("legal_name")] - public string? LegalName { get; init; } + public string? LegalName { get; set; } /// /// The company's tax number. /// [JsonPropertyName("tax_number")] - public string? TaxNumber { get; init; } + public string? TaxNumber { get; set; } /// /// The company's fiscal year end month. /// [JsonPropertyName("fiscal_year_end_month")] - public int? FiscalYearEndMonth { get; init; } + public int? FiscalYearEndMonth { get; set; } /// /// The company's fiscal year end day. /// [JsonPropertyName("fiscal_year_end_day")] - public int? FiscalYearEndDay { get; init; } + public int? FiscalYearEndDay { get; set; } /// /// The currency set in the company's accounting platform. @@ -369,35 +368,35 @@ public class CompanyInfo /// - `ZWL` - Zimbabwean Dollar (2009) /// [JsonPropertyName("currency")] - public CurrencyEnum? Currency { get; init; } + public CurrencyEnum? Currency { get; set; } /// /// When the third party's company was created. /// [JsonPropertyName("remote_created_at")] - public DateTime? RemoteCreatedAt { get; init; } + public DateTime? RemoteCreatedAt { get; set; } /// /// The company's urls. /// [JsonPropertyName("urls")] - public IEnumerable? Urls { get; init; } + public IEnumerable? Urls { get; set; } [JsonPropertyName("addresses")] - public IEnumerable
? Addresses { get; init; } + public IEnumerable
? Addresses { get; set; } [JsonPropertyName("phone_numbers")] - public IEnumerable? PhoneNumbers { get; init; } + public IEnumerable? PhoneNumbers { get; set; } /// /// Indicates whether or not this object has been deleted in the third party platform. /// [JsonPropertyName("remote_was_deleted")] - public bool? RemoteWasDeleted { get; init; } + public bool? RemoteWasDeleted { get; set; } [JsonPropertyName("field_mappings")] - public Dictionary? FieldMappings { get; init; } + public Dictionary? FieldMappings { get; set; } [JsonPropertyName("remote_data")] - public IEnumerable? RemoteData { get; init; } + public IEnumerable? RemoteData { get; set; } } diff --git a/src/Merge.Client/Accounting/Types/Contact.cs b/src/Merge.Client/Accounting/Types/Contact.cs index b6843934..db3d3901 100644 --- a/src/Merge.Client/Accounting/Types/Contact.cs +++ b/src/Merge.Client/Accounting/Types/Contact.cs @@ -1,5 +1,4 @@ using System.Text.Json.Serialization; -using Merge.Client.Accounting; using Merge.Client.Core; using OneOf; @@ -7,58 +6,58 @@ namespace Merge.Client.Accounting; -public class Contact +public record Contact { [JsonPropertyName("id")] - public string? Id { get; init; } + public string? Id { get; set; } /// /// The third-party API ID of the matching object. /// [JsonPropertyName("remote_id")] - public string? RemoteId { get; init; } + public string? RemoteId { get; set; } /// /// The datetime that this object was created by Merge. /// [JsonPropertyName("created_at")] - public DateTime? CreatedAt { get; init; } + public DateTime? CreatedAt { get; set; } /// /// The datetime that this object was modified by Merge. /// [JsonPropertyName("modified_at")] - public DateTime? ModifiedAt { get; init; } + public DateTime? ModifiedAt { get; set; } /// /// The contact's name. /// [JsonPropertyName("name")] - public string? Name { get; init; } + public string? Name { get; set; } /// /// Whether the contact is a supplier. /// [JsonPropertyName("is_supplier")] - public bool? IsSupplier { get; init; } + public bool? IsSupplier { get; set; } /// /// Whether the contact is a customer. /// [JsonPropertyName("is_customer")] - public bool? IsCustomer { get; init; } + public bool? IsCustomer { get; set; } /// /// The contact's email address. /// [JsonPropertyName("email_address")] - public string? EmailAddress { get; init; } + public string? EmailAddress { get; set; } /// /// The contact's tax number. /// [JsonPropertyName("tax_number")] - public string? TaxNumber { get; init; } + public string? TaxNumber { get; set; } /// /// The contact's status @@ -67,25 +66,25 @@ public class Contact /// - `ARCHIVED` - ARCHIVED /// [JsonPropertyName("status")] - public Status7D1Enum? Status { get; init; } + public Status7D1Enum? Status { get; set; } /// /// The currency the contact's transactions are in. /// [JsonPropertyName("currency")] - public string? Currency { get; init; } + public string? Currency { get; set; } /// /// When the third party's contact was updated. /// [JsonPropertyName("remote_updated_at")] - public DateTime? RemoteUpdatedAt { get; init; } + public DateTime? RemoteUpdatedAt { get; set; } /// /// The company the contact belongs to. /// [JsonPropertyName("company")] - public string? Company { get; init; } + public string? Company { get; set; } /// /// `Address` object IDs for the given `Contacts` object. @@ -97,23 +96,23 @@ public class Contact OneOfSerializer> >) )] - public IEnumerable>? Addresses { get; init; } + public IEnumerable>? Addresses { get; set; } /// /// `AccountingPhoneNumber` object for the given `Contacts` object. /// [JsonPropertyName("phone_numbers")] - public IEnumerable? PhoneNumbers { get; init; } + public IEnumerable? PhoneNumbers { get; set; } /// /// Indicates whether or not this object has been deleted in the third party platform. /// [JsonPropertyName("remote_was_deleted")] - public bool? RemoteWasDeleted { get; init; } + public bool? RemoteWasDeleted { get; set; } [JsonPropertyName("field_mappings")] - public Dictionary? FieldMappings { get; init; } + public Dictionary? FieldMappings { get; set; } [JsonPropertyName("remote_data")] - public IEnumerable? RemoteData { get; init; } + public IEnumerable? RemoteData { get; set; } } diff --git a/src/Merge.Client/Accounting/Types/ContactRequest.cs b/src/Merge.Client/Accounting/Types/ContactRequest.cs index c4eed9ee..8b9b1519 100644 --- a/src/Merge.Client/Accounting/Types/ContactRequest.cs +++ b/src/Merge.Client/Accounting/Types/ContactRequest.cs @@ -1,5 +1,4 @@ using System.Text.Json.Serialization; -using Merge.Client.Accounting; using Merge.Client.Core; using OneOf; @@ -7,37 +6,37 @@ namespace Merge.Client.Accounting; -public class ContactRequest +public record ContactRequest { /// /// The contact's name. /// [JsonPropertyName("name")] - public string? Name { get; init; } + public string? Name { get; set; } /// /// Whether the contact is a supplier. /// [JsonPropertyName("is_supplier")] - public bool? IsSupplier { get; init; } + public bool? IsSupplier { get; set; } /// /// Whether the contact is a customer. /// [JsonPropertyName("is_customer")] - public bool? IsCustomer { get; init; } + public bool? IsCustomer { get; set; } /// /// The contact's email address. /// [JsonPropertyName("email_address")] - public string? EmailAddress { get; init; } + public string? EmailAddress { get; set; } /// /// The contact's tax number. /// [JsonPropertyName("tax_number")] - public string? TaxNumber { get; init; } + public string? TaxNumber { get; set; } /// /// The contact's status @@ -46,19 +45,19 @@ public class ContactRequest /// - `ARCHIVED` - ARCHIVED /// [JsonPropertyName("status")] - public Status7D1Enum? Status { get; init; } + public Status7D1Enum? Status { get; set; } /// /// The currency the contact's transactions are in. /// [JsonPropertyName("currency")] - public string? Currency { get; init; } + public string? Currency { get; set; } /// /// The company the contact belongs to. /// [JsonPropertyName("company")] - public string? Company { get; init; } + public string? Company { get; set; } /// /// `Address` object IDs for the given `Contacts` object. @@ -70,17 +69,17 @@ public class ContactRequest OneOfSerializer> >) )] - public IEnumerable>? Addresses { get; init; } + public IEnumerable>? Addresses { get; set; } /// /// `AccountingPhoneNumber` object for the given `Contacts` object. /// [JsonPropertyName("phone_numbers")] - public IEnumerable? PhoneNumbers { get; init; } + public IEnumerable? PhoneNumbers { get; set; } [JsonPropertyName("integration_params")] - public Dictionary? IntegrationParams { get; init; } + public Dictionary? IntegrationParams { get; set; } [JsonPropertyName("linked_account_params")] - public Dictionary? LinkedAccountParams { get; init; } + public Dictionary? LinkedAccountParams { get; set; } } diff --git a/src/Merge.Client/Accounting/Types/ContactResponse.cs b/src/Merge.Client/Accounting/Types/ContactResponse.cs index a2c558f2..f0fb91d7 100644 --- a/src/Merge.Client/Accounting/Types/ContactResponse.cs +++ b/src/Merge.Client/Accounting/Types/ContactResponse.cs @@ -1,21 +1,22 @@ using System.Text.Json.Serialization; -using Merge.Client.Accounting; #nullable enable namespace Merge.Client.Accounting; -public class ContactResponse +public record ContactResponse { [JsonPropertyName("model")] - public Contact Model { get; init; } + public required Contact Model { get; set; } [JsonPropertyName("warnings")] - public IEnumerable Warnings { get; init; } + public IEnumerable Warnings { get; set; } = + new List(); [JsonPropertyName("errors")] - public IEnumerable Errors { get; init; } + public IEnumerable Errors { get; set; } = + new List(); [JsonPropertyName("logs")] - public IEnumerable? Logs { get; init; } + public IEnumerable? Logs { get; set; } } diff --git a/src/Merge.Client/Accounting/Types/CountryEnum.cs b/src/Merge.Client/Accounting/Types/CountryEnum.cs index bc2d8c39..d92204bc 100644 --- a/src/Merge.Client/Accounting/Types/CountryEnum.cs +++ b/src/Merge.Client/Accounting/Types/CountryEnum.cs @@ -1,6 +1,5 @@ using System.Runtime.Serialization; using System.Text.Json.Serialization; -using Merge.Client.Accounting; using Merge.Client.Core; #nullable enable diff --git a/src/Merge.Client/Accounting/Types/CreditNote.cs b/src/Merge.Client/Accounting/Types/CreditNote.cs index 693331b1..92666709 100644 --- a/src/Merge.Client/Accounting/Types/CreditNote.cs +++ b/src/Merge.Client/Accounting/Types/CreditNote.cs @@ -1,5 +1,4 @@ using System.Text.Json.Serialization; -using Merge.Client.Accounting; using Merge.Client.Core; using OneOf; @@ -7,34 +6,34 @@ namespace Merge.Client.Accounting; -public class CreditNote +public record CreditNote { [JsonPropertyName("id")] - public string? Id { get; init; } + public string? Id { get; set; } /// /// The third-party API ID of the matching object. /// [JsonPropertyName("remote_id")] - public string? RemoteId { get; init; } + public string? RemoteId { get; set; } /// /// The datetime that this object was created by Merge. /// [JsonPropertyName("created_at")] - public DateTime? CreatedAt { get; init; } + public DateTime? CreatedAt { get; set; } /// /// The datetime that this object was modified by Merge. /// [JsonPropertyName("modified_at")] - public DateTime? ModifiedAt { get; init; } + public DateTime? ModifiedAt { get; set; } /// /// The credit note's transaction date. /// [JsonPropertyName("transaction_date")] - public DateTime? TransactionDate { get; init; } + public DateTime? TransactionDate { get; set; } /// /// The credit note's status. @@ -44,48 +43,48 @@ public class CreditNote /// - `PAID` - PAID /// [JsonPropertyName("status")] - public CreditNoteStatusEnum? Status { get; init; } + public CreditNoteStatusEnum? Status { get; set; } /// /// The credit note's number. /// [JsonPropertyName("number")] - public string? Number { get; init; } + public string? Number { get; set; } /// /// The credit note's contact. /// [JsonPropertyName("contact")] [JsonConverter(typeof(OneOfSerializer>))] - public OneOf? Contact { get; init; } + public OneOf? Contact { get; set; } /// /// The company the credit note belongs to. /// [JsonPropertyName("company")] [JsonConverter(typeof(OneOfSerializer>))] - public OneOf? Company { get; init; } + public OneOf? Company { get; set; } /// /// The credit note's exchange rate. /// [JsonPropertyName("exchange_rate")] - public string? ExchangeRate { get; init; } + public string? ExchangeRate { get; set; } /// /// The credit note's total amount. /// [JsonPropertyName("total_amount")] - public double? TotalAmount { get; init; } + public double? TotalAmount { get; set; } /// /// The amount of value remaining in the credit note that the customer can use. /// [JsonPropertyName("remaining_credit")] - public double? RemainingCredit { get; init; } + public double? RemainingCredit { get; set; } [JsonPropertyName("line_items")] - public IEnumerable? LineItems { get; init; } + public IEnumerable? LineItems { get; set; } [JsonPropertyName("tracking_categories")] [JsonConverter( @@ -94,7 +93,7 @@ public class CreditNote OneOfSerializer> >) )] - public IEnumerable>? TrackingCategories { get; init; } + public IEnumerable>? TrackingCategories { get; set; } /// /// The credit note's currency. @@ -407,19 +406,19 @@ public class CreditNote /// - `ZWL` - Zimbabwean Dollar (2009) /// [JsonPropertyName("currency")] - public CurrencyEnum? Currency { get; init; } + public CurrencyEnum? Currency { get; set; } /// /// When the third party's credit note was created. /// [JsonPropertyName("remote_created_at")] - public DateTime? RemoteCreatedAt { get; init; } + public DateTime? RemoteCreatedAt { get; set; } /// /// When the third party's credit note was updated. /// [JsonPropertyName("remote_updated_at")] - public DateTime? RemoteUpdatedAt { get; init; } + public DateTime? RemoteUpdatedAt { get; set; } /// /// Array of `Payment` object IDs @@ -431,7 +430,7 @@ public class CreditNote OneOfSerializer> >) )] - public IEnumerable>? Payments { get; init; } + public IEnumerable>? Payments { get; set; } /// /// A list of the Payment Applied to Lines common models related to a given Invoice, Credit Note, or Journal Entry. @@ -443,24 +442,24 @@ public class CreditNote OneOfSerializer> >) )] - public IEnumerable>? AppliedPayments { get; init; } + public IEnumerable>? AppliedPayments { get; set; } /// /// Indicates whether or not this object has been deleted in the third party platform. /// [JsonPropertyName("remote_was_deleted")] - public bool? RemoteWasDeleted { get; init; } + public bool? RemoteWasDeleted { get; set; } /// /// The accounting period that the CreditNote was generated in. /// [JsonPropertyName("accounting_period")] [JsonConverter(typeof(OneOfSerializer>))] - public OneOf? AccountingPeriod { get; init; } + public OneOf? AccountingPeriod { get; set; } [JsonPropertyName("field_mappings")] - public Dictionary? FieldMappings { get; init; } + public Dictionary? FieldMappings { get; set; } [JsonPropertyName("remote_data")] - public IEnumerable? RemoteData { get; init; } + public IEnumerable? RemoteData { get; set; } } diff --git a/src/Merge.Client/Accounting/Types/CreditNoteLineItem.cs b/src/Merge.Client/Accounting/Types/CreditNoteLineItem.cs index 5c9e0c20..978175f6 100644 --- a/src/Merge.Client/Accounting/Types/CreditNoteLineItem.cs +++ b/src/Merge.Client/Accounting/Types/CreditNoteLineItem.cs @@ -1,5 +1,4 @@ using System.Text.Json.Serialization; -using Merge.Client.Accounting; using Merge.Client.Core; using OneOf; @@ -7,97 +6,97 @@ namespace Merge.Client.Accounting; -public class CreditNoteLineItem +public record CreditNoteLineItem { [JsonPropertyName("id")] - public string? Id { get; init; } + public string? Id { get; set; } /// /// The third-party API ID of the matching object. /// [JsonPropertyName("remote_id")] - public string? RemoteId { get; init; } + public string? RemoteId { get; set; } /// /// The datetime that this object was created by Merge. /// [JsonPropertyName("created_at")] - public DateTime? CreatedAt { get; init; } + public DateTime? CreatedAt { get; set; } /// /// The datetime that this object was modified by Merge. /// [JsonPropertyName("modified_at")] - public DateTime? ModifiedAt { get; init; } + public DateTime? ModifiedAt { get; set; } [JsonPropertyName("item")] [JsonConverter(typeof(OneOfSerializer>))] - public OneOf? Item { get; init; } + public OneOf? Item { get; set; } /// /// The credit note line item's name. /// [JsonPropertyName("name")] - public string? Name { get; init; } + public string? Name { get; set; } /// /// The description of the item that is owed. /// [JsonPropertyName("description")] - public string? Description { get; init; } + public string? Description { get; set; } /// /// The credit note line item's quantity. /// [JsonPropertyName("quantity")] - public string? Quantity { get; init; } + public string? Quantity { get; set; } /// /// The credit note line item's memo. /// [JsonPropertyName("memo")] - public string? Memo { get; init; } + public string? Memo { get; set; } /// /// The credit note line item's unit price. /// [JsonPropertyName("unit_price")] - public string? UnitPrice { get; init; } + public string? UnitPrice { get; set; } /// /// The credit note line item's total. /// [JsonPropertyName("total_line_amount")] - public string? TotalLineAmount { get; init; } + public string? TotalLineAmount { get; set; } /// /// The credit note line item's associated tracking category. /// [JsonPropertyName("tracking_category")] - public string? TrackingCategory { get; init; } + public string? TrackingCategory { get; set; } /// /// The credit note line item's associated tracking categories. /// [JsonPropertyName("tracking_categories")] - public IEnumerable TrackingCategories { get; init; } + public IEnumerable TrackingCategories { get; set; } = new List(); /// /// The credit note line item's account. /// [JsonPropertyName("account")] - public string? Account { get; init; } + public string? Account { get; set; } /// /// The company the credit note belongs to. /// [JsonPropertyName("company")] [JsonConverter(typeof(OneOfSerializer>))] - public OneOf? Company { get; init; } + public OneOf? Company { get; set; } /// /// Indicates whether or not this object has been deleted in the third party platform. /// [JsonPropertyName("remote_was_deleted")] - public bool? RemoteWasDeleted { get; init; } + public bool? RemoteWasDeleted { get; set; } } diff --git a/src/Merge.Client/Accounting/Types/CreditNoteStatusEnum.cs b/src/Merge.Client/Accounting/Types/CreditNoteStatusEnum.cs index 27f8a995..f32f2b05 100644 --- a/src/Merge.Client/Accounting/Types/CreditNoteStatusEnum.cs +++ b/src/Merge.Client/Accounting/Types/CreditNoteStatusEnum.cs @@ -1,6 +1,5 @@ using System.Runtime.Serialization; using System.Text.Json.Serialization; -using Merge.Client.Accounting; using Merge.Client.Core; #nullable enable diff --git a/src/Merge.Client/Accounting/Types/CurrencyEnum.cs b/src/Merge.Client/Accounting/Types/CurrencyEnum.cs index f27941cf..57d465e3 100644 --- a/src/Merge.Client/Accounting/Types/CurrencyEnum.cs +++ b/src/Merge.Client/Accounting/Types/CurrencyEnum.cs @@ -1,6 +1,5 @@ using System.Runtime.Serialization; using System.Text.Json.Serialization; -using Merge.Client.Accounting; using Merge.Client.Core; #nullable enable diff --git a/src/Merge.Client/Accounting/Types/DataPassthroughRequest.cs b/src/Merge.Client/Accounting/Types/DataPassthroughRequest.cs index 9bab55a7..5615cae1 100644 --- a/src/Merge.Client/Accounting/Types/DataPassthroughRequest.cs +++ b/src/Merge.Client/Accounting/Types/DataPassthroughRequest.cs @@ -1,51 +1,50 @@ using System.Text.Json.Serialization; -using Merge.Client.Accounting; #nullable enable namespace Merge.Client.Accounting; -public class DataPassthroughRequest +public record DataPassthroughRequest { [JsonPropertyName("method")] - public MethodEnum Method { get; init; } + public required MethodEnum Method { get; set; } /// /// The path of the request in the third party's platform. /// [JsonPropertyName("path")] - public string Path { get; init; } + public required string Path { get; set; } /// /// An optional override of the third party's base url for the request. /// [JsonPropertyName("base_url_override")] - public string? BaseUrlOverride { get; init; } + public string? BaseUrlOverride { get; set; } /// /// The data with the request. You must include a `request_format` parameter matching the data's format /// [JsonPropertyName("data")] - public string? Data { get; init; } + public string? Data { get; set; } /// /// Pass an array of `MultipartFormField` objects in here instead of using the `data` param if `request_format` is set to `MULTIPART`. /// [JsonPropertyName("multipart_form_data")] - public IEnumerable? MultipartFormData { get; init; } + public IEnumerable? MultipartFormData { get; set; } /// /// The headers to use for the request (Merge will handle the account's authorization headers). `Content-Type` header is required for passthrough. Choose content type corresponding to expected format of receiving server. /// [JsonPropertyName("headers")] - public Dictionary? Headers { get; init; } + public Dictionary? Headers { get; set; } [JsonPropertyName("request_format")] - public RequestFormatEnum? RequestFormat { get; init; } + public RequestFormatEnum? RequestFormat { get; set; } /// /// Optional. If true, the response will always be an object of the form `{"type": T, "value": ...}` where `T` will be one of `string, boolean, number, null, array, object`. /// [JsonPropertyName("normalize_response")] - public bool? NormalizeResponse { get; init; } + public bool? NormalizeResponse { get; set; } } diff --git a/src/Merge.Client/Accounting/Types/DebugModeLog.cs b/src/Merge.Client/Accounting/Types/DebugModeLog.cs index d3092a3a..5db304e7 100644 --- a/src/Merge.Client/Accounting/Types/DebugModeLog.cs +++ b/src/Merge.Client/Accounting/Types/DebugModeLog.cs @@ -1,18 +1,17 @@ using System.Text.Json.Serialization; -using Merge.Client.Accounting; #nullable enable namespace Merge.Client.Accounting; -public class DebugModeLog +public record DebugModeLog { [JsonPropertyName("log_id")] - public string LogId { get; init; } + public required string LogId { get; set; } [JsonPropertyName("dashboard_view")] - public string DashboardView { get; init; } + public required string DashboardView { get; set; } [JsonPropertyName("log_summary")] - public DebugModelLogSummary LogSummary { get; init; } + public required DebugModelLogSummary LogSummary { get; set; } } diff --git a/src/Merge.Client/Accounting/Types/DebugModelLogSummary.cs b/src/Merge.Client/Accounting/Types/DebugModelLogSummary.cs index 1eb96020..0cf0beb1 100644 --- a/src/Merge.Client/Accounting/Types/DebugModelLogSummary.cs +++ b/src/Merge.Client/Accounting/Types/DebugModelLogSummary.cs @@ -4,14 +4,14 @@ namespace Merge.Client.Accounting; -public class DebugModelLogSummary +public record DebugModelLogSummary { [JsonPropertyName("url")] - public string Url { get; init; } + public required string Url { get; set; } [JsonPropertyName("method")] - public string Method { get; init; } + public required string Method { get; set; } [JsonPropertyName("status_code")] - public int StatusCode { get; init; } + public required int StatusCode { get; set; } } diff --git a/src/Merge.Client/Accounting/Types/EnabledActionsEnum.cs b/src/Merge.Client/Accounting/Types/EnabledActionsEnum.cs index 86e76061..3a34d461 100644 --- a/src/Merge.Client/Accounting/Types/EnabledActionsEnum.cs +++ b/src/Merge.Client/Accounting/Types/EnabledActionsEnum.cs @@ -1,6 +1,5 @@ using System.Runtime.Serialization; using System.Text.Json.Serialization; -using Merge.Client.Accounting; using Merge.Client.Core; #nullable enable diff --git a/src/Merge.Client/Accounting/Types/EncodingEnum.cs b/src/Merge.Client/Accounting/Types/EncodingEnum.cs index 3acf7a11..7ad67c79 100644 --- a/src/Merge.Client/Accounting/Types/EncodingEnum.cs +++ b/src/Merge.Client/Accounting/Types/EncodingEnum.cs @@ -1,6 +1,5 @@ using System.Runtime.Serialization; using System.Text.Json.Serialization; -using Merge.Client.Accounting; using Merge.Client.Core; #nullable enable diff --git a/src/Merge.Client/Accounting/Types/ErrorValidationProblem.cs b/src/Merge.Client/Accounting/Types/ErrorValidationProblem.cs index b879f714..08c69ba8 100644 --- a/src/Merge.Client/Accounting/Types/ErrorValidationProblem.cs +++ b/src/Merge.Client/Accounting/Types/ErrorValidationProblem.cs @@ -1,21 +1,20 @@ using System.Text.Json.Serialization; -using Merge.Client.Accounting; #nullable enable namespace Merge.Client.Accounting; -public class ErrorValidationProblem +public record ErrorValidationProblem { [JsonPropertyName("source")] - public ValidationProblemSource? Source { get; init; } + public ValidationProblemSource? Source { get; set; } [JsonPropertyName("title")] - public string Title { get; init; } + public required string Title { get; set; } [JsonPropertyName("detail")] - public string Detail { get; init; } + public required string Detail { get; set; } [JsonPropertyName("problem_type")] - public string ProblemType { get; init; } + public required string ProblemType { get; set; } } diff --git a/src/Merge.Client/Accounting/Types/EventTypeEnum.cs b/src/Merge.Client/Accounting/Types/EventTypeEnum.cs index d4082ee9..44fab163 100644 --- a/src/Merge.Client/Accounting/Types/EventTypeEnum.cs +++ b/src/Merge.Client/Accounting/Types/EventTypeEnum.cs @@ -1,6 +1,5 @@ using System.Runtime.Serialization; using System.Text.Json.Serialization; -using Merge.Client.Accounting; using Merge.Client.Core; #nullable enable diff --git a/src/Merge.Client/Accounting/Types/Expense.cs b/src/Merge.Client/Accounting/Types/Expense.cs index 2e9632bc..9f4c9a32 100644 --- a/src/Merge.Client/Accounting/Types/Expense.cs +++ b/src/Merge.Client/Accounting/Types/Expense.cs @@ -1,5 +1,4 @@ using System.Text.Json.Serialization; -using Merge.Client.Accounting; using Merge.Client.Core; using OneOf; @@ -7,72 +6,72 @@ namespace Merge.Client.Accounting; -public class Expense +public record Expense { [JsonPropertyName("id")] - public string? Id { get; init; } + public string? Id { get; set; } /// /// The third-party API ID of the matching object. /// [JsonPropertyName("remote_id")] - public string? RemoteId { get; init; } + public string? RemoteId { get; set; } /// /// The datetime that this object was created by Merge. /// [JsonPropertyName("created_at")] - public DateTime? CreatedAt { get; init; } + public DateTime? CreatedAt { get; set; } /// /// The datetime that this object was modified by Merge. /// [JsonPropertyName("modified_at")] - public DateTime? ModifiedAt { get; init; } + public DateTime? ModifiedAt { get; set; } /// /// When the transaction occurred. /// [JsonPropertyName("transaction_date")] - public DateTime? TransactionDate { get; init; } + public DateTime? TransactionDate { get; set; } /// /// When the expense was created. /// [JsonPropertyName("remote_created_at")] - public DateTime? RemoteCreatedAt { get; init; } + public DateTime? RemoteCreatedAt { get; set; } /// /// The expense's payment account. /// [JsonPropertyName("account")] [JsonConverter(typeof(OneOfSerializer>))] - public OneOf? Account { get; init; } + public OneOf? Account { get; set; } /// /// The expense's contact. /// [JsonPropertyName("contact")] [JsonConverter(typeof(OneOfSerializer>))] - public OneOf? Contact { get; init; } + public OneOf? Contact { get; set; } /// /// The expense's total amount. /// [JsonPropertyName("total_amount")] - public double? TotalAmount { get; init; } + public double? TotalAmount { get; set; } /// /// The expense's total amount before tax. /// [JsonPropertyName("sub_total")] - public double? SubTotal { get; init; } + public double? SubTotal { get; set; } /// /// The expense's total tax amount. /// [JsonPropertyName("total_tax_amount")] - public double? TotalTaxAmount { get; init; } + public double? TotalTaxAmount { get; set; } /// /// The expense's currency. @@ -385,29 +384,29 @@ public class Expense /// - `ZWL` - Zimbabwean Dollar (2009) /// [JsonPropertyName("currency")] - public CurrencyEnum? Currency { get; init; } + public CurrencyEnum? Currency { get; set; } /// /// The expense's exchange rate. /// [JsonPropertyName("exchange_rate")] - public string? ExchangeRate { get; init; } + public string? ExchangeRate { get; set; } /// /// The company the expense belongs to. /// [JsonPropertyName("company")] [JsonConverter(typeof(OneOfSerializer>))] - public OneOf? Company { get; init; } + public OneOf? Company { get; set; } /// /// The expense's private note. /// [JsonPropertyName("memo")] - public string? Memo { get; init; } + public string? Memo { get; set; } [JsonPropertyName("lines")] - public IEnumerable? Lines { get; init; } + public IEnumerable? Lines { get; set; } [JsonPropertyName("tracking_categories")] [JsonConverter( @@ -416,24 +415,24 @@ public class Expense OneOfSerializer> >) )] - public IEnumerable>? TrackingCategories { get; init; } + public IEnumerable>? TrackingCategories { get; set; } /// /// Indicates whether or not this object has been deleted in the third party platform. /// [JsonPropertyName("remote_was_deleted")] - public bool? RemoteWasDeleted { get; init; } + public bool? RemoteWasDeleted { get; set; } /// /// The accounting period that the Expense was generated in. /// [JsonPropertyName("accounting_period")] [JsonConverter(typeof(OneOfSerializer>))] - public OneOf? AccountingPeriod { get; init; } + public OneOf? AccountingPeriod { get; set; } [JsonPropertyName("field_mappings")] - public Dictionary? FieldMappings { get; init; } + public Dictionary? FieldMappings { get; set; } [JsonPropertyName("remote_data")] - public IEnumerable? RemoteData { get; init; } + public IEnumerable? RemoteData { get; set; } } diff --git a/src/Merge.Client/Accounting/Types/ExpenseLine.cs b/src/Merge.Client/Accounting/Types/ExpenseLine.cs index a1e93a71..e1705e75 100644 --- a/src/Merge.Client/Accounting/Types/ExpenseLine.cs +++ b/src/Merge.Client/Accounting/Types/ExpenseLine.cs @@ -1,5 +1,4 @@ using System.Text.Json.Serialization; -using Merge.Client.Accounting; using Merge.Client.Core; using OneOf; @@ -7,45 +6,45 @@ namespace Merge.Client.Accounting; -public class ExpenseLine +public record ExpenseLine { [JsonPropertyName("id")] - public string? Id { get; init; } + public string? Id { get; set; } /// /// The third-party API ID of the matching object. /// [JsonPropertyName("remote_id")] - public string? RemoteId { get; init; } + public string? RemoteId { get; set; } /// /// The datetime that this object was created by Merge. /// [JsonPropertyName("created_at")] - public DateTime? CreatedAt { get; init; } + public DateTime? CreatedAt { get; set; } /// /// The datetime that this object was modified by Merge. /// [JsonPropertyName("modified_at")] - public DateTime? ModifiedAt { get; init; } + public DateTime? ModifiedAt { get; set; } /// /// The line's item. /// [JsonPropertyName("item")] [JsonConverter(typeof(OneOfSerializer>))] - public OneOf? Item { get; init; } + public OneOf? Item { get; set; } /// /// The line's net amount. /// [JsonPropertyName("net_amount")] - public double? NetAmount { get; init; } + public double? NetAmount { get; set; } [JsonPropertyName("tracking_category")] [JsonConverter(typeof(OneOfSerializer>))] - public OneOf? TrackingCategory { get; init; } + public OneOf? TrackingCategory { get; set; } [JsonPropertyName("tracking_categories")] [JsonConverter( @@ -54,13 +53,13 @@ public class ExpenseLine OneOfSerializer> >) )] - public IEnumerable>? TrackingCategories { get; init; } + public IEnumerable>? TrackingCategories { get; set; } /// /// The company the line belongs to. /// [JsonPropertyName("company")] - public string? Company { get; init; } + public string? Company { get; set; } /// /// The expense line item's currency. @@ -373,37 +372,37 @@ public class ExpenseLine /// - `ZWL` - Zimbabwean Dollar (2009) /// [JsonPropertyName("currency")] - public CurrencyEnum? Currency { get; init; } + public CurrencyEnum? Currency { get; set; } /// /// The expense's payment account. /// [JsonPropertyName("account")] [JsonConverter(typeof(OneOfSerializer>))] - public OneOf? Account { get; init; } + public OneOf? Account { get; set; } /// /// The expense's contact. /// [JsonPropertyName("contact")] [JsonConverter(typeof(OneOfSerializer>))] - public OneOf? Contact { get; init; } + public OneOf? Contact { get; set; } /// /// The description of the item that was purchased by the company. /// [JsonPropertyName("description")] - public string? Description { get; init; } + public string? Description { get; set; } /// /// The expense line item's exchange rate. /// [JsonPropertyName("exchange_rate")] - public string? ExchangeRate { get; init; } + public string? ExchangeRate { get; set; } /// /// Indicates whether or not this object has been deleted in the third party platform. /// [JsonPropertyName("remote_was_deleted")] - public bool? RemoteWasDeleted { get; init; } + public bool? RemoteWasDeleted { get; set; } } diff --git a/src/Merge.Client/Accounting/Types/ExpenseLineRequest.cs b/src/Merge.Client/Accounting/Types/ExpenseLineRequest.cs index 00c6fb13..f673b554 100644 --- a/src/Merge.Client/Accounting/Types/ExpenseLineRequest.cs +++ b/src/Merge.Client/Accounting/Types/ExpenseLineRequest.cs @@ -1,5 +1,4 @@ using System.Text.Json.Serialization; -using Merge.Client.Accounting; using Merge.Client.Core; using OneOf; @@ -7,30 +6,30 @@ namespace Merge.Client.Accounting; -public class ExpenseLineRequest +public record ExpenseLineRequest { /// /// The third-party API ID of the matching object. /// [JsonPropertyName("remote_id")] - public string? RemoteId { get; init; } + public string? RemoteId { get; set; } /// /// The line's item. /// [JsonPropertyName("item")] [JsonConverter(typeof(OneOfSerializer>))] - public OneOf? Item { get; init; } + public OneOf? Item { get; set; } /// /// The line's net amount. /// [JsonPropertyName("net_amount")] - public double? NetAmount { get; init; } + public double? NetAmount { get; set; } [JsonPropertyName("tracking_category")] [JsonConverter(typeof(OneOfSerializer>))] - public OneOf? TrackingCategory { get; init; } + public OneOf? TrackingCategory { get; set; } [JsonPropertyName("tracking_categories")] [JsonConverter( @@ -39,13 +38,13 @@ public class ExpenseLineRequest OneOfSerializer> >) )] - public IEnumerable>? TrackingCategories { get; init; } + public IEnumerable>? TrackingCategories { get; set; } /// /// The company the line belongs to. /// [JsonPropertyName("company")] - public string? Company { get; init; } + public string? Company { get; set; } /// /// The expense line item's currency. @@ -358,37 +357,37 @@ public class ExpenseLineRequest /// - `ZWL` - Zimbabwean Dollar (2009) /// [JsonPropertyName("currency")] - public CurrencyEnum? Currency { get; init; } + public CurrencyEnum? Currency { get; set; } /// /// The expense's payment account. /// [JsonPropertyName("account")] [JsonConverter(typeof(OneOfSerializer>))] - public OneOf? Account { get; init; } + public OneOf? Account { get; set; } /// /// The expense's contact. /// [JsonPropertyName("contact")] [JsonConverter(typeof(OneOfSerializer>))] - public OneOf? Contact { get; init; } + public OneOf? Contact { get; set; } /// /// The description of the item that was purchased by the company. /// [JsonPropertyName("description")] - public string? Description { get; init; } + public string? Description { get; set; } /// /// The expense line item's exchange rate. /// [JsonPropertyName("exchange_rate")] - public string? ExchangeRate { get; init; } + public string? ExchangeRate { get; set; } [JsonPropertyName("integration_params")] - public Dictionary? IntegrationParams { get; init; } + public Dictionary? IntegrationParams { get; set; } [JsonPropertyName("linked_account_params")] - public Dictionary? LinkedAccountParams { get; init; } + public Dictionary? LinkedAccountParams { get; set; } } diff --git a/src/Merge.Client/Accounting/Types/ExpenseRequest.cs b/src/Merge.Client/Accounting/Types/ExpenseRequest.cs index f7564bac..fd90430e 100644 --- a/src/Merge.Client/Accounting/Types/ExpenseRequest.cs +++ b/src/Merge.Client/Accounting/Types/ExpenseRequest.cs @@ -1,5 +1,4 @@ using System.Text.Json.Serialization; -using Merge.Client.Accounting; using Merge.Client.Core; using OneOf; @@ -7,45 +6,45 @@ namespace Merge.Client.Accounting; -public class ExpenseRequest +public record ExpenseRequest { /// /// When the transaction occurred. /// [JsonPropertyName("transaction_date")] - public DateTime? TransactionDate { get; init; } + public DateTime? TransactionDate { get; set; } /// /// The expense's payment account. /// [JsonPropertyName("account")] [JsonConverter(typeof(OneOfSerializer>))] - public OneOf? Account { get; init; } + public OneOf? Account { get; set; } /// /// The expense's contact. /// [JsonPropertyName("contact")] [JsonConverter(typeof(OneOfSerializer>))] - public OneOf? Contact { get; init; } + public OneOf? Contact { get; set; } /// /// The expense's total amount. /// [JsonPropertyName("total_amount")] - public double? TotalAmount { get; init; } + public double? TotalAmount { get; set; } /// /// The expense's total amount before tax. /// [JsonPropertyName("sub_total")] - public double? SubTotal { get; init; } + public double? SubTotal { get; set; } /// /// The expense's total tax amount. /// [JsonPropertyName("total_tax_amount")] - public double? TotalTaxAmount { get; init; } + public double? TotalTaxAmount { get; set; } /// /// The expense's currency. @@ -358,29 +357,29 @@ public class ExpenseRequest /// - `ZWL` - Zimbabwean Dollar (2009) /// [JsonPropertyName("currency")] - public CurrencyEnum? Currency { get; init; } + public CurrencyEnum? Currency { get; set; } /// /// The expense's exchange rate. /// [JsonPropertyName("exchange_rate")] - public string? ExchangeRate { get; init; } + public string? ExchangeRate { get; set; } /// /// The company the expense belongs to. /// [JsonPropertyName("company")] [JsonConverter(typeof(OneOfSerializer>))] - public OneOf? Company { get; init; } + public OneOf? Company { get; set; } /// /// The expense's private note. /// [JsonPropertyName("memo")] - public string? Memo { get; init; } + public string? Memo { get; set; } [JsonPropertyName("lines")] - public IEnumerable? Lines { get; init; } + public IEnumerable? Lines { get; set; } [JsonPropertyName("tracking_categories")] [JsonConverter( @@ -389,18 +388,18 @@ public class ExpenseRequest OneOfSerializer> >) )] - public IEnumerable>? TrackingCategories { get; init; } + public IEnumerable>? TrackingCategories { get; set; } /// /// The accounting period that the Expense was generated in. /// [JsonPropertyName("accounting_period")] [JsonConverter(typeof(OneOfSerializer>))] - public OneOf? AccountingPeriod { get; init; } + public OneOf? AccountingPeriod { get; set; } [JsonPropertyName("integration_params")] - public Dictionary? IntegrationParams { get; init; } + public Dictionary? IntegrationParams { get; set; } [JsonPropertyName("linked_account_params")] - public Dictionary? LinkedAccountParams { get; init; } + public Dictionary? LinkedAccountParams { get; set; } } diff --git a/src/Merge.Client/Accounting/Types/ExpenseResponse.cs b/src/Merge.Client/Accounting/Types/ExpenseResponse.cs index a54d3eb6..9ee9c23e 100644 --- a/src/Merge.Client/Accounting/Types/ExpenseResponse.cs +++ b/src/Merge.Client/Accounting/Types/ExpenseResponse.cs @@ -1,21 +1,22 @@ using System.Text.Json.Serialization; -using Merge.Client.Accounting; #nullable enable namespace Merge.Client.Accounting; -public class ExpenseResponse +public record ExpenseResponse { [JsonPropertyName("model")] - public Expense Model { get; init; } + public required Expense Model { get; set; } [JsonPropertyName("warnings")] - public IEnumerable Warnings { get; init; } + public IEnumerable Warnings { get; set; } = + new List(); [JsonPropertyName("errors")] - public IEnumerable Errors { get; init; } + public IEnumerable Errors { get; set; } = + new List(); [JsonPropertyName("logs")] - public IEnumerable? Logs { get; init; } + public IEnumerable? Logs { get; set; } } diff --git a/src/Merge.Client/Accounting/Types/ExternalTargetFieldApi.cs b/src/Merge.Client/Accounting/Types/ExternalTargetFieldApi.cs index e18365ed..76e6c20c 100644 --- a/src/Merge.Client/Accounting/Types/ExternalTargetFieldApi.cs +++ b/src/Merge.Client/Accounting/Types/ExternalTargetFieldApi.cs @@ -4,14 +4,14 @@ namespace Merge.Client.Accounting; -public class ExternalTargetFieldApi +public record ExternalTargetFieldApi { [JsonPropertyName("name")] - public string? Name { get; init; } + public string? Name { get; set; } [JsonPropertyName("description")] - public string? Description { get; init; } + public string? Description { get; set; } [JsonPropertyName("is_mapped")] - public string? IsMapped { get; init; } + public string? IsMapped { get; set; } } diff --git a/src/Merge.Client/Accounting/Types/ExternalTargetFieldApiResponse.cs b/src/Merge.Client/Accounting/Types/ExternalTargetFieldApiResponse.cs index 0cb90ad9..49352f9c 100644 --- a/src/Merge.Client/Accounting/Types/ExternalTargetFieldApiResponse.cs +++ b/src/Merge.Client/Accounting/Types/ExternalTargetFieldApiResponse.cs @@ -1,66 +1,65 @@ using System.Text.Json.Serialization; -using Merge.Client.Accounting; #nullable enable namespace Merge.Client.Accounting; -public class ExternalTargetFieldApiResponse +public record ExternalTargetFieldApiResponse { [JsonPropertyName("Account")] - public IEnumerable? Account { get; init; } + public IEnumerable? Account { get; set; } [JsonPropertyName("AccountingAttachment")] - public IEnumerable? AccountingAttachment { get; init; } + public IEnumerable? AccountingAttachment { get; set; } [JsonPropertyName("BalanceSheet")] - public IEnumerable? BalanceSheet { get; init; } + public IEnumerable? BalanceSheet { get; set; } [JsonPropertyName("CashFlowStatement")] - public IEnumerable? CashFlowStatement { get; init; } + public IEnumerable? CashFlowStatement { get; set; } [JsonPropertyName("CompanyInfo")] - public IEnumerable? CompanyInfo { get; init; } + public IEnumerable? CompanyInfo { get; set; } [JsonPropertyName("Contact")] - public IEnumerable? Contact { get; init; } + public IEnumerable? Contact { get; set; } [JsonPropertyName("IncomeStatement")] - public IEnumerable? IncomeStatement { get; init; } + public IEnumerable? IncomeStatement { get; set; } [JsonPropertyName("CreditNote")] - public IEnumerable? CreditNote { get; init; } + public IEnumerable? CreditNote { get; set; } [JsonPropertyName("Item")] - public IEnumerable? Item { get; init; } + public IEnumerable? Item { get; set; } [JsonPropertyName("PurchaseOrder")] - public IEnumerable? PurchaseOrder { get; init; } + public IEnumerable? PurchaseOrder { get; set; } [JsonPropertyName("TrackingCategory")] - public IEnumerable? TrackingCategory { get; init; } + public IEnumerable? TrackingCategory { get; set; } [JsonPropertyName("JournalEntry")] - public IEnumerable? JournalEntry { get; init; } + public IEnumerable? JournalEntry { get; set; } [JsonPropertyName("TaxRate")] - public IEnumerable? TaxRate { get; init; } + public IEnumerable? TaxRate { get; set; } [JsonPropertyName("Invoice")] - public IEnumerable? Invoice { get; init; } + public IEnumerable? Invoice { get; set; } [JsonPropertyName("Payment")] - public IEnumerable? Payment { get; init; } + public IEnumerable? Payment { get; set; } [JsonPropertyName("Expense")] - public IEnumerable? Expense { get; init; } + public IEnumerable? Expense { get; set; } [JsonPropertyName("VendorCredit")] - public IEnumerable? VendorCredit { get; init; } + public IEnumerable? VendorCredit { get; set; } [JsonPropertyName("Transaction")] - public IEnumerable? Transaction { get; init; } + public IEnumerable? Transaction { get; set; } [JsonPropertyName("GeneralLedgerTransaction")] - public IEnumerable? GeneralLedgerTransaction { get; init; } + public IEnumerable? GeneralLedgerTransaction { get; set; } } diff --git a/src/Merge.Client/Accounting/Types/FieldMappingApiInstance.cs b/src/Merge.Client/Accounting/Types/FieldMappingApiInstance.cs index 0d2e5f08..5dbcc04e 100644 --- a/src/Merge.Client/Accounting/Types/FieldMappingApiInstance.cs +++ b/src/Merge.Client/Accounting/Types/FieldMappingApiInstance.cs @@ -1,21 +1,20 @@ using System.Text.Json.Serialization; -using Merge.Client.Accounting; #nullable enable namespace Merge.Client.Accounting; -public class FieldMappingApiInstance +public record FieldMappingApiInstance { [JsonPropertyName("id")] - public string? Id { get; init; } + public string? Id { get; set; } [JsonPropertyName("is_integration_wide")] - public bool? IsIntegrationWide { get; init; } + public bool? IsIntegrationWide { get; set; } [JsonPropertyName("target_field")] - public FieldMappingApiInstanceTargetField? TargetField { get; init; } + public FieldMappingApiInstanceTargetField? TargetField { get; set; } [JsonPropertyName("remote_field")] - public FieldMappingApiInstanceRemoteField? RemoteField { get; init; } + public FieldMappingApiInstanceRemoteField? RemoteField { get; set; } } diff --git a/src/Merge.Client/Accounting/Types/FieldMappingApiInstanceRemoteField.cs b/src/Merge.Client/Accounting/Types/FieldMappingApiInstanceRemoteField.cs index e2043f75..536898e4 100644 --- a/src/Merge.Client/Accounting/Types/FieldMappingApiInstanceRemoteField.cs +++ b/src/Merge.Client/Accounting/Types/FieldMappingApiInstanceRemoteField.cs @@ -1,18 +1,17 @@ using System.Text.Json.Serialization; -using Merge.Client.Accounting; #nullable enable namespace Merge.Client.Accounting; -public class FieldMappingApiInstanceRemoteField +public record FieldMappingApiInstanceRemoteField { [JsonPropertyName("remote_key_name")] - public string RemoteKeyName { get; init; } + public required string RemoteKeyName { get; set; } [JsonPropertyName("schema")] - public Dictionary Schema { get; init; } + public Dictionary Schema { get; set; } = new Dictionary(); [JsonPropertyName("remote_endpoint_info")] - public FieldMappingApiInstanceRemoteFieldRemoteEndpointInfo RemoteEndpointInfo { get; init; } + public required FieldMappingApiInstanceRemoteFieldRemoteEndpointInfo RemoteEndpointInfo { get; set; } } diff --git a/src/Merge.Client/Accounting/Types/FieldMappingApiInstanceRemoteFieldRemoteEndpointInfo.cs b/src/Merge.Client/Accounting/Types/FieldMappingApiInstanceRemoteFieldRemoteEndpointInfo.cs index 4c75252a..5557ccb0 100644 --- a/src/Merge.Client/Accounting/Types/FieldMappingApiInstanceRemoteFieldRemoteEndpointInfo.cs +++ b/src/Merge.Client/Accounting/Types/FieldMappingApiInstanceRemoteFieldRemoteEndpointInfo.cs @@ -4,14 +4,14 @@ namespace Merge.Client.Accounting; -public class FieldMappingApiInstanceRemoteFieldRemoteEndpointInfo +public record FieldMappingApiInstanceRemoteFieldRemoteEndpointInfo { [JsonPropertyName("method")] - public string? Method { get; init; } + public string? Method { get; set; } [JsonPropertyName("url_path")] - public string? UrlPath { get; init; } + public string? UrlPath { get; set; } [JsonPropertyName("field_traversal_path")] - public IEnumerable? FieldTraversalPath { get; init; } + public IEnumerable? FieldTraversalPath { get; set; } } diff --git a/src/Merge.Client/Accounting/Types/FieldMappingApiInstanceResponse.cs b/src/Merge.Client/Accounting/Types/FieldMappingApiInstanceResponse.cs index 6f59774e..e0c0dc54 100644 --- a/src/Merge.Client/Accounting/Types/FieldMappingApiInstanceResponse.cs +++ b/src/Merge.Client/Accounting/Types/FieldMappingApiInstanceResponse.cs @@ -1,66 +1,65 @@ using System.Text.Json.Serialization; -using Merge.Client.Accounting; #nullable enable namespace Merge.Client.Accounting; -public class FieldMappingApiInstanceResponse +public record FieldMappingApiInstanceResponse { [JsonPropertyName("Account")] - public IEnumerable? Account { get; init; } + public IEnumerable? Account { get; set; } [JsonPropertyName("AccountingAttachment")] - public IEnumerable? AccountingAttachment { get; init; } + public IEnumerable? AccountingAttachment { get; set; } [JsonPropertyName("BalanceSheet")] - public IEnumerable? BalanceSheet { get; init; } + public IEnumerable? BalanceSheet { get; set; } [JsonPropertyName("CashFlowStatement")] - public IEnumerable? CashFlowStatement { get; init; } + public IEnumerable? CashFlowStatement { get; set; } [JsonPropertyName("CompanyInfo")] - public IEnumerable? CompanyInfo { get; init; } + public IEnumerable? CompanyInfo { get; set; } [JsonPropertyName("Contact")] - public IEnumerable? Contact { get; init; } + public IEnumerable? Contact { get; set; } [JsonPropertyName("IncomeStatement")] - public IEnumerable? IncomeStatement { get; init; } + public IEnumerable? IncomeStatement { get; set; } [JsonPropertyName("CreditNote")] - public IEnumerable? CreditNote { get; init; } + public IEnumerable? CreditNote { get; set; } [JsonPropertyName("Item")] - public IEnumerable? Item { get; init; } + public IEnumerable? Item { get; set; } [JsonPropertyName("PurchaseOrder")] - public IEnumerable? PurchaseOrder { get; init; } + public IEnumerable? PurchaseOrder { get; set; } [JsonPropertyName("TrackingCategory")] - public IEnumerable? TrackingCategory { get; init; } + public IEnumerable? TrackingCategory { get; set; } [JsonPropertyName("JournalEntry")] - public IEnumerable? JournalEntry { get; init; } + public IEnumerable? JournalEntry { get; set; } [JsonPropertyName("TaxRate")] - public IEnumerable? TaxRate { get; init; } + public IEnumerable? TaxRate { get; set; } [JsonPropertyName("Invoice")] - public IEnumerable? Invoice { get; init; } + public IEnumerable? Invoice { get; set; } [JsonPropertyName("Payment")] - public IEnumerable? Payment { get; init; } + public IEnumerable? Payment { get; set; } [JsonPropertyName("Expense")] - public IEnumerable? Expense { get; init; } + public IEnumerable? Expense { get; set; } [JsonPropertyName("VendorCredit")] - public IEnumerable? VendorCredit { get; init; } + public IEnumerable? VendorCredit { get; set; } [JsonPropertyName("Transaction")] - public IEnumerable? Transaction { get; init; } + public IEnumerable? Transaction { get; set; } [JsonPropertyName("GeneralLedgerTransaction")] - public IEnumerable? GeneralLedgerTransaction { get; init; } + public IEnumerable? GeneralLedgerTransaction { get; set; } } diff --git a/src/Merge.Client/Accounting/Types/FieldMappingApiInstanceTargetField.cs b/src/Merge.Client/Accounting/Types/FieldMappingApiInstanceTargetField.cs index ac317e9d..e3532a71 100644 --- a/src/Merge.Client/Accounting/Types/FieldMappingApiInstanceTargetField.cs +++ b/src/Merge.Client/Accounting/Types/FieldMappingApiInstanceTargetField.cs @@ -4,14 +4,14 @@ namespace Merge.Client.Accounting; -public class FieldMappingApiInstanceTargetField +public record FieldMappingApiInstanceTargetField { [JsonPropertyName("name")] - public string Name { get; init; } + public required string Name { get; set; } [JsonPropertyName("description")] - public string Description { get; init; } + public required string Description { get; set; } [JsonPropertyName("is_organization_wide")] - public bool IsOrganizationWide { get; init; } + public required bool IsOrganizationWide { get; set; } } diff --git a/src/Merge.Client/Accounting/Types/FieldMappingInstanceResponse.cs b/src/Merge.Client/Accounting/Types/FieldMappingInstanceResponse.cs index 11545016..8cd27045 100644 --- a/src/Merge.Client/Accounting/Types/FieldMappingInstanceResponse.cs +++ b/src/Merge.Client/Accounting/Types/FieldMappingInstanceResponse.cs @@ -1,21 +1,22 @@ using System.Text.Json.Serialization; -using Merge.Client.Accounting; #nullable enable namespace Merge.Client.Accounting; -public class FieldMappingInstanceResponse +public record FieldMappingInstanceResponse { [JsonPropertyName("model")] - public FieldMappingApiInstance Model { get; init; } + public required FieldMappingApiInstance Model { get; set; } [JsonPropertyName("warnings")] - public IEnumerable Warnings { get; init; } + public IEnumerable Warnings { get; set; } = + new List(); [JsonPropertyName("errors")] - public IEnumerable Errors { get; init; } + public IEnumerable Errors { get; set; } = + new List(); [JsonPropertyName("logs")] - public IEnumerable? Logs { get; init; } + public IEnumerable? Logs { get; set; } } diff --git a/src/Merge.Client/Accounting/Types/FieldPermissionDeserializer.cs b/src/Merge.Client/Accounting/Types/FieldPermissionDeserializer.cs index 14c7389a..490e5ac7 100644 --- a/src/Merge.Client/Accounting/Types/FieldPermissionDeserializer.cs +++ b/src/Merge.Client/Accounting/Types/FieldPermissionDeserializer.cs @@ -4,11 +4,11 @@ namespace Merge.Client.Accounting; -public class FieldPermissionDeserializer +public record FieldPermissionDeserializer { [JsonPropertyName("enabled")] - public IEnumerable? Enabled { get; init; } + public IEnumerable? Enabled { get; set; } [JsonPropertyName("disabled")] - public IEnumerable? Disabled { get; init; } + public IEnumerable? Disabled { get; set; } } diff --git a/src/Merge.Client/Accounting/Types/FieldPermissionDeserializerRequest.cs b/src/Merge.Client/Accounting/Types/FieldPermissionDeserializerRequest.cs index 32a147dc..0b4f8b1a 100644 --- a/src/Merge.Client/Accounting/Types/FieldPermissionDeserializerRequest.cs +++ b/src/Merge.Client/Accounting/Types/FieldPermissionDeserializerRequest.cs @@ -4,11 +4,11 @@ namespace Merge.Client.Accounting; -public class FieldPermissionDeserializerRequest +public record FieldPermissionDeserializerRequest { [JsonPropertyName("enabled")] - public IEnumerable? Enabled { get; init; } + public IEnumerable? Enabled { get; set; } [JsonPropertyName("disabled")] - public IEnumerable? Disabled { get; init; } + public IEnumerable? Disabled { get; set; } } diff --git a/src/Merge.Client/Accounting/Types/IncomeStatement.cs b/src/Merge.Client/Accounting/Types/IncomeStatement.cs index 1f06e707..f5eda803 100644 --- a/src/Merge.Client/Accounting/Types/IncomeStatement.cs +++ b/src/Merge.Client/Accounting/Types/IncomeStatement.cs @@ -1,5 +1,4 @@ using System.Text.Json.Serialization; -using Merge.Client.Accounting; using Merge.Client.Core; using OneOf; @@ -7,34 +6,34 @@ namespace Merge.Client.Accounting; -public class IncomeStatement +public record IncomeStatement { [JsonPropertyName("id")] - public string? Id { get; init; } + public string? Id { get; set; } /// /// The third-party API ID of the matching object. /// [JsonPropertyName("remote_id")] - public string? RemoteId { get; init; } + public string? RemoteId { get; set; } /// /// The datetime that this object was created by Merge. /// [JsonPropertyName("created_at")] - public DateTime? CreatedAt { get; init; } + public DateTime? CreatedAt { get; set; } /// /// The datetime that this object was modified by Merge. /// [JsonPropertyName("modified_at")] - public DateTime? ModifiedAt { get; init; } + public DateTime? ModifiedAt { get; set; } /// /// The income statement's name. /// [JsonPropertyName("name")] - public string? Name { get; init; } + public string? Name { get; set; } /// /// The income statement's currency. @@ -347,66 +346,66 @@ public class IncomeStatement /// - `ZWL` - Zimbabwean Dollar (2009) /// [JsonPropertyName("currency")] - public CurrencyEnum? Currency { get; init; } + public CurrencyEnum? Currency { get; set; } /// /// The company the income statement belongs to. /// [JsonPropertyName("company")] [JsonConverter(typeof(OneOfSerializer>))] - public OneOf? Company { get; init; } + public OneOf? Company { get; set; } /// /// The income statement's start period. /// [JsonPropertyName("start_period")] - public DateTime? StartPeriod { get; init; } + public DateTime? StartPeriod { get; set; } /// /// The income statement's end period. /// [JsonPropertyName("end_period")] - public DateTime? EndPeriod { get; init; } + public DateTime? EndPeriod { get; set; } [JsonPropertyName("income")] - public IEnumerable? Income { get; init; } + public IEnumerable? Income { get; set; } [JsonPropertyName("cost_of_sales")] - public IEnumerable? CostOfSales { get; init; } + public IEnumerable? CostOfSales { get; set; } /// /// The revenue minus the cost of sale. /// [JsonPropertyName("gross_profit")] - public double? GrossProfit { get; init; } + public double? GrossProfit { get; set; } [JsonPropertyName("operating_expenses")] - public IEnumerable? OperatingExpenses { get; init; } + public IEnumerable? OperatingExpenses { get; set; } /// /// The revenue minus the operating expenses. /// [JsonPropertyName("net_operating_income")] - public double? NetOperatingIncome { get; init; } + public double? NetOperatingIncome { get; set; } [JsonPropertyName("non_operating_expenses")] - public IEnumerable? NonOperatingExpenses { get; init; } + public IEnumerable? NonOperatingExpenses { get; set; } /// /// The gross profit minus the total expenses. /// [JsonPropertyName("net_income")] - public double? NetIncome { get; init; } + public double? NetIncome { get; set; } /// /// Indicates whether or not this object has been deleted in the third party platform. /// [JsonPropertyName("remote_was_deleted")] - public bool? RemoteWasDeleted { get; init; } + public bool? RemoteWasDeleted { get; set; } [JsonPropertyName("field_mappings")] - public Dictionary? FieldMappings { get; init; } + public Dictionary? FieldMappings { get; set; } [JsonPropertyName("remote_data")] - public IEnumerable? RemoteData { get; init; } + public IEnumerable? RemoteData { get; set; } } diff --git a/src/Merge.Client/Accounting/Types/IndividualCommonModelScopeDeserializer.cs b/src/Merge.Client/Accounting/Types/IndividualCommonModelScopeDeserializer.cs index 8e0b45b5..9a6d72a6 100644 --- a/src/Merge.Client/Accounting/Types/IndividualCommonModelScopeDeserializer.cs +++ b/src/Merge.Client/Accounting/Types/IndividualCommonModelScopeDeserializer.cs @@ -1,18 +1,17 @@ using System.Text.Json.Serialization; -using Merge.Client.Accounting; #nullable enable namespace Merge.Client.Accounting; -public class IndividualCommonModelScopeDeserializer +public record IndividualCommonModelScopeDeserializer { [JsonPropertyName("model_name")] - public string ModelName { get; init; } + public required string ModelName { get; set; } [JsonPropertyName("model_permissions")] - public Dictionary? ModelPermissions { get; init; } + public Dictionary? ModelPermissions { get; set; } [JsonPropertyName("field_permissions")] - public FieldPermissionDeserializer? FieldPermissions { get; init; } + public FieldPermissionDeserializer? FieldPermissions { get; set; } } diff --git a/src/Merge.Client/Accounting/Types/IndividualCommonModelScopeDeserializerRequest.cs b/src/Merge.Client/Accounting/Types/IndividualCommonModelScopeDeserializerRequest.cs index 0969662c..32f02078 100644 --- a/src/Merge.Client/Accounting/Types/IndividualCommonModelScopeDeserializerRequest.cs +++ b/src/Merge.Client/Accounting/Types/IndividualCommonModelScopeDeserializerRequest.cs @@ -1,18 +1,17 @@ using System.Text.Json.Serialization; -using Merge.Client.Accounting; #nullable enable namespace Merge.Client.Accounting; -public class IndividualCommonModelScopeDeserializerRequest +public record IndividualCommonModelScopeDeserializerRequest { [JsonPropertyName("model_name")] - public string ModelName { get; init; } + public required string ModelName { get; set; } [JsonPropertyName("model_permissions")] - public Dictionary? ModelPermissions { get; init; } + public Dictionary? ModelPermissions { get; set; } [JsonPropertyName("field_permissions")] - public FieldPermissionDeserializerRequest? FieldPermissions { get; init; } + public FieldPermissionDeserializerRequest? FieldPermissions { get; set; } } diff --git a/src/Merge.Client/Accounting/Types/Invoice.cs b/src/Merge.Client/Accounting/Types/Invoice.cs index 32d2fec8..f1d2ba58 100644 --- a/src/Merge.Client/Accounting/Types/Invoice.cs +++ b/src/Merge.Client/Accounting/Types/Invoice.cs @@ -1,5 +1,4 @@ using System.Text.Json.Serialization; -using Merge.Client.Accounting; using Merge.Client.Core; using OneOf; @@ -7,28 +6,28 @@ namespace Merge.Client.Accounting; -public class Invoice +public record Invoice { [JsonPropertyName("id")] - public string? Id { get; init; } + public string? Id { get; set; } /// /// The third-party API ID of the matching object. /// [JsonPropertyName("remote_id")] - public string? RemoteId { get; init; } + public string? RemoteId { get; set; } /// /// The datetime that this object was created by Merge. /// [JsonPropertyName("created_at")] - public DateTime? CreatedAt { get; init; } + public DateTime? CreatedAt { get; set; } /// /// The datetime that this object was modified by Merge. /// [JsonPropertyName("modified_at")] - public DateTime? ModifiedAt { get; init; } + public DateTime? ModifiedAt { get; set; } /// /// Whether the invoice is an accounts receivable or accounts payable. If `type` is `ACCOUNTS_PAYABLE`, the invoice is a bill. If `type` is `ACCOUNTS_RECEIVABLE`, it is an invoice. @@ -37,51 +36,51 @@ public class Invoice /// - `ACCOUNTS_PAYABLE` - ACCOUNTS_PAYABLE /// [JsonPropertyName("type")] - public InvoiceTypeEnum? Type { get; init; } + public InvoiceTypeEnum? Type { get; set; } /// /// The invoice's contact. /// [JsonPropertyName("contact")] [JsonConverter(typeof(OneOfSerializer>))] - public OneOf? Contact { get; init; } + public OneOf? Contact { get; set; } /// /// The invoice's number. /// [JsonPropertyName("number")] - public string? Number { get; init; } + public string? Number { get; set; } /// /// The invoice's issue date. /// [JsonPropertyName("issue_date")] - public DateTime? IssueDate { get; init; } + public DateTime? IssueDate { get; set; } /// /// The invoice's due date. /// [JsonPropertyName("due_date")] - public DateTime? DueDate { get; init; } + public DateTime? DueDate { get; set; } /// /// The invoice's paid date. /// [JsonPropertyName("paid_on_date")] - public DateTime? PaidOnDate { get; init; } + public DateTime? PaidOnDate { get; set; } /// /// The invoice's private note. /// [JsonPropertyName("memo")] - public string? Memo { get; init; } + public string? Memo { get; set; } /// /// The company the invoice belongs to. /// [JsonPropertyName("company")] [JsonConverter(typeof(OneOfSerializer>))] - public OneOf? Company { get; init; } + public OneOf? Company { get; set; } /// /// The invoice's currency. @@ -394,25 +393,25 @@ public class Invoice /// - `ZWL` - Zimbabwean Dollar (2009) /// [JsonPropertyName("currency")] - public CurrencyEnum? Currency { get; init; } + public CurrencyEnum? Currency { get; set; } /// /// The invoice's exchange rate. /// [JsonPropertyName("exchange_rate")] - public string? ExchangeRate { get; init; } + public string? ExchangeRate { get; set; } /// /// The total discounts applied to the total cost. /// [JsonPropertyName("total_discount")] - public double? TotalDiscount { get; init; } + public double? TotalDiscount { get; set; } /// /// The total amount being paid before taxes. /// [JsonPropertyName("sub_total")] - public double? SubTotal { get; init; } + public double? SubTotal { get; set; } /// /// The status of the invoice. @@ -425,31 +424,31 @@ public class Invoice /// - `VOID` - VOID /// [JsonPropertyName("status")] - public InvoiceStatusEnum? Status { get; init; } + public InvoiceStatusEnum? Status { get; set; } /// /// The total amount being paid in taxes. /// [JsonPropertyName("total_tax_amount")] - public double? TotalTaxAmount { get; init; } + public double? TotalTaxAmount { get; set; } /// /// The invoice's total amount. /// [JsonPropertyName("total_amount")] - public double? TotalAmount { get; init; } + public double? TotalAmount { get; set; } /// /// The invoice's remaining balance. /// [JsonPropertyName("balance")] - public double? Balance { get; init; } + public double? Balance { get; set; } /// /// When the third party's invoice entry was updated. /// [JsonPropertyName("remote_updated_at")] - public DateTime? RemoteUpdatedAt { get; init; } + public DateTime? RemoteUpdatedAt { get; set; } [JsonPropertyName("tracking_categories")] [JsonConverter( @@ -458,7 +457,7 @@ public class Invoice OneOfSerializer> >) )] - public IEnumerable>? TrackingCategories { get; init; } + public IEnumerable>? TrackingCategories { get; set; } /// /// Array of `Payment` object IDs. @@ -470,7 +469,7 @@ public class Invoice OneOfSerializer> >) )] - public IEnumerable>? Payments { get; init; } + public IEnumerable>? Payments { get; set; } /// /// A list of the Payment Applied to Lines common models related to a given Invoice, Credit Note, or Journal Entry. @@ -482,20 +481,20 @@ public class Invoice OneOfSerializer> >) )] - public IEnumerable>? AppliedPayments { get; init; } + public IEnumerable>? AppliedPayments { get; set; } [JsonPropertyName("line_items")] - public IEnumerable? LineItems { get; init; } + public IEnumerable? LineItems { get; set; } [JsonPropertyName("remote_was_deleted")] - public bool? RemoteWasDeleted { get; init; } + public bool? RemoteWasDeleted { get; set; } /// /// The accounting period that the Invoice was generated in. /// [JsonPropertyName("accounting_period")] [JsonConverter(typeof(OneOfSerializer>))] - public OneOf? AccountingPeriod { get; init; } + public OneOf? AccountingPeriod { get; set; } [JsonPropertyName("purchase_orders")] [JsonConverter( @@ -504,11 +503,11 @@ public class Invoice OneOfSerializer> >) )] - public IEnumerable>? PurchaseOrders { get; init; } + public IEnumerable>? PurchaseOrders { get; set; } [JsonPropertyName("field_mappings")] - public Dictionary? FieldMappings { get; init; } + public Dictionary? FieldMappings { get; set; } [JsonPropertyName("remote_data")] - public IEnumerable? RemoteData { get; init; } + public IEnumerable? RemoteData { get; set; } } diff --git a/src/Merge.Client/Accounting/Types/InvoiceLineItem.cs b/src/Merge.Client/Accounting/Types/InvoiceLineItem.cs index 48083886..001e45b1 100644 --- a/src/Merge.Client/Accounting/Types/InvoiceLineItem.cs +++ b/src/Merge.Client/Accounting/Types/InvoiceLineItem.cs @@ -1,5 +1,4 @@ using System.Text.Json.Serialization; -using Merge.Client.Accounting; using Merge.Client.Core; using OneOf; @@ -7,52 +6,52 @@ namespace Merge.Client.Accounting; -public class InvoiceLineItem +public record InvoiceLineItem { [JsonPropertyName("id")] - public string? Id { get; init; } + public string? Id { get; set; } /// /// The third-party API ID of the matching object. /// [JsonPropertyName("remote_id")] - public string? RemoteId { get; init; } + public string? RemoteId { get; set; } /// /// The datetime that this object was created by Merge. /// [JsonPropertyName("created_at")] - public DateTime? CreatedAt { get; init; } + public DateTime? CreatedAt { get; set; } /// /// The datetime that this object was modified by Merge. /// [JsonPropertyName("modified_at")] - public DateTime? ModifiedAt { get; init; } + public DateTime? ModifiedAt { get; set; } /// /// The line item's description. /// [JsonPropertyName("description")] - public string? Description { get; init; } + public string? Description { get; set; } /// /// The line item's unit price. /// [JsonPropertyName("unit_price")] - public double? UnitPrice { get; init; } + public double? UnitPrice { get; set; } /// /// The line item's quantity. /// [JsonPropertyName("quantity")] - public double? Quantity { get; init; } + public double? Quantity { get; set; } /// /// The line item's total amount. /// [JsonPropertyName("total_amount")] - public double? TotalAmount { get; init; } + public double? TotalAmount { get; set; } /// /// The line item's currency. @@ -365,25 +364,25 @@ public class InvoiceLineItem /// - `ZWL` - Zimbabwean Dollar (2009) /// [JsonPropertyName("currency")] - public CurrencyEnum? Currency { get; init; } + public CurrencyEnum? Currency { get; set; } /// /// The line item's exchange rate. /// [JsonPropertyName("exchange_rate")] - public string? ExchangeRate { get; init; } + public string? ExchangeRate { get; set; } [JsonPropertyName("item")] [JsonConverter(typeof(OneOfSerializer>))] - public OneOf? Item { get; init; } + public OneOf? Item { get; set; } [JsonPropertyName("account")] [JsonConverter(typeof(OneOfSerializer>))] - public OneOf? Account { get; init; } + public OneOf? Account { get; set; } [JsonPropertyName("tracking_category")] [JsonConverter(typeof(OneOfSerializer>))] - public OneOf? TrackingCategory { get; init; } + public OneOf? TrackingCategory { get; set; } [JsonPropertyName("tracking_categories")] [JsonConverter( @@ -392,20 +391,20 @@ public class InvoiceLineItem OneOfSerializer> >) )] - public IEnumerable>? TrackingCategories { get; init; } + public IEnumerable>? TrackingCategories { get; set; } /// /// The company the line item belongs to. /// [JsonPropertyName("company")] - public string? Company { get; init; } + public string? Company { get; set; } /// /// Indicates whether or not this object has been deleted in the third party platform. /// [JsonPropertyName("remote_was_deleted")] - public bool? RemoteWasDeleted { get; init; } + public bool? RemoteWasDeleted { get; set; } [JsonPropertyName("field_mappings")] - public Dictionary? FieldMappings { get; init; } + public Dictionary? FieldMappings { get; set; } } diff --git a/src/Merge.Client/Accounting/Types/InvoiceLineItemRequest.cs b/src/Merge.Client/Accounting/Types/InvoiceLineItemRequest.cs index ff907549..82aa7a8f 100644 --- a/src/Merge.Client/Accounting/Types/InvoiceLineItemRequest.cs +++ b/src/Merge.Client/Accounting/Types/InvoiceLineItemRequest.cs @@ -1,5 +1,4 @@ using System.Text.Json.Serialization; -using Merge.Client.Accounting; using Merge.Client.Core; using OneOf; @@ -7,37 +6,37 @@ namespace Merge.Client.Accounting; -public class InvoiceLineItemRequest +public record InvoiceLineItemRequest { /// /// The third-party API ID of the matching object. /// [JsonPropertyName("remote_id")] - public string? RemoteId { get; init; } + public string? RemoteId { get; set; } /// /// The line item's description. /// [JsonPropertyName("description")] - public string? Description { get; init; } + public string? Description { get; set; } /// /// The line item's unit price. /// [JsonPropertyName("unit_price")] - public double? UnitPrice { get; init; } + public double? UnitPrice { get; set; } /// /// The line item's quantity. /// [JsonPropertyName("quantity")] - public double? Quantity { get; init; } + public double? Quantity { get; set; } /// /// The line item's total amount. /// [JsonPropertyName("total_amount")] - public double? TotalAmount { get; init; } + public double? TotalAmount { get; set; } /// /// The line item's currency. @@ -350,25 +349,25 @@ public class InvoiceLineItemRequest /// - `ZWL` - Zimbabwean Dollar (2009) /// [JsonPropertyName("currency")] - public CurrencyEnum? Currency { get; init; } + public CurrencyEnum? Currency { get; set; } /// /// The line item's exchange rate. /// [JsonPropertyName("exchange_rate")] - public string? ExchangeRate { get; init; } + public string? ExchangeRate { get; set; } [JsonPropertyName("item")] [JsonConverter(typeof(OneOfSerializer>))] - public OneOf? Item { get; init; } + public OneOf? Item { get; set; } [JsonPropertyName("account")] [JsonConverter(typeof(OneOfSerializer>))] - public OneOf? Account { get; init; } + public OneOf? Account { get; set; } [JsonPropertyName("tracking_category")] [JsonConverter(typeof(OneOfSerializer>))] - public OneOf? TrackingCategory { get; init; } + public OneOf? TrackingCategory { get; set; } [JsonPropertyName("tracking_categories")] [JsonConverter( @@ -377,17 +376,17 @@ public class InvoiceLineItemRequest OneOfSerializer> >) )] - public IEnumerable>? TrackingCategories { get; init; } + public IEnumerable>? TrackingCategories { get; set; } /// /// The company the line item belongs to. /// [JsonPropertyName("company")] - public string? Company { get; init; } + public string? Company { get; set; } [JsonPropertyName("integration_params")] - public Dictionary? IntegrationParams { get; init; } + public Dictionary? IntegrationParams { get; set; } [JsonPropertyName("linked_account_params")] - public Dictionary? LinkedAccountParams { get; init; } + public Dictionary? LinkedAccountParams { get; set; } } diff --git a/src/Merge.Client/Accounting/Types/InvoiceRequest.cs b/src/Merge.Client/Accounting/Types/InvoiceRequest.cs index e5b4c9bf..69694ae0 100644 --- a/src/Merge.Client/Accounting/Types/InvoiceRequest.cs +++ b/src/Merge.Client/Accounting/Types/InvoiceRequest.cs @@ -1,5 +1,4 @@ using System.Text.Json.Serialization; -using Merge.Client.Accounting; using Merge.Client.Core; using OneOf; @@ -7,7 +6,7 @@ namespace Merge.Client.Accounting; -public class InvoiceRequest +public record InvoiceRequest { /// /// Whether the invoice is an accounts receivable or accounts payable. If `type` is `ACCOUNTS_PAYABLE`, the invoice is a bill. If `type` is `ACCOUNTS_RECEIVABLE`, it is an invoice. @@ -16,44 +15,44 @@ public class InvoiceRequest /// - `ACCOUNTS_PAYABLE` - ACCOUNTS_PAYABLE /// [JsonPropertyName("type")] - public InvoiceTypeEnum? Type { get; init; } + public InvoiceTypeEnum? Type { get; set; } /// /// The invoice's contact. /// [JsonPropertyName("contact")] [JsonConverter(typeof(OneOfSerializer>))] - public OneOf? Contact { get; init; } + public OneOf? Contact { get; set; } /// /// The invoice's number. /// [JsonPropertyName("number")] - public string? Number { get; init; } + public string? Number { get; set; } /// /// The invoice's issue date. /// [JsonPropertyName("issue_date")] - public DateTime? IssueDate { get; init; } + public DateTime? IssueDate { get; set; } /// /// The invoice's due date. /// [JsonPropertyName("due_date")] - public DateTime? DueDate { get; init; } + public DateTime? DueDate { get; set; } /// /// The invoice's paid date. /// [JsonPropertyName("paid_on_date")] - public DateTime? PaidOnDate { get; init; } + public DateTime? PaidOnDate { get; set; } /// /// The invoice's private note. /// [JsonPropertyName("memo")] - public string? Memo { get; init; } + public string? Memo { get; set; } /// /// The status of the invoice. @@ -66,14 +65,14 @@ public class InvoiceRequest /// - `VOID` - VOID /// [JsonPropertyName("status")] - public InvoiceStatusEnum? Status { get; init; } + public InvoiceStatusEnum? Status { get; set; } /// /// The company the invoice belongs to. /// [JsonPropertyName("company")] [JsonConverter(typeof(OneOfSerializer>))] - public OneOf? Company { get; init; } + public OneOf? Company { get; set; } /// /// The invoice's currency. @@ -386,43 +385,43 @@ public class InvoiceRequest /// - `ZWL` - Zimbabwean Dollar (2009) /// [JsonPropertyName("currency")] - public CurrencyEnum? Currency { get; init; } + public CurrencyEnum? Currency { get; set; } /// /// The invoice's exchange rate. /// [JsonPropertyName("exchange_rate")] - public string? ExchangeRate { get; init; } + public string? ExchangeRate { get; set; } /// /// The total discounts applied to the total cost. /// [JsonPropertyName("total_discount")] - public double? TotalDiscount { get; init; } + public double? TotalDiscount { get; set; } /// /// The total amount being paid before taxes. /// [JsonPropertyName("sub_total")] - public double? SubTotal { get; init; } + public double? SubTotal { get; set; } /// /// The total amount being paid in taxes. /// [JsonPropertyName("total_tax_amount")] - public double? TotalTaxAmount { get; init; } + public double? TotalTaxAmount { get; set; } /// /// The invoice's total amount. /// [JsonPropertyName("total_amount")] - public double? TotalAmount { get; init; } + public double? TotalAmount { get; set; } /// /// The invoice's remaining balance. /// [JsonPropertyName("balance")] - public double? Balance { get; init; } + public double? Balance { get; set; } /// /// Array of `Payment` object IDs. @@ -434,7 +433,7 @@ public class InvoiceRequest OneOfSerializer> >) )] - public IEnumerable>? Payments { get; init; } + public IEnumerable>? Payments { get; set; } [JsonPropertyName("tracking_categories")] [JsonConverter( @@ -443,10 +442,10 @@ public class InvoiceRequest OneOfSerializer> >) )] - public IEnumerable>? TrackingCategories { get; init; } + public IEnumerable>? TrackingCategories { get; set; } [JsonPropertyName("line_items")] - public IEnumerable? LineItems { get; init; } + public IEnumerable? LineItems { get; set; } [JsonPropertyName("purchase_orders")] [JsonConverter( @@ -455,11 +454,11 @@ public class InvoiceRequest OneOfSerializer> >) )] - public IEnumerable>? PurchaseOrders { get; init; } + public IEnumerable>? PurchaseOrders { get; set; } [JsonPropertyName("integration_params")] - public Dictionary? IntegrationParams { get; init; } + public Dictionary? IntegrationParams { get; set; } [JsonPropertyName("linked_account_params")] - public Dictionary? LinkedAccountParams { get; init; } + public Dictionary? LinkedAccountParams { get; set; } } diff --git a/src/Merge.Client/Accounting/Types/InvoiceResponse.cs b/src/Merge.Client/Accounting/Types/InvoiceResponse.cs index d8cd4758..9b7dd6ad 100644 --- a/src/Merge.Client/Accounting/Types/InvoiceResponse.cs +++ b/src/Merge.Client/Accounting/Types/InvoiceResponse.cs @@ -1,21 +1,22 @@ using System.Text.Json.Serialization; -using Merge.Client.Accounting; #nullable enable namespace Merge.Client.Accounting; -public class InvoiceResponse +public record InvoiceResponse { [JsonPropertyName("model")] - public Invoice Model { get; init; } + public required Invoice Model { get; set; } [JsonPropertyName("warnings")] - public IEnumerable Warnings { get; init; } + public IEnumerable Warnings { get; set; } = + new List(); [JsonPropertyName("errors")] - public IEnumerable Errors { get; init; } + public IEnumerable Errors { get; set; } = + new List(); [JsonPropertyName("logs")] - public IEnumerable? Logs { get; init; } + public IEnumerable? Logs { get; set; } } diff --git a/src/Merge.Client/Accounting/Types/InvoiceStatusEnum.cs b/src/Merge.Client/Accounting/Types/InvoiceStatusEnum.cs index 3342d80f..b5779971 100644 --- a/src/Merge.Client/Accounting/Types/InvoiceStatusEnum.cs +++ b/src/Merge.Client/Accounting/Types/InvoiceStatusEnum.cs @@ -1,6 +1,5 @@ using System.Runtime.Serialization; using System.Text.Json.Serialization; -using Merge.Client.Accounting; using Merge.Client.Core; #nullable enable diff --git a/src/Merge.Client/Accounting/Types/InvoiceTypeEnum.cs b/src/Merge.Client/Accounting/Types/InvoiceTypeEnum.cs index f7054c70..2a8e23d4 100644 --- a/src/Merge.Client/Accounting/Types/InvoiceTypeEnum.cs +++ b/src/Merge.Client/Accounting/Types/InvoiceTypeEnum.cs @@ -1,6 +1,5 @@ using System.Runtime.Serialization; using System.Text.Json.Serialization; -using Merge.Client.Accounting; using Merge.Client.Core; #nullable enable diff --git a/src/Merge.Client/Accounting/Types/Issue.cs b/src/Merge.Client/Accounting/Types/Issue.cs index 6125fa3a..02c30fc5 100644 --- a/src/Merge.Client/Accounting/Types/Issue.cs +++ b/src/Merge.Client/Accounting/Types/Issue.cs @@ -1,14 +1,13 @@ using System.Text.Json.Serialization; -using Merge.Client.Accounting; #nullable enable namespace Merge.Client.Accounting; -public class Issue +public record Issue { [JsonPropertyName("id")] - public string? Id { get; init; } + public string? Id { get; set; } /// /// Status of the issue. Options: ('ONGOING', 'RESOLVED') @@ -17,23 +16,23 @@ public class Issue /// - `RESOLVED` - RESOLVED /// [JsonPropertyName("status")] - public IssueStatusEnum? Status { get; init; } + public IssueStatusEnum? Status { get; set; } [JsonPropertyName("error_description")] - public string ErrorDescription { get; init; } + public required string ErrorDescription { get; set; } [JsonPropertyName("end_user")] - public Dictionary? EndUser { get; init; } + public Dictionary? EndUser { get; set; } [JsonPropertyName("first_incident_time")] - public DateTime? FirstIncidentTime { get; init; } + public DateTime? FirstIncidentTime { get; set; } [JsonPropertyName("last_incident_time")] - public DateTime? LastIncidentTime { get; init; } + public DateTime? LastIncidentTime { get; set; } [JsonPropertyName("is_muted")] - public bool? IsMuted { get; init; } + public bool? IsMuted { get; set; } [JsonPropertyName("error_details")] - public IEnumerable? ErrorDetails { get; init; } + public IEnumerable? ErrorDetails { get; set; } } diff --git a/src/Merge.Client/Accounting/Types/IssueStatusEnum.cs b/src/Merge.Client/Accounting/Types/IssueStatusEnum.cs index 84987212..6a67e83f 100644 --- a/src/Merge.Client/Accounting/Types/IssueStatusEnum.cs +++ b/src/Merge.Client/Accounting/Types/IssueStatusEnum.cs @@ -1,6 +1,5 @@ using System.Runtime.Serialization; using System.Text.Json.Serialization; -using Merge.Client.Accounting; using Merge.Client.Core; #nullable enable diff --git a/src/Merge.Client/Accounting/Types/Item.cs b/src/Merge.Client/Accounting/Types/Item.cs index cf68abbe..fcf8ac66 100644 --- a/src/Merge.Client/Accounting/Types/Item.cs +++ b/src/Merge.Client/Accounting/Types/Item.cs @@ -1,5 +1,4 @@ using System.Text.Json.Serialization; -using Merge.Client.Accounting; using Merge.Client.Core; using OneOf; @@ -7,34 +6,34 @@ namespace Merge.Client.Accounting; -public class Item +public record Item { [JsonPropertyName("id")] - public string? Id { get; init; } + public string? Id { get; set; } /// /// The third-party API ID of the matching object. /// [JsonPropertyName("remote_id")] - public string? RemoteId { get; init; } + public string? RemoteId { get; set; } /// /// The datetime that this object was created by Merge. /// [JsonPropertyName("created_at")] - public DateTime? CreatedAt { get; init; } + public DateTime? CreatedAt { get; set; } /// /// The datetime that this object was modified by Merge. /// [JsonPropertyName("modified_at")] - public DateTime? ModifiedAt { get; init; } + public DateTime? ModifiedAt { get; set; } /// /// The item's name. /// [JsonPropertyName("name")] - public string? Name { get; init; } + public string? Name { get; set; } /// /// The item's status. @@ -43,56 +42,56 @@ public class Item /// - `ARCHIVED` - ARCHIVED /// [JsonPropertyName("status")] - public Status7D1Enum? Status { get; init; } + public Status7D1Enum? Status { get; set; } /// /// The item's unit price. /// [JsonPropertyName("unit_price")] - public double? UnitPrice { get; init; } + public double? UnitPrice { get; set; } /// /// The price at which the item is purchased from a vendor. /// [JsonPropertyName("purchase_price")] - public double? PurchasePrice { get; init; } + public double? PurchasePrice { get; set; } /// /// References the default account used to record a purchase of the item. /// [JsonPropertyName("purchase_account")] [JsonConverter(typeof(OneOfSerializer>))] - public OneOf? PurchaseAccount { get; init; } + public OneOf? PurchaseAccount { get; set; } /// /// References the default account used to record a sale. /// [JsonPropertyName("sales_account")] [JsonConverter(typeof(OneOfSerializer>))] - public OneOf? SalesAccount { get; init; } + public OneOf? SalesAccount { get; set; } /// /// The company the item belongs to. /// [JsonPropertyName("company")] [JsonConverter(typeof(OneOfSerializer>))] - public OneOf? Company { get; init; } + public OneOf? Company { get; set; } /// /// When the third party's item note was updated. /// [JsonPropertyName("remote_updated_at")] - public DateTime? RemoteUpdatedAt { get; init; } + public DateTime? RemoteUpdatedAt { get; set; } /// /// Indicates whether or not this object has been deleted in the third party platform. /// [JsonPropertyName("remote_was_deleted")] - public bool? RemoteWasDeleted { get; init; } + public bool? RemoteWasDeleted { get; set; } [JsonPropertyName("field_mappings")] - public Dictionary? FieldMappings { get; init; } + public Dictionary? FieldMappings { get; set; } [JsonPropertyName("remote_data")] - public IEnumerable? RemoteData { get; init; } + public IEnumerable? RemoteData { get; set; } } diff --git a/src/Merge.Client/Accounting/Types/JournalEntry.cs b/src/Merge.Client/Accounting/Types/JournalEntry.cs index 22528407..fd3e2f31 100644 --- a/src/Merge.Client/Accounting/Types/JournalEntry.cs +++ b/src/Merge.Client/Accounting/Types/JournalEntry.cs @@ -1,5 +1,4 @@ using System.Text.Json.Serialization; -using Merge.Client.Accounting; using Merge.Client.Core; using OneOf; @@ -7,46 +6,46 @@ namespace Merge.Client.Accounting; -public class JournalEntry +public record JournalEntry { [JsonPropertyName("id")] - public string? Id { get; init; } + public string? Id { get; set; } /// /// The third-party API ID of the matching object. /// [JsonPropertyName("remote_id")] - public string? RemoteId { get; init; } + public string? RemoteId { get; set; } /// /// The datetime that this object was created by Merge. /// [JsonPropertyName("created_at")] - public DateTime? CreatedAt { get; init; } + public DateTime? CreatedAt { get; set; } /// /// The datetime that this object was modified by Merge. /// [JsonPropertyName("modified_at")] - public DateTime? ModifiedAt { get; init; } + public DateTime? ModifiedAt { get; set; } /// /// The journal entry's transaction date. /// [JsonPropertyName("transaction_date")] - public DateTime? TransactionDate { get; init; } + public DateTime? TransactionDate { get; set; } /// /// When the third party's journal entry was created. /// [JsonPropertyName("remote_created_at")] - public DateTime? RemoteCreatedAt { get; init; } + public DateTime? RemoteCreatedAt { get; set; } /// /// When the third party's journal entry was updated. /// [JsonPropertyName("remote_updated_at")] - public DateTime? RemoteUpdatedAt { get; init; } + public DateTime? RemoteUpdatedAt { get; set; } /// /// Array of `Payment` object IDs. @@ -58,7 +57,7 @@ public class JournalEntry OneOfSerializer> >) )] - public IEnumerable>? Payments { get; init; } + public IEnumerable>? Payments { get; set; } /// /// A list of the Payment Applied to Lines common models related to a given Invoice, Credit Note, or Journal Entry. @@ -70,13 +69,13 @@ public class JournalEntry OneOfSerializer> >) )] - public IEnumerable>? AppliedPayments { get; init; } + public IEnumerable>? AppliedPayments { get; set; } /// /// The journal entry's private note. /// [JsonPropertyName("memo")] - public string? Memo { get; init; } + public string? Memo { get; set; } /// /// The journal's currency. @@ -389,29 +388,29 @@ public class JournalEntry /// - `ZWL` - Zimbabwean Dollar (2009) /// [JsonPropertyName("currency")] - public CurrencyEnum? Currency { get; init; } + public CurrencyEnum? Currency { get; set; } /// /// The journal entry's exchange rate. /// [JsonPropertyName("exchange_rate")] - public string? ExchangeRate { get; init; } + public string? ExchangeRate { get; set; } /// /// The company the journal entry belongs to. /// [JsonPropertyName("company")] [JsonConverter(typeof(OneOfSerializer>))] - public OneOf? Company { get; init; } + public OneOf? Company { get; set; } [JsonPropertyName("lines")] - public IEnumerable? Lines { get; init; } + public IEnumerable? Lines { get; set; } /// /// Reference number for identifying journal entries. /// [JsonPropertyName("journal_number")] - public string? JournalNumber { get; init; } + public string? JournalNumber { get; set; } [JsonPropertyName("tracking_categories")] [JsonConverter( @@ -420,10 +419,10 @@ public class JournalEntry OneOfSerializer> >) )] - public IEnumerable>? TrackingCategories { get; init; } + public IEnumerable>? TrackingCategories { get; set; } [JsonPropertyName("remote_was_deleted")] - public bool? RemoteWasDeleted { get; init; } + public bool? RemoteWasDeleted { get; set; } /// /// The journal's posting status. @@ -432,18 +431,18 @@ public class JournalEntry /// - `POSTED` - POSTED /// [JsonPropertyName("posting_status")] - public PostingStatusEnum? PostingStatus { get; init; } + public PostingStatusEnum? PostingStatus { get; set; } /// /// The accounting period that the JournalEntry was generated in. /// [JsonPropertyName("accounting_period")] [JsonConverter(typeof(OneOfSerializer>))] - public OneOf? AccountingPeriod { get; init; } + public OneOf? AccountingPeriod { get; set; } [JsonPropertyName("field_mappings")] - public Dictionary? FieldMappings { get; init; } + public Dictionary? FieldMappings { get; set; } [JsonPropertyName("remote_data")] - public IEnumerable? RemoteData { get; init; } + public IEnumerable? RemoteData { get; set; } } diff --git a/src/Merge.Client/Accounting/Types/JournalEntryRequest.cs b/src/Merge.Client/Accounting/Types/JournalEntryRequest.cs index 64987beb..4a79e3ed 100644 --- a/src/Merge.Client/Accounting/Types/JournalEntryRequest.cs +++ b/src/Merge.Client/Accounting/Types/JournalEntryRequest.cs @@ -1,5 +1,4 @@ using System.Text.Json.Serialization; -using Merge.Client.Accounting; using Merge.Client.Core; using OneOf; @@ -7,13 +6,13 @@ namespace Merge.Client.Accounting; -public class JournalEntryRequest +public record JournalEntryRequest { /// /// The journal entry's transaction date. /// [JsonPropertyName("transaction_date")] - public DateTime? TransactionDate { get; init; } + public DateTime? TransactionDate { get; set; } /// /// Array of `Payment` object IDs. @@ -25,13 +24,13 @@ public class JournalEntryRequest OneOfSerializer> >) )] - public IEnumerable>? Payments { get; init; } + public IEnumerable>? Payments { get; set; } /// /// The journal entry's private note. /// [JsonPropertyName("memo")] - public string? Memo { get; init; } + public string? Memo { get; set; } /// /// The journal's currency. @@ -344,20 +343,20 @@ public class JournalEntryRequest /// - `ZWL` - Zimbabwean Dollar (2009) /// [JsonPropertyName("currency")] - public CurrencyEnum? Currency { get; init; } + public CurrencyEnum? Currency { get; set; } /// /// The journal entry's exchange rate. /// [JsonPropertyName("exchange_rate")] - public string? ExchangeRate { get; init; } + public string? ExchangeRate { get; set; } /// /// The company the journal entry belongs to. /// [JsonPropertyName("company")] [JsonConverter(typeof(OneOfSerializer>))] - public OneOf? Company { get; init; } + public OneOf? Company { get; set; } [JsonPropertyName("tracking_categories")] [JsonConverter( @@ -366,16 +365,16 @@ public class JournalEntryRequest OneOfSerializer> >) )] - public IEnumerable>? TrackingCategories { get; init; } + public IEnumerable>? TrackingCategories { get; set; } [JsonPropertyName("lines")] - public IEnumerable? Lines { get; init; } + public IEnumerable? Lines { get; set; } /// /// Reference number for identifying journal entries. /// [JsonPropertyName("journal_number")] - public string? JournalNumber { get; init; } + public string? JournalNumber { get; set; } /// /// The journal's posting status. @@ -384,11 +383,11 @@ public class JournalEntryRequest /// - `POSTED` - POSTED /// [JsonPropertyName("posting_status")] - public PostingStatusEnum? PostingStatus { get; init; } + public PostingStatusEnum? PostingStatus { get; set; } [JsonPropertyName("integration_params")] - public Dictionary? IntegrationParams { get; init; } + public Dictionary? IntegrationParams { get; set; } [JsonPropertyName("linked_account_params")] - public Dictionary? LinkedAccountParams { get; init; } + public Dictionary? LinkedAccountParams { get; set; } } diff --git a/src/Merge.Client/Accounting/Types/JournalEntryResponse.cs b/src/Merge.Client/Accounting/Types/JournalEntryResponse.cs index 89065362..7b189c2c 100644 --- a/src/Merge.Client/Accounting/Types/JournalEntryResponse.cs +++ b/src/Merge.Client/Accounting/Types/JournalEntryResponse.cs @@ -1,21 +1,22 @@ using System.Text.Json.Serialization; -using Merge.Client.Accounting; #nullable enable namespace Merge.Client.Accounting; -public class JournalEntryResponse +public record JournalEntryResponse { [JsonPropertyName("model")] - public JournalEntry Model { get; init; } + public required JournalEntry Model { get; set; } [JsonPropertyName("warnings")] - public IEnumerable Warnings { get; init; } + public IEnumerable Warnings { get; set; } = + new List(); [JsonPropertyName("errors")] - public IEnumerable Errors { get; init; } + public IEnumerable Errors { get; set; } = + new List(); [JsonPropertyName("logs")] - public IEnumerable? Logs { get; init; } + public IEnumerable? Logs { get; set; } } diff --git a/src/Merge.Client/Accounting/Types/JournalLine.cs b/src/Merge.Client/Accounting/Types/JournalLine.cs index 5b1a00f7..782d8f01 100644 --- a/src/Merge.Client/Accounting/Types/JournalLine.cs +++ b/src/Merge.Client/Accounting/Types/JournalLine.cs @@ -1,5 +1,4 @@ using System.Text.Json.Serialization; -using Merge.Client.Accounting; using Merge.Client.Core; using OneOf; @@ -7,42 +6,42 @@ namespace Merge.Client.Accounting; -public class JournalLine +public record JournalLine { [JsonPropertyName("id")] - public string? Id { get; init; } + public string? Id { get; set; } /// /// The third-party API ID of the matching object. /// [JsonPropertyName("remote_id")] - public string? RemoteId { get; init; } + public string? RemoteId { get; set; } /// /// The datetime that this object was created by Merge. /// [JsonPropertyName("created_at")] - public DateTime? CreatedAt { get; init; } + public DateTime? CreatedAt { get; set; } /// /// The datetime that this object was modified by Merge. /// [JsonPropertyName("modified_at")] - public DateTime? ModifiedAt { get; init; } + public DateTime? ModifiedAt { get; set; } [JsonPropertyName("account")] [JsonConverter(typeof(OneOfSerializer>))] - public OneOf? Account { get; init; } + public OneOf? Account { get; set; } /// /// The value of the line item including taxes and other fees. /// [JsonPropertyName("net_amount")] - public double? NetAmount { get; init; } + public double? NetAmount { get; set; } [JsonPropertyName("tracking_category")] [JsonConverter(typeof(OneOfSerializer>))] - public OneOf? TrackingCategory { get; init; } + public OneOf? TrackingCategory { get; set; } [JsonPropertyName("tracking_categories")] [JsonConverter( @@ -51,7 +50,7 @@ public class JournalLine OneOfSerializer> >) )] - public IEnumerable>? TrackingCategories { get; init; } + public IEnumerable>? TrackingCategories { get; set; } /// /// The journal line item's currency. @@ -364,32 +363,32 @@ public class JournalLine /// - `ZWL` - Zimbabwean Dollar (2009) /// [JsonPropertyName("currency")] - public CurrencyEnum? Currency { get; init; } + public CurrencyEnum? Currency { get; set; } /// /// The company the journal entry belongs to. /// [JsonPropertyName("company")] - public string? Company { get; init; } + public string? Company { get; set; } [JsonPropertyName("contact")] - public string? Contact { get; init; } + public string? Contact { get; set; } /// /// The line's description. /// [JsonPropertyName("description")] - public string? Description { get; init; } + public string? Description { get; set; } /// /// The journal line item's exchange rate. /// [JsonPropertyName("exchange_rate")] - public string? ExchangeRate { get; init; } + public string? ExchangeRate { get; set; } /// /// Indicates whether or not this object has been deleted in the third party platform. /// [JsonPropertyName("remote_was_deleted")] - public bool? RemoteWasDeleted { get; init; } + public bool? RemoteWasDeleted { get; set; } } diff --git a/src/Merge.Client/Accounting/Types/JournalLineRequest.cs b/src/Merge.Client/Accounting/Types/JournalLineRequest.cs index b7cd6cc7..f836fb6b 100644 --- a/src/Merge.Client/Accounting/Types/JournalLineRequest.cs +++ b/src/Merge.Client/Accounting/Types/JournalLineRequest.cs @@ -1,5 +1,4 @@ using System.Text.Json.Serialization; -using Merge.Client.Accounting; using Merge.Client.Core; using OneOf; @@ -7,27 +6,27 @@ namespace Merge.Client.Accounting; -public class JournalLineRequest +public record JournalLineRequest { /// /// The third-party API ID of the matching object. /// [JsonPropertyName("remote_id")] - public string? RemoteId { get; init; } + public string? RemoteId { get; set; } [JsonPropertyName("account")] [JsonConverter(typeof(OneOfSerializer>))] - public OneOf? Account { get; init; } + public OneOf? Account { get; set; } /// /// The value of the line item including taxes and other fees. /// [JsonPropertyName("net_amount")] - public double? NetAmount { get; init; } + public double? NetAmount { get; set; } [JsonPropertyName("tracking_category")] [JsonConverter(typeof(OneOfSerializer>))] - public OneOf? TrackingCategory { get; init; } + public OneOf? TrackingCategory { get; set; } [JsonPropertyName("tracking_categories")] [JsonConverter( @@ -36,7 +35,7 @@ public class JournalLineRequest OneOfSerializer> >) )] - public IEnumerable>? TrackingCategories { get; init; } + public IEnumerable>? TrackingCategories { get; set; } /// /// The journal line item's currency. @@ -349,32 +348,32 @@ public class JournalLineRequest /// - `ZWL` - Zimbabwean Dollar (2009) /// [JsonPropertyName("currency")] - public CurrencyEnum? Currency { get; init; } + public CurrencyEnum? Currency { get; set; } /// /// The company the journal entry belongs to. /// [JsonPropertyName("company")] - public string? Company { get; init; } + public string? Company { get; set; } [JsonPropertyName("contact")] - public string? Contact { get; init; } + public string? Contact { get; set; } /// /// The line's description. /// [JsonPropertyName("description")] - public string? Description { get; init; } + public string? Description { get; set; } /// /// The journal line item's exchange rate. /// [JsonPropertyName("exchange_rate")] - public string? ExchangeRate { get; init; } + public string? ExchangeRate { get; set; } [JsonPropertyName("integration_params")] - public Dictionary? IntegrationParams { get; init; } + public Dictionary? IntegrationParams { get; set; } [JsonPropertyName("linked_account_params")] - public Dictionary? LinkedAccountParams { get; init; } + public Dictionary? LinkedAccountParams { get; set; } } diff --git a/src/Merge.Client/Accounting/Types/LinkToken.cs b/src/Merge.Client/Accounting/Types/LinkToken.cs index 5824094e..ba0a764f 100644 --- a/src/Merge.Client/Accounting/Types/LinkToken.cs +++ b/src/Merge.Client/Accounting/Types/LinkToken.cs @@ -4,14 +4,14 @@ namespace Merge.Client.Accounting; -public class LinkToken +public record LinkToken { [JsonPropertyName("link_token")] - public string LinkToken_ { get; init; } + public required string LinkToken_ { get; set; } [JsonPropertyName("integration_name")] - public string? IntegrationName { get; init; } + public string? IntegrationName { get; set; } [JsonPropertyName("magic_link_url")] - public string? MagicLinkUrl { get; init; } + public string? MagicLinkUrl { get; set; } } diff --git a/src/Merge.Client/Accounting/Types/LinkedAccountStatus.cs b/src/Merge.Client/Accounting/Types/LinkedAccountStatus.cs index 26dd96c5..7ee868f9 100644 --- a/src/Merge.Client/Accounting/Types/LinkedAccountStatus.cs +++ b/src/Merge.Client/Accounting/Types/LinkedAccountStatus.cs @@ -4,11 +4,11 @@ namespace Merge.Client.Accounting; -public class LinkedAccountStatus +public record LinkedAccountStatus { [JsonPropertyName("linked_account_status")] - public string LinkedAccountStatus_ { get; init; } + public required string LinkedAccountStatus_ { get; set; } [JsonPropertyName("can_make_request")] - public bool CanMakeRequest { get; init; } + public required bool CanMakeRequest { get; set; } } diff --git a/src/Merge.Client/Accounting/Types/MetaResponse.cs b/src/Merge.Client/Accounting/Types/MetaResponse.cs index 72ecb0a3..1b69c3ef 100644 --- a/src/Merge.Client/Accounting/Types/MetaResponse.cs +++ b/src/Merge.Client/Accounting/Types/MetaResponse.cs @@ -1,24 +1,24 @@ using System.Text.Json.Serialization; -using Merge.Client.Accounting; #nullable enable namespace Merge.Client.Accounting; -public class MetaResponse +public record MetaResponse { [JsonPropertyName("request_schema")] - public Dictionary RequestSchema { get; init; } + public Dictionary RequestSchema { get; set; } = + new Dictionary(); [JsonPropertyName("remote_field_classes")] - public Dictionary? RemoteFieldClasses { get; init; } + public Dictionary? RemoteFieldClasses { get; set; } [JsonPropertyName("status")] - public LinkedAccountStatus? Status { get; init; } + public LinkedAccountStatus? Status { get; set; } [JsonPropertyName("has_conditional_params")] - public bool HasConditionalParams { get; init; } + public required bool HasConditionalParams { get; set; } [JsonPropertyName("has_required_linked_account_params")] - public bool HasRequiredLinkedAccountParams { get; init; } + public required bool HasRequiredLinkedAccountParams { get; set; } } diff --git a/src/Merge.Client/Accounting/Types/MethodEnum.cs b/src/Merge.Client/Accounting/Types/MethodEnum.cs index 39d2aa49..f00205a7 100644 --- a/src/Merge.Client/Accounting/Types/MethodEnum.cs +++ b/src/Merge.Client/Accounting/Types/MethodEnum.cs @@ -1,6 +1,5 @@ using System.Runtime.Serialization; using System.Text.Json.Serialization; -using Merge.Client.Accounting; using Merge.Client.Core; #nullable enable diff --git a/src/Merge.Client/Accounting/Types/ModelOperation.cs b/src/Merge.Client/Accounting/Types/ModelOperation.cs index 4e329411..585d6727 100644 --- a/src/Merge.Client/Accounting/Types/ModelOperation.cs +++ b/src/Merge.Client/Accounting/Types/ModelOperation.cs @@ -4,17 +4,17 @@ namespace Merge.Client.Accounting; -public class ModelOperation +public record ModelOperation { [JsonPropertyName("model_name")] - public string ModelName { get; init; } + public required string ModelName { get; set; } [JsonPropertyName("available_operations")] - public IEnumerable AvailableOperations { get; init; } + public IEnumerable AvailableOperations { get; set; } = new List(); [JsonPropertyName("required_post_parameters")] - public IEnumerable RequiredPostParameters { get; init; } + public IEnumerable RequiredPostParameters { get; set; } = new List(); [JsonPropertyName("supported_fields")] - public IEnumerable SupportedFields { get; init; } + public IEnumerable SupportedFields { get; set; } = new List(); } diff --git a/src/Merge.Client/Accounting/Types/ModelPermissionDeserializer.cs b/src/Merge.Client/Accounting/Types/ModelPermissionDeserializer.cs index b8dcc5a6..dbdb3fae 100644 --- a/src/Merge.Client/Accounting/Types/ModelPermissionDeserializer.cs +++ b/src/Merge.Client/Accounting/Types/ModelPermissionDeserializer.cs @@ -4,8 +4,8 @@ namespace Merge.Client.Accounting; -public class ModelPermissionDeserializer +public record ModelPermissionDeserializer { [JsonPropertyName("is_enabled")] - public bool? IsEnabled { get; init; } + public bool? IsEnabled { get; set; } } diff --git a/src/Merge.Client/Accounting/Types/ModelPermissionDeserializerRequest.cs b/src/Merge.Client/Accounting/Types/ModelPermissionDeserializerRequest.cs index aa6d1abe..4807a9b5 100644 --- a/src/Merge.Client/Accounting/Types/ModelPermissionDeserializerRequest.cs +++ b/src/Merge.Client/Accounting/Types/ModelPermissionDeserializerRequest.cs @@ -4,8 +4,8 @@ namespace Merge.Client.Accounting; -public class ModelPermissionDeserializerRequest +public record ModelPermissionDeserializerRequest { [JsonPropertyName("is_enabled")] - public bool? IsEnabled { get; init; } + public bool? IsEnabled { get; set; } } diff --git a/src/Merge.Client/Accounting/Types/MultipartFormFieldRequest.cs b/src/Merge.Client/Accounting/Types/MultipartFormFieldRequest.cs index 2328390a..7fe2cfe0 100644 --- a/src/Merge.Client/Accounting/Types/MultipartFormFieldRequest.cs +++ b/src/Merge.Client/Accounting/Types/MultipartFormFieldRequest.cs @@ -1,23 +1,22 @@ using System.Text.Json.Serialization; -using Merge.Client.Accounting; #nullable enable namespace Merge.Client.Accounting; -public class MultipartFormFieldRequest +public record MultipartFormFieldRequest { /// /// The name of the form field /// [JsonPropertyName("name")] - public string Name { get; init; } + public required string Name { get; set; } /// /// The data for the form field. /// [JsonPropertyName("data")] - public string Data { get; init; } + public required string Data { get; set; } /// /// The encoding of the value of `data`. Defaults to `RAW` if not defined. @@ -27,17 +26,17 @@ public class MultipartFormFieldRequest /// - `GZIP_BASE64` - GZIP_BASE64 /// [JsonPropertyName("encoding")] - public EncodingEnum? Encoding { get; init; } + public EncodingEnum? Encoding { get; set; } /// /// The file name of the form field, if the field is for a file. /// [JsonPropertyName("file_name")] - public string? FileName { get; init; } + public string? FileName { get; set; } /// /// The MIME type of the file, if the field is for a file. /// [JsonPropertyName("content_type")] - public string? ContentType { get; init; } + public string? ContentType { get; set; } } diff --git a/src/Merge.Client/Accounting/Types/PaginatedAccountDetailsAndActionsList.cs b/src/Merge.Client/Accounting/Types/PaginatedAccountDetailsAndActionsList.cs index d3cd2f16..2290039a 100644 --- a/src/Merge.Client/Accounting/Types/PaginatedAccountDetailsAndActionsList.cs +++ b/src/Merge.Client/Accounting/Types/PaginatedAccountDetailsAndActionsList.cs @@ -1,18 +1,17 @@ using System.Text.Json.Serialization; -using Merge.Client.Accounting; #nullable enable namespace Merge.Client.Accounting; -public class PaginatedAccountDetailsAndActionsList +public record PaginatedAccountDetailsAndActionsList { [JsonPropertyName("next")] - public string? Next { get; init; } + public string? Next { get; set; } [JsonPropertyName("previous")] - public string? Previous { get; init; } + public string? Previous { get; set; } [JsonPropertyName("results")] - public IEnumerable? Results { get; init; } + public IEnumerable? Results { get; set; } } diff --git a/src/Merge.Client/Accounting/Types/PaginatedAccountList.cs b/src/Merge.Client/Accounting/Types/PaginatedAccountList.cs index f21823ef..4831a059 100644 --- a/src/Merge.Client/Accounting/Types/PaginatedAccountList.cs +++ b/src/Merge.Client/Accounting/Types/PaginatedAccountList.cs @@ -1,18 +1,17 @@ using System.Text.Json.Serialization; -using Merge.Client.Accounting; #nullable enable namespace Merge.Client.Accounting; -public class PaginatedAccountList +public record PaginatedAccountList { [JsonPropertyName("next")] - public string? Next { get; init; } + public string? Next { get; set; } [JsonPropertyName("previous")] - public string? Previous { get; init; } + public string? Previous { get; set; } [JsonPropertyName("results")] - public IEnumerable? Results { get; init; } + public IEnumerable? Results { get; set; } } diff --git a/src/Merge.Client/Accounting/Types/PaginatedAccountingAttachmentList.cs b/src/Merge.Client/Accounting/Types/PaginatedAccountingAttachmentList.cs index f1dc096e..b4356c56 100644 --- a/src/Merge.Client/Accounting/Types/PaginatedAccountingAttachmentList.cs +++ b/src/Merge.Client/Accounting/Types/PaginatedAccountingAttachmentList.cs @@ -1,18 +1,17 @@ using System.Text.Json.Serialization; -using Merge.Client.Accounting; #nullable enable namespace Merge.Client.Accounting; -public class PaginatedAccountingAttachmentList +public record PaginatedAccountingAttachmentList { [JsonPropertyName("next")] - public string? Next { get; init; } + public string? Next { get; set; } [JsonPropertyName("previous")] - public string? Previous { get; init; } + public string? Previous { get; set; } [JsonPropertyName("results")] - public IEnumerable? Results { get; init; } + public IEnumerable? Results { get; set; } } diff --git a/src/Merge.Client/Accounting/Types/PaginatedAccountingPeriodList.cs b/src/Merge.Client/Accounting/Types/PaginatedAccountingPeriodList.cs index 7e05fba2..b450e6f6 100644 --- a/src/Merge.Client/Accounting/Types/PaginatedAccountingPeriodList.cs +++ b/src/Merge.Client/Accounting/Types/PaginatedAccountingPeriodList.cs @@ -1,18 +1,17 @@ using System.Text.Json.Serialization; -using Merge.Client.Accounting; #nullable enable namespace Merge.Client.Accounting; -public class PaginatedAccountingPeriodList +public record PaginatedAccountingPeriodList { [JsonPropertyName("next")] - public string? Next { get; init; } + public string? Next { get; set; } [JsonPropertyName("previous")] - public string? Previous { get; init; } + public string? Previous { get; set; } [JsonPropertyName("results")] - public IEnumerable? Results { get; init; } + public IEnumerable? Results { get; set; } } diff --git a/src/Merge.Client/Accounting/Types/PaginatedAuditLogEventList.cs b/src/Merge.Client/Accounting/Types/PaginatedAuditLogEventList.cs index 407208c1..59c92535 100644 --- a/src/Merge.Client/Accounting/Types/PaginatedAuditLogEventList.cs +++ b/src/Merge.Client/Accounting/Types/PaginatedAuditLogEventList.cs @@ -1,18 +1,17 @@ using System.Text.Json.Serialization; -using Merge.Client.Accounting; #nullable enable namespace Merge.Client.Accounting; -public class PaginatedAuditLogEventList +public record PaginatedAuditLogEventList { [JsonPropertyName("next")] - public string? Next { get; init; } + public string? Next { get; set; } [JsonPropertyName("previous")] - public string? Previous { get; init; } + public string? Previous { get; set; } [JsonPropertyName("results")] - public IEnumerable? Results { get; init; } + public IEnumerable? Results { get; set; } } diff --git a/src/Merge.Client/Accounting/Types/PaginatedBalanceSheetList.cs b/src/Merge.Client/Accounting/Types/PaginatedBalanceSheetList.cs index 8d935014..c6bd21d9 100644 --- a/src/Merge.Client/Accounting/Types/PaginatedBalanceSheetList.cs +++ b/src/Merge.Client/Accounting/Types/PaginatedBalanceSheetList.cs @@ -1,18 +1,17 @@ using System.Text.Json.Serialization; -using Merge.Client.Accounting; #nullable enable namespace Merge.Client.Accounting; -public class PaginatedBalanceSheetList +public record PaginatedBalanceSheetList { [JsonPropertyName("next")] - public string? Next { get; init; } + public string? Next { get; set; } [JsonPropertyName("previous")] - public string? Previous { get; init; } + public string? Previous { get; set; } [JsonPropertyName("results")] - public IEnumerable? Results { get; init; } + public IEnumerable? Results { get; set; } } diff --git a/src/Merge.Client/Accounting/Types/PaginatedCashFlowStatementList.cs b/src/Merge.Client/Accounting/Types/PaginatedCashFlowStatementList.cs index 09b8f373..d24ec48e 100644 --- a/src/Merge.Client/Accounting/Types/PaginatedCashFlowStatementList.cs +++ b/src/Merge.Client/Accounting/Types/PaginatedCashFlowStatementList.cs @@ -1,18 +1,17 @@ using System.Text.Json.Serialization; -using Merge.Client.Accounting; #nullable enable namespace Merge.Client.Accounting; -public class PaginatedCashFlowStatementList +public record PaginatedCashFlowStatementList { [JsonPropertyName("next")] - public string? Next { get; init; } + public string? Next { get; set; } [JsonPropertyName("previous")] - public string? Previous { get; init; } + public string? Previous { get; set; } [JsonPropertyName("results")] - public IEnumerable? Results { get; init; } + public IEnumerable? Results { get; set; } } diff --git a/src/Merge.Client/Accounting/Types/PaginatedCompanyInfoList.cs b/src/Merge.Client/Accounting/Types/PaginatedCompanyInfoList.cs index 5293aacd..0cdfe1a6 100644 --- a/src/Merge.Client/Accounting/Types/PaginatedCompanyInfoList.cs +++ b/src/Merge.Client/Accounting/Types/PaginatedCompanyInfoList.cs @@ -1,18 +1,17 @@ using System.Text.Json.Serialization; -using Merge.Client.Accounting; #nullable enable namespace Merge.Client.Accounting; -public class PaginatedCompanyInfoList +public record PaginatedCompanyInfoList { [JsonPropertyName("next")] - public string? Next { get; init; } + public string? Next { get; set; } [JsonPropertyName("previous")] - public string? Previous { get; init; } + public string? Previous { get; set; } [JsonPropertyName("results")] - public IEnumerable? Results { get; init; } + public IEnumerable? Results { get; set; } } diff --git a/src/Merge.Client/Accounting/Types/PaginatedContactList.cs b/src/Merge.Client/Accounting/Types/PaginatedContactList.cs index 921b0190..69036735 100644 --- a/src/Merge.Client/Accounting/Types/PaginatedContactList.cs +++ b/src/Merge.Client/Accounting/Types/PaginatedContactList.cs @@ -1,18 +1,17 @@ using System.Text.Json.Serialization; -using Merge.Client.Accounting; #nullable enable namespace Merge.Client.Accounting; -public class PaginatedContactList +public record PaginatedContactList { [JsonPropertyName("next")] - public string? Next { get; init; } + public string? Next { get; set; } [JsonPropertyName("previous")] - public string? Previous { get; init; } + public string? Previous { get; set; } [JsonPropertyName("results")] - public IEnumerable? Results { get; init; } + public IEnumerable? Results { get; set; } } diff --git a/src/Merge.Client/Accounting/Types/PaginatedCreditNoteList.cs b/src/Merge.Client/Accounting/Types/PaginatedCreditNoteList.cs index 226ee48b..74b5630c 100644 --- a/src/Merge.Client/Accounting/Types/PaginatedCreditNoteList.cs +++ b/src/Merge.Client/Accounting/Types/PaginatedCreditNoteList.cs @@ -1,18 +1,17 @@ using System.Text.Json.Serialization; -using Merge.Client.Accounting; #nullable enable namespace Merge.Client.Accounting; -public class PaginatedCreditNoteList +public record PaginatedCreditNoteList { [JsonPropertyName("next")] - public string? Next { get; init; } + public string? Next { get; set; } [JsonPropertyName("previous")] - public string? Previous { get; init; } + public string? Previous { get; set; } [JsonPropertyName("results")] - public IEnumerable? Results { get; init; } + public IEnumerable? Results { get; set; } } diff --git a/src/Merge.Client/Accounting/Types/PaginatedExpenseList.cs b/src/Merge.Client/Accounting/Types/PaginatedExpenseList.cs index 4a81787b..7eb15b46 100644 --- a/src/Merge.Client/Accounting/Types/PaginatedExpenseList.cs +++ b/src/Merge.Client/Accounting/Types/PaginatedExpenseList.cs @@ -1,18 +1,17 @@ using System.Text.Json.Serialization; -using Merge.Client.Accounting; #nullable enable namespace Merge.Client.Accounting; -public class PaginatedExpenseList +public record PaginatedExpenseList { [JsonPropertyName("next")] - public string? Next { get; init; } + public string? Next { get; set; } [JsonPropertyName("previous")] - public string? Previous { get; init; } + public string? Previous { get; set; } [JsonPropertyName("results")] - public IEnumerable? Results { get; init; } + public IEnumerable? Results { get; set; } } diff --git a/src/Merge.Client/Accounting/Types/PaginatedIncomeStatementList.cs b/src/Merge.Client/Accounting/Types/PaginatedIncomeStatementList.cs index 1ff506f7..45238f68 100644 --- a/src/Merge.Client/Accounting/Types/PaginatedIncomeStatementList.cs +++ b/src/Merge.Client/Accounting/Types/PaginatedIncomeStatementList.cs @@ -1,18 +1,17 @@ using System.Text.Json.Serialization; -using Merge.Client.Accounting; #nullable enable namespace Merge.Client.Accounting; -public class PaginatedIncomeStatementList +public record PaginatedIncomeStatementList { [JsonPropertyName("next")] - public string? Next { get; init; } + public string? Next { get; set; } [JsonPropertyName("previous")] - public string? Previous { get; init; } + public string? Previous { get; set; } [JsonPropertyName("results")] - public IEnumerable? Results { get; init; } + public IEnumerable? Results { get; set; } } diff --git a/src/Merge.Client/Accounting/Types/PaginatedInvoiceList.cs b/src/Merge.Client/Accounting/Types/PaginatedInvoiceList.cs index ad68199f..7b339ad5 100644 --- a/src/Merge.Client/Accounting/Types/PaginatedInvoiceList.cs +++ b/src/Merge.Client/Accounting/Types/PaginatedInvoiceList.cs @@ -1,18 +1,17 @@ using System.Text.Json.Serialization; -using Merge.Client.Accounting; #nullable enable namespace Merge.Client.Accounting; -public class PaginatedInvoiceList +public record PaginatedInvoiceList { [JsonPropertyName("next")] - public string? Next { get; init; } + public string? Next { get; set; } [JsonPropertyName("previous")] - public string? Previous { get; init; } + public string? Previous { get; set; } [JsonPropertyName("results")] - public IEnumerable? Results { get; init; } + public IEnumerable? Results { get; set; } } diff --git a/src/Merge.Client/Accounting/Types/PaginatedIssueList.cs b/src/Merge.Client/Accounting/Types/PaginatedIssueList.cs index 2f274256..e71de8d5 100644 --- a/src/Merge.Client/Accounting/Types/PaginatedIssueList.cs +++ b/src/Merge.Client/Accounting/Types/PaginatedIssueList.cs @@ -1,18 +1,17 @@ using System.Text.Json.Serialization; -using Merge.Client.Accounting; #nullable enable namespace Merge.Client.Accounting; -public class PaginatedIssueList +public record PaginatedIssueList { [JsonPropertyName("next")] - public string? Next { get; init; } + public string? Next { get; set; } [JsonPropertyName("previous")] - public string? Previous { get; init; } + public string? Previous { get; set; } [JsonPropertyName("results")] - public IEnumerable? Results { get; init; } + public IEnumerable? Results { get; set; } } diff --git a/src/Merge.Client/Accounting/Types/PaginatedItemList.cs b/src/Merge.Client/Accounting/Types/PaginatedItemList.cs index 8c2f7e55..81a85d3d 100644 --- a/src/Merge.Client/Accounting/Types/PaginatedItemList.cs +++ b/src/Merge.Client/Accounting/Types/PaginatedItemList.cs @@ -1,18 +1,17 @@ using System.Text.Json.Serialization; -using Merge.Client.Accounting; #nullable enable namespace Merge.Client.Accounting; -public class PaginatedItemList +public record PaginatedItemList { [JsonPropertyName("next")] - public string? Next { get; init; } + public string? Next { get; set; } [JsonPropertyName("previous")] - public string? Previous { get; init; } + public string? Previous { get; set; } [JsonPropertyName("results")] - public IEnumerable? Results { get; init; } + public IEnumerable? Results { get; set; } } diff --git a/src/Merge.Client/Accounting/Types/PaginatedJournalEntryList.cs b/src/Merge.Client/Accounting/Types/PaginatedJournalEntryList.cs index 7b06c635..ab8aa0bb 100644 --- a/src/Merge.Client/Accounting/Types/PaginatedJournalEntryList.cs +++ b/src/Merge.Client/Accounting/Types/PaginatedJournalEntryList.cs @@ -1,18 +1,17 @@ using System.Text.Json.Serialization; -using Merge.Client.Accounting; #nullable enable namespace Merge.Client.Accounting; -public class PaginatedJournalEntryList +public record PaginatedJournalEntryList { [JsonPropertyName("next")] - public string? Next { get; init; } + public string? Next { get; set; } [JsonPropertyName("previous")] - public string? Previous { get; init; } + public string? Previous { get; set; } [JsonPropertyName("results")] - public IEnumerable? Results { get; init; } + public IEnumerable? Results { get; set; } } diff --git a/src/Merge.Client/Accounting/Types/PaginatedPaymentList.cs b/src/Merge.Client/Accounting/Types/PaginatedPaymentList.cs index 8757f692..6f05c24d 100644 --- a/src/Merge.Client/Accounting/Types/PaginatedPaymentList.cs +++ b/src/Merge.Client/Accounting/Types/PaginatedPaymentList.cs @@ -1,18 +1,17 @@ using System.Text.Json.Serialization; -using Merge.Client.Accounting; #nullable enable namespace Merge.Client.Accounting; -public class PaginatedPaymentList +public record PaginatedPaymentList { [JsonPropertyName("next")] - public string? Next { get; init; } + public string? Next { get; set; } [JsonPropertyName("previous")] - public string? Previous { get; init; } + public string? Previous { get; set; } [JsonPropertyName("results")] - public IEnumerable? Results { get; init; } + public IEnumerable? Results { get; set; } } diff --git a/src/Merge.Client/Accounting/Types/PaginatedPurchaseOrderList.cs b/src/Merge.Client/Accounting/Types/PaginatedPurchaseOrderList.cs index 03cf2355..53e7c9cf 100644 --- a/src/Merge.Client/Accounting/Types/PaginatedPurchaseOrderList.cs +++ b/src/Merge.Client/Accounting/Types/PaginatedPurchaseOrderList.cs @@ -1,18 +1,17 @@ using System.Text.Json.Serialization; -using Merge.Client.Accounting; #nullable enable namespace Merge.Client.Accounting; -public class PaginatedPurchaseOrderList +public record PaginatedPurchaseOrderList { [JsonPropertyName("next")] - public string? Next { get; init; } + public string? Next { get; set; } [JsonPropertyName("previous")] - public string? Previous { get; init; } + public string? Previous { get; set; } [JsonPropertyName("results")] - public IEnumerable? Results { get; init; } + public IEnumerable? Results { get; set; } } diff --git a/src/Merge.Client/Accounting/Types/PaginatedSyncStatusList.cs b/src/Merge.Client/Accounting/Types/PaginatedSyncStatusList.cs index 9d7f3e9e..138dc491 100644 --- a/src/Merge.Client/Accounting/Types/PaginatedSyncStatusList.cs +++ b/src/Merge.Client/Accounting/Types/PaginatedSyncStatusList.cs @@ -1,18 +1,17 @@ using System.Text.Json.Serialization; -using Merge.Client.Accounting; #nullable enable namespace Merge.Client.Accounting; -public class PaginatedSyncStatusList +public record PaginatedSyncStatusList { [JsonPropertyName("next")] - public string? Next { get; init; } + public string? Next { get; set; } [JsonPropertyName("previous")] - public string? Previous { get; init; } + public string? Previous { get; set; } [JsonPropertyName("results")] - public IEnumerable? Results { get; init; } + public IEnumerable? Results { get; set; } } diff --git a/src/Merge.Client/Accounting/Types/PaginatedTaxRateList.cs b/src/Merge.Client/Accounting/Types/PaginatedTaxRateList.cs index e4a66b42..cec00483 100644 --- a/src/Merge.Client/Accounting/Types/PaginatedTaxRateList.cs +++ b/src/Merge.Client/Accounting/Types/PaginatedTaxRateList.cs @@ -1,18 +1,17 @@ using System.Text.Json.Serialization; -using Merge.Client.Accounting; #nullable enable namespace Merge.Client.Accounting; -public class PaginatedTaxRateList +public record PaginatedTaxRateList { [JsonPropertyName("next")] - public string? Next { get; init; } + public string? Next { get; set; } [JsonPropertyName("previous")] - public string? Previous { get; init; } + public string? Previous { get; set; } [JsonPropertyName("results")] - public IEnumerable? Results { get; init; } + public IEnumerable? Results { get; set; } } diff --git a/src/Merge.Client/Accounting/Types/PaginatedTrackingCategoryList.cs b/src/Merge.Client/Accounting/Types/PaginatedTrackingCategoryList.cs index 1e18c58c..f208804e 100644 --- a/src/Merge.Client/Accounting/Types/PaginatedTrackingCategoryList.cs +++ b/src/Merge.Client/Accounting/Types/PaginatedTrackingCategoryList.cs @@ -1,18 +1,17 @@ using System.Text.Json.Serialization; -using Merge.Client.Accounting; #nullable enable namespace Merge.Client.Accounting; -public class PaginatedTrackingCategoryList +public record PaginatedTrackingCategoryList { [JsonPropertyName("next")] - public string? Next { get; init; } + public string? Next { get; set; } [JsonPropertyName("previous")] - public string? Previous { get; init; } + public string? Previous { get; set; } [JsonPropertyName("results")] - public IEnumerable? Results { get; init; } + public IEnumerable? Results { get; set; } } diff --git a/src/Merge.Client/Accounting/Types/PaginatedTransactionList.cs b/src/Merge.Client/Accounting/Types/PaginatedTransactionList.cs index 3baa9353..0a4b4a76 100644 --- a/src/Merge.Client/Accounting/Types/PaginatedTransactionList.cs +++ b/src/Merge.Client/Accounting/Types/PaginatedTransactionList.cs @@ -1,18 +1,17 @@ using System.Text.Json.Serialization; -using Merge.Client.Accounting; #nullable enable namespace Merge.Client.Accounting; -public class PaginatedTransactionList +public record PaginatedTransactionList { [JsonPropertyName("next")] - public string? Next { get; init; } + public string? Next { get; set; } [JsonPropertyName("previous")] - public string? Previous { get; init; } + public string? Previous { get; set; } [JsonPropertyName("results")] - public IEnumerable? Results { get; init; } + public IEnumerable? Results { get; set; } } diff --git a/src/Merge.Client/Accounting/Types/PaginatedVendorCreditList.cs b/src/Merge.Client/Accounting/Types/PaginatedVendorCreditList.cs index d60550ec..aa0fff94 100644 --- a/src/Merge.Client/Accounting/Types/PaginatedVendorCreditList.cs +++ b/src/Merge.Client/Accounting/Types/PaginatedVendorCreditList.cs @@ -1,18 +1,17 @@ using System.Text.Json.Serialization; -using Merge.Client.Accounting; #nullable enable namespace Merge.Client.Accounting; -public class PaginatedVendorCreditList +public record PaginatedVendorCreditList { [JsonPropertyName("next")] - public string? Next { get; init; } + public string? Next { get; set; } [JsonPropertyName("previous")] - public string? Previous { get; init; } + public string? Previous { get; set; } [JsonPropertyName("results")] - public IEnumerable? Results { get; init; } + public IEnumerable? Results { get; set; } } diff --git a/src/Merge.Client/Accounting/Types/PatchedPaymentRequest.cs b/src/Merge.Client/Accounting/Types/PatchedPaymentRequest.cs index 05ca6ed8..906b5263 100644 --- a/src/Merge.Client/Accounting/Types/PatchedPaymentRequest.cs +++ b/src/Merge.Client/Accounting/Types/PatchedPaymentRequest.cs @@ -1,5 +1,4 @@ using System.Text.Json.Serialization; -using Merge.Client.Accounting; using Merge.Client.Core; using OneOf; @@ -7,27 +6,27 @@ namespace Merge.Client.Accounting; -public class PatchedPaymentRequest +public record PatchedPaymentRequest { /// /// The payment's transaction date. /// [JsonPropertyName("transaction_date")] - public DateTime? TransactionDate { get; init; } + public DateTime? TransactionDate { get; set; } /// /// The supplier, or customer involved in the payment. /// [JsonPropertyName("contact")] [JsonConverter(typeof(OneOfSerializer>))] - public OneOf? Contact { get; init; } + public OneOf? Contact { get; set; } /// /// The supplier’s or customer’s account in which the payment is made. /// [JsonPropertyName("account")] [JsonConverter(typeof(OneOfSerializer>))] - public OneOf? Account { get; init; } + public OneOf? Account { get; set; } /// /// The payment's currency. @@ -340,26 +339,26 @@ public class PatchedPaymentRequest /// - `ZWL` - Zimbabwean Dollar (2009) /// [JsonPropertyName("currency")] - public CurrencyEnum? Currency { get; init; } + public CurrencyEnum? Currency { get; set; } /// /// The payment's exchange rate. /// [JsonPropertyName("exchange_rate")] - public string? ExchangeRate { get; init; } + public string? ExchangeRate { get; set; } /// /// The company the payment belongs to. /// [JsonPropertyName("company")] [JsonConverter(typeof(OneOfSerializer>))] - public OneOf? Company { get; init; } + public OneOf? Company { get; set; } /// /// The total amount of money being paid to the supplier, or customer, after taxes. /// [JsonPropertyName("total_amount")] - public double? TotalAmount { get; init; } + public double? TotalAmount { get; set; } /// /// The type of the invoice. @@ -368,7 +367,7 @@ public class PatchedPaymentRequest /// - `ACCOUNTS_RECEIVABLE` - ACCOUNTS_RECEIVABLE /// [JsonPropertyName("type")] - public PaymentTypeEnum? Type { get; init; } + public PaymentTypeEnum? Type { get; set; } [JsonPropertyName("tracking_categories")] [JsonConverter( @@ -377,14 +376,14 @@ public class PatchedPaymentRequest OneOfSerializer> >) )] - public IEnumerable>? TrackingCategories { get; init; } + public IEnumerable>? TrackingCategories { get; set; } /// /// The accounting period that the Payment was generated in. /// [JsonPropertyName("accounting_period")] [JsonConverter(typeof(OneOfSerializer>))] - public OneOf? AccountingPeriod { get; init; } + public OneOf? AccountingPeriod { get; set; } /// /// A list of “Payment Applied to Lines” objects. @@ -396,11 +395,11 @@ public class PatchedPaymentRequest OneOfSerializer> >) )] - public IEnumerable>? AppliedToLines { get; init; } + public IEnumerable>? AppliedToLines { get; set; } [JsonPropertyName("integration_params")] - public Dictionary? IntegrationParams { get; init; } + public Dictionary? IntegrationParams { get; set; } [JsonPropertyName("linked_account_params")] - public Dictionary? LinkedAccountParams { get; init; } + public Dictionary? LinkedAccountParams { get; set; } } diff --git a/src/Merge.Client/Accounting/Types/Payment.cs b/src/Merge.Client/Accounting/Types/Payment.cs index 5331e502..6338ee20 100644 --- a/src/Merge.Client/Accounting/Types/Payment.cs +++ b/src/Merge.Client/Accounting/Types/Payment.cs @@ -1,5 +1,4 @@ using System.Text.Json.Serialization; -using Merge.Client.Accounting; using Merge.Client.Core; using OneOf; @@ -7,48 +6,48 @@ namespace Merge.Client.Accounting; -public class Payment +public record Payment { [JsonPropertyName("id")] - public string? Id { get; init; } + public string? Id { get; set; } /// /// The third-party API ID of the matching object. /// [JsonPropertyName("remote_id")] - public string? RemoteId { get; init; } + public string? RemoteId { get; set; } /// /// The datetime that this object was created by Merge. /// [JsonPropertyName("created_at")] - public DateTime? CreatedAt { get; init; } + public DateTime? CreatedAt { get; set; } /// /// The datetime that this object was modified by Merge. /// [JsonPropertyName("modified_at")] - public DateTime? ModifiedAt { get; init; } + public DateTime? ModifiedAt { get; set; } /// /// The payment's transaction date. /// [JsonPropertyName("transaction_date")] - public DateTime? TransactionDate { get; init; } + public DateTime? TransactionDate { get; set; } /// /// The supplier, or customer involved in the payment. /// [JsonPropertyName("contact")] [JsonConverter(typeof(OneOfSerializer>))] - public OneOf? Contact { get; init; } + public OneOf? Contact { get; set; } /// /// The supplier’s or customer’s account in which the payment is made. /// [JsonPropertyName("account")] [JsonConverter(typeof(OneOfSerializer>))] - public OneOf? Account { get; init; } + public OneOf? Account { get; set; } /// /// The payment's currency. @@ -361,26 +360,26 @@ public class Payment /// - `ZWL` - Zimbabwean Dollar (2009) /// [JsonPropertyName("currency")] - public CurrencyEnum? Currency { get; init; } + public CurrencyEnum? Currency { get; set; } /// /// The payment's exchange rate. /// [JsonPropertyName("exchange_rate")] - public string? ExchangeRate { get; init; } + public string? ExchangeRate { get; set; } /// /// The company the payment belongs to. /// [JsonPropertyName("company")] [JsonConverter(typeof(OneOfSerializer>))] - public OneOf? Company { get; init; } + public OneOf? Company { get; set; } /// /// The total amount of money being paid to the supplier, or customer, after taxes. /// [JsonPropertyName("total_amount")] - public double? TotalAmount { get; init; } + public double? TotalAmount { get; set; } /// /// The type of the invoice. @@ -389,7 +388,7 @@ public class Payment /// - `ACCOUNTS_RECEIVABLE` - ACCOUNTS_RECEIVABLE /// [JsonPropertyName("type")] - public PaymentTypeEnum? Type { get; init; } + public PaymentTypeEnum? Type { get; set; } [JsonPropertyName("tracking_categories")] [JsonConverter( @@ -398,26 +397,26 @@ public class Payment OneOfSerializer> >) )] - public IEnumerable>? TrackingCategories { get; init; } + public IEnumerable>? TrackingCategories { get; set; } /// /// When the third party's payment entry was updated. /// [JsonPropertyName("remote_updated_at")] - public DateTime? RemoteUpdatedAt { get; init; } + public DateTime? RemoteUpdatedAt { get; set; } /// /// Indicates whether or not this object has been deleted in the third party platform. /// [JsonPropertyName("remote_was_deleted")] - public bool? RemoteWasDeleted { get; init; } + public bool? RemoteWasDeleted { get; set; } /// /// The accounting period that the Payment was generated in. /// [JsonPropertyName("accounting_period")] [JsonConverter(typeof(OneOfSerializer>))] - public OneOf? AccountingPeriod { get; init; } + public OneOf? AccountingPeriod { get; set; } /// /// A list of “Payment Applied to Lines” objects. @@ -429,11 +428,11 @@ public class Payment OneOfSerializer> >) )] - public IEnumerable>? AppliedToLines { get; init; } + public IEnumerable>? AppliedToLines { get; set; } [JsonPropertyName("field_mappings")] - public Dictionary? FieldMappings { get; init; } + public Dictionary? FieldMappings { get; set; } [JsonPropertyName("remote_data")] - public IEnumerable? RemoteData { get; init; } + public IEnumerable? RemoteData { get; set; } } diff --git a/src/Merge.Client/Accounting/Types/PaymentLineItem.cs b/src/Merge.Client/Accounting/Types/PaymentLineItem.cs index 2890b7d1..4fe6aa23 100644 --- a/src/Merge.Client/Accounting/Types/PaymentLineItem.cs +++ b/src/Merge.Client/Accounting/Types/PaymentLineItem.cs @@ -4,50 +4,50 @@ namespace Merge.Client.Accounting; -public class PaymentLineItem +public record PaymentLineItem { [JsonPropertyName("id")] - public string? Id { get; init; } + public string? Id { get; set; } /// /// The third-party API ID of the matching object. /// [JsonPropertyName("remote_id")] - public string? RemoteId { get; init; } + public string? RemoteId { get; set; } /// /// The datetime that this object was created by Merge. /// [JsonPropertyName("created_at")] - public DateTime? CreatedAt { get; init; } + public DateTime? CreatedAt { get; set; } /// /// The datetime that this object was modified by Merge. /// [JsonPropertyName("modified_at")] - public DateTime? ModifiedAt { get; init; } + public DateTime? ModifiedAt { get; set; } /// /// The amount being applied to the transaction. /// [JsonPropertyName("applied_amount")] - public string? AppliedAmount { get; init; } + public string? AppliedAmount { get; set; } /// /// The date the payment portion is applied. /// [JsonPropertyName("applied_date")] - public DateTime? AppliedDate { get; init; } + public DateTime? AppliedDate { get; set; } /// /// The Merge ID of the transaction the payment portion is being applied to. /// [JsonPropertyName("related_object_id")] - public string? RelatedObjectId { get; init; } + public string? RelatedObjectId { get; set; } /// /// The type of transaction the payment portion is being applied to. Possible values include: INVOICE, JOURNAL_ENTRY, or CREDIT_NOTE. /// [JsonPropertyName("related_object_type")] - public string? RelatedObjectType { get; init; } + public string? RelatedObjectType { get; set; } } diff --git a/src/Merge.Client/Accounting/Types/PaymentLineItemRequest.cs b/src/Merge.Client/Accounting/Types/PaymentLineItemRequest.cs index 8a54cba8..9e5c12b2 100644 --- a/src/Merge.Client/Accounting/Types/PaymentLineItemRequest.cs +++ b/src/Merge.Client/Accounting/Types/PaymentLineItemRequest.cs @@ -4,41 +4,41 @@ namespace Merge.Client.Accounting; -public class PaymentLineItemRequest +public record PaymentLineItemRequest { /// /// The third-party API ID of the matching object. /// [JsonPropertyName("remote_id")] - public string? RemoteId { get; init; } + public string? RemoteId { get; set; } /// /// The amount being applied to the transaction. /// [JsonPropertyName("applied_amount")] - public string? AppliedAmount { get; init; } + public string? AppliedAmount { get; set; } /// /// The date the payment portion is applied. /// [JsonPropertyName("applied_date")] - public DateTime? AppliedDate { get; init; } + public DateTime? AppliedDate { get; set; } /// /// The Merge ID of the transaction the payment portion is being applied to. /// [JsonPropertyName("related_object_id")] - public string? RelatedObjectId { get; init; } + public string? RelatedObjectId { get; set; } /// /// The type of transaction the payment portion is being applied to. Possible values include: INVOICE, JOURNAL_ENTRY, or CREDIT_NOTE. /// [JsonPropertyName("related_object_type")] - public string? RelatedObjectType { get; init; } + public string? RelatedObjectType { get; set; } [JsonPropertyName("integration_params")] - public Dictionary? IntegrationParams { get; init; } + public Dictionary? IntegrationParams { get; set; } [JsonPropertyName("linked_account_params")] - public Dictionary? LinkedAccountParams { get; init; } + public Dictionary? LinkedAccountParams { get; set; } } diff --git a/src/Merge.Client/Accounting/Types/PaymentRequest.cs b/src/Merge.Client/Accounting/Types/PaymentRequest.cs index 603d4ef1..84066764 100644 --- a/src/Merge.Client/Accounting/Types/PaymentRequest.cs +++ b/src/Merge.Client/Accounting/Types/PaymentRequest.cs @@ -1,5 +1,4 @@ using System.Text.Json.Serialization; -using Merge.Client.Accounting; using Merge.Client.Core; using OneOf; @@ -7,27 +6,27 @@ namespace Merge.Client.Accounting; -public class PaymentRequest +public record PaymentRequest { /// /// The payment's transaction date. /// [JsonPropertyName("transaction_date")] - public DateTime? TransactionDate { get; init; } + public DateTime? TransactionDate { get; set; } /// /// The supplier, or customer involved in the payment. /// [JsonPropertyName("contact")] [JsonConverter(typeof(OneOfSerializer>))] - public OneOf? Contact { get; init; } + public OneOf? Contact { get; set; } /// /// The supplier’s or customer’s account in which the payment is made. /// [JsonPropertyName("account")] [JsonConverter(typeof(OneOfSerializer>))] - public OneOf? Account { get; init; } + public OneOf? Account { get; set; } /// /// The payment's currency. @@ -340,26 +339,26 @@ public class PaymentRequest /// - `ZWL` - Zimbabwean Dollar (2009) /// [JsonPropertyName("currency")] - public CurrencyEnum? Currency { get; init; } + public CurrencyEnum? Currency { get; set; } /// /// The payment's exchange rate. /// [JsonPropertyName("exchange_rate")] - public string? ExchangeRate { get; init; } + public string? ExchangeRate { get; set; } /// /// The company the payment belongs to. /// [JsonPropertyName("company")] [JsonConverter(typeof(OneOfSerializer>))] - public OneOf? Company { get; init; } + public OneOf? Company { get; set; } /// /// The total amount of money being paid to the supplier, or customer, after taxes. /// [JsonPropertyName("total_amount")] - public double? TotalAmount { get; init; } + public double? TotalAmount { get; set; } /// /// The type of the invoice. @@ -368,7 +367,7 @@ public class PaymentRequest /// - `ACCOUNTS_RECEIVABLE` - ACCOUNTS_RECEIVABLE /// [JsonPropertyName("type")] - public PaymentTypeEnum? Type { get; init; } + public PaymentTypeEnum? Type { get; set; } [JsonPropertyName("tracking_categories")] [JsonConverter( @@ -377,14 +376,14 @@ public class PaymentRequest OneOfSerializer> >) )] - public IEnumerable>? TrackingCategories { get; init; } + public IEnumerable>? TrackingCategories { get; set; } /// /// The accounting period that the Payment was generated in. /// [JsonPropertyName("accounting_period")] [JsonConverter(typeof(OneOfSerializer>))] - public OneOf? AccountingPeriod { get; init; } + public OneOf? AccountingPeriod { get; set; } /// /// A list of “Payment Applied to Lines” objects. @@ -396,11 +395,11 @@ public class PaymentRequest OneOfSerializer> >) )] - public IEnumerable>? AppliedToLines { get; init; } + public IEnumerable>? AppliedToLines { get; set; } [JsonPropertyName("integration_params")] - public Dictionary? IntegrationParams { get; init; } + public Dictionary? IntegrationParams { get; set; } [JsonPropertyName("linked_account_params")] - public Dictionary? LinkedAccountParams { get; init; } + public Dictionary? LinkedAccountParams { get; set; } } diff --git a/src/Merge.Client/Accounting/Types/PaymentResponse.cs b/src/Merge.Client/Accounting/Types/PaymentResponse.cs index 18637c6a..c53e23c3 100644 --- a/src/Merge.Client/Accounting/Types/PaymentResponse.cs +++ b/src/Merge.Client/Accounting/Types/PaymentResponse.cs @@ -1,21 +1,22 @@ using System.Text.Json.Serialization; -using Merge.Client.Accounting; #nullable enable namespace Merge.Client.Accounting; -public class PaymentResponse +public record PaymentResponse { [JsonPropertyName("model")] - public Payment Model { get; init; } + public required Payment Model { get; set; } [JsonPropertyName("warnings")] - public IEnumerable Warnings { get; init; } + public IEnumerable Warnings { get; set; } = + new List(); [JsonPropertyName("errors")] - public IEnumerable Errors { get; init; } + public IEnumerable Errors { get; set; } = + new List(); [JsonPropertyName("logs")] - public IEnumerable? Logs { get; init; } + public IEnumerable? Logs { get; set; } } diff --git a/src/Merge.Client/Accounting/Types/PaymentTypeEnum.cs b/src/Merge.Client/Accounting/Types/PaymentTypeEnum.cs index 77e88391..a3555bb5 100644 --- a/src/Merge.Client/Accounting/Types/PaymentTypeEnum.cs +++ b/src/Merge.Client/Accounting/Types/PaymentTypeEnum.cs @@ -1,6 +1,5 @@ using System.Runtime.Serialization; using System.Text.Json.Serialization; -using Merge.Client.Accounting; using Merge.Client.Core; #nullable enable diff --git a/src/Merge.Client/Accounting/Types/PostingStatusEnum.cs b/src/Merge.Client/Accounting/Types/PostingStatusEnum.cs index ac6713e9..a36d28b5 100644 --- a/src/Merge.Client/Accounting/Types/PostingStatusEnum.cs +++ b/src/Merge.Client/Accounting/Types/PostingStatusEnum.cs @@ -1,6 +1,5 @@ using System.Runtime.Serialization; using System.Text.Json.Serialization; -using Merge.Client.Accounting; using Merge.Client.Core; #nullable enable diff --git a/src/Merge.Client/Accounting/Types/PurchaseOrder.cs b/src/Merge.Client/Accounting/Types/PurchaseOrder.cs index 468bc3a1..5a7fee14 100644 --- a/src/Merge.Client/Accounting/Types/PurchaseOrder.cs +++ b/src/Merge.Client/Accounting/Types/PurchaseOrder.cs @@ -1,5 +1,4 @@ using System.Text.Json.Serialization; -using Merge.Client.Accounting; using Merge.Client.Core; using OneOf; @@ -7,28 +6,28 @@ namespace Merge.Client.Accounting; -public class PurchaseOrder +public record PurchaseOrder { [JsonPropertyName("id")] - public string? Id { get; init; } + public string? Id { get; set; } /// /// The third-party API ID of the matching object. /// [JsonPropertyName("remote_id")] - public string? RemoteId { get; init; } + public string? RemoteId { get; set; } /// /// The datetime that this object was created by Merge. /// [JsonPropertyName("created_at")] - public DateTime? CreatedAt { get; init; } + public DateTime? CreatedAt { get; set; } /// /// The datetime that this object was modified by Merge. /// [JsonPropertyName("modified_at")] - public DateTime? ModifiedAt { get; init; } + public DateTime? ModifiedAt { get; set; } /// /// The purchase order's status. @@ -40,64 +39,64 @@ public class PurchaseOrder /// - `DELETED` - DELETED /// [JsonPropertyName("status")] - public PurchaseOrderStatusEnum? Status { get; init; } + public PurchaseOrderStatusEnum? Status { get; set; } /// /// The purchase order's issue date. /// [JsonPropertyName("issue_date")] - public DateTime? IssueDate { get; init; } + public DateTime? IssueDate { get; set; } /// /// The human-readable number of the purchase order. /// [JsonPropertyName("purchase_order_number")] - public string? PurchaseOrderNumber { get; init; } + public string? PurchaseOrderNumber { get; set; } /// /// The purchase order's delivery date. /// [JsonPropertyName("delivery_date")] - public DateTime? DeliveryDate { get; init; } + public DateTime? DeliveryDate { get; set; } /// /// The purchase order's delivery address. /// [JsonPropertyName("delivery_address")] [JsonConverter(typeof(OneOfSerializer>))] - public OneOf? DeliveryAddress { get; init; } + public OneOf? DeliveryAddress { get; set; } /// /// The contact making the purchase order. /// [JsonPropertyName("customer")] - public string? Customer { get; init; } + public string? Customer { get; set; } /// /// The party fulfilling the purchase order. /// [JsonPropertyName("vendor")] [JsonConverter(typeof(OneOfSerializer>))] - public OneOf? Vendor { get; init; } + public OneOf? Vendor { get; set; } /// /// A memo attached to the purchase order. /// [JsonPropertyName("memo")] - public string? Memo { get; init; } + public string? Memo { get; set; } /// /// The company the purchase order belongs to. /// [JsonPropertyName("company")] [JsonConverter(typeof(OneOfSerializer>))] - public OneOf? Company { get; init; } + public OneOf? Company { get; set; } /// /// The purchase order's total amount. /// [JsonPropertyName("total_amount")] - public double? TotalAmount { get; init; } + public double? TotalAmount { get; set; } /// /// The purchase order's currency. @@ -410,16 +409,16 @@ public class PurchaseOrder /// - `ZWL` - Zimbabwean Dollar (2009) /// [JsonPropertyName("currency")] - public CurrencyEnum? Currency { get; init; } + public CurrencyEnum? Currency { get; set; } /// /// The purchase order's exchange rate. /// [JsonPropertyName("exchange_rate")] - public string? ExchangeRate { get; init; } + public string? ExchangeRate { get; set; } [JsonPropertyName("line_items")] - public IEnumerable? LineItems { get; init; } + public IEnumerable? LineItems { get; set; } [JsonPropertyName("tracking_categories")] [JsonConverter( @@ -428,36 +427,36 @@ public class PurchaseOrder OneOfSerializer> >) )] - public IEnumerable>? TrackingCategories { get; init; } + public IEnumerable>? TrackingCategories { get; set; } /// /// When the third party's purchase order note was created. /// [JsonPropertyName("remote_created_at")] - public DateTime? RemoteCreatedAt { get; init; } + public DateTime? RemoteCreatedAt { get; set; } /// /// When the third party's purchase order note was updated. /// [JsonPropertyName("remote_updated_at")] - public DateTime? RemoteUpdatedAt { get; init; } + public DateTime? RemoteUpdatedAt { get; set; } /// /// Indicates whether or not this object has been deleted in the third party platform. /// [JsonPropertyName("remote_was_deleted")] - public bool? RemoteWasDeleted { get; init; } + public bool? RemoteWasDeleted { get; set; } /// /// The accounting period that the PurchaseOrder was generated in. /// [JsonPropertyName("accounting_period")] [JsonConverter(typeof(OneOfSerializer>))] - public OneOf? AccountingPeriod { get; init; } + public OneOf? AccountingPeriod { get; set; } [JsonPropertyName("field_mappings")] - public Dictionary? FieldMappings { get; init; } + public Dictionary? FieldMappings { get; set; } [JsonPropertyName("remote_data")] - public IEnumerable? RemoteData { get; init; } + public IEnumerable? RemoteData { get; set; } } diff --git a/src/Merge.Client/Accounting/Types/PurchaseOrderLineItem.cs b/src/Merge.Client/Accounting/Types/PurchaseOrderLineItem.cs index 14f6150b..2c3cef1b 100644 --- a/src/Merge.Client/Accounting/Types/PurchaseOrderLineItem.cs +++ b/src/Merge.Client/Accounting/Types/PurchaseOrderLineItem.cs @@ -1,5 +1,4 @@ using System.Text.Json.Serialization; -using Merge.Client.Accounting; using Merge.Client.Core; using OneOf; @@ -7,80 +6,80 @@ namespace Merge.Client.Accounting; -public class PurchaseOrderLineItem +public record PurchaseOrderLineItem { [JsonPropertyName("id")] - public string? Id { get; init; } + public string? Id { get; set; } /// /// The third-party API ID of the matching object. /// [JsonPropertyName("remote_id")] - public string? RemoteId { get; init; } + public string? RemoteId { get; set; } /// /// The datetime that this object was created by Merge. /// [JsonPropertyName("created_at")] - public DateTime? CreatedAt { get; init; } + public DateTime? CreatedAt { get; set; } /// /// The datetime that this object was modified by Merge. /// [JsonPropertyName("modified_at")] - public DateTime? ModifiedAt { get; init; } + public DateTime? ModifiedAt { get; set; } /// /// A description of the good being purchased. /// [JsonPropertyName("description")] - public string? Description { get; init; } + public string? Description { get; set; } /// /// The line item's unit price. /// [JsonPropertyName("unit_price")] - public double? UnitPrice { get; init; } + public double? UnitPrice { get; set; } /// /// The line item's quantity. /// [JsonPropertyName("quantity")] - public double? Quantity { get; init; } + public double? Quantity { get; set; } [JsonPropertyName("item")] [JsonConverter(typeof(OneOfSerializer>))] - public OneOf? Item { get; init; } + public OneOf? Item { get; set; } /// /// The purchase order line item's account. /// [JsonPropertyName("account")] - public string? Account { get; init; } + public string? Account { get; set; } /// /// The purchase order line item's associated tracking category. /// [JsonPropertyName("tracking_category")] - public string? TrackingCategory { get; init; } + public string? TrackingCategory { get; set; } /// /// The purchase order line item's associated tracking categories. /// [JsonPropertyName("tracking_categories")] - public IEnumerable TrackingCategories { get; init; } + public IEnumerable TrackingCategories { get; set; } = new List(); /// /// The purchase order line item's tax amount. /// [JsonPropertyName("tax_amount")] - public string? TaxAmount { get; init; } + public string? TaxAmount { get; set; } /// /// The purchase order line item's total amount. /// [JsonPropertyName("total_line_amount")] - public string? TotalLineAmount { get; init; } + public string? TotalLineAmount { get; set; } /// /// The purchase order line item's currency. @@ -393,23 +392,23 @@ public class PurchaseOrderLineItem /// - `ZWL` - Zimbabwean Dollar (2009) /// [JsonPropertyName("currency")] - public CurrencyEnum? Currency { get; init; } + public CurrencyEnum? Currency { get; set; } /// /// The purchase order line item's exchange rate. /// [JsonPropertyName("exchange_rate")] - public string? ExchangeRate { get; init; } + public string? ExchangeRate { get; set; } /// /// The company the purchase order line item belongs to. /// [JsonPropertyName("company")] - public string? Company { get; init; } + public string? Company { get; set; } /// /// Indicates whether or not this object has been deleted in the third party platform. /// [JsonPropertyName("remote_was_deleted")] - public bool? RemoteWasDeleted { get; init; } + public bool? RemoteWasDeleted { get; set; } } diff --git a/src/Merge.Client/Accounting/Types/PurchaseOrderLineItemRequest.cs b/src/Merge.Client/Accounting/Types/PurchaseOrderLineItemRequest.cs index 674be8df..03fbb4b2 100644 --- a/src/Merge.Client/Accounting/Types/PurchaseOrderLineItemRequest.cs +++ b/src/Merge.Client/Accounting/Types/PurchaseOrderLineItemRequest.cs @@ -1,5 +1,4 @@ using System.Text.Json.Serialization; -using Merge.Client.Accounting; using Merge.Client.Core; using OneOf; @@ -7,65 +6,65 @@ namespace Merge.Client.Accounting; -public class PurchaseOrderLineItemRequest +public record PurchaseOrderLineItemRequest { /// /// The third-party API ID of the matching object. /// [JsonPropertyName("remote_id")] - public string? RemoteId { get; init; } + public string? RemoteId { get; set; } /// /// A description of the good being purchased. /// [JsonPropertyName("description")] - public string? Description { get; init; } + public string? Description { get; set; } /// /// The line item's unit price. /// [JsonPropertyName("unit_price")] - public double? UnitPrice { get; init; } + public double? UnitPrice { get; set; } /// /// The line item's quantity. /// [JsonPropertyName("quantity")] - public double? Quantity { get; init; } + public double? Quantity { get; set; } [JsonPropertyName("item")] [JsonConverter(typeof(OneOfSerializer>))] - public OneOf? Item { get; init; } + public OneOf? Item { get; set; } /// /// The purchase order line item's account. /// [JsonPropertyName("account")] - public string? Account { get; init; } + public string? Account { get; set; } /// /// The purchase order line item's associated tracking category. /// [JsonPropertyName("tracking_category")] - public string? TrackingCategory { get; init; } + public string? TrackingCategory { get; set; } /// /// The purchase order line item's associated tracking categories. /// [JsonPropertyName("tracking_categories")] - public IEnumerable TrackingCategories { get; init; } + public IEnumerable TrackingCategories { get; set; } = new List(); /// /// The purchase order line item's tax amount. /// [JsonPropertyName("tax_amount")] - public string? TaxAmount { get; init; } + public string? TaxAmount { get; set; } /// /// The purchase order line item's total amount. /// [JsonPropertyName("total_line_amount")] - public string? TotalLineAmount { get; init; } + public string? TotalLineAmount { get; set; } /// /// The purchase order line item's currency. @@ -378,23 +377,23 @@ public class PurchaseOrderLineItemRequest /// - `ZWL` - Zimbabwean Dollar (2009) /// [JsonPropertyName("currency")] - public CurrencyEnum? Currency { get; init; } + public CurrencyEnum? Currency { get; set; } /// /// The purchase order line item's exchange rate. /// [JsonPropertyName("exchange_rate")] - public string? ExchangeRate { get; init; } + public string? ExchangeRate { get; set; } /// /// The company the purchase order line item belongs to. /// [JsonPropertyName("company")] - public string? Company { get; init; } + public string? Company { get; set; } [JsonPropertyName("integration_params")] - public Dictionary? IntegrationParams { get; init; } + public Dictionary? IntegrationParams { get; set; } [JsonPropertyName("linked_account_params")] - public Dictionary? LinkedAccountParams { get; init; } + public Dictionary? LinkedAccountParams { get; set; } } diff --git a/src/Merge.Client/Accounting/Types/PurchaseOrderRequest.cs b/src/Merge.Client/Accounting/Types/PurchaseOrderRequest.cs index 994764f6..12684d3a 100644 --- a/src/Merge.Client/Accounting/Types/PurchaseOrderRequest.cs +++ b/src/Merge.Client/Accounting/Types/PurchaseOrderRequest.cs @@ -1,5 +1,4 @@ using System.Text.Json.Serialization; -using Merge.Client.Accounting; using Merge.Client.Core; using OneOf; @@ -7,7 +6,7 @@ namespace Merge.Client.Accounting; -public class PurchaseOrderRequest +public record PurchaseOrderRequest { /// /// The purchase order's status. @@ -19,58 +18,58 @@ public class PurchaseOrderRequest /// - `DELETED` - DELETED /// [JsonPropertyName("status")] - public PurchaseOrderStatusEnum? Status { get; init; } + public PurchaseOrderStatusEnum? Status { get; set; } /// /// The purchase order's issue date. /// [JsonPropertyName("issue_date")] - public DateTime? IssueDate { get; init; } + public DateTime? IssueDate { get; set; } /// /// The purchase order's delivery date. /// [JsonPropertyName("delivery_date")] - public DateTime? DeliveryDate { get; init; } + public DateTime? DeliveryDate { get; set; } /// /// The purchase order's delivery address. /// [JsonPropertyName("delivery_address")] [JsonConverter(typeof(OneOfSerializer>))] - public OneOf? DeliveryAddress { get; init; } + public OneOf? DeliveryAddress { get; set; } /// /// The contact making the purchase order. /// [JsonPropertyName("customer")] - public string? Customer { get; init; } + public string? Customer { get; set; } /// /// The party fulfilling the purchase order. /// [JsonPropertyName("vendor")] [JsonConverter(typeof(OneOfSerializer>))] - public OneOf? Vendor { get; init; } + public OneOf? Vendor { get; set; } /// /// A memo attached to the purchase order. /// [JsonPropertyName("memo")] - public string? Memo { get; init; } + public string? Memo { get; set; } /// /// The company the purchase order belongs to. /// [JsonPropertyName("company")] [JsonConverter(typeof(OneOfSerializer>))] - public OneOf? Company { get; init; } + public OneOf? Company { get; set; } /// /// The purchase order's total amount. /// [JsonPropertyName("total_amount")] - public double? TotalAmount { get; init; } + public double? TotalAmount { get; set; } /// /// The purchase order's currency. @@ -383,13 +382,13 @@ public class PurchaseOrderRequest /// - `ZWL` - Zimbabwean Dollar (2009) /// [JsonPropertyName("currency")] - public CurrencyEnum? Currency { get; init; } + public CurrencyEnum? Currency { get; set; } /// /// The purchase order's exchange rate. /// [JsonPropertyName("exchange_rate")] - public string? ExchangeRate { get; init; } + public string? ExchangeRate { get; set; } [JsonPropertyName("tracking_categories")] [JsonConverter( @@ -398,14 +397,14 @@ public class PurchaseOrderRequest OneOfSerializer> >) )] - public IEnumerable>? TrackingCategories { get; init; } + public IEnumerable>? TrackingCategories { get; set; } [JsonPropertyName("line_items")] - public IEnumerable? LineItems { get; init; } + public IEnumerable? LineItems { get; set; } [JsonPropertyName("integration_params")] - public Dictionary? IntegrationParams { get; init; } + public Dictionary? IntegrationParams { get; set; } [JsonPropertyName("linked_account_params")] - public Dictionary? LinkedAccountParams { get; init; } + public Dictionary? LinkedAccountParams { get; set; } } diff --git a/src/Merge.Client/Accounting/Types/PurchaseOrderResponse.cs b/src/Merge.Client/Accounting/Types/PurchaseOrderResponse.cs index 92c1c6d3..5d6dc67a 100644 --- a/src/Merge.Client/Accounting/Types/PurchaseOrderResponse.cs +++ b/src/Merge.Client/Accounting/Types/PurchaseOrderResponse.cs @@ -1,21 +1,22 @@ using System.Text.Json.Serialization; -using Merge.Client.Accounting; #nullable enable namespace Merge.Client.Accounting; -public class PurchaseOrderResponse +public record PurchaseOrderResponse { [JsonPropertyName("model")] - public PurchaseOrder Model { get; init; } + public required PurchaseOrder Model { get; set; } [JsonPropertyName("warnings")] - public IEnumerable Warnings { get; init; } + public IEnumerable Warnings { get; set; } = + new List(); [JsonPropertyName("errors")] - public IEnumerable Errors { get; init; } + public IEnumerable Errors { get; set; } = + new List(); [JsonPropertyName("logs")] - public IEnumerable? Logs { get; init; } + public IEnumerable? Logs { get; set; } } diff --git a/src/Merge.Client/Accounting/Types/PurchaseOrderStatusEnum.cs b/src/Merge.Client/Accounting/Types/PurchaseOrderStatusEnum.cs index 3d5f2107..6c35deb1 100644 --- a/src/Merge.Client/Accounting/Types/PurchaseOrderStatusEnum.cs +++ b/src/Merge.Client/Accounting/Types/PurchaseOrderStatusEnum.cs @@ -1,6 +1,5 @@ using System.Runtime.Serialization; using System.Text.Json.Serialization; -using Merge.Client.Accounting; using Merge.Client.Core; #nullable enable diff --git a/src/Merge.Client/Accounting/Types/RemoteData.cs b/src/Merge.Client/Accounting/Types/RemoteData.cs index 4faefec9..d06ad450 100644 --- a/src/Merge.Client/Accounting/Types/RemoteData.cs +++ b/src/Merge.Client/Accounting/Types/RemoteData.cs @@ -4,11 +4,11 @@ namespace Merge.Client.Accounting; -public class RemoteData +public record RemoteData { [JsonPropertyName("path")] - public string Path { get; init; } + public required string Path { get; set; } [JsonPropertyName("data")] - public object? Data { get; init; } + public object? Data { get; set; } } diff --git a/src/Merge.Client/Accounting/Types/RemoteEndpointInfo.cs b/src/Merge.Client/Accounting/Types/RemoteEndpointInfo.cs index 99c1fd1d..d35356a2 100644 --- a/src/Merge.Client/Accounting/Types/RemoteEndpointInfo.cs +++ b/src/Merge.Client/Accounting/Types/RemoteEndpointInfo.cs @@ -4,14 +4,14 @@ namespace Merge.Client.Accounting; -public class RemoteEndpointInfo +public record RemoteEndpointInfo { [JsonPropertyName("method")] - public string Method { get; init; } + public required string Method { get; set; } [JsonPropertyName("url_path")] - public string UrlPath { get; init; } + public required string UrlPath { get; set; } [JsonPropertyName("field_traversal_path")] - public IEnumerable FieldTraversalPath { get; init; } + public IEnumerable FieldTraversalPath { get; set; } = new List(); } diff --git a/src/Merge.Client/Accounting/Types/RemoteFieldApi.cs b/src/Merge.Client/Accounting/Types/RemoteFieldApi.cs index e48c4c30..b03d46c2 100644 --- a/src/Merge.Client/Accounting/Types/RemoteFieldApi.cs +++ b/src/Merge.Client/Accounting/Types/RemoteFieldApi.cs @@ -1,5 +1,4 @@ using System.Text.Json.Serialization; -using Merge.Client.Accounting; using Merge.Client.Core; using OneOf; @@ -7,24 +6,24 @@ namespace Merge.Client.Accounting; -public class RemoteFieldApi +public record RemoteFieldApi { [JsonPropertyName("schema")] - public Dictionary Schema { get; init; } + public Dictionary Schema { get; set; } = new Dictionary(); [JsonPropertyName("remote_key_name")] - public string RemoteKeyName { get; init; } + public required string RemoteKeyName { get; set; } [JsonPropertyName("remote_endpoint_info")] - public RemoteEndpointInfo RemoteEndpointInfo { get; init; } + public required RemoteEndpointInfo RemoteEndpointInfo { get; set; } [JsonPropertyName("example_values")] - public IEnumerable ExampleValues { get; init; } + public IEnumerable ExampleValues { get; set; } = new List(); [JsonPropertyName("advanced_metadata")] - public AdvancedMetadata? AdvancedMetadata { get; init; } + public AdvancedMetadata? AdvancedMetadata { get; set; } [JsonPropertyName("coverage")] [JsonConverter(typeof(OneOfSerializer>))] - public OneOf? Coverage { get; init; } + public OneOf? Coverage { get; set; } } diff --git a/src/Merge.Client/Accounting/Types/RemoteFieldApiResponse.cs b/src/Merge.Client/Accounting/Types/RemoteFieldApiResponse.cs index 5dbe3562..a0525565 100644 --- a/src/Merge.Client/Accounting/Types/RemoteFieldApiResponse.cs +++ b/src/Merge.Client/Accounting/Types/RemoteFieldApiResponse.cs @@ -1,66 +1,65 @@ using System.Text.Json.Serialization; -using Merge.Client.Accounting; #nullable enable namespace Merge.Client.Accounting; -public class RemoteFieldApiResponse +public record RemoteFieldApiResponse { [JsonPropertyName("Account")] - public IEnumerable? Account { get; init; } + public IEnumerable? Account { get; set; } [JsonPropertyName("AccountingAttachment")] - public IEnumerable? AccountingAttachment { get; init; } + public IEnumerable? AccountingAttachment { get; set; } [JsonPropertyName("BalanceSheet")] - public IEnumerable? BalanceSheet { get; init; } + public IEnumerable? BalanceSheet { get; set; } [JsonPropertyName("CashFlowStatement")] - public IEnumerable? CashFlowStatement { get; init; } + public IEnumerable? CashFlowStatement { get; set; } [JsonPropertyName("CompanyInfo")] - public IEnumerable? CompanyInfo { get; init; } + public IEnumerable? CompanyInfo { get; set; } [JsonPropertyName("Contact")] - public IEnumerable? Contact { get; init; } + public IEnumerable? Contact { get; set; } [JsonPropertyName("IncomeStatement")] - public IEnumerable? IncomeStatement { get; init; } + public IEnumerable? IncomeStatement { get; set; } [JsonPropertyName("CreditNote")] - public IEnumerable? CreditNote { get; init; } + public IEnumerable? CreditNote { get; set; } [JsonPropertyName("Item")] - public IEnumerable? Item { get; init; } + public IEnumerable? Item { get; set; } [JsonPropertyName("PurchaseOrder")] - public IEnumerable? PurchaseOrder { get; init; } + public IEnumerable? PurchaseOrder { get; set; } [JsonPropertyName("TrackingCategory")] - public IEnumerable? TrackingCategory { get; init; } + public IEnumerable? TrackingCategory { get; set; } [JsonPropertyName("JournalEntry")] - public IEnumerable? JournalEntry { get; init; } + public IEnumerable? JournalEntry { get; set; } [JsonPropertyName("TaxRate")] - public IEnumerable? TaxRate { get; init; } + public IEnumerable? TaxRate { get; set; } [JsonPropertyName("Invoice")] - public IEnumerable? Invoice { get; init; } + public IEnumerable? Invoice { get; set; } [JsonPropertyName("Payment")] - public IEnumerable? Payment { get; init; } + public IEnumerable? Payment { get; set; } [JsonPropertyName("Expense")] - public IEnumerable? Expense { get; init; } + public IEnumerable? Expense { get; set; } [JsonPropertyName("VendorCredit")] - public IEnumerable? VendorCredit { get; init; } + public IEnumerable? VendorCredit { get; set; } [JsonPropertyName("Transaction")] - public IEnumerable? Transaction { get; init; } + public IEnumerable? Transaction { get; set; } [JsonPropertyName("GeneralLedgerTransaction")] - public IEnumerable? GeneralLedgerTransaction { get; init; } + public IEnumerable? GeneralLedgerTransaction { get; set; } } diff --git a/src/Merge.Client/Accounting/Types/RemoteKey.cs b/src/Merge.Client/Accounting/Types/RemoteKey.cs index 4366a69c..648929e6 100644 --- a/src/Merge.Client/Accounting/Types/RemoteKey.cs +++ b/src/Merge.Client/Accounting/Types/RemoteKey.cs @@ -4,11 +4,11 @@ namespace Merge.Client.Accounting; -public class RemoteKey +public record RemoteKey { [JsonPropertyName("name")] - public string Name { get; init; } + public required string Name { get; set; } [JsonPropertyName("key")] - public string Key { get; init; } + public required string Key { get; set; } } diff --git a/src/Merge.Client/Accounting/Types/RemoteResponse.cs b/src/Merge.Client/Accounting/Types/RemoteResponse.cs index ae1b9954..360f5542 100644 --- a/src/Merge.Client/Accounting/Types/RemoteResponse.cs +++ b/src/Merge.Client/Accounting/Types/RemoteResponse.cs @@ -1,30 +1,29 @@ using System.Text.Json.Serialization; -using Merge.Client.Accounting; #nullable enable namespace Merge.Client.Accounting; -public class RemoteResponse +public record RemoteResponse { [JsonPropertyName("method")] - public string Method { get; init; } + public required string Method { get; set; } [JsonPropertyName("path")] - public string Path { get; init; } + public required string Path { get; set; } [JsonPropertyName("status")] - public int Status { get; init; } + public required int Status { get; set; } [JsonPropertyName("response")] - public object Response { get; init; } + public required object Response { get; set; } [JsonPropertyName("response_headers")] - public Dictionary? ResponseHeaders { get; init; } + public Dictionary? ResponseHeaders { get; set; } [JsonPropertyName("response_type")] - public ResponseTypeEnum? ResponseType { get; init; } + public ResponseTypeEnum? ResponseType { get; set; } [JsonPropertyName("headers")] - public Dictionary? Headers { get; init; } + public Dictionary? Headers { get; set; } } diff --git a/src/Merge.Client/Accounting/Types/ReportItem.cs b/src/Merge.Client/Accounting/Types/ReportItem.cs index 258918dd..6fc545a8 100644 --- a/src/Merge.Client/Accounting/Types/ReportItem.cs +++ b/src/Merge.Client/Accounting/Types/ReportItem.cs @@ -4,44 +4,44 @@ namespace Merge.Client.Accounting; -public class ReportItem +public record ReportItem { /// /// The third-party API ID of the matching object. /// [JsonPropertyName("remote_id")] - public string? RemoteId { get; init; } + public string? RemoteId { get; set; } /// /// The datetime that this object was created by Merge. /// [JsonPropertyName("created_at")] - public DateTime? CreatedAt { get; init; } + public DateTime? CreatedAt { get; set; } /// /// The datetime that this object was modified by Merge. /// [JsonPropertyName("modified_at")] - public DateTime? ModifiedAt { get; init; } + public DateTime? ModifiedAt { get; set; } /// /// The report item's name. /// [JsonPropertyName("name")] - public string? Name { get; init; } + public string? Name { get; set; } /// /// The report item's value. /// [JsonPropertyName("value")] - public double? Value { get; init; } + public double? Value { get; set; } [JsonPropertyName("sub_items")] - public IEnumerable>? SubItems { get; init; } + public IEnumerable>? SubItems { get; set; } /// /// The company the report item belongs to. /// [JsonPropertyName("company")] - public string? Company { get; init; } + public string? Company { get; set; } } diff --git a/src/Merge.Client/Accounting/Types/RequestFormatEnum.cs b/src/Merge.Client/Accounting/Types/RequestFormatEnum.cs index 1b8cdcff..c35fde95 100644 --- a/src/Merge.Client/Accounting/Types/RequestFormatEnum.cs +++ b/src/Merge.Client/Accounting/Types/RequestFormatEnum.cs @@ -1,6 +1,5 @@ using System.Runtime.Serialization; using System.Text.Json.Serialization; -using Merge.Client.Accounting; using Merge.Client.Core; #nullable enable diff --git a/src/Merge.Client/Accounting/Types/ResponseTypeEnum.cs b/src/Merge.Client/Accounting/Types/ResponseTypeEnum.cs index d07fb8b5..010c50e7 100644 --- a/src/Merge.Client/Accounting/Types/ResponseTypeEnum.cs +++ b/src/Merge.Client/Accounting/Types/ResponseTypeEnum.cs @@ -1,6 +1,5 @@ using System.Runtime.Serialization; using System.Text.Json.Serialization; -using Merge.Client.Accounting; using Merge.Client.Core; #nullable enable diff --git a/src/Merge.Client/Accounting/Types/RoleEnum.cs b/src/Merge.Client/Accounting/Types/RoleEnum.cs index c9a563ac..58c9e54c 100644 --- a/src/Merge.Client/Accounting/Types/RoleEnum.cs +++ b/src/Merge.Client/Accounting/Types/RoleEnum.cs @@ -1,6 +1,5 @@ using System.Runtime.Serialization; using System.Text.Json.Serialization; -using Merge.Client.Accounting; using Merge.Client.Core; #nullable enable diff --git a/src/Merge.Client/Accounting/Types/SelectiveSyncConfigurationsUsageEnum.cs b/src/Merge.Client/Accounting/Types/SelectiveSyncConfigurationsUsageEnum.cs index dd67aaea..73c6be50 100644 --- a/src/Merge.Client/Accounting/Types/SelectiveSyncConfigurationsUsageEnum.cs +++ b/src/Merge.Client/Accounting/Types/SelectiveSyncConfigurationsUsageEnum.cs @@ -1,6 +1,5 @@ using System.Runtime.Serialization; using System.Text.Json.Serialization; -using Merge.Client.Accounting; using Merge.Client.Core; #nullable enable diff --git a/src/Merge.Client/Accounting/Types/Status7D1Enum.cs b/src/Merge.Client/Accounting/Types/Status7D1Enum.cs index 30bb820c..07ae11b9 100644 --- a/src/Merge.Client/Accounting/Types/Status7D1Enum.cs +++ b/src/Merge.Client/Accounting/Types/Status7D1Enum.cs @@ -1,6 +1,5 @@ using System.Runtime.Serialization; using System.Text.Json.Serialization; -using Merge.Client.Accounting; using Merge.Client.Core; #nullable enable diff --git a/src/Merge.Client/Accounting/Types/SyncStatus.cs b/src/Merge.Client/Accounting/Types/SyncStatus.cs index 0323514f..c554cc4b 100644 --- a/src/Merge.Client/Accounting/Types/SyncStatus.cs +++ b/src/Merge.Client/Accounting/Types/SyncStatus.cs @@ -1,30 +1,29 @@ using System.Text.Json.Serialization; -using Merge.Client.Accounting; #nullable enable namespace Merge.Client.Accounting; -public class SyncStatus +public record SyncStatus { [JsonPropertyName("model_name")] - public string ModelName { get; init; } + public required string ModelName { get; set; } [JsonPropertyName("model_id")] - public string ModelId { get; init; } + public required string ModelId { get; set; } [JsonPropertyName("last_sync_start")] - public DateTime? LastSyncStart { get; init; } + public DateTime? LastSyncStart { get; set; } [JsonPropertyName("next_sync_start")] - public DateTime? NextSyncStart { get; init; } + public DateTime? NextSyncStart { get; set; } [JsonPropertyName("status")] - public SyncStatusStatusEnum Status { get; init; } + public required SyncStatusStatusEnum Status { get; set; } [JsonPropertyName("is_initial_sync")] - public bool IsInitialSync { get; init; } + public required bool IsInitialSync { get; set; } [JsonPropertyName("selective_sync_configurations_usage")] - public SelectiveSyncConfigurationsUsageEnum? SelectiveSyncConfigurationsUsage { get; init; } + public SelectiveSyncConfigurationsUsageEnum? SelectiveSyncConfigurationsUsage { get; set; } } diff --git a/src/Merge.Client/Accounting/Types/SyncStatusStatusEnum.cs b/src/Merge.Client/Accounting/Types/SyncStatusStatusEnum.cs index 54545735..73f62af7 100644 --- a/src/Merge.Client/Accounting/Types/SyncStatusStatusEnum.cs +++ b/src/Merge.Client/Accounting/Types/SyncStatusStatusEnum.cs @@ -1,6 +1,5 @@ using System.Runtime.Serialization; using System.Text.Json.Serialization; -using Merge.Client.Accounting; using Merge.Client.Core; #nullable enable diff --git a/src/Merge.Client/Accounting/Types/TaxRate.cs b/src/Merge.Client/Accounting/Types/TaxRate.cs index 513ca2de..cb0cc5b0 100644 --- a/src/Merge.Client/Accounting/Types/TaxRate.cs +++ b/src/Merge.Client/Accounting/Types/TaxRate.cs @@ -1,5 +1,4 @@ using System.Text.Json.Serialization; -using Merge.Client.Accounting; using Merge.Client.Core; using OneOf; @@ -7,63 +6,63 @@ namespace Merge.Client.Accounting; -public class TaxRate +public record TaxRate { [JsonPropertyName("id")] - public string? Id { get; init; } + public string? Id { get; set; } /// /// The third-party API ID of the matching object. /// [JsonPropertyName("remote_id")] - public string? RemoteId { get; init; } + public string? RemoteId { get; set; } /// /// The datetime that this object was created by Merge. /// [JsonPropertyName("created_at")] - public DateTime? CreatedAt { get; init; } + public DateTime? CreatedAt { get; set; } /// /// The datetime that this object was modified by Merge. /// [JsonPropertyName("modified_at")] - public DateTime? ModifiedAt { get; init; } + public DateTime? ModifiedAt { get; set; } /// /// The tax rate's description. /// [JsonPropertyName("description")] - public string? Description { get; init; } + public string? Description { get; set; } /// /// The tax’s total tax rate - sum of the tax components (not compounded). /// [JsonPropertyName("total_tax_rate")] - public double? TotalTaxRate { get; init; } + public double? TotalTaxRate { get; set; } /// /// The tax rate’s effective tax rate - total amount of tax with compounding. /// [JsonPropertyName("effective_tax_rate")] - public double? EffectiveTaxRate { get; init; } + public double? EffectiveTaxRate { get; set; } /// /// The subsidiary that the tax rate belongs to (in the case of multi-entity systems). /// [JsonPropertyName("company")] [JsonConverter(typeof(OneOfSerializer>))] - public OneOf? Company { get; init; } + public OneOf? Company { get; set; } /// /// Indicates whether or not this object has been deleted in the third party platform. /// [JsonPropertyName("remote_was_deleted")] - public bool? RemoteWasDeleted { get; init; } + public bool? RemoteWasDeleted { get; set; } [JsonPropertyName("field_mappings")] - public Dictionary? FieldMappings { get; init; } + public Dictionary? FieldMappings { get; set; } [JsonPropertyName("remote_data")] - public IEnumerable? RemoteData { get; init; } + public IEnumerable? RemoteData { get; set; } } diff --git a/src/Merge.Client/Accounting/Types/TrackingCategory.cs b/src/Merge.Client/Accounting/Types/TrackingCategory.cs index b7cf21c5..af70cb5c 100644 --- a/src/Merge.Client/Accounting/Types/TrackingCategory.cs +++ b/src/Merge.Client/Accounting/Types/TrackingCategory.cs @@ -1,5 +1,4 @@ using System.Text.Json.Serialization; -using Merge.Client.Accounting; using Merge.Client.Core; using OneOf; @@ -7,34 +6,34 @@ namespace Merge.Client.Accounting; -public class TrackingCategory +public record TrackingCategory { [JsonPropertyName("id")] - public string? Id { get; init; } + public string? Id { get; set; } /// /// The third-party API ID of the matching object. /// [JsonPropertyName("remote_id")] - public string? RemoteId { get; init; } + public string? RemoteId { get; set; } /// /// The datetime that this object was created by Merge. /// [JsonPropertyName("created_at")] - public DateTime? CreatedAt { get; init; } + public DateTime? CreatedAt { get; set; } /// /// The datetime that this object was modified by Merge. /// [JsonPropertyName("modified_at")] - public DateTime? ModifiedAt { get; init; } + public DateTime? ModifiedAt { get; set; } /// /// The tracking category's name. /// [JsonPropertyName("name")] - public string? Name { get; init; } + public string? Name { get; set; } /// /// The tracking category's status. @@ -43,7 +42,7 @@ public class TrackingCategory /// - `ARCHIVED` - ARCHIVED /// [JsonPropertyName("status")] - public Status7D1Enum? Status { get; init; } + public Status7D1Enum? Status { get; set; } /// /// The tracking category’s type. @@ -52,30 +51,30 @@ public class TrackingCategory /// - `DEPARTMENT` - DEPARTMENT /// [JsonPropertyName("category_type")] - public CategoryTypeEnum? CategoryType { get; init; } + public CategoryTypeEnum? CategoryType { get; set; } /// /// ID of the parent tracking category. /// [JsonPropertyName("parent_category")] - public string? ParentCategory { get; init; } + public string? ParentCategory { get; set; } /// /// The company the tracking category belongs to. /// [JsonPropertyName("company")] [JsonConverter(typeof(OneOfSerializer>))] - public OneOf? Company { get; init; } + public OneOf? Company { get; set; } /// /// Indicates whether or not this object has been deleted in the third party platform. /// [JsonPropertyName("remote_was_deleted")] - public bool? RemoteWasDeleted { get; init; } + public bool? RemoteWasDeleted { get; set; } [JsonPropertyName("field_mappings")] - public Dictionary? FieldMappings { get; init; } + public Dictionary? FieldMappings { get; set; } [JsonPropertyName("remote_data")] - public IEnumerable? RemoteData { get; init; } + public IEnumerable? RemoteData { get; set; } } diff --git a/src/Merge.Client/Accounting/Types/Transaction.cs b/src/Merge.Client/Accounting/Types/Transaction.cs index d77434da..4328aa80 100644 --- a/src/Merge.Client/Accounting/Types/Transaction.cs +++ b/src/Merge.Client/Accounting/Types/Transaction.cs @@ -1,5 +1,4 @@ using System.Text.Json.Serialization; -using Merge.Client.Accounting; using Merge.Client.Core; using OneOf; @@ -7,66 +6,66 @@ namespace Merge.Client.Accounting; -public class Transaction +public record Transaction { [JsonPropertyName("id")] - public string? Id { get; init; } + public string? Id { get; set; } /// /// The third-party API ID of the matching object. /// [JsonPropertyName("remote_id")] - public string? RemoteId { get; init; } + public string? RemoteId { get; set; } /// /// The datetime that this object was created by Merge. /// [JsonPropertyName("created_at")] - public DateTime? CreatedAt { get; init; } + public DateTime? CreatedAt { get; set; } /// /// The datetime that this object was modified by Merge. /// [JsonPropertyName("modified_at")] - public DateTime? ModifiedAt { get; init; } + public DateTime? ModifiedAt { get; set; } /// /// The type of transaction, which can by any transaction object not already included in Merge’s common model. /// [JsonPropertyName("transaction_type")] - public string? TransactionType { get; init; } + public string? TransactionType { get; set; } /// /// The transaction's number used for identifying purposes. /// [JsonPropertyName("number")] - public string? Number { get; init; } + public string? Number { get; set; } /// /// The date upon which the transaction occurred. /// [JsonPropertyName("transaction_date")] - public DateTime? TransactionDate { get; init; } + public DateTime? TransactionDate { get; set; } /// /// The transaction's account. /// [JsonPropertyName("account")] [JsonConverter(typeof(OneOfSerializer>))] - public OneOf? Account { get; init; } + public OneOf? Account { get; set; } /// /// The contact to whom the transaction relates to. /// [JsonPropertyName("contact")] [JsonConverter(typeof(OneOfSerializer>))] - public OneOf? Contact { get; init; } + public OneOf? Contact { get; set; } /// /// The total amount being paid after taxes. /// [JsonPropertyName("total_amount")] - public string? TotalAmount { get; init; } + public string? TotalAmount { get; set; } /// /// The transaction's currency. @@ -379,19 +378,19 @@ public class Transaction /// - `ZWL` - Zimbabwean Dollar (2009) /// [JsonPropertyName("currency")] - public CurrencyEnum? Currency { get; init; } + public CurrencyEnum? Currency { get; set; } /// /// The transaction's exchange rate. /// [JsonPropertyName("exchange_rate")] - public string? ExchangeRate { get; init; } + public string? ExchangeRate { get; set; } /// /// The company the transaction belongs to. /// [JsonPropertyName("company")] - public string? Company { get; init; } + public string? Company { get; set; } [JsonPropertyName("tracking_categories")] [JsonConverter( @@ -400,27 +399,27 @@ public class Transaction OneOfSerializer> >) )] - public IEnumerable>? TrackingCategories { get; init; } + public IEnumerable>? TrackingCategories { get; set; } [JsonPropertyName("line_items")] - public IEnumerable? LineItems { get; init; } + public IEnumerable? LineItems { get; set; } /// /// Indicates whether or not this object has been deleted in the third party platform. /// [JsonPropertyName("remote_was_deleted")] - public bool? RemoteWasDeleted { get; init; } + public bool? RemoteWasDeleted { get; set; } /// /// The accounting period that the Transaction was generated in. /// [JsonPropertyName("accounting_period")] [JsonConverter(typeof(OneOfSerializer>))] - public OneOf? AccountingPeriod { get; init; } + public OneOf? AccountingPeriod { get; set; } [JsonPropertyName("field_mappings")] - public Dictionary? FieldMappings { get; init; } + public Dictionary? FieldMappings { get; set; } [JsonPropertyName("remote_data")] - public IEnumerable? RemoteData { get; init; } + public IEnumerable? RemoteData { get; set; } } diff --git a/src/Merge.Client/Accounting/Types/TransactionLineItem.cs b/src/Merge.Client/Accounting/Types/TransactionLineItem.cs index f0f11014..dd2fe85f 100644 --- a/src/Merge.Client/Accounting/Types/TransactionLineItem.cs +++ b/src/Merge.Client/Accounting/Types/TransactionLineItem.cs @@ -1,5 +1,4 @@ using System.Text.Json.Serialization; -using Merge.Client.Accounting; using Merge.Client.Core; using OneOf; @@ -7,77 +6,77 @@ namespace Merge.Client.Accounting; -public class TransactionLineItem +public record TransactionLineItem { [JsonPropertyName("id")] - public string? Id { get; init; } + public string? Id { get; set; } /// /// The third-party API ID of the matching object. /// [JsonPropertyName("remote_id")] - public string? RemoteId { get; init; } + public string? RemoteId { get; set; } /// /// The datetime that this object was created by Merge. /// [JsonPropertyName("created_at")] - public DateTime? CreatedAt { get; init; } + public DateTime? CreatedAt { get; set; } /// /// The datetime that this object was modified by Merge. /// [JsonPropertyName("modified_at")] - public DateTime? ModifiedAt { get; init; } + public DateTime? ModifiedAt { get; set; } /// /// An internal note used by the business to clarify purpose of the transaction. /// [JsonPropertyName("memo")] - public string? Memo { get; init; } + public string? Memo { get; set; } /// /// The line item's unit price. /// [JsonPropertyName("unit_price")] - public string? UnitPrice { get; init; } + public string? UnitPrice { get; set; } /// /// The line item's quantity. /// [JsonPropertyName("quantity")] - public string? Quantity { get; init; } + public string? Quantity { get; set; } [JsonPropertyName("item")] [JsonConverter(typeof(OneOfSerializer>))] - public OneOf? Item { get; init; } + public OneOf? Item { get; set; } /// /// The line item's account. /// [JsonPropertyName("account")] - public string? Account { get; init; } + public string? Account { get; set; } /// /// The line's associated tracking category. /// [JsonPropertyName("tracking_category")] - public string? TrackingCategory { get; init; } + public string? TrackingCategory { get; set; } /// /// The line's associated tracking categories. /// [JsonPropertyName("tracking_categories")] - public IEnumerable TrackingCategories { get; init; } + public IEnumerable TrackingCategories { get; set; } = new List(); /// /// The line item's total. /// [JsonPropertyName("total_line_amount")] - public string? TotalLineAmount { get; init; } + public string? TotalLineAmount { get; set; } [JsonPropertyName("tax_rate")] - public string? TaxRate { get; init; } + public string? TaxRate { get; set; } /// /// The line item's currency. @@ -390,23 +389,23 @@ public class TransactionLineItem /// - `ZWL` - Zimbabwean Dollar (2009) /// [JsonPropertyName("currency")] - public CurrencyEnum? Currency { get; init; } + public CurrencyEnum? Currency { get; set; } /// /// The line item's exchange rate. /// [JsonPropertyName("exchange_rate")] - public string? ExchangeRate { get; init; } + public string? ExchangeRate { get; set; } /// /// The company the line belongs to. /// [JsonPropertyName("company")] - public string? Company { get; init; } + public string? Company { get; set; } /// /// Indicates whether or not this object has been deleted in the third party platform. /// [JsonPropertyName("remote_was_deleted")] - public bool? RemoteWasDeleted { get; init; } + public bool? RemoteWasDeleted { get; set; } } diff --git a/src/Merge.Client/Accounting/Types/ValidationProblemSource.cs b/src/Merge.Client/Accounting/Types/ValidationProblemSource.cs index d8a77e49..102f904c 100644 --- a/src/Merge.Client/Accounting/Types/ValidationProblemSource.cs +++ b/src/Merge.Client/Accounting/Types/ValidationProblemSource.cs @@ -4,8 +4,8 @@ namespace Merge.Client.Accounting; -public class ValidationProblemSource +public record ValidationProblemSource { [JsonPropertyName("pointer")] - public string Pointer { get; init; } + public required string Pointer { get; set; } } diff --git a/src/Merge.Client/Accounting/Types/VendorCredit.cs b/src/Merge.Client/Accounting/Types/VendorCredit.cs index 4a0c025c..5bdeefb7 100644 --- a/src/Merge.Client/Accounting/Types/VendorCredit.cs +++ b/src/Merge.Client/Accounting/Types/VendorCredit.cs @@ -1,5 +1,4 @@ using System.Text.Json.Serialization; -using Merge.Client.Accounting; using Merge.Client.Core; using OneOf; @@ -7,53 +6,53 @@ namespace Merge.Client.Accounting; -public class VendorCredit +public record VendorCredit { [JsonPropertyName("id")] - public string? Id { get; init; } + public string? Id { get; set; } /// /// The third-party API ID of the matching object. /// [JsonPropertyName("remote_id")] - public string? RemoteId { get; init; } + public string? RemoteId { get; set; } /// /// The datetime that this object was created by Merge. /// [JsonPropertyName("created_at")] - public DateTime? CreatedAt { get; init; } + public DateTime? CreatedAt { get; set; } /// /// The datetime that this object was modified by Merge. /// [JsonPropertyName("modified_at")] - public DateTime? ModifiedAt { get; init; } + public DateTime? ModifiedAt { get; set; } /// /// The vendor credit's number. /// [JsonPropertyName("number")] - public string? Number { get; init; } + public string? Number { get; set; } /// /// The vendor credit's transaction date. /// [JsonPropertyName("transaction_date")] - public DateTime? TransactionDate { get; init; } + public DateTime? TransactionDate { get; set; } /// /// The vendor that owes the gift or refund. /// [JsonPropertyName("vendor")] [JsonConverter(typeof(OneOfSerializer>))] - public OneOf? Vendor { get; init; } + public OneOf? Vendor { get; set; } /// /// The vendor credit's total amount. /// [JsonPropertyName("total_amount")] - public double? TotalAmount { get; init; } + public double? TotalAmount { get; set; } /// /// The vendor credit's currency. @@ -366,23 +365,23 @@ public class VendorCredit /// - `ZWL` - Zimbabwean Dollar (2009) /// [JsonPropertyName("currency")] - public CurrencyEnum? Currency { get; init; } + public CurrencyEnum? Currency { get; set; } /// /// The vendor credit's exchange rate. /// [JsonPropertyName("exchange_rate")] - public string? ExchangeRate { get; init; } + public string? ExchangeRate { get; set; } /// /// The company the vendor credit belongs to. /// [JsonPropertyName("company")] [JsonConverter(typeof(OneOfSerializer>))] - public OneOf? Company { get; init; } + public OneOf? Company { get; set; } [JsonPropertyName("lines")] - public IEnumerable? Lines { get; init; } + public IEnumerable? Lines { get; set; } [JsonPropertyName("tracking_categories")] [JsonConverter( @@ -391,24 +390,24 @@ public class VendorCredit OneOfSerializer> >) )] - public IEnumerable>? TrackingCategories { get; init; } + public IEnumerable>? TrackingCategories { get; set; } /// /// Indicates whether or not this object has been deleted in the third party platform. /// [JsonPropertyName("remote_was_deleted")] - public bool? RemoteWasDeleted { get; init; } + public bool? RemoteWasDeleted { get; set; } /// /// The accounting period that the VendorCredit was generated in. /// [JsonPropertyName("accounting_period")] [JsonConverter(typeof(OneOfSerializer>))] - public OneOf? AccountingPeriod { get; init; } + public OneOf? AccountingPeriod { get; set; } [JsonPropertyName("field_mappings")] - public Dictionary? FieldMappings { get; init; } + public Dictionary? FieldMappings { get; set; } [JsonPropertyName("remote_data")] - public IEnumerable? RemoteData { get; init; } + public IEnumerable? RemoteData { get; set; } } diff --git a/src/Merge.Client/Accounting/Types/VendorCreditLine.cs b/src/Merge.Client/Accounting/Types/VendorCreditLine.cs index 5ef87610..ed940397 100644 --- a/src/Merge.Client/Accounting/Types/VendorCreditLine.cs +++ b/src/Merge.Client/Accounting/Types/VendorCreditLine.cs @@ -1,5 +1,4 @@ using System.Text.Json.Serialization; -using Merge.Client.Accounting; using Merge.Client.Core; using OneOf; @@ -7,75 +6,75 @@ namespace Merge.Client.Accounting; -public class VendorCreditLine +public record VendorCreditLine { [JsonPropertyName("id")] - public string? Id { get; init; } + public string? Id { get; set; } /// /// The third-party API ID of the matching object. /// [JsonPropertyName("remote_id")] - public string? RemoteId { get; init; } + public string? RemoteId { get; set; } /// /// The datetime that this object was created by Merge. /// [JsonPropertyName("created_at")] - public DateTime? CreatedAt { get; init; } + public DateTime? CreatedAt { get; set; } /// /// The datetime that this object was modified by Merge. /// [JsonPropertyName("modified_at")] - public DateTime? ModifiedAt { get; init; } + public DateTime? ModifiedAt { get; set; } /// /// The full value of the credit. /// [JsonPropertyName("net_amount")] - public double? NetAmount { get; init; } + public double? NetAmount { get; set; } /// /// The line's associated tracking category. /// [JsonPropertyName("tracking_category")] - public string? TrackingCategory { get; init; } + public string? TrackingCategory { get; set; } /// /// The line's associated tracking categories. /// [JsonPropertyName("tracking_categories")] - public IEnumerable TrackingCategories { get; init; } + public IEnumerable TrackingCategories { get; set; } = new List(); /// /// The line's description. /// [JsonPropertyName("description")] - public string? Description { get; init; } + public string? Description { get; set; } /// /// The line's account. /// [JsonPropertyName("account")] [JsonConverter(typeof(OneOfSerializer>))] - public OneOf? Account { get; init; } + public OneOf? Account { get; set; } /// /// The company the line belongs to. /// [JsonPropertyName("company")] - public string? Company { get; init; } + public string? Company { get; set; } /// /// The vendor credit line item's exchange rate. /// [JsonPropertyName("exchange_rate")] - public string? ExchangeRate { get; init; } + public string? ExchangeRate { get; set; } /// /// Indicates whether or not this object has been deleted in the third party platform. /// [JsonPropertyName("remote_was_deleted")] - public bool? RemoteWasDeleted { get; init; } + public bool? RemoteWasDeleted { get; set; } } diff --git a/src/Merge.Client/Accounting/Types/WarningValidationProblem.cs b/src/Merge.Client/Accounting/Types/WarningValidationProblem.cs index 01b239a1..e915f612 100644 --- a/src/Merge.Client/Accounting/Types/WarningValidationProblem.cs +++ b/src/Merge.Client/Accounting/Types/WarningValidationProblem.cs @@ -1,21 +1,20 @@ using System.Text.Json.Serialization; -using Merge.Client.Accounting; #nullable enable namespace Merge.Client.Accounting; -public class WarningValidationProblem +public record WarningValidationProblem { [JsonPropertyName("source")] - public ValidationProblemSource? Source { get; init; } + public ValidationProblemSource? Source { get; set; } [JsonPropertyName("title")] - public string Title { get; init; } + public required string Title { get; set; } [JsonPropertyName("detail")] - public string Detail { get; init; } + public required string Detail { get; set; } [JsonPropertyName("problem_type")] - public string ProblemType { get; init; } + public required string ProblemType { get; set; } } diff --git a/src/Merge.Client/Accounting/Types/WebhookReceiver.cs b/src/Merge.Client/Accounting/Types/WebhookReceiver.cs index 1a7f1f9a..7c1e1687 100644 --- a/src/Merge.Client/Accounting/Types/WebhookReceiver.cs +++ b/src/Merge.Client/Accounting/Types/WebhookReceiver.cs @@ -4,14 +4,14 @@ namespace Merge.Client.Accounting; -public class WebhookReceiver +public record WebhookReceiver { [JsonPropertyName("event")] - public string Event { get; init; } + public required string Event { get; set; } [JsonPropertyName("is_active")] - public bool IsActive { get; init; } + public required bool IsActive { get; set; } [JsonPropertyName("key")] - public string? Key { get; init; } + public string? Key { get; set; } } diff --git a/src/Merge.Client/Accounting/VendorCredits/Requests/VendorCreditsListRequest.cs b/src/Merge.Client/Accounting/VendorCredits/Requests/VendorCreditsListRequest.cs index efe91adc..3e2aeabd 100644 --- a/src/Merge.Client/Accounting/VendorCredits/Requests/VendorCreditsListRequest.cs +++ b/src/Merge.Client/Accounting/VendorCredits/Requests/VendorCreditsListRequest.cs @@ -1,73 +1,69 @@ -using Merge.Client.Accounting; - -#nullable enable - namespace Merge.Client.Accounting; -public class VendorCreditsListRequest +public record VendorCreditsListRequest { /// /// If provided, will only return vendor credits for this company. /// - public string? CompanyId { get; init; } + public string? CompanyId { get; set; } /// /// If provided, will only return objects created after this datetime. /// - public DateTime? CreatedAfter { get; init; } + public DateTime? CreatedAfter { get; set; } /// /// If provided, will only return objects created before this datetime. /// - public DateTime? CreatedBefore { get; init; } + public DateTime? CreatedBefore { get; set; } /// /// The pagination cursor value. /// - public string? Cursor { get; init; } + public string? Cursor { get; set; } /// /// Which relations should be returned in expanded form. Multiple relation names should be comma separated without spaces. /// - public VendorCreditsListRequestExpand? Expand { get; init; } + public VendorCreditsListRequestExpand? Expand { get; set; } /// /// Whether to include data that was marked as deleted by third party webhooks. /// - public bool? IncludeDeletedData { get; init; } + public bool? IncludeDeletedData { get; set; } /// /// Whether to include the original data Merge fetched from the third-party to produce these models. /// - public bool? IncludeRemoteData { get; init; } + public bool? IncludeRemoteData { get; set; } /// /// If provided, only objects synced by Merge after this date time will be returned. /// - public DateTime? ModifiedAfter { get; init; } + public DateTime? ModifiedAfter { get; set; } /// /// If provided, only objects synced by Merge before this date time will be returned. /// - public DateTime? ModifiedBefore { get; init; } + public DateTime? ModifiedBefore { get; set; } /// /// Number of results to return per page. /// - public int? PageSize { get; init; } + public int? PageSize { get; set; } /// /// The API provider's ID for the given object. /// - public string? RemoteId { get; init; } + public string? RemoteId { get; set; } /// /// If provided, will only return objects created after this datetime. /// - public DateTime? TransactionDateAfter { get; init; } + public DateTime? TransactionDateAfter { get; set; } /// /// If provided, will only return objects created before this datetime. /// - public DateTime? TransactionDateBefore { get; init; } + public DateTime? TransactionDateBefore { get; set; } } diff --git a/src/Merge.Client/Accounting/VendorCredits/Requests/VendorCreditsRetrieveRequest.cs b/src/Merge.Client/Accounting/VendorCredits/Requests/VendorCreditsRetrieveRequest.cs index 2c15b880..ad480006 100644 --- a/src/Merge.Client/Accounting/VendorCredits/Requests/VendorCreditsRetrieveRequest.cs +++ b/src/Merge.Client/Accounting/VendorCredits/Requests/VendorCreditsRetrieveRequest.cs @@ -1,18 +1,14 @@ -using Merge.Client.Accounting; - -#nullable enable - namespace Merge.Client.Accounting; -public class VendorCreditsRetrieveRequest +public record VendorCreditsRetrieveRequest { /// /// Which relations should be returned in expanded form. Multiple relation names should be comma separated without spaces. /// - public VendorCreditsRetrieveRequestExpand? Expand { get; init; } + public VendorCreditsRetrieveRequestExpand? Expand { get; set; } /// /// Whether to include the original data Merge fetched from the third-party to produce these models. /// - public bool? IncludeRemoteData { get; init; } + public bool? IncludeRemoteData { get; set; } } diff --git a/src/Merge.Client/Accounting/VendorCredits/Types/VendorCreditsListRequestExpand.cs b/src/Merge.Client/Accounting/VendorCredits/Types/VendorCreditsListRequestExpand.cs index 31ccfb53..a86d717a 100644 --- a/src/Merge.Client/Accounting/VendorCredits/Types/VendorCreditsListRequestExpand.cs +++ b/src/Merge.Client/Accounting/VendorCredits/Types/VendorCreditsListRequestExpand.cs @@ -1,6 +1,5 @@ using System.Runtime.Serialization; using System.Text.Json.Serialization; -using Merge.Client.Accounting; using Merge.Client.Core; #nullable enable diff --git a/src/Merge.Client/Accounting/VendorCredits/Types/VendorCreditsRetrieveRequestExpand.cs b/src/Merge.Client/Accounting/VendorCredits/Types/VendorCreditsRetrieveRequestExpand.cs index f2d3c75e..2d69ddf4 100644 --- a/src/Merge.Client/Accounting/VendorCredits/Types/VendorCreditsRetrieveRequestExpand.cs +++ b/src/Merge.Client/Accounting/VendorCredits/Types/VendorCreditsRetrieveRequestExpand.cs @@ -1,6 +1,5 @@ using System.Runtime.Serialization; using System.Text.Json.Serialization; -using Merge.Client.Accounting; using Merge.Client.Core; #nullable enable diff --git a/src/Merge.Client/Accounting/VendorCredits/VendorCreditsClient.cs b/src/Merge.Client/Accounting/VendorCredits/VendorCreditsClient.cs index 377790c7..a3e11b8f 100644 --- a/src/Merge.Client/Accounting/VendorCredits/VendorCreditsClient.cs +++ b/src/Merge.Client/Accounting/VendorCredits/VendorCreditsClient.cs @@ -1,6 +1,6 @@ +using System.Net.Http; using System.Text.Json; -using Merge.Client; -using Merge.Client.Accounting; +using Merge.Client.Core; #nullable enable @@ -18,7 +18,10 @@ public VendorCreditsClient(RawClient client) /// /// Returns a list of `VendorCredit` objects. /// - public async Task ListAsync(VendorCreditsListRequest request) + public async Task ListAsync( + VendorCreditsListRequest request, + RequestOptions? options = null + ) { var _query = new Dictionary() { }; if (request.CompanyId != null) @@ -27,11 +30,13 @@ public async Task ListAsync(VendorCreditsListRequest } if (request.CreatedAfter != null) { - _query["created_after"] = request.CreatedAfter.Value.ToString("o0"); + _query["created_after"] = request.CreatedAfter.Value.ToString(Constants.DateTimeFormat); } if (request.CreatedBefore != null) { - _query["created_before"] = request.CreatedBefore.Value.ToString("o0"); + _query["created_before"] = request.CreatedBefore.Value.ToString( + Constants.DateTimeFormat + ); } if (request.Cursor != null) { @@ -51,11 +56,15 @@ public async Task ListAsync(VendorCreditsListRequest } if (request.ModifiedAfter != null) { - _query["modified_after"] = request.ModifiedAfter.Value.ToString("o0"); + _query["modified_after"] = request.ModifiedAfter.Value.ToString( + Constants.DateTimeFormat + ); } if (request.ModifiedBefore != null) { - _query["modified_before"] = request.ModifiedBefore.Value.ToString("o0"); + _query["modified_before"] = request.ModifiedBefore.Value.ToString( + Constants.DateTimeFormat + ); } if (request.PageSize != null) { @@ -67,32 +76,54 @@ public async Task ListAsync(VendorCreditsListRequest } if (request.TransactionDateAfter != null) { - _query["transaction_date_after"] = request.TransactionDateAfter.Value.ToString("o0"); + _query["transaction_date_after"] = request.TransactionDateAfter.Value.ToString( + Constants.DateTimeFormat + ); } if (request.TransactionDateBefore != null) { - _query["transaction_date_before"] = request.TransactionDateBefore.Value.ToString("o0"); + _query["transaction_date_before"] = request.TransactionDateBefore.Value.ToString( + Constants.DateTimeFormat + ); } var response = await _client.MakeRequestAsync( new RawClient.JsonApiRequest { + BaseUrl = _client.Options.BaseUrl, Method = HttpMethod.Get, Path = "accounting/v1/vendor-credits", - Query = _query + Query = _query, + Options = options } ); - string responseBody = await response.Raw.Content.ReadAsStringAsync(); - if (response.StatusCode >= 200 && response.StatusCode < 400) + var responseBody = await response.Raw.Content.ReadAsStringAsync(); + if (response.StatusCode is >= 200 and < 400) { - return JsonSerializer.Deserialize(responseBody); + try + { + return JsonUtils.Deserialize(responseBody)!; + } + catch (JsonException e) + { + throw new MergeException("Failed to deserialize response", e); + } } - throw new Exception(responseBody); + + throw new MergeApiException( + $"Error with status code {response.StatusCode}", + response.StatusCode, + JsonUtils.Deserialize(responseBody) + ); } /// /// Returns a `VendorCredit` object with the given `id`. /// - public async Task RetrieveAsync(string id, VendorCreditsRetrieveRequest request) + public async Task RetrieveAsync( + string id, + VendorCreditsRetrieveRequest request, + RequestOptions? options = null + ) { var _query = new Dictionary() { }; if (request.Expand != null) @@ -106,16 +137,30 @@ public async Task RetrieveAsync(string id, VendorCreditsRetrieveRe var response = await _client.MakeRequestAsync( new RawClient.JsonApiRequest { + BaseUrl = _client.Options.BaseUrl, Method = HttpMethod.Get, Path = $"accounting/v1/vendor-credits/{id}", - Query = _query + Query = _query, + Options = options } ); - string responseBody = await response.Raw.Content.ReadAsStringAsync(); - if (response.StatusCode >= 200 && response.StatusCode < 400) + var responseBody = await response.Raw.Content.ReadAsStringAsync(); + if (response.StatusCode is >= 200 and < 400) { - return JsonSerializer.Deserialize(responseBody); + try + { + return JsonUtils.Deserialize(responseBody)!; + } + catch (JsonException e) + { + throw new MergeException("Failed to deserialize response", e); + } } - throw new Exception(responseBody); + + throw new MergeApiException( + $"Error with status code {response.StatusCode}", + response.StatusCode, + JsonUtils.Deserialize(responseBody) + ); } } diff --git a/src/Merge.Client/Accounting/WebhookReceivers/Requests/WebhookReceiverRequest.cs b/src/Merge.Client/Accounting/WebhookReceivers/Requests/WebhookReceiverRequest.cs index 8b9aafc6..2f68372f 100644 --- a/src/Merge.Client/Accounting/WebhookReceivers/Requests/WebhookReceiverRequest.cs +++ b/src/Merge.Client/Accounting/WebhookReceivers/Requests/WebhookReceiverRequest.cs @@ -4,14 +4,14 @@ namespace Merge.Client.Accounting; -public class WebhookReceiverRequest +public record WebhookReceiverRequest { [JsonPropertyName("event")] - public string Event { get; init; } + public required string Event { get; set; } [JsonPropertyName("is_active")] - public bool IsActive { get; init; } + public required bool IsActive { get; set; } [JsonPropertyName("key")] - public string? Key { get; init; } + public string? Key { get; set; } } diff --git a/src/Merge.Client/Accounting/WebhookReceivers/WebhookReceiversClient.cs b/src/Merge.Client/Accounting/WebhookReceivers/WebhookReceiversClient.cs index f0980ce4..bd872177 100644 --- a/src/Merge.Client/Accounting/WebhookReceivers/WebhookReceiversClient.cs +++ b/src/Merge.Client/Accounting/WebhookReceivers/WebhookReceiversClient.cs @@ -1,6 +1,6 @@ +using System.Net.Http; using System.Text.Json; -using Merge.Client; -using Merge.Client.Accounting; +using Merge.Client.Core; #nullable enable @@ -18,41 +18,72 @@ public WebhookReceiversClient(RawClient client) /// /// Returns a list of `WebhookReceiver` objects. /// - public async Task> ListAsync() + public async Task> ListAsync(RequestOptions? options = null) { var response = await _client.MakeRequestAsync( new RawClient.JsonApiRequest { + BaseUrl = _client.Options.BaseUrl, Method = HttpMethod.Get, - Path = "accounting/v1/webhook-receivers" + Path = "accounting/v1/webhook-receivers", + Options = options } ); - string responseBody = await response.Raw.Content.ReadAsStringAsync(); - if (response.StatusCode >= 200 && response.StatusCode < 400) + var responseBody = await response.Raw.Content.ReadAsStringAsync(); + if (response.StatusCode is >= 200 and < 400) { - return JsonSerializer.Deserialize>(responseBody); + try + { + return JsonUtils.Deserialize>(responseBody)!; + } + catch (JsonException e) + { + throw new MergeException("Failed to deserialize response", e); + } } - throw new Exception(responseBody); + + throw new MergeApiException( + $"Error with status code {response.StatusCode}", + response.StatusCode, + JsonUtils.Deserialize(responseBody) + ); } /// /// Creates a `WebhookReceiver` object with the given values. /// - public async Task CreateAsync(WebhookReceiverRequest request) + public async Task CreateAsync( + WebhookReceiverRequest request, + RequestOptions? options = null + ) { var response = await _client.MakeRequestAsync( new RawClient.JsonApiRequest { + BaseUrl = _client.Options.BaseUrl, Method = HttpMethod.Post, Path = "accounting/v1/webhook-receivers", - Body = request + Body = request, + Options = options } ); - string responseBody = await response.Raw.Content.ReadAsStringAsync(); - if (response.StatusCode >= 200 && response.StatusCode < 400) + var responseBody = await response.Raw.Content.ReadAsStringAsync(); + if (response.StatusCode is >= 200 and < 400) { - return JsonSerializer.Deserialize(responseBody); + try + { + return JsonUtils.Deserialize(responseBody)!; + } + catch (JsonException e) + { + throw new MergeException("Failed to deserialize response", e); + } } - throw new Exception(responseBody); + + throw new MergeApiException( + $"Error with status code {response.StatusCode}", + response.StatusCode, + JsonUtils.Deserialize(responseBody) + ); } } diff --git a/src/Merge.Client/Ats/AccountDetails/AccountDetailsClient.cs b/src/Merge.Client/Ats/AccountDetails/AccountDetailsClient.cs index 558bcd8b..d82fd4dc 100644 --- a/src/Merge.Client/Ats/AccountDetails/AccountDetailsClient.cs +++ b/src/Merge.Client/Ats/AccountDetails/AccountDetailsClient.cs @@ -1,6 +1,6 @@ +using System.Net.Http; using System.Text.Json; -using Merge.Client; -using Merge.Client.Ats; +using Merge.Client.Core; #nullable enable @@ -18,20 +18,34 @@ public AccountDetailsClient(RawClient client) /// /// Get details for a linked account. /// - public async Task RetrieveAsync() + public async Task RetrieveAsync(RequestOptions? options = null) { var response = await _client.MakeRequestAsync( new RawClient.JsonApiRequest { + BaseUrl = _client.Options.BaseUrl, Method = HttpMethod.Get, - Path = "ats/v1/account-details" + Path = "ats/v1/account-details", + Options = options } ); - string responseBody = await response.Raw.Content.ReadAsStringAsync(); - if (response.StatusCode >= 200 && response.StatusCode < 400) + var responseBody = await response.Raw.Content.ReadAsStringAsync(); + if (response.StatusCode is >= 200 and < 400) { - return JsonSerializer.Deserialize(responseBody); + try + { + return JsonUtils.Deserialize(responseBody)!; + } + catch (JsonException e) + { + throw new MergeException("Failed to deserialize response", e); + } } - throw new Exception(responseBody); + + throw new MergeApiException( + $"Error with status code {response.StatusCode}", + response.StatusCode, + JsonUtils.Deserialize(responseBody) + ); } } diff --git a/src/Merge.Client/Ats/AccountToken/AccountTokenClient.cs b/src/Merge.Client/Ats/AccountToken/AccountTokenClient.cs index d5c9fb4f..4655f2fd 100644 --- a/src/Merge.Client/Ats/AccountToken/AccountTokenClient.cs +++ b/src/Merge.Client/Ats/AccountToken/AccountTokenClient.cs @@ -1,6 +1,6 @@ +using System.Net.Http; using System.Text.Json; -using Merge.Client; -using Merge.Client.Ats; +using Merge.Client.Core; #nullable enable @@ -18,20 +18,37 @@ public AccountTokenClient(RawClient client) /// /// Returns the account token for the end user with the provided public token. /// - public async Task RetrieveAsync(string publicToken) + public async Task RetrieveAsync( + string publicToken, + RequestOptions? options = null + ) { var response = await _client.MakeRequestAsync( new RawClient.JsonApiRequest { + BaseUrl = _client.Options.BaseUrl, Method = HttpMethod.Get, - Path = $"ats/v1/account-token/{publicToken}" + Path = $"ats/v1/account-token/{publicToken}", + Options = options } ); - string responseBody = await response.Raw.Content.ReadAsStringAsync(); - if (response.StatusCode >= 200 && response.StatusCode < 400) + var responseBody = await response.Raw.Content.ReadAsStringAsync(); + if (response.StatusCode is >= 200 and < 400) { - return JsonSerializer.Deserialize(responseBody); + try + { + return JsonUtils.Deserialize(responseBody)!; + } + catch (JsonException e) + { + throw new MergeException("Failed to deserialize response", e); + } } - throw new Exception(responseBody); + + throw new MergeApiException( + $"Error with status code {response.StatusCode}", + response.StatusCode, + JsonUtils.Deserialize(responseBody) + ); } } diff --git a/src/Merge.Client/Ats/Activities/ActivitiesClient.cs b/src/Merge.Client/Ats/Activities/ActivitiesClient.cs index 806e125d..0e03b26e 100644 --- a/src/Merge.Client/Ats/Activities/ActivitiesClient.cs +++ b/src/Merge.Client/Ats/Activities/ActivitiesClient.cs @@ -1,6 +1,6 @@ +using System.Net.Http; using System.Text.Json; -using Merge.Client; -using Merge.Client.Ats; +using Merge.Client.Core; #nullable enable @@ -18,16 +18,21 @@ public ActivitiesClient(RawClient client) /// /// Returns a list of `Activity` objects. /// - public async Task ListAsync(ActivitiesListRequest request) + public async Task ListAsync( + ActivitiesListRequest request, + RequestOptions? options = null + ) { var _query = new Dictionary() { }; if (request.CreatedAfter != null) { - _query["created_after"] = request.CreatedAfter.Value.ToString("o0"); + _query["created_after"] = request.CreatedAfter.Value.ToString(Constants.DateTimeFormat); } if (request.CreatedBefore != null) { - _query["created_before"] = request.CreatedBefore.Value.ToString("o0"); + _query["created_before"] = request.CreatedBefore.Value.ToString( + Constants.DateTimeFormat + ); } if (request.Cursor != null) { @@ -47,11 +52,15 @@ public async Task ListAsync(ActivitiesListRequest request } if (request.ModifiedAfter != null) { - _query["modified_after"] = request.ModifiedAfter.Value.ToString("o0"); + _query["modified_after"] = request.ModifiedAfter.Value.ToString( + Constants.DateTimeFormat + ); } if (request.ModifiedBefore != null) { - _query["modified_before"] = request.ModifiedBefore.Value.ToString("o0"); + _query["modified_before"] = request.ModifiedBefore.Value.ToString( + Constants.DateTimeFormat + ); } if (request.PageSize != null) { @@ -76,23 +85,40 @@ public async Task ListAsync(ActivitiesListRequest request var response = await _client.MakeRequestAsync( new RawClient.JsonApiRequest { + BaseUrl = _client.Options.BaseUrl, Method = HttpMethod.Get, Path = "ats/v1/activities", - Query = _query + Query = _query, + Options = options } ); - string responseBody = await response.Raw.Content.ReadAsStringAsync(); - if (response.StatusCode >= 200 && response.StatusCode < 400) + var responseBody = await response.Raw.Content.ReadAsStringAsync(); + if (response.StatusCode is >= 200 and < 400) { - return JsonSerializer.Deserialize(responseBody); + try + { + return JsonUtils.Deserialize(responseBody)!; + } + catch (JsonException e) + { + throw new MergeException("Failed to deserialize response", e); + } } - throw new Exception(responseBody); + + throw new MergeApiException( + $"Error with status code {response.StatusCode}", + response.StatusCode, + JsonUtils.Deserialize(responseBody) + ); } /// /// Creates an `Activity` object with the given values. /// - public async Task CreateAsync(ActivityEndpointRequest request) + public async Task CreateAsync( + ActivityEndpointRequest request, + RequestOptions? options = null + ) { var _query = new Dictionary() { }; if (request.IsDebugMode != null) @@ -106,23 +132,41 @@ public async Task CreateAsync(ActivityEndpointRequest request) var response = await _client.MakeRequestAsync( new RawClient.JsonApiRequest { + BaseUrl = _client.Options.BaseUrl, Method = HttpMethod.Post, Path = "ats/v1/activities", - Query = _query + Query = _query, + Options = options } ); - string responseBody = await response.Raw.Content.ReadAsStringAsync(); - if (response.StatusCode >= 200 && response.StatusCode < 400) + var responseBody = await response.Raw.Content.ReadAsStringAsync(); + if (response.StatusCode is >= 200 and < 400) { - return JsonSerializer.Deserialize(responseBody); + try + { + return JsonUtils.Deserialize(responseBody)!; + } + catch (JsonException e) + { + throw new MergeException("Failed to deserialize response", e); + } } - throw new Exception(responseBody); + + throw new MergeApiException( + $"Error with status code {response.StatusCode}", + response.StatusCode, + JsonUtils.Deserialize(responseBody) + ); } /// /// Returns an `Activity` object with the given `id`. /// - public async Task RetrieveAsync(string id, ActivitiesRetrieveRequest request) + public async Task RetrieveAsync( + string id, + ActivitiesRetrieveRequest request, + RequestOptions? options = null + ) { var _query = new Dictionary() { }; if (request.Expand != null) @@ -144,36 +188,64 @@ public async Task RetrieveAsync(string id, ActivitiesRetrieveRequest r var response = await _client.MakeRequestAsync( new RawClient.JsonApiRequest { + BaseUrl = _client.Options.BaseUrl, Method = HttpMethod.Get, Path = $"ats/v1/activities/{id}", - Query = _query + Query = _query, + Options = options } ); - string responseBody = await response.Raw.Content.ReadAsStringAsync(); - if (response.StatusCode >= 200 && response.StatusCode < 400) + var responseBody = await response.Raw.Content.ReadAsStringAsync(); + if (response.StatusCode is >= 200 and < 400) { - return JsonSerializer.Deserialize(responseBody); + try + { + return JsonUtils.Deserialize(responseBody)!; + } + catch (JsonException e) + { + throw new MergeException("Failed to deserialize response", e); + } } - throw new Exception(responseBody); + + throw new MergeApiException( + $"Error with status code {response.StatusCode}", + response.StatusCode, + JsonUtils.Deserialize(responseBody) + ); } /// /// Returns metadata for `Activity` POSTs. /// - public async Task MetaPostRetrieveAsync() + public async Task MetaPostRetrieveAsync(RequestOptions? options = null) { var response = await _client.MakeRequestAsync( new RawClient.JsonApiRequest { + BaseUrl = _client.Options.BaseUrl, Method = HttpMethod.Get, - Path = "ats/v1/activities/meta/post" + Path = "ats/v1/activities/meta/post", + Options = options } ); - string responseBody = await response.Raw.Content.ReadAsStringAsync(); - if (response.StatusCode >= 200 && response.StatusCode < 400) + var responseBody = await response.Raw.Content.ReadAsStringAsync(); + if (response.StatusCode is >= 200 and < 400) { - return JsonSerializer.Deserialize(responseBody); + try + { + return JsonUtils.Deserialize(responseBody)!; + } + catch (JsonException e) + { + throw new MergeException("Failed to deserialize response", e); + } } - throw new Exception(responseBody); + + throw new MergeApiException( + $"Error with status code {response.StatusCode}", + response.StatusCode, + JsonUtils.Deserialize(responseBody) + ); } } diff --git a/src/Merge.Client/Ats/Activities/Requests/ActivitiesListRequest.cs b/src/Merge.Client/Ats/Activities/Requests/ActivitiesListRequest.cs index 5c7c6052..022310b3 100644 --- a/src/Merge.Client/Ats/Activities/Requests/ActivitiesListRequest.cs +++ b/src/Merge.Client/Ats/Activities/Requests/ActivitiesListRequest.cs @@ -1,73 +1,69 @@ -using Merge.Client.Ats; - -#nullable enable - namespace Merge.Client.Ats; -public class ActivitiesListRequest +public record ActivitiesListRequest { /// /// If provided, will only return objects created after this datetime. /// - public DateTime? CreatedAfter { get; init; } + public DateTime? CreatedAfter { get; set; } /// /// If provided, will only return objects created before this datetime. /// - public DateTime? CreatedBefore { get; init; } + public DateTime? CreatedBefore { get; set; } /// /// The pagination cursor value. /// - public string? Cursor { get; init; } + public string? Cursor { get; set; } /// /// Which relations should be returned in expanded form. Multiple relation names should be comma separated without spaces. /// - public string? Expand { get; init; } + public string? Expand { get; set; } /// /// Whether to include data that was marked as deleted by third party webhooks. /// - public bool? IncludeDeletedData { get; init; } + public bool? IncludeDeletedData { get; set; } /// /// Whether to include the original data Merge fetched from the third-party to produce these models. /// - public bool? IncludeRemoteData { get; init; } + public bool? IncludeRemoteData { get; set; } /// /// If provided, only objects synced by Merge after this date time will be returned. /// - public DateTime? ModifiedAfter { get; init; } + public DateTime? ModifiedAfter { get; set; } /// /// If provided, only objects synced by Merge before this date time will be returned. /// - public DateTime? ModifiedBefore { get; init; } + public DateTime? ModifiedBefore { get; set; } /// /// Number of results to return per page. /// - public int? PageSize { get; init; } + public int? PageSize { get; set; } /// /// Deprecated. Use show_enum_origins. /// - public ActivitiesListRequestRemoteFields? RemoteFields { get; init; } + public ActivitiesListRequestRemoteFields? RemoteFields { get; set; } /// /// The API provider's ID for the given object. /// - public string? RemoteId { get; init; } + public string? RemoteId { get; set; } /// /// A comma separated list of enum field names for which you'd like the original values to be returned, instead of Merge's normalized enum values. [Learn more](https://help.merge.dev/en/articles/8950958-show_enum_origins-query-parameter) /// - public ActivitiesListRequestShowEnumOrigins? ShowEnumOrigins { get; init; } + public ActivitiesListRequestShowEnumOrigins? ShowEnumOrigins { get; set; } /// /// If provided, will only return activities done by this user. /// - public string? UserId { get; init; } + public string? UserId { get; set; } } diff --git a/src/Merge.Client/Ats/Activities/Requests/ActivitiesRetrieveRequest.cs b/src/Merge.Client/Ats/Activities/Requests/ActivitiesRetrieveRequest.cs index f5439850..1564e346 100644 --- a/src/Merge.Client/Ats/Activities/Requests/ActivitiesRetrieveRequest.cs +++ b/src/Merge.Client/Ats/Activities/Requests/ActivitiesRetrieveRequest.cs @@ -1,28 +1,24 @@ -using Merge.Client.Ats; - -#nullable enable - namespace Merge.Client.Ats; -public class ActivitiesRetrieveRequest +public record ActivitiesRetrieveRequest { /// /// Which relations should be returned in expanded form. Multiple relation names should be comma separated without spaces. /// - public string? Expand { get; init; } + public string? Expand { get; set; } /// /// Whether to include the original data Merge fetched from the third-party to produce these models. /// - public bool? IncludeRemoteData { get; init; } + public bool? IncludeRemoteData { get; set; } /// /// Deprecated. Use show_enum_origins. /// - public ActivitiesRetrieveRequestRemoteFields? RemoteFields { get; init; } + public ActivitiesRetrieveRequestRemoteFields? RemoteFields { get; set; } /// /// A comma separated list of enum field names for which you'd like the original values to be returned, instead of Merge's normalized enum values. [Learn more](https://help.merge.dev/en/articles/8950958-show_enum_origins-query-parameter) /// - public ActivitiesRetrieveRequestShowEnumOrigins? ShowEnumOrigins { get; init; } + public ActivitiesRetrieveRequestShowEnumOrigins? ShowEnumOrigins { get; set; } } diff --git a/src/Merge.Client/Ats/Activities/Requests/ActivityEndpointRequest.cs b/src/Merge.Client/Ats/Activities/Requests/ActivityEndpointRequest.cs index dc622864..5d172d62 100644 --- a/src/Merge.Client/Ats/Activities/Requests/ActivityEndpointRequest.cs +++ b/src/Merge.Client/Ats/Activities/Requests/ActivityEndpointRequest.cs @@ -1,22 +1,18 @@ -using Merge.Client.Ats; - -#nullable enable - namespace Merge.Client.Ats; -public class ActivityEndpointRequest +public record ActivityEndpointRequest { /// /// Whether to include debug fields (such as log file links) in the response. /// - public bool? IsDebugMode { get; init; } + public bool? IsDebugMode { get; set; } /// /// Whether or not third-party updates should be run asynchronously. /// - public bool? RunAsync { get; init; } + public bool? RunAsync { get; set; } - public ActivityRequest Model { get; init; } + public required ActivityRequest Model { get; set; } - public string RemoteUserId { get; init; } + public required string RemoteUserId { get; set; } } diff --git a/src/Merge.Client/Ats/Activities/Types/ActivitiesListRequestRemoteFields.cs b/src/Merge.Client/Ats/Activities/Types/ActivitiesListRequestRemoteFields.cs index ab68b771..da0d8c4a 100644 --- a/src/Merge.Client/Ats/Activities/Types/ActivitiesListRequestRemoteFields.cs +++ b/src/Merge.Client/Ats/Activities/Types/ActivitiesListRequestRemoteFields.cs @@ -1,6 +1,5 @@ using System.Runtime.Serialization; using System.Text.Json.Serialization; -using Merge.Client.Ats; using Merge.Client.Core; #nullable enable diff --git a/src/Merge.Client/Ats/Activities/Types/ActivitiesListRequestShowEnumOrigins.cs b/src/Merge.Client/Ats/Activities/Types/ActivitiesListRequestShowEnumOrigins.cs index d10dce7b..cad967dd 100644 --- a/src/Merge.Client/Ats/Activities/Types/ActivitiesListRequestShowEnumOrigins.cs +++ b/src/Merge.Client/Ats/Activities/Types/ActivitiesListRequestShowEnumOrigins.cs @@ -1,6 +1,5 @@ using System.Runtime.Serialization; using System.Text.Json.Serialization; -using Merge.Client.Ats; using Merge.Client.Core; #nullable enable diff --git a/src/Merge.Client/Ats/Activities/Types/ActivitiesRetrieveRequestRemoteFields.cs b/src/Merge.Client/Ats/Activities/Types/ActivitiesRetrieveRequestRemoteFields.cs index c50b7e38..38e819c4 100644 --- a/src/Merge.Client/Ats/Activities/Types/ActivitiesRetrieveRequestRemoteFields.cs +++ b/src/Merge.Client/Ats/Activities/Types/ActivitiesRetrieveRequestRemoteFields.cs @@ -1,6 +1,5 @@ using System.Runtime.Serialization; using System.Text.Json.Serialization; -using Merge.Client.Ats; using Merge.Client.Core; #nullable enable diff --git a/src/Merge.Client/Ats/Activities/Types/ActivitiesRetrieveRequestShowEnumOrigins.cs b/src/Merge.Client/Ats/Activities/Types/ActivitiesRetrieveRequestShowEnumOrigins.cs index e51d15e2..df3603a3 100644 --- a/src/Merge.Client/Ats/Activities/Types/ActivitiesRetrieveRequestShowEnumOrigins.cs +++ b/src/Merge.Client/Ats/Activities/Types/ActivitiesRetrieveRequestShowEnumOrigins.cs @@ -1,6 +1,5 @@ using System.Runtime.Serialization; using System.Text.Json.Serialization; -using Merge.Client.Ats; using Merge.Client.Core; #nullable enable diff --git a/src/Merge.Client/Ats/Applications/ApplicationsClient.cs b/src/Merge.Client/Ats/Applications/ApplicationsClient.cs index 65137382..03d7b214 100644 --- a/src/Merge.Client/Ats/Applications/ApplicationsClient.cs +++ b/src/Merge.Client/Ats/Applications/ApplicationsClient.cs @@ -1,6 +1,6 @@ +using System.Net.Http; using System.Text.Json; -using Merge.Client; -using Merge.Client.Ats; +using Merge.Client.Core; #nullable enable @@ -18,7 +18,10 @@ public ApplicationsClient(RawClient client) /// /// Returns a list of `Application` objects. /// - public async Task ListAsync(ApplicationsListRequest request) + public async Task ListAsync( + ApplicationsListRequest request, + RequestOptions? options = null + ) { var _query = new Dictionary() { }; if (request.CandidateId != null) @@ -27,11 +30,13 @@ public async Task ListAsync(ApplicationsListRequest re } if (request.CreatedAfter != null) { - _query["created_after"] = request.CreatedAfter.Value.ToString("o0"); + _query["created_after"] = request.CreatedAfter.Value.ToString(Constants.DateTimeFormat); } if (request.CreatedBefore != null) { - _query["created_before"] = request.CreatedBefore.Value.ToString("o0"); + _query["created_before"] = request.CreatedBefore.Value.ToString( + Constants.DateTimeFormat + ); } if (request.CreditedToId != null) { @@ -63,11 +68,15 @@ public async Task ListAsync(ApplicationsListRequest re } if (request.ModifiedAfter != null) { - _query["modified_after"] = request.ModifiedAfter.Value.ToString("o0"); + _query["modified_after"] = request.ModifiedAfter.Value.ToString( + Constants.DateTimeFormat + ); } if (request.ModifiedBefore != null) { - _query["modified_before"] = request.ModifiedBefore.Value.ToString("o0"); + _query["modified_before"] = request.ModifiedBefore.Value.ToString( + Constants.DateTimeFormat + ); } if (request.PageSize != null) { @@ -88,23 +97,40 @@ public async Task ListAsync(ApplicationsListRequest re var response = await _client.MakeRequestAsync( new RawClient.JsonApiRequest { + BaseUrl = _client.Options.BaseUrl, Method = HttpMethod.Get, Path = "ats/v1/applications", - Query = _query + Query = _query, + Options = options } ); - string responseBody = await response.Raw.Content.ReadAsStringAsync(); - if (response.StatusCode >= 200 && response.StatusCode < 400) + var responseBody = await response.Raw.Content.ReadAsStringAsync(); + if (response.StatusCode is >= 200 and < 400) { - return JsonSerializer.Deserialize(responseBody); + try + { + return JsonUtils.Deserialize(responseBody)!; + } + catch (JsonException e) + { + throw new MergeException("Failed to deserialize response", e); + } } - throw new Exception(responseBody); + + throw new MergeApiException( + $"Error with status code {response.StatusCode}", + response.StatusCode, + JsonUtils.Deserialize(responseBody) + ); } /// /// Creates an `Application` object with the given values. /// - public async Task CreateAsync(ApplicationEndpointRequest request) + public async Task CreateAsync( + ApplicationEndpointRequest request, + RequestOptions? options = null + ) { var _query = new Dictionary() { }; if (request.IsDebugMode != null) @@ -118,23 +144,41 @@ public async Task CreateAsync(ApplicationEndpointRequest re var response = await _client.MakeRequestAsync( new RawClient.JsonApiRequest { + BaseUrl = _client.Options.BaseUrl, Method = HttpMethod.Post, Path = "ats/v1/applications", - Query = _query + Query = _query, + Options = options } ); - string responseBody = await response.Raw.Content.ReadAsStringAsync(); - if (response.StatusCode >= 200 && response.StatusCode < 400) + var responseBody = await response.Raw.Content.ReadAsStringAsync(); + if (response.StatusCode is >= 200 and < 400) { - return JsonSerializer.Deserialize(responseBody); + try + { + return JsonUtils.Deserialize(responseBody)!; + } + catch (JsonException e) + { + throw new MergeException("Failed to deserialize response", e); + } } - throw new Exception(responseBody); + + throw new MergeApiException( + $"Error with status code {response.StatusCode}", + response.StatusCode, + JsonUtils.Deserialize(responseBody) + ); } /// /// Returns an `Application` object with the given `id`. /// - public async Task RetrieveAsync(string id, ApplicationsRetrieveRequest request) + public async Task RetrieveAsync( + string id, + ApplicationsRetrieveRequest request, + RequestOptions? options = null + ) { var _query = new Dictionary() { }; if (request.Expand != null) @@ -148,17 +192,31 @@ public async Task RetrieveAsync(string id, ApplicationsRetrieveRequ var response = await _client.MakeRequestAsync( new RawClient.JsonApiRequest { + BaseUrl = _client.Options.BaseUrl, Method = HttpMethod.Get, Path = $"ats/v1/applications/{id}", - Query = _query + Query = _query, + Options = options } ); - string responseBody = await response.Raw.Content.ReadAsStringAsync(); - if (response.StatusCode >= 200 && response.StatusCode < 400) + var responseBody = await response.Raw.Content.ReadAsStringAsync(); + if (response.StatusCode is >= 200 and < 400) { - return JsonSerializer.Deserialize(responseBody); + try + { + return JsonUtils.Deserialize(responseBody)!; + } + catch (JsonException e) + { + throw new MergeException("Failed to deserialize response", e); + } } - throw new Exception(responseBody); + + throw new MergeApiException( + $"Error with status code {response.StatusCode}", + response.StatusCode, + JsonUtils.Deserialize(responseBody) + ); } /// @@ -166,7 +224,8 @@ public async Task RetrieveAsync(string id, ApplicationsRetrieveRequ /// public async Task ChangeStageCreateAsync( string id, - UpdateApplicationStageRequest request + UpdateApplicationStageRequest request, + RequestOptions? options = null ) { var _query = new Dictionary() { }; @@ -181,24 +240,39 @@ UpdateApplicationStageRequest request var response = await _client.MakeRequestAsync( new RawClient.JsonApiRequest { + BaseUrl = _client.Options.BaseUrl, Method = HttpMethod.Post, Path = $"ats/v1/applications/{id}/change-stage", - Query = _query + Query = _query, + Options = options } ); - string responseBody = await response.Raw.Content.ReadAsStringAsync(); - if (response.StatusCode >= 200 && response.StatusCode < 400) + var responseBody = await response.Raw.Content.ReadAsStringAsync(); + if (response.StatusCode is >= 200 and < 400) { - return JsonSerializer.Deserialize(responseBody); + try + { + return JsonUtils.Deserialize(responseBody)!; + } + catch (JsonException e) + { + throw new MergeException("Failed to deserialize response", e); + } } - throw new Exception(responseBody); + + throw new MergeApiException( + $"Error with status code {response.StatusCode}", + response.StatusCode, + JsonUtils.Deserialize(responseBody) + ); } /// /// Returns metadata for `Application` POSTs. /// public async Task MetaPostRetrieveAsync( - ApplicationsMetaPostRetrieveRequest request + ApplicationsMetaPostRetrieveRequest request, + RequestOptions? options = null ) { var _query = new Dictionary() { }; @@ -209,16 +283,30 @@ ApplicationsMetaPostRetrieveRequest request var response = await _client.MakeRequestAsync( new RawClient.JsonApiRequest { + BaseUrl = _client.Options.BaseUrl, Method = HttpMethod.Get, Path = "ats/v1/applications/meta/post", - Query = _query + Query = _query, + Options = options } ); - string responseBody = await response.Raw.Content.ReadAsStringAsync(); - if (response.StatusCode >= 200 && response.StatusCode < 400) + var responseBody = await response.Raw.Content.ReadAsStringAsync(); + if (response.StatusCode is >= 200 and < 400) { - return JsonSerializer.Deserialize(responseBody); + try + { + return JsonUtils.Deserialize(responseBody)!; + } + catch (JsonException e) + { + throw new MergeException("Failed to deserialize response", e); + } } - throw new Exception(responseBody); + + throw new MergeApiException( + $"Error with status code {response.StatusCode}", + response.StatusCode, + JsonUtils.Deserialize(responseBody) + ); } } diff --git a/src/Merge.Client/Ats/Applications/Requests/ApplicationEndpointRequest.cs b/src/Merge.Client/Ats/Applications/Requests/ApplicationEndpointRequest.cs index 36a92f46..6997310c 100644 --- a/src/Merge.Client/Ats/Applications/Requests/ApplicationEndpointRequest.cs +++ b/src/Merge.Client/Ats/Applications/Requests/ApplicationEndpointRequest.cs @@ -1,22 +1,18 @@ -using Merge.Client.Ats; - -#nullable enable - namespace Merge.Client.Ats; -public class ApplicationEndpointRequest +public record ApplicationEndpointRequest { /// /// Whether to include debug fields (such as log file links) in the response. /// - public bool? IsDebugMode { get; init; } + public bool? IsDebugMode { get; set; } /// /// Whether or not third-party updates should be run asynchronously. /// - public bool? RunAsync { get; init; } + public bool? RunAsync { get; set; } - public ApplicationRequest Model { get; init; } + public required ApplicationRequest Model { get; set; } - public string RemoteUserId { get; init; } + public required string RemoteUserId { get; set; } } diff --git a/src/Merge.Client/Ats/Applications/Requests/ApplicationsListRequest.cs b/src/Merge.Client/Ats/Applications/Requests/ApplicationsListRequest.cs index 00463da3..b3d77628 100644 --- a/src/Merge.Client/Ats/Applications/Requests/ApplicationsListRequest.cs +++ b/src/Merge.Client/Ats/Applications/Requests/ApplicationsListRequest.cs @@ -1,88 +1,84 @@ -using Merge.Client.Ats; - -#nullable enable - namespace Merge.Client.Ats; -public class ApplicationsListRequest +public record ApplicationsListRequest { /// /// If provided, will only return applications for this candidate. /// - public string? CandidateId { get; init; } + public string? CandidateId { get; set; } /// /// If provided, will only return objects created after this datetime. /// - public DateTime? CreatedAfter { get; init; } + public DateTime? CreatedAfter { get; set; } /// /// If provided, will only return objects created before this datetime. /// - public DateTime? CreatedBefore { get; init; } + public DateTime? CreatedBefore { get; set; } /// /// If provided, will only return applications credited to this user. /// - public string? CreditedToId { get; init; } + public string? CreditedToId { get; set; } /// /// If provided, will only return applications at this interview stage. /// - public string? CurrentStageId { get; init; } + public string? CurrentStageId { get; set; } /// /// The pagination cursor value. /// - public string? Cursor { get; init; } + public string? Cursor { get; set; } /// /// Which relations should be returned in expanded form. Multiple relation names should be comma separated without spaces. /// - public ApplicationsListRequestExpand? Expand { get; init; } + public ApplicationsListRequestExpand? Expand { get; set; } /// /// Whether to include data that was marked as deleted by third party webhooks. /// - public bool? IncludeDeletedData { get; init; } + public bool? IncludeDeletedData { get; set; } /// /// Whether to include the original data Merge fetched from the third-party to produce these models. /// - public bool? IncludeRemoteData { get; init; } + public bool? IncludeRemoteData { get; set; } /// /// If provided, will only return applications for this job. /// - public string? JobId { get; init; } + public string? JobId { get; set; } /// /// If provided, only objects synced by Merge after this date time will be returned. /// - public DateTime? ModifiedAfter { get; init; } + public DateTime? ModifiedAfter { get; set; } /// /// If provided, only objects synced by Merge before this date time will be returned. /// - public DateTime? ModifiedBefore { get; init; } + public DateTime? ModifiedBefore { get; set; } /// /// Number of results to return per page. /// - public int? PageSize { get; init; } + public int? PageSize { get; set; } /// /// If provided, will only return applications with this reject reason. /// - public string? RejectReasonId { get; init; } + public string? RejectReasonId { get; set; } /// /// The API provider's ID for the given object. /// - public string? RemoteId { get; init; } + public string? RemoteId { get; set; } /// /// If provided, will only return applications with this source. /// - public string? Source { get; init; } + public string? Source { get; set; } } diff --git a/src/Merge.Client/Ats/Applications/Requests/ApplicationsMetaPostRetrieveRequest.cs b/src/Merge.Client/Ats/Applications/Requests/ApplicationsMetaPostRetrieveRequest.cs index 13a6bc07..f1557a32 100644 --- a/src/Merge.Client/Ats/Applications/Requests/ApplicationsMetaPostRetrieveRequest.cs +++ b/src/Merge.Client/Ats/Applications/Requests/ApplicationsMetaPostRetrieveRequest.cs @@ -1,9 +1,9 @@ namespace Merge.Client.Ats; -public class ApplicationsMetaPostRetrieveRequest +public record ApplicationsMetaPostRetrieveRequest { /// /// The template ID associated with the nested application in the request. /// - public string? ApplicationRemoteTemplateId { get; init; } + public string? ApplicationRemoteTemplateId { get; set; } } diff --git a/src/Merge.Client/Ats/Applications/Requests/ApplicationsRetrieveRequest.cs b/src/Merge.Client/Ats/Applications/Requests/ApplicationsRetrieveRequest.cs index c239c214..9de3ed7b 100644 --- a/src/Merge.Client/Ats/Applications/Requests/ApplicationsRetrieveRequest.cs +++ b/src/Merge.Client/Ats/Applications/Requests/ApplicationsRetrieveRequest.cs @@ -1,18 +1,14 @@ -using Merge.Client.Ats; - -#nullable enable - namespace Merge.Client.Ats; -public class ApplicationsRetrieveRequest +public record ApplicationsRetrieveRequest { /// /// Which relations should be returned in expanded form. Multiple relation names should be comma separated without spaces. /// - public ApplicationsRetrieveRequestExpand? Expand { get; init; } + public ApplicationsRetrieveRequestExpand? Expand { get; set; } /// /// Whether to include the original data Merge fetched from the third-party to produce these models. /// - public bool? IncludeRemoteData { get; init; } + public bool? IncludeRemoteData { get; set; } } diff --git a/src/Merge.Client/Ats/Applications/Requests/UpdateApplicationStageRequest.cs b/src/Merge.Client/Ats/Applications/Requests/UpdateApplicationStageRequest.cs index fa943677..25ff5f09 100644 --- a/src/Merge.Client/Ats/Applications/Requests/UpdateApplicationStageRequest.cs +++ b/src/Merge.Client/Ats/Applications/Requests/UpdateApplicationStageRequest.cs @@ -1,21 +1,21 @@ namespace Merge.Client.Ats; -public class UpdateApplicationStageRequest +public record UpdateApplicationStageRequest { /// /// Whether to include debug fields (such as log file links) in the response. /// - public bool? IsDebugMode { get; init; } + public bool? IsDebugMode { get; set; } /// /// Whether or not third-party updates should be run asynchronously. /// - public bool? RunAsync { get; init; } + public bool? RunAsync { get; set; } /// /// The interview stage to move the application to. /// - public string? JobInterviewStage { get; init; } + public string? JobInterviewStage { get; set; } - public string? RemoteUserId { get; init; } + public string? RemoteUserId { get; set; } } diff --git a/src/Merge.Client/Ats/Applications/Types/ApplicationsListRequestExpand.cs b/src/Merge.Client/Ats/Applications/Types/ApplicationsListRequestExpand.cs index 5cda6d90..4180d20a 100644 --- a/src/Merge.Client/Ats/Applications/Types/ApplicationsListRequestExpand.cs +++ b/src/Merge.Client/Ats/Applications/Types/ApplicationsListRequestExpand.cs @@ -1,6 +1,5 @@ using System.Runtime.Serialization; using System.Text.Json.Serialization; -using Merge.Client.Ats; using Merge.Client.Core; #nullable enable diff --git a/src/Merge.Client/Ats/Applications/Types/ApplicationsRetrieveRequestExpand.cs b/src/Merge.Client/Ats/Applications/Types/ApplicationsRetrieveRequestExpand.cs index a1986106..30f80c17 100644 --- a/src/Merge.Client/Ats/Applications/Types/ApplicationsRetrieveRequestExpand.cs +++ b/src/Merge.Client/Ats/Applications/Types/ApplicationsRetrieveRequestExpand.cs @@ -1,6 +1,5 @@ using System.Runtime.Serialization; using System.Text.Json.Serialization; -using Merge.Client.Ats; using Merge.Client.Core; #nullable enable diff --git a/src/Merge.Client/Ats/AsyncPassthrough/AsyncPassthroughClient.cs b/src/Merge.Client/Ats/AsyncPassthrough/AsyncPassthroughClient.cs index 47285c6f..b5a06134 100644 --- a/src/Merge.Client/Ats/AsyncPassthrough/AsyncPassthroughClient.cs +++ b/src/Merge.Client/Ats/AsyncPassthrough/AsyncPassthroughClient.cs @@ -1,6 +1,6 @@ +using System.Net.Http; using System.Text.Json; -using Merge.Client; -using Merge.Client.Ats; +using Merge.Client.Core; #nullable enable @@ -18,41 +18,75 @@ public AsyncPassthroughClient(RawClient client) /// /// Asynchronously pull data from an endpoint not currently supported by Merge. /// - public async Task CreateAsync(DataPassthroughRequest request) + public async Task CreateAsync( + DataPassthroughRequest request, + RequestOptions? options = null + ) { var response = await _client.MakeRequestAsync( new RawClient.JsonApiRequest { + BaseUrl = _client.Options.BaseUrl, Method = HttpMethod.Post, Path = "ats/v1/async-passthrough", - Body = request + Body = request, + Options = options } ); - string responseBody = await response.Raw.Content.ReadAsStringAsync(); - if (response.StatusCode >= 200 && response.StatusCode < 400) + var responseBody = await response.Raw.Content.ReadAsStringAsync(); + if (response.StatusCode is >= 200 and < 400) { - return JsonSerializer.Deserialize(responseBody); + try + { + return JsonUtils.Deserialize(responseBody)!; + } + catch (JsonException e) + { + throw new MergeException("Failed to deserialize response", e); + } } - throw new Exception(responseBody); + + throw new MergeApiException( + $"Error with status code {response.StatusCode}", + response.StatusCode, + JsonUtils.Deserialize(responseBody) + ); } /// /// Retrieves data from earlier async-passthrough POST request /// - public async Task RetrieveAsync(string asyncPassthroughReceiptId) + public async Task RetrieveAsync( + string asyncPassthroughReceiptId, + RequestOptions? options = null + ) { var response = await _client.MakeRequestAsync( new RawClient.JsonApiRequest { + BaseUrl = _client.Options.BaseUrl, Method = HttpMethod.Get, - Path = $"ats/v1/async-passthrough/{asyncPassthroughReceiptId}" + Path = $"ats/v1/async-passthrough/{asyncPassthroughReceiptId}", + Options = options } ); - string responseBody = await response.Raw.Content.ReadAsStringAsync(); - if (response.StatusCode >= 200 && response.StatusCode < 400) + var responseBody = await response.Raw.Content.ReadAsStringAsync(); + if (response.StatusCode is >= 200 and < 400) { - return JsonSerializer.Deserialize(responseBody); + try + { + return JsonUtils.Deserialize(responseBody)!; + } + catch (JsonException e) + { + throw new MergeException("Failed to deserialize response", e); + } } - throw new Exception(responseBody); + + throw new MergeApiException( + $"Error with status code {response.StatusCode}", + response.StatusCode, + JsonUtils.Deserialize(responseBody) + ); } } diff --git a/src/Merge.Client/Ats/AtsClient.cs b/src/Merge.Client/Ats/AtsClient.cs index b174e3da..4964b9f7 100644 --- a/src/Merge.Client/Ats/AtsClient.cs +++ b/src/Merge.Client/Ats/AtsClient.cs @@ -1,5 +1,4 @@ -using Merge.Client; -using Merge.Client.Ats; +using Merge.Client.Core; #nullable enable diff --git a/src/Merge.Client/Ats/Attachments/AttachmentsClient.cs b/src/Merge.Client/Ats/Attachments/AttachmentsClient.cs index 5cc91c35..0d9ddeb9 100644 --- a/src/Merge.Client/Ats/Attachments/AttachmentsClient.cs +++ b/src/Merge.Client/Ats/Attachments/AttachmentsClient.cs @@ -1,6 +1,6 @@ +using System.Net.Http; using System.Text.Json; -using Merge.Client; -using Merge.Client.Ats; +using Merge.Client.Core; #nullable enable @@ -18,7 +18,10 @@ public AttachmentsClient(RawClient client) /// /// Returns a list of `Attachment` objects. /// - public async Task ListAsync(AttachmentsListRequest request) + public async Task ListAsync( + AttachmentsListRequest request, + RequestOptions? options = null + ) { var _query = new Dictionary() { }; if (request.CandidateId != null) @@ -27,11 +30,13 @@ public async Task ListAsync(AttachmentsListRequest requ } if (request.CreatedAfter != null) { - _query["created_after"] = request.CreatedAfter.Value.ToString("o0"); + _query["created_after"] = request.CreatedAfter.Value.ToString(Constants.DateTimeFormat); } if (request.CreatedBefore != null) { - _query["created_before"] = request.CreatedBefore.Value.ToString("o0"); + _query["created_before"] = request.CreatedBefore.Value.ToString( + Constants.DateTimeFormat + ); } if (request.Cursor != null) { @@ -51,11 +56,15 @@ public async Task ListAsync(AttachmentsListRequest requ } if (request.ModifiedAfter != null) { - _query["modified_after"] = request.ModifiedAfter.Value.ToString("o0"); + _query["modified_after"] = request.ModifiedAfter.Value.ToString( + Constants.DateTimeFormat + ); } if (request.ModifiedBefore != null) { - _query["modified_before"] = request.ModifiedBefore.Value.ToString("o0"); + _query["modified_before"] = request.ModifiedBefore.Value.ToString( + Constants.DateTimeFormat + ); } if (request.PageSize != null) { @@ -76,23 +85,40 @@ public async Task ListAsync(AttachmentsListRequest requ var response = await _client.MakeRequestAsync( new RawClient.JsonApiRequest { + BaseUrl = _client.Options.BaseUrl, Method = HttpMethod.Get, Path = "ats/v1/attachments", - Query = _query + Query = _query, + Options = options } ); - string responseBody = await response.Raw.Content.ReadAsStringAsync(); - if (response.StatusCode >= 200 && response.StatusCode < 400) + var responseBody = await response.Raw.Content.ReadAsStringAsync(); + if (response.StatusCode is >= 200 and < 400) { - return JsonSerializer.Deserialize(responseBody); + try + { + return JsonUtils.Deserialize(responseBody)!; + } + catch (JsonException e) + { + throw new MergeException("Failed to deserialize response", e); + } } - throw new Exception(responseBody); + + throw new MergeApiException( + $"Error with status code {response.StatusCode}", + response.StatusCode, + JsonUtils.Deserialize(responseBody) + ); } /// /// Creates an `Attachment` object with the given values. /// - public async Task CreateAsync(AttachmentEndpointRequest request) + public async Task CreateAsync( + AttachmentEndpointRequest request, + RequestOptions? options = null + ) { var _query = new Dictionary() { }; if (request.IsDebugMode != null) @@ -106,23 +132,41 @@ public async Task CreateAsync(AttachmentEndpointRequest requ var response = await _client.MakeRequestAsync( new RawClient.JsonApiRequest { + BaseUrl = _client.Options.BaseUrl, Method = HttpMethod.Post, Path = "ats/v1/attachments", - Query = _query + Query = _query, + Options = options } ); - string responseBody = await response.Raw.Content.ReadAsStringAsync(); - if (response.StatusCode >= 200 && response.StatusCode < 400) + var responseBody = await response.Raw.Content.ReadAsStringAsync(); + if (response.StatusCode is >= 200 and < 400) { - return JsonSerializer.Deserialize(responseBody); + try + { + return JsonUtils.Deserialize(responseBody)!; + } + catch (JsonException e) + { + throw new MergeException("Failed to deserialize response", e); + } } - throw new Exception(responseBody); + + throw new MergeApiException( + $"Error with status code {response.StatusCode}", + response.StatusCode, + JsonUtils.Deserialize(responseBody) + ); } /// /// Returns an `Attachment` object with the given `id`. /// - public async Task RetrieveAsync(string id, AttachmentsRetrieveRequest request) + public async Task RetrieveAsync( + string id, + AttachmentsRetrieveRequest request, + RequestOptions? options = null + ) { var _query = new Dictionary() { }; if (request.Expand != null) @@ -144,36 +188,64 @@ public async Task RetrieveAsync(string id, AttachmentsRetrieveReques var response = await _client.MakeRequestAsync( new RawClient.JsonApiRequest { + BaseUrl = _client.Options.BaseUrl, Method = HttpMethod.Get, Path = $"ats/v1/attachments/{id}", - Query = _query + Query = _query, + Options = options } ); - string responseBody = await response.Raw.Content.ReadAsStringAsync(); - if (response.StatusCode >= 200 && response.StatusCode < 400) + var responseBody = await response.Raw.Content.ReadAsStringAsync(); + if (response.StatusCode is >= 200 and < 400) { - return JsonSerializer.Deserialize(responseBody); + try + { + return JsonUtils.Deserialize(responseBody)!; + } + catch (JsonException e) + { + throw new MergeException("Failed to deserialize response", e); + } } - throw new Exception(responseBody); + + throw new MergeApiException( + $"Error with status code {response.StatusCode}", + response.StatusCode, + JsonUtils.Deserialize(responseBody) + ); } /// /// Returns metadata for `Attachment` POSTs. /// - public async Task MetaPostRetrieveAsync() + public async Task MetaPostRetrieveAsync(RequestOptions? options = null) { var response = await _client.MakeRequestAsync( new RawClient.JsonApiRequest { + BaseUrl = _client.Options.BaseUrl, Method = HttpMethod.Get, - Path = "ats/v1/attachments/meta/post" + Path = "ats/v1/attachments/meta/post", + Options = options } ); - string responseBody = await response.Raw.Content.ReadAsStringAsync(); - if (response.StatusCode >= 200 && response.StatusCode < 400) + var responseBody = await response.Raw.Content.ReadAsStringAsync(); + if (response.StatusCode is >= 200 and < 400) { - return JsonSerializer.Deserialize(responseBody); + try + { + return JsonUtils.Deserialize(responseBody)!; + } + catch (JsonException e) + { + throw new MergeException("Failed to deserialize response", e); + } } - throw new Exception(responseBody); + + throw new MergeApiException( + $"Error with status code {response.StatusCode}", + response.StatusCode, + JsonUtils.Deserialize(responseBody) + ); } } diff --git a/src/Merge.Client/Ats/Attachments/Requests/AttachmentEndpointRequest.cs b/src/Merge.Client/Ats/Attachments/Requests/AttachmentEndpointRequest.cs index dfee093a..3a442498 100644 --- a/src/Merge.Client/Ats/Attachments/Requests/AttachmentEndpointRequest.cs +++ b/src/Merge.Client/Ats/Attachments/Requests/AttachmentEndpointRequest.cs @@ -1,22 +1,18 @@ -using Merge.Client.Ats; - -#nullable enable - namespace Merge.Client.Ats; -public class AttachmentEndpointRequest +public record AttachmentEndpointRequest { /// /// Whether to include debug fields (such as log file links) in the response. /// - public bool? IsDebugMode { get; init; } + public bool? IsDebugMode { get; set; } /// /// Whether or not third-party updates should be run asynchronously. /// - public bool? RunAsync { get; init; } + public bool? RunAsync { get; set; } - public AttachmentRequest Model { get; init; } + public required AttachmentRequest Model { get; set; } - public string RemoteUserId { get; init; } + public required string RemoteUserId { get; set; } } diff --git a/src/Merge.Client/Ats/Attachments/Requests/AttachmentsListRequest.cs b/src/Merge.Client/Ats/Attachments/Requests/AttachmentsListRequest.cs index c20006bc..573f44f3 100644 --- a/src/Merge.Client/Ats/Attachments/Requests/AttachmentsListRequest.cs +++ b/src/Merge.Client/Ats/Attachments/Requests/AttachmentsListRequest.cs @@ -1,69 +1,69 @@ namespace Merge.Client.Ats; -public class AttachmentsListRequest +public record AttachmentsListRequest { /// /// If provided, will only return attachments for this candidate. /// - public string? CandidateId { get; init; } + public string? CandidateId { get; set; } /// /// If provided, will only return objects created after this datetime. /// - public DateTime? CreatedAfter { get; init; } + public DateTime? CreatedAfter { get; set; } /// /// If provided, will only return objects created before this datetime. /// - public DateTime? CreatedBefore { get; init; } + public DateTime? CreatedBefore { get; set; } /// /// The pagination cursor value. /// - public string? Cursor { get; init; } + public string? Cursor { get; set; } /// /// Which relations should be returned in expanded form. Multiple relation names should be comma separated without spaces. /// - public string? Expand { get; init; } + public string? Expand { get; set; } /// /// Whether to include data that was marked as deleted by third party webhooks. /// - public bool? IncludeDeletedData { get; init; } + public bool? IncludeDeletedData { get; set; } /// /// Whether to include the original data Merge fetched from the third-party to produce these models. /// - public bool? IncludeRemoteData { get; init; } + public bool? IncludeRemoteData { get; set; } /// /// If provided, only objects synced by Merge after this date time will be returned. /// - public DateTime? ModifiedAfter { get; init; } + public DateTime? ModifiedAfter { get; set; } /// /// If provided, only objects synced by Merge before this date time will be returned. /// - public DateTime? ModifiedBefore { get; init; } + public DateTime? ModifiedBefore { get; set; } /// /// Number of results to return per page. /// - public int? PageSize { get; init; } + public int? PageSize { get; set; } /// /// Deprecated. Use show_enum_origins. /// - public string? RemoteFields { get; init; } + public string? RemoteFields { get; set; } /// /// The API provider's ID for the given object. /// - public string? RemoteId { get; init; } + public string? RemoteId { get; set; } /// /// A comma separated list of enum field names for which you'd like the original values to be returned, instead of Merge's normalized enum values. [Learn more](https://help.merge.dev/en/articles/8950958-show_enum_origins-query-parameter) /// - public string? ShowEnumOrigins { get; init; } + public string? ShowEnumOrigins { get; set; } } diff --git a/src/Merge.Client/Ats/Attachments/Requests/AttachmentsRetrieveRequest.cs b/src/Merge.Client/Ats/Attachments/Requests/AttachmentsRetrieveRequest.cs index b19a43be..bbcac28c 100644 --- a/src/Merge.Client/Ats/Attachments/Requests/AttachmentsRetrieveRequest.cs +++ b/src/Merge.Client/Ats/Attachments/Requests/AttachmentsRetrieveRequest.cs @@ -1,24 +1,24 @@ namespace Merge.Client.Ats; -public class AttachmentsRetrieveRequest +public record AttachmentsRetrieveRequest { /// /// Which relations should be returned in expanded form. Multiple relation names should be comma separated without spaces. /// - public string? Expand { get; init; } + public string? Expand { get; set; } /// /// Whether to include the original data Merge fetched from the third-party to produce these models. /// - public bool? IncludeRemoteData { get; init; } + public bool? IncludeRemoteData { get; set; } /// /// Deprecated. Use show_enum_origins. /// - public string? RemoteFields { get; init; } + public string? RemoteFields { get; set; } /// /// A comma separated list of enum field names for which you'd like the original values to be returned, instead of Merge's normalized enum values. [Learn more](https://help.merge.dev/en/articles/8950958-show_enum_origins-query-parameter) /// - public string? ShowEnumOrigins { get; init; } + public string? ShowEnumOrigins { get; set; } } diff --git a/src/Merge.Client/Ats/AuditTrail/AuditTrailClient.cs b/src/Merge.Client/Ats/AuditTrail/AuditTrailClient.cs index 47022661..6bb44a65 100644 --- a/src/Merge.Client/Ats/AuditTrail/AuditTrailClient.cs +++ b/src/Merge.Client/Ats/AuditTrail/AuditTrailClient.cs @@ -1,6 +1,6 @@ +using System.Net.Http; using System.Text.Json; -using Merge.Client; -using Merge.Client.Ats; +using Merge.Client.Core; #nullable enable @@ -18,7 +18,10 @@ public AuditTrailClient(RawClient client) /// /// Gets a list of audit trail events. /// - public async Task ListAsync(AuditTrailListRequest request) + public async Task ListAsync( + AuditTrailListRequest request, + RequestOptions? options = null + ) { var _query = new Dictionary() { }; if (request.Cursor != null) @@ -48,16 +51,30 @@ public async Task ListAsync(AuditTrailListRequest re var response = await _client.MakeRequestAsync( new RawClient.JsonApiRequest { + BaseUrl = _client.Options.BaseUrl, Method = HttpMethod.Get, Path = "ats/v1/audit-trail", - Query = _query + Query = _query, + Options = options } ); - string responseBody = await response.Raw.Content.ReadAsStringAsync(); - if (response.StatusCode >= 200 && response.StatusCode < 400) + var responseBody = await response.Raw.Content.ReadAsStringAsync(); + if (response.StatusCode is >= 200 and < 400) { - return JsonSerializer.Deserialize(responseBody); + try + { + return JsonUtils.Deserialize(responseBody)!; + } + catch (JsonException e) + { + throw new MergeException("Failed to deserialize response", e); + } } - throw new Exception(responseBody); + + throw new MergeApiException( + $"Error with status code {response.StatusCode}", + response.StatusCode, + JsonUtils.Deserialize(responseBody) + ); } } diff --git a/src/Merge.Client/Ats/AuditTrail/Requests/AuditTrailListRequest.cs b/src/Merge.Client/Ats/AuditTrail/Requests/AuditTrailListRequest.cs index 033aacd3..c348665f 100644 --- a/src/Merge.Client/Ats/AuditTrail/Requests/AuditTrailListRequest.cs +++ b/src/Merge.Client/Ats/AuditTrail/Requests/AuditTrailListRequest.cs @@ -1,34 +1,34 @@ namespace Merge.Client.Ats; -public class AuditTrailListRequest +public record AuditTrailListRequest { /// /// The pagination cursor value. /// - public string? Cursor { get; init; } + public string? Cursor { get; set; } /// /// If included, will only include audit trail events that occurred before this time /// - public string? EndDate { get; init; } + public string? EndDate { get; set; } /// /// If included, will only include events with the given event type. Possible values include: `CREATED_REMOTE_PRODUCTION_API_KEY`, `DELETED_REMOTE_PRODUCTION_API_KEY`, `CREATED_TEST_API_KEY`, `DELETED_TEST_API_KEY`, `REGENERATED_PRODUCTION_API_KEY`, `INVITED_USER`, `TWO_FACTOR_AUTH_ENABLED`, `TWO_FACTOR_AUTH_DISABLED`, `DELETED_LINKED_ACCOUNT`, `CREATED_DESTINATION`, `DELETED_DESTINATION`, `CHANGED_DESTINATION`, `CHANGED_SCOPES`, `CHANGED_PERSONAL_INFORMATION`, `CHANGED_ORGANIZATION_SETTINGS`, `ENABLED_INTEGRATION`, `DISABLED_INTEGRATION`, `ENABLED_CATEGORY`, `DISABLED_CATEGORY`, `CHANGED_PASSWORD`, `RESET_PASSWORD`, `ENABLED_REDACT_UNMAPPED_DATA_FOR_ORGANIZATION`, `ENABLED_REDACT_UNMAPPED_DATA_FOR_LINKED_ACCOUNT`, `DISABLED_REDACT_UNMAPPED_DATA_FOR_ORGANIZATION`, `DISABLED_REDACT_UNMAPPED_DATA_FOR_LINKED_ACCOUNT`, `CREATED_INTEGRATION_WIDE_FIELD_MAPPING`, `CREATED_LINKED_ACCOUNT_FIELD_MAPPING`, `CHANGED_INTEGRATION_WIDE_FIELD_MAPPING`, `CHANGED_LINKED_ACCOUNT_FIELD_MAPPING`, `DELETED_INTEGRATION_WIDE_FIELD_MAPPING`, `DELETED_LINKED_ACCOUNT_FIELD_MAPPING`, `FORCED_LINKED_ACCOUNT_RESYNC`, `MUTED_ISSUE`, `GENERATED_MAGIC_LINK`, `ENABLED_MERGE_WEBHOOK`, `DISABLED_MERGE_WEBHOOK`, `MERGE_WEBHOOK_TARGET_CHANGED`, `END_USER_CREDENTIALS_ACCESSED` /// - public string? EventType { get; init; } + public string? EventType { get; set; } /// /// Number of results to return per page. /// - public int? PageSize { get; init; } + public int? PageSize { get; set; } /// /// If included, will only include audit trail events that occurred after this time /// - public string? StartDate { get; init; } + public string? StartDate { get; set; } /// /// If provided, this will return events associated with the specified user email. Please note that the email address reflects the user's email at the time of the event, and may not be their current email. /// - public string? UserEmail { get; init; } + public string? UserEmail { get; set; } } diff --git a/src/Merge.Client/Ats/AvailableActions/AvailableActionsClient.cs b/src/Merge.Client/Ats/AvailableActions/AvailableActionsClient.cs index 56e93bdb..8bb62004 100644 --- a/src/Merge.Client/Ats/AvailableActions/AvailableActionsClient.cs +++ b/src/Merge.Client/Ats/AvailableActions/AvailableActionsClient.cs @@ -1,6 +1,6 @@ +using System.Net.Http; using System.Text.Json; -using Merge.Client; -using Merge.Client.Ats; +using Merge.Client.Core; #nullable enable @@ -18,20 +18,34 @@ public AvailableActionsClient(RawClient client) /// /// Returns a list of models and actions available for an account. /// - public async Task RetrieveAsync() + public async Task RetrieveAsync(RequestOptions? options = null) { var response = await _client.MakeRequestAsync( new RawClient.JsonApiRequest { + BaseUrl = _client.Options.BaseUrl, Method = HttpMethod.Get, - Path = "ats/v1/available-actions" + Path = "ats/v1/available-actions", + Options = options } ); - string responseBody = await response.Raw.Content.ReadAsStringAsync(); - if (response.StatusCode >= 200 && response.StatusCode < 400) + var responseBody = await response.Raw.Content.ReadAsStringAsync(); + if (response.StatusCode is >= 200 and < 400) { - return JsonSerializer.Deserialize(responseBody); + try + { + return JsonUtils.Deserialize(responseBody)!; + } + catch (JsonException e) + { + throw new MergeException("Failed to deserialize response", e); + } } - throw new Exception(responseBody); + + throw new MergeApiException( + $"Error with status code {response.StatusCode}", + response.StatusCode, + JsonUtils.Deserialize(responseBody) + ); } } diff --git a/src/Merge.Client/Ats/Candidates/CandidatesClient.cs b/src/Merge.Client/Ats/Candidates/CandidatesClient.cs index cbad4285..1ddd03b1 100644 --- a/src/Merge.Client/Ats/Candidates/CandidatesClient.cs +++ b/src/Merge.Client/Ats/Candidates/CandidatesClient.cs @@ -1,6 +1,6 @@ +using System.Net.Http; using System.Text.Json; -using Merge.Client; -using Merge.Client.Ats; +using Merge.Client.Core; #nullable enable @@ -18,16 +18,21 @@ public CandidatesClient(RawClient client) /// /// Returns a list of `Candidate` objects. /// - public async Task ListAsync(CandidatesListRequest request) + public async Task ListAsync( + CandidatesListRequest request, + RequestOptions? options = null + ) { var _query = new Dictionary() { }; if (request.CreatedAfter != null) { - _query["created_after"] = request.CreatedAfter.Value.ToString("o0"); + _query["created_after"] = request.CreatedAfter.Value.ToString(Constants.DateTimeFormat); } if (request.CreatedBefore != null) { - _query["created_before"] = request.CreatedBefore.Value.ToString("o0"); + _query["created_before"] = request.CreatedBefore.Value.ToString( + Constants.DateTimeFormat + ); } if (request.Cursor != null) { @@ -59,11 +64,15 @@ public async Task ListAsync(CandidatesListRequest reques } if (request.ModifiedAfter != null) { - _query["modified_after"] = request.ModifiedAfter.Value.ToString("o0"); + _query["modified_after"] = request.ModifiedAfter.Value.ToString( + Constants.DateTimeFormat + ); } if (request.ModifiedBefore != null) { - _query["modified_before"] = request.ModifiedBefore.Value.ToString("o0"); + _query["modified_before"] = request.ModifiedBefore.Value.ToString( + Constants.DateTimeFormat + ); } if (request.PageSize != null) { @@ -80,23 +89,40 @@ public async Task ListAsync(CandidatesListRequest reques var response = await _client.MakeRequestAsync( new RawClient.JsonApiRequest { + BaseUrl = _client.Options.BaseUrl, Method = HttpMethod.Get, Path = "ats/v1/candidates", - Query = _query + Query = _query, + Options = options } ); - string responseBody = await response.Raw.Content.ReadAsStringAsync(); - if (response.StatusCode >= 200 && response.StatusCode < 400) + var responseBody = await response.Raw.Content.ReadAsStringAsync(); + if (response.StatusCode is >= 200 and < 400) { - return JsonSerializer.Deserialize(responseBody); + try + { + return JsonUtils.Deserialize(responseBody)!; + } + catch (JsonException e) + { + throw new MergeException("Failed to deserialize response", e); + } } - throw new Exception(responseBody); + + throw new MergeApiException( + $"Error with status code {response.StatusCode}", + response.StatusCode, + JsonUtils.Deserialize(responseBody) + ); } /// /// Creates a `Candidate` object with the given values. /// - public async Task CreateAsync(CandidateEndpointRequest request) + public async Task CreateAsync( + CandidateEndpointRequest request, + RequestOptions? options = null + ) { var _query = new Dictionary() { }; if (request.IsDebugMode != null) @@ -110,23 +136,41 @@ public async Task CreateAsync(CandidateEndpointRequest reques var response = await _client.MakeRequestAsync( new RawClient.JsonApiRequest { + BaseUrl = _client.Options.BaseUrl, Method = HttpMethod.Post, Path = "ats/v1/candidates", - Query = _query + Query = _query, + Options = options } ); - string responseBody = await response.Raw.Content.ReadAsStringAsync(); - if (response.StatusCode >= 200 && response.StatusCode < 400) + var responseBody = await response.Raw.Content.ReadAsStringAsync(); + if (response.StatusCode is >= 200 and < 400) { - return JsonSerializer.Deserialize(responseBody); + try + { + return JsonUtils.Deserialize(responseBody)!; + } + catch (JsonException e) + { + throw new MergeException("Failed to deserialize response", e); + } } - throw new Exception(responseBody); + + throw new MergeApiException( + $"Error with status code {response.StatusCode}", + response.StatusCode, + JsonUtils.Deserialize(responseBody) + ); } /// /// Returns a `Candidate` object with the given `id`. /// - public async Task RetrieveAsync(string id, CandidatesRetrieveRequest request) + public async Task RetrieveAsync( + string id, + CandidatesRetrieveRequest request, + RequestOptions? options = null + ) { var _query = new Dictionary() { }; if (request.Expand != null) @@ -140,17 +184,31 @@ public async Task RetrieveAsync(string id, CandidatesRetrieveRequest var response = await _client.MakeRequestAsync( new RawClient.JsonApiRequest { + BaseUrl = _client.Options.BaseUrl, Method = HttpMethod.Get, Path = $"ats/v1/candidates/{id}", - Query = _query + Query = _query, + Options = options } ); - string responseBody = await response.Raw.Content.ReadAsStringAsync(); - if (response.StatusCode >= 200 && response.StatusCode < 400) + var responseBody = await response.Raw.Content.ReadAsStringAsync(); + if (response.StatusCode is >= 200 and < 400) { - return JsonSerializer.Deserialize(responseBody); + try + { + return JsonUtils.Deserialize(responseBody)!; + } + catch (JsonException e) + { + throw new MergeException("Failed to deserialize response", e); + } } - throw new Exception(responseBody); + + throw new MergeApiException( + $"Error with status code {response.StatusCode}", + response.StatusCode, + JsonUtils.Deserialize(responseBody) + ); } /// @@ -158,7 +216,8 @@ public async Task RetrieveAsync(string id, CandidatesRetrieveRequest /// public async Task PartialUpdateAsync( string id, - PatchedCandidateEndpointRequest request + PatchedCandidateEndpointRequest request, + RequestOptions? options = null ) { var _query = new Dictionary() { }; @@ -173,71 +232,132 @@ PatchedCandidateEndpointRequest request var response = await _client.MakeRequestAsync( new RawClient.JsonApiRequest { - Method = HttpMethod.Patch, + BaseUrl = _client.Options.BaseUrl, + Method = HttpMethodExtensions.Patch, Path = $"ats/v1/candidates/{id}", - Query = _query + Query = _query, + Options = options } ); - string responseBody = await response.Raw.Content.ReadAsStringAsync(); - if (response.StatusCode >= 200 && response.StatusCode < 400) + var responseBody = await response.Raw.Content.ReadAsStringAsync(); + if (response.StatusCode is >= 200 and < 400) { - return JsonSerializer.Deserialize(responseBody); + try + { + return JsonUtils.Deserialize(responseBody)!; + } + catch (JsonException e) + { + throw new MergeException("Failed to deserialize response", e); + } } - throw new Exception(responseBody); + + throw new MergeApiException( + $"Error with status code {response.StatusCode}", + response.StatusCode, + JsonUtils.Deserialize(responseBody) + ); } /// /// Ignores a specific row based on the `model_id` in the url. These records will have their properties set to null, and will not be updated in future syncs. The "reason" and "message" fields in the request body will be stored for audit purposes. /// - public async void IgnoreCreateAsync(string modelId, IgnoreCommonModelRequest request) + public async Task IgnoreCreateAsync( + string modelId, + IgnoreCommonModelRequest request, + RequestOptions? options = null + ) { var response = await _client.MakeRequestAsync( new RawClient.JsonApiRequest { + BaseUrl = _client.Options.BaseUrl, Method = HttpMethod.Post, Path = $"ats/v1/candidates/ignore/{modelId}", - Body = request + Body = request, + Options = options } ); + if (response.StatusCode is >= 200 and < 400) + { + return; + } + var responseBody = await response.Raw.Content.ReadAsStringAsync(); + throw new MergeApiException( + $"Error with status code {response.StatusCode}", + response.StatusCode, + JsonUtils.Deserialize(responseBody) + ); } /// /// Returns metadata for `Candidate` PATCHs. /// - public async Task MetaPatchRetrieveAsync(string id) + public async Task MetaPatchRetrieveAsync( + string id, + RequestOptions? options = null + ) { var response = await _client.MakeRequestAsync( new RawClient.JsonApiRequest { + BaseUrl = _client.Options.BaseUrl, Method = HttpMethod.Get, - Path = $"ats/v1/candidates/meta/patch/{id}" + Path = $"ats/v1/candidates/meta/patch/{id}", + Options = options } ); - string responseBody = await response.Raw.Content.ReadAsStringAsync(); - if (response.StatusCode >= 200 && response.StatusCode < 400) + var responseBody = await response.Raw.Content.ReadAsStringAsync(); + if (response.StatusCode is >= 200 and < 400) { - return JsonSerializer.Deserialize(responseBody); + try + { + return JsonUtils.Deserialize(responseBody)!; + } + catch (JsonException e) + { + throw new MergeException("Failed to deserialize response", e); + } } - throw new Exception(responseBody); + + throw new MergeApiException( + $"Error with status code {response.StatusCode}", + response.StatusCode, + JsonUtils.Deserialize(responseBody) + ); } /// /// Returns metadata for `Candidate` POSTs. /// - public async Task MetaPostRetrieveAsync() + public async Task MetaPostRetrieveAsync(RequestOptions? options = null) { var response = await _client.MakeRequestAsync( new RawClient.JsonApiRequest { + BaseUrl = _client.Options.BaseUrl, Method = HttpMethod.Get, - Path = "ats/v1/candidates/meta/post" + Path = "ats/v1/candidates/meta/post", + Options = options } ); - string responseBody = await response.Raw.Content.ReadAsStringAsync(); - if (response.StatusCode >= 200 && response.StatusCode < 400) + var responseBody = await response.Raw.Content.ReadAsStringAsync(); + if (response.StatusCode is >= 200 and < 400) { - return JsonSerializer.Deserialize(responseBody); + try + { + return JsonUtils.Deserialize(responseBody)!; + } + catch (JsonException e) + { + throw new MergeException("Failed to deserialize response", e); + } } - throw new Exception(responseBody); + + throw new MergeApiException( + $"Error with status code {response.StatusCode}", + response.StatusCode, + JsonUtils.Deserialize(responseBody) + ); } } diff --git a/src/Merge.Client/Ats/Candidates/Requests/CandidateEndpointRequest.cs b/src/Merge.Client/Ats/Candidates/Requests/CandidateEndpointRequest.cs index 6fb23c04..a18be586 100644 --- a/src/Merge.Client/Ats/Candidates/Requests/CandidateEndpointRequest.cs +++ b/src/Merge.Client/Ats/Candidates/Requests/CandidateEndpointRequest.cs @@ -1,22 +1,18 @@ -using Merge.Client.Ats; - -#nullable enable - namespace Merge.Client.Ats; -public class CandidateEndpointRequest +public record CandidateEndpointRequest { /// /// Whether to include debug fields (such as log file links) in the response. /// - public bool? IsDebugMode { get; init; } + public bool? IsDebugMode { get; set; } /// /// Whether or not third-party updates should be run asynchronously. /// - public bool? RunAsync { get; init; } + public bool? RunAsync { get; set; } - public CandidateRequest Model { get; init; } + public required CandidateRequest Model { get; set; } - public string RemoteUserId { get; init; } + public required string RemoteUserId { get; set; } } diff --git a/src/Merge.Client/Ats/Candidates/Requests/CandidatesListRequest.cs b/src/Merge.Client/Ats/Candidates/Requests/CandidatesListRequest.cs index 26392503..9ac80efc 100644 --- a/src/Merge.Client/Ats/Candidates/Requests/CandidatesListRequest.cs +++ b/src/Merge.Client/Ats/Candidates/Requests/CandidatesListRequest.cs @@ -1,78 +1,74 @@ -using Merge.Client.Ats; - -#nullable enable - namespace Merge.Client.Ats; -public class CandidatesListRequest +public record CandidatesListRequest { /// /// If provided, will only return objects created after this datetime. /// - public DateTime? CreatedAfter { get; init; } + public DateTime? CreatedAfter { get; set; } /// /// If provided, will only return objects created before this datetime. /// - public DateTime? CreatedBefore { get; init; } + public DateTime? CreatedBefore { get; set; } /// /// The pagination cursor value. /// - public string? Cursor { get; init; } + public string? Cursor { get; set; } /// /// If provided, will only return candidates with these email addresses; multiple addresses can be separated by commas. /// - public string? EmailAddresses { get; init; } + public string? EmailAddresses { get; set; } /// /// Which relations should be returned in expanded form. Multiple relation names should be comma separated without spaces. /// - public CandidatesListRequestExpand? Expand { get; init; } + public CandidatesListRequestExpand? Expand { get; set; } /// /// If provided, will only return candidates with this first name. /// - public string? FirstName { get; init; } + public string? FirstName { get; set; } /// /// Whether to include data that was marked as deleted by third party webhooks. /// - public bool? IncludeDeletedData { get; init; } + public bool? IncludeDeletedData { get; set; } /// /// Whether to include the original data Merge fetched from the third-party to produce these models. /// - public bool? IncludeRemoteData { get; init; } + public bool? IncludeRemoteData { get; set; } /// /// If provided, will only return candidates with this last name. /// - public string? LastName { get; init; } + public string? LastName { get; set; } /// /// If provided, only objects synced by Merge after this date time will be returned. /// - public DateTime? ModifiedAfter { get; init; } + public DateTime? ModifiedAfter { get; set; } /// /// If provided, only objects synced by Merge before this date time will be returned. /// - public DateTime? ModifiedBefore { get; init; } + public DateTime? ModifiedBefore { get; set; } /// /// Number of results to return per page. /// - public int? PageSize { get; init; } + public int? PageSize { get; set; } /// /// The API provider's ID for the given object. /// - public string? RemoteId { get; init; } + public string? RemoteId { get; set; } /// /// If provided, will only return candidates with these tags; multiple tags can be separated by commas. /// - public string? Tags { get; init; } + public string? Tags { get; set; } } diff --git a/src/Merge.Client/Ats/Candidates/Requests/CandidatesRetrieveRequest.cs b/src/Merge.Client/Ats/Candidates/Requests/CandidatesRetrieveRequest.cs index cf28df60..2d2b427a 100644 --- a/src/Merge.Client/Ats/Candidates/Requests/CandidatesRetrieveRequest.cs +++ b/src/Merge.Client/Ats/Candidates/Requests/CandidatesRetrieveRequest.cs @@ -1,18 +1,14 @@ -using Merge.Client.Ats; - -#nullable enable - namespace Merge.Client.Ats; -public class CandidatesRetrieveRequest +public record CandidatesRetrieveRequest { /// /// Which relations should be returned in expanded form. Multiple relation names should be comma separated without spaces. /// - public CandidatesRetrieveRequestExpand? Expand { get; init; } + public CandidatesRetrieveRequestExpand? Expand { get; set; } /// /// Whether to include the original data Merge fetched from the third-party to produce these models. /// - public bool? IncludeRemoteData { get; init; } + public bool? IncludeRemoteData { get; set; } } diff --git a/src/Merge.Client/Ats/Candidates/Requests/IgnoreCommonModelRequest.cs b/src/Merge.Client/Ats/Candidates/Requests/IgnoreCommonModelRequest.cs index 2196e016..4ddb344b 100644 --- a/src/Merge.Client/Ats/Candidates/Requests/IgnoreCommonModelRequest.cs +++ b/src/Merge.Client/Ats/Candidates/Requests/IgnoreCommonModelRequest.cs @@ -1,15 +1,14 @@ using System.Text.Json.Serialization; -using Merge.Client.Ats; #nullable enable namespace Merge.Client.Ats; -public class IgnoreCommonModelRequest +public record IgnoreCommonModelRequest { [JsonPropertyName("reason")] - public ReasonEnum Reason { get; init; } + public required ReasonEnum Reason { get; set; } [JsonPropertyName("message")] - public string? Message { get; init; } + public string? Message { get; set; } } diff --git a/src/Merge.Client/Ats/Candidates/Requests/PatchedCandidateEndpointRequest.cs b/src/Merge.Client/Ats/Candidates/Requests/PatchedCandidateEndpointRequest.cs index 2f0f8a6c..5340cf11 100644 --- a/src/Merge.Client/Ats/Candidates/Requests/PatchedCandidateEndpointRequest.cs +++ b/src/Merge.Client/Ats/Candidates/Requests/PatchedCandidateEndpointRequest.cs @@ -1,22 +1,18 @@ -using Merge.Client.Ats; - -#nullable enable - namespace Merge.Client.Ats; -public class PatchedCandidateEndpointRequest +public record PatchedCandidateEndpointRequest { /// /// Whether to include debug fields (such as log file links) in the response. /// - public bool? IsDebugMode { get; init; } + public bool? IsDebugMode { get; set; } /// /// Whether or not third-party updates should be run asynchronously. /// - public bool? RunAsync { get; init; } + public bool? RunAsync { get; set; } - public PatchedCandidateRequest Model { get; init; } + public required PatchedCandidateRequest Model { get; set; } - public string RemoteUserId { get; init; } + public required string RemoteUserId { get; set; } } diff --git a/src/Merge.Client/Ats/Candidates/Types/CandidatesListRequestExpand.cs b/src/Merge.Client/Ats/Candidates/Types/CandidatesListRequestExpand.cs index 64c150ab..c71f3209 100644 --- a/src/Merge.Client/Ats/Candidates/Types/CandidatesListRequestExpand.cs +++ b/src/Merge.Client/Ats/Candidates/Types/CandidatesListRequestExpand.cs @@ -1,6 +1,5 @@ using System.Runtime.Serialization; using System.Text.Json.Serialization; -using Merge.Client.Ats; using Merge.Client.Core; #nullable enable diff --git a/src/Merge.Client/Ats/Candidates/Types/CandidatesRetrieveRequestExpand.cs b/src/Merge.Client/Ats/Candidates/Types/CandidatesRetrieveRequestExpand.cs index 44e7e672..ea907734 100644 --- a/src/Merge.Client/Ats/Candidates/Types/CandidatesRetrieveRequestExpand.cs +++ b/src/Merge.Client/Ats/Candidates/Types/CandidatesRetrieveRequestExpand.cs @@ -1,6 +1,5 @@ using System.Runtime.Serialization; using System.Text.Json.Serialization; -using Merge.Client.Ats; using Merge.Client.Core; #nullable enable diff --git a/src/Merge.Client/Ats/DeleteAccount/DeleteAccountClient.cs b/src/Merge.Client/Ats/DeleteAccount/DeleteAccountClient.cs index 3f1ef205..9e7ccdb5 100644 --- a/src/Merge.Client/Ats/DeleteAccount/DeleteAccountClient.cs +++ b/src/Merge.Client/Ats/DeleteAccount/DeleteAccountClient.cs @@ -1,4 +1,5 @@ -using Merge.Client; +using System.Net.Http; +using Merge.Client.Core; #nullable enable @@ -16,14 +17,26 @@ public DeleteAccountClient(RawClient client) /// /// Delete a linked account. /// - public async void DeleteAsync() + public async Task DeleteAsync(RequestOptions? options = null) { var response = await _client.MakeRequestAsync( new RawClient.JsonApiRequest { + BaseUrl = _client.Options.BaseUrl, Method = HttpMethod.Post, - Path = "ats/v1/delete-account" + Path = "ats/v1/delete-account", + Options = options } ); + if (response.StatusCode is >= 200 and < 400) + { + return; + } + var responseBody = await response.Raw.Content.ReadAsStringAsync(); + throw new MergeApiException( + $"Error with status code {response.StatusCode}", + response.StatusCode, + JsonUtils.Deserialize(responseBody) + ); } } diff --git a/src/Merge.Client/Ats/Departments/DepartmentsClient.cs b/src/Merge.Client/Ats/Departments/DepartmentsClient.cs index 77c304bc..bf53ac85 100644 --- a/src/Merge.Client/Ats/Departments/DepartmentsClient.cs +++ b/src/Merge.Client/Ats/Departments/DepartmentsClient.cs @@ -1,6 +1,6 @@ +using System.Net.Http; using System.Text.Json; -using Merge.Client; -using Merge.Client.Ats; +using Merge.Client.Core; #nullable enable @@ -18,16 +18,21 @@ public DepartmentsClient(RawClient client) /// /// Returns a list of `Department` objects. /// - public async Task ListAsync(DepartmentsListRequest request) + public async Task ListAsync( + DepartmentsListRequest request, + RequestOptions? options = null + ) { var _query = new Dictionary() { }; if (request.CreatedAfter != null) { - _query["created_after"] = request.CreatedAfter.Value.ToString("o0"); + _query["created_after"] = request.CreatedAfter.Value.ToString(Constants.DateTimeFormat); } if (request.CreatedBefore != null) { - _query["created_before"] = request.CreatedBefore.Value.ToString("o0"); + _query["created_before"] = request.CreatedBefore.Value.ToString( + Constants.DateTimeFormat + ); } if (request.Cursor != null) { @@ -43,11 +48,15 @@ public async Task ListAsync(DepartmentsListRequest requ } if (request.ModifiedAfter != null) { - _query["modified_after"] = request.ModifiedAfter.Value.ToString("o0"); + _query["modified_after"] = request.ModifiedAfter.Value.ToString( + Constants.DateTimeFormat + ); } if (request.ModifiedBefore != null) { - _query["modified_before"] = request.ModifiedBefore.Value.ToString("o0"); + _query["modified_before"] = request.ModifiedBefore.Value.ToString( + Constants.DateTimeFormat + ); } if (request.PageSize != null) { @@ -60,23 +69,41 @@ public async Task ListAsync(DepartmentsListRequest requ var response = await _client.MakeRequestAsync( new RawClient.JsonApiRequest { + BaseUrl = _client.Options.BaseUrl, Method = HttpMethod.Get, Path = "ats/v1/departments", - Query = _query + Query = _query, + Options = options } ); - string responseBody = await response.Raw.Content.ReadAsStringAsync(); - if (response.StatusCode >= 200 && response.StatusCode < 400) + var responseBody = await response.Raw.Content.ReadAsStringAsync(); + if (response.StatusCode is >= 200 and < 400) { - return JsonSerializer.Deserialize(responseBody); + try + { + return JsonUtils.Deserialize(responseBody)!; + } + catch (JsonException e) + { + throw new MergeException("Failed to deserialize response", e); + } } - throw new Exception(responseBody); + + throw new MergeApiException( + $"Error with status code {response.StatusCode}", + response.StatusCode, + JsonUtils.Deserialize(responseBody) + ); } /// /// Returns a `Department` object with the given `id`. /// - public async Task RetrieveAsync(string id, DepartmentsRetrieveRequest request) + public async Task RetrieveAsync( + string id, + DepartmentsRetrieveRequest request, + RequestOptions? options = null + ) { var _query = new Dictionary() { }; if (request.IncludeRemoteData != null) @@ -86,16 +113,30 @@ public async Task RetrieveAsync(string id, DepartmentsRetrieveReques var response = await _client.MakeRequestAsync( new RawClient.JsonApiRequest { + BaseUrl = _client.Options.BaseUrl, Method = HttpMethod.Get, Path = $"ats/v1/departments/{id}", - Query = _query + Query = _query, + Options = options } ); - string responseBody = await response.Raw.Content.ReadAsStringAsync(); - if (response.StatusCode >= 200 && response.StatusCode < 400) + var responseBody = await response.Raw.Content.ReadAsStringAsync(); + if (response.StatusCode is >= 200 and < 400) { - return JsonSerializer.Deserialize(responseBody); + try + { + return JsonUtils.Deserialize(responseBody)!; + } + catch (JsonException e) + { + throw new MergeException("Failed to deserialize response", e); + } } - throw new Exception(responseBody); + + throw new MergeApiException( + $"Error with status code {response.StatusCode}", + response.StatusCode, + JsonUtils.Deserialize(responseBody) + ); } } diff --git a/src/Merge.Client/Ats/Departments/Requests/DepartmentsListRequest.cs b/src/Merge.Client/Ats/Departments/Requests/DepartmentsListRequest.cs index ba89c818..9ab33162 100644 --- a/src/Merge.Client/Ats/Departments/Requests/DepartmentsListRequest.cs +++ b/src/Merge.Client/Ats/Departments/Requests/DepartmentsListRequest.cs @@ -1,49 +1,49 @@ namespace Merge.Client.Ats; -public class DepartmentsListRequest +public record DepartmentsListRequest { /// /// If provided, will only return objects created after this datetime. /// - public DateTime? CreatedAfter { get; init; } + public DateTime? CreatedAfter { get; set; } /// /// If provided, will only return objects created before this datetime. /// - public DateTime? CreatedBefore { get; init; } + public DateTime? CreatedBefore { get; set; } /// /// The pagination cursor value. /// - public string? Cursor { get; init; } + public string? Cursor { get; set; } /// /// Whether to include data that was marked as deleted by third party webhooks. /// - public bool? IncludeDeletedData { get; init; } + public bool? IncludeDeletedData { get; set; } /// /// Whether to include the original data Merge fetched from the third-party to produce these models. /// - public bool? IncludeRemoteData { get; init; } + public bool? IncludeRemoteData { get; set; } /// /// If provided, only objects synced by Merge after this date time will be returned. /// - public DateTime? ModifiedAfter { get; init; } + public DateTime? ModifiedAfter { get; set; } /// /// If provided, only objects synced by Merge before this date time will be returned. /// - public DateTime? ModifiedBefore { get; init; } + public DateTime? ModifiedBefore { get; set; } /// /// Number of results to return per page. /// - public int? PageSize { get; init; } + public int? PageSize { get; set; } /// /// The API provider's ID for the given object. /// - public string? RemoteId { get; init; } + public string? RemoteId { get; set; } } diff --git a/src/Merge.Client/Ats/Departments/Requests/DepartmentsRetrieveRequest.cs b/src/Merge.Client/Ats/Departments/Requests/DepartmentsRetrieveRequest.cs index a7b83539..ab927019 100644 --- a/src/Merge.Client/Ats/Departments/Requests/DepartmentsRetrieveRequest.cs +++ b/src/Merge.Client/Ats/Departments/Requests/DepartmentsRetrieveRequest.cs @@ -1,9 +1,9 @@ namespace Merge.Client.Ats; -public class DepartmentsRetrieveRequest +public record DepartmentsRetrieveRequest { /// /// Whether to include the original data Merge fetched from the third-party to produce these models. /// - public bool? IncludeRemoteData { get; init; } + public bool? IncludeRemoteData { get; set; } } diff --git a/src/Merge.Client/Ats/Eeocs/EeocsClient.cs b/src/Merge.Client/Ats/Eeocs/EeocsClient.cs index bbccb8ac..0b9d452b 100644 --- a/src/Merge.Client/Ats/Eeocs/EeocsClient.cs +++ b/src/Merge.Client/Ats/Eeocs/EeocsClient.cs @@ -1,6 +1,6 @@ +using System.Net.Http; using System.Text.Json; -using Merge.Client; -using Merge.Client.Ats; +using Merge.Client.Core; #nullable enable @@ -18,7 +18,10 @@ public EeocsClient(RawClient client) /// /// Returns a list of `EEOC` objects. /// - public async Task ListAsync(EeocsListRequest request) + public async Task ListAsync( + EeocsListRequest request, + RequestOptions? options = null + ) { var _query = new Dictionary() { }; if (request.CandidateId != null) @@ -27,11 +30,13 @@ public async Task ListAsync(EeocsListRequest request) } if (request.CreatedAfter != null) { - _query["created_after"] = request.CreatedAfter.Value.ToString("o0"); + _query["created_after"] = request.CreatedAfter.Value.ToString(Constants.DateTimeFormat); } if (request.CreatedBefore != null) { - _query["created_before"] = request.CreatedBefore.Value.ToString("o0"); + _query["created_before"] = request.CreatedBefore.Value.ToString( + Constants.DateTimeFormat + ); } if (request.Cursor != null) { @@ -51,11 +56,15 @@ public async Task ListAsync(EeocsListRequest request) } if (request.ModifiedAfter != null) { - _query["modified_after"] = request.ModifiedAfter.Value.ToString("o0"); + _query["modified_after"] = request.ModifiedAfter.Value.ToString( + Constants.DateTimeFormat + ); } if (request.ModifiedBefore != null) { - _query["modified_before"] = request.ModifiedBefore.Value.ToString("o0"); + _query["modified_before"] = request.ModifiedBefore.Value.ToString( + Constants.DateTimeFormat + ); } if (request.PageSize != null) { @@ -76,23 +85,41 @@ public async Task ListAsync(EeocsListRequest request) var response = await _client.MakeRequestAsync( new RawClient.JsonApiRequest { + BaseUrl = _client.Options.BaseUrl, Method = HttpMethod.Get, Path = "ats/v1/eeocs", - Query = _query + Query = _query, + Options = options } ); - string responseBody = await response.Raw.Content.ReadAsStringAsync(); - if (response.StatusCode >= 200 && response.StatusCode < 400) + var responseBody = await response.Raw.Content.ReadAsStringAsync(); + if (response.StatusCode is >= 200 and < 400) { - return JsonSerializer.Deserialize(responseBody); + try + { + return JsonUtils.Deserialize(responseBody)!; + } + catch (JsonException e) + { + throw new MergeException("Failed to deserialize response", e); + } } - throw new Exception(responseBody); + + throw new MergeApiException( + $"Error with status code {response.StatusCode}", + response.StatusCode, + JsonUtils.Deserialize(responseBody) + ); } /// /// Returns an `EEOC` object with the given `id`. /// - public async Task RetrieveAsync(string id, EeocsRetrieveRequest request) + public async Task RetrieveAsync( + string id, + EeocsRetrieveRequest request, + RequestOptions? options = null + ) { var _query = new Dictionary() { }; if (request.Expand != null) @@ -114,16 +141,30 @@ public async Task RetrieveAsync(string id, EeocsRetrieveRequest request) var response = await _client.MakeRequestAsync( new RawClient.JsonApiRequest { + BaseUrl = _client.Options.BaseUrl, Method = HttpMethod.Get, Path = $"ats/v1/eeocs/{id}", - Query = _query + Query = _query, + Options = options } ); - string responseBody = await response.Raw.Content.ReadAsStringAsync(); - if (response.StatusCode >= 200 && response.StatusCode < 400) + var responseBody = await response.Raw.Content.ReadAsStringAsync(); + if (response.StatusCode is >= 200 and < 400) { - return JsonSerializer.Deserialize(responseBody); + try + { + return JsonUtils.Deserialize(responseBody)!; + } + catch (JsonException e) + { + throw new MergeException("Failed to deserialize response", e); + } } - throw new Exception(responseBody); + + throw new MergeApiException( + $"Error with status code {response.StatusCode}", + response.StatusCode, + JsonUtils.Deserialize(responseBody) + ); } } diff --git a/src/Merge.Client/Ats/Eeocs/Requests/EeocsListRequest.cs b/src/Merge.Client/Ats/Eeocs/Requests/EeocsListRequest.cs index 9e55850c..bcfe609d 100644 --- a/src/Merge.Client/Ats/Eeocs/Requests/EeocsListRequest.cs +++ b/src/Merge.Client/Ats/Eeocs/Requests/EeocsListRequest.cs @@ -1,73 +1,69 @@ -using Merge.Client.Ats; - -#nullable enable - namespace Merge.Client.Ats; -public class EeocsListRequest +public record EeocsListRequest { /// /// If provided, will only return EEOC info for this candidate. /// - public string? CandidateId { get; init; } + public string? CandidateId { get; set; } /// /// If provided, will only return objects created after this datetime. /// - public DateTime? CreatedAfter { get; init; } + public DateTime? CreatedAfter { get; set; } /// /// If provided, will only return objects created before this datetime. /// - public DateTime? CreatedBefore { get; init; } + public DateTime? CreatedBefore { get; set; } /// /// The pagination cursor value. /// - public string? Cursor { get; init; } + public string? Cursor { get; set; } /// /// Which relations should be returned in expanded form. Multiple relation names should be comma separated without spaces. /// - public string? Expand { get; init; } + public string? Expand { get; set; } /// /// Whether to include data that was marked as deleted by third party webhooks. /// - public bool? IncludeDeletedData { get; init; } + public bool? IncludeDeletedData { get; set; } /// /// Whether to include the original data Merge fetched from the third-party to produce these models. /// - public bool? IncludeRemoteData { get; init; } + public bool? IncludeRemoteData { get; set; } /// /// If provided, only objects synced by Merge after this date time will be returned. /// - public DateTime? ModifiedAfter { get; init; } + public DateTime? ModifiedAfter { get; set; } /// /// If provided, only objects synced by Merge before this date time will be returned. /// - public DateTime? ModifiedBefore { get; init; } + public DateTime? ModifiedBefore { get; set; } /// /// Number of results to return per page. /// - public int? PageSize { get; init; } + public int? PageSize { get; set; } /// /// Deprecated. Use show_enum_origins. /// - public EeocsListRequestRemoteFields? RemoteFields { get; init; } + public EeocsListRequestRemoteFields? RemoteFields { get; set; } /// /// The API provider's ID for the given object. /// - public string? RemoteId { get; init; } + public string? RemoteId { get; set; } /// /// A comma separated list of enum field names for which you'd like the original values to be returned, instead of Merge's normalized enum values. [Learn more](https://help.merge.dev/en/articles/8950958-show_enum_origins-query-parameter) /// - public EeocsListRequestShowEnumOrigins? ShowEnumOrigins { get; init; } + public EeocsListRequestShowEnumOrigins? ShowEnumOrigins { get; set; } } diff --git a/src/Merge.Client/Ats/Eeocs/Requests/EeocsRetrieveRequest.cs b/src/Merge.Client/Ats/Eeocs/Requests/EeocsRetrieveRequest.cs index eafcd021..f8a5a078 100644 --- a/src/Merge.Client/Ats/Eeocs/Requests/EeocsRetrieveRequest.cs +++ b/src/Merge.Client/Ats/Eeocs/Requests/EeocsRetrieveRequest.cs @@ -1,28 +1,24 @@ -using Merge.Client.Ats; - -#nullable enable - namespace Merge.Client.Ats; -public class EeocsRetrieveRequest +public record EeocsRetrieveRequest { /// /// Which relations should be returned in expanded form. Multiple relation names should be comma separated without spaces. /// - public string? Expand { get; init; } + public string? Expand { get; set; } /// /// Whether to include the original data Merge fetched from the third-party to produce these models. /// - public bool? IncludeRemoteData { get; init; } + public bool? IncludeRemoteData { get; set; } /// /// Deprecated. Use show_enum_origins. /// - public EeocsRetrieveRequestRemoteFields? RemoteFields { get; init; } + public EeocsRetrieveRequestRemoteFields? RemoteFields { get; set; } /// /// A comma separated list of enum field names for which you'd like the original values to be returned, instead of Merge's normalized enum values. [Learn more](https://help.merge.dev/en/articles/8950958-show_enum_origins-query-parameter) /// - public EeocsRetrieveRequestShowEnumOrigins? ShowEnumOrigins { get; init; } + public EeocsRetrieveRequestShowEnumOrigins? ShowEnumOrigins { get; set; } } diff --git a/src/Merge.Client/Ats/Eeocs/Types/EeocsListRequestRemoteFields.cs b/src/Merge.Client/Ats/Eeocs/Types/EeocsListRequestRemoteFields.cs index 664c2174..da03d186 100644 --- a/src/Merge.Client/Ats/Eeocs/Types/EeocsListRequestRemoteFields.cs +++ b/src/Merge.Client/Ats/Eeocs/Types/EeocsListRequestRemoteFields.cs @@ -1,6 +1,5 @@ using System.Runtime.Serialization; using System.Text.Json.Serialization; -using Merge.Client.Ats; using Merge.Client.Core; #nullable enable diff --git a/src/Merge.Client/Ats/Eeocs/Types/EeocsListRequestShowEnumOrigins.cs b/src/Merge.Client/Ats/Eeocs/Types/EeocsListRequestShowEnumOrigins.cs index 9d455ef9..1f122edb 100644 --- a/src/Merge.Client/Ats/Eeocs/Types/EeocsListRequestShowEnumOrigins.cs +++ b/src/Merge.Client/Ats/Eeocs/Types/EeocsListRequestShowEnumOrigins.cs @@ -1,6 +1,5 @@ using System.Runtime.Serialization; using System.Text.Json.Serialization; -using Merge.Client.Ats; using Merge.Client.Core; #nullable enable diff --git a/src/Merge.Client/Ats/Eeocs/Types/EeocsRetrieveRequestRemoteFields.cs b/src/Merge.Client/Ats/Eeocs/Types/EeocsRetrieveRequestRemoteFields.cs index 7aab3ac5..62c9a7f7 100644 --- a/src/Merge.Client/Ats/Eeocs/Types/EeocsRetrieveRequestRemoteFields.cs +++ b/src/Merge.Client/Ats/Eeocs/Types/EeocsRetrieveRequestRemoteFields.cs @@ -1,6 +1,5 @@ using System.Runtime.Serialization; using System.Text.Json.Serialization; -using Merge.Client.Ats; using Merge.Client.Core; #nullable enable diff --git a/src/Merge.Client/Ats/Eeocs/Types/EeocsRetrieveRequestShowEnumOrigins.cs b/src/Merge.Client/Ats/Eeocs/Types/EeocsRetrieveRequestShowEnumOrigins.cs index b61c931c..e769d5d3 100644 --- a/src/Merge.Client/Ats/Eeocs/Types/EeocsRetrieveRequestShowEnumOrigins.cs +++ b/src/Merge.Client/Ats/Eeocs/Types/EeocsRetrieveRequestShowEnumOrigins.cs @@ -1,6 +1,5 @@ using System.Runtime.Serialization; using System.Text.Json.Serialization; -using Merge.Client.Ats; using Merge.Client.Core; #nullable enable diff --git a/src/Merge.Client/Ats/FieldMapping/FieldMappingClient.cs b/src/Merge.Client/Ats/FieldMapping/FieldMappingClient.cs index 84b57c66..cfcb280e 100644 --- a/src/Merge.Client/Ats/FieldMapping/FieldMappingClient.cs +++ b/src/Merge.Client/Ats/FieldMapping/FieldMappingClient.cs @@ -1,6 +1,6 @@ +using System.Net.Http; using System.Text.Json; -using Merge.Client; -using Merge.Client.Ats; +using Merge.Client.Core; #nullable enable @@ -18,60 +18,112 @@ public FieldMappingClient(RawClient client) /// /// Get all Field Mappings for this Linked Account. Field Mappings are mappings between third-party Remote Fields and user defined Merge fields. [Learn more](https://docs.merge.dev/supplemental-data/field-mappings/overview/). /// - public async Task FieldMappingsRetrieveAsync() + public async Task FieldMappingsRetrieveAsync( + RequestOptions? options = null + ) { var response = await _client.MakeRequestAsync( - new RawClient.JsonApiRequest { Method = HttpMethod.Get, Path = "ats/v1/field-mappings" } + new RawClient.JsonApiRequest + { + BaseUrl = _client.Options.BaseUrl, + Method = HttpMethod.Get, + Path = "ats/v1/field-mappings", + Options = options + } ); - string responseBody = await response.Raw.Content.ReadAsStringAsync(); - if (response.StatusCode >= 200 && response.StatusCode < 400) + var responseBody = await response.Raw.Content.ReadAsStringAsync(); + if (response.StatusCode is >= 200 and < 400) { - return JsonSerializer.Deserialize(responseBody); + try + { + return JsonUtils.Deserialize(responseBody)!; + } + catch (JsonException e) + { + throw new MergeException("Failed to deserialize response", e); + } } - throw new Exception(responseBody); + + throw new MergeApiException( + $"Error with status code {response.StatusCode}", + response.StatusCode, + JsonUtils.Deserialize(responseBody) + ); } /// /// Create new Field Mappings that will be available after the next scheduled sync. This will cause the next sync for this Linked Account to sync **ALL** data from start. /// public async Task FieldMappingsCreateAsync( - CreateFieldMappingRequest request + CreateFieldMappingRequest request, + RequestOptions? options = null ) { var response = await _client.MakeRequestAsync( new RawClient.JsonApiRequest { + BaseUrl = _client.Options.BaseUrl, Method = HttpMethod.Post, Path = "ats/v1/field-mappings", - Body = request + Body = request, + Options = options } ); - string responseBody = await response.Raw.Content.ReadAsStringAsync(); - if (response.StatusCode >= 200 && response.StatusCode < 400) + var responseBody = await response.Raw.Content.ReadAsStringAsync(); + if (response.StatusCode is >= 200 and < 400) { - return JsonSerializer.Deserialize(responseBody); + try + { + return JsonUtils.Deserialize(responseBody)!; + } + catch (JsonException e) + { + throw new MergeException("Failed to deserialize response", e); + } } - throw new Exception(responseBody); + + throw new MergeApiException( + $"Error with status code {response.StatusCode}", + response.StatusCode, + JsonUtils.Deserialize(responseBody) + ); } /// /// Deletes Field Mappings for a Linked Account. All data related to this Field Mapping will be deleted and these changes will be reflected after the next scheduled sync. This will cause the next sync for this Linked Account to sync **ALL** data from start. /// - public async Task FieldMappingsDestroyAsync(string fieldMappingId) + public async Task FieldMappingsDestroyAsync( + string fieldMappingId, + RequestOptions? options = null + ) { var response = await _client.MakeRequestAsync( new RawClient.JsonApiRequest { + BaseUrl = _client.Options.BaseUrl, Method = HttpMethod.Delete, - Path = $"ats/v1/field-mappings/{fieldMappingId}" + Path = $"ats/v1/field-mappings/{fieldMappingId}", + Options = options } ); - string responseBody = await response.Raw.Content.ReadAsStringAsync(); - if (response.StatusCode >= 200 && response.StatusCode < 400) + var responseBody = await response.Raw.Content.ReadAsStringAsync(); + if (response.StatusCode is >= 200 and < 400) { - return JsonSerializer.Deserialize(responseBody); + try + { + return JsonUtils.Deserialize(responseBody)!; + } + catch (JsonException e) + { + throw new MergeException("Failed to deserialize response", e); + } } - throw new Exception(responseBody); + + throw new MergeApiException( + $"Error with status code {response.StatusCode}", + response.StatusCode, + JsonUtils.Deserialize(responseBody) + ); } /// @@ -79,30 +131,46 @@ public async Task FieldMappingsDestroyAsync(string /// public async Task FieldMappingsPartialUpdateAsync( string fieldMappingId, - PatchedEditFieldMappingRequest request + PatchedEditFieldMappingRequest request, + RequestOptions? options = null ) { var response = await _client.MakeRequestAsync( new RawClient.JsonApiRequest { - Method = HttpMethod.Patch, + BaseUrl = _client.Options.BaseUrl, + Method = HttpMethodExtensions.Patch, Path = $"ats/v1/field-mappings/{fieldMappingId}", - Body = request + Body = request, + Options = options } ); - string responseBody = await response.Raw.Content.ReadAsStringAsync(); - if (response.StatusCode >= 200 && response.StatusCode < 400) + var responseBody = await response.Raw.Content.ReadAsStringAsync(); + if (response.StatusCode is >= 200 and < 400) { - return JsonSerializer.Deserialize(responseBody); + try + { + return JsonUtils.Deserialize(responseBody)!; + } + catch (JsonException e) + { + throw new MergeException("Failed to deserialize response", e); + } } - throw new Exception(responseBody); + + throw new MergeApiException( + $"Error with status code {response.StatusCode}", + response.StatusCode, + JsonUtils.Deserialize(responseBody) + ); } /// /// Get all remote fields for a Linked Account. Remote fields are third-party fields that are accessible after initial sync if remote_data is enabled. You can use remote fields to override existing Merge fields or map a new Merge field. [Learn more](https://docs.merge.dev/supplemental-data/field-mappings/overview/). /// public async Task RemoteFieldsRetrieveAsync( - RemoteFieldsRetrieveRequest request + RemoteFieldsRetrieveRequest request, + RequestOptions? options = null ) { var _query = new Dictionary() { }; @@ -117,32 +185,66 @@ RemoteFieldsRetrieveRequest request var response = await _client.MakeRequestAsync( new RawClient.JsonApiRequest { + BaseUrl = _client.Options.BaseUrl, Method = HttpMethod.Get, Path = "ats/v1/remote-fields", - Query = _query + Query = _query, + Options = options } ); - string responseBody = await response.Raw.Content.ReadAsStringAsync(); - if (response.StatusCode >= 200 && response.StatusCode < 400) + var responseBody = await response.Raw.Content.ReadAsStringAsync(); + if (response.StatusCode is >= 200 and < 400) { - return JsonSerializer.Deserialize(responseBody); + try + { + return JsonUtils.Deserialize(responseBody)!; + } + catch (JsonException e) + { + throw new MergeException("Failed to deserialize response", e); + } } - throw new Exception(responseBody); + + throw new MergeApiException( + $"Error with status code {response.StatusCode}", + response.StatusCode, + JsonUtils.Deserialize(responseBody) + ); } /// /// Get all organization-wide Target Fields, this will not include any Linked Account specific Target Fields. Organization-wide Target Fields are additional fields appended to the Merge Common Model for all Linked Accounts in a category. [Learn more](https://docs.merge.dev/supplemental-data/field-mappings/target-fields/). /// - public async Task TargetFieldsRetrieveAsync() + public async Task TargetFieldsRetrieveAsync( + RequestOptions? options = null + ) { var response = await _client.MakeRequestAsync( - new RawClient.JsonApiRequest { Method = HttpMethod.Get, Path = "ats/v1/target-fields" } + new RawClient.JsonApiRequest + { + BaseUrl = _client.Options.BaseUrl, + Method = HttpMethod.Get, + Path = "ats/v1/target-fields", + Options = options + } ); - string responseBody = await response.Raw.Content.ReadAsStringAsync(); - if (response.StatusCode >= 200 && response.StatusCode < 400) + var responseBody = await response.Raw.Content.ReadAsStringAsync(); + if (response.StatusCode is >= 200 and < 400) { - return JsonSerializer.Deserialize(responseBody); + try + { + return JsonUtils.Deserialize(responseBody)!; + } + catch (JsonException e) + { + throw new MergeException("Failed to deserialize response", e); + } } - throw new Exception(responseBody); + + throw new MergeApiException( + $"Error with status code {response.StatusCode}", + response.StatusCode, + JsonUtils.Deserialize(responseBody) + ); } } diff --git a/src/Merge.Client/Ats/FieldMapping/Requests/CreateFieldMappingRequest.cs b/src/Merge.Client/Ats/FieldMapping/Requests/CreateFieldMappingRequest.cs index e8c8ecdd..7af7e9e1 100644 --- a/src/Merge.Client/Ats/FieldMapping/Requests/CreateFieldMappingRequest.cs +++ b/src/Merge.Client/Ats/FieldMapping/Requests/CreateFieldMappingRequest.cs @@ -4,41 +4,41 @@ namespace Merge.Client.Ats; -public class CreateFieldMappingRequest +public record CreateFieldMappingRequest { /// /// The name of the target field you want this remote field to map to. /// [JsonPropertyName("target_field_name")] - public string TargetFieldName { get; init; } + public required string TargetFieldName { get; set; } /// /// The description of the target field you want this remote field to map to. /// [JsonPropertyName("target_field_description")] - public string TargetFieldDescription { get; init; } + public required string TargetFieldDescription { get; set; } /// /// The field traversal path of the remote field listed when you hit the GET /remote-fields endpoint. /// [JsonPropertyName("remote_field_traversal_path")] - public IEnumerable RemoteFieldTraversalPath { get; init; } + public IEnumerable RemoteFieldTraversalPath { get; set; } = new List(); /// /// The method of the remote endpoint where the remote field is coming from. /// [JsonPropertyName("remote_method")] - public string RemoteMethod { get; init; } + public required string RemoteMethod { get; set; } /// /// The path of the remote endpoint where the remote field is coming from. /// [JsonPropertyName("remote_url_path")] - public string RemoteUrlPath { get; init; } + public required string RemoteUrlPath { get; set; } /// /// The name of the Common Model that the remote field corresponds to in a given category. /// [JsonPropertyName("common_model_name")] - public string CommonModelName { get; init; } + public required string CommonModelName { get; set; } } diff --git a/src/Merge.Client/Ats/FieldMapping/Requests/PatchedEditFieldMappingRequest.cs b/src/Merge.Client/Ats/FieldMapping/Requests/PatchedEditFieldMappingRequest.cs index 5e1f12ed..cb1259ce 100644 --- a/src/Merge.Client/Ats/FieldMapping/Requests/PatchedEditFieldMappingRequest.cs +++ b/src/Merge.Client/Ats/FieldMapping/Requests/PatchedEditFieldMappingRequest.cs @@ -4,23 +4,23 @@ namespace Merge.Client.Ats; -public class PatchedEditFieldMappingRequest +public record PatchedEditFieldMappingRequest { /// /// The field traversal path of the remote field listed when you hit the GET /remote-fields endpoint. /// [JsonPropertyName("remote_field_traversal_path")] - public IEnumerable? RemoteFieldTraversalPath { get; init; } + public IEnumerable? RemoteFieldTraversalPath { get; set; } /// /// The method of the remote endpoint where the remote field is coming from. /// [JsonPropertyName("remote_method")] - public string? RemoteMethod { get; init; } + public string? RemoteMethod { get; set; } /// /// The path of the remote endpoint where the remote field is coming from. /// [JsonPropertyName("remote_url_path")] - public string? RemoteUrlPath { get; init; } + public string? RemoteUrlPath { get; set; } } diff --git a/src/Merge.Client/Ats/FieldMapping/Requests/RemoteFieldsRetrieveRequest.cs b/src/Merge.Client/Ats/FieldMapping/Requests/RemoteFieldsRetrieveRequest.cs index a143488d..eba8bb2c 100644 --- a/src/Merge.Client/Ats/FieldMapping/Requests/RemoteFieldsRetrieveRequest.cs +++ b/src/Merge.Client/Ats/FieldMapping/Requests/RemoteFieldsRetrieveRequest.cs @@ -1,14 +1,14 @@ namespace Merge.Client.Ats; -public class RemoteFieldsRetrieveRequest +public record RemoteFieldsRetrieveRequest { /// /// A comma seperated list of Common Model names. If included, will only return Remote Fields for those Common Models. /// - public string? CommonModels { get; init; } + public string? CommonModels { get; set; } /// /// If true, will include example values, where available, for remote fields in the 3rd party platform. These examples come from active data from your customers. /// - public string? IncludeExampleValues { get; init; } + public string? IncludeExampleValues { get; set; } } diff --git a/src/Merge.Client/Ats/ForceResync/ForceResyncClient.cs b/src/Merge.Client/Ats/ForceResync/ForceResyncClient.cs index a27b3ac9..9825ff33 100644 --- a/src/Merge.Client/Ats/ForceResync/ForceResyncClient.cs +++ b/src/Merge.Client/Ats/ForceResync/ForceResyncClient.cs @@ -1,6 +1,6 @@ +using System.Net.Http; using System.Text.Json; -using Merge.Client; -using Merge.Client.Ats; +using Merge.Client.Core; #nullable enable @@ -18,20 +18,36 @@ public ForceResyncClient(RawClient client) /// /// Force re-sync of all models. This is available for all organizations via the dashboard. Force re-sync is also available programmatically via API for monthly, quarterly, and highest sync frequency customers on the Launch, Professional, or Enterprise plans. Doing so will consume a sync credit for the relevant linked account. /// - public async Task> SyncStatusResyncCreateAsync() + public async Task> SyncStatusResyncCreateAsync( + RequestOptions? options = null + ) { var response = await _client.MakeRequestAsync( new RawClient.JsonApiRequest { + BaseUrl = _client.Options.BaseUrl, Method = HttpMethod.Post, - Path = "ats/v1/sync-status/resync" + Path = "ats/v1/sync-status/resync", + Options = options } ); - string responseBody = await response.Raw.Content.ReadAsStringAsync(); - if (response.StatusCode >= 200 && response.StatusCode < 400) + var responseBody = await response.Raw.Content.ReadAsStringAsync(); + if (response.StatusCode is >= 200 and < 400) { - return JsonSerializer.Deserialize>(responseBody); + try + { + return JsonUtils.Deserialize>(responseBody)!; + } + catch (JsonException e) + { + throw new MergeException("Failed to deserialize response", e); + } } - throw new Exception(responseBody); + + throw new MergeApiException( + $"Error with status code {response.StatusCode}", + response.StatusCode, + JsonUtils.Deserialize(responseBody) + ); } } diff --git a/src/Merge.Client/Ats/GenerateKey/GenerateKeyClient.cs b/src/Merge.Client/Ats/GenerateKey/GenerateKeyClient.cs index a73ea1de..2436d672 100644 --- a/src/Merge.Client/Ats/GenerateKey/GenerateKeyClient.cs +++ b/src/Merge.Client/Ats/GenerateKey/GenerateKeyClient.cs @@ -1,6 +1,6 @@ +using System.Net.Http; using System.Text.Json; -using Merge.Client; -using Merge.Client.Ats; +using Merge.Client.Core; #nullable enable @@ -18,21 +18,38 @@ public GenerateKeyClient(RawClient client) /// /// Create a remote key. /// - public async Task CreateAsync(GenerateRemoteKeyRequest request) + public async Task CreateAsync( + GenerateRemoteKeyRequest request, + RequestOptions? options = null + ) { var response = await _client.MakeRequestAsync( new RawClient.JsonApiRequest { + BaseUrl = _client.Options.BaseUrl, Method = HttpMethod.Post, Path = "ats/v1/generate-key", - Body = request + Body = request, + Options = options } ); - string responseBody = await response.Raw.Content.ReadAsStringAsync(); - if (response.StatusCode >= 200 && response.StatusCode < 400) + var responseBody = await response.Raw.Content.ReadAsStringAsync(); + if (response.StatusCode is >= 200 and < 400) { - return JsonSerializer.Deserialize(responseBody); + try + { + return JsonUtils.Deserialize(responseBody)!; + } + catch (JsonException e) + { + throw new MergeException("Failed to deserialize response", e); + } } - throw new Exception(responseBody); + + throw new MergeApiException( + $"Error with status code {response.StatusCode}", + response.StatusCode, + JsonUtils.Deserialize(responseBody) + ); } } diff --git a/src/Merge.Client/Ats/GenerateKey/Requests/GenerateRemoteKeyRequest.cs b/src/Merge.Client/Ats/GenerateKey/Requests/GenerateRemoteKeyRequest.cs index 6ae35eb6..b8bc4053 100644 --- a/src/Merge.Client/Ats/GenerateKey/Requests/GenerateRemoteKeyRequest.cs +++ b/src/Merge.Client/Ats/GenerateKey/Requests/GenerateRemoteKeyRequest.cs @@ -4,11 +4,11 @@ namespace Merge.Client.Ats; -public class GenerateRemoteKeyRequest +public record GenerateRemoteKeyRequest { /// /// The name of the remote key /// [JsonPropertyName("name")] - public string Name { get; init; } + public required string Name { get; set; } } diff --git a/src/Merge.Client/Ats/Interviews/InterviewsClient.cs b/src/Merge.Client/Ats/Interviews/InterviewsClient.cs index c64f68c6..7cfdd3ab 100644 --- a/src/Merge.Client/Ats/Interviews/InterviewsClient.cs +++ b/src/Merge.Client/Ats/Interviews/InterviewsClient.cs @@ -1,6 +1,6 @@ +using System.Net.Http; using System.Text.Json; -using Merge.Client; -using Merge.Client.Ats; +using Merge.Client.Core; #nullable enable @@ -18,7 +18,10 @@ public InterviewsClient(RawClient client) /// /// Returns a list of `ScheduledInterview` objects. /// - public async Task ListAsync(InterviewsListRequest request) + public async Task ListAsync( + InterviewsListRequest request, + RequestOptions? options = null + ) { var _query = new Dictionary() { }; if (request.ApplicationId != null) @@ -27,11 +30,13 @@ public async Task ListAsync(InterviewsListReque } if (request.CreatedAfter != null) { - _query["created_after"] = request.CreatedAfter.Value.ToString("o0"); + _query["created_after"] = request.CreatedAfter.Value.ToString(Constants.DateTimeFormat); } if (request.CreatedBefore != null) { - _query["created_before"] = request.CreatedBefore.Value.ToString("o0"); + _query["created_before"] = request.CreatedBefore.Value.ToString( + Constants.DateTimeFormat + ); } if (request.Cursor != null) { @@ -59,11 +64,15 @@ public async Task ListAsync(InterviewsListReque } if (request.ModifiedAfter != null) { - _query["modified_after"] = request.ModifiedAfter.Value.ToString("o0"); + _query["modified_after"] = request.ModifiedAfter.Value.ToString( + Constants.DateTimeFormat + ); } if (request.ModifiedBefore != null) { - _query["modified_before"] = request.ModifiedBefore.Value.ToString("o0"); + _query["modified_before"] = request.ModifiedBefore.Value.ToString( + Constants.DateTimeFormat + ); } if (request.OrganizerId != null) { @@ -88,24 +97,39 @@ public async Task ListAsync(InterviewsListReque var response = await _client.MakeRequestAsync( new RawClient.JsonApiRequest { + BaseUrl = _client.Options.BaseUrl, Method = HttpMethod.Get, Path = "ats/v1/interviews", - Query = _query + Query = _query, + Options = options } ); - string responseBody = await response.Raw.Content.ReadAsStringAsync(); - if (response.StatusCode >= 200 && response.StatusCode < 400) + var responseBody = await response.Raw.Content.ReadAsStringAsync(); + if (response.StatusCode is >= 200 and < 400) { - return JsonSerializer.Deserialize(responseBody); + try + { + return JsonUtils.Deserialize(responseBody)!; + } + catch (JsonException e) + { + throw new MergeException("Failed to deserialize response", e); + } } - throw new Exception(responseBody); + + throw new MergeApiException( + $"Error with status code {response.StatusCode}", + response.StatusCode, + JsonUtils.Deserialize(responseBody) + ); } /// /// Creates a `ScheduledInterview` object with the given values. /// public async Task CreateAsync( - ScheduledInterviewEndpointRequest request + ScheduledInterviewEndpointRequest request, + RequestOptions? options = null ) { var _query = new Dictionary() { }; @@ -120,17 +144,31 @@ ScheduledInterviewEndpointRequest request var response = await _client.MakeRequestAsync( new RawClient.JsonApiRequest { + BaseUrl = _client.Options.BaseUrl, Method = HttpMethod.Post, Path = "ats/v1/interviews", - Query = _query + Query = _query, + Options = options } ); - string responseBody = await response.Raw.Content.ReadAsStringAsync(); - if (response.StatusCode >= 200 && response.StatusCode < 400) + var responseBody = await response.Raw.Content.ReadAsStringAsync(); + if (response.StatusCode is >= 200 and < 400) { - return JsonSerializer.Deserialize(responseBody); + try + { + return JsonUtils.Deserialize(responseBody)!; + } + catch (JsonException e) + { + throw new MergeException("Failed to deserialize response", e); + } } - throw new Exception(responseBody); + + throw new MergeApiException( + $"Error with status code {response.StatusCode}", + response.StatusCode, + JsonUtils.Deserialize(responseBody) + ); } /// @@ -138,7 +176,8 @@ ScheduledInterviewEndpointRequest request /// public async Task RetrieveAsync( string id, - InterviewsRetrieveRequest request + InterviewsRetrieveRequest request, + RequestOptions? options = null ) { var _query = new Dictionary() { }; @@ -161,36 +200,64 @@ InterviewsRetrieveRequest request var response = await _client.MakeRequestAsync( new RawClient.JsonApiRequest { + BaseUrl = _client.Options.BaseUrl, Method = HttpMethod.Get, Path = $"ats/v1/interviews/{id}", - Query = _query + Query = _query, + Options = options } ); - string responseBody = await response.Raw.Content.ReadAsStringAsync(); - if (response.StatusCode >= 200 && response.StatusCode < 400) + var responseBody = await response.Raw.Content.ReadAsStringAsync(); + if (response.StatusCode is >= 200 and < 400) { - return JsonSerializer.Deserialize(responseBody); + try + { + return JsonUtils.Deserialize(responseBody)!; + } + catch (JsonException e) + { + throw new MergeException("Failed to deserialize response", e); + } } - throw new Exception(responseBody); + + throw new MergeApiException( + $"Error with status code {response.StatusCode}", + response.StatusCode, + JsonUtils.Deserialize(responseBody) + ); } /// /// Returns metadata for `ScheduledInterview` POSTs. /// - public async Task MetaPostRetrieveAsync() + public async Task MetaPostRetrieveAsync(RequestOptions? options = null) { var response = await _client.MakeRequestAsync( new RawClient.JsonApiRequest { + BaseUrl = _client.Options.BaseUrl, Method = HttpMethod.Get, - Path = "ats/v1/interviews/meta/post" + Path = "ats/v1/interviews/meta/post", + Options = options } ); - string responseBody = await response.Raw.Content.ReadAsStringAsync(); - if (response.StatusCode >= 200 && response.StatusCode < 400) + var responseBody = await response.Raw.Content.ReadAsStringAsync(); + if (response.StatusCode is >= 200 and < 400) { - return JsonSerializer.Deserialize(responseBody); + try + { + return JsonUtils.Deserialize(responseBody)!; + } + catch (JsonException e) + { + throw new MergeException("Failed to deserialize response", e); + } } - throw new Exception(responseBody); + + throw new MergeApiException( + $"Error with status code {response.StatusCode}", + response.StatusCode, + JsonUtils.Deserialize(responseBody) + ); } } diff --git a/src/Merge.Client/Ats/Interviews/Requests/InterviewsListRequest.cs b/src/Merge.Client/Ats/Interviews/Requests/InterviewsListRequest.cs index 687059e6..ea6df2c0 100644 --- a/src/Merge.Client/Ats/Interviews/Requests/InterviewsListRequest.cs +++ b/src/Merge.Client/Ats/Interviews/Requests/InterviewsListRequest.cs @@ -1,88 +1,84 @@ -using Merge.Client.Ats; - -#nullable enable - namespace Merge.Client.Ats; -public class InterviewsListRequest +public record InterviewsListRequest { /// /// If provided, will only return interviews for this application. /// - public string? ApplicationId { get; init; } + public string? ApplicationId { get; set; } /// /// If provided, will only return objects created after this datetime. /// - public DateTime? CreatedAfter { get; init; } + public DateTime? CreatedAfter { get; set; } /// /// If provided, will only return objects created before this datetime. /// - public DateTime? CreatedBefore { get; init; } + public DateTime? CreatedBefore { get; set; } /// /// The pagination cursor value. /// - public string? Cursor { get; init; } + public string? Cursor { get; set; } /// /// Which relations should be returned in expanded form. Multiple relation names should be comma separated without spaces. /// - public InterviewsListRequestExpand? Expand { get; init; } + public InterviewsListRequestExpand? Expand { get; set; } /// /// Whether to include data that was marked as deleted by third party webhooks. /// - public bool? IncludeDeletedData { get; init; } + public bool? IncludeDeletedData { get; set; } /// /// Whether to include the original data Merge fetched from the third-party to produce these models. /// - public bool? IncludeRemoteData { get; init; } + public bool? IncludeRemoteData { get; set; } /// /// If provided, wll only return interviews organized for this job. /// - public string? JobId { get; init; } + public string? JobId { get; set; } /// /// If provided, will only return interviews at this stage. /// - public string? JobInterviewStageId { get; init; } + public string? JobInterviewStageId { get; set; } /// /// If provided, only objects synced by Merge after this date time will be returned. /// - public DateTime? ModifiedAfter { get; init; } + public DateTime? ModifiedAfter { get; set; } /// /// If provided, only objects synced by Merge before this date time will be returned. /// - public DateTime? ModifiedBefore { get; init; } + public DateTime? ModifiedBefore { get; set; } /// /// If provided, will only return interviews organized by this user. /// - public string? OrganizerId { get; init; } + public string? OrganizerId { get; set; } /// /// Number of results to return per page. /// - public int? PageSize { get; init; } + public int? PageSize { get; set; } /// /// Deprecated. Use show_enum_origins. /// - public string? RemoteFields { get; init; } + public string? RemoteFields { get; set; } /// /// The API provider's ID for the given object. /// - public string? RemoteId { get; init; } + public string? RemoteId { get; set; } /// /// A comma separated list of enum field names for which you'd like the original values to be returned, instead of Merge's normalized enum values. [Learn more](https://help.merge.dev/en/articles/8950958-show_enum_origins-query-parameter) /// - public string? ShowEnumOrigins { get; init; } + public string? ShowEnumOrigins { get; set; } } diff --git a/src/Merge.Client/Ats/Interviews/Requests/InterviewsRetrieveRequest.cs b/src/Merge.Client/Ats/Interviews/Requests/InterviewsRetrieveRequest.cs index 5fb7e5da..30818adb 100644 --- a/src/Merge.Client/Ats/Interviews/Requests/InterviewsRetrieveRequest.cs +++ b/src/Merge.Client/Ats/Interviews/Requests/InterviewsRetrieveRequest.cs @@ -1,28 +1,24 @@ -using Merge.Client.Ats; - -#nullable enable - namespace Merge.Client.Ats; -public class InterviewsRetrieveRequest +public record InterviewsRetrieveRequest { /// /// Which relations should be returned in expanded form. Multiple relation names should be comma separated without spaces. /// - public InterviewsRetrieveRequestExpand? Expand { get; init; } + public InterviewsRetrieveRequestExpand? Expand { get; set; } /// /// Whether to include the original data Merge fetched from the third-party to produce these models. /// - public bool? IncludeRemoteData { get; init; } + public bool? IncludeRemoteData { get; set; } /// /// Deprecated. Use show_enum_origins. /// - public string? RemoteFields { get; init; } + public string? RemoteFields { get; set; } /// /// A comma separated list of enum field names for which you'd like the original values to be returned, instead of Merge's normalized enum values. [Learn more](https://help.merge.dev/en/articles/8950958-show_enum_origins-query-parameter) /// - public string? ShowEnumOrigins { get; init; } + public string? ShowEnumOrigins { get; set; } } diff --git a/src/Merge.Client/Ats/Interviews/Requests/ScheduledInterviewEndpointRequest.cs b/src/Merge.Client/Ats/Interviews/Requests/ScheduledInterviewEndpointRequest.cs index 98fd2e6d..8d5c8ec7 100644 --- a/src/Merge.Client/Ats/Interviews/Requests/ScheduledInterviewEndpointRequest.cs +++ b/src/Merge.Client/Ats/Interviews/Requests/ScheduledInterviewEndpointRequest.cs @@ -1,22 +1,18 @@ -using Merge.Client.Ats; - -#nullable enable - namespace Merge.Client.Ats; -public class ScheduledInterviewEndpointRequest +public record ScheduledInterviewEndpointRequest { /// /// Whether to include debug fields (such as log file links) in the response. /// - public bool? IsDebugMode { get; init; } + public bool? IsDebugMode { get; set; } /// /// Whether or not third-party updates should be run asynchronously. /// - public bool? RunAsync { get; init; } + public bool? RunAsync { get; set; } - public ScheduledInterviewRequest Model { get; init; } + public required ScheduledInterviewRequest Model { get; set; } - public string RemoteUserId { get; init; } + public required string RemoteUserId { get; set; } } diff --git a/src/Merge.Client/Ats/Interviews/Types/InterviewsListRequestExpand.cs b/src/Merge.Client/Ats/Interviews/Types/InterviewsListRequestExpand.cs index 24025d5a..4e5c08e1 100644 --- a/src/Merge.Client/Ats/Interviews/Types/InterviewsListRequestExpand.cs +++ b/src/Merge.Client/Ats/Interviews/Types/InterviewsListRequestExpand.cs @@ -1,6 +1,5 @@ using System.Runtime.Serialization; using System.Text.Json.Serialization; -using Merge.Client.Ats; using Merge.Client.Core; #nullable enable diff --git a/src/Merge.Client/Ats/Interviews/Types/InterviewsRetrieveRequestExpand.cs b/src/Merge.Client/Ats/Interviews/Types/InterviewsRetrieveRequestExpand.cs index 6e9713a3..2e765c76 100644 --- a/src/Merge.Client/Ats/Interviews/Types/InterviewsRetrieveRequestExpand.cs +++ b/src/Merge.Client/Ats/Interviews/Types/InterviewsRetrieveRequestExpand.cs @@ -1,6 +1,5 @@ using System.Runtime.Serialization; using System.Text.Json.Serialization; -using Merge.Client.Ats; using Merge.Client.Core; #nullable enable diff --git a/src/Merge.Client/Ats/Issues/IssuesClient.cs b/src/Merge.Client/Ats/Issues/IssuesClient.cs index 3421f3cc..624845e9 100644 --- a/src/Merge.Client/Ats/Issues/IssuesClient.cs +++ b/src/Merge.Client/Ats/Issues/IssuesClient.cs @@ -1,6 +1,6 @@ +using System.Net.Http; using System.Text.Json; -using Merge.Client; -using Merge.Client.Ats; +using Merge.Client.Core; #nullable enable @@ -18,7 +18,10 @@ public IssuesClient(RawClient client) /// /// Gets all issues for Organization. /// - public async Task ListAsync(IssuesListRequest request) + public async Task ListAsync( + IssuesListRequest request, + RequestOptions? options = null + ) { var _query = new Dictionary() { }; if (request.AccountToken != null) @@ -40,13 +43,13 @@ public async Task ListAsync(IssuesListRequest request) if (request.FirstIncidentTimeAfter != null) { _query["first_incident_time_after"] = request.FirstIncidentTimeAfter.Value.ToString( - "o0" + Constants.DateTimeFormat ); } if (request.FirstIncidentTimeBefore != null) { _query["first_incident_time_before"] = request.FirstIncidentTimeBefore.Value.ToString( - "o0" + Constants.DateTimeFormat ); } if (request.IncludeMuted != null) @@ -59,12 +62,14 @@ public async Task ListAsync(IssuesListRequest request) } if (request.LastIncidentTimeAfter != null) { - _query["last_incident_time_after"] = request.LastIncidentTimeAfter.Value.ToString("o0"); + _query["last_incident_time_after"] = request.LastIncidentTimeAfter.Value.ToString( + Constants.DateTimeFormat + ); } if (request.LastIncidentTimeBefore != null) { _query["last_incident_time_before"] = request.LastIncidentTimeBefore.Value.ToString( - "o0" + Constants.DateTimeFormat ); } if (request.LinkedAccountId != null) @@ -86,32 +91,64 @@ public async Task ListAsync(IssuesListRequest request) var response = await _client.MakeRequestAsync( new RawClient.JsonApiRequest { + BaseUrl = _client.Options.BaseUrl, Method = HttpMethod.Get, Path = "ats/v1/issues", - Query = _query + Query = _query, + Options = options } ); - string responseBody = await response.Raw.Content.ReadAsStringAsync(); - if (response.StatusCode >= 200 && response.StatusCode < 400) + var responseBody = await response.Raw.Content.ReadAsStringAsync(); + if (response.StatusCode is >= 200 and < 400) { - return JsonSerializer.Deserialize(responseBody); + try + { + return JsonUtils.Deserialize(responseBody)!; + } + catch (JsonException e) + { + throw new MergeException("Failed to deserialize response", e); + } } - throw new Exception(responseBody); + + throw new MergeApiException( + $"Error with status code {response.StatusCode}", + response.StatusCode, + JsonUtils.Deserialize(responseBody) + ); } /// /// Get a specific issue. /// - public async Task RetrieveAsync(string id) + public async Task RetrieveAsync(string id, RequestOptions? options = null) { var response = await _client.MakeRequestAsync( - new RawClient.JsonApiRequest { Method = HttpMethod.Get, Path = $"ats/v1/issues/{id}" } + new RawClient.JsonApiRequest + { + BaseUrl = _client.Options.BaseUrl, + Method = HttpMethod.Get, + Path = $"ats/v1/issues/{id}", + Options = options + } ); - string responseBody = await response.Raw.Content.ReadAsStringAsync(); - if (response.StatusCode >= 200 && response.StatusCode < 400) + var responseBody = await response.Raw.Content.ReadAsStringAsync(); + if (response.StatusCode is >= 200 and < 400) { - return JsonSerializer.Deserialize(responseBody); + try + { + return JsonUtils.Deserialize(responseBody)!; + } + catch (JsonException e) + { + throw new MergeException("Failed to deserialize response", e); + } } - throw new Exception(responseBody); + + throw new MergeApiException( + $"Error with status code {response.StatusCode}", + response.StatusCode, + JsonUtils.Deserialize(responseBody) + ); } } diff --git a/src/Merge.Client/Ats/Issues/Requests/IssuesListRequest.cs b/src/Merge.Client/Ats/Issues/Requests/IssuesListRequest.cs index b3051357..f9472892 100644 --- a/src/Merge.Client/Ats/Issues/Requests/IssuesListRequest.cs +++ b/src/Merge.Client/Ats/Issues/Requests/IssuesListRequest.cs @@ -1,66 +1,62 @@ -using Merge.Client.Ats; - -#nullable enable - namespace Merge.Client.Ats; -public class IssuesListRequest +public record IssuesListRequest { - public string? AccountToken { get; init; } + public string? AccountToken { get; set; } /// /// The pagination cursor value. /// - public string? Cursor { get; init; } + public string? Cursor { get; set; } /// /// If included, will only include issues whose most recent action occurred before this time /// - public string? EndDate { get; init; } + public string? EndDate { get; set; } - public string? EndUserOrganizationName { get; init; } + public string? EndUserOrganizationName { get; set; } /// /// If provided, will only return issues whose first incident time was after this datetime. /// - public DateTime? FirstIncidentTimeAfter { get; init; } + public DateTime? FirstIncidentTimeAfter { get; set; } /// /// If provided, will only return issues whose first incident time was before this datetime. /// - public DateTime? FirstIncidentTimeBefore { get; init; } + public DateTime? FirstIncidentTimeBefore { get; set; } /// /// If true, will include muted issues /// - public string? IncludeMuted { get; init; } + public string? IncludeMuted { get; set; } - public string? IntegrationName { get; init; } + public string? IntegrationName { get; set; } /// /// If provided, will only return issues whose last incident time was after this datetime. /// - public DateTime? LastIncidentTimeAfter { get; init; } + public DateTime? LastIncidentTimeAfter { get; set; } /// /// If provided, will only return issues whose last incident time was before this datetime. /// - public DateTime? LastIncidentTimeBefore { get; init; } + public DateTime? LastIncidentTimeBefore { get; set; } /// /// If provided, will only include issues pertaining to the linked account passed in. /// - public string? LinkedAccountId { get; init; } + public string? LinkedAccountId { get; set; } /// /// Number of results to return per page. /// - public int? PageSize { get; init; } + public int? PageSize { get; set; } /// /// If included, will only include issues whose most recent action occurred after this time /// - public string? StartDate { get; init; } + public string? StartDate { get; set; } /// /// Status of the issue. Options: ('ONGOING', 'RESOLVED') @@ -68,5 +64,5 @@ public class IssuesListRequest /// - `ONGOING` - ONGOING /// - `RESOLVED` - RESOLVED /// - public IssuesListRequestStatus? Status { get; init; } + public IssuesListRequestStatus? Status { get; set; } } diff --git a/src/Merge.Client/Ats/Issues/Types/IssuesListRequestStatus.cs b/src/Merge.Client/Ats/Issues/Types/IssuesListRequestStatus.cs index bd3915d6..04bb4d52 100644 --- a/src/Merge.Client/Ats/Issues/Types/IssuesListRequestStatus.cs +++ b/src/Merge.Client/Ats/Issues/Types/IssuesListRequestStatus.cs @@ -1,6 +1,5 @@ using System.Runtime.Serialization; using System.Text.Json.Serialization; -using Merge.Client.Ats; using Merge.Client.Core; #nullable enable diff --git a/src/Merge.Client/Ats/JobInterviewStages/JobInterviewStagesClient.cs b/src/Merge.Client/Ats/JobInterviewStages/JobInterviewStagesClient.cs index e853a859..8c0dce4b 100644 --- a/src/Merge.Client/Ats/JobInterviewStages/JobInterviewStagesClient.cs +++ b/src/Merge.Client/Ats/JobInterviewStages/JobInterviewStagesClient.cs @@ -1,6 +1,6 @@ +using System.Net.Http; using System.Text.Json; -using Merge.Client; -using Merge.Client.Ats; +using Merge.Client.Core; #nullable enable @@ -19,17 +19,20 @@ public JobInterviewStagesClient(RawClient client) /// Returns a list of `JobInterviewStage` objects. /// public async Task ListAsync( - JobInterviewStagesListRequest request + JobInterviewStagesListRequest request, + RequestOptions? options = null ) { var _query = new Dictionary() { }; if (request.CreatedAfter != null) { - _query["created_after"] = request.CreatedAfter.Value.ToString("o0"); + _query["created_after"] = request.CreatedAfter.Value.ToString(Constants.DateTimeFormat); } if (request.CreatedBefore != null) { - _query["created_before"] = request.CreatedBefore.Value.ToString("o0"); + _query["created_before"] = request.CreatedBefore.Value.ToString( + Constants.DateTimeFormat + ); } if (request.Cursor != null) { @@ -53,11 +56,15 @@ JobInterviewStagesListRequest request } if (request.ModifiedAfter != null) { - _query["modified_after"] = request.ModifiedAfter.Value.ToString("o0"); + _query["modified_after"] = request.ModifiedAfter.Value.ToString( + Constants.DateTimeFormat + ); } if (request.ModifiedBefore != null) { - _query["modified_before"] = request.ModifiedBefore.Value.ToString("o0"); + _query["modified_before"] = request.ModifiedBefore.Value.ToString( + Constants.DateTimeFormat + ); } if (request.PageSize != null) { @@ -70,17 +77,31 @@ JobInterviewStagesListRequest request var response = await _client.MakeRequestAsync( new RawClient.JsonApiRequest { + BaseUrl = _client.Options.BaseUrl, Method = HttpMethod.Get, Path = "ats/v1/job-interview-stages", - Query = _query + Query = _query, + Options = options } ); - string responseBody = await response.Raw.Content.ReadAsStringAsync(); - if (response.StatusCode >= 200 && response.StatusCode < 400) + var responseBody = await response.Raw.Content.ReadAsStringAsync(); + if (response.StatusCode is >= 200 and < 400) { - return JsonSerializer.Deserialize(responseBody); + try + { + return JsonUtils.Deserialize(responseBody)!; + } + catch (JsonException e) + { + throw new MergeException("Failed to deserialize response", e); + } } - throw new Exception(responseBody); + + throw new MergeApiException( + $"Error with status code {response.StatusCode}", + response.StatusCode, + JsonUtils.Deserialize(responseBody) + ); } /// @@ -88,7 +109,8 @@ JobInterviewStagesListRequest request /// public async Task RetrieveAsync( string id, - JobInterviewStagesRetrieveRequest request + JobInterviewStagesRetrieveRequest request, + RequestOptions? options = null ) { var _query = new Dictionary() { }; @@ -103,16 +125,30 @@ JobInterviewStagesRetrieveRequest request var response = await _client.MakeRequestAsync( new RawClient.JsonApiRequest { + BaseUrl = _client.Options.BaseUrl, Method = HttpMethod.Get, Path = $"ats/v1/job-interview-stages/{id}", - Query = _query + Query = _query, + Options = options } ); - string responseBody = await response.Raw.Content.ReadAsStringAsync(); - if (response.StatusCode >= 200 && response.StatusCode < 400) + var responseBody = await response.Raw.Content.ReadAsStringAsync(); + if (response.StatusCode is >= 200 and < 400) { - return JsonSerializer.Deserialize(responseBody); + try + { + return JsonUtils.Deserialize(responseBody)!; + } + catch (JsonException e) + { + throw new MergeException("Failed to deserialize response", e); + } } - throw new Exception(responseBody); + + throw new MergeApiException( + $"Error with status code {response.StatusCode}", + response.StatusCode, + JsonUtils.Deserialize(responseBody) + ); } } diff --git a/src/Merge.Client/Ats/JobInterviewStages/Requests/JobInterviewStagesListRequest.cs b/src/Merge.Client/Ats/JobInterviewStages/Requests/JobInterviewStagesListRequest.cs index 857b2579..03176946 100644 --- a/src/Merge.Client/Ats/JobInterviewStages/Requests/JobInterviewStagesListRequest.cs +++ b/src/Merge.Client/Ats/JobInterviewStages/Requests/JobInterviewStagesListRequest.cs @@ -1,59 +1,59 @@ namespace Merge.Client.Ats; -public class JobInterviewStagesListRequest +public record JobInterviewStagesListRequest { /// /// If provided, will only return objects created after this datetime. /// - public DateTime? CreatedAfter { get; init; } + public DateTime? CreatedAfter { get; set; } /// /// If provided, will only return objects created before this datetime. /// - public DateTime? CreatedBefore { get; init; } + public DateTime? CreatedBefore { get; set; } /// /// The pagination cursor value. /// - public string? Cursor { get; init; } + public string? Cursor { get; set; } /// /// Which relations should be returned in expanded form. Multiple relation names should be comma separated without spaces. /// - public string? Expand { get; init; } + public string? Expand { get; set; } /// /// Whether to include data that was marked as deleted by third party webhooks. /// - public bool? IncludeDeletedData { get; init; } + public bool? IncludeDeletedData { get; set; } /// /// Whether to include the original data Merge fetched from the third-party to produce these models. /// - public bool? IncludeRemoteData { get; init; } + public bool? IncludeRemoteData { get; set; } /// /// If provided, will only return interview stages for this job. /// - public string? JobId { get; init; } + public string? JobId { get; set; } /// /// If provided, only objects synced by Merge after this date time will be returned. /// - public DateTime? ModifiedAfter { get; init; } + public DateTime? ModifiedAfter { get; set; } /// /// If provided, only objects synced by Merge before this date time will be returned. /// - public DateTime? ModifiedBefore { get; init; } + public DateTime? ModifiedBefore { get; set; } /// /// Number of results to return per page. /// - public int? PageSize { get; init; } + public int? PageSize { get; set; } /// /// The API provider's ID for the given object. /// - public string? RemoteId { get; init; } + public string? RemoteId { get; set; } } diff --git a/src/Merge.Client/Ats/JobInterviewStages/Requests/JobInterviewStagesRetrieveRequest.cs b/src/Merge.Client/Ats/JobInterviewStages/Requests/JobInterviewStagesRetrieveRequest.cs index 1ebeb01c..f9595038 100644 --- a/src/Merge.Client/Ats/JobInterviewStages/Requests/JobInterviewStagesRetrieveRequest.cs +++ b/src/Merge.Client/Ats/JobInterviewStages/Requests/JobInterviewStagesRetrieveRequest.cs @@ -1,14 +1,14 @@ namespace Merge.Client.Ats; -public class JobInterviewStagesRetrieveRequest +public record JobInterviewStagesRetrieveRequest { /// /// Which relations should be returned in expanded form. Multiple relation names should be comma separated without spaces. /// - public string? Expand { get; init; } + public string? Expand { get; set; } /// /// Whether to include the original data Merge fetched from the third-party to produce these models. /// - public bool? IncludeRemoteData { get; init; } + public bool? IncludeRemoteData { get; set; } } diff --git a/src/Merge.Client/Ats/JobPostings/JobPostingsClient.cs b/src/Merge.Client/Ats/JobPostings/JobPostingsClient.cs index ddb5fc87..f96caaf8 100644 --- a/src/Merge.Client/Ats/JobPostings/JobPostingsClient.cs +++ b/src/Merge.Client/Ats/JobPostings/JobPostingsClient.cs @@ -1,6 +1,6 @@ +using System.Net.Http; using System.Text.Json; -using Merge.Client; -using Merge.Client.Ats; +using Merge.Client.Core; #nullable enable @@ -18,16 +18,21 @@ public JobPostingsClient(RawClient client) /// /// Returns a list of `JobPosting` objects. /// - public async Task ListAsync(JobPostingsListRequest request) + public async Task ListAsync( + JobPostingsListRequest request, + RequestOptions? options = null + ) { var _query = new Dictionary() { }; if (request.CreatedAfter != null) { - _query["created_after"] = request.CreatedAfter.Value.ToString("o0"); + _query["created_after"] = request.CreatedAfter.Value.ToString(Constants.DateTimeFormat); } if (request.CreatedBefore != null) { - _query["created_before"] = request.CreatedBefore.Value.ToString("o0"); + _query["created_before"] = request.CreatedBefore.Value.ToString( + Constants.DateTimeFormat + ); } if (request.Cursor != null) { @@ -47,11 +52,15 @@ public async Task ListAsync(JobPostingsListRequest requ } if (request.ModifiedAfter != null) { - _query["modified_after"] = request.ModifiedAfter.Value.ToString("o0"); + _query["modified_after"] = request.ModifiedAfter.Value.ToString( + Constants.DateTimeFormat + ); } if (request.ModifiedBefore != null) { - _query["modified_before"] = request.ModifiedBefore.Value.ToString("o0"); + _query["modified_before"] = request.ModifiedBefore.Value.ToString( + Constants.DateTimeFormat + ); } if (request.PageSize != null) { @@ -68,23 +77,41 @@ public async Task ListAsync(JobPostingsListRequest requ var response = await _client.MakeRequestAsync( new RawClient.JsonApiRequest { + BaseUrl = _client.Options.BaseUrl, Method = HttpMethod.Get, Path = "ats/v1/job-postings", - Query = _query + Query = _query, + Options = options } ); - string responseBody = await response.Raw.Content.ReadAsStringAsync(); - if (response.StatusCode >= 200 && response.StatusCode < 400) + var responseBody = await response.Raw.Content.ReadAsStringAsync(); + if (response.StatusCode is >= 200 and < 400) { - return JsonSerializer.Deserialize(responseBody); + try + { + return JsonUtils.Deserialize(responseBody)!; + } + catch (JsonException e) + { + throw new MergeException("Failed to deserialize response", e); + } } - throw new Exception(responseBody); + + throw new MergeApiException( + $"Error with status code {response.StatusCode}", + response.StatusCode, + JsonUtils.Deserialize(responseBody) + ); } /// /// Returns a `JobPosting` object with the given `id`. /// - public async Task RetrieveAsync(string id, JobPostingsRetrieveRequest request) + public async Task RetrieveAsync( + string id, + JobPostingsRetrieveRequest request, + RequestOptions? options = null + ) { var _query = new Dictionary() { }; if (request.Expand != null) @@ -98,16 +125,30 @@ public async Task RetrieveAsync(string id, JobPostingsRetrieveReques var response = await _client.MakeRequestAsync( new RawClient.JsonApiRequest { + BaseUrl = _client.Options.BaseUrl, Method = HttpMethod.Get, Path = $"ats/v1/job-postings/{id}", - Query = _query + Query = _query, + Options = options } ); - string responseBody = await response.Raw.Content.ReadAsStringAsync(); - if (response.StatusCode >= 200 && response.StatusCode < 400) + var responseBody = await response.Raw.Content.ReadAsStringAsync(); + if (response.StatusCode is >= 200 and < 400) { - return JsonSerializer.Deserialize(responseBody); + try + { + return JsonUtils.Deserialize(responseBody)!; + } + catch (JsonException e) + { + throw new MergeException("Failed to deserialize response", e); + } } - throw new Exception(responseBody); + + throw new MergeApiException( + $"Error with status code {response.StatusCode}", + response.StatusCode, + JsonUtils.Deserialize(responseBody) + ); } } diff --git a/src/Merge.Client/Ats/JobPostings/Requests/JobPostingsListRequest.cs b/src/Merge.Client/Ats/JobPostings/Requests/JobPostingsListRequest.cs index cefd296f..7c308e25 100644 --- a/src/Merge.Client/Ats/JobPostings/Requests/JobPostingsListRequest.cs +++ b/src/Merge.Client/Ats/JobPostings/Requests/JobPostingsListRequest.cs @@ -1,60 +1,56 @@ -using Merge.Client.Ats; - -#nullable enable - namespace Merge.Client.Ats; -public class JobPostingsListRequest +public record JobPostingsListRequest { /// /// If provided, will only return objects created after this datetime. /// - public DateTime? CreatedAfter { get; init; } + public DateTime? CreatedAfter { get; set; } /// /// If provided, will only return objects created before this datetime. /// - public DateTime? CreatedBefore { get; init; } + public DateTime? CreatedBefore { get; set; } /// /// The pagination cursor value. /// - public string? Cursor { get; init; } + public string? Cursor { get; set; } /// /// Which relations should be returned in expanded form. Multiple relation names should be comma separated without spaces. /// - public string? Expand { get; init; } + public string? Expand { get; set; } /// /// Whether to include data that was marked as deleted by third party webhooks. /// - public bool? IncludeDeletedData { get; init; } + public bool? IncludeDeletedData { get; set; } /// /// Whether to include the original data Merge fetched from the third-party to produce these models. /// - public bool? IncludeRemoteData { get; init; } + public bool? IncludeRemoteData { get; set; } /// /// If provided, only objects synced by Merge after this date time will be returned. /// - public DateTime? ModifiedAfter { get; init; } + public DateTime? ModifiedAfter { get; set; } /// /// If provided, only objects synced by Merge before this date time will be returned. /// - public DateTime? ModifiedBefore { get; init; } + public DateTime? ModifiedBefore { get; set; } /// /// Number of results to return per page. /// - public int? PageSize { get; init; } + public int? PageSize { get; set; } /// /// The API provider's ID for the given object. /// - public string? RemoteId { get; init; } + public string? RemoteId { get; set; } /// /// If provided, will only return Job Postings with this status. Options: ('PUBLISHED', 'CLOSED', 'DRAFT', 'INTERNAL', 'PENDING') @@ -65,5 +61,5 @@ public class JobPostingsListRequest /// - `INTERNAL` - INTERNAL /// - `PENDING` - PENDING /// - public JobPostingsListRequestStatus? Status { get; init; } + public JobPostingsListRequestStatus? Status { get; set; } } diff --git a/src/Merge.Client/Ats/JobPostings/Requests/JobPostingsRetrieveRequest.cs b/src/Merge.Client/Ats/JobPostings/Requests/JobPostingsRetrieveRequest.cs index f3d1b08e..7d5d9c2f 100644 --- a/src/Merge.Client/Ats/JobPostings/Requests/JobPostingsRetrieveRequest.cs +++ b/src/Merge.Client/Ats/JobPostings/Requests/JobPostingsRetrieveRequest.cs @@ -1,14 +1,14 @@ namespace Merge.Client.Ats; -public class JobPostingsRetrieveRequest +public record JobPostingsRetrieveRequest { /// /// Which relations should be returned in expanded form. Multiple relation names should be comma separated without spaces. /// - public string? Expand { get; init; } + public string? Expand { get; set; } /// /// Whether to include the original data Merge fetched from the third-party to produce these models. /// - public bool? IncludeRemoteData { get; init; } + public bool? IncludeRemoteData { get; set; } } diff --git a/src/Merge.Client/Ats/JobPostings/Types/JobPostingsListRequestStatus.cs b/src/Merge.Client/Ats/JobPostings/Types/JobPostingsListRequestStatus.cs index e6c0975d..0a7fa525 100644 --- a/src/Merge.Client/Ats/JobPostings/Types/JobPostingsListRequestStatus.cs +++ b/src/Merge.Client/Ats/JobPostings/Types/JobPostingsListRequestStatus.cs @@ -1,6 +1,5 @@ using System.Runtime.Serialization; using System.Text.Json.Serialization; -using Merge.Client.Ats; using Merge.Client.Core; #nullable enable diff --git a/src/Merge.Client/Ats/Jobs/JobsClient.cs b/src/Merge.Client/Ats/Jobs/JobsClient.cs index 79befac6..7e3fa495 100644 --- a/src/Merge.Client/Ats/Jobs/JobsClient.cs +++ b/src/Merge.Client/Ats/Jobs/JobsClient.cs @@ -1,6 +1,6 @@ +using System.Net.Http; using System.Text.Json; -using Merge.Client; -using Merge.Client.Ats; +using Merge.Client.Core; #nullable enable @@ -18,7 +18,10 @@ public JobsClient(RawClient client) /// /// Returns a list of `Job` objects. /// - public async Task ListAsync(JobsListRequest request) + public async Task ListAsync( + JobsListRequest request, + RequestOptions? options = null + ) { var _query = new Dictionary() { }; if (request.Code != null) @@ -27,11 +30,13 @@ public async Task ListAsync(JobsListRequest request) } if (request.CreatedAfter != null) { - _query["created_after"] = request.CreatedAfter.Value.ToString("o0"); + _query["created_after"] = request.CreatedAfter.Value.ToString(Constants.DateTimeFormat); } if (request.CreatedBefore != null) { - _query["created_before"] = request.CreatedBefore.Value.ToString("o0"); + _query["created_before"] = request.CreatedBefore.Value.ToString( + Constants.DateTimeFormat + ); } if (request.Cursor != null) { @@ -51,11 +56,15 @@ public async Task ListAsync(JobsListRequest request) } if (request.ModifiedAfter != null) { - _query["modified_after"] = request.ModifiedAfter.Value.ToString("o0"); + _query["modified_after"] = request.ModifiedAfter.Value.ToString( + Constants.DateTimeFormat + ); } if (request.ModifiedBefore != null) { - _query["modified_before"] = request.ModifiedBefore.Value.ToString("o0"); + _query["modified_before"] = request.ModifiedBefore.Value.ToString( + Constants.DateTimeFormat + ); } if (request.Offices != null) { @@ -84,23 +93,41 @@ public async Task ListAsync(JobsListRequest request) var response = await _client.MakeRequestAsync( new RawClient.JsonApiRequest { + BaseUrl = _client.Options.BaseUrl, Method = HttpMethod.Get, Path = "ats/v1/jobs", - Query = _query + Query = _query, + Options = options } ); - string responseBody = await response.Raw.Content.ReadAsStringAsync(); - if (response.StatusCode >= 200 && response.StatusCode < 400) + var responseBody = await response.Raw.Content.ReadAsStringAsync(); + if (response.StatusCode is >= 200 and < 400) { - return JsonSerializer.Deserialize(responseBody); + try + { + return JsonUtils.Deserialize(responseBody)!; + } + catch (JsonException e) + { + throw new MergeException("Failed to deserialize response", e); + } } - throw new Exception(responseBody); + + throw new MergeApiException( + $"Error with status code {response.StatusCode}", + response.StatusCode, + JsonUtils.Deserialize(responseBody) + ); } /// /// Returns a `Job` object with the given `id`. /// - public async Task RetrieveAsync(string id, JobsRetrieveRequest request) + public async Task RetrieveAsync( + string id, + JobsRetrieveRequest request, + RequestOptions? options = null + ) { var _query = new Dictionary() { }; if (request.Expand != null) @@ -122,17 +149,31 @@ public async Task RetrieveAsync(string id, JobsRetrieveRequest request) var response = await _client.MakeRequestAsync( new RawClient.JsonApiRequest { + BaseUrl = _client.Options.BaseUrl, Method = HttpMethod.Get, Path = $"ats/v1/jobs/{id}", - Query = _query + Query = _query, + Options = options } ); - string responseBody = await response.Raw.Content.ReadAsStringAsync(); - if (response.StatusCode >= 200 && response.StatusCode < 400) + var responseBody = await response.Raw.Content.ReadAsStringAsync(); + if (response.StatusCode is >= 200 and < 400) { - return JsonSerializer.Deserialize(responseBody); + try + { + return JsonUtils.Deserialize(responseBody)!; + } + catch (JsonException e) + { + throw new MergeException("Failed to deserialize response", e); + } } - throw new Exception(responseBody); + + throw new MergeApiException( + $"Error with status code {response.StatusCode}", + response.StatusCode, + JsonUtils.Deserialize(responseBody) + ); } /// @@ -140,7 +181,8 @@ public async Task RetrieveAsync(string id, JobsRetrieveRequest request) /// public async Task ScreeningQuestionsListAsync( string jobId, - JobsScreeningQuestionsListRequest request + JobsScreeningQuestionsListRequest request, + RequestOptions? options = null ) { var _query = new Dictionary() { }; @@ -167,16 +209,30 @@ JobsScreeningQuestionsListRequest request var response = await _client.MakeRequestAsync( new RawClient.JsonApiRequest { + BaseUrl = _client.Options.BaseUrl, Method = HttpMethod.Get, Path = $"ats/v1/jobs/{jobId}/screening-questions", - Query = _query + Query = _query, + Options = options } ); - string responseBody = await response.Raw.Content.ReadAsStringAsync(); - if (response.StatusCode >= 200 && response.StatusCode < 400) + var responseBody = await response.Raw.Content.ReadAsStringAsync(); + if (response.StatusCode is >= 200 and < 400) { - return JsonSerializer.Deserialize(responseBody); + try + { + return JsonUtils.Deserialize(responseBody)!; + } + catch (JsonException e) + { + throw new MergeException("Failed to deserialize response", e); + } } - throw new Exception(responseBody); + + throw new MergeApiException( + $"Error with status code {response.StatusCode}", + response.StatusCode, + JsonUtils.Deserialize(responseBody) + ); } } diff --git a/src/Merge.Client/Ats/Jobs/Requests/JobsListRequest.cs b/src/Merge.Client/Ats/Jobs/Requests/JobsListRequest.cs index 49816442..7b7c2d41 100644 --- a/src/Merge.Client/Ats/Jobs/Requests/JobsListRequest.cs +++ b/src/Merge.Client/Ats/Jobs/Requests/JobsListRequest.cs @@ -1,80 +1,76 @@ -using Merge.Client.Ats; - -#nullable enable - namespace Merge.Client.Ats; -public class JobsListRequest +public record JobsListRequest { /// /// If provided, will only return jobs with this code. /// - public string? Code { get; init; } + public string? Code { get; set; } /// /// If provided, will only return objects created after this datetime. /// - public DateTime? CreatedAfter { get; init; } + public DateTime? CreatedAfter { get; set; } /// /// If provided, will only return objects created before this datetime. /// - public DateTime? CreatedBefore { get; init; } + public DateTime? CreatedBefore { get; set; } /// /// The pagination cursor value. /// - public string? Cursor { get; init; } + public string? Cursor { get; set; } /// /// Which relations should be returned in expanded form. Multiple relation names should be comma separated without spaces. /// - public JobsListRequestExpand? Expand { get; init; } + public JobsListRequestExpand? Expand { get; set; } /// /// Whether to include data that was marked as deleted by third party webhooks. /// - public bool? IncludeDeletedData { get; init; } + public bool? IncludeDeletedData { get; set; } /// /// Whether to include the original data Merge fetched from the third-party to produce these models. /// - public bool? IncludeRemoteData { get; init; } + public bool? IncludeRemoteData { get; set; } /// /// If provided, only objects synced by Merge after this date time will be returned. /// - public DateTime? ModifiedAfter { get; init; } + public DateTime? ModifiedAfter { get; set; } /// /// If provided, only objects synced by Merge before this date time will be returned. /// - public DateTime? ModifiedBefore { get; init; } + public DateTime? ModifiedBefore { get; set; } /// /// If provided, will only return jobs for this office; multiple offices can be separated by commas. /// - public string? Offices { get; init; } + public string? Offices { get; set; } /// /// Number of results to return per page. /// - public int? PageSize { get; init; } + public int? PageSize { get; set; } /// /// Deprecated. Use show_enum_origins. /// - public string? RemoteFields { get; init; } + public string? RemoteFields { get; set; } /// /// The API provider's ID for the given object. /// - public string? RemoteId { get; init; } + public string? RemoteId { get; set; } /// /// A comma separated list of enum field names for which you'd like the original values to be returned, instead of Merge's normalized enum values. [Learn more](https://help.merge.dev/en/articles/8950958-show_enum_origins-query-parameter) /// - public string? ShowEnumOrigins { get; init; } + public string? ShowEnumOrigins { get; set; } /// /// If provided, will only return jobs with this status. Options: ('OPEN', 'CLOSED', 'DRAFT', 'ARCHIVED', 'PENDING') @@ -85,5 +81,5 @@ public class JobsListRequest /// - `ARCHIVED` - ARCHIVED /// - `PENDING` - PENDING /// - public JobsListRequestStatus? Status { get; init; } + public JobsListRequestStatus? Status { get; set; } } diff --git a/src/Merge.Client/Ats/Jobs/Requests/JobsRetrieveRequest.cs b/src/Merge.Client/Ats/Jobs/Requests/JobsRetrieveRequest.cs index 62a0b3dd..8440825f 100644 --- a/src/Merge.Client/Ats/Jobs/Requests/JobsRetrieveRequest.cs +++ b/src/Merge.Client/Ats/Jobs/Requests/JobsRetrieveRequest.cs @@ -1,28 +1,24 @@ -using Merge.Client.Ats; - -#nullable enable - namespace Merge.Client.Ats; -public class JobsRetrieveRequest +public record JobsRetrieveRequest { /// /// Which relations should be returned in expanded form. Multiple relation names should be comma separated without spaces. /// - public JobsRetrieveRequestExpand? Expand { get; init; } + public JobsRetrieveRequestExpand? Expand { get; set; } /// /// Whether to include the original data Merge fetched from the third-party to produce these models. /// - public bool? IncludeRemoteData { get; init; } + public bool? IncludeRemoteData { get; set; } /// /// Deprecated. Use show_enum_origins. /// - public string? RemoteFields { get; init; } + public string? RemoteFields { get; set; } /// /// A comma separated list of enum field names for which you'd like the original values to be returned, instead of Merge's normalized enum values. [Learn more](https://help.merge.dev/en/articles/8950958-show_enum_origins-query-parameter) /// - public string? ShowEnumOrigins { get; init; } + public string? ShowEnumOrigins { get; set; } } diff --git a/src/Merge.Client/Ats/Jobs/Requests/JobsScreeningQuestionsListRequest.cs b/src/Merge.Client/Ats/Jobs/Requests/JobsScreeningQuestionsListRequest.cs index a9f6173b..92682a79 100644 --- a/src/Merge.Client/Ats/Jobs/Requests/JobsScreeningQuestionsListRequest.cs +++ b/src/Merge.Client/Ats/Jobs/Requests/JobsScreeningQuestionsListRequest.cs @@ -1,33 +1,29 @@ -using Merge.Client.Ats; - -#nullable enable - namespace Merge.Client.Ats; -public class JobsScreeningQuestionsListRequest +public record JobsScreeningQuestionsListRequest { /// /// The pagination cursor value. /// - public string? Cursor { get; init; } + public string? Cursor { get; set; } /// /// Which relations should be returned in expanded form. Multiple relation names should be comma separated without spaces. /// - public JobsScreeningQuestionsListRequestExpand? Expand { get; init; } + public JobsScreeningQuestionsListRequestExpand? Expand { get; set; } /// /// Whether to include data that was marked as deleted by third party webhooks. /// - public bool? IncludeDeletedData { get; init; } + public bool? IncludeDeletedData { get; set; } /// /// Whether to include the original data Merge fetched from the third-party to produce these models. /// - public bool? IncludeRemoteData { get; init; } + public bool? IncludeRemoteData { get; set; } /// /// Number of results to return per page. /// - public int? PageSize { get; init; } + public int? PageSize { get; set; } } diff --git a/src/Merge.Client/Ats/Jobs/Types/JobsListRequestExpand.cs b/src/Merge.Client/Ats/Jobs/Types/JobsListRequestExpand.cs index 0547ad88..67a77409 100644 --- a/src/Merge.Client/Ats/Jobs/Types/JobsListRequestExpand.cs +++ b/src/Merge.Client/Ats/Jobs/Types/JobsListRequestExpand.cs @@ -1,6 +1,5 @@ using System.Runtime.Serialization; using System.Text.Json.Serialization; -using Merge.Client.Ats; using Merge.Client.Core; #nullable enable diff --git a/src/Merge.Client/Ats/Jobs/Types/JobsListRequestStatus.cs b/src/Merge.Client/Ats/Jobs/Types/JobsListRequestStatus.cs index db721be7..5fcbf46e 100644 --- a/src/Merge.Client/Ats/Jobs/Types/JobsListRequestStatus.cs +++ b/src/Merge.Client/Ats/Jobs/Types/JobsListRequestStatus.cs @@ -1,6 +1,5 @@ using System.Runtime.Serialization; using System.Text.Json.Serialization; -using Merge.Client.Ats; using Merge.Client.Core; #nullable enable diff --git a/src/Merge.Client/Ats/Jobs/Types/JobsRetrieveRequestExpand.cs b/src/Merge.Client/Ats/Jobs/Types/JobsRetrieveRequestExpand.cs index 6f0362e0..f6848e20 100644 --- a/src/Merge.Client/Ats/Jobs/Types/JobsRetrieveRequestExpand.cs +++ b/src/Merge.Client/Ats/Jobs/Types/JobsRetrieveRequestExpand.cs @@ -1,6 +1,5 @@ using System.Runtime.Serialization; using System.Text.Json.Serialization; -using Merge.Client.Ats; using Merge.Client.Core; #nullable enable diff --git a/src/Merge.Client/Ats/Jobs/Types/JobsScreeningQuestionsListRequestExpand.cs b/src/Merge.Client/Ats/Jobs/Types/JobsScreeningQuestionsListRequestExpand.cs index 55bfe545..df3fdfaf 100644 --- a/src/Merge.Client/Ats/Jobs/Types/JobsScreeningQuestionsListRequestExpand.cs +++ b/src/Merge.Client/Ats/Jobs/Types/JobsScreeningQuestionsListRequestExpand.cs @@ -1,6 +1,5 @@ using System.Runtime.Serialization; using System.Text.Json.Serialization; -using Merge.Client.Ats; using Merge.Client.Core; #nullable enable diff --git a/src/Merge.Client/Ats/LinkToken/LinkTokenClient.cs b/src/Merge.Client/Ats/LinkToken/LinkTokenClient.cs index dfe0239e..cd7f4336 100644 --- a/src/Merge.Client/Ats/LinkToken/LinkTokenClient.cs +++ b/src/Merge.Client/Ats/LinkToken/LinkTokenClient.cs @@ -1,6 +1,6 @@ +using System.Net.Http; using System.Text.Json; -using Merge.Client; -using Merge.Client.Ats; +using Merge.Client.Core; #nullable enable @@ -18,21 +18,38 @@ public LinkTokenClient(RawClient client) /// /// Creates a link token to be used when linking a new end user. /// - public async Task CreateAsync(EndUserDetailsRequest request) + public async Task CreateAsync( + EndUserDetailsRequest request, + RequestOptions? options = null + ) { var response = await _client.MakeRequestAsync( new RawClient.JsonApiRequest { + BaseUrl = _client.Options.BaseUrl, Method = HttpMethod.Post, Path = "ats/v1/link-token", - Body = request + Body = request, + Options = options } ); - string responseBody = await response.Raw.Content.ReadAsStringAsync(); - if (response.StatusCode >= 200 && response.StatusCode < 400) + var responseBody = await response.Raw.Content.ReadAsStringAsync(); + if (response.StatusCode is >= 200 and < 400) { - return JsonSerializer.Deserialize(responseBody); + try + { + return JsonUtils.Deserialize(responseBody)!; + } + catch (JsonException e) + { + throw new MergeException("Failed to deserialize response", e); + } } - throw new Exception(responseBody); + + throw new MergeApiException( + $"Error with status code {response.StatusCode}", + response.StatusCode, + JsonUtils.Deserialize(responseBody) + ); } } diff --git a/src/Merge.Client/Ats/LinkToken/Requests/EndUserDetailsRequest.cs b/src/Merge.Client/Ats/LinkToken/Requests/EndUserDetailsRequest.cs index 82b7210f..e878067a 100644 --- a/src/Merge.Client/Ats/LinkToken/Requests/EndUserDetailsRequest.cs +++ b/src/Merge.Client/Ats/LinkToken/Requests/EndUserDetailsRequest.cs @@ -1,65 +1,64 @@ using System.Text.Json.Serialization; -using Merge.Client.Ats; #nullable enable namespace Merge.Client.Ats; -public class EndUserDetailsRequest +public record EndUserDetailsRequest { /// /// Your end user's email address. This is purely for identification purposes - setting this value will not cause any emails to be sent. /// [JsonPropertyName("end_user_email_address")] - public string EndUserEmailAddress { get; init; } + public required string EndUserEmailAddress { get; set; } /// /// Your end user's organization. /// [JsonPropertyName("end_user_organization_name")] - public string EndUserOrganizationName { get; init; } + public required string EndUserOrganizationName { get; set; } /// /// This unique identifier typically represents the ID for your end user in your product's database. This value must be distinct from other Linked Accounts' unique identifiers. /// [JsonPropertyName("end_user_origin_id")] - public string EndUserOriginId { get; init; } + public required string EndUserOriginId { get; set; } /// /// The integration categories to show in Merge Link. /// [JsonPropertyName("categories")] - public IEnumerable Categories { get; init; } + public IEnumerable Categories { get; set; } = new List(); /// /// The slug of a specific pre-selected integration for this linking flow token. For examples of slugs, see https://docs.merge.dev/guides/merge-link/single-integration/. /// [JsonPropertyName("integration")] - public string? Integration { get; init; } + public string? Integration { get; set; } /// /// An integer number of minutes between [30, 720 or 10080 if for a Magic Link URL] for how long this token is valid. Defaults to 30. /// [JsonPropertyName("link_expiry_mins")] - public int? LinkExpiryMins { get; init; } + public int? LinkExpiryMins { get; set; } /// /// Whether to generate a Magic Link URL. Defaults to false. For more information on Magic Link, see https://merge.dev/blog/integrations-fast-say-hello-to-magic-link. /// [JsonPropertyName("should_create_magic_link_url")] - public bool? ShouldCreateMagicLinkUrl { get; init; } + public bool? ShouldCreateMagicLinkUrl { get; set; } /// /// Whether to generate a Magic Link URL on the Admin Needed screen during the linking flow. Defaults to false. For more information on Magic Link, see https://merge.dev/blog/integrations-fast-say-hello-to-magic-link. /// [JsonPropertyName("hide_admin_magic_link")] - public bool? HideAdminMagicLink { get; init; } + public bool? HideAdminMagicLink { get; set; } /// /// An array of objects to specify the models and fields that will be disabled for a given Linked Account. Each object uses model_id, enabled_actions, and disabled_fields to specify the model, method, and fields that are scoped for a given Linked Account. /// [JsonPropertyName("common_models")] - public IEnumerable? CommonModels { get; init; } + public IEnumerable? CommonModels { get; set; } /// /// When creating a Link Token, you can set permissions for Common Models that will apply to the account that is going to be linked. Any model or field not specified in link token payload will default to existing settings. @@ -68,17 +67,17 @@ public class EndUserDetailsRequest public Dictionary< string, IEnumerable? - >? CategoryCommonModelScopes { get; init; } + >? CategoryCommonModelScopes { get; set; } /// /// The language code for the language to localize Merge Link to. /// [JsonPropertyName("language")] - public string? Language { get; init; } + public string? Language { get; set; } /// /// A JSON object containing integration-specific configuration options. /// [JsonPropertyName("integration_specific_config")] - public Dictionary? IntegrationSpecificConfig { get; init; } + public Dictionary? IntegrationSpecificConfig { get; set; } } diff --git a/src/Merge.Client/Ats/LinkedAccounts/LinkedAccountsClient.cs b/src/Merge.Client/Ats/LinkedAccounts/LinkedAccountsClient.cs index 5e601afd..29df5ce5 100644 --- a/src/Merge.Client/Ats/LinkedAccounts/LinkedAccountsClient.cs +++ b/src/Merge.Client/Ats/LinkedAccounts/LinkedAccountsClient.cs @@ -1,6 +1,6 @@ +using System.Net.Http; using System.Text.Json; -using Merge.Client; -using Merge.Client.Ats; +using Merge.Client.Core; #nullable enable @@ -19,7 +19,8 @@ public LinkedAccountsClient(RawClient client) /// List linked accounts for your organization. /// public async Task ListAsync( - LinkedAccountsListRequest request + LinkedAccountsListRequest request, + RequestOptions? options = null ) { var _query = new Dictionary() { }; @@ -78,16 +79,30 @@ LinkedAccountsListRequest request var response = await _client.MakeRequestAsync( new RawClient.JsonApiRequest { + BaseUrl = _client.Options.BaseUrl, Method = HttpMethod.Get, Path = "ats/v1/linked-accounts", - Query = _query + Query = _query, + Options = options } ); - string responseBody = await response.Raw.Content.ReadAsStringAsync(); - if (response.StatusCode >= 200 && response.StatusCode < 400) + var responseBody = await response.Raw.Content.ReadAsStringAsync(); + if (response.StatusCode is >= 200 and < 400) { - return JsonSerializer.Deserialize(responseBody); + try + { + return JsonUtils.Deserialize(responseBody)!; + } + catch (JsonException e) + { + throw new MergeException("Failed to deserialize response", e); + } } - throw new Exception(responseBody); + + throw new MergeApiException( + $"Error with status code {response.StatusCode}", + response.StatusCode, + JsonUtils.Deserialize(responseBody) + ); } } diff --git a/src/Merge.Client/Ats/LinkedAccounts/Requests/LinkedAccountsListRequest.cs b/src/Merge.Client/Ats/LinkedAccounts/Requests/LinkedAccountsListRequest.cs index d3423b21..5aa4f998 100644 --- a/src/Merge.Client/Ats/LinkedAccounts/Requests/LinkedAccountsListRequest.cs +++ b/src/Merge.Client/Ats/LinkedAccounts/Requests/LinkedAccountsListRequest.cs @@ -1,10 +1,6 @@ -using Merge.Client.Ats; - -#nullable enable - namespace Merge.Client.Ats; -public class LinkedAccountsListRequest +public record LinkedAccountsListRequest { /// /// Options: `accounting`, `ats`, `crm`, `filestorage`, `hris`, `mktg`, `ticketing` @@ -17,62 +13,62 @@ public class LinkedAccountsListRequest /// - `mktg` - mktg /// - `filestorage` - filestorage /// - public LinkedAccountsListRequestCategory? Category { get; init; } + public LinkedAccountsListRequestCategory? Category { get; set; } /// /// The pagination cursor value. /// - public string? Cursor { get; init; } + public string? Cursor { get; set; } /// /// If provided, will only return linked accounts associated with the given email address. /// - public string? EndUserEmailAddress { get; init; } + public string? EndUserEmailAddress { get; set; } /// /// If provided, will only return linked accounts associated with the given organization name. /// - public string? EndUserOrganizationName { get; init; } + public string? EndUserOrganizationName { get; set; } /// /// If provided, will only return linked accounts associated with the given origin ID. /// - public string? EndUserOriginId { get; init; } + public string? EndUserOriginId { get; set; } /// /// Comma-separated list of EndUser origin IDs, making it possible to specify multiple EndUsers at once. /// - public string? EndUserOriginIds { get; init; } + public string? EndUserOriginIds { get; set; } - public string? Id { get; init; } + public string? Id { get; set; } /// /// Comma-separated list of LinkedAccount IDs, making it possible to specify multiple LinkedAccounts at once. /// - public string? Ids { get; init; } + public string? Ids { get; set; } /// /// If `true`, will include complete production duplicates of the account specified by the `id` query parameter in the response. `id` must be for a complete production linked account. /// - public bool? IncludeDuplicates { get; init; } + public bool? IncludeDuplicates { get; set; } /// /// If provided, will only return linked accounts associated with the given integration name. /// - public string? IntegrationName { get; init; } + public string? IntegrationName { get; set; } /// /// If included, will only include test linked accounts. If not included, will only include non-test linked accounts. /// - public string? IsTestAccount { get; init; } + public string? IsTestAccount { get; set; } /// /// Number of results to return per page. /// - public int? PageSize { get; init; } + public int? PageSize { get; set; } /// /// Filter by status. Options: `COMPLETE`, `INCOMPLETE`, `RELINK_NEEDED` /// - public string? Status { get; init; } + public string? Status { get; set; } } diff --git a/src/Merge.Client/Ats/LinkedAccounts/Types/LinkedAccountsListRequestCategory.cs b/src/Merge.Client/Ats/LinkedAccounts/Types/LinkedAccountsListRequestCategory.cs index e18cbabf..893860bc 100644 --- a/src/Merge.Client/Ats/LinkedAccounts/Types/LinkedAccountsListRequestCategory.cs +++ b/src/Merge.Client/Ats/LinkedAccounts/Types/LinkedAccountsListRequestCategory.cs @@ -1,6 +1,5 @@ using System.Runtime.Serialization; using System.Text.Json.Serialization; -using Merge.Client.Ats; using Merge.Client.Core; #nullable enable diff --git a/src/Merge.Client/Ats/Offers/OffersClient.cs b/src/Merge.Client/Ats/Offers/OffersClient.cs index 42c06bcd..3571bac0 100644 --- a/src/Merge.Client/Ats/Offers/OffersClient.cs +++ b/src/Merge.Client/Ats/Offers/OffersClient.cs @@ -1,6 +1,6 @@ +using System.Net.Http; using System.Text.Json; -using Merge.Client; -using Merge.Client.Ats; +using Merge.Client.Core; #nullable enable @@ -18,7 +18,10 @@ public OffersClient(RawClient client) /// /// Returns a list of `Offer` objects. /// - public async Task ListAsync(OffersListRequest request) + public async Task ListAsync( + OffersListRequest request, + RequestOptions? options = null + ) { var _query = new Dictionary() { }; if (request.ApplicationId != null) @@ -27,11 +30,13 @@ public async Task ListAsync(OffersListRequest request) } if (request.CreatedAfter != null) { - _query["created_after"] = request.CreatedAfter.Value.ToString("o0"); + _query["created_after"] = request.CreatedAfter.Value.ToString(Constants.DateTimeFormat); } if (request.CreatedBefore != null) { - _query["created_before"] = request.CreatedBefore.Value.ToString("o0"); + _query["created_before"] = request.CreatedBefore.Value.ToString( + Constants.DateTimeFormat + ); } if (request.CreatorId != null) { @@ -55,11 +60,15 @@ public async Task ListAsync(OffersListRequest request) } if (request.ModifiedAfter != null) { - _query["modified_after"] = request.ModifiedAfter.Value.ToString("o0"); + _query["modified_after"] = request.ModifiedAfter.Value.ToString( + Constants.DateTimeFormat + ); } if (request.ModifiedBefore != null) { - _query["modified_before"] = request.ModifiedBefore.Value.ToString("o0"); + _query["modified_before"] = request.ModifiedBefore.Value.ToString( + Constants.DateTimeFormat + ); } if (request.PageSize != null) { @@ -80,23 +89,41 @@ public async Task ListAsync(OffersListRequest request) var response = await _client.MakeRequestAsync( new RawClient.JsonApiRequest { + BaseUrl = _client.Options.BaseUrl, Method = HttpMethod.Get, Path = "ats/v1/offers", - Query = _query + Query = _query, + Options = options } ); - string responseBody = await response.Raw.Content.ReadAsStringAsync(); - if (response.StatusCode >= 200 && response.StatusCode < 400) + var responseBody = await response.Raw.Content.ReadAsStringAsync(); + if (response.StatusCode is >= 200 and < 400) { - return JsonSerializer.Deserialize(responseBody); + try + { + return JsonUtils.Deserialize(responseBody)!; + } + catch (JsonException e) + { + throw new MergeException("Failed to deserialize response", e); + } } - throw new Exception(responseBody); + + throw new MergeApiException( + $"Error with status code {response.StatusCode}", + response.StatusCode, + JsonUtils.Deserialize(responseBody) + ); } /// /// Returns an `Offer` object with the given `id`. /// - public async Task RetrieveAsync(string id, OffersRetrieveRequest request) + public async Task RetrieveAsync( + string id, + OffersRetrieveRequest request, + RequestOptions? options = null + ) { var _query = new Dictionary() { }; if (request.Expand != null) @@ -118,16 +145,30 @@ public async Task RetrieveAsync(string id, OffersRetrieveRequest request) var response = await _client.MakeRequestAsync( new RawClient.JsonApiRequest { + BaseUrl = _client.Options.BaseUrl, Method = HttpMethod.Get, Path = $"ats/v1/offers/{id}", - Query = _query + Query = _query, + Options = options } ); - string responseBody = await response.Raw.Content.ReadAsStringAsync(); - if (response.StatusCode >= 200 && response.StatusCode < 400) + var responseBody = await response.Raw.Content.ReadAsStringAsync(); + if (response.StatusCode is >= 200 and < 400) { - return JsonSerializer.Deserialize(responseBody); + try + { + return JsonUtils.Deserialize(responseBody)!; + } + catch (JsonException e) + { + throw new MergeException("Failed to deserialize response", e); + } } - throw new Exception(responseBody); + + throw new MergeApiException( + $"Error with status code {response.StatusCode}", + response.StatusCode, + JsonUtils.Deserialize(responseBody) + ); } } diff --git a/src/Merge.Client/Ats/Offers/Requests/OffersListRequest.cs b/src/Merge.Client/Ats/Offers/Requests/OffersListRequest.cs index 0f57e6de..956577be 100644 --- a/src/Merge.Client/Ats/Offers/Requests/OffersListRequest.cs +++ b/src/Merge.Client/Ats/Offers/Requests/OffersListRequest.cs @@ -1,78 +1,74 @@ -using Merge.Client.Ats; - -#nullable enable - namespace Merge.Client.Ats; -public class OffersListRequest +public record OffersListRequest { /// /// If provided, will only return offers for this application. /// - public string? ApplicationId { get; init; } + public string? ApplicationId { get; set; } /// /// If provided, will only return objects created after this datetime. /// - public DateTime? CreatedAfter { get; init; } + public DateTime? CreatedAfter { get; set; } /// /// If provided, will only return objects created before this datetime. /// - public DateTime? CreatedBefore { get; init; } + public DateTime? CreatedBefore { get; set; } /// /// If provided, will only return offers created by this user. /// - public string? CreatorId { get; init; } + public string? CreatorId { get; set; } /// /// The pagination cursor value. /// - public string? Cursor { get; init; } + public string? Cursor { get; set; } /// /// Which relations should be returned in expanded form. Multiple relation names should be comma separated without spaces. /// - public OffersListRequestExpand? Expand { get; init; } + public OffersListRequestExpand? Expand { get; set; } /// /// Whether to include data that was marked as deleted by third party webhooks. /// - public bool? IncludeDeletedData { get; init; } + public bool? IncludeDeletedData { get; set; } /// /// Whether to include the original data Merge fetched from the third-party to produce these models. /// - public bool? IncludeRemoteData { get; init; } + public bool? IncludeRemoteData { get; set; } /// /// If provided, only objects synced by Merge after this date time will be returned. /// - public DateTime? ModifiedAfter { get; init; } + public DateTime? ModifiedAfter { get; set; } /// /// If provided, only objects synced by Merge before this date time will be returned. /// - public DateTime? ModifiedBefore { get; init; } + public DateTime? ModifiedBefore { get; set; } /// /// Number of results to return per page. /// - public int? PageSize { get; init; } + public int? PageSize { get; set; } /// /// Deprecated. Use show_enum_origins. /// - public string? RemoteFields { get; init; } + public string? RemoteFields { get; set; } /// /// The API provider's ID for the given object. /// - public string? RemoteId { get; init; } + public string? RemoteId { get; set; } /// /// A comma separated list of enum field names for which you'd like the original values to be returned, instead of Merge's normalized enum values. [Learn more](https://help.merge.dev/en/articles/8950958-show_enum_origins-query-parameter) /// - public string? ShowEnumOrigins { get; init; } + public string? ShowEnumOrigins { get; set; } } diff --git a/src/Merge.Client/Ats/Offers/Requests/OffersRetrieveRequest.cs b/src/Merge.Client/Ats/Offers/Requests/OffersRetrieveRequest.cs index 3d043960..4bbddbad 100644 --- a/src/Merge.Client/Ats/Offers/Requests/OffersRetrieveRequest.cs +++ b/src/Merge.Client/Ats/Offers/Requests/OffersRetrieveRequest.cs @@ -1,28 +1,24 @@ -using Merge.Client.Ats; - -#nullable enable - namespace Merge.Client.Ats; -public class OffersRetrieveRequest +public record OffersRetrieveRequest { /// /// Which relations should be returned in expanded form. Multiple relation names should be comma separated without spaces. /// - public OffersRetrieveRequestExpand? Expand { get; init; } + public OffersRetrieveRequestExpand? Expand { get; set; } /// /// Whether to include the original data Merge fetched from the third-party to produce these models. /// - public bool? IncludeRemoteData { get; init; } + public bool? IncludeRemoteData { get; set; } /// /// Deprecated. Use show_enum_origins. /// - public string? RemoteFields { get; init; } + public string? RemoteFields { get; set; } /// /// A comma separated list of enum field names for which you'd like the original values to be returned, instead of Merge's normalized enum values. [Learn more](https://help.merge.dev/en/articles/8950958-show_enum_origins-query-parameter) /// - public string? ShowEnumOrigins { get; init; } + public string? ShowEnumOrigins { get; set; } } diff --git a/src/Merge.Client/Ats/Offers/Types/OffersListRequestExpand.cs b/src/Merge.Client/Ats/Offers/Types/OffersListRequestExpand.cs index 231df7ef..1078ee90 100644 --- a/src/Merge.Client/Ats/Offers/Types/OffersListRequestExpand.cs +++ b/src/Merge.Client/Ats/Offers/Types/OffersListRequestExpand.cs @@ -1,6 +1,5 @@ using System.Runtime.Serialization; using System.Text.Json.Serialization; -using Merge.Client.Ats; using Merge.Client.Core; #nullable enable diff --git a/src/Merge.Client/Ats/Offers/Types/OffersRetrieveRequestExpand.cs b/src/Merge.Client/Ats/Offers/Types/OffersRetrieveRequestExpand.cs index fe186b28..bce2a508 100644 --- a/src/Merge.Client/Ats/Offers/Types/OffersRetrieveRequestExpand.cs +++ b/src/Merge.Client/Ats/Offers/Types/OffersRetrieveRequestExpand.cs @@ -1,6 +1,5 @@ using System.Runtime.Serialization; using System.Text.Json.Serialization; -using Merge.Client.Ats; using Merge.Client.Core; #nullable enable diff --git a/src/Merge.Client/Ats/Offices/OfficesClient.cs b/src/Merge.Client/Ats/Offices/OfficesClient.cs index b2ae3565..c6320391 100644 --- a/src/Merge.Client/Ats/Offices/OfficesClient.cs +++ b/src/Merge.Client/Ats/Offices/OfficesClient.cs @@ -1,6 +1,6 @@ +using System.Net.Http; using System.Text.Json; -using Merge.Client; -using Merge.Client.Ats; +using Merge.Client.Core; #nullable enable @@ -18,16 +18,21 @@ public OfficesClient(RawClient client) /// /// Returns a list of `Office` objects. /// - public async Task ListAsync(OfficesListRequest request) + public async Task ListAsync( + OfficesListRequest request, + RequestOptions? options = null + ) { var _query = new Dictionary() { }; if (request.CreatedAfter != null) { - _query["created_after"] = request.CreatedAfter.Value.ToString("o0"); + _query["created_after"] = request.CreatedAfter.Value.ToString(Constants.DateTimeFormat); } if (request.CreatedBefore != null) { - _query["created_before"] = request.CreatedBefore.Value.ToString("o0"); + _query["created_before"] = request.CreatedBefore.Value.ToString( + Constants.DateTimeFormat + ); } if (request.Cursor != null) { @@ -43,11 +48,15 @@ public async Task ListAsync(OfficesListRequest request) } if (request.ModifiedAfter != null) { - _query["modified_after"] = request.ModifiedAfter.Value.ToString("o0"); + _query["modified_after"] = request.ModifiedAfter.Value.ToString( + Constants.DateTimeFormat + ); } if (request.ModifiedBefore != null) { - _query["modified_before"] = request.ModifiedBefore.Value.ToString("o0"); + _query["modified_before"] = request.ModifiedBefore.Value.ToString( + Constants.DateTimeFormat + ); } if (request.PageSize != null) { @@ -60,23 +69,41 @@ public async Task ListAsync(OfficesListRequest request) var response = await _client.MakeRequestAsync( new RawClient.JsonApiRequest { + BaseUrl = _client.Options.BaseUrl, Method = HttpMethod.Get, Path = "ats/v1/offices", - Query = _query + Query = _query, + Options = options } ); - string responseBody = await response.Raw.Content.ReadAsStringAsync(); - if (response.StatusCode >= 200 && response.StatusCode < 400) + var responseBody = await response.Raw.Content.ReadAsStringAsync(); + if (response.StatusCode is >= 200 and < 400) { - return JsonSerializer.Deserialize(responseBody); + try + { + return JsonUtils.Deserialize(responseBody)!; + } + catch (JsonException e) + { + throw new MergeException("Failed to deserialize response", e); + } } - throw new Exception(responseBody); + + throw new MergeApiException( + $"Error with status code {response.StatusCode}", + response.StatusCode, + JsonUtils.Deserialize(responseBody) + ); } /// /// Returns an `Office` object with the given `id`. /// - public async Task RetrieveAsync(string id, OfficesRetrieveRequest request) + public async Task RetrieveAsync( + string id, + OfficesRetrieveRequest request, + RequestOptions? options = null + ) { var _query = new Dictionary() { }; if (request.IncludeRemoteData != null) @@ -86,16 +113,30 @@ public async Task RetrieveAsync(string id, OfficesRetrieveRequest reques var response = await _client.MakeRequestAsync( new RawClient.JsonApiRequest { + BaseUrl = _client.Options.BaseUrl, Method = HttpMethod.Get, Path = $"ats/v1/offices/{id}", - Query = _query + Query = _query, + Options = options } ); - string responseBody = await response.Raw.Content.ReadAsStringAsync(); - if (response.StatusCode >= 200 && response.StatusCode < 400) + var responseBody = await response.Raw.Content.ReadAsStringAsync(); + if (response.StatusCode is >= 200 and < 400) { - return JsonSerializer.Deserialize(responseBody); + try + { + return JsonUtils.Deserialize(responseBody)!; + } + catch (JsonException e) + { + throw new MergeException("Failed to deserialize response", e); + } } - throw new Exception(responseBody); + + throw new MergeApiException( + $"Error with status code {response.StatusCode}", + response.StatusCode, + JsonUtils.Deserialize(responseBody) + ); } } diff --git a/src/Merge.Client/Ats/Offices/Requests/OfficesListRequest.cs b/src/Merge.Client/Ats/Offices/Requests/OfficesListRequest.cs index 6e2cb763..c01245d9 100644 --- a/src/Merge.Client/Ats/Offices/Requests/OfficesListRequest.cs +++ b/src/Merge.Client/Ats/Offices/Requests/OfficesListRequest.cs @@ -1,49 +1,49 @@ namespace Merge.Client.Ats; -public class OfficesListRequest +public record OfficesListRequest { /// /// If provided, will only return objects created after this datetime. /// - public DateTime? CreatedAfter { get; init; } + public DateTime? CreatedAfter { get; set; } /// /// If provided, will only return objects created before this datetime. /// - public DateTime? CreatedBefore { get; init; } + public DateTime? CreatedBefore { get; set; } /// /// The pagination cursor value. /// - public string? Cursor { get; init; } + public string? Cursor { get; set; } /// /// Whether to include data that was marked as deleted by third party webhooks. /// - public bool? IncludeDeletedData { get; init; } + public bool? IncludeDeletedData { get; set; } /// /// Whether to include the original data Merge fetched from the third-party to produce these models. /// - public bool? IncludeRemoteData { get; init; } + public bool? IncludeRemoteData { get; set; } /// /// If provided, only objects synced by Merge after this date time will be returned. /// - public DateTime? ModifiedAfter { get; init; } + public DateTime? ModifiedAfter { get; set; } /// /// If provided, only objects synced by Merge before this date time will be returned. /// - public DateTime? ModifiedBefore { get; init; } + public DateTime? ModifiedBefore { get; set; } /// /// Number of results to return per page. /// - public int? PageSize { get; init; } + public int? PageSize { get; set; } /// /// The API provider's ID for the given object. /// - public string? RemoteId { get; init; } + public string? RemoteId { get; set; } } diff --git a/src/Merge.Client/Ats/Offices/Requests/OfficesRetrieveRequest.cs b/src/Merge.Client/Ats/Offices/Requests/OfficesRetrieveRequest.cs index 072dd78f..e4cb8bbf 100644 --- a/src/Merge.Client/Ats/Offices/Requests/OfficesRetrieveRequest.cs +++ b/src/Merge.Client/Ats/Offices/Requests/OfficesRetrieveRequest.cs @@ -1,9 +1,9 @@ namespace Merge.Client.Ats; -public class OfficesRetrieveRequest +public record OfficesRetrieveRequest { /// /// Whether to include the original data Merge fetched from the third-party to produce these models. /// - public bool? IncludeRemoteData { get; init; } + public bool? IncludeRemoteData { get; set; } } diff --git a/src/Merge.Client/Ats/Passthrough/PassthroughClient.cs b/src/Merge.Client/Ats/Passthrough/PassthroughClient.cs index 03f91c63..c8b6d7a4 100644 --- a/src/Merge.Client/Ats/Passthrough/PassthroughClient.cs +++ b/src/Merge.Client/Ats/Passthrough/PassthroughClient.cs @@ -1,6 +1,6 @@ +using System.Net.Http; using System.Text.Json; -using Merge.Client; -using Merge.Client.Ats; +using Merge.Client.Core; #nullable enable @@ -18,21 +18,38 @@ public PassthroughClient(RawClient client) /// /// Pull data from an endpoint not currently supported by Merge. /// - public async Task CreateAsync(DataPassthroughRequest request) + public async Task CreateAsync( + DataPassthroughRequest request, + RequestOptions? options = null + ) { var response = await _client.MakeRequestAsync( new RawClient.JsonApiRequest { + BaseUrl = _client.Options.BaseUrl, Method = HttpMethod.Post, Path = "ats/v1/passthrough", - Body = request + Body = request, + Options = options } ); - string responseBody = await response.Raw.Content.ReadAsStringAsync(); - if (response.StatusCode >= 200 && response.StatusCode < 400) + var responseBody = await response.Raw.Content.ReadAsStringAsync(); + if (response.StatusCode is >= 200 and < 400) { - return JsonSerializer.Deserialize(responseBody); + try + { + return JsonUtils.Deserialize(responseBody)!; + } + catch (JsonException e) + { + throw new MergeException("Failed to deserialize response", e); + } } - throw new Exception(responseBody); + + throw new MergeApiException( + $"Error with status code {response.StatusCode}", + response.StatusCode, + JsonUtils.Deserialize(responseBody) + ); } } diff --git a/src/Merge.Client/Ats/RegenerateKey/RegenerateKeyClient.cs b/src/Merge.Client/Ats/RegenerateKey/RegenerateKeyClient.cs index cc5b78b9..5784c858 100644 --- a/src/Merge.Client/Ats/RegenerateKey/RegenerateKeyClient.cs +++ b/src/Merge.Client/Ats/RegenerateKey/RegenerateKeyClient.cs @@ -1,6 +1,6 @@ +using System.Net.Http; using System.Text.Json; -using Merge.Client; -using Merge.Client.Ats; +using Merge.Client.Core; #nullable enable @@ -18,21 +18,38 @@ public RegenerateKeyClient(RawClient client) /// /// Exchange remote keys. /// - public async Task CreateAsync(RemoteKeyForRegenerationRequest request) + public async Task CreateAsync( + RemoteKeyForRegenerationRequest request, + RequestOptions? options = null + ) { var response = await _client.MakeRequestAsync( new RawClient.JsonApiRequest { + BaseUrl = _client.Options.BaseUrl, Method = HttpMethod.Post, Path = "ats/v1/regenerate-key", - Body = request + Body = request, + Options = options } ); - string responseBody = await response.Raw.Content.ReadAsStringAsync(); - if (response.StatusCode >= 200 && response.StatusCode < 400) + var responseBody = await response.Raw.Content.ReadAsStringAsync(); + if (response.StatusCode is >= 200 and < 400) { - return JsonSerializer.Deserialize(responseBody); + try + { + return JsonUtils.Deserialize(responseBody)!; + } + catch (JsonException e) + { + throw new MergeException("Failed to deserialize response", e); + } } - throw new Exception(responseBody); + + throw new MergeApiException( + $"Error with status code {response.StatusCode}", + response.StatusCode, + JsonUtils.Deserialize(responseBody) + ); } } diff --git a/src/Merge.Client/Ats/RegenerateKey/Requests/RemoteKeyForRegenerationRequest.cs b/src/Merge.Client/Ats/RegenerateKey/Requests/RemoteKeyForRegenerationRequest.cs index 23af2366..3876028f 100644 --- a/src/Merge.Client/Ats/RegenerateKey/Requests/RemoteKeyForRegenerationRequest.cs +++ b/src/Merge.Client/Ats/RegenerateKey/Requests/RemoteKeyForRegenerationRequest.cs @@ -4,11 +4,11 @@ namespace Merge.Client.Ats; -public class RemoteKeyForRegenerationRequest +public record RemoteKeyForRegenerationRequest { /// /// The name of the remote key /// [JsonPropertyName("name")] - public string Name { get; init; } + public required string Name { get; set; } } diff --git a/src/Merge.Client/Ats/RejectReasons/RejectReasonsClient.cs b/src/Merge.Client/Ats/RejectReasons/RejectReasonsClient.cs index 0df402ca..d4c3472c 100644 --- a/src/Merge.Client/Ats/RejectReasons/RejectReasonsClient.cs +++ b/src/Merge.Client/Ats/RejectReasons/RejectReasonsClient.cs @@ -1,6 +1,6 @@ +using System.Net.Http; using System.Text.Json; -using Merge.Client; -using Merge.Client.Ats; +using Merge.Client.Core; #nullable enable @@ -18,16 +18,21 @@ public RejectReasonsClient(RawClient client) /// /// Returns a list of `RejectReason` objects. /// - public async Task ListAsync(RejectReasonsListRequest request) + public async Task ListAsync( + RejectReasonsListRequest request, + RequestOptions? options = null + ) { var _query = new Dictionary() { }; if (request.CreatedAfter != null) { - _query["created_after"] = request.CreatedAfter.Value.ToString("o0"); + _query["created_after"] = request.CreatedAfter.Value.ToString(Constants.DateTimeFormat); } if (request.CreatedBefore != null) { - _query["created_before"] = request.CreatedBefore.Value.ToString("o0"); + _query["created_before"] = request.CreatedBefore.Value.ToString( + Constants.DateTimeFormat + ); } if (request.Cursor != null) { @@ -43,11 +48,15 @@ public async Task ListAsync(RejectReasonsListRequest } if (request.ModifiedAfter != null) { - _query["modified_after"] = request.ModifiedAfter.Value.ToString("o0"); + _query["modified_after"] = request.ModifiedAfter.Value.ToString( + Constants.DateTimeFormat + ); } if (request.ModifiedBefore != null) { - _query["modified_before"] = request.ModifiedBefore.Value.ToString("o0"); + _query["modified_before"] = request.ModifiedBefore.Value.ToString( + Constants.DateTimeFormat + ); } if (request.PageSize != null) { @@ -60,23 +69,41 @@ public async Task ListAsync(RejectReasonsListRequest var response = await _client.MakeRequestAsync( new RawClient.JsonApiRequest { + BaseUrl = _client.Options.BaseUrl, Method = HttpMethod.Get, Path = "ats/v1/reject-reasons", - Query = _query + Query = _query, + Options = options } ); - string responseBody = await response.Raw.Content.ReadAsStringAsync(); - if (response.StatusCode >= 200 && response.StatusCode < 400) + var responseBody = await response.Raw.Content.ReadAsStringAsync(); + if (response.StatusCode is >= 200 and < 400) { - return JsonSerializer.Deserialize(responseBody); + try + { + return JsonUtils.Deserialize(responseBody)!; + } + catch (JsonException e) + { + throw new MergeException("Failed to deserialize response", e); + } } - throw new Exception(responseBody); + + throw new MergeApiException( + $"Error with status code {response.StatusCode}", + response.StatusCode, + JsonUtils.Deserialize(responseBody) + ); } /// /// Returns a `RejectReason` object with the given `id`. /// - public async Task RetrieveAsync(string id, RejectReasonsRetrieveRequest request) + public async Task RetrieveAsync( + string id, + RejectReasonsRetrieveRequest request, + RequestOptions? options = null + ) { var _query = new Dictionary() { }; if (request.IncludeRemoteData != null) @@ -86,16 +113,30 @@ public async Task RetrieveAsync(string id, RejectReasonsRetrieveRe var response = await _client.MakeRequestAsync( new RawClient.JsonApiRequest { + BaseUrl = _client.Options.BaseUrl, Method = HttpMethod.Get, Path = $"ats/v1/reject-reasons/{id}", - Query = _query + Query = _query, + Options = options } ); - string responseBody = await response.Raw.Content.ReadAsStringAsync(); - if (response.StatusCode >= 200 && response.StatusCode < 400) + var responseBody = await response.Raw.Content.ReadAsStringAsync(); + if (response.StatusCode is >= 200 and < 400) { - return JsonSerializer.Deserialize(responseBody); + try + { + return JsonUtils.Deserialize(responseBody)!; + } + catch (JsonException e) + { + throw new MergeException("Failed to deserialize response", e); + } } - throw new Exception(responseBody); + + throw new MergeApiException( + $"Error with status code {response.StatusCode}", + response.StatusCode, + JsonUtils.Deserialize(responseBody) + ); } } diff --git a/src/Merge.Client/Ats/RejectReasons/Requests/RejectReasonsListRequest.cs b/src/Merge.Client/Ats/RejectReasons/Requests/RejectReasonsListRequest.cs index babb3000..049ce104 100644 --- a/src/Merge.Client/Ats/RejectReasons/Requests/RejectReasonsListRequest.cs +++ b/src/Merge.Client/Ats/RejectReasons/Requests/RejectReasonsListRequest.cs @@ -1,49 +1,49 @@ namespace Merge.Client.Ats; -public class RejectReasonsListRequest +public record RejectReasonsListRequest { /// /// If provided, will only return objects created after this datetime. /// - public DateTime? CreatedAfter { get; init; } + public DateTime? CreatedAfter { get; set; } /// /// If provided, will only return objects created before this datetime. /// - public DateTime? CreatedBefore { get; init; } + public DateTime? CreatedBefore { get; set; } /// /// The pagination cursor value. /// - public string? Cursor { get; init; } + public string? Cursor { get; set; } /// /// Whether to include data that was marked as deleted by third party webhooks. /// - public bool? IncludeDeletedData { get; init; } + public bool? IncludeDeletedData { get; set; } /// /// Whether to include the original data Merge fetched from the third-party to produce these models. /// - public bool? IncludeRemoteData { get; init; } + public bool? IncludeRemoteData { get; set; } /// /// If provided, only objects synced by Merge after this date time will be returned. /// - public DateTime? ModifiedAfter { get; init; } + public DateTime? ModifiedAfter { get; set; } /// /// If provided, only objects synced by Merge before this date time will be returned. /// - public DateTime? ModifiedBefore { get; init; } + public DateTime? ModifiedBefore { get; set; } /// /// Number of results to return per page. /// - public int? PageSize { get; init; } + public int? PageSize { get; set; } /// /// The API provider's ID for the given object. /// - public string? RemoteId { get; init; } + public string? RemoteId { get; set; } } diff --git a/src/Merge.Client/Ats/RejectReasons/Requests/RejectReasonsRetrieveRequest.cs b/src/Merge.Client/Ats/RejectReasons/Requests/RejectReasonsRetrieveRequest.cs index 44ecbcb9..2f060bd4 100644 --- a/src/Merge.Client/Ats/RejectReasons/Requests/RejectReasonsRetrieveRequest.cs +++ b/src/Merge.Client/Ats/RejectReasons/Requests/RejectReasonsRetrieveRequest.cs @@ -1,9 +1,9 @@ namespace Merge.Client.Ats; -public class RejectReasonsRetrieveRequest +public record RejectReasonsRetrieveRequest { /// /// Whether to include the original data Merge fetched from the third-party to produce these models. /// - public bool? IncludeRemoteData { get; init; } + public bool? IncludeRemoteData { get; set; } } diff --git a/src/Merge.Client/Ats/Scopes/Requests/LinkedAccountCommonModelScopeDeserializerRequest.cs b/src/Merge.Client/Ats/Scopes/Requests/LinkedAccountCommonModelScopeDeserializerRequest.cs index 205760ca..d271acf4 100644 --- a/src/Merge.Client/Ats/Scopes/Requests/LinkedAccountCommonModelScopeDeserializerRequest.cs +++ b/src/Merge.Client/Ats/Scopes/Requests/LinkedAccountCommonModelScopeDeserializerRequest.cs @@ -1,15 +1,15 @@ using System.Text.Json.Serialization; -using Merge.Client.Ats; #nullable enable namespace Merge.Client.Ats; -public class LinkedAccountCommonModelScopeDeserializerRequest +public record LinkedAccountCommonModelScopeDeserializerRequest { /// /// The common models you want to update the scopes for /// [JsonPropertyName("common_models")] - public IEnumerable CommonModels { get; init; } + public IEnumerable CommonModels { get; set; } = + new List(); } diff --git a/src/Merge.Client/Ats/Scopes/ScopesClient.cs b/src/Merge.Client/Ats/Scopes/ScopesClient.cs index 52b20d8b..01cf070a 100644 --- a/src/Merge.Client/Ats/Scopes/ScopesClient.cs +++ b/src/Merge.Client/Ats/Scopes/ScopesClient.cs @@ -1,6 +1,6 @@ +using System.Net.Http; using System.Text.Json; -using Merge.Client; -using Merge.Client.Ats; +using Merge.Client.Core; #nullable enable @@ -18,59 +18,110 @@ public ScopesClient(RawClient client) /// /// Get the default permissions for Merge Common Models and fields across all Linked Accounts of a given category. [Learn more](https://help.merge.dev/en/articles/8828211-common-model-and-field-scopes). /// - public async Task DefaultScopesRetrieveAsync() + public async Task DefaultScopesRetrieveAsync( + RequestOptions? options = null + ) { var response = await _client.MakeRequestAsync( - new RawClient.JsonApiRequest { Method = HttpMethod.Get, Path = "ats/v1/default-scopes" } + new RawClient.JsonApiRequest + { + BaseUrl = _client.Options.BaseUrl, + Method = HttpMethod.Get, + Path = "ats/v1/default-scopes", + Options = options + } ); - string responseBody = await response.Raw.Content.ReadAsStringAsync(); - if (response.StatusCode >= 200 && response.StatusCode < 400) + var responseBody = await response.Raw.Content.ReadAsStringAsync(); + if (response.StatusCode is >= 200 and < 400) { - return JsonSerializer.Deserialize(responseBody); + try + { + return JsonUtils.Deserialize(responseBody)!; + } + catch (JsonException e) + { + throw new MergeException("Failed to deserialize response", e); + } } - throw new Exception(responseBody); + + throw new MergeApiException( + $"Error with status code {response.StatusCode}", + response.StatusCode, + JsonUtils.Deserialize(responseBody) + ); } /// /// Get all available permissions for Merge Common Models and fields for a single Linked Account. [Learn more](https://help.merge.dev/en/articles/8828211-common-model-and-field-scopes). /// - public async Task LinkedAccountScopesRetrieveAsync() + public async Task LinkedAccountScopesRetrieveAsync( + RequestOptions? options = null + ) { var response = await _client.MakeRequestAsync( new RawClient.JsonApiRequest { + BaseUrl = _client.Options.BaseUrl, Method = HttpMethod.Get, - Path = "ats/v1/linked-account-scopes" + Path = "ats/v1/linked-account-scopes", + Options = options } ); - string responseBody = await response.Raw.Content.ReadAsStringAsync(); - if (response.StatusCode >= 200 && response.StatusCode < 400) + var responseBody = await response.Raw.Content.ReadAsStringAsync(); + if (response.StatusCode is >= 200 and < 400) { - return JsonSerializer.Deserialize(responseBody); + try + { + return JsonUtils.Deserialize(responseBody)!; + } + catch (JsonException e) + { + throw new MergeException("Failed to deserialize response", e); + } } - throw new Exception(responseBody); + + throw new MergeApiException( + $"Error with status code {response.StatusCode}", + response.StatusCode, + JsonUtils.Deserialize(responseBody) + ); } /// /// Update permissions for any Common Model or field for a single Linked Account. Any Scopes not set in this POST request will inherit the default Scopes. [Learn more](https://help.merge.dev/en/articles/8828211-common-model-and-field-scopes) /// public async Task LinkedAccountScopesCreateAsync( - LinkedAccountCommonModelScopeDeserializerRequest request + LinkedAccountCommonModelScopeDeserializerRequest request, + RequestOptions? options = null ) { var response = await _client.MakeRequestAsync( new RawClient.JsonApiRequest { + BaseUrl = _client.Options.BaseUrl, Method = HttpMethod.Post, Path = "ats/v1/linked-account-scopes", - Body = request + Body = request, + Options = options } ); - string responseBody = await response.Raw.Content.ReadAsStringAsync(); - if (response.StatusCode >= 200 && response.StatusCode < 400) + var responseBody = await response.Raw.Content.ReadAsStringAsync(); + if (response.StatusCode is >= 200 and < 400) { - return JsonSerializer.Deserialize(responseBody); + try + { + return JsonUtils.Deserialize(responseBody)!; + } + catch (JsonException e) + { + throw new MergeException("Failed to deserialize response", e); + } } - throw new Exception(responseBody); + + throw new MergeApiException( + $"Error with status code {response.StatusCode}", + response.StatusCode, + JsonUtils.Deserialize(responseBody) + ); } } diff --git a/src/Merge.Client/Ats/Scorecards/Requests/ScorecardsListRequest.cs b/src/Merge.Client/Ats/Scorecards/Requests/ScorecardsListRequest.cs index 4ac616a1..8e8b4cea 100644 --- a/src/Merge.Client/Ats/Scorecards/Requests/ScorecardsListRequest.cs +++ b/src/Merge.Client/Ats/Scorecards/Requests/ScorecardsListRequest.cs @@ -1,83 +1,79 @@ -using Merge.Client.Ats; - -#nullable enable - namespace Merge.Client.Ats; -public class ScorecardsListRequest +public record ScorecardsListRequest { /// /// If provided, will only return scorecards for this application. /// - public string? ApplicationId { get; init; } + public string? ApplicationId { get; set; } /// /// If provided, will only return objects created after this datetime. /// - public DateTime? CreatedAfter { get; init; } + public DateTime? CreatedAfter { get; set; } /// /// If provided, will only return objects created before this datetime. /// - public DateTime? CreatedBefore { get; init; } + public DateTime? CreatedBefore { get; set; } /// /// The pagination cursor value. /// - public string? Cursor { get; init; } + public string? Cursor { get; set; } /// /// Which relations should be returned in expanded form. Multiple relation names should be comma separated without spaces. /// - public ScorecardsListRequestExpand? Expand { get; init; } + public ScorecardsListRequestExpand? Expand { get; set; } /// /// Whether to include data that was marked as deleted by third party webhooks. /// - public bool? IncludeDeletedData { get; init; } + public bool? IncludeDeletedData { get; set; } /// /// Whether to include the original data Merge fetched from the third-party to produce these models. /// - public bool? IncludeRemoteData { get; init; } + public bool? IncludeRemoteData { get; set; } /// /// If provided, will only return scorecards for this interview. /// - public string? InterviewId { get; init; } + public string? InterviewId { get; set; } /// /// If provided, will only return scorecards for this interviewer. /// - public string? InterviewerId { get; init; } + public string? InterviewerId { get; set; } /// /// If provided, only objects synced by Merge after this date time will be returned. /// - public DateTime? ModifiedAfter { get; init; } + public DateTime? ModifiedAfter { get; set; } /// /// If provided, only objects synced by Merge before this date time will be returned. /// - public DateTime? ModifiedBefore { get; init; } + public DateTime? ModifiedBefore { get; set; } /// /// Number of results to return per page. /// - public int? PageSize { get; init; } + public int? PageSize { get; set; } /// /// Deprecated. Use show_enum_origins. /// - public string? RemoteFields { get; init; } + public string? RemoteFields { get; set; } /// /// The API provider's ID for the given object. /// - public string? RemoteId { get; init; } + public string? RemoteId { get; set; } /// /// A comma separated list of enum field names for which you'd like the original values to be returned, instead of Merge's normalized enum values. [Learn more](https://help.merge.dev/en/articles/8950958-show_enum_origins-query-parameter) /// - public string? ShowEnumOrigins { get; init; } + public string? ShowEnumOrigins { get; set; } } diff --git a/src/Merge.Client/Ats/Scorecards/Requests/ScorecardsRetrieveRequest.cs b/src/Merge.Client/Ats/Scorecards/Requests/ScorecardsRetrieveRequest.cs index eb1b0cf0..d6aa3230 100644 --- a/src/Merge.Client/Ats/Scorecards/Requests/ScorecardsRetrieveRequest.cs +++ b/src/Merge.Client/Ats/Scorecards/Requests/ScorecardsRetrieveRequest.cs @@ -1,28 +1,24 @@ -using Merge.Client.Ats; - -#nullable enable - namespace Merge.Client.Ats; -public class ScorecardsRetrieveRequest +public record ScorecardsRetrieveRequest { /// /// Which relations should be returned in expanded form. Multiple relation names should be comma separated without spaces. /// - public ScorecardsRetrieveRequestExpand? Expand { get; init; } + public ScorecardsRetrieveRequestExpand? Expand { get; set; } /// /// Whether to include the original data Merge fetched from the third-party to produce these models. /// - public bool? IncludeRemoteData { get; init; } + public bool? IncludeRemoteData { get; set; } /// /// Deprecated. Use show_enum_origins. /// - public string? RemoteFields { get; init; } + public string? RemoteFields { get; set; } /// /// A comma separated list of enum field names for which you'd like the original values to be returned, instead of Merge's normalized enum values. [Learn more](https://help.merge.dev/en/articles/8950958-show_enum_origins-query-parameter) /// - public string? ShowEnumOrigins { get; init; } + public string? ShowEnumOrigins { get; set; } } diff --git a/src/Merge.Client/Ats/Scorecards/ScorecardsClient.cs b/src/Merge.Client/Ats/Scorecards/ScorecardsClient.cs index e35caa75..f121b84b 100644 --- a/src/Merge.Client/Ats/Scorecards/ScorecardsClient.cs +++ b/src/Merge.Client/Ats/Scorecards/ScorecardsClient.cs @@ -1,6 +1,6 @@ +using System.Net.Http; using System.Text.Json; -using Merge.Client; -using Merge.Client.Ats; +using Merge.Client.Core; #nullable enable @@ -18,7 +18,10 @@ public ScorecardsClient(RawClient client) /// /// Returns a list of `Scorecard` objects. /// - public async Task ListAsync(ScorecardsListRequest request) + public async Task ListAsync( + ScorecardsListRequest request, + RequestOptions? options = null + ) { var _query = new Dictionary() { }; if (request.ApplicationId != null) @@ -27,11 +30,13 @@ public async Task ListAsync(ScorecardsListRequest reques } if (request.CreatedAfter != null) { - _query["created_after"] = request.CreatedAfter.Value.ToString("o0"); + _query["created_after"] = request.CreatedAfter.Value.ToString(Constants.DateTimeFormat); } if (request.CreatedBefore != null) { - _query["created_before"] = request.CreatedBefore.Value.ToString("o0"); + _query["created_before"] = request.CreatedBefore.Value.ToString( + Constants.DateTimeFormat + ); } if (request.Cursor != null) { @@ -59,11 +64,15 @@ public async Task ListAsync(ScorecardsListRequest reques } if (request.ModifiedAfter != null) { - _query["modified_after"] = request.ModifiedAfter.Value.ToString("o0"); + _query["modified_after"] = request.ModifiedAfter.Value.ToString( + Constants.DateTimeFormat + ); } if (request.ModifiedBefore != null) { - _query["modified_before"] = request.ModifiedBefore.Value.ToString("o0"); + _query["modified_before"] = request.ModifiedBefore.Value.ToString( + Constants.DateTimeFormat + ); } if (request.PageSize != null) { @@ -84,23 +93,41 @@ public async Task ListAsync(ScorecardsListRequest reques var response = await _client.MakeRequestAsync( new RawClient.JsonApiRequest { + BaseUrl = _client.Options.BaseUrl, Method = HttpMethod.Get, Path = "ats/v1/scorecards", - Query = _query + Query = _query, + Options = options } ); - string responseBody = await response.Raw.Content.ReadAsStringAsync(); - if (response.StatusCode >= 200 && response.StatusCode < 400) + var responseBody = await response.Raw.Content.ReadAsStringAsync(); + if (response.StatusCode is >= 200 and < 400) { - return JsonSerializer.Deserialize(responseBody); + try + { + return JsonUtils.Deserialize(responseBody)!; + } + catch (JsonException e) + { + throw new MergeException("Failed to deserialize response", e); + } } - throw new Exception(responseBody); + + throw new MergeApiException( + $"Error with status code {response.StatusCode}", + response.StatusCode, + JsonUtils.Deserialize(responseBody) + ); } /// /// Returns a `Scorecard` object with the given `id`. /// - public async Task RetrieveAsync(string id, ScorecardsRetrieveRequest request) + public async Task RetrieveAsync( + string id, + ScorecardsRetrieveRequest request, + RequestOptions? options = null + ) { var _query = new Dictionary() { }; if (request.Expand != null) @@ -122,16 +149,30 @@ public async Task RetrieveAsync(string id, ScorecardsRetrieveRequest var response = await _client.MakeRequestAsync( new RawClient.JsonApiRequest { + BaseUrl = _client.Options.BaseUrl, Method = HttpMethod.Get, Path = $"ats/v1/scorecards/{id}", - Query = _query + Query = _query, + Options = options } ); - string responseBody = await response.Raw.Content.ReadAsStringAsync(); - if (response.StatusCode >= 200 && response.StatusCode < 400) + var responseBody = await response.Raw.Content.ReadAsStringAsync(); + if (response.StatusCode is >= 200 and < 400) { - return JsonSerializer.Deserialize(responseBody); + try + { + return JsonUtils.Deserialize(responseBody)!; + } + catch (JsonException e) + { + throw new MergeException("Failed to deserialize response", e); + } } - throw new Exception(responseBody); + + throw new MergeApiException( + $"Error with status code {response.StatusCode}", + response.StatusCode, + JsonUtils.Deserialize(responseBody) + ); } } diff --git a/src/Merge.Client/Ats/Scorecards/Types/ScorecardsListRequestExpand.cs b/src/Merge.Client/Ats/Scorecards/Types/ScorecardsListRequestExpand.cs index 50c5e5b3..552fa94a 100644 --- a/src/Merge.Client/Ats/Scorecards/Types/ScorecardsListRequestExpand.cs +++ b/src/Merge.Client/Ats/Scorecards/Types/ScorecardsListRequestExpand.cs @@ -1,6 +1,5 @@ using System.Runtime.Serialization; using System.Text.Json.Serialization; -using Merge.Client.Ats; using Merge.Client.Core; #nullable enable diff --git a/src/Merge.Client/Ats/Scorecards/Types/ScorecardsRetrieveRequestExpand.cs b/src/Merge.Client/Ats/Scorecards/Types/ScorecardsRetrieveRequestExpand.cs index ed45ad7c..d7e5eab9 100644 --- a/src/Merge.Client/Ats/Scorecards/Types/ScorecardsRetrieveRequestExpand.cs +++ b/src/Merge.Client/Ats/Scorecards/Types/ScorecardsRetrieveRequestExpand.cs @@ -1,6 +1,5 @@ using System.Runtime.Serialization; using System.Text.Json.Serialization; -using Merge.Client.Ats; using Merge.Client.Core; #nullable enable diff --git a/src/Merge.Client/Ats/SyncStatus/Requests/SyncStatusListRequest.cs b/src/Merge.Client/Ats/SyncStatus/Requests/SyncStatusListRequest.cs index 521164fc..eef5e563 100644 --- a/src/Merge.Client/Ats/SyncStatus/Requests/SyncStatusListRequest.cs +++ b/src/Merge.Client/Ats/SyncStatus/Requests/SyncStatusListRequest.cs @@ -1,14 +1,14 @@ namespace Merge.Client.Ats; -public class SyncStatusListRequest +public record SyncStatusListRequest { /// /// The pagination cursor value. /// - public string? Cursor { get; init; } + public string? Cursor { get; set; } /// /// Number of results to return per page. /// - public int? PageSize { get; init; } + public int? PageSize { get; set; } } diff --git a/src/Merge.Client/Ats/SyncStatus/SyncStatusClient.cs b/src/Merge.Client/Ats/SyncStatus/SyncStatusClient.cs index 0e5d0292..7558cbdb 100644 --- a/src/Merge.Client/Ats/SyncStatus/SyncStatusClient.cs +++ b/src/Merge.Client/Ats/SyncStatus/SyncStatusClient.cs @@ -1,6 +1,6 @@ +using System.Net.Http; using System.Text.Json; -using Merge.Client; -using Merge.Client.Ats; +using Merge.Client.Core; #nullable enable @@ -18,7 +18,10 @@ public SyncStatusClient(RawClient client) /// /// Get syncing status. Possible values: `DISABLED`, `DONE`, `FAILED`, `PARTIALLY_SYNCED`, `PAUSED`, `SYNCING`. Learn more about sync status in our [Help Center](https://help.merge.dev/en/articles/8184193-merge-sync-statuses). /// - public async Task ListAsync(SyncStatusListRequest request) + public async Task ListAsync( + SyncStatusListRequest request, + RequestOptions? options = null + ) { var _query = new Dictionary() { }; if (request.Cursor != null) @@ -32,16 +35,30 @@ public async Task ListAsync(SyncStatusListRequest reque var response = await _client.MakeRequestAsync( new RawClient.JsonApiRequest { + BaseUrl = _client.Options.BaseUrl, Method = HttpMethod.Get, Path = "ats/v1/sync-status", - Query = _query + Query = _query, + Options = options } ); - string responseBody = await response.Raw.Content.ReadAsStringAsync(); - if (response.StatusCode >= 200 && response.StatusCode < 400) + var responseBody = await response.Raw.Content.ReadAsStringAsync(); + if (response.StatusCode is >= 200 and < 400) { - return JsonSerializer.Deserialize(responseBody); + try + { + return JsonUtils.Deserialize(responseBody)!; + } + catch (JsonException e) + { + throw new MergeException("Failed to deserialize response", e); + } } - throw new Exception(responseBody); + + throw new MergeApiException( + $"Error with status code {response.StatusCode}", + response.StatusCode, + JsonUtils.Deserialize(responseBody) + ); } } diff --git a/src/Merge.Client/Ats/Tags/Requests/TagsListRequest.cs b/src/Merge.Client/Ats/Tags/Requests/TagsListRequest.cs index aa6f9e0f..686bc590 100644 --- a/src/Merge.Client/Ats/Tags/Requests/TagsListRequest.cs +++ b/src/Merge.Client/Ats/Tags/Requests/TagsListRequest.cs @@ -1,49 +1,49 @@ namespace Merge.Client.Ats; -public class TagsListRequest +public record TagsListRequest { /// /// If provided, will only return objects created after this datetime. /// - public DateTime? CreatedAfter { get; init; } + public DateTime? CreatedAfter { get; set; } /// /// If provided, will only return objects created before this datetime. /// - public DateTime? CreatedBefore { get; init; } + public DateTime? CreatedBefore { get; set; } /// /// The pagination cursor value. /// - public string? Cursor { get; init; } + public string? Cursor { get; set; } /// /// Whether to include data that was marked as deleted by third party webhooks. /// - public bool? IncludeDeletedData { get; init; } + public bool? IncludeDeletedData { get; set; } /// /// Whether to include the original data Merge fetched from the third-party to produce these models. /// - public bool? IncludeRemoteData { get; init; } + public bool? IncludeRemoteData { get; set; } /// /// If provided, only objects synced by Merge after this date time will be returned. /// - public DateTime? ModifiedAfter { get; init; } + public DateTime? ModifiedAfter { get; set; } /// /// If provided, only objects synced by Merge before this date time will be returned. /// - public DateTime? ModifiedBefore { get; init; } + public DateTime? ModifiedBefore { get; set; } /// /// Number of results to return per page. /// - public int? PageSize { get; init; } + public int? PageSize { get; set; } /// /// The API provider's ID for the given object. /// - public string? RemoteId { get; init; } + public string? RemoteId { get; set; } } diff --git a/src/Merge.Client/Ats/Tags/TagsClient.cs b/src/Merge.Client/Ats/Tags/TagsClient.cs index 092074d3..62dfc332 100644 --- a/src/Merge.Client/Ats/Tags/TagsClient.cs +++ b/src/Merge.Client/Ats/Tags/TagsClient.cs @@ -1,6 +1,6 @@ +using System.Net.Http; using System.Text.Json; -using Merge.Client; -using Merge.Client.Ats; +using Merge.Client.Core; #nullable enable @@ -18,16 +18,21 @@ public TagsClient(RawClient client) /// /// Returns a list of `Tag` objects. /// - public async Task ListAsync(TagsListRequest request) + public async Task ListAsync( + TagsListRequest request, + RequestOptions? options = null + ) { var _query = new Dictionary() { }; if (request.CreatedAfter != null) { - _query["created_after"] = request.CreatedAfter.Value.ToString("o0"); + _query["created_after"] = request.CreatedAfter.Value.ToString(Constants.DateTimeFormat); } if (request.CreatedBefore != null) { - _query["created_before"] = request.CreatedBefore.Value.ToString("o0"); + _query["created_before"] = request.CreatedBefore.Value.ToString( + Constants.DateTimeFormat + ); } if (request.Cursor != null) { @@ -43,11 +48,15 @@ public async Task ListAsync(TagsListRequest request) } if (request.ModifiedAfter != null) { - _query["modified_after"] = request.ModifiedAfter.Value.ToString("o0"); + _query["modified_after"] = request.ModifiedAfter.Value.ToString( + Constants.DateTimeFormat + ); } if (request.ModifiedBefore != null) { - _query["modified_before"] = request.ModifiedBefore.Value.ToString("o0"); + _query["modified_before"] = request.ModifiedBefore.Value.ToString( + Constants.DateTimeFormat + ); } if (request.PageSize != null) { @@ -60,16 +69,30 @@ public async Task ListAsync(TagsListRequest request) var response = await _client.MakeRequestAsync( new RawClient.JsonApiRequest { + BaseUrl = _client.Options.BaseUrl, Method = HttpMethod.Get, Path = "ats/v1/tags", - Query = _query + Query = _query, + Options = options } ); - string responseBody = await response.Raw.Content.ReadAsStringAsync(); - if (response.StatusCode >= 200 && response.StatusCode < 400) + var responseBody = await response.Raw.Content.ReadAsStringAsync(); + if (response.StatusCode is >= 200 and < 400) { - return JsonSerializer.Deserialize(responseBody); + try + { + return JsonUtils.Deserialize(responseBody)!; + } + catch (JsonException e) + { + throw new MergeException("Failed to deserialize response", e); + } } - throw new Exception(responseBody); + + throw new MergeApiException( + $"Error with status code {response.StatusCode}", + response.StatusCode, + JsonUtils.Deserialize(responseBody) + ); } } diff --git a/src/Merge.Client/Ats/Types/AccessRoleEnum.cs b/src/Merge.Client/Ats/Types/AccessRoleEnum.cs index 7afb0786..026170b9 100644 --- a/src/Merge.Client/Ats/Types/AccessRoleEnum.cs +++ b/src/Merge.Client/Ats/Types/AccessRoleEnum.cs @@ -1,6 +1,5 @@ using System.Runtime.Serialization; using System.Text.Json.Serialization; -using Merge.Client.Ats; using Merge.Client.Core; #nullable enable diff --git a/src/Merge.Client/Ats/Types/AccountDetails.cs b/src/Merge.Client/Ats/Types/AccountDetails.cs index 6e2517bc..7416811d 100644 --- a/src/Merge.Client/Ats/Types/AccountDetails.cs +++ b/src/Merge.Client/Ats/Types/AccountDetails.cs @@ -1,45 +1,44 @@ using System.Text.Json.Serialization; -using Merge.Client.Ats; #nullable enable namespace Merge.Client.Ats; -public class AccountDetails +public record AccountDetails { [JsonPropertyName("id")] - public string? Id { get; init; } + public string? Id { get; set; } [JsonPropertyName("integration")] - public string? Integration { get; init; } + public string? Integration { get; set; } [JsonPropertyName("integration_slug")] - public string? IntegrationSlug { get; init; } + public string? IntegrationSlug { get; set; } [JsonPropertyName("category")] - public CategoryEnum? Category { get; init; } + public CategoryEnum? Category { get; set; } [JsonPropertyName("end_user_origin_id")] - public string? EndUserOriginId { get; init; } + public string? EndUserOriginId { get; set; } [JsonPropertyName("end_user_organization_name")] - public string? EndUserOrganizationName { get; init; } + public string? EndUserOrganizationName { get; set; } [JsonPropertyName("end_user_email_address")] - public string? EndUserEmailAddress { get; init; } + public string? EndUserEmailAddress { get; set; } [JsonPropertyName("status")] - public string? Status { get; init; } + public string? Status { get; set; } [JsonPropertyName("webhook_listener_url")] - public string? WebhookListenerUrl { get; init; } + public string? WebhookListenerUrl { get; set; } /// /// Whether a Production Linked Account's credentials match another existing Production Linked Account. This field is `null` for Test Linked Accounts, incomplete Production Linked Accounts, and ignored duplicate Production Linked Account sets. /// [JsonPropertyName("is_duplicate")] - public bool? IsDuplicate { get; init; } + public bool? IsDuplicate { get; set; } [JsonPropertyName("account_type")] - public string? AccountType { get; init; } + public string? AccountType { get; set; } } diff --git a/src/Merge.Client/Ats/Types/AccountDetailsAndActions.cs b/src/Merge.Client/Ats/Types/AccountDetailsAndActions.cs index 30242460..036be1d1 100644 --- a/src/Merge.Client/Ats/Types/AccountDetailsAndActions.cs +++ b/src/Merge.Client/Ats/Types/AccountDetailsAndActions.cs @@ -1,51 +1,50 @@ using System.Text.Json.Serialization; -using Merge.Client.Ats; #nullable enable namespace Merge.Client.Ats; -public class AccountDetailsAndActions +public record AccountDetailsAndActions { [JsonPropertyName("id")] - public string Id { get; init; } + public required string Id { get; set; } [JsonPropertyName("category")] - public CategoryEnum? Category { get; init; } + public CategoryEnum? Category { get; set; } [JsonPropertyName("status")] - public AccountDetailsAndActionsStatusEnum Status { get; init; } + public required AccountDetailsAndActionsStatusEnum Status { get; set; } [JsonPropertyName("status_detail")] - public string? StatusDetail { get; init; } + public string? StatusDetail { get; set; } [JsonPropertyName("end_user_origin_id")] - public string? EndUserOriginId { get; init; } + public string? EndUserOriginId { get; set; } [JsonPropertyName("end_user_organization_name")] - public string EndUserOrganizationName { get; init; } + public required string EndUserOrganizationName { get; set; } [JsonPropertyName("end_user_email_address")] - public string EndUserEmailAddress { get; init; } + public required string EndUserEmailAddress { get; set; } /// /// The tenant or domain the customer has provided access to. /// [JsonPropertyName("subdomain")] - public string? Subdomain { get; init; } + public string? Subdomain { get; set; } [JsonPropertyName("webhook_listener_url")] - public string WebhookListenerUrl { get; init; } + public required string WebhookListenerUrl { get; set; } /// /// Whether a Production Linked Account's credentials match another existing Production Linked Account. This field is `null` for Test Linked Accounts, incomplete Production Linked Accounts, and ignored duplicate Production Linked Account sets. /// [JsonPropertyName("is_duplicate")] - public bool? IsDuplicate { get; init; } + public bool? IsDuplicate { get; set; } [JsonPropertyName("integration")] - public AccountDetailsAndActionsIntegration? Integration { get; init; } + public AccountDetailsAndActionsIntegration? Integration { get; set; } [JsonPropertyName("account_type")] - public string AccountType { get; init; } + public required string AccountType { get; set; } } diff --git a/src/Merge.Client/Ats/Types/AccountDetailsAndActionsIntegration.cs b/src/Merge.Client/Ats/Types/AccountDetailsAndActionsIntegration.cs index d2ccc6f0..97d4b553 100644 --- a/src/Merge.Client/Ats/Types/AccountDetailsAndActionsIntegration.cs +++ b/src/Merge.Client/Ats/Types/AccountDetailsAndActionsIntegration.cs @@ -1,33 +1,32 @@ using System.Text.Json.Serialization; -using Merge.Client.Ats; #nullable enable namespace Merge.Client.Ats; -public class AccountDetailsAndActionsIntegration +public record AccountDetailsAndActionsIntegration { [JsonPropertyName("name")] - public string Name { get; init; } + public required string Name { get; set; } [JsonPropertyName("categories")] - public IEnumerable Categories { get; init; } + public IEnumerable Categories { get; set; } = new List(); [JsonPropertyName("image")] - public string? Image { get; init; } + public string? Image { get; set; } [JsonPropertyName("square_image")] - public string? SquareImage { get; init; } + public string? SquareImage { get; set; } [JsonPropertyName("color")] - public string Color { get; init; } + public required string Color { get; set; } [JsonPropertyName("slug")] - public string Slug { get; init; } + public required string Slug { get; set; } [JsonPropertyName("passthrough_available")] - public bool PassthroughAvailable { get; init; } + public required bool PassthroughAvailable { get; set; } [JsonPropertyName("available_model_operations")] - public IEnumerable? AvailableModelOperations { get; init; } + public IEnumerable? AvailableModelOperations { get; set; } } diff --git a/src/Merge.Client/Ats/Types/AccountDetailsAndActionsStatusEnum.cs b/src/Merge.Client/Ats/Types/AccountDetailsAndActionsStatusEnum.cs index 513068aa..3de37c61 100644 --- a/src/Merge.Client/Ats/Types/AccountDetailsAndActionsStatusEnum.cs +++ b/src/Merge.Client/Ats/Types/AccountDetailsAndActionsStatusEnum.cs @@ -1,6 +1,5 @@ using System.Runtime.Serialization; using System.Text.Json.Serialization; -using Merge.Client.Ats; using Merge.Client.Core; #nullable enable diff --git a/src/Merge.Client/Ats/Types/AccountIntegration.cs b/src/Merge.Client/Ats/Types/AccountIntegration.cs index 1b5e0cf1..d9a02f28 100644 --- a/src/Merge.Client/Ats/Types/AccountIntegration.cs +++ b/src/Merge.Client/Ats/Types/AccountIntegration.cs @@ -1,66 +1,65 @@ using System.Text.Json.Serialization; -using Merge.Client.Ats; #nullable enable namespace Merge.Client.Ats; -public class AccountIntegration +public record AccountIntegration { /// /// Company name. /// [JsonPropertyName("name")] - public string Name { get; init; } + public required string Name { get; set; } /// /// Optional. This shortened name appears in places with limited space, usually in conjunction with the platform's logo (e.g., Merge Link menu).

Example: Workforce Now (in lieu of ADP Workforce Now), SuccessFactors (in lieu of SAP SuccessFactors) ///
[JsonPropertyName("abbreviated_name")] - public string? AbbreviatedName { get; init; } + public string? AbbreviatedName { get; set; } /// /// Category or categories this integration belongs to. Multiple categories should be comma separated, i.e. [ats, hris]. /// [JsonPropertyName("categories")] - public IEnumerable? Categories { get; init; } + public IEnumerable? Categories { get; set; } /// /// Company logo in rectangular shape. Upload an image with a clear background. /// [JsonPropertyName("image")] - public string? Image { get; init; } + public string? Image { get; set; } /// /// Company logo in square shape. Upload an image with a white background. /// [JsonPropertyName("square_image")] - public string? SquareImage { get; init; } + public string? SquareImage { get; set; } /// /// The color of this integration used for buttons and text throughout the app and landing pages. Choose a darker, saturated color. /// [JsonPropertyName("color")] - public string? Color { get; init; } + public string? Color { get; set; } [JsonPropertyName("slug")] - public string? Slug { get; init; } + public string? Slug { get; set; } /// /// Mapping of API endpoints to documentation urls for support. Example: {'GET': [['/common-model-scopes', 'https://docs.merge.dev/accounting/common-model-scopes/#common_model_scopes_retrieve'],['/common-model-actions', 'https://docs.merge.dev/accounting/common-model-actions/#common_model_actions_retrieve']], 'POST': []} /// [JsonPropertyName("api_endpoints_to_documentation_urls")] - public Dictionary? ApiEndpointsToDocumentationUrls { get; init; } + public Dictionary? ApiEndpointsToDocumentationUrls { get; set; } /// /// Setup guide URL for third party webhook creation. Exposed in Merge Docs. /// [JsonPropertyName("webhook_setup_guide_url")] - public string? WebhookSetupGuideUrl { get; init; } + public string? WebhookSetupGuideUrl { get; set; } /// /// Category or categories this integration is in beta status for. /// [JsonPropertyName("category_beta_status")] - public Dictionary? CategoryBetaStatus { get; init; } + public Dictionary? CategoryBetaStatus { get; set; } } diff --git a/src/Merge.Client/Ats/Types/AccountToken.cs b/src/Merge.Client/Ats/Types/AccountToken.cs index b09446a9..5a61f1a9 100644 --- a/src/Merge.Client/Ats/Types/AccountToken.cs +++ b/src/Merge.Client/Ats/Types/AccountToken.cs @@ -1,15 +1,14 @@ using System.Text.Json.Serialization; -using Merge.Client.Ats; #nullable enable namespace Merge.Client.Ats; -public class AccountToken +public record AccountToken { [JsonPropertyName("account_token")] - public string AccountToken_ { get; init; } + public required string AccountToken_ { get; set; } [JsonPropertyName("integration")] - public AccountIntegration Integration { get; init; } + public required AccountIntegration Integration { get; set; } } diff --git a/src/Merge.Client/Ats/Types/Activity.cs b/src/Merge.Client/Ats/Types/Activity.cs index a5124142..8ddee898 100644 --- a/src/Merge.Client/Ats/Types/Activity.cs +++ b/src/Merge.Client/Ats/Types/Activity.cs @@ -1,5 +1,4 @@ using System.Text.Json.Serialization; -using Merge.Client.Ats; using Merge.Client.Core; using OneOf; @@ -7,41 +6,41 @@ namespace Merge.Client.Ats; -public class Activity +public record Activity { [JsonPropertyName("id")] - public string? Id { get; init; } + public string? Id { get; set; } /// /// The third-party API ID of the matching object. /// [JsonPropertyName("remote_id")] - public string? RemoteId { get; init; } + public string? RemoteId { get; set; } /// /// The datetime that this object was created by Merge. /// [JsonPropertyName("created_at")] - public DateTime? CreatedAt { get; init; } + public DateTime? CreatedAt { get; set; } /// /// The datetime that this object was modified by Merge. /// [JsonPropertyName("modified_at")] - public DateTime? ModifiedAt { get; init; } + public DateTime? ModifiedAt { get; set; } /// /// The user that performed the action. /// [JsonPropertyName("user")] [JsonConverter(typeof(OneOfSerializer>))] - public OneOf? User { get; init; } + public OneOf? User { get; set; } /// /// When the third party's activity was created. /// [JsonPropertyName("remote_created_at")] - public DateTime? RemoteCreatedAt { get; init; } + public DateTime? RemoteCreatedAt { get; set; } /// /// The activity's type. @@ -51,19 +50,19 @@ public class Activity /// - `OTHER` - OTHER /// [JsonPropertyName("activity_type")] - public ActivityTypeEnum? ActivityType { get; init; } + public ActivityTypeEnum? ActivityType { get; set; } /// /// The activity's subject. /// [JsonPropertyName("subject")] - public string? Subject { get; init; } + public string? Subject { get; set; } /// /// The activity's body. /// [JsonPropertyName("body")] - public string? Body { get; init; } + public string? Body { get; set; } /// /// The activity's visibility. @@ -73,20 +72,20 @@ public class Activity /// - `PRIVATE` - PRIVATE /// [JsonPropertyName("visibility")] - public VisibilityEnum? Visibility { get; init; } + public VisibilityEnum? Visibility { get; set; } [JsonPropertyName("candidate")] - public string? Candidate { get; init; } + public string? Candidate { get; set; } /// /// Indicates whether or not this object has been deleted in the third party platform. /// [JsonPropertyName("remote_was_deleted")] - public bool? RemoteWasDeleted { get; init; } + public bool? RemoteWasDeleted { get; set; } [JsonPropertyName("field_mappings")] - public Dictionary? FieldMappings { get; init; } + public Dictionary? FieldMappings { get; set; } [JsonPropertyName("remote_data")] - public IEnumerable? RemoteData { get; init; } + public IEnumerable? RemoteData { get; set; } } diff --git a/src/Merge.Client/Ats/Types/ActivityRequest.cs b/src/Merge.Client/Ats/Types/ActivityRequest.cs index 37d8f9f0..9d115a60 100644 --- a/src/Merge.Client/Ats/Types/ActivityRequest.cs +++ b/src/Merge.Client/Ats/Types/ActivityRequest.cs @@ -1,5 +1,4 @@ using System.Text.Json.Serialization; -using Merge.Client.Ats; using Merge.Client.Core; using OneOf; @@ -7,14 +6,14 @@ namespace Merge.Client.Ats; -public class ActivityRequest +public record ActivityRequest { /// /// The user that performed the action. /// [JsonPropertyName("user")] [JsonConverter(typeof(OneOfSerializer>))] - public OneOf? User { get; init; } + public OneOf? User { get; set; } /// /// The activity's type. @@ -24,19 +23,19 @@ public class ActivityRequest /// - `OTHER` - OTHER /// [JsonPropertyName("activity_type")] - public ActivityTypeEnum? ActivityType { get; init; } + public ActivityTypeEnum? ActivityType { get; set; } /// /// The activity's subject. /// [JsonPropertyName("subject")] - public string? Subject { get; init; } + public string? Subject { get; set; } /// /// The activity's body. /// [JsonPropertyName("body")] - public string? Body { get; init; } + public string? Body { get; set; } /// /// The activity's visibility. @@ -46,14 +45,14 @@ public class ActivityRequest /// - `PRIVATE` - PRIVATE /// [JsonPropertyName("visibility")] - public VisibilityEnum? Visibility { get; init; } + public VisibilityEnum? Visibility { get; set; } [JsonPropertyName("candidate")] - public string? Candidate { get; init; } + public string? Candidate { get; set; } [JsonPropertyName("integration_params")] - public Dictionary? IntegrationParams { get; init; } + public Dictionary? IntegrationParams { get; set; } [JsonPropertyName("linked_account_params")] - public Dictionary? LinkedAccountParams { get; init; } + public Dictionary? LinkedAccountParams { get; set; } } diff --git a/src/Merge.Client/Ats/Types/ActivityResponse.cs b/src/Merge.Client/Ats/Types/ActivityResponse.cs index 55cc8485..c750c354 100644 --- a/src/Merge.Client/Ats/Types/ActivityResponse.cs +++ b/src/Merge.Client/Ats/Types/ActivityResponse.cs @@ -1,21 +1,22 @@ using System.Text.Json.Serialization; -using Merge.Client.Ats; #nullable enable namespace Merge.Client.Ats; -public class ActivityResponse +public record ActivityResponse { [JsonPropertyName("model")] - public Activity Model { get; init; } + public required Activity Model { get; set; } [JsonPropertyName("warnings")] - public IEnumerable Warnings { get; init; } + public IEnumerable Warnings { get; set; } = + new List(); [JsonPropertyName("errors")] - public IEnumerable Errors { get; init; } + public IEnumerable Errors { get; set; } = + new List(); [JsonPropertyName("logs")] - public IEnumerable? Logs { get; init; } + public IEnumerable? Logs { get; set; } } diff --git a/src/Merge.Client/Ats/Types/ActivityTypeEnum.cs b/src/Merge.Client/Ats/Types/ActivityTypeEnum.cs index fc5d2c88..5b0cfe23 100644 --- a/src/Merge.Client/Ats/Types/ActivityTypeEnum.cs +++ b/src/Merge.Client/Ats/Types/ActivityTypeEnum.cs @@ -1,6 +1,5 @@ using System.Runtime.Serialization; using System.Text.Json.Serialization; -using Merge.Client.Ats; using Merge.Client.Core; #nullable enable diff --git a/src/Merge.Client/Ats/Types/AdvancedMetadata.cs b/src/Merge.Client/Ats/Types/AdvancedMetadata.cs index fbcbc864..4643717c 100644 --- a/src/Merge.Client/Ats/Types/AdvancedMetadata.cs +++ b/src/Merge.Client/Ats/Types/AdvancedMetadata.cs @@ -4,23 +4,23 @@ namespace Merge.Client.Ats; -public class AdvancedMetadata +public record AdvancedMetadata { [JsonPropertyName("id")] - public string Id { get; init; } + public required string Id { get; set; } [JsonPropertyName("display_name")] - public string? DisplayName { get; init; } + public string? DisplayName { get; set; } [JsonPropertyName("description")] - public string? Description { get; init; } + public string? Description { get; set; } [JsonPropertyName("is_required")] - public bool? IsRequired { get; init; } + public bool? IsRequired { get; set; } [JsonPropertyName("is_custom")] - public bool? IsCustom { get; init; } + public bool? IsCustom { get; set; } [JsonPropertyName("field_choices")] - public IEnumerable? FieldChoices { get; init; } + public IEnumerable? FieldChoices { get; set; } } diff --git a/src/Merge.Client/Ats/Types/Application.cs b/src/Merge.Client/Ats/Types/Application.cs index da9122be..706f0b41 100644 --- a/src/Merge.Client/Ats/Types/Application.cs +++ b/src/Merge.Client/Ats/Types/Application.cs @@ -1,5 +1,4 @@ using System.Text.Json.Serialization; -using Merge.Client.Ats; using Merge.Client.Core; using OneOf; @@ -7,54 +6,54 @@ namespace Merge.Client.Ats; -public class Application +public record Application { [JsonPropertyName("id")] - public string? Id { get; init; } + public string? Id { get; set; } /// /// The third-party API ID of the matching object. /// [JsonPropertyName("remote_id")] - public string? RemoteId { get; init; } + public string? RemoteId { get; set; } /// /// The datetime that this object was created by Merge. /// [JsonPropertyName("created_at")] - public DateTime? CreatedAt { get; init; } + public DateTime? CreatedAt { get; set; } /// /// The datetime that this object was modified by Merge. /// [JsonPropertyName("modified_at")] - public DateTime? ModifiedAt { get; init; } + public DateTime? ModifiedAt { get; set; } /// /// The candidate applying. /// [JsonPropertyName("candidate")] [JsonConverter(typeof(OneOfSerializer>))] - public OneOf? Candidate { get; init; } + public OneOf? Candidate { get; set; } /// /// The job being applied for. /// [JsonPropertyName("job")] [JsonConverter(typeof(OneOfSerializer>))] - public OneOf? Job { get; init; } + public OneOf? Job { get; set; } /// /// When the application was submitted. /// [JsonPropertyName("applied_at")] - public DateTime? AppliedAt { get; init; } + public DateTime? AppliedAt { get; set; } /// /// When the application was rejected. /// [JsonPropertyName("rejected_at")] - public DateTime? RejectedAt { get; init; } + public DateTime? RejectedAt { get; set; } [JsonPropertyName("offers")] [JsonConverter( @@ -63,20 +62,20 @@ public class Application OneOfSerializer> >) )] - public IEnumerable>? Offers { get; init; } + public IEnumerable>? Offers { get; set; } /// /// The application's source. /// [JsonPropertyName("source")] - public string? Source { get; init; } + public string? Source { get; set; } /// /// The user credited for this application. /// [JsonPropertyName("credited_to")] [JsonConverter(typeof(OneOfSerializer>))] - public OneOf? CreditedTo { get; init; } + public OneOf? CreditedTo { get; set; } [JsonPropertyName("screening_question_answers")] [JsonConverter( @@ -87,28 +86,28 @@ public class Application )] public IEnumerable< OneOf - >? ScreeningQuestionAnswers { get; init; } + >? ScreeningQuestionAnswers { get; set; } /// /// The application's current stage. /// [JsonPropertyName("current_stage")] [JsonConverter(typeof(OneOfSerializer>))] - public OneOf? CurrentStage { get; init; } + public OneOf? CurrentStage { get; set; } /// /// The application's reason for rejection. /// [JsonPropertyName("reject_reason")] [JsonConverter(typeof(OneOfSerializer>))] - public OneOf? RejectReason { get; init; } + public OneOf? RejectReason { get; set; } [JsonPropertyName("remote_was_deleted")] - public bool? RemoteWasDeleted { get; init; } + public bool? RemoteWasDeleted { get; set; } [JsonPropertyName("field_mappings")] - public Dictionary? FieldMappings { get; init; } + public Dictionary? FieldMappings { get; set; } [JsonPropertyName("remote_data")] - public IEnumerable? RemoteData { get; init; } + public IEnumerable? RemoteData { get; set; } } diff --git a/src/Merge.Client/Ats/Types/ApplicationRequest.cs b/src/Merge.Client/Ats/Types/ApplicationRequest.cs index 97411a8d..397555bb 100644 --- a/src/Merge.Client/Ats/Types/ApplicationRequest.cs +++ b/src/Merge.Client/Ats/Types/ApplicationRequest.cs @@ -1,5 +1,4 @@ using System.Text.Json.Serialization; -using Merge.Client.Ats; using Merge.Client.Core; using OneOf; @@ -7,33 +6,33 @@ namespace Merge.Client.Ats; -public class ApplicationRequest +public record ApplicationRequest { /// /// The candidate applying. /// [JsonPropertyName("candidate")] [JsonConverter(typeof(OneOfSerializer>))] - public OneOf? Candidate { get; init; } + public OneOf? Candidate { get; set; } /// /// The job being applied for. /// [JsonPropertyName("job")] [JsonConverter(typeof(OneOfSerializer>))] - public OneOf? Job { get; init; } + public OneOf? Job { get; set; } /// /// When the application was submitted. /// [JsonPropertyName("applied_at")] - public DateTime? AppliedAt { get; init; } + public DateTime? AppliedAt { get; set; } /// /// When the application was rejected. /// [JsonPropertyName("rejected_at")] - public DateTime? RejectedAt { get; init; } + public DateTime? RejectedAt { get; set; } [JsonPropertyName("offers")] [JsonConverter( @@ -42,20 +41,20 @@ public class ApplicationRequest OneOfSerializer> >) )] - public IEnumerable>? Offers { get; init; } + public IEnumerable>? Offers { get; set; } /// /// The application's source. /// [JsonPropertyName("source")] - public string? Source { get; init; } + public string? Source { get; set; } /// /// The user credited for this application. /// [JsonPropertyName("credited_to")] [JsonConverter(typeof(OneOfSerializer>))] - public OneOf? CreditedTo { get; init; } + public OneOf? CreditedTo { get; set; } [JsonPropertyName("screening_question_answers")] [JsonConverter( @@ -66,28 +65,28 @@ public class ApplicationRequest )] public IEnumerable< OneOf - >? ScreeningQuestionAnswers { get; init; } + >? ScreeningQuestionAnswers { get; set; } /// /// The application's current stage. /// [JsonPropertyName("current_stage")] [JsonConverter(typeof(OneOfSerializer>))] - public OneOf? CurrentStage { get; init; } + public OneOf? CurrentStage { get; set; } /// /// The application's reason for rejection. /// [JsonPropertyName("reject_reason")] [JsonConverter(typeof(OneOfSerializer>))] - public OneOf? RejectReason { get; init; } + public OneOf? RejectReason { get; set; } [JsonPropertyName("remote_template_id")] - public string? RemoteTemplateId { get; init; } + public string? RemoteTemplateId { get; set; } [JsonPropertyName("integration_params")] - public Dictionary? IntegrationParams { get; init; } + public Dictionary? IntegrationParams { get; set; } [JsonPropertyName("linked_account_params")] - public Dictionary? LinkedAccountParams { get; init; } + public Dictionary? LinkedAccountParams { get; set; } } diff --git a/src/Merge.Client/Ats/Types/ApplicationResponse.cs b/src/Merge.Client/Ats/Types/ApplicationResponse.cs index a419cb18..d012c010 100644 --- a/src/Merge.Client/Ats/Types/ApplicationResponse.cs +++ b/src/Merge.Client/Ats/Types/ApplicationResponse.cs @@ -1,21 +1,22 @@ using System.Text.Json.Serialization; -using Merge.Client.Ats; #nullable enable namespace Merge.Client.Ats; -public class ApplicationResponse +public record ApplicationResponse { [JsonPropertyName("model")] - public Application Model { get; init; } + public required Application Model { get; set; } [JsonPropertyName("warnings")] - public IEnumerable Warnings { get; init; } + public IEnumerable Warnings { get; set; } = + new List(); [JsonPropertyName("errors")] - public IEnumerable Errors { get; init; } + public IEnumerable Errors { get; set; } = + new List(); [JsonPropertyName("logs")] - public IEnumerable? Logs { get; init; } + public IEnumerable? Logs { get; set; } } diff --git a/src/Merge.Client/Ats/Types/AsyncPassthroughReciept.cs b/src/Merge.Client/Ats/Types/AsyncPassthroughReciept.cs index 72c6b88f..4da3cc6c 100644 --- a/src/Merge.Client/Ats/Types/AsyncPassthroughReciept.cs +++ b/src/Merge.Client/Ats/Types/AsyncPassthroughReciept.cs @@ -4,8 +4,8 @@ namespace Merge.Client.Ats; -public class AsyncPassthroughReciept +public record AsyncPassthroughReciept { [JsonPropertyName("async_passthrough_receipt_id")] - public string AsyncPassthroughReceiptId { get; init; } + public required string AsyncPassthroughReceiptId { get; set; } } diff --git a/src/Merge.Client/Ats/Types/Attachment.cs b/src/Merge.Client/Ats/Types/Attachment.cs index 68689bbd..5563c733 100644 --- a/src/Merge.Client/Ats/Types/Attachment.cs +++ b/src/Merge.Client/Ats/Types/Attachment.cs @@ -1,50 +1,49 @@ using System.Text.Json.Serialization; -using Merge.Client.Ats; #nullable enable namespace Merge.Client.Ats; -public class Attachment +public record Attachment { [JsonPropertyName("id")] - public string? Id { get; init; } + public string? Id { get; set; } /// /// The third-party API ID of the matching object. /// [JsonPropertyName("remote_id")] - public string? RemoteId { get; init; } + public string? RemoteId { get; set; } /// /// The datetime that this object was created by Merge. /// [JsonPropertyName("created_at")] - public DateTime? CreatedAt { get; init; } + public DateTime? CreatedAt { get; set; } /// /// The datetime that this object was modified by Merge. /// [JsonPropertyName("modified_at")] - public DateTime? ModifiedAt { get; init; } + public DateTime? ModifiedAt { get; set; } /// /// The attachment's name. /// [JsonPropertyName("file_name")] - public string? FileName { get; init; } + public string? FileName { get; set; } /// /// The attachment's url. /// [JsonPropertyName("file_url")] - public string? FileUrl { get; init; } + public string? FileUrl { get; set; } /// /// /// [JsonPropertyName("candidate")] - public string? Candidate { get; init; } + public string? Candidate { get; set; } /// /// The attachment's type. @@ -55,14 +54,14 @@ public class Attachment /// - `OTHER` - OTHER /// [JsonPropertyName("attachment_type")] - public AttachmentTypeEnum? AttachmentType { get; init; } + public AttachmentTypeEnum? AttachmentType { get; set; } [JsonPropertyName("remote_was_deleted")] - public bool? RemoteWasDeleted { get; init; } + public bool? RemoteWasDeleted { get; set; } [JsonPropertyName("field_mappings")] - public Dictionary? FieldMappings { get; init; } + public Dictionary? FieldMappings { get; set; } [JsonPropertyName("remote_data")] - public IEnumerable? RemoteData { get; init; } + public IEnumerable? RemoteData { get; set; } } diff --git a/src/Merge.Client/Ats/Types/AttachmentRequest.cs b/src/Merge.Client/Ats/Types/AttachmentRequest.cs index 5773cda9..320ad4d4 100644 --- a/src/Merge.Client/Ats/Types/AttachmentRequest.cs +++ b/src/Merge.Client/Ats/Types/AttachmentRequest.cs @@ -1,29 +1,28 @@ using System.Text.Json.Serialization; -using Merge.Client.Ats; #nullable enable namespace Merge.Client.Ats; -public class AttachmentRequest +public record AttachmentRequest { /// /// The attachment's name. /// [JsonPropertyName("file_name")] - public string? FileName { get; init; } + public string? FileName { get; set; } /// /// The attachment's url. /// [JsonPropertyName("file_url")] - public string? FileUrl { get; init; } + public string? FileUrl { get; set; } /// /// /// [JsonPropertyName("candidate")] - public string? Candidate { get; init; } + public string? Candidate { get; set; } /// /// The attachment's type. @@ -34,11 +33,11 @@ public class AttachmentRequest /// - `OTHER` - OTHER /// [JsonPropertyName("attachment_type")] - public AttachmentTypeEnum? AttachmentType { get; init; } + public AttachmentTypeEnum? AttachmentType { get; set; } [JsonPropertyName("integration_params")] - public Dictionary? IntegrationParams { get; init; } + public Dictionary? IntegrationParams { get; set; } [JsonPropertyName("linked_account_params")] - public Dictionary? LinkedAccountParams { get; init; } + public Dictionary? LinkedAccountParams { get; set; } } diff --git a/src/Merge.Client/Ats/Types/AttachmentResponse.cs b/src/Merge.Client/Ats/Types/AttachmentResponse.cs index 9287da25..f859694b 100644 --- a/src/Merge.Client/Ats/Types/AttachmentResponse.cs +++ b/src/Merge.Client/Ats/Types/AttachmentResponse.cs @@ -1,21 +1,22 @@ using System.Text.Json.Serialization; -using Merge.Client.Ats; #nullable enable namespace Merge.Client.Ats; -public class AttachmentResponse +public record AttachmentResponse { [JsonPropertyName("model")] - public Attachment Model { get; init; } + public required Attachment Model { get; set; } [JsonPropertyName("warnings")] - public IEnumerable Warnings { get; init; } + public IEnumerable Warnings { get; set; } = + new List(); [JsonPropertyName("errors")] - public IEnumerable Errors { get; init; } + public IEnumerable Errors { get; set; } = + new List(); [JsonPropertyName("logs")] - public IEnumerable? Logs { get; init; } + public IEnumerable? Logs { get; set; } } diff --git a/src/Merge.Client/Ats/Types/AttachmentTypeEnum.cs b/src/Merge.Client/Ats/Types/AttachmentTypeEnum.cs index 422c1a17..8318ee80 100644 --- a/src/Merge.Client/Ats/Types/AttachmentTypeEnum.cs +++ b/src/Merge.Client/Ats/Types/AttachmentTypeEnum.cs @@ -1,6 +1,5 @@ using System.Runtime.Serialization; using System.Text.Json.Serialization; -using Merge.Client.Ats; using Merge.Client.Core; #nullable enable diff --git a/src/Merge.Client/Ats/Types/AuditLogEvent.cs b/src/Merge.Client/Ats/Types/AuditLogEvent.cs index 22c55d38..92e0d220 100644 --- a/src/Merge.Client/Ats/Types/AuditLogEvent.cs +++ b/src/Merge.Client/Ats/Types/AuditLogEvent.cs @@ -1,26 +1,25 @@ using System.Text.Json.Serialization; -using Merge.Client.Ats; #nullable enable namespace Merge.Client.Ats; -public class AuditLogEvent +public record AuditLogEvent { [JsonPropertyName("id")] - public string? Id { get; init; } + public string? Id { get; set; } /// /// The User's full name at the time of this Event occurring. /// [JsonPropertyName("user_name")] - public string? UserName { get; init; } + public string? UserName { get; set; } /// /// The User's email at the time of this Event occurring. /// [JsonPropertyName("user_email")] - public string? UserEmail { get; init; } + public string? UserEmail { get; set; } /// /// Designates the role of the user (or SYSTEM/API if action not taken by a user) at the time of this Event occurring. @@ -33,10 +32,10 @@ public class AuditLogEvent /// - `MERGE_TEAM` - MERGE_TEAM /// [JsonPropertyName("role")] - public RoleEnum Role { get; init; } + public required RoleEnum Role { get; set; } [JsonPropertyName("ip_address")] - public string IpAddress { get; init; } + public required string IpAddress { get; set; } /// /// Designates the type of event that occurred. @@ -81,11 +80,11 @@ public class AuditLogEvent /// - `END_USER_CREDENTIALS_ACCESSED` - END_USER_CREDENTIALS_ACCESSED /// [JsonPropertyName("event_type")] - public EventTypeEnum EventType { get; init; } + public required EventTypeEnum EventType { get; set; } [JsonPropertyName("event_description")] - public string EventDescription { get; init; } + public required string EventDescription { get; set; } [JsonPropertyName("created_at")] - public DateTime? CreatedAt { get; init; } + public DateTime? CreatedAt { get; set; } } diff --git a/src/Merge.Client/Ats/Types/AvailableActions.cs b/src/Merge.Client/Ats/Types/AvailableActions.cs index 91c1d3c3..6c9dba4a 100644 --- a/src/Merge.Client/Ats/Types/AvailableActions.cs +++ b/src/Merge.Client/Ats/Types/AvailableActions.cs @@ -1,18 +1,17 @@ using System.Text.Json.Serialization; -using Merge.Client.Ats; #nullable enable namespace Merge.Client.Ats; -public class AvailableActions +public record AvailableActions { [JsonPropertyName("integration")] - public AccountIntegration Integration { get; init; } + public required AccountIntegration Integration { get; set; } [JsonPropertyName("passthrough_available")] - public bool PassthroughAvailable { get; init; } + public required bool PassthroughAvailable { get; set; } [JsonPropertyName("available_model_operations")] - public IEnumerable? AvailableModelOperations { get; init; } + public IEnumerable? AvailableModelOperations { get; set; } } diff --git a/src/Merge.Client/Ats/Types/Candidate.cs b/src/Merge.Client/Ats/Types/Candidate.cs index 4ce723d4..5f0ad7ad 100644 --- a/src/Merge.Client/Ats/Types/Candidate.cs +++ b/src/Merge.Client/Ats/Types/Candidate.cs @@ -1,5 +1,4 @@ using System.Text.Json.Serialization; -using Merge.Client.Ats; using Merge.Client.Core; using OneOf; @@ -7,103 +6,103 @@ namespace Merge.Client.Ats; -public class Candidate +public record Candidate { [JsonPropertyName("id")] - public string? Id { get; init; } + public string? Id { get; set; } /// /// The third-party API ID of the matching object. /// [JsonPropertyName("remote_id")] - public string? RemoteId { get; init; } + public string? RemoteId { get; set; } /// /// The datetime that this object was created by Merge. /// [JsonPropertyName("created_at")] - public DateTime? CreatedAt { get; init; } + public DateTime? CreatedAt { get; set; } /// /// The datetime that this object was modified by Merge. /// [JsonPropertyName("modified_at")] - public DateTime? ModifiedAt { get; init; } + public DateTime? ModifiedAt { get; set; } /// /// The candidate's first name. /// [JsonPropertyName("first_name")] - public string? FirstName { get; init; } + public string? FirstName { get; set; } /// /// The candidate's last name. /// [JsonPropertyName("last_name")] - public string? LastName { get; init; } + public string? LastName { get; set; } /// /// The candidate's current company. /// [JsonPropertyName("company")] - public string? Company { get; init; } + public string? Company { get; set; } /// /// The candidate's current title. /// [JsonPropertyName("title")] - public string? Title { get; init; } + public string? Title { get; set; } /// /// When the third party's candidate was created. /// [JsonPropertyName("remote_created_at")] - public DateTime? RemoteCreatedAt { get; init; } + public DateTime? RemoteCreatedAt { get; set; } /// /// When the third party's candidate was updated. /// [JsonPropertyName("remote_updated_at")] - public DateTime? RemoteUpdatedAt { get; init; } + public DateTime? RemoteUpdatedAt { get; set; } /// /// When the most recent interaction with the candidate occurred. /// [JsonPropertyName("last_interaction_at")] - public DateTime? LastInteractionAt { get; init; } + public DateTime? LastInteractionAt { get; set; } /// /// Whether or not the candidate is private. /// [JsonPropertyName("is_private")] - public bool? IsPrivate { get; init; } + public bool? IsPrivate { get; set; } /// /// Whether or not the candidate can be emailed. /// [JsonPropertyName("can_email")] - public bool? CanEmail { get; init; } + public bool? CanEmail { get; set; } /// /// The candidate's locations. /// [JsonPropertyName("locations")] - public IEnumerable? Locations { get; init; } + public IEnumerable? Locations { get; set; } [JsonPropertyName("phone_numbers")] - public IEnumerable? PhoneNumbers { get; init; } + public IEnumerable? PhoneNumbers { get; set; } [JsonPropertyName("email_addresses")] - public IEnumerable? EmailAddresses { get; init; } + public IEnumerable? EmailAddresses { get; set; } [JsonPropertyName("urls")] - public IEnumerable? Urls { get; init; } + public IEnumerable? Urls { get; set; } /// /// Array of `Tag` names as strings. /// [JsonPropertyName("tags")] - public IEnumerable? Tags { get; init; } + public IEnumerable? Tags { get; set; } /// /// Array of `Application` object IDs. @@ -115,7 +114,7 @@ public class Candidate OneOfSerializer> >) )] - public IEnumerable>? Applications { get; init; } + public IEnumerable>? Applications { get; set; } /// /// Array of `Attachment` object IDs. @@ -127,14 +126,14 @@ public class Candidate OneOfSerializer> >) )] - public IEnumerable>? Attachments { get; init; } + public IEnumerable>? Attachments { get; set; } [JsonPropertyName("remote_was_deleted")] - public bool? RemoteWasDeleted { get; init; } + public bool? RemoteWasDeleted { get; set; } [JsonPropertyName("field_mappings")] - public Dictionary? FieldMappings { get; init; } + public Dictionary? FieldMappings { get; set; } [JsonPropertyName("remote_data")] - public IEnumerable? RemoteData { get; init; } + public IEnumerable? RemoteData { get; set; } } diff --git a/src/Merge.Client/Ats/Types/CandidateRequest.cs b/src/Merge.Client/Ats/Types/CandidateRequest.cs index b7b13254..4a461608 100644 --- a/src/Merge.Client/Ats/Types/CandidateRequest.cs +++ b/src/Merge.Client/Ats/Types/CandidateRequest.cs @@ -1,5 +1,4 @@ using System.Text.Json.Serialization; -using Merge.Client.Ats; using Merge.Client.Core; using OneOf; @@ -7,70 +6,70 @@ namespace Merge.Client.Ats; -public class CandidateRequest +public record CandidateRequest { /// /// The candidate's first name. /// [JsonPropertyName("first_name")] - public string? FirstName { get; init; } + public string? FirstName { get; set; } /// /// The candidate's last name. /// [JsonPropertyName("last_name")] - public string? LastName { get; init; } + public string? LastName { get; set; } /// /// The candidate's current company. /// [JsonPropertyName("company")] - public string? Company { get; init; } + public string? Company { get; set; } /// /// The candidate's current title. /// [JsonPropertyName("title")] - public string? Title { get; init; } + public string? Title { get; set; } /// /// When the most recent interaction with the candidate occurred. /// [JsonPropertyName("last_interaction_at")] - public DateTime? LastInteractionAt { get; init; } + public DateTime? LastInteractionAt { get; set; } /// /// Whether or not the candidate is private. /// [JsonPropertyName("is_private")] - public bool? IsPrivate { get; init; } + public bool? IsPrivate { get; set; } /// /// Whether or not the candidate can be emailed. /// [JsonPropertyName("can_email")] - public bool? CanEmail { get; init; } + public bool? CanEmail { get; set; } /// /// The candidate's locations. /// [JsonPropertyName("locations")] - public IEnumerable? Locations { get; init; } + public IEnumerable? Locations { get; set; } [JsonPropertyName("phone_numbers")] - public IEnumerable? PhoneNumbers { get; init; } + public IEnumerable? PhoneNumbers { get; set; } [JsonPropertyName("email_addresses")] - public IEnumerable? EmailAddresses { get; init; } + public IEnumerable? EmailAddresses { get; set; } [JsonPropertyName("urls")] - public IEnumerable? Urls { get; init; } + public IEnumerable? Urls { get; set; } /// /// Array of `Tag` names as strings. /// [JsonPropertyName("tags")] - public IEnumerable? Tags { get; init; } + public IEnumerable? Tags { get; set; } /// /// Array of `Application` object IDs. @@ -82,7 +81,7 @@ public class CandidateRequest OneOfSerializer> >) )] - public IEnumerable>? Applications { get; init; } + public IEnumerable>? Applications { get; set; } /// /// Array of `Attachment` object IDs. @@ -94,14 +93,14 @@ public class CandidateRequest OneOfSerializer> >) )] - public IEnumerable>? Attachments { get; init; } + public IEnumerable>? Attachments { get; set; } [JsonPropertyName("remote_template_id")] - public string? RemoteTemplateId { get; init; } + public string? RemoteTemplateId { get; set; } [JsonPropertyName("integration_params")] - public Dictionary? IntegrationParams { get; init; } + public Dictionary? IntegrationParams { get; set; } [JsonPropertyName("linked_account_params")] - public Dictionary? LinkedAccountParams { get; init; } + public Dictionary? LinkedAccountParams { get; set; } } diff --git a/src/Merge.Client/Ats/Types/CandidateResponse.cs b/src/Merge.Client/Ats/Types/CandidateResponse.cs index 229f009b..0a7d082b 100644 --- a/src/Merge.Client/Ats/Types/CandidateResponse.cs +++ b/src/Merge.Client/Ats/Types/CandidateResponse.cs @@ -1,21 +1,22 @@ using System.Text.Json.Serialization; -using Merge.Client.Ats; #nullable enable namespace Merge.Client.Ats; -public class CandidateResponse +public record CandidateResponse { [JsonPropertyName("model")] - public Candidate Model { get; init; } + public required Candidate Model { get; set; } [JsonPropertyName("warnings")] - public IEnumerable Warnings { get; init; } + public IEnumerable Warnings { get; set; } = + new List(); [JsonPropertyName("errors")] - public IEnumerable Errors { get; init; } + public IEnumerable Errors { get; set; } = + new List(); [JsonPropertyName("logs")] - public IEnumerable? Logs { get; init; } + public IEnumerable? Logs { get; set; } } diff --git a/src/Merge.Client/Ats/Types/CategoriesEnum.cs b/src/Merge.Client/Ats/Types/CategoriesEnum.cs index bdd0c61a..e856a19f 100644 --- a/src/Merge.Client/Ats/Types/CategoriesEnum.cs +++ b/src/Merge.Client/Ats/Types/CategoriesEnum.cs @@ -1,6 +1,5 @@ using System.Runtime.Serialization; using System.Text.Json.Serialization; -using Merge.Client.Ats; using Merge.Client.Core; #nullable enable diff --git a/src/Merge.Client/Ats/Types/CategoryEnum.cs b/src/Merge.Client/Ats/Types/CategoryEnum.cs index 87ad021b..a6c8b93d 100644 --- a/src/Merge.Client/Ats/Types/CategoryEnum.cs +++ b/src/Merge.Client/Ats/Types/CategoryEnum.cs @@ -1,6 +1,5 @@ using System.Runtime.Serialization; using System.Text.Json.Serialization; -using Merge.Client.Ats; using Merge.Client.Core; #nullable enable diff --git a/src/Merge.Client/Ats/Types/CommonModelScopeApi.cs b/src/Merge.Client/Ats/Types/CommonModelScopeApi.cs index 4d40385f..55b8bcec 100644 --- a/src/Merge.Client/Ats/Types/CommonModelScopeApi.cs +++ b/src/Merge.Client/Ats/Types/CommonModelScopeApi.cs @@ -1,15 +1,15 @@ using System.Text.Json.Serialization; -using Merge.Client.Ats; #nullable enable namespace Merge.Client.Ats; -public class CommonModelScopeApi +public record CommonModelScopeApi { /// /// The common models you want to update the scopes for /// [JsonPropertyName("common_models")] - public IEnumerable CommonModels { get; init; } + public IEnumerable CommonModels { get; set; } = + new List(); } diff --git a/src/Merge.Client/Ats/Types/CommonModelScopesBodyRequest.cs b/src/Merge.Client/Ats/Types/CommonModelScopesBodyRequest.cs index f2fe8021..49445172 100644 --- a/src/Merge.Client/Ats/Types/CommonModelScopesBodyRequest.cs +++ b/src/Merge.Client/Ats/Types/CommonModelScopesBodyRequest.cs @@ -1,18 +1,18 @@ using System.Text.Json.Serialization; -using Merge.Client.Ats; #nullable enable namespace Merge.Client.Ats; -public class CommonModelScopesBodyRequest +public record CommonModelScopesBodyRequest { [JsonPropertyName("model_id")] - public string ModelId { get; init; } + public required string ModelId { get; set; } [JsonPropertyName("enabled_actions")] - public IEnumerable EnabledActions { get; init; } + public IEnumerable EnabledActions { get; set; } = + new List(); [JsonPropertyName("disabled_fields")] - public IEnumerable DisabledFields { get; init; } + public IEnumerable DisabledFields { get; set; } = new List(); } diff --git a/src/Merge.Client/Ats/Types/DataPassthroughRequest.cs b/src/Merge.Client/Ats/Types/DataPassthroughRequest.cs index a424cb29..cead9ff0 100644 --- a/src/Merge.Client/Ats/Types/DataPassthroughRequest.cs +++ b/src/Merge.Client/Ats/Types/DataPassthroughRequest.cs @@ -1,51 +1,50 @@ using System.Text.Json.Serialization; -using Merge.Client.Ats; #nullable enable namespace Merge.Client.Ats; -public class DataPassthroughRequest +public record DataPassthroughRequest { [JsonPropertyName("method")] - public MethodEnum Method { get; init; } + public required MethodEnum Method { get; set; } /// /// The path of the request in the third party's platform. /// [JsonPropertyName("path")] - public string Path { get; init; } + public required string Path { get; set; } /// /// An optional override of the third party's base url for the request. /// [JsonPropertyName("base_url_override")] - public string? BaseUrlOverride { get; init; } + public string? BaseUrlOverride { get; set; } /// /// The data with the request. You must include a `request_format` parameter matching the data's format /// [JsonPropertyName("data")] - public string? Data { get; init; } + public string? Data { get; set; } /// /// Pass an array of `MultipartFormField` objects in here instead of using the `data` param if `request_format` is set to `MULTIPART`. /// [JsonPropertyName("multipart_form_data")] - public IEnumerable? MultipartFormData { get; init; } + public IEnumerable? MultipartFormData { get; set; } /// /// The headers to use for the request (Merge will handle the account's authorization headers). `Content-Type` header is required for passthrough. Choose content type corresponding to expected format of receiving server. /// [JsonPropertyName("headers")] - public Dictionary? Headers { get; init; } + public Dictionary? Headers { get; set; } [JsonPropertyName("request_format")] - public RequestFormatEnum? RequestFormat { get; init; } + public RequestFormatEnum? RequestFormat { get; set; } /// /// Optional. If true, the response will always be an object of the form `{"type": T, "value": ...}` where `T` will be one of `string, boolean, number, null, array, object`. /// [JsonPropertyName("normalize_response")] - public bool? NormalizeResponse { get; init; } + public bool? NormalizeResponse { get; set; } } diff --git a/src/Merge.Client/Ats/Types/DebugModeLog.cs b/src/Merge.Client/Ats/Types/DebugModeLog.cs index cde19ab4..52be84e7 100644 --- a/src/Merge.Client/Ats/Types/DebugModeLog.cs +++ b/src/Merge.Client/Ats/Types/DebugModeLog.cs @@ -1,18 +1,17 @@ using System.Text.Json.Serialization; -using Merge.Client.Ats; #nullable enable namespace Merge.Client.Ats; -public class DebugModeLog +public record DebugModeLog { [JsonPropertyName("log_id")] - public string LogId { get; init; } + public required string LogId { get; set; } [JsonPropertyName("dashboard_view")] - public string DashboardView { get; init; } + public required string DashboardView { get; set; } [JsonPropertyName("log_summary")] - public DebugModelLogSummary LogSummary { get; init; } + public required DebugModelLogSummary LogSummary { get; set; } } diff --git a/src/Merge.Client/Ats/Types/DebugModelLogSummary.cs b/src/Merge.Client/Ats/Types/DebugModelLogSummary.cs index c22e7d37..517fd6ad 100644 --- a/src/Merge.Client/Ats/Types/DebugModelLogSummary.cs +++ b/src/Merge.Client/Ats/Types/DebugModelLogSummary.cs @@ -4,14 +4,14 @@ namespace Merge.Client.Ats; -public class DebugModelLogSummary +public record DebugModelLogSummary { [JsonPropertyName("url")] - public string Url { get; init; } + public required string Url { get; set; } [JsonPropertyName("method")] - public string Method { get; init; } + public required string Method { get; set; } [JsonPropertyName("status_code")] - public int StatusCode { get; init; } + public required int StatusCode { get; set; } } diff --git a/src/Merge.Client/Ats/Types/Department.cs b/src/Merge.Client/Ats/Types/Department.cs index 2e388b59..79530bd0 100644 --- a/src/Merge.Client/Ats/Types/Department.cs +++ b/src/Merge.Client/Ats/Types/Department.cs @@ -1,48 +1,47 @@ using System.Text.Json.Serialization; -using Merge.Client.Ats; #nullable enable namespace Merge.Client.Ats; -public class Department +public record Department { [JsonPropertyName("id")] - public string? Id { get; init; } + public string? Id { get; set; } /// /// The third-party API ID of the matching object. /// [JsonPropertyName("remote_id")] - public string? RemoteId { get; init; } + public string? RemoteId { get; set; } /// /// The datetime that this object was created by Merge. /// [JsonPropertyName("created_at")] - public DateTime? CreatedAt { get; init; } + public DateTime? CreatedAt { get; set; } /// /// The datetime that this object was modified by Merge. /// [JsonPropertyName("modified_at")] - public DateTime? ModifiedAt { get; init; } + public DateTime? ModifiedAt { get; set; } /// /// The department's name. /// [JsonPropertyName("name")] - public string? Name { get; init; } + public string? Name { get; set; } /// /// Indicates whether or not this object has been deleted in the third party platform. /// [JsonPropertyName("remote_was_deleted")] - public bool? RemoteWasDeleted { get; init; } + public bool? RemoteWasDeleted { get; set; } [JsonPropertyName("field_mappings")] - public Dictionary? FieldMappings { get; init; } + public Dictionary? FieldMappings { get; set; } [JsonPropertyName("remote_data")] - public IEnumerable? RemoteData { get; init; } + public IEnumerable? RemoteData { get; set; } } diff --git a/src/Merge.Client/Ats/Types/DisabilityStatusEnum.cs b/src/Merge.Client/Ats/Types/DisabilityStatusEnum.cs index 2d747dac..8a61d573 100644 --- a/src/Merge.Client/Ats/Types/DisabilityStatusEnum.cs +++ b/src/Merge.Client/Ats/Types/DisabilityStatusEnum.cs @@ -1,6 +1,5 @@ using System.Runtime.Serialization; using System.Text.Json.Serialization; -using Merge.Client.Ats; using Merge.Client.Core; #nullable enable diff --git a/src/Merge.Client/Ats/Types/Eeoc.cs b/src/Merge.Client/Ats/Types/Eeoc.cs index 0b3922f5..13912ca9 100644 --- a/src/Merge.Client/Ats/Types/Eeoc.cs +++ b/src/Merge.Client/Ats/Types/Eeoc.cs @@ -1,5 +1,4 @@ using System.Text.Json.Serialization; -using Merge.Client.Ats; using Merge.Client.Core; using OneOf; @@ -7,41 +6,41 @@ namespace Merge.Client.Ats; -public class Eeoc +public record Eeoc { [JsonPropertyName("id")] - public string? Id { get; init; } + public string? Id { get; set; } /// /// The third-party API ID of the matching object. /// [JsonPropertyName("remote_id")] - public string? RemoteId { get; init; } + public string? RemoteId { get; set; } /// /// The datetime that this object was created by Merge. /// [JsonPropertyName("created_at")] - public DateTime? CreatedAt { get; init; } + public DateTime? CreatedAt { get; set; } /// /// The datetime that this object was modified by Merge. /// [JsonPropertyName("modified_at")] - public DateTime? ModifiedAt { get; init; } + public DateTime? ModifiedAt { get; set; } /// /// The candidate being represented. /// [JsonPropertyName("candidate")] [JsonConverter(typeof(OneOfSerializer>))] - public OneOf? Candidate { get; init; } + public OneOf? Candidate { get; set; } /// /// When the information was submitted. /// [JsonPropertyName("submitted_at")] - public DateTime? SubmittedAt { get; init; } + public DateTime? SubmittedAt { get; set; } /// /// The candidate's race. @@ -56,7 +55,7 @@ public class Eeoc /// - `DECLINE_TO_SELF_IDENTIFY` - DECLINE_TO_SELF_IDENTIFY /// [JsonPropertyName("race")] - public RaceEnum? Race { get; init; } + public RaceEnum? Race { get; set; } /// /// The candidate's gender. @@ -68,7 +67,7 @@ public class Eeoc /// - `DECLINE_TO_SELF_IDENTIFY` - DECLINE_TO_SELF_IDENTIFY /// [JsonPropertyName("gender")] - public GenderEnum? Gender { get; init; } + public GenderEnum? Gender { get; set; } /// /// The candidate's veteran status. @@ -78,7 +77,7 @@ public class Eeoc /// - `I_DONT_WISH_TO_ANSWER` - I_DONT_WISH_TO_ANSWER /// [JsonPropertyName("veteran_status")] - public VeteranStatusEnum? VeteranStatus { get; init; } + public VeteranStatusEnum? VeteranStatus { get; set; } /// /// The candidate's disability status. @@ -88,17 +87,17 @@ public class Eeoc /// - `I_DONT_WISH_TO_ANSWER` - I_DONT_WISH_TO_ANSWER /// [JsonPropertyName("disability_status")] - public DisabilityStatusEnum? DisabilityStatus { get; init; } + public DisabilityStatusEnum? DisabilityStatus { get; set; } /// /// Indicates whether or not this object has been deleted in the third party platform. /// [JsonPropertyName("remote_was_deleted")] - public bool? RemoteWasDeleted { get; init; } + public bool? RemoteWasDeleted { get; set; } [JsonPropertyName("field_mappings")] - public Dictionary? FieldMappings { get; init; } + public Dictionary? FieldMappings { get; set; } [JsonPropertyName("remote_data")] - public IEnumerable? RemoteData { get; init; } + public IEnumerable? RemoteData { get; set; } } diff --git a/src/Merge.Client/Ats/Types/EmailAddress.cs b/src/Merge.Client/Ats/Types/EmailAddress.cs index 91c8f690..6a12130b 100644 --- a/src/Merge.Client/Ats/Types/EmailAddress.cs +++ b/src/Merge.Client/Ats/Types/EmailAddress.cs @@ -1,29 +1,28 @@ using System.Text.Json.Serialization; -using Merge.Client.Ats; #nullable enable namespace Merge.Client.Ats; -public class EmailAddress +public record EmailAddress { /// /// The datetime that this object was created by Merge. /// [JsonPropertyName("created_at")] - public DateTime? CreatedAt { get; init; } + public DateTime? CreatedAt { get; set; } /// /// The datetime that this object was modified by Merge. /// [JsonPropertyName("modified_at")] - public DateTime? ModifiedAt { get; init; } + public DateTime? ModifiedAt { get; set; } /// /// The email address. /// [JsonPropertyName("value")] - public string? Value { get; init; } + public string? Value { get; set; } /// /// The type of email address. @@ -33,11 +32,11 @@ public class EmailAddress /// - `OTHER` - OTHER /// [JsonPropertyName("email_address_type")] - public EmailAddressTypeEnum? EmailAddressType { get; init; } + public EmailAddressTypeEnum? EmailAddressType { get; set; } /// /// Indicates whether or not this object has been deleted in the third party platform. /// [JsonPropertyName("remote_was_deleted")] - public bool? RemoteWasDeleted { get; init; } + public bool? RemoteWasDeleted { get; set; } } diff --git a/src/Merge.Client/Ats/Types/EmailAddressRequest.cs b/src/Merge.Client/Ats/Types/EmailAddressRequest.cs index 3c1b9604..bb302bb1 100644 --- a/src/Merge.Client/Ats/Types/EmailAddressRequest.cs +++ b/src/Merge.Client/Ats/Types/EmailAddressRequest.cs @@ -1,17 +1,16 @@ using System.Text.Json.Serialization; -using Merge.Client.Ats; #nullable enable namespace Merge.Client.Ats; -public class EmailAddressRequest +public record EmailAddressRequest { /// /// The email address. /// [JsonPropertyName("value")] - public string? Value { get; init; } + public string? Value { get; set; } /// /// The type of email address. @@ -21,11 +20,11 @@ public class EmailAddressRequest /// - `OTHER` - OTHER /// [JsonPropertyName("email_address_type")] - public EmailAddressTypeEnum? EmailAddressType { get; init; } + public EmailAddressTypeEnum? EmailAddressType { get; set; } [JsonPropertyName("integration_params")] - public Dictionary? IntegrationParams { get; init; } + public Dictionary? IntegrationParams { get; set; } [JsonPropertyName("linked_account_params")] - public Dictionary? LinkedAccountParams { get; init; } + public Dictionary? LinkedAccountParams { get; set; } } diff --git a/src/Merge.Client/Ats/Types/EmailAddressTypeEnum.cs b/src/Merge.Client/Ats/Types/EmailAddressTypeEnum.cs index 1ec38aa9..655e169e 100644 --- a/src/Merge.Client/Ats/Types/EmailAddressTypeEnum.cs +++ b/src/Merge.Client/Ats/Types/EmailAddressTypeEnum.cs @@ -1,6 +1,5 @@ using System.Runtime.Serialization; using System.Text.Json.Serialization; -using Merge.Client.Ats; using Merge.Client.Core; #nullable enable diff --git a/src/Merge.Client/Ats/Types/EnabledActionsEnum.cs b/src/Merge.Client/Ats/Types/EnabledActionsEnum.cs index 90d52a85..b906d125 100644 --- a/src/Merge.Client/Ats/Types/EnabledActionsEnum.cs +++ b/src/Merge.Client/Ats/Types/EnabledActionsEnum.cs @@ -1,6 +1,5 @@ using System.Runtime.Serialization; using System.Text.Json.Serialization; -using Merge.Client.Ats; using Merge.Client.Core; #nullable enable diff --git a/src/Merge.Client/Ats/Types/EncodingEnum.cs b/src/Merge.Client/Ats/Types/EncodingEnum.cs index 6cff51c4..c44a0d37 100644 --- a/src/Merge.Client/Ats/Types/EncodingEnum.cs +++ b/src/Merge.Client/Ats/Types/EncodingEnum.cs @@ -1,6 +1,5 @@ using System.Runtime.Serialization; using System.Text.Json.Serialization; -using Merge.Client.Ats; using Merge.Client.Core; #nullable enable diff --git a/src/Merge.Client/Ats/Types/ErrorValidationProblem.cs b/src/Merge.Client/Ats/Types/ErrorValidationProblem.cs index 46a77049..357b8b5b 100644 --- a/src/Merge.Client/Ats/Types/ErrorValidationProblem.cs +++ b/src/Merge.Client/Ats/Types/ErrorValidationProblem.cs @@ -1,21 +1,20 @@ using System.Text.Json.Serialization; -using Merge.Client.Ats; #nullable enable namespace Merge.Client.Ats; -public class ErrorValidationProblem +public record ErrorValidationProblem { [JsonPropertyName("source")] - public ValidationProblemSource? Source { get; init; } + public ValidationProblemSource? Source { get; set; } [JsonPropertyName("title")] - public string Title { get; init; } + public required string Title { get; set; } [JsonPropertyName("detail")] - public string Detail { get; init; } + public required string Detail { get; set; } [JsonPropertyName("problem_type")] - public string ProblemType { get; init; } + public required string ProblemType { get; set; } } diff --git a/src/Merge.Client/Ats/Types/EventTypeEnum.cs b/src/Merge.Client/Ats/Types/EventTypeEnum.cs index b3e73398..4cf6a887 100644 --- a/src/Merge.Client/Ats/Types/EventTypeEnum.cs +++ b/src/Merge.Client/Ats/Types/EventTypeEnum.cs @@ -1,6 +1,5 @@ using System.Runtime.Serialization; using System.Text.Json.Serialization; -using Merge.Client.Ats; using Merge.Client.Core; #nullable enable diff --git a/src/Merge.Client/Ats/Types/ExternalTargetFieldApi.cs b/src/Merge.Client/Ats/Types/ExternalTargetFieldApi.cs index db3ae9fb..de1d27db 100644 --- a/src/Merge.Client/Ats/Types/ExternalTargetFieldApi.cs +++ b/src/Merge.Client/Ats/Types/ExternalTargetFieldApi.cs @@ -4,14 +4,14 @@ namespace Merge.Client.Ats; -public class ExternalTargetFieldApi +public record ExternalTargetFieldApi { [JsonPropertyName("name")] - public string? Name { get; init; } + public string? Name { get; set; } [JsonPropertyName("description")] - public string? Description { get; init; } + public string? Description { get; set; } [JsonPropertyName("is_mapped")] - public string? IsMapped { get; init; } + public string? IsMapped { get; set; } } diff --git a/src/Merge.Client/Ats/Types/ExternalTargetFieldApiResponse.cs b/src/Merge.Client/Ats/Types/ExternalTargetFieldApiResponse.cs index a06ed9f2..82a493b8 100644 --- a/src/Merge.Client/Ats/Types/ExternalTargetFieldApiResponse.cs +++ b/src/Merge.Client/Ats/Types/ExternalTargetFieldApiResponse.cs @@ -1,57 +1,56 @@ using System.Text.Json.Serialization; -using Merge.Client.Ats; #nullable enable namespace Merge.Client.Ats; -public class ExternalTargetFieldApiResponse +public record ExternalTargetFieldApiResponse { [JsonPropertyName("Activity")] - public IEnumerable? Activity { get; init; } + public IEnumerable? Activity { get; set; } [JsonPropertyName("Application")] - public IEnumerable? Application { get; init; } + public IEnumerable? Application { get; set; } [JsonPropertyName("Attachment")] - public IEnumerable? Attachment { get; init; } + public IEnumerable? Attachment { get; set; } [JsonPropertyName("Candidate")] - public IEnumerable? Candidate { get; init; } + public IEnumerable? Candidate { get; set; } [JsonPropertyName("Department")] - public IEnumerable? Department { get; init; } + public IEnumerable? Department { get; set; } [JsonPropertyName("EEOC")] - public IEnumerable? Eeoc { get; init; } + public IEnumerable? Eeoc { get; set; } [JsonPropertyName("ScheduledInterview")] - public IEnumerable? ScheduledInterview { get; init; } + public IEnumerable? ScheduledInterview { get; set; } [JsonPropertyName("Job")] - public IEnumerable? Job { get; init; } + public IEnumerable? Job { get; set; } [JsonPropertyName("JobPosting")] - public IEnumerable? JobPosting { get; init; } + public IEnumerable? JobPosting { get; set; } [JsonPropertyName("JobInterviewStage")] - public IEnumerable? JobInterviewStage { get; init; } + public IEnumerable? JobInterviewStage { get; set; } [JsonPropertyName("Offer")] - public IEnumerable? Offer { get; init; } + public IEnumerable? Offer { get; set; } [JsonPropertyName("Office")] - public IEnumerable? Office { get; init; } + public IEnumerable? Office { get; set; } [JsonPropertyName("RejectReason")] - public IEnumerable? RejectReason { get; init; } + public IEnumerable? RejectReason { get; set; } [JsonPropertyName("Scorecard")] - public IEnumerable? Scorecard { get; init; } + public IEnumerable? Scorecard { get; set; } [JsonPropertyName("Tag")] - public IEnumerable? Tag { get; init; } + public IEnumerable? Tag { get; set; } [JsonPropertyName("RemoteUser")] - public IEnumerable? RemoteUser { get; init; } + public IEnumerable? RemoteUser { get; set; } } diff --git a/src/Merge.Client/Ats/Types/FieldMappingApiInstance.cs b/src/Merge.Client/Ats/Types/FieldMappingApiInstance.cs index 5a5b6114..90116d30 100644 --- a/src/Merge.Client/Ats/Types/FieldMappingApiInstance.cs +++ b/src/Merge.Client/Ats/Types/FieldMappingApiInstance.cs @@ -1,21 +1,20 @@ using System.Text.Json.Serialization; -using Merge.Client.Ats; #nullable enable namespace Merge.Client.Ats; -public class FieldMappingApiInstance +public record FieldMappingApiInstance { [JsonPropertyName("id")] - public string? Id { get; init; } + public string? Id { get; set; } [JsonPropertyName("is_integration_wide")] - public bool? IsIntegrationWide { get; init; } + public bool? IsIntegrationWide { get; set; } [JsonPropertyName("target_field")] - public FieldMappingApiInstanceTargetField? TargetField { get; init; } + public FieldMappingApiInstanceTargetField? TargetField { get; set; } [JsonPropertyName("remote_field")] - public FieldMappingApiInstanceRemoteField? RemoteField { get; init; } + public FieldMappingApiInstanceRemoteField? RemoteField { get; set; } } diff --git a/src/Merge.Client/Ats/Types/FieldMappingApiInstanceRemoteField.cs b/src/Merge.Client/Ats/Types/FieldMappingApiInstanceRemoteField.cs index fc5e971c..575057f3 100644 --- a/src/Merge.Client/Ats/Types/FieldMappingApiInstanceRemoteField.cs +++ b/src/Merge.Client/Ats/Types/FieldMappingApiInstanceRemoteField.cs @@ -1,18 +1,17 @@ using System.Text.Json.Serialization; -using Merge.Client.Ats; #nullable enable namespace Merge.Client.Ats; -public class FieldMappingApiInstanceRemoteField +public record FieldMappingApiInstanceRemoteField { [JsonPropertyName("remote_key_name")] - public string RemoteKeyName { get; init; } + public required string RemoteKeyName { get; set; } [JsonPropertyName("schema")] - public Dictionary Schema { get; init; } + public Dictionary Schema { get; set; } = new Dictionary(); [JsonPropertyName("remote_endpoint_info")] - public FieldMappingApiInstanceRemoteFieldRemoteEndpointInfo RemoteEndpointInfo { get; init; } + public required FieldMappingApiInstanceRemoteFieldRemoteEndpointInfo RemoteEndpointInfo { get; set; } } diff --git a/src/Merge.Client/Ats/Types/FieldMappingApiInstanceRemoteFieldRemoteEndpointInfo.cs b/src/Merge.Client/Ats/Types/FieldMappingApiInstanceRemoteFieldRemoteEndpointInfo.cs index 0468ab2a..113436b8 100644 --- a/src/Merge.Client/Ats/Types/FieldMappingApiInstanceRemoteFieldRemoteEndpointInfo.cs +++ b/src/Merge.Client/Ats/Types/FieldMappingApiInstanceRemoteFieldRemoteEndpointInfo.cs @@ -4,14 +4,14 @@ namespace Merge.Client.Ats; -public class FieldMappingApiInstanceRemoteFieldRemoteEndpointInfo +public record FieldMappingApiInstanceRemoteFieldRemoteEndpointInfo { [JsonPropertyName("method")] - public string? Method { get; init; } + public string? Method { get; set; } [JsonPropertyName("url_path")] - public string? UrlPath { get; init; } + public string? UrlPath { get; set; } [JsonPropertyName("field_traversal_path")] - public IEnumerable? FieldTraversalPath { get; init; } + public IEnumerable? FieldTraversalPath { get; set; } } diff --git a/src/Merge.Client/Ats/Types/FieldMappingApiInstanceResponse.cs b/src/Merge.Client/Ats/Types/FieldMappingApiInstanceResponse.cs index 016c26ce..d4e4f615 100644 --- a/src/Merge.Client/Ats/Types/FieldMappingApiInstanceResponse.cs +++ b/src/Merge.Client/Ats/Types/FieldMappingApiInstanceResponse.cs @@ -1,57 +1,56 @@ using System.Text.Json.Serialization; -using Merge.Client.Ats; #nullable enable namespace Merge.Client.Ats; -public class FieldMappingApiInstanceResponse +public record FieldMappingApiInstanceResponse { [JsonPropertyName("Activity")] - public IEnumerable? Activity { get; init; } + public IEnumerable? Activity { get; set; } [JsonPropertyName("Application")] - public IEnumerable? Application { get; init; } + public IEnumerable? Application { get; set; } [JsonPropertyName("Attachment")] - public IEnumerable? Attachment { get; init; } + public IEnumerable? Attachment { get; set; } [JsonPropertyName("Candidate")] - public IEnumerable? Candidate { get; init; } + public IEnumerable? Candidate { get; set; } [JsonPropertyName("Department")] - public IEnumerable? Department { get; init; } + public IEnumerable? Department { get; set; } [JsonPropertyName("EEOC")] - public IEnumerable? Eeoc { get; init; } + public IEnumerable? Eeoc { get; set; } [JsonPropertyName("ScheduledInterview")] - public IEnumerable? ScheduledInterview { get; init; } + public IEnumerable? ScheduledInterview { get; set; } [JsonPropertyName("Job")] - public IEnumerable? Job { get; init; } + public IEnumerable? Job { get; set; } [JsonPropertyName("JobPosting")] - public IEnumerable? JobPosting { get; init; } + public IEnumerable? JobPosting { get; set; } [JsonPropertyName("JobInterviewStage")] - public IEnumerable? JobInterviewStage { get; init; } + public IEnumerable? JobInterviewStage { get; set; } [JsonPropertyName("Offer")] - public IEnumerable? Offer { get; init; } + public IEnumerable? Offer { get; set; } [JsonPropertyName("Office")] - public IEnumerable? Office { get; init; } + public IEnumerable? Office { get; set; } [JsonPropertyName("RejectReason")] - public IEnumerable? RejectReason { get; init; } + public IEnumerable? RejectReason { get; set; } [JsonPropertyName("Scorecard")] - public IEnumerable? Scorecard { get; init; } + public IEnumerable? Scorecard { get; set; } [JsonPropertyName("Tag")] - public IEnumerable? Tag { get; init; } + public IEnumerable? Tag { get; set; } [JsonPropertyName("RemoteUser")] - public IEnumerable? RemoteUser { get; init; } + public IEnumerable? RemoteUser { get; set; } } diff --git a/src/Merge.Client/Ats/Types/FieldMappingApiInstanceTargetField.cs b/src/Merge.Client/Ats/Types/FieldMappingApiInstanceTargetField.cs index 2249b829..c07ac77e 100644 --- a/src/Merge.Client/Ats/Types/FieldMappingApiInstanceTargetField.cs +++ b/src/Merge.Client/Ats/Types/FieldMappingApiInstanceTargetField.cs @@ -4,14 +4,14 @@ namespace Merge.Client.Ats; -public class FieldMappingApiInstanceTargetField +public record FieldMappingApiInstanceTargetField { [JsonPropertyName("name")] - public string Name { get; init; } + public required string Name { get; set; } [JsonPropertyName("description")] - public string Description { get; init; } + public required string Description { get; set; } [JsonPropertyName("is_organization_wide")] - public bool IsOrganizationWide { get; init; } + public required bool IsOrganizationWide { get; set; } } diff --git a/src/Merge.Client/Ats/Types/FieldMappingInstanceResponse.cs b/src/Merge.Client/Ats/Types/FieldMappingInstanceResponse.cs index 7afd4dd8..2dff1080 100644 --- a/src/Merge.Client/Ats/Types/FieldMappingInstanceResponse.cs +++ b/src/Merge.Client/Ats/Types/FieldMappingInstanceResponse.cs @@ -1,21 +1,22 @@ using System.Text.Json.Serialization; -using Merge.Client.Ats; #nullable enable namespace Merge.Client.Ats; -public class FieldMappingInstanceResponse +public record FieldMappingInstanceResponse { [JsonPropertyName("model")] - public FieldMappingApiInstance Model { get; init; } + public required FieldMappingApiInstance Model { get; set; } [JsonPropertyName("warnings")] - public IEnumerable Warnings { get; init; } + public IEnumerable Warnings { get; set; } = + new List(); [JsonPropertyName("errors")] - public IEnumerable Errors { get; init; } + public IEnumerable Errors { get; set; } = + new List(); [JsonPropertyName("logs")] - public IEnumerable? Logs { get; init; } + public IEnumerable? Logs { get; set; } } diff --git a/src/Merge.Client/Ats/Types/FieldPermissionDeserializer.cs b/src/Merge.Client/Ats/Types/FieldPermissionDeserializer.cs index 744a9cbb..2703f9cb 100644 --- a/src/Merge.Client/Ats/Types/FieldPermissionDeserializer.cs +++ b/src/Merge.Client/Ats/Types/FieldPermissionDeserializer.cs @@ -4,11 +4,11 @@ namespace Merge.Client.Ats; -public class FieldPermissionDeserializer +public record FieldPermissionDeserializer { [JsonPropertyName("enabled")] - public IEnumerable? Enabled { get; init; } + public IEnumerable? Enabled { get; set; } [JsonPropertyName("disabled")] - public IEnumerable? Disabled { get; init; } + public IEnumerable? Disabled { get; set; } } diff --git a/src/Merge.Client/Ats/Types/FieldPermissionDeserializerRequest.cs b/src/Merge.Client/Ats/Types/FieldPermissionDeserializerRequest.cs index c4e3e624..b2120c94 100644 --- a/src/Merge.Client/Ats/Types/FieldPermissionDeserializerRequest.cs +++ b/src/Merge.Client/Ats/Types/FieldPermissionDeserializerRequest.cs @@ -4,11 +4,11 @@ namespace Merge.Client.Ats; -public class FieldPermissionDeserializerRequest +public record FieldPermissionDeserializerRequest { [JsonPropertyName("enabled")] - public IEnumerable? Enabled { get; init; } + public IEnumerable? Enabled { get; set; } [JsonPropertyName("disabled")] - public IEnumerable? Disabled { get; init; } + public IEnumerable? Disabled { get; set; } } diff --git a/src/Merge.Client/Ats/Types/GenderEnum.cs b/src/Merge.Client/Ats/Types/GenderEnum.cs index 0c124794..00cfa777 100644 --- a/src/Merge.Client/Ats/Types/GenderEnum.cs +++ b/src/Merge.Client/Ats/Types/GenderEnum.cs @@ -1,6 +1,5 @@ using System.Runtime.Serialization; using System.Text.Json.Serialization; -using Merge.Client.Ats; using Merge.Client.Core; #nullable enable diff --git a/src/Merge.Client/Ats/Types/IndividualCommonModelScopeDeserializer.cs b/src/Merge.Client/Ats/Types/IndividualCommonModelScopeDeserializer.cs index 7da6ac3b..ec0a378f 100644 --- a/src/Merge.Client/Ats/Types/IndividualCommonModelScopeDeserializer.cs +++ b/src/Merge.Client/Ats/Types/IndividualCommonModelScopeDeserializer.cs @@ -1,18 +1,17 @@ using System.Text.Json.Serialization; -using Merge.Client.Ats; #nullable enable namespace Merge.Client.Ats; -public class IndividualCommonModelScopeDeserializer +public record IndividualCommonModelScopeDeserializer { [JsonPropertyName("model_name")] - public string ModelName { get; init; } + public required string ModelName { get; set; } [JsonPropertyName("model_permissions")] - public Dictionary? ModelPermissions { get; init; } + public Dictionary? ModelPermissions { get; set; } [JsonPropertyName("field_permissions")] - public FieldPermissionDeserializer? FieldPermissions { get; init; } + public FieldPermissionDeserializer? FieldPermissions { get; set; } } diff --git a/src/Merge.Client/Ats/Types/IndividualCommonModelScopeDeserializerRequest.cs b/src/Merge.Client/Ats/Types/IndividualCommonModelScopeDeserializerRequest.cs index 098cea47..257b74cf 100644 --- a/src/Merge.Client/Ats/Types/IndividualCommonModelScopeDeserializerRequest.cs +++ b/src/Merge.Client/Ats/Types/IndividualCommonModelScopeDeserializerRequest.cs @@ -1,18 +1,17 @@ using System.Text.Json.Serialization; -using Merge.Client.Ats; #nullable enable namespace Merge.Client.Ats; -public class IndividualCommonModelScopeDeserializerRequest +public record IndividualCommonModelScopeDeserializerRequest { [JsonPropertyName("model_name")] - public string ModelName { get; init; } + public required string ModelName { get; set; } [JsonPropertyName("model_permissions")] - public Dictionary? ModelPermissions { get; init; } + public Dictionary? ModelPermissions { get; set; } [JsonPropertyName("field_permissions")] - public FieldPermissionDeserializerRequest? FieldPermissions { get; init; } + public FieldPermissionDeserializerRequest? FieldPermissions { get; set; } } diff --git a/src/Merge.Client/Ats/Types/Issue.cs b/src/Merge.Client/Ats/Types/Issue.cs index 8270222f..d25f8e04 100644 --- a/src/Merge.Client/Ats/Types/Issue.cs +++ b/src/Merge.Client/Ats/Types/Issue.cs @@ -1,14 +1,13 @@ using System.Text.Json.Serialization; -using Merge.Client.Ats; #nullable enable namespace Merge.Client.Ats; -public class Issue +public record Issue { [JsonPropertyName("id")] - public string? Id { get; init; } + public string? Id { get; set; } /// /// Status of the issue. Options: ('ONGOING', 'RESOLVED') @@ -17,23 +16,23 @@ public class Issue /// - `RESOLVED` - RESOLVED /// [JsonPropertyName("status")] - public IssueStatusEnum? Status { get; init; } + public IssueStatusEnum? Status { get; set; } [JsonPropertyName("error_description")] - public string ErrorDescription { get; init; } + public required string ErrorDescription { get; set; } [JsonPropertyName("end_user")] - public Dictionary? EndUser { get; init; } + public Dictionary? EndUser { get; set; } [JsonPropertyName("first_incident_time")] - public DateTime? FirstIncidentTime { get; init; } + public DateTime? FirstIncidentTime { get; set; } [JsonPropertyName("last_incident_time")] - public DateTime? LastIncidentTime { get; init; } + public DateTime? LastIncidentTime { get; set; } [JsonPropertyName("is_muted")] - public bool? IsMuted { get; init; } + public bool? IsMuted { get; set; } [JsonPropertyName("error_details")] - public IEnumerable? ErrorDetails { get; init; } + public IEnumerable? ErrorDetails { get; set; } } diff --git a/src/Merge.Client/Ats/Types/IssueStatusEnum.cs b/src/Merge.Client/Ats/Types/IssueStatusEnum.cs index a79a251e..645d492e 100644 --- a/src/Merge.Client/Ats/Types/IssueStatusEnum.cs +++ b/src/Merge.Client/Ats/Types/IssueStatusEnum.cs @@ -1,6 +1,5 @@ using System.Runtime.Serialization; using System.Text.Json.Serialization; -using Merge.Client.Ats; using Merge.Client.Core; #nullable enable diff --git a/src/Merge.Client/Ats/Types/Job.cs b/src/Merge.Client/Ats/Types/Job.cs index 036a368e..8deb3933 100644 --- a/src/Merge.Client/Ats/Types/Job.cs +++ b/src/Merge.Client/Ats/Types/Job.cs @@ -1,5 +1,4 @@ using System.Text.Json.Serialization; -using Merge.Client.Ats; using Merge.Client.Core; using OneOf; @@ -7,46 +6,46 @@ namespace Merge.Client.Ats; -public class Job +public record Job { [JsonPropertyName("id")] - public string? Id { get; init; } + public string? Id { get; set; } /// /// The third-party API ID of the matching object. /// [JsonPropertyName("remote_id")] - public string? RemoteId { get; init; } + public string? RemoteId { get; set; } /// /// The datetime that this object was created by Merge. /// [JsonPropertyName("created_at")] - public DateTime? CreatedAt { get; init; } + public DateTime? CreatedAt { get; set; } /// /// The datetime that this object was modified by Merge. /// [JsonPropertyName("modified_at")] - public DateTime? ModifiedAt { get; init; } + public DateTime? ModifiedAt { get; set; } /// /// The job's name. /// [JsonPropertyName("name")] - public string? Name { get; init; } + public string? Name { get; set; } /// /// The job's description. /// [JsonPropertyName("description")] - public string? Description { get; init; } + public string? Description { get; set; } /// /// The job's code. Typically an additional identifier used to reference the particular job that is displayed on the ATS. /// [JsonPropertyName("code")] - public string? Code { get; init; } + public string? Code { get; set; } /// /// The job's status. @@ -58,7 +57,7 @@ public class Job /// - `PENDING` - PENDING /// [JsonPropertyName("status")] - public JobStatusEnum? Status { get; init; } + public JobStatusEnum? Status { get; set; } /// /// The job's type. @@ -68,34 +67,34 @@ public class Job /// - `PROFILE` - PROFILE /// [JsonPropertyName("type")] - public JobTypeEnum? Type { get; init; } + public JobTypeEnum? Type { get; set; } /// /// IDs of `JobPosting` objects that serve as job postings for this `Job`. /// [JsonPropertyName("job_postings")] - public IEnumerable? JobPostings { get; init; } + public IEnumerable? JobPostings { get; set; } [JsonPropertyName("job_posting_urls")] - public IEnumerable? JobPostingUrls { get; init; } + public IEnumerable? JobPostingUrls { get; set; } /// /// When the third party's job was created. /// [JsonPropertyName("remote_created_at")] - public DateTime? RemoteCreatedAt { get; init; } + public DateTime? RemoteCreatedAt { get; set; } /// /// When the third party's job was updated. /// [JsonPropertyName("remote_updated_at")] - public DateTime? RemoteUpdatedAt { get; init; } + public DateTime? RemoteUpdatedAt { get; set; } /// /// Whether the job is confidential. /// [JsonPropertyName("confidential")] - public bool? Confidential { get; init; } + public bool? Confidential { get; set; } /// /// IDs of `Department` objects for this `Job`. @@ -107,7 +106,7 @@ public class Job OneOfSerializer> >) )] - public IEnumerable>? Departments { get; init; } + public IEnumerable>? Departments { get; set; } /// /// IDs of `Office` objects for this `Job`. @@ -119,7 +118,7 @@ public class Job OneOfSerializer> >) )] - public IEnumerable>? Offices { get; init; } + public IEnumerable>? Offices { get; set; } /// /// IDs of `RemoteUser` objects that serve as hiring managers for this `Job`. @@ -131,7 +130,7 @@ public class Job OneOfSerializer> >) )] - public IEnumerable>? HiringManagers { get; init; } + public IEnumerable>? HiringManagers { get; set; } /// /// IDs of `RemoteUser` objects that serve as recruiters for this `Job`. @@ -143,17 +142,17 @@ public class Job OneOfSerializer> >) )] - public IEnumerable>? Recruiters { get; init; } + public IEnumerable>? Recruiters { get; set; } /// /// Indicates whether or not this object has been deleted in the third party platform. /// [JsonPropertyName("remote_was_deleted")] - public bool? RemoteWasDeleted { get; init; } + public bool? RemoteWasDeleted { get; set; } [JsonPropertyName("field_mappings")] - public Dictionary? FieldMappings { get; init; } + public Dictionary? FieldMappings { get; set; } [JsonPropertyName("remote_data")] - public IEnumerable? RemoteData { get; init; } + public IEnumerable? RemoteData { get; set; } } diff --git a/src/Merge.Client/Ats/Types/JobInterviewStage.cs b/src/Merge.Client/Ats/Types/JobInterviewStage.cs index 1c9474b7..5f88448d 100644 --- a/src/Merge.Client/Ats/Types/JobInterviewStage.cs +++ b/src/Merge.Client/Ats/Types/JobInterviewStage.cs @@ -1,5 +1,4 @@ using System.Text.Json.Serialization; -using Merge.Client.Ats; using Merge.Client.Core; using OneOf; @@ -7,57 +6,57 @@ namespace Merge.Client.Ats; -public class JobInterviewStage +public record JobInterviewStage { [JsonPropertyName("id")] - public string? Id { get; init; } + public string? Id { get; set; } /// /// The third-party API ID of the matching object. /// [JsonPropertyName("remote_id")] - public string? RemoteId { get; init; } + public string? RemoteId { get; set; } /// /// The datetime that this object was created by Merge. /// [JsonPropertyName("created_at")] - public DateTime? CreatedAt { get; init; } + public DateTime? CreatedAt { get; set; } /// /// The datetime that this object was modified by Merge. /// [JsonPropertyName("modified_at")] - public DateTime? ModifiedAt { get; init; } + public DateTime? ModifiedAt { get; set; } /// /// Standard stage names are offered by ATS systems but can be modified by users. /// [JsonPropertyName("name")] - public string? Name { get; init; } + public string? Name { get; set; } /// /// This field is populated only if the stage is specific to a particular job. If the stage is generic, this field will not be populated. /// [JsonPropertyName("job")] [JsonConverter(typeof(OneOfSerializer>))] - public OneOf? Job { get; init; } + public OneOf? Job { get; set; } /// /// The stage’s order, with the lowest values ordered first. If the third-party does not return details on the order of stages, this field will not be populated. /// [JsonPropertyName("stage_order")] - public int? StageOrder { get; init; } + public int? StageOrder { get; set; } /// /// Indicates whether or not this object has been deleted in the third party platform. /// [JsonPropertyName("remote_was_deleted")] - public bool? RemoteWasDeleted { get; init; } + public bool? RemoteWasDeleted { get; set; } [JsonPropertyName("field_mappings")] - public Dictionary? FieldMappings { get; init; } + public Dictionary? FieldMappings { get; set; } [JsonPropertyName("remote_data")] - public IEnumerable? RemoteData { get; init; } + public IEnumerable? RemoteData { get; set; } } diff --git a/src/Merge.Client/Ats/Types/JobPosting.cs b/src/Merge.Client/Ats/Types/JobPosting.cs index d5f50e07..08b86acb 100644 --- a/src/Merge.Client/Ats/Types/JobPosting.cs +++ b/src/Merge.Client/Ats/Types/JobPosting.cs @@ -1,5 +1,4 @@ using System.Text.Json.Serialization; -using Merge.Client.Ats; using Merge.Client.Core; using OneOf; @@ -7,34 +6,34 @@ namespace Merge.Client.Ats; -public class JobPosting +public record JobPosting { [JsonPropertyName("id")] - public string? Id { get; init; } + public string? Id { get; set; } /// /// The third-party API ID of the matching object. /// [JsonPropertyName("remote_id")] - public string? RemoteId { get; init; } + public string? RemoteId { get; set; } /// /// The datetime that this object was created by Merge. /// [JsonPropertyName("created_at")] - public DateTime? CreatedAt { get; init; } + public DateTime? CreatedAt { get; set; } /// /// The datetime that this object was modified by Merge. /// [JsonPropertyName("modified_at")] - public DateTime? ModifiedAt { get; init; } + public DateTime? ModifiedAt { get; set; } /// /// The job posting’s title. /// [JsonPropertyName("title")] - public string? Title { get; init; } + public string? Title { get; set; } /// /// The Url object is used to represent hyperlinks for a candidate to apply to a given job. @@ -43,14 +42,14 @@ public class JobPosting [JsonConverter( typeof(CollectionItemSerializer, OneOfSerializer>>) )] - public IEnumerable>? JobPostingUrls { get; init; } + public IEnumerable>? JobPostingUrls { get; set; } /// /// ID of `Job` object for this `JobPosting`. /// [JsonPropertyName("job")] [JsonConverter(typeof(OneOfSerializer>))] - public OneOf? Job { get; init; } + public OneOf? Job { get; set; } /// /// The job posting's status. @@ -62,41 +61,41 @@ public class JobPosting /// - `PENDING` - PENDING /// [JsonPropertyName("status")] - public JobPostingStatusEnum? Status { get; init; } + public JobPostingStatusEnum? Status { get; set; } /// /// The job posting’s content. /// [JsonPropertyName("content")] - public string? Content { get; init; } + public string? Content { get; set; } /// /// When the third party's job posting was created. /// [JsonPropertyName("remote_created_at")] - public DateTime? RemoteCreatedAt { get; init; } + public DateTime? RemoteCreatedAt { get; set; } /// /// When the third party's job posting was updated. /// [JsonPropertyName("remote_updated_at")] - public DateTime? RemoteUpdatedAt { get; init; } + public DateTime? RemoteUpdatedAt { get; set; } /// /// Indicates whether the job posting is internal or external. /// [JsonPropertyName("is_internal")] - public bool? IsInternal { get; init; } + public bool? IsInternal { get; set; } /// /// Indicates whether or not this object has been deleted in the third party platform. /// [JsonPropertyName("remote_was_deleted")] - public bool? RemoteWasDeleted { get; init; } + public bool? RemoteWasDeleted { get; set; } [JsonPropertyName("field_mappings")] - public Dictionary? FieldMappings { get; init; } + public Dictionary? FieldMappings { get; set; } [JsonPropertyName("remote_data")] - public IEnumerable? RemoteData { get; init; } + public IEnumerable? RemoteData { get; set; } } diff --git a/src/Merge.Client/Ats/Types/JobPostingStatusEnum.cs b/src/Merge.Client/Ats/Types/JobPostingStatusEnum.cs index 2827545c..694fca2d 100644 --- a/src/Merge.Client/Ats/Types/JobPostingStatusEnum.cs +++ b/src/Merge.Client/Ats/Types/JobPostingStatusEnum.cs @@ -1,6 +1,5 @@ using System.Runtime.Serialization; using System.Text.Json.Serialization; -using Merge.Client.Ats; using Merge.Client.Core; #nullable enable diff --git a/src/Merge.Client/Ats/Types/JobStatusEnum.cs b/src/Merge.Client/Ats/Types/JobStatusEnum.cs index cf7bd2ac..c679e43c 100644 --- a/src/Merge.Client/Ats/Types/JobStatusEnum.cs +++ b/src/Merge.Client/Ats/Types/JobStatusEnum.cs @@ -1,6 +1,5 @@ using System.Runtime.Serialization; using System.Text.Json.Serialization; -using Merge.Client.Ats; using Merge.Client.Core; #nullable enable diff --git a/src/Merge.Client/Ats/Types/JobTypeEnum.cs b/src/Merge.Client/Ats/Types/JobTypeEnum.cs index 5e7853ae..073422dd 100644 --- a/src/Merge.Client/Ats/Types/JobTypeEnum.cs +++ b/src/Merge.Client/Ats/Types/JobTypeEnum.cs @@ -1,6 +1,5 @@ using System.Runtime.Serialization; using System.Text.Json.Serialization; -using Merge.Client.Ats; using Merge.Client.Core; #nullable enable diff --git a/src/Merge.Client/Ats/Types/LinkToken.cs b/src/Merge.Client/Ats/Types/LinkToken.cs index c4b1e019..8ef6c71c 100644 --- a/src/Merge.Client/Ats/Types/LinkToken.cs +++ b/src/Merge.Client/Ats/Types/LinkToken.cs @@ -4,14 +4,14 @@ namespace Merge.Client.Ats; -public class LinkToken +public record LinkToken { [JsonPropertyName("link_token")] - public string LinkToken_ { get; init; } + public required string LinkToken_ { get; set; } [JsonPropertyName("integration_name")] - public string? IntegrationName { get; init; } + public string? IntegrationName { get; set; } [JsonPropertyName("magic_link_url")] - public string? MagicLinkUrl { get; init; } + public string? MagicLinkUrl { get; set; } } diff --git a/src/Merge.Client/Ats/Types/LinkedAccountStatus.cs b/src/Merge.Client/Ats/Types/LinkedAccountStatus.cs index 39de0729..8c173f5d 100644 --- a/src/Merge.Client/Ats/Types/LinkedAccountStatus.cs +++ b/src/Merge.Client/Ats/Types/LinkedAccountStatus.cs @@ -4,11 +4,11 @@ namespace Merge.Client.Ats; -public class LinkedAccountStatus +public record LinkedAccountStatus { [JsonPropertyName("linked_account_status")] - public string LinkedAccountStatus_ { get; init; } + public required string LinkedAccountStatus_ { get; set; } [JsonPropertyName("can_make_request")] - public bool CanMakeRequest { get; init; } + public required bool CanMakeRequest { get; set; } } diff --git a/src/Merge.Client/Ats/Types/MetaResponse.cs b/src/Merge.Client/Ats/Types/MetaResponse.cs index e68543c6..61f5c725 100644 --- a/src/Merge.Client/Ats/Types/MetaResponse.cs +++ b/src/Merge.Client/Ats/Types/MetaResponse.cs @@ -1,24 +1,24 @@ using System.Text.Json.Serialization; -using Merge.Client.Ats; #nullable enable namespace Merge.Client.Ats; -public class MetaResponse +public record MetaResponse { [JsonPropertyName("request_schema")] - public Dictionary RequestSchema { get; init; } + public Dictionary RequestSchema { get; set; } = + new Dictionary(); [JsonPropertyName("remote_field_classes")] - public Dictionary? RemoteFieldClasses { get; init; } + public Dictionary? RemoteFieldClasses { get; set; } [JsonPropertyName("status")] - public LinkedAccountStatus? Status { get; init; } + public LinkedAccountStatus? Status { get; set; } [JsonPropertyName("has_conditional_params")] - public bool HasConditionalParams { get; init; } + public required bool HasConditionalParams { get; set; } [JsonPropertyName("has_required_linked_account_params")] - public bool HasRequiredLinkedAccountParams { get; init; } + public required bool HasRequiredLinkedAccountParams { get; set; } } diff --git a/src/Merge.Client/Ats/Types/MethodEnum.cs b/src/Merge.Client/Ats/Types/MethodEnum.cs index be21f00a..93ee44b9 100644 --- a/src/Merge.Client/Ats/Types/MethodEnum.cs +++ b/src/Merge.Client/Ats/Types/MethodEnum.cs @@ -1,6 +1,5 @@ using System.Runtime.Serialization; using System.Text.Json.Serialization; -using Merge.Client.Ats; using Merge.Client.Core; #nullable enable diff --git a/src/Merge.Client/Ats/Types/ModelOperation.cs b/src/Merge.Client/Ats/Types/ModelOperation.cs index 231a3745..97d9501b 100644 --- a/src/Merge.Client/Ats/Types/ModelOperation.cs +++ b/src/Merge.Client/Ats/Types/ModelOperation.cs @@ -4,17 +4,17 @@ namespace Merge.Client.Ats; -public class ModelOperation +public record ModelOperation { [JsonPropertyName("model_name")] - public string ModelName { get; init; } + public required string ModelName { get; set; } [JsonPropertyName("available_operations")] - public IEnumerable AvailableOperations { get; init; } + public IEnumerable AvailableOperations { get; set; } = new List(); [JsonPropertyName("required_post_parameters")] - public IEnumerable RequiredPostParameters { get; init; } + public IEnumerable RequiredPostParameters { get; set; } = new List(); [JsonPropertyName("supported_fields")] - public IEnumerable SupportedFields { get; init; } + public IEnumerable SupportedFields { get; set; } = new List(); } diff --git a/src/Merge.Client/Ats/Types/ModelPermissionDeserializer.cs b/src/Merge.Client/Ats/Types/ModelPermissionDeserializer.cs index 1f77a80c..08e17d1f 100644 --- a/src/Merge.Client/Ats/Types/ModelPermissionDeserializer.cs +++ b/src/Merge.Client/Ats/Types/ModelPermissionDeserializer.cs @@ -4,8 +4,8 @@ namespace Merge.Client.Ats; -public class ModelPermissionDeserializer +public record ModelPermissionDeserializer { [JsonPropertyName("is_enabled")] - public bool? IsEnabled { get; init; } + public bool? IsEnabled { get; set; } } diff --git a/src/Merge.Client/Ats/Types/ModelPermissionDeserializerRequest.cs b/src/Merge.Client/Ats/Types/ModelPermissionDeserializerRequest.cs index ed0046ac..04d71627 100644 --- a/src/Merge.Client/Ats/Types/ModelPermissionDeserializerRequest.cs +++ b/src/Merge.Client/Ats/Types/ModelPermissionDeserializerRequest.cs @@ -4,8 +4,8 @@ namespace Merge.Client.Ats; -public class ModelPermissionDeserializerRequest +public record ModelPermissionDeserializerRequest { [JsonPropertyName("is_enabled")] - public bool? IsEnabled { get; init; } + public bool? IsEnabled { get; set; } } diff --git a/src/Merge.Client/Ats/Types/MultipartFormFieldRequest.cs b/src/Merge.Client/Ats/Types/MultipartFormFieldRequest.cs index f36e750f..333fa08c 100644 --- a/src/Merge.Client/Ats/Types/MultipartFormFieldRequest.cs +++ b/src/Merge.Client/Ats/Types/MultipartFormFieldRequest.cs @@ -1,23 +1,22 @@ using System.Text.Json.Serialization; -using Merge.Client.Ats; #nullable enable namespace Merge.Client.Ats; -public class MultipartFormFieldRequest +public record MultipartFormFieldRequest { /// /// The name of the form field /// [JsonPropertyName("name")] - public string Name { get; init; } + public required string Name { get; set; } /// /// The data for the form field. /// [JsonPropertyName("data")] - public string Data { get; init; } + public required string Data { get; set; } /// /// The encoding of the value of `data`. Defaults to `RAW` if not defined. @@ -27,17 +26,17 @@ public class MultipartFormFieldRequest /// - `GZIP_BASE64` - GZIP_BASE64 /// [JsonPropertyName("encoding")] - public EncodingEnum? Encoding { get; init; } + public EncodingEnum? Encoding { get; set; } /// /// The file name of the form field, if the field is for a file. /// [JsonPropertyName("file_name")] - public string? FileName { get; init; } + public string? FileName { get; set; } /// /// The MIME type of the file, if the field is for a file. /// [JsonPropertyName("content_type")] - public string? ContentType { get; init; } + public string? ContentType { get; set; } } diff --git a/src/Merge.Client/Ats/Types/Offer.cs b/src/Merge.Client/Ats/Types/Offer.cs index 9fb18dc2..de67affc 100644 --- a/src/Merge.Client/Ats/Types/Offer.cs +++ b/src/Merge.Client/Ats/Types/Offer.cs @@ -1,5 +1,4 @@ using System.Text.Json.Serialization; -using Merge.Client.Ats; using Merge.Client.Core; using OneOf; @@ -7,66 +6,66 @@ namespace Merge.Client.Ats; -public class Offer +public record Offer { [JsonPropertyName("id")] - public string? Id { get; init; } + public string? Id { get; set; } /// /// The third-party API ID of the matching object. /// [JsonPropertyName("remote_id")] - public string? RemoteId { get; init; } + public string? RemoteId { get; set; } /// /// The datetime that this object was created by Merge. /// [JsonPropertyName("created_at")] - public DateTime? CreatedAt { get; init; } + public DateTime? CreatedAt { get; set; } /// /// The datetime that this object was modified by Merge. /// [JsonPropertyName("modified_at")] - public DateTime? ModifiedAt { get; init; } + public DateTime? ModifiedAt { get; set; } /// /// The application who is receiving the offer. /// [JsonPropertyName("application")] [JsonConverter(typeof(OneOfSerializer>))] - public OneOf? Application { get; init; } + public OneOf? Application { get; set; } /// /// The user who created the offer. /// [JsonPropertyName("creator")] [JsonConverter(typeof(OneOfSerializer>))] - public OneOf? Creator { get; init; } + public OneOf? Creator { get; set; } /// /// When the third party's offer was created. /// [JsonPropertyName("remote_created_at")] - public DateTime? RemoteCreatedAt { get; init; } + public DateTime? RemoteCreatedAt { get; set; } /// /// When the offer was closed. /// [JsonPropertyName("closed_at")] - public DateTime? ClosedAt { get; init; } + public DateTime? ClosedAt { get; set; } /// /// When the offer was sent. /// [JsonPropertyName("sent_at")] - public DateTime? SentAt { get; init; } + public DateTime? SentAt { get; set; } /// /// The employment start date on the offer. /// [JsonPropertyName("start_date")] - public DateTime? StartDate { get; init; } + public DateTime? StartDate { get; set; } /// /// The offer's status. @@ -82,17 +81,17 @@ public class Offer /// - `DEPRECATED` - DEPRECATED /// [JsonPropertyName("status")] - public OfferStatusEnum? Status { get; init; } + public OfferStatusEnum? Status { get; set; } /// /// Indicates whether or not this object has been deleted in the third party platform. /// [JsonPropertyName("remote_was_deleted")] - public bool? RemoteWasDeleted { get; init; } + public bool? RemoteWasDeleted { get; set; } [JsonPropertyName("field_mappings")] - public Dictionary? FieldMappings { get; init; } + public Dictionary? FieldMappings { get; set; } [JsonPropertyName("remote_data")] - public IEnumerable? RemoteData { get; init; } + public IEnumerable? RemoteData { get; set; } } diff --git a/src/Merge.Client/Ats/Types/OfferStatusEnum.cs b/src/Merge.Client/Ats/Types/OfferStatusEnum.cs index 4fd04334..68cf5432 100644 --- a/src/Merge.Client/Ats/Types/OfferStatusEnum.cs +++ b/src/Merge.Client/Ats/Types/OfferStatusEnum.cs @@ -1,6 +1,5 @@ using System.Runtime.Serialization; using System.Text.Json.Serialization; -using Merge.Client.Ats; using Merge.Client.Core; #nullable enable diff --git a/src/Merge.Client/Ats/Types/Office.cs b/src/Merge.Client/Ats/Types/Office.cs index fb749ec5..edb984ca 100644 --- a/src/Merge.Client/Ats/Types/Office.cs +++ b/src/Merge.Client/Ats/Types/Office.cs @@ -1,54 +1,53 @@ using System.Text.Json.Serialization; -using Merge.Client.Ats; #nullable enable namespace Merge.Client.Ats; -public class Office +public record Office { [JsonPropertyName("id")] - public string? Id { get; init; } + public string? Id { get; set; } /// /// The third-party API ID of the matching object. /// [JsonPropertyName("remote_id")] - public string? RemoteId { get; init; } + public string? RemoteId { get; set; } /// /// The datetime that this object was created by Merge. /// [JsonPropertyName("created_at")] - public DateTime? CreatedAt { get; init; } + public DateTime? CreatedAt { get; set; } /// /// The datetime that this object was modified by Merge. /// [JsonPropertyName("modified_at")] - public DateTime? ModifiedAt { get; init; } + public DateTime? ModifiedAt { get; set; } /// /// The office's name. /// [JsonPropertyName("name")] - public string? Name { get; init; } + public string? Name { get; set; } /// /// The office's location. /// [JsonPropertyName("location")] - public string? Location { get; init; } + public string? Location { get; set; } /// /// Indicates whether or not this object has been deleted in the third party platform. /// [JsonPropertyName("remote_was_deleted")] - public bool? RemoteWasDeleted { get; init; } + public bool? RemoteWasDeleted { get; set; } [JsonPropertyName("field_mappings")] - public Dictionary? FieldMappings { get; init; } + public Dictionary? FieldMappings { get; set; } [JsonPropertyName("remote_data")] - public IEnumerable? RemoteData { get; init; } + public IEnumerable? RemoteData { get; set; } } diff --git a/src/Merge.Client/Ats/Types/OverallRecommendationEnum.cs b/src/Merge.Client/Ats/Types/OverallRecommendationEnum.cs index 6d9697ae..803f3e97 100644 --- a/src/Merge.Client/Ats/Types/OverallRecommendationEnum.cs +++ b/src/Merge.Client/Ats/Types/OverallRecommendationEnum.cs @@ -1,6 +1,5 @@ using System.Runtime.Serialization; using System.Text.Json.Serialization; -using Merge.Client.Ats; using Merge.Client.Core; #nullable enable diff --git a/src/Merge.Client/Ats/Types/PaginatedAccountDetailsAndActionsList.cs b/src/Merge.Client/Ats/Types/PaginatedAccountDetailsAndActionsList.cs index 6fd2526b..29cdf24a 100644 --- a/src/Merge.Client/Ats/Types/PaginatedAccountDetailsAndActionsList.cs +++ b/src/Merge.Client/Ats/Types/PaginatedAccountDetailsAndActionsList.cs @@ -1,18 +1,17 @@ using System.Text.Json.Serialization; -using Merge.Client.Ats; #nullable enable namespace Merge.Client.Ats; -public class PaginatedAccountDetailsAndActionsList +public record PaginatedAccountDetailsAndActionsList { [JsonPropertyName("next")] - public string? Next { get; init; } + public string? Next { get; set; } [JsonPropertyName("previous")] - public string? Previous { get; init; } + public string? Previous { get; set; } [JsonPropertyName("results")] - public IEnumerable? Results { get; init; } + public IEnumerable? Results { get; set; } } diff --git a/src/Merge.Client/Ats/Types/PaginatedActivityList.cs b/src/Merge.Client/Ats/Types/PaginatedActivityList.cs index 3568b883..4b5bea93 100644 --- a/src/Merge.Client/Ats/Types/PaginatedActivityList.cs +++ b/src/Merge.Client/Ats/Types/PaginatedActivityList.cs @@ -1,18 +1,17 @@ using System.Text.Json.Serialization; -using Merge.Client.Ats; #nullable enable namespace Merge.Client.Ats; -public class PaginatedActivityList +public record PaginatedActivityList { [JsonPropertyName("next")] - public string? Next { get; init; } + public string? Next { get; set; } [JsonPropertyName("previous")] - public string? Previous { get; init; } + public string? Previous { get; set; } [JsonPropertyName("results")] - public IEnumerable? Results { get; init; } + public IEnumerable? Results { get; set; } } diff --git a/src/Merge.Client/Ats/Types/PaginatedApplicationList.cs b/src/Merge.Client/Ats/Types/PaginatedApplicationList.cs index 952a634f..60c1af63 100644 --- a/src/Merge.Client/Ats/Types/PaginatedApplicationList.cs +++ b/src/Merge.Client/Ats/Types/PaginatedApplicationList.cs @@ -1,18 +1,17 @@ using System.Text.Json.Serialization; -using Merge.Client.Ats; #nullable enable namespace Merge.Client.Ats; -public class PaginatedApplicationList +public record PaginatedApplicationList { [JsonPropertyName("next")] - public string? Next { get; init; } + public string? Next { get; set; } [JsonPropertyName("previous")] - public string? Previous { get; init; } + public string? Previous { get; set; } [JsonPropertyName("results")] - public IEnumerable? Results { get; init; } + public IEnumerable? Results { get; set; } } diff --git a/src/Merge.Client/Ats/Types/PaginatedAttachmentList.cs b/src/Merge.Client/Ats/Types/PaginatedAttachmentList.cs index 3fef18ae..c596df9c 100644 --- a/src/Merge.Client/Ats/Types/PaginatedAttachmentList.cs +++ b/src/Merge.Client/Ats/Types/PaginatedAttachmentList.cs @@ -1,18 +1,17 @@ using System.Text.Json.Serialization; -using Merge.Client.Ats; #nullable enable namespace Merge.Client.Ats; -public class PaginatedAttachmentList +public record PaginatedAttachmentList { [JsonPropertyName("next")] - public string? Next { get; init; } + public string? Next { get; set; } [JsonPropertyName("previous")] - public string? Previous { get; init; } + public string? Previous { get; set; } [JsonPropertyName("results")] - public IEnumerable? Results { get; init; } + public IEnumerable? Results { get; set; } } diff --git a/src/Merge.Client/Ats/Types/PaginatedAuditLogEventList.cs b/src/Merge.Client/Ats/Types/PaginatedAuditLogEventList.cs index a2b69e0b..94014992 100644 --- a/src/Merge.Client/Ats/Types/PaginatedAuditLogEventList.cs +++ b/src/Merge.Client/Ats/Types/PaginatedAuditLogEventList.cs @@ -1,18 +1,17 @@ using System.Text.Json.Serialization; -using Merge.Client.Ats; #nullable enable namespace Merge.Client.Ats; -public class PaginatedAuditLogEventList +public record PaginatedAuditLogEventList { [JsonPropertyName("next")] - public string? Next { get; init; } + public string? Next { get; set; } [JsonPropertyName("previous")] - public string? Previous { get; init; } + public string? Previous { get; set; } [JsonPropertyName("results")] - public IEnumerable? Results { get; init; } + public IEnumerable? Results { get; set; } } diff --git a/src/Merge.Client/Ats/Types/PaginatedCandidateList.cs b/src/Merge.Client/Ats/Types/PaginatedCandidateList.cs index 80017fc8..3c8c3b71 100644 --- a/src/Merge.Client/Ats/Types/PaginatedCandidateList.cs +++ b/src/Merge.Client/Ats/Types/PaginatedCandidateList.cs @@ -1,18 +1,17 @@ using System.Text.Json.Serialization; -using Merge.Client.Ats; #nullable enable namespace Merge.Client.Ats; -public class PaginatedCandidateList +public record PaginatedCandidateList { [JsonPropertyName("next")] - public string? Next { get; init; } + public string? Next { get; set; } [JsonPropertyName("previous")] - public string? Previous { get; init; } + public string? Previous { get; set; } [JsonPropertyName("results")] - public IEnumerable? Results { get; init; } + public IEnumerable? Results { get; set; } } diff --git a/src/Merge.Client/Ats/Types/PaginatedDepartmentList.cs b/src/Merge.Client/Ats/Types/PaginatedDepartmentList.cs index 031e574c..9503fe80 100644 --- a/src/Merge.Client/Ats/Types/PaginatedDepartmentList.cs +++ b/src/Merge.Client/Ats/Types/PaginatedDepartmentList.cs @@ -1,18 +1,17 @@ using System.Text.Json.Serialization; -using Merge.Client.Ats; #nullable enable namespace Merge.Client.Ats; -public class PaginatedDepartmentList +public record PaginatedDepartmentList { [JsonPropertyName("next")] - public string? Next { get; init; } + public string? Next { get; set; } [JsonPropertyName("previous")] - public string? Previous { get; init; } + public string? Previous { get; set; } [JsonPropertyName("results")] - public IEnumerable? Results { get; init; } + public IEnumerable? Results { get; set; } } diff --git a/src/Merge.Client/Ats/Types/PaginatedEeocList.cs b/src/Merge.Client/Ats/Types/PaginatedEeocList.cs index 23c498b9..abdaf522 100644 --- a/src/Merge.Client/Ats/Types/PaginatedEeocList.cs +++ b/src/Merge.Client/Ats/Types/PaginatedEeocList.cs @@ -1,18 +1,17 @@ using System.Text.Json.Serialization; -using Merge.Client.Ats; #nullable enable namespace Merge.Client.Ats; -public class PaginatedEeocList +public record PaginatedEeocList { [JsonPropertyName("next")] - public string? Next { get; init; } + public string? Next { get; set; } [JsonPropertyName("previous")] - public string? Previous { get; init; } + public string? Previous { get; set; } [JsonPropertyName("results")] - public IEnumerable? Results { get; init; } + public IEnumerable? Results { get; set; } } diff --git a/src/Merge.Client/Ats/Types/PaginatedIssueList.cs b/src/Merge.Client/Ats/Types/PaginatedIssueList.cs index 7ad6a294..4bee5895 100644 --- a/src/Merge.Client/Ats/Types/PaginatedIssueList.cs +++ b/src/Merge.Client/Ats/Types/PaginatedIssueList.cs @@ -1,18 +1,17 @@ using System.Text.Json.Serialization; -using Merge.Client.Ats; #nullable enable namespace Merge.Client.Ats; -public class PaginatedIssueList +public record PaginatedIssueList { [JsonPropertyName("next")] - public string? Next { get; init; } + public string? Next { get; set; } [JsonPropertyName("previous")] - public string? Previous { get; init; } + public string? Previous { get; set; } [JsonPropertyName("results")] - public IEnumerable? Results { get; init; } + public IEnumerable? Results { get; set; } } diff --git a/src/Merge.Client/Ats/Types/PaginatedJobInterviewStageList.cs b/src/Merge.Client/Ats/Types/PaginatedJobInterviewStageList.cs index 782a240f..1107d3af 100644 --- a/src/Merge.Client/Ats/Types/PaginatedJobInterviewStageList.cs +++ b/src/Merge.Client/Ats/Types/PaginatedJobInterviewStageList.cs @@ -1,18 +1,17 @@ using System.Text.Json.Serialization; -using Merge.Client.Ats; #nullable enable namespace Merge.Client.Ats; -public class PaginatedJobInterviewStageList +public record PaginatedJobInterviewStageList { [JsonPropertyName("next")] - public string? Next { get; init; } + public string? Next { get; set; } [JsonPropertyName("previous")] - public string? Previous { get; init; } + public string? Previous { get; set; } [JsonPropertyName("results")] - public IEnumerable? Results { get; init; } + public IEnumerable? Results { get; set; } } diff --git a/src/Merge.Client/Ats/Types/PaginatedJobList.cs b/src/Merge.Client/Ats/Types/PaginatedJobList.cs index f502954c..97fc192a 100644 --- a/src/Merge.Client/Ats/Types/PaginatedJobList.cs +++ b/src/Merge.Client/Ats/Types/PaginatedJobList.cs @@ -1,18 +1,17 @@ using System.Text.Json.Serialization; -using Merge.Client.Ats; #nullable enable namespace Merge.Client.Ats; -public class PaginatedJobList +public record PaginatedJobList { [JsonPropertyName("next")] - public string? Next { get; init; } + public string? Next { get; set; } [JsonPropertyName("previous")] - public string? Previous { get; init; } + public string? Previous { get; set; } [JsonPropertyName("results")] - public IEnumerable? Results { get; init; } + public IEnumerable? Results { get; set; } } diff --git a/src/Merge.Client/Ats/Types/PaginatedJobPostingList.cs b/src/Merge.Client/Ats/Types/PaginatedJobPostingList.cs index efa12a6d..f80724ae 100644 --- a/src/Merge.Client/Ats/Types/PaginatedJobPostingList.cs +++ b/src/Merge.Client/Ats/Types/PaginatedJobPostingList.cs @@ -1,18 +1,17 @@ using System.Text.Json.Serialization; -using Merge.Client.Ats; #nullable enable namespace Merge.Client.Ats; -public class PaginatedJobPostingList +public record PaginatedJobPostingList { [JsonPropertyName("next")] - public string? Next { get; init; } + public string? Next { get; set; } [JsonPropertyName("previous")] - public string? Previous { get; init; } + public string? Previous { get; set; } [JsonPropertyName("results")] - public IEnumerable? Results { get; init; } + public IEnumerable? Results { get; set; } } diff --git a/src/Merge.Client/Ats/Types/PaginatedOfferList.cs b/src/Merge.Client/Ats/Types/PaginatedOfferList.cs index 7b6de5b0..123cd790 100644 --- a/src/Merge.Client/Ats/Types/PaginatedOfferList.cs +++ b/src/Merge.Client/Ats/Types/PaginatedOfferList.cs @@ -1,18 +1,17 @@ using System.Text.Json.Serialization; -using Merge.Client.Ats; #nullable enable namespace Merge.Client.Ats; -public class PaginatedOfferList +public record PaginatedOfferList { [JsonPropertyName("next")] - public string? Next { get; init; } + public string? Next { get; set; } [JsonPropertyName("previous")] - public string? Previous { get; init; } + public string? Previous { get; set; } [JsonPropertyName("results")] - public IEnumerable? Results { get; init; } + public IEnumerable? Results { get; set; } } diff --git a/src/Merge.Client/Ats/Types/PaginatedOfficeList.cs b/src/Merge.Client/Ats/Types/PaginatedOfficeList.cs index a55d0837..ef32ab09 100644 --- a/src/Merge.Client/Ats/Types/PaginatedOfficeList.cs +++ b/src/Merge.Client/Ats/Types/PaginatedOfficeList.cs @@ -1,18 +1,17 @@ using System.Text.Json.Serialization; -using Merge.Client.Ats; #nullable enable namespace Merge.Client.Ats; -public class PaginatedOfficeList +public record PaginatedOfficeList { [JsonPropertyName("next")] - public string? Next { get; init; } + public string? Next { get; set; } [JsonPropertyName("previous")] - public string? Previous { get; init; } + public string? Previous { get; set; } [JsonPropertyName("results")] - public IEnumerable? Results { get; init; } + public IEnumerable? Results { get; set; } } diff --git a/src/Merge.Client/Ats/Types/PaginatedRejectReasonList.cs b/src/Merge.Client/Ats/Types/PaginatedRejectReasonList.cs index 61c76e4c..02549bdb 100644 --- a/src/Merge.Client/Ats/Types/PaginatedRejectReasonList.cs +++ b/src/Merge.Client/Ats/Types/PaginatedRejectReasonList.cs @@ -1,18 +1,17 @@ using System.Text.Json.Serialization; -using Merge.Client.Ats; #nullable enable namespace Merge.Client.Ats; -public class PaginatedRejectReasonList +public record PaginatedRejectReasonList { [JsonPropertyName("next")] - public string? Next { get; init; } + public string? Next { get; set; } [JsonPropertyName("previous")] - public string? Previous { get; init; } + public string? Previous { get; set; } [JsonPropertyName("results")] - public IEnumerable? Results { get; init; } + public IEnumerable? Results { get; set; } } diff --git a/src/Merge.Client/Ats/Types/PaginatedRemoteUserList.cs b/src/Merge.Client/Ats/Types/PaginatedRemoteUserList.cs index d0149205..afd623f2 100644 --- a/src/Merge.Client/Ats/Types/PaginatedRemoteUserList.cs +++ b/src/Merge.Client/Ats/Types/PaginatedRemoteUserList.cs @@ -1,18 +1,17 @@ using System.Text.Json.Serialization; -using Merge.Client.Ats; #nullable enable namespace Merge.Client.Ats; -public class PaginatedRemoteUserList +public record PaginatedRemoteUserList { [JsonPropertyName("next")] - public string? Next { get; init; } + public string? Next { get; set; } [JsonPropertyName("previous")] - public string? Previous { get; init; } + public string? Previous { get; set; } [JsonPropertyName("results")] - public IEnumerable? Results { get; init; } + public IEnumerable? Results { get; set; } } diff --git a/src/Merge.Client/Ats/Types/PaginatedScheduledInterviewList.cs b/src/Merge.Client/Ats/Types/PaginatedScheduledInterviewList.cs index 137d526b..96679961 100644 --- a/src/Merge.Client/Ats/Types/PaginatedScheduledInterviewList.cs +++ b/src/Merge.Client/Ats/Types/PaginatedScheduledInterviewList.cs @@ -1,18 +1,17 @@ using System.Text.Json.Serialization; -using Merge.Client.Ats; #nullable enable namespace Merge.Client.Ats; -public class PaginatedScheduledInterviewList +public record PaginatedScheduledInterviewList { [JsonPropertyName("next")] - public string? Next { get; init; } + public string? Next { get; set; } [JsonPropertyName("previous")] - public string? Previous { get; init; } + public string? Previous { get; set; } [JsonPropertyName("results")] - public IEnumerable? Results { get; init; } + public IEnumerable? Results { get; set; } } diff --git a/src/Merge.Client/Ats/Types/PaginatedScorecardList.cs b/src/Merge.Client/Ats/Types/PaginatedScorecardList.cs index c2cce529..847ec96c 100644 --- a/src/Merge.Client/Ats/Types/PaginatedScorecardList.cs +++ b/src/Merge.Client/Ats/Types/PaginatedScorecardList.cs @@ -1,18 +1,17 @@ using System.Text.Json.Serialization; -using Merge.Client.Ats; #nullable enable namespace Merge.Client.Ats; -public class PaginatedScorecardList +public record PaginatedScorecardList { [JsonPropertyName("next")] - public string? Next { get; init; } + public string? Next { get; set; } [JsonPropertyName("previous")] - public string? Previous { get; init; } + public string? Previous { get; set; } [JsonPropertyName("results")] - public IEnumerable? Results { get; init; } + public IEnumerable? Results { get; set; } } diff --git a/src/Merge.Client/Ats/Types/PaginatedScreeningQuestionList.cs b/src/Merge.Client/Ats/Types/PaginatedScreeningQuestionList.cs index 7958af80..dd8810b8 100644 --- a/src/Merge.Client/Ats/Types/PaginatedScreeningQuestionList.cs +++ b/src/Merge.Client/Ats/Types/PaginatedScreeningQuestionList.cs @@ -1,18 +1,17 @@ using System.Text.Json.Serialization; -using Merge.Client.Ats; #nullable enable namespace Merge.Client.Ats; -public class PaginatedScreeningQuestionList +public record PaginatedScreeningQuestionList { [JsonPropertyName("next")] - public string? Next { get; init; } + public string? Next { get; set; } [JsonPropertyName("previous")] - public string? Previous { get; init; } + public string? Previous { get; set; } [JsonPropertyName("results")] - public IEnumerable? Results { get; init; } + public IEnumerable? Results { get; set; } } diff --git a/src/Merge.Client/Ats/Types/PaginatedSyncStatusList.cs b/src/Merge.Client/Ats/Types/PaginatedSyncStatusList.cs index 6fcd781d..36370ddb 100644 --- a/src/Merge.Client/Ats/Types/PaginatedSyncStatusList.cs +++ b/src/Merge.Client/Ats/Types/PaginatedSyncStatusList.cs @@ -1,18 +1,17 @@ using System.Text.Json.Serialization; -using Merge.Client.Ats; #nullable enable namespace Merge.Client.Ats; -public class PaginatedSyncStatusList +public record PaginatedSyncStatusList { [JsonPropertyName("next")] - public string? Next { get; init; } + public string? Next { get; set; } [JsonPropertyName("previous")] - public string? Previous { get; init; } + public string? Previous { get; set; } [JsonPropertyName("results")] - public IEnumerable? Results { get; init; } + public IEnumerable? Results { get; set; } } diff --git a/src/Merge.Client/Ats/Types/PaginatedTagList.cs b/src/Merge.Client/Ats/Types/PaginatedTagList.cs index 25f95a7a..d70853d3 100644 --- a/src/Merge.Client/Ats/Types/PaginatedTagList.cs +++ b/src/Merge.Client/Ats/Types/PaginatedTagList.cs @@ -1,18 +1,17 @@ using System.Text.Json.Serialization; -using Merge.Client.Ats; #nullable enable namespace Merge.Client.Ats; -public class PaginatedTagList +public record PaginatedTagList { [JsonPropertyName("next")] - public string? Next { get; init; } + public string? Next { get; set; } [JsonPropertyName("previous")] - public string? Previous { get; init; } + public string? Previous { get; set; } [JsonPropertyName("results")] - public IEnumerable? Results { get; init; } + public IEnumerable? Results { get; set; } } diff --git a/src/Merge.Client/Ats/Types/PatchedCandidateRequest.cs b/src/Merge.Client/Ats/Types/PatchedCandidateRequest.cs index bc751a6c..438dc99f 100644 --- a/src/Merge.Client/Ats/Types/PatchedCandidateRequest.cs +++ b/src/Merge.Client/Ats/Types/PatchedCandidateRequest.cs @@ -1,93 +1,92 @@ using System.Text.Json.Serialization; -using Merge.Client.Ats; #nullable enable namespace Merge.Client.Ats; -public class PatchedCandidateRequest +public record PatchedCandidateRequest { /// /// The candidate's first name. /// [JsonPropertyName("first_name")] - public string? FirstName { get; init; } + public string? FirstName { get; set; } /// /// The candidate's last name. /// [JsonPropertyName("last_name")] - public string? LastName { get; init; } + public string? LastName { get; set; } /// /// The candidate's current company. /// [JsonPropertyName("company")] - public string? Company { get; init; } + public string? Company { get; set; } /// /// The candidate's current title. /// [JsonPropertyName("title")] - public string? Title { get; init; } + public string? Title { get; set; } /// /// When the most recent interaction with the candidate occurred. /// [JsonPropertyName("last_interaction_at")] - public DateTime? LastInteractionAt { get; init; } + public DateTime? LastInteractionAt { get; set; } /// /// Whether or not the candidate is private. /// [JsonPropertyName("is_private")] - public bool? IsPrivate { get; init; } + public bool? IsPrivate { get; set; } /// /// Whether or not the candidate can be emailed. /// [JsonPropertyName("can_email")] - public bool? CanEmail { get; init; } + public bool? CanEmail { get; set; } /// /// The candidate's locations. /// [JsonPropertyName("locations")] - public IEnumerable? Locations { get; init; } + public IEnumerable? Locations { get; set; } [JsonPropertyName("phone_numbers")] - public IEnumerable? PhoneNumbers { get; init; } + public IEnumerable? PhoneNumbers { get; set; } [JsonPropertyName("email_addresses")] - public IEnumerable? EmailAddresses { get; init; } + public IEnumerable? EmailAddresses { get; set; } [JsonPropertyName("urls")] - public IEnumerable? Urls { get; init; } + public IEnumerable? Urls { get; set; } /// /// Array of `Tag` names as strings. /// [JsonPropertyName("tags")] - public IEnumerable? Tags { get; init; } + public IEnumerable? Tags { get; set; } /// /// Array of `Application` object IDs. /// [JsonPropertyName("applications")] - public IEnumerable? Applications { get; init; } + public IEnumerable? Applications { get; set; } /// /// Array of `Attachment` object IDs. /// [JsonPropertyName("attachments")] - public IEnumerable? Attachments { get; init; } + public IEnumerable? Attachments { get; set; } [JsonPropertyName("remote_template_id")] - public string? RemoteTemplateId { get; init; } + public string? RemoteTemplateId { get; set; } [JsonPropertyName("integration_params")] - public Dictionary? IntegrationParams { get; init; } + public Dictionary? IntegrationParams { get; set; } [JsonPropertyName("linked_account_params")] - public Dictionary? LinkedAccountParams { get; init; } + public Dictionary? LinkedAccountParams { get; set; } } diff --git a/src/Merge.Client/Ats/Types/PhoneNumber.cs b/src/Merge.Client/Ats/Types/PhoneNumber.cs index 1811f8d3..ac321b3b 100644 --- a/src/Merge.Client/Ats/Types/PhoneNumber.cs +++ b/src/Merge.Client/Ats/Types/PhoneNumber.cs @@ -1,29 +1,28 @@ using System.Text.Json.Serialization; -using Merge.Client.Ats; #nullable enable namespace Merge.Client.Ats; -public class PhoneNumber +public record PhoneNumber { /// /// The datetime that this object was created by Merge. /// [JsonPropertyName("created_at")] - public DateTime? CreatedAt { get; init; } + public DateTime? CreatedAt { get; set; } /// /// The datetime that this object was modified by Merge. /// [JsonPropertyName("modified_at")] - public DateTime? ModifiedAt { get; init; } + public DateTime? ModifiedAt { get; set; } /// /// The phone number. /// [JsonPropertyName("value")] - public string? Value { get; init; } + public string? Value { get; set; } /// /// The type of phone number. @@ -35,11 +34,11 @@ public class PhoneNumber /// - `OTHER` - OTHER /// [JsonPropertyName("phone_number_type")] - public PhoneNumberTypeEnum? PhoneNumberType { get; init; } + public PhoneNumberTypeEnum? PhoneNumberType { get; set; } /// /// Indicates whether or not this object has been deleted in the third party platform. /// [JsonPropertyName("remote_was_deleted")] - public bool? RemoteWasDeleted { get; init; } + public bool? RemoteWasDeleted { get; set; } } diff --git a/src/Merge.Client/Ats/Types/PhoneNumberRequest.cs b/src/Merge.Client/Ats/Types/PhoneNumberRequest.cs index 3ce12722..3ff20b9b 100644 --- a/src/Merge.Client/Ats/Types/PhoneNumberRequest.cs +++ b/src/Merge.Client/Ats/Types/PhoneNumberRequest.cs @@ -1,17 +1,16 @@ using System.Text.Json.Serialization; -using Merge.Client.Ats; #nullable enable namespace Merge.Client.Ats; -public class PhoneNumberRequest +public record PhoneNumberRequest { /// /// The phone number. /// [JsonPropertyName("value")] - public string? Value { get; init; } + public string? Value { get; set; } /// /// The type of phone number. @@ -23,11 +22,11 @@ public class PhoneNumberRequest /// - `OTHER` - OTHER /// [JsonPropertyName("phone_number_type")] - public PhoneNumberTypeEnum? PhoneNumberType { get; init; } + public PhoneNumberTypeEnum? PhoneNumberType { get; set; } [JsonPropertyName("integration_params")] - public Dictionary? IntegrationParams { get; init; } + public Dictionary? IntegrationParams { get; set; } [JsonPropertyName("linked_account_params")] - public Dictionary? LinkedAccountParams { get; init; } + public Dictionary? LinkedAccountParams { get; set; } } diff --git a/src/Merge.Client/Ats/Types/PhoneNumberTypeEnum.cs b/src/Merge.Client/Ats/Types/PhoneNumberTypeEnum.cs index 0acc990e..9ae4a1bd 100644 --- a/src/Merge.Client/Ats/Types/PhoneNumberTypeEnum.cs +++ b/src/Merge.Client/Ats/Types/PhoneNumberTypeEnum.cs @@ -1,6 +1,5 @@ using System.Runtime.Serialization; using System.Text.Json.Serialization; -using Merge.Client.Ats; using Merge.Client.Core; #nullable enable diff --git a/src/Merge.Client/Ats/Types/RaceEnum.cs b/src/Merge.Client/Ats/Types/RaceEnum.cs index 164f4caa..65e6b296 100644 --- a/src/Merge.Client/Ats/Types/RaceEnum.cs +++ b/src/Merge.Client/Ats/Types/RaceEnum.cs @@ -1,6 +1,5 @@ using System.Runtime.Serialization; using System.Text.Json.Serialization; -using Merge.Client.Ats; using Merge.Client.Core; #nullable enable diff --git a/src/Merge.Client/Ats/Types/ReasonEnum.cs b/src/Merge.Client/Ats/Types/ReasonEnum.cs index 5edd34ef..52917478 100644 --- a/src/Merge.Client/Ats/Types/ReasonEnum.cs +++ b/src/Merge.Client/Ats/Types/ReasonEnum.cs @@ -1,6 +1,5 @@ using System.Runtime.Serialization; using System.Text.Json.Serialization; -using Merge.Client.Ats; using Merge.Client.Core; #nullable enable diff --git a/src/Merge.Client/Ats/Types/RejectReason.cs b/src/Merge.Client/Ats/Types/RejectReason.cs index 6c0e0a1c..796e7f8b 100644 --- a/src/Merge.Client/Ats/Types/RejectReason.cs +++ b/src/Merge.Client/Ats/Types/RejectReason.cs @@ -1,48 +1,47 @@ using System.Text.Json.Serialization; -using Merge.Client.Ats; #nullable enable namespace Merge.Client.Ats; -public class RejectReason +public record RejectReason { [JsonPropertyName("id")] - public string? Id { get; init; } + public string? Id { get; set; } /// /// The third-party API ID of the matching object. /// [JsonPropertyName("remote_id")] - public string? RemoteId { get; init; } + public string? RemoteId { get; set; } /// /// The datetime that this object was created by Merge. /// [JsonPropertyName("created_at")] - public DateTime? CreatedAt { get; init; } + public DateTime? CreatedAt { get; set; } /// /// The datetime that this object was modified by Merge. /// [JsonPropertyName("modified_at")] - public DateTime? ModifiedAt { get; init; } + public DateTime? ModifiedAt { get; set; } /// /// The rejection reason’s name. /// [JsonPropertyName("name")] - public string? Name { get; init; } + public string? Name { get; set; } /// /// Indicates whether or not this object has been deleted in the third party platform. /// [JsonPropertyName("remote_was_deleted")] - public bool? RemoteWasDeleted { get; init; } + public bool? RemoteWasDeleted { get; set; } [JsonPropertyName("field_mappings")] - public Dictionary? FieldMappings { get; init; } + public Dictionary? FieldMappings { get; set; } [JsonPropertyName("remote_data")] - public IEnumerable? RemoteData { get; init; } + public IEnumerable? RemoteData { get; set; } } diff --git a/src/Merge.Client/Ats/Types/RemoteData.cs b/src/Merge.Client/Ats/Types/RemoteData.cs index f888fb4c..93aeacfa 100644 --- a/src/Merge.Client/Ats/Types/RemoteData.cs +++ b/src/Merge.Client/Ats/Types/RemoteData.cs @@ -4,11 +4,11 @@ namespace Merge.Client.Ats; -public class RemoteData +public record RemoteData { [JsonPropertyName("path")] - public string Path { get; init; } + public required string Path { get; set; } [JsonPropertyName("data")] - public object? Data { get; init; } + public object? Data { get; set; } } diff --git a/src/Merge.Client/Ats/Types/RemoteEndpointInfo.cs b/src/Merge.Client/Ats/Types/RemoteEndpointInfo.cs index 6cae5208..bfeb2b7c 100644 --- a/src/Merge.Client/Ats/Types/RemoteEndpointInfo.cs +++ b/src/Merge.Client/Ats/Types/RemoteEndpointInfo.cs @@ -4,14 +4,14 @@ namespace Merge.Client.Ats; -public class RemoteEndpointInfo +public record RemoteEndpointInfo { [JsonPropertyName("method")] - public string Method { get; init; } + public required string Method { get; set; } [JsonPropertyName("url_path")] - public string UrlPath { get; init; } + public required string UrlPath { get; set; } [JsonPropertyName("field_traversal_path")] - public IEnumerable FieldTraversalPath { get; init; } + public IEnumerable FieldTraversalPath { get; set; } = new List(); } diff --git a/src/Merge.Client/Ats/Types/RemoteFieldApi.cs b/src/Merge.Client/Ats/Types/RemoteFieldApi.cs index 63c9b1eb..8d95d554 100644 --- a/src/Merge.Client/Ats/Types/RemoteFieldApi.cs +++ b/src/Merge.Client/Ats/Types/RemoteFieldApi.cs @@ -1,5 +1,4 @@ using System.Text.Json.Serialization; -using Merge.Client.Ats; using Merge.Client.Core; using OneOf; @@ -7,24 +6,24 @@ namespace Merge.Client.Ats; -public class RemoteFieldApi +public record RemoteFieldApi { [JsonPropertyName("schema")] - public Dictionary Schema { get; init; } + public Dictionary Schema { get; set; } = new Dictionary(); [JsonPropertyName("remote_key_name")] - public string RemoteKeyName { get; init; } + public required string RemoteKeyName { get; set; } [JsonPropertyName("remote_endpoint_info")] - public RemoteEndpointInfo RemoteEndpointInfo { get; init; } + public required RemoteEndpointInfo RemoteEndpointInfo { get; set; } [JsonPropertyName("example_values")] - public IEnumerable? ExampleValues { get; init; } + public IEnumerable? ExampleValues { get; set; } [JsonPropertyName("advanced_metadata")] - public AdvancedMetadata? AdvancedMetadata { get; init; } + public AdvancedMetadata? AdvancedMetadata { get; set; } [JsonPropertyName("coverage")] [JsonConverter(typeof(OneOfSerializer>))] - public OneOf? Coverage { get; init; } + public OneOf? Coverage { get; set; } } diff --git a/src/Merge.Client/Ats/Types/RemoteFieldApiResponse.cs b/src/Merge.Client/Ats/Types/RemoteFieldApiResponse.cs index 27314fe9..d5526f2d 100644 --- a/src/Merge.Client/Ats/Types/RemoteFieldApiResponse.cs +++ b/src/Merge.Client/Ats/Types/RemoteFieldApiResponse.cs @@ -1,57 +1,56 @@ using System.Text.Json.Serialization; -using Merge.Client.Ats; #nullable enable namespace Merge.Client.Ats; -public class RemoteFieldApiResponse +public record RemoteFieldApiResponse { [JsonPropertyName("Activity")] - public IEnumerable? Activity { get; init; } + public IEnumerable? Activity { get; set; } [JsonPropertyName("Application")] - public IEnumerable? Application { get; init; } + public IEnumerable? Application { get; set; } [JsonPropertyName("Attachment")] - public IEnumerable? Attachment { get; init; } + public IEnumerable? Attachment { get; set; } [JsonPropertyName("Candidate")] - public IEnumerable? Candidate { get; init; } + public IEnumerable? Candidate { get; set; } [JsonPropertyName("Department")] - public IEnumerable? Department { get; init; } + public IEnumerable? Department { get; set; } [JsonPropertyName("EEOC")] - public IEnumerable? Eeoc { get; init; } + public IEnumerable? Eeoc { get; set; } [JsonPropertyName("ScheduledInterview")] - public IEnumerable? ScheduledInterview { get; init; } + public IEnumerable? ScheduledInterview { get; set; } [JsonPropertyName("Job")] - public IEnumerable? Job { get; init; } + public IEnumerable? Job { get; set; } [JsonPropertyName("JobPosting")] - public IEnumerable? JobPosting { get; init; } + public IEnumerable? JobPosting { get; set; } [JsonPropertyName("JobInterviewStage")] - public IEnumerable? JobInterviewStage { get; init; } + public IEnumerable? JobInterviewStage { get; set; } [JsonPropertyName("Offer")] - public IEnumerable? Offer { get; init; } + public IEnumerable? Offer { get; set; } [JsonPropertyName("Office")] - public IEnumerable? Office { get; init; } + public IEnumerable? Office { get; set; } [JsonPropertyName("RejectReason")] - public IEnumerable? RejectReason { get; init; } + public IEnumerable? RejectReason { get; set; } [JsonPropertyName("Scorecard")] - public IEnumerable? Scorecard { get; init; } + public IEnumerable? Scorecard { get; set; } [JsonPropertyName("Tag")] - public IEnumerable? Tag { get; init; } + public IEnumerable? Tag { get; set; } [JsonPropertyName("RemoteUser")] - public IEnumerable? RemoteUser { get; init; } + public IEnumerable? RemoteUser { get; set; } } diff --git a/src/Merge.Client/Ats/Types/RemoteKey.cs b/src/Merge.Client/Ats/Types/RemoteKey.cs index 0a2bf3d0..1afb7342 100644 --- a/src/Merge.Client/Ats/Types/RemoteKey.cs +++ b/src/Merge.Client/Ats/Types/RemoteKey.cs @@ -4,11 +4,11 @@ namespace Merge.Client.Ats; -public class RemoteKey +public record RemoteKey { [JsonPropertyName("name")] - public string Name { get; init; } + public required string Name { get; set; } [JsonPropertyName("key")] - public string Key { get; init; } + public required string Key { get; set; } } diff --git a/src/Merge.Client/Ats/Types/RemoteResponse.cs b/src/Merge.Client/Ats/Types/RemoteResponse.cs index 69fa0ca1..315e964f 100644 --- a/src/Merge.Client/Ats/Types/RemoteResponse.cs +++ b/src/Merge.Client/Ats/Types/RemoteResponse.cs @@ -1,30 +1,29 @@ using System.Text.Json.Serialization; -using Merge.Client.Ats; #nullable enable namespace Merge.Client.Ats; -public class RemoteResponse +public record RemoteResponse { [JsonPropertyName("method")] - public string Method { get; init; } + public required string Method { get; set; } [JsonPropertyName("path")] - public string Path { get; init; } + public required string Path { get; set; } [JsonPropertyName("status")] - public int Status { get; init; } + public required int Status { get; set; } [JsonPropertyName("response")] - public object Response { get; init; } + public required object Response { get; set; } [JsonPropertyName("response_headers")] - public Dictionary? ResponseHeaders { get; init; } + public Dictionary? ResponseHeaders { get; set; } [JsonPropertyName("response_type")] - public ResponseTypeEnum? ResponseType { get; init; } + public ResponseTypeEnum? ResponseType { get; set; } [JsonPropertyName("headers")] - public Dictionary? Headers { get; init; } + public Dictionary? Headers { get; set; } } diff --git a/src/Merge.Client/Ats/Types/RemoteUser.cs b/src/Merge.Client/Ats/Types/RemoteUser.cs index 558b1a58..ec1eee7a 100644 --- a/src/Merge.Client/Ats/Types/RemoteUser.cs +++ b/src/Merge.Client/Ats/Types/RemoteUser.cs @@ -1,62 +1,61 @@ using System.Text.Json.Serialization; -using Merge.Client.Ats; #nullable enable namespace Merge.Client.Ats; -public class RemoteUser +public record RemoteUser { [JsonPropertyName("id")] - public string? Id { get; init; } + public string? Id { get; set; } /// /// The third-party API ID of the matching object. /// [JsonPropertyName("remote_id")] - public string? RemoteId { get; init; } + public string? RemoteId { get; set; } /// /// The datetime that this object was created by Merge. /// [JsonPropertyName("created_at")] - public DateTime? CreatedAt { get; init; } + public DateTime? CreatedAt { get; set; } /// /// The datetime that this object was modified by Merge. /// [JsonPropertyName("modified_at")] - public DateTime? ModifiedAt { get; init; } + public DateTime? ModifiedAt { get; set; } /// /// The user's first name. /// [JsonPropertyName("first_name")] - public string? FirstName { get; init; } + public string? FirstName { get; set; } /// /// The user's last name. /// [JsonPropertyName("last_name")] - public string? LastName { get; init; } + public string? LastName { get; set; } /// /// The user's email. /// [JsonPropertyName("email")] - public string? Email { get; init; } + public string? Email { get; set; } /// /// Whether the user's account had been disabled. /// [JsonPropertyName("disabled")] - public bool? Disabled { get; init; } + public bool? Disabled { get; set; } /// /// When the third party's user was created. /// [JsonPropertyName("remote_created_at")] - public DateTime? RemoteCreatedAt { get; init; } + public DateTime? RemoteCreatedAt { get; set; } /// /// The user's role. @@ -68,17 +67,17 @@ public class RemoteUser /// - `INTERVIEWER` - INTERVIEWER /// [JsonPropertyName("access_role")] - public AccessRoleEnum? AccessRole { get; init; } + public AccessRoleEnum? AccessRole { get; set; } /// /// Indicates whether or not this object has been deleted in the third party platform. /// [JsonPropertyName("remote_was_deleted")] - public bool? RemoteWasDeleted { get; init; } + public bool? RemoteWasDeleted { get; set; } [JsonPropertyName("field_mappings")] - public Dictionary? FieldMappings { get; init; } + public Dictionary? FieldMappings { get; set; } [JsonPropertyName("remote_data")] - public IEnumerable? RemoteData { get; init; } + public IEnumerable? RemoteData { get; set; } } diff --git a/src/Merge.Client/Ats/Types/RequestFormatEnum.cs b/src/Merge.Client/Ats/Types/RequestFormatEnum.cs index ee4c3760..b46baf3c 100644 --- a/src/Merge.Client/Ats/Types/RequestFormatEnum.cs +++ b/src/Merge.Client/Ats/Types/RequestFormatEnum.cs @@ -1,6 +1,5 @@ using System.Runtime.Serialization; using System.Text.Json.Serialization; -using Merge.Client.Ats; using Merge.Client.Core; #nullable enable diff --git a/src/Merge.Client/Ats/Types/ResponseTypeEnum.cs b/src/Merge.Client/Ats/Types/ResponseTypeEnum.cs index 07ab50b2..d1674f3a 100644 --- a/src/Merge.Client/Ats/Types/ResponseTypeEnum.cs +++ b/src/Merge.Client/Ats/Types/ResponseTypeEnum.cs @@ -1,6 +1,5 @@ using System.Runtime.Serialization; using System.Text.Json.Serialization; -using Merge.Client.Ats; using Merge.Client.Core; #nullable enable diff --git a/src/Merge.Client/Ats/Types/RoleEnum.cs b/src/Merge.Client/Ats/Types/RoleEnum.cs index 48215f41..0dac9244 100644 --- a/src/Merge.Client/Ats/Types/RoleEnum.cs +++ b/src/Merge.Client/Ats/Types/RoleEnum.cs @@ -1,6 +1,5 @@ using System.Runtime.Serialization; using System.Text.Json.Serialization; -using Merge.Client.Ats; using Merge.Client.Core; #nullable enable diff --git a/src/Merge.Client/Ats/Types/ScheduledInterview.cs b/src/Merge.Client/Ats/Types/ScheduledInterview.cs index 96d43f0f..7adc940e 100644 --- a/src/Merge.Client/Ats/Types/ScheduledInterview.cs +++ b/src/Merge.Client/Ats/Types/ScheduledInterview.cs @@ -1,5 +1,4 @@ using System.Text.Json.Serialization; -using Merge.Client.Ats; using Merge.Client.Core; using OneOf; @@ -7,49 +6,49 @@ namespace Merge.Client.Ats; -public class ScheduledInterview +public record ScheduledInterview { [JsonPropertyName("id")] - public string? Id { get; init; } + public string? Id { get; set; } /// /// The third-party API ID of the matching object. /// [JsonPropertyName("remote_id")] - public string? RemoteId { get; init; } + public string? RemoteId { get; set; } /// /// The datetime that this object was created by Merge. /// [JsonPropertyName("created_at")] - public DateTime? CreatedAt { get; init; } + public DateTime? CreatedAt { get; set; } /// /// The datetime that this object was modified by Merge. /// [JsonPropertyName("modified_at")] - public DateTime? ModifiedAt { get; init; } + public DateTime? ModifiedAt { get; set; } /// /// The application being interviewed. /// [JsonPropertyName("application")] [JsonConverter(typeof(OneOfSerializer>))] - public OneOf? Application { get; init; } + public OneOf? Application { get; set; } /// /// The stage of the interview. /// [JsonPropertyName("job_interview_stage")] [JsonConverter(typeof(OneOfSerializer>))] - public OneOf? JobInterviewStage { get; init; } + public OneOf? JobInterviewStage { get; set; } /// /// The user organizing the interview. /// [JsonPropertyName("organizer")] [JsonConverter(typeof(OneOfSerializer>))] - public OneOf? Organizer { get; init; } + public OneOf? Organizer { get; set; } /// /// Array of `RemoteUser` IDs. @@ -61,37 +60,37 @@ public class ScheduledInterview OneOfSerializer> >) )] - public IEnumerable>? Interviewers { get; init; } + public IEnumerable>? Interviewers { get; set; } /// /// The interview's location. /// [JsonPropertyName("location")] - public string? Location { get; init; } + public string? Location { get; set; } /// /// When the interview was started. /// [JsonPropertyName("start_at")] - public DateTime? StartAt { get; init; } + public DateTime? StartAt { get; set; } /// /// When the interview was ended. /// [JsonPropertyName("end_at")] - public DateTime? EndAt { get; init; } + public DateTime? EndAt { get; set; } /// /// When the third party's interview was created. /// [JsonPropertyName("remote_created_at")] - public DateTime? RemoteCreatedAt { get; init; } + public DateTime? RemoteCreatedAt { get; set; } /// /// When the third party's interview was updated. /// [JsonPropertyName("remote_updated_at")] - public DateTime? RemoteUpdatedAt { get; init; } + public DateTime? RemoteUpdatedAt { get; set; } /// /// The interview's status. @@ -101,17 +100,17 @@ public class ScheduledInterview /// - `COMPLETE` - COMPLETE /// [JsonPropertyName("status")] - public ScheduledInterviewStatusEnum? Status { get; init; } + public ScheduledInterviewStatusEnum? Status { get; set; } /// /// Indicates whether or not this object has been deleted in the third party platform. /// [JsonPropertyName("remote_was_deleted")] - public bool? RemoteWasDeleted { get; init; } + public bool? RemoteWasDeleted { get; set; } [JsonPropertyName("field_mappings")] - public Dictionary? FieldMappings { get; init; } + public Dictionary? FieldMappings { get; set; } [JsonPropertyName("remote_data")] - public IEnumerable? RemoteData { get; init; } + public IEnumerable? RemoteData { get; set; } } diff --git a/src/Merge.Client/Ats/Types/ScheduledInterviewRequest.cs b/src/Merge.Client/Ats/Types/ScheduledInterviewRequest.cs index ea3d3701..6dec629b 100644 --- a/src/Merge.Client/Ats/Types/ScheduledInterviewRequest.cs +++ b/src/Merge.Client/Ats/Types/ScheduledInterviewRequest.cs @@ -1,5 +1,4 @@ using System.Text.Json.Serialization; -using Merge.Client.Ats; using Merge.Client.Core; using OneOf; @@ -7,28 +6,28 @@ namespace Merge.Client.Ats; -public class ScheduledInterviewRequest +public record ScheduledInterviewRequest { /// /// The application being interviewed. /// [JsonPropertyName("application")] [JsonConverter(typeof(OneOfSerializer>))] - public OneOf? Application { get; init; } + public OneOf? Application { get; set; } /// /// The stage of the interview. /// [JsonPropertyName("job_interview_stage")] [JsonConverter(typeof(OneOfSerializer>))] - public OneOf? JobInterviewStage { get; init; } + public OneOf? JobInterviewStage { get; set; } /// /// The user organizing the interview. /// [JsonPropertyName("organizer")] [JsonConverter(typeof(OneOfSerializer>))] - public OneOf? Organizer { get; init; } + public OneOf? Organizer { get; set; } /// /// Array of `RemoteUser` IDs. @@ -40,25 +39,25 @@ public class ScheduledInterviewRequest OneOfSerializer> >) )] - public IEnumerable>? Interviewers { get; init; } + public IEnumerable>? Interviewers { get; set; } /// /// The interview's location. /// [JsonPropertyName("location")] - public string? Location { get; init; } + public string? Location { get; set; } /// /// When the interview was started. /// [JsonPropertyName("start_at")] - public DateTime? StartAt { get; init; } + public DateTime? StartAt { get; set; } /// /// When the interview was ended. /// [JsonPropertyName("end_at")] - public DateTime? EndAt { get; init; } + public DateTime? EndAt { get; set; } /// /// The interview's status. @@ -68,11 +67,11 @@ public class ScheduledInterviewRequest /// - `COMPLETE` - COMPLETE /// [JsonPropertyName("status")] - public ScheduledInterviewStatusEnum? Status { get; init; } + public ScheduledInterviewStatusEnum? Status { get; set; } [JsonPropertyName("integration_params")] - public Dictionary? IntegrationParams { get; init; } + public Dictionary? IntegrationParams { get; set; } [JsonPropertyName("linked_account_params")] - public Dictionary? LinkedAccountParams { get; init; } + public Dictionary? LinkedAccountParams { get; set; } } diff --git a/src/Merge.Client/Ats/Types/ScheduledInterviewResponse.cs b/src/Merge.Client/Ats/Types/ScheduledInterviewResponse.cs index 52708448..d54cd23a 100644 --- a/src/Merge.Client/Ats/Types/ScheduledInterviewResponse.cs +++ b/src/Merge.Client/Ats/Types/ScheduledInterviewResponse.cs @@ -1,21 +1,22 @@ using System.Text.Json.Serialization; -using Merge.Client.Ats; #nullable enable namespace Merge.Client.Ats; -public class ScheduledInterviewResponse +public record ScheduledInterviewResponse { [JsonPropertyName("model")] - public ScheduledInterview Model { get; init; } + public required ScheduledInterview Model { get; set; } [JsonPropertyName("warnings")] - public IEnumerable Warnings { get; init; } + public IEnumerable Warnings { get; set; } = + new List(); [JsonPropertyName("errors")] - public IEnumerable Errors { get; init; } + public IEnumerable Errors { get; set; } = + new List(); [JsonPropertyName("logs")] - public IEnumerable? Logs { get; init; } + public IEnumerable? Logs { get; set; } } diff --git a/src/Merge.Client/Ats/Types/ScheduledInterviewStatusEnum.cs b/src/Merge.Client/Ats/Types/ScheduledInterviewStatusEnum.cs index 53174c50..06e05f95 100644 --- a/src/Merge.Client/Ats/Types/ScheduledInterviewStatusEnum.cs +++ b/src/Merge.Client/Ats/Types/ScheduledInterviewStatusEnum.cs @@ -1,6 +1,5 @@ using System.Runtime.Serialization; using System.Text.Json.Serialization; -using Merge.Client.Ats; using Merge.Client.Core; #nullable enable diff --git a/src/Merge.Client/Ats/Types/Scorecard.cs b/src/Merge.Client/Ats/Types/Scorecard.cs index 8e31a6d8..097bf993 100644 --- a/src/Merge.Client/Ats/Types/Scorecard.cs +++ b/src/Merge.Client/Ats/Types/Scorecard.cs @@ -1,5 +1,4 @@ using System.Text.Json.Serialization; -using Merge.Client.Ats; using Merge.Client.Core; using OneOf; @@ -7,61 +6,61 @@ namespace Merge.Client.Ats; -public class Scorecard +public record Scorecard { [JsonPropertyName("id")] - public string? Id { get; init; } + public string? Id { get; set; } /// /// The third-party API ID of the matching object. /// [JsonPropertyName("remote_id")] - public string? RemoteId { get; init; } + public string? RemoteId { get; set; } /// /// The datetime that this object was created by Merge. /// [JsonPropertyName("created_at")] - public DateTime? CreatedAt { get; init; } + public DateTime? CreatedAt { get; set; } /// /// The datetime that this object was modified by Merge. /// [JsonPropertyName("modified_at")] - public DateTime? ModifiedAt { get; init; } + public DateTime? ModifiedAt { get; set; } /// /// The application being scored. /// [JsonPropertyName("application")] [JsonConverter(typeof(OneOfSerializer>))] - public OneOf? Application { get; init; } + public OneOf? Application { get; set; } /// /// The interview being scored. /// [JsonPropertyName("interview")] [JsonConverter(typeof(OneOfSerializer>))] - public OneOf? Interview { get; init; } + public OneOf? Interview { get; set; } /// /// The interviewer doing the scoring. /// [JsonPropertyName("interviewer")] [JsonConverter(typeof(OneOfSerializer>))] - public OneOf? Interviewer { get; init; } + public OneOf? Interviewer { get; set; } /// /// When the third party's scorecard was created. /// [JsonPropertyName("remote_created_at")] - public DateTime? RemoteCreatedAt { get; init; } + public DateTime? RemoteCreatedAt { get; set; } /// /// When the scorecard was submitted. /// [JsonPropertyName("submitted_at")] - public DateTime? SubmittedAt { get; init; } + public DateTime? SubmittedAt { get; set; } /// /// The inteviewer's recommendation. @@ -73,17 +72,17 @@ public class Scorecard /// - `NO_DECISION` - NO_DECISION /// [JsonPropertyName("overall_recommendation")] - public OverallRecommendationEnum? OverallRecommendation { get; init; } + public OverallRecommendationEnum? OverallRecommendation { get; set; } /// /// Indicates whether or not this object has been deleted in the third party platform. /// [JsonPropertyName("remote_was_deleted")] - public bool? RemoteWasDeleted { get; init; } + public bool? RemoteWasDeleted { get; set; } [JsonPropertyName("field_mappings")] - public Dictionary? FieldMappings { get; init; } + public Dictionary? FieldMappings { get; set; } [JsonPropertyName("remote_data")] - public IEnumerable? RemoteData { get; init; } + public IEnumerable? RemoteData { get; set; } } diff --git a/src/Merge.Client/Ats/Types/ScreeningQuestion.cs b/src/Merge.Client/Ats/Types/ScreeningQuestion.cs index af0b30b3..d5293b2f 100644 --- a/src/Merge.Client/Ats/Types/ScreeningQuestion.cs +++ b/src/Merge.Client/Ats/Types/ScreeningQuestion.cs @@ -1,5 +1,4 @@ using System.Text.Json.Serialization; -using Merge.Client.Ats; using Merge.Client.Core; using OneOf; @@ -7,47 +6,47 @@ namespace Merge.Client.Ats; -public class ScreeningQuestion +public record ScreeningQuestion { [JsonPropertyName("id")] - public string? Id { get; init; } + public string? Id { get; set; } /// /// The third-party API ID of the matching object. /// [JsonPropertyName("remote_id")] - public string? RemoteId { get; init; } + public string? RemoteId { get; set; } /// /// The datetime that this object was created by Merge. /// [JsonPropertyName("created_at")] - public DateTime? CreatedAt { get; init; } + public DateTime? CreatedAt { get; set; } /// /// The datetime that this object was modified by Merge. /// [JsonPropertyName("modified_at")] - public DateTime? ModifiedAt { get; init; } + public DateTime? ModifiedAt { get; set; } /// /// The job associated with the screening question. /// [JsonPropertyName("job")] [JsonConverter(typeof(OneOfSerializer>))] - public OneOf? Job { get; init; } + public OneOf? Job { get; set; } /// /// The description of the screening question /// [JsonPropertyName("description")] - public string? Description { get; init; } + public string? Description { get; set; } /// /// The title of the screening question /// [JsonPropertyName("title")] - public string? Title { get; init; } + public string? Title { get; set; } /// /// The data type for the screening question. @@ -62,20 +61,20 @@ public class ScreeningQuestion /// - `BOOLEAN` - BOOLEAN /// [JsonPropertyName("type")] - public ScreeningQuestionTypeEnum? Type { get; init; } + public ScreeningQuestionTypeEnum? Type { get; set; } /// /// Whether or not the screening question is required. /// [JsonPropertyName("required")] - public bool? Required { get; init; } + public bool? Required { get; set; } [JsonPropertyName("options")] - public IEnumerable? Options { get; init; } + public IEnumerable? Options { get; set; } /// /// Indicates whether or not this object has been deleted in the third party platform. /// [JsonPropertyName("remote_was_deleted")] - public bool? RemoteWasDeleted { get; init; } + public bool? RemoteWasDeleted { get; set; } } diff --git a/src/Merge.Client/Ats/Types/ScreeningQuestionAnswer.cs b/src/Merge.Client/Ats/Types/ScreeningQuestionAnswer.cs index 7e9eb128..7e52c864 100644 --- a/src/Merge.Client/Ats/Types/ScreeningQuestionAnswer.cs +++ b/src/Merge.Client/Ats/Types/ScreeningQuestionAnswer.cs @@ -1,5 +1,4 @@ using System.Text.Json.Serialization; -using Merge.Client.Ats; using Merge.Client.Core; using OneOf; @@ -7,45 +6,45 @@ namespace Merge.Client.Ats; -public class ScreeningQuestionAnswer +public record ScreeningQuestionAnswer { [JsonPropertyName("id")] - public string? Id { get; init; } + public string? Id { get; set; } /// /// The third-party API ID of the matching object. /// [JsonPropertyName("remote_id")] - public string? RemoteId { get; init; } + public string? RemoteId { get; set; } /// /// The datetime that this object was created by Merge. /// [JsonPropertyName("created_at")] - public DateTime? CreatedAt { get; init; } + public DateTime? CreatedAt { get; set; } /// /// The datetime that this object was modified by Merge. /// [JsonPropertyName("modified_at")] - public DateTime? ModifiedAt { get; init; } + public DateTime? ModifiedAt { get; set; } /// /// The screening question associated with the candidate’s answer. To determine the data type of the answer, you can expand on the screening question by adding `screening_question_answers.question` to the `expand` query parameter. /// [JsonPropertyName("question")] [JsonConverter(typeof(OneOfSerializer>))] - public OneOf? Question { get; init; } + public OneOf? Question { get; set; } /// /// The candidate’s response to the screening question. /// [JsonPropertyName("answer")] - public string? Answer { get; init; } + public string? Answer { get; set; } /// /// Indicates whether or not this object has been deleted in the third party platform. /// [JsonPropertyName("remote_was_deleted")] - public bool? RemoteWasDeleted { get; init; } + public bool? RemoteWasDeleted { get; set; } } diff --git a/src/Merge.Client/Ats/Types/ScreeningQuestionAnswerRequest.cs b/src/Merge.Client/Ats/Types/ScreeningQuestionAnswerRequest.cs index d21b304d..850a95e5 100644 --- a/src/Merge.Client/Ats/Types/ScreeningQuestionAnswerRequest.cs +++ b/src/Merge.Client/Ats/Types/ScreeningQuestionAnswerRequest.cs @@ -1,5 +1,4 @@ using System.Text.Json.Serialization; -using Merge.Client.Ats; using Merge.Client.Core; using OneOf; @@ -7,30 +6,30 @@ namespace Merge.Client.Ats; -public class ScreeningQuestionAnswerRequest +public record ScreeningQuestionAnswerRequest { /// /// The third-party API ID of the matching object. /// [JsonPropertyName("remote_id")] - public string? RemoteId { get; init; } + public string? RemoteId { get; set; } /// /// The screening question associated with the candidate’s answer. To determine the data type of the answer, you can expand on the screening question by adding `screening_question_answers.question` to the `expand` query parameter. /// [JsonPropertyName("question")] [JsonConverter(typeof(OneOfSerializer>))] - public OneOf? Question { get; init; } + public OneOf? Question { get; set; } /// /// The candidate’s response to the screening question. /// [JsonPropertyName("answer")] - public string? Answer { get; init; } + public string? Answer { get; set; } [JsonPropertyName("integration_params")] - public Dictionary? IntegrationParams { get; init; } + public Dictionary? IntegrationParams { get; set; } [JsonPropertyName("linked_account_params")] - public Dictionary? LinkedAccountParams { get; init; } + public Dictionary? LinkedAccountParams { get; set; } } diff --git a/src/Merge.Client/Ats/Types/ScreeningQuestionOption.cs b/src/Merge.Client/Ats/Types/ScreeningQuestionOption.cs index 23778750..baf9aad9 100644 --- a/src/Merge.Client/Ats/Types/ScreeningQuestionOption.cs +++ b/src/Merge.Client/Ats/Types/ScreeningQuestionOption.cs @@ -4,38 +4,38 @@ namespace Merge.Client.Ats; -public class ScreeningQuestionOption +public record ScreeningQuestionOption { [JsonPropertyName("id")] - public string? Id { get; init; } + public string? Id { get; set; } /// /// The third-party API ID of the matching object. /// [JsonPropertyName("remote_id")] - public string? RemoteId { get; init; } + public string? RemoteId { get; set; } /// /// The datetime that this object was created by Merge. /// [JsonPropertyName("created_at")] - public DateTime? CreatedAt { get; init; } + public DateTime? CreatedAt { get; set; } /// /// The datetime that this object was modified by Merge. /// [JsonPropertyName("modified_at")] - public DateTime? ModifiedAt { get; init; } + public DateTime? ModifiedAt { get; set; } /// /// Available response options /// [JsonPropertyName("label")] - public string? Label { get; init; } + public string? Label { get; set; } /// /// Indicates whether or not this object has been deleted in the third party platform. /// [JsonPropertyName("remote_was_deleted")] - public bool? RemoteWasDeleted { get; init; } + public bool? RemoteWasDeleted { get; set; } } diff --git a/src/Merge.Client/Ats/Types/ScreeningQuestionTypeEnum.cs b/src/Merge.Client/Ats/Types/ScreeningQuestionTypeEnum.cs index a1ccb932..300743d9 100644 --- a/src/Merge.Client/Ats/Types/ScreeningQuestionTypeEnum.cs +++ b/src/Merge.Client/Ats/Types/ScreeningQuestionTypeEnum.cs @@ -1,6 +1,5 @@ using System.Runtime.Serialization; using System.Text.Json.Serialization; -using Merge.Client.Ats; using Merge.Client.Core; #nullable enable diff --git a/src/Merge.Client/Ats/Types/SelectiveSyncConfigurationsUsageEnum.cs b/src/Merge.Client/Ats/Types/SelectiveSyncConfigurationsUsageEnum.cs index e058a4fd..41248a15 100644 --- a/src/Merge.Client/Ats/Types/SelectiveSyncConfigurationsUsageEnum.cs +++ b/src/Merge.Client/Ats/Types/SelectiveSyncConfigurationsUsageEnum.cs @@ -1,6 +1,5 @@ using System.Runtime.Serialization; using System.Text.Json.Serialization; -using Merge.Client.Ats; using Merge.Client.Core; #nullable enable diff --git a/src/Merge.Client/Ats/Types/SyncStatus.cs b/src/Merge.Client/Ats/Types/SyncStatus.cs index 7dd47bc7..88bd497d 100644 --- a/src/Merge.Client/Ats/Types/SyncStatus.cs +++ b/src/Merge.Client/Ats/Types/SyncStatus.cs @@ -1,30 +1,29 @@ using System.Text.Json.Serialization; -using Merge.Client.Ats; #nullable enable namespace Merge.Client.Ats; -public class SyncStatus +public record SyncStatus { [JsonPropertyName("model_name")] - public string ModelName { get; init; } + public required string ModelName { get; set; } [JsonPropertyName("model_id")] - public string ModelId { get; init; } + public required string ModelId { get; set; } [JsonPropertyName("last_sync_start")] - public DateTime? LastSyncStart { get; init; } + public DateTime? LastSyncStart { get; set; } [JsonPropertyName("next_sync_start")] - public DateTime? NextSyncStart { get; init; } + public DateTime? NextSyncStart { get; set; } [JsonPropertyName("status")] - public SyncStatusStatusEnum Status { get; init; } + public required SyncStatusStatusEnum Status { get; set; } [JsonPropertyName("is_initial_sync")] - public bool IsInitialSync { get; init; } + public required bool IsInitialSync { get; set; } [JsonPropertyName("selective_sync_configurations_usage")] - public SelectiveSyncConfigurationsUsageEnum? SelectiveSyncConfigurationsUsage { get; init; } + public SelectiveSyncConfigurationsUsageEnum? SelectiveSyncConfigurationsUsage { get; set; } } diff --git a/src/Merge.Client/Ats/Types/SyncStatusStatusEnum.cs b/src/Merge.Client/Ats/Types/SyncStatusStatusEnum.cs index abf175ad..f0c7cf62 100644 --- a/src/Merge.Client/Ats/Types/SyncStatusStatusEnum.cs +++ b/src/Merge.Client/Ats/Types/SyncStatusStatusEnum.cs @@ -1,6 +1,5 @@ using System.Runtime.Serialization; using System.Text.Json.Serialization; -using Merge.Client.Ats; using Merge.Client.Core; #nullable enable diff --git a/src/Merge.Client/Ats/Types/Tag.cs b/src/Merge.Client/Ats/Types/Tag.cs index 0f7f7c81..594c70ac 100644 --- a/src/Merge.Client/Ats/Types/Tag.cs +++ b/src/Merge.Client/Ats/Types/Tag.cs @@ -4,41 +4,41 @@ namespace Merge.Client.Ats; -public class Tag +public record Tag { /// /// The third-party API ID of the matching object. /// [JsonPropertyName("remote_id")] - public string? RemoteId { get; init; } + public string? RemoteId { get; set; } /// /// The datetime that this object was created by Merge. /// [JsonPropertyName("created_at")] - public DateTime? CreatedAt { get; init; } + public DateTime? CreatedAt { get; set; } /// /// The datetime that this object was modified by Merge. /// [JsonPropertyName("modified_at")] - public DateTime? ModifiedAt { get; init; } + public DateTime? ModifiedAt { get; set; } /// /// The tag's name. /// [JsonPropertyName("name")] - public string? Name { get; init; } + public string? Name { get; set; } /// /// Indicates whether or not this object has been deleted in the third party platform. /// [JsonPropertyName("remote_was_deleted")] - public bool? RemoteWasDeleted { get; init; } + public bool? RemoteWasDeleted { get; set; } [JsonPropertyName("field_mappings")] - public Dictionary? FieldMappings { get; init; } + public Dictionary? FieldMappings { get; set; } [JsonPropertyName("remote_data")] - public IEnumerable>? RemoteData { get; init; } + public IEnumerable>? RemoteData { get; set; } } diff --git a/src/Merge.Client/Ats/Types/Url.cs b/src/Merge.Client/Ats/Types/Url.cs index b4d07a8d..4852b612 100644 --- a/src/Merge.Client/Ats/Types/Url.cs +++ b/src/Merge.Client/Ats/Types/Url.cs @@ -1,29 +1,28 @@ using System.Text.Json.Serialization; -using Merge.Client.Ats; #nullable enable namespace Merge.Client.Ats; -public class Url +public record Url { /// /// The datetime that this object was created by Merge. /// [JsonPropertyName("created_at")] - public DateTime? CreatedAt { get; init; } + public DateTime? CreatedAt { get; set; } /// /// The datetime that this object was modified by Merge. /// [JsonPropertyName("modified_at")] - public DateTime? ModifiedAt { get; init; } + public DateTime? ModifiedAt { get; set; } /// /// The site's url. /// [JsonPropertyName("value")] - public string? Value { get; init; } + public string? Value { get; set; } /// /// The type of site. @@ -37,11 +36,11 @@ public class Url /// - `JOB_POSTING` - JOB_POSTING /// [JsonPropertyName("url_type")] - public UrlTypeEnum? UrlType { get; init; } + public UrlTypeEnum? UrlType { get; set; } /// /// Indicates whether or not this object has been deleted in the third party platform. /// [JsonPropertyName("remote_was_deleted")] - public bool? RemoteWasDeleted { get; init; } + public bool? RemoteWasDeleted { get; set; } } diff --git a/src/Merge.Client/Ats/Types/UrlRequest.cs b/src/Merge.Client/Ats/Types/UrlRequest.cs index f646f6e6..4972219f 100644 --- a/src/Merge.Client/Ats/Types/UrlRequest.cs +++ b/src/Merge.Client/Ats/Types/UrlRequest.cs @@ -1,17 +1,16 @@ using System.Text.Json.Serialization; -using Merge.Client.Ats; #nullable enable namespace Merge.Client.Ats; -public class UrlRequest +public record UrlRequest { /// /// The site's url. /// [JsonPropertyName("value")] - public string? Value { get; init; } + public string? Value { get; set; } /// /// The type of site. @@ -25,11 +24,11 @@ public class UrlRequest /// - `JOB_POSTING` - JOB_POSTING /// [JsonPropertyName("url_type")] - public UrlTypeEnum? UrlType { get; init; } + public UrlTypeEnum? UrlType { get; set; } [JsonPropertyName("integration_params")] - public Dictionary? IntegrationParams { get; init; } + public Dictionary? IntegrationParams { get; set; } [JsonPropertyName("linked_account_params")] - public Dictionary? LinkedAccountParams { get; init; } + public Dictionary? LinkedAccountParams { get; set; } } diff --git a/src/Merge.Client/Ats/Types/UrlTypeEnum.cs b/src/Merge.Client/Ats/Types/UrlTypeEnum.cs index 6d752851..fc84ce66 100644 --- a/src/Merge.Client/Ats/Types/UrlTypeEnum.cs +++ b/src/Merge.Client/Ats/Types/UrlTypeEnum.cs @@ -1,6 +1,5 @@ using System.Runtime.Serialization; using System.Text.Json.Serialization; -using Merge.Client.Ats; using Merge.Client.Core; #nullable enable diff --git a/src/Merge.Client/Ats/Types/ValidationProblemSource.cs b/src/Merge.Client/Ats/Types/ValidationProblemSource.cs index 4b349ec5..dba53c61 100644 --- a/src/Merge.Client/Ats/Types/ValidationProblemSource.cs +++ b/src/Merge.Client/Ats/Types/ValidationProblemSource.cs @@ -4,8 +4,8 @@ namespace Merge.Client.Ats; -public class ValidationProblemSource +public record ValidationProblemSource { [JsonPropertyName("pointer")] - public string Pointer { get; init; } + public required string Pointer { get; set; } } diff --git a/src/Merge.Client/Ats/Types/VeteranStatusEnum.cs b/src/Merge.Client/Ats/Types/VeteranStatusEnum.cs index 8d11ee3b..891c0c9e 100644 --- a/src/Merge.Client/Ats/Types/VeteranStatusEnum.cs +++ b/src/Merge.Client/Ats/Types/VeteranStatusEnum.cs @@ -1,6 +1,5 @@ using System.Runtime.Serialization; using System.Text.Json.Serialization; -using Merge.Client.Ats; using Merge.Client.Core; #nullable enable diff --git a/src/Merge.Client/Ats/Types/VisibilityEnum.cs b/src/Merge.Client/Ats/Types/VisibilityEnum.cs index 854fe1bd..c525482b 100644 --- a/src/Merge.Client/Ats/Types/VisibilityEnum.cs +++ b/src/Merge.Client/Ats/Types/VisibilityEnum.cs @@ -1,6 +1,5 @@ using System.Runtime.Serialization; using System.Text.Json.Serialization; -using Merge.Client.Ats; using Merge.Client.Core; #nullable enable diff --git a/src/Merge.Client/Ats/Types/WarningValidationProblem.cs b/src/Merge.Client/Ats/Types/WarningValidationProblem.cs index e676d718..03f18161 100644 --- a/src/Merge.Client/Ats/Types/WarningValidationProblem.cs +++ b/src/Merge.Client/Ats/Types/WarningValidationProblem.cs @@ -1,21 +1,20 @@ using System.Text.Json.Serialization; -using Merge.Client.Ats; #nullable enable namespace Merge.Client.Ats; -public class WarningValidationProblem +public record WarningValidationProblem { [JsonPropertyName("source")] - public ValidationProblemSource? Source { get; init; } + public ValidationProblemSource? Source { get; set; } [JsonPropertyName("title")] - public string Title { get; init; } + public required string Title { get; set; } [JsonPropertyName("detail")] - public string Detail { get; init; } + public required string Detail { get; set; } [JsonPropertyName("problem_type")] - public string ProblemType { get; init; } + public required string ProblemType { get; set; } } diff --git a/src/Merge.Client/Ats/Types/WebhookReceiver.cs b/src/Merge.Client/Ats/Types/WebhookReceiver.cs index d1a10912..cb49872a 100644 --- a/src/Merge.Client/Ats/Types/WebhookReceiver.cs +++ b/src/Merge.Client/Ats/Types/WebhookReceiver.cs @@ -4,14 +4,14 @@ namespace Merge.Client.Ats; -public class WebhookReceiver +public record WebhookReceiver { [JsonPropertyName("event")] - public string Event { get; init; } + public required string Event { get; set; } [JsonPropertyName("is_active")] - public bool IsActive { get; init; } + public required bool IsActive { get; set; } [JsonPropertyName("key")] - public string? Key { get; init; } + public string? Key { get; set; } } diff --git a/src/Merge.Client/Ats/Users/Requests/UsersListRequest.cs b/src/Merge.Client/Ats/Users/Requests/UsersListRequest.cs index 86d40c43..95e95b08 100644 --- a/src/Merge.Client/Ats/Users/Requests/UsersListRequest.cs +++ b/src/Merge.Client/Ats/Users/Requests/UsersListRequest.cs @@ -1,64 +1,64 @@ namespace Merge.Client.Ats; -public class UsersListRequest +public record UsersListRequest { /// /// If provided, will only return objects created after this datetime. /// - public DateTime? CreatedAfter { get; init; } + public DateTime? CreatedAfter { get; set; } /// /// If provided, will only return objects created before this datetime. /// - public DateTime? CreatedBefore { get; init; } + public DateTime? CreatedBefore { get; set; } /// /// The pagination cursor value. /// - public string? Cursor { get; init; } + public string? Cursor { get; set; } /// /// If provided, will only return remote users with the given email address /// - public string? Email { get; init; } + public string? Email { get; set; } /// /// Whether to include data that was marked as deleted by third party webhooks. /// - public bool? IncludeDeletedData { get; init; } + public bool? IncludeDeletedData { get; set; } /// /// Whether to include the original data Merge fetched from the third-party to produce these models. /// - public bool? IncludeRemoteData { get; init; } + public bool? IncludeRemoteData { get; set; } /// /// If provided, only objects synced by Merge after this date time will be returned. /// - public DateTime? ModifiedAfter { get; init; } + public DateTime? ModifiedAfter { get; set; } /// /// If provided, only objects synced by Merge before this date time will be returned. /// - public DateTime? ModifiedBefore { get; init; } + public DateTime? ModifiedBefore { get; set; } /// /// Number of results to return per page. /// - public int? PageSize { get; init; } + public int? PageSize { get; set; } /// /// Deprecated. Use show_enum_origins. /// - public string? RemoteFields { get; init; } + public string? RemoteFields { get; set; } /// /// The API provider's ID for the given object. /// - public string? RemoteId { get; init; } + public string? RemoteId { get; set; } /// /// A comma separated list of enum field names for which you'd like the original values to be returned, instead of Merge's normalized enum values. [Learn more](https://help.merge.dev/en/articles/8950958-show_enum_origins-query-parameter) /// - public string? ShowEnumOrigins { get; init; } + public string? ShowEnumOrigins { get; set; } } diff --git a/src/Merge.Client/Ats/Users/Requests/UsersRetrieveRequest.cs b/src/Merge.Client/Ats/Users/Requests/UsersRetrieveRequest.cs index 581b79e2..3e21876e 100644 --- a/src/Merge.Client/Ats/Users/Requests/UsersRetrieveRequest.cs +++ b/src/Merge.Client/Ats/Users/Requests/UsersRetrieveRequest.cs @@ -1,19 +1,19 @@ namespace Merge.Client.Ats; -public class UsersRetrieveRequest +public record UsersRetrieveRequest { /// /// Whether to include the original data Merge fetched from the third-party to produce these models. /// - public bool? IncludeRemoteData { get; init; } + public bool? IncludeRemoteData { get; set; } /// /// Deprecated. Use show_enum_origins. /// - public string? RemoteFields { get; init; } + public string? RemoteFields { get; set; } /// /// A comma separated list of enum field names for which you'd like the original values to be returned, instead of Merge's normalized enum values. [Learn more](https://help.merge.dev/en/articles/8950958-show_enum_origins-query-parameter) /// - public string? ShowEnumOrigins { get; init; } + public string? ShowEnumOrigins { get; set; } } diff --git a/src/Merge.Client/Ats/Users/UsersClient.cs b/src/Merge.Client/Ats/Users/UsersClient.cs index 746527ec..46dccbb0 100644 --- a/src/Merge.Client/Ats/Users/UsersClient.cs +++ b/src/Merge.Client/Ats/Users/UsersClient.cs @@ -1,6 +1,6 @@ +using System.Net.Http; using System.Text.Json; -using Merge.Client; -using Merge.Client.Ats; +using Merge.Client.Core; #nullable enable @@ -18,16 +18,21 @@ public UsersClient(RawClient client) /// /// Returns a list of `RemoteUser` objects. /// - public async Task ListAsync(UsersListRequest request) + public async Task ListAsync( + UsersListRequest request, + RequestOptions? options = null + ) { var _query = new Dictionary() { }; if (request.CreatedAfter != null) { - _query["created_after"] = request.CreatedAfter.Value.ToString("o0"); + _query["created_after"] = request.CreatedAfter.Value.ToString(Constants.DateTimeFormat); } if (request.CreatedBefore != null) { - _query["created_before"] = request.CreatedBefore.Value.ToString("o0"); + _query["created_before"] = request.CreatedBefore.Value.ToString( + Constants.DateTimeFormat + ); } if (request.Cursor != null) { @@ -47,11 +52,15 @@ public async Task ListAsync(UsersListRequest request) } if (request.ModifiedAfter != null) { - _query["modified_after"] = request.ModifiedAfter.Value.ToString("o0"); + _query["modified_after"] = request.ModifiedAfter.Value.ToString( + Constants.DateTimeFormat + ); } if (request.ModifiedBefore != null) { - _query["modified_before"] = request.ModifiedBefore.Value.ToString("o0"); + _query["modified_before"] = request.ModifiedBefore.Value.ToString( + Constants.DateTimeFormat + ); } if (request.PageSize != null) { @@ -72,23 +81,41 @@ public async Task ListAsync(UsersListRequest request) var response = await _client.MakeRequestAsync( new RawClient.JsonApiRequest { + BaseUrl = _client.Options.BaseUrl, Method = HttpMethod.Get, Path = "ats/v1/users", - Query = _query + Query = _query, + Options = options } ); - string responseBody = await response.Raw.Content.ReadAsStringAsync(); - if (response.StatusCode >= 200 && response.StatusCode < 400) + var responseBody = await response.Raw.Content.ReadAsStringAsync(); + if (response.StatusCode is >= 200 and < 400) { - return JsonSerializer.Deserialize(responseBody); + try + { + return JsonUtils.Deserialize(responseBody)!; + } + catch (JsonException e) + { + throw new MergeException("Failed to deserialize response", e); + } } - throw new Exception(responseBody); + + throw new MergeApiException( + $"Error with status code {response.StatusCode}", + response.StatusCode, + JsonUtils.Deserialize(responseBody) + ); } /// /// Returns a `RemoteUser` object with the given `id`. /// - public async Task RetrieveAsync(string id, UsersRetrieveRequest request) + public async Task RetrieveAsync( + string id, + UsersRetrieveRequest request, + RequestOptions? options = null + ) { var _query = new Dictionary() { }; if (request.IncludeRemoteData != null) @@ -106,16 +133,30 @@ public async Task RetrieveAsync(string id, UsersRetrieveRequest requ var response = await _client.MakeRequestAsync( new RawClient.JsonApiRequest { + BaseUrl = _client.Options.BaseUrl, Method = HttpMethod.Get, Path = $"ats/v1/users/{id}", - Query = _query + Query = _query, + Options = options } ); - string responseBody = await response.Raw.Content.ReadAsStringAsync(); - if (response.StatusCode >= 200 && response.StatusCode < 400) + var responseBody = await response.Raw.Content.ReadAsStringAsync(); + if (response.StatusCode is >= 200 and < 400) { - return JsonSerializer.Deserialize(responseBody); + try + { + return JsonUtils.Deserialize(responseBody)!; + } + catch (JsonException e) + { + throw new MergeException("Failed to deserialize response", e); + } } - throw new Exception(responseBody); + + throw new MergeApiException( + $"Error with status code {response.StatusCode}", + response.StatusCode, + JsonUtils.Deserialize(responseBody) + ); } } diff --git a/src/Merge.Client/Ats/WebhookReceivers/Requests/WebhookReceiverRequest.cs b/src/Merge.Client/Ats/WebhookReceivers/Requests/WebhookReceiverRequest.cs index c92dd987..bbfc85de 100644 --- a/src/Merge.Client/Ats/WebhookReceivers/Requests/WebhookReceiverRequest.cs +++ b/src/Merge.Client/Ats/WebhookReceivers/Requests/WebhookReceiverRequest.cs @@ -4,14 +4,14 @@ namespace Merge.Client.Ats; -public class WebhookReceiverRequest +public record WebhookReceiverRequest { [JsonPropertyName("event")] - public string Event { get; init; } + public required string Event { get; set; } [JsonPropertyName("is_active")] - public bool IsActive { get; init; } + public required bool IsActive { get; set; } [JsonPropertyName("key")] - public string? Key { get; init; } + public string? Key { get; set; } } diff --git a/src/Merge.Client/Ats/WebhookReceivers/WebhookReceiversClient.cs b/src/Merge.Client/Ats/WebhookReceivers/WebhookReceiversClient.cs index 1c8cb206..c5da7b1e 100644 --- a/src/Merge.Client/Ats/WebhookReceivers/WebhookReceiversClient.cs +++ b/src/Merge.Client/Ats/WebhookReceivers/WebhookReceiversClient.cs @@ -1,6 +1,6 @@ +using System.Net.Http; using System.Text.Json; -using Merge.Client; -using Merge.Client.Ats; +using Merge.Client.Core; #nullable enable @@ -18,41 +18,72 @@ public WebhookReceiversClient(RawClient client) /// /// Returns a list of `WebhookReceiver` objects. /// - public async Task> ListAsync() + public async Task> ListAsync(RequestOptions? options = null) { var response = await _client.MakeRequestAsync( new RawClient.JsonApiRequest { + BaseUrl = _client.Options.BaseUrl, Method = HttpMethod.Get, - Path = "ats/v1/webhook-receivers" + Path = "ats/v1/webhook-receivers", + Options = options } ); - string responseBody = await response.Raw.Content.ReadAsStringAsync(); - if (response.StatusCode >= 200 && response.StatusCode < 400) + var responseBody = await response.Raw.Content.ReadAsStringAsync(); + if (response.StatusCode is >= 200 and < 400) { - return JsonSerializer.Deserialize>(responseBody); + try + { + return JsonUtils.Deserialize>(responseBody)!; + } + catch (JsonException e) + { + throw new MergeException("Failed to deserialize response", e); + } } - throw new Exception(responseBody); + + throw new MergeApiException( + $"Error with status code {response.StatusCode}", + response.StatusCode, + JsonUtils.Deserialize(responseBody) + ); } /// /// Creates a `WebhookReceiver` object with the given values. /// - public async Task CreateAsync(WebhookReceiverRequest request) + public async Task CreateAsync( + WebhookReceiverRequest request, + RequestOptions? options = null + ) { var response = await _client.MakeRequestAsync( new RawClient.JsonApiRequest { + BaseUrl = _client.Options.BaseUrl, Method = HttpMethod.Post, Path = "ats/v1/webhook-receivers", - Body = request + Body = request, + Options = options } ); - string responseBody = await response.Raw.Content.ReadAsStringAsync(); - if (response.StatusCode >= 200 && response.StatusCode < 400) + var responseBody = await response.Raw.Content.ReadAsStringAsync(); + if (response.StatusCode is >= 200 and < 400) { - return JsonSerializer.Deserialize(responseBody); + try + { + return JsonUtils.Deserialize(responseBody)!; + } + catch (JsonException e) + { + throw new MergeException("Failed to deserialize response", e); + } } - throw new Exception(responseBody); + + throw new MergeApiException( + $"Error with status code {response.StatusCode}", + response.StatusCode, + JsonUtils.Deserialize(responseBody) + ); } } diff --git a/src/Merge.Client/Core/ClientOptions.cs b/src/Merge.Client/Core/ClientOptions.cs index f4be4468..d813dd6f 100644 --- a/src/Merge.Client/Core/ClientOptions.cs +++ b/src/Merge.Client/Core/ClientOptions.cs @@ -1,15 +1,16 @@ -using Merge.Client.Core; +using System; +using System.Net.Http; #nullable enable -namespace Merge.Client; +namespace Merge.Client.Core; public partial class ClientOptions { /// /// The Base URL for the API. /// - public string BaseUrl { get; init; } = Environments.PRODUCTION; + public string BaseUrl { get; init; } = MergeEnvironment.PRODUCTION; /// /// The http client used to make requests. @@ -22,7 +23,7 @@ public partial class ClientOptions public int MaxRetries { get; init; } = 2; /// - /// The timeout for the request in seconds. + /// The timeout for the request. /// - public int TimeoutInSeconds { get; init; } = 30; + public TimeSpan Timeout { get; init; } = TimeSpan.FromSeconds(30); } diff --git a/src/Merge.Client/Core/CollectionItemSerializer.cs b/src/Merge.Client/Core/CollectionItemSerializer.cs index da8ead79..bce5fd22 100644 --- a/src/Merge.Client/Core/CollectionItemSerializer.cs +++ b/src/Merge.Client/Core/CollectionItemSerializer.cs @@ -3,7 +3,7 @@ using System.Text.Json; using System.Text.Json.Serialization; -namespace Merge.Client; +namespace Merge.Client.Core; /// /// Json collection converter. @@ -21,35 +21,34 @@ public class CollectionItemSerializer /// Type to convert. /// Serializer options. /// Created object. - public override IEnumerable Read( + public override IEnumerable? Read( ref Utf8JsonReader reader, - Type typeToConvert, + System.Type typeToConvert, JsonSerializerOptions options ) { if (reader.TokenType == JsonTokenType.Null) { - return default(IEnumerable); + return default; } - JsonSerializerOptions jsonSerializerOptions = new JsonSerializerOptions(options); + var jsonSerializerOptions = new JsonSerializerOptions(options); jsonSerializerOptions.Converters.Clear(); jsonSerializerOptions.Converters.Add(Activator.CreateInstance()); - List returnValue = new List(); + var returnValue = new List(); while (reader.TokenType != JsonTokenType.EndArray) { if (reader.TokenType != JsonTokenType.StartArray) { - returnValue.Add( - (TDatatype) - JsonSerializer.Deserialize( - ref reader, - typeof(TDatatype), - jsonSerializerOptions - ) + var item = (TDatatype)( + JsonSerializer.Deserialize(ref reader, typeof(TDatatype), jsonSerializerOptions) + ?? throw new Exception( + $"Failed to deserialize collection item of type {typeof(TDatatype)}" + ) ); + returnValue.Add(item); } reader.Read(); @@ -66,7 +65,7 @@ JsonSerializerOptions options /// Serializer options. public override void Write( Utf8JsonWriter writer, - IEnumerable value, + IEnumerable? value, JsonSerializerOptions options ) { @@ -82,7 +81,7 @@ JsonSerializerOptions options writer.WriteStartArray(); - foreach (TDatatype data in value) + foreach (var data in value) { JsonSerializer.Serialize(writer, data, jsonSerializerOptions); } diff --git a/src/Merge.Client/Core/Constants.cs b/src/Merge.Client/Core/Constants.cs new file mode 100644 index 00000000..c3fc1915 --- /dev/null +++ b/src/Merge.Client/Core/Constants.cs @@ -0,0 +1,6 @@ +namespace Merge.Client.Core; + +public static class Constants +{ + public const string DateTimeFormat = "yyyy'-'MM'-'dd'T'HH':'mm':'ss.fffK"; +} diff --git a/src/Merge.Client/Core/DateTimeSerializer.cs b/src/Merge.Client/Core/DateTimeSerializer.cs new file mode 100644 index 00000000..951a4547 --- /dev/null +++ b/src/Merge.Client/Core/DateTimeSerializer.cs @@ -0,0 +1,22 @@ +using System.Globalization; +using System.Text.Json; +using System.Text.Json.Serialization; + +namespace Merge.Client.Core; + +public class DateTimeSerializer : JsonConverter +{ + public override DateTime Read( + ref Utf8JsonReader reader, + System.Type typeToConvert, + JsonSerializerOptions options + ) + { + return DateTime.Parse(reader.GetString()!, null, DateTimeStyles.RoundtripKind); + } + + public override void Write(Utf8JsonWriter writer, DateTime value, JsonSerializerOptions options) + { + writer.WriteStringValue(value.ToString(Constants.DateTimeFormat)); + } +} diff --git a/src/Merge.Client/Core/HttpMethodExtensions.cs b/src/Merge.Client/Core/HttpMethodExtensions.cs new file mode 100644 index 00000000..6226a13d --- /dev/null +++ b/src/Merge.Client/Core/HttpMethodExtensions.cs @@ -0,0 +1,8 @@ +using System.Net.Http; + +namespace Merge.Client.Core; + +public static class HttpMethodExtensions +{ + public static readonly HttpMethod Patch = new("PATCH"); +} diff --git a/src/Merge.Client/Core/JsonConfiguration.cs b/src/Merge.Client/Core/JsonConfiguration.cs new file mode 100644 index 00000000..60dbec04 --- /dev/null +++ b/src/Merge.Client/Core/JsonConfiguration.cs @@ -0,0 +1,30 @@ +using System.Text.Json; + +namespace Merge.Client.Core; + +public static class JsonOptions +{ + public static readonly JsonSerializerOptions JsonSerializerOptions; + + static JsonOptions() + { + JsonSerializerOptions = new JsonSerializerOptions + { + Converters = { new DateTimeSerializer() }, + WriteIndented = true + }; + } +} + +public static class JsonUtils +{ + public static string Serialize(T obj) + { + return JsonSerializer.Serialize(obj, JsonOptions.JsonSerializerOptions); + } + + public static T Deserialize(string json) + { + return JsonSerializer.Deserialize(json, JsonOptions.JsonSerializerOptions)!; + } +} diff --git a/src/Merge.Client/Core/MergeApiException.cs b/src/Merge.Client/Core/MergeApiException.cs new file mode 100644 index 00000000..02050b60 --- /dev/null +++ b/src/Merge.Client/Core/MergeApiException.cs @@ -0,0 +1,23 @@ +namespace Merge.Client.Core; + +/// +/// This exception type will be thrown for any non-2XX API responses. +/// +public class MergeApiException(string message, int statusCode, object body) + : MergeException(message) +{ + /// + /// The error code of the response that triggered the exception. + /// + public int StatusCode { get; } = statusCode; + + /// + /// The body of the response that triggered the exception. + /// + public object Body { get; } = body; + + public override string ToString() + { + return $"MergeApiException {{ message: {Message}, statusCode: {StatusCode}, body: {Body} }}"; + } +} diff --git a/src/Merge.Client/Core/Environments.cs b/src/Merge.Client/Core/MergeEnvironment.cs similarity index 89% rename from src/Merge.Client/Core/Environments.cs rename to src/Merge.Client/Core/MergeEnvironment.cs index 65c83b3f..1d361bf7 100644 --- a/src/Merge.Client/Core/Environments.cs +++ b/src/Merge.Client/Core/MergeEnvironment.cs @@ -1,6 +1,6 @@ namespace Merge.Client.Core; -public class Environments +public class MergeEnvironment { public static string PRODUCTION = "https://api.merge.dev/api"; diff --git a/src/Merge.Client/Core/MergeException.cs b/src/Merge.Client/Core/MergeException.cs new file mode 100644 index 00000000..6f1c2925 --- /dev/null +++ b/src/Merge.Client/Core/MergeException.cs @@ -0,0 +1,11 @@ +using System; + +#nullable enable + +namespace Merge.Client.Core; + +/// +/// Base exception class for all exceptions thrown by the SDK. +/// +public class MergeException(string message, Exception? innerException = null) + : Exception(message, innerException) { } diff --git a/src/Merge.Client/Core/OneOfSerializer.cs b/src/Merge.Client/Core/OneOfSerializer.cs index 8348cc62..e361874f 100644 --- a/src/Merge.Client/Core/OneOfSerializer.cs +++ b/src/Merge.Client/Core/OneOfSerializer.cs @@ -3,14 +3,14 @@ using System.Text.Json.Serialization; using OneOf; -namespace Merge.Client; +namespace Merge.Client.Core; public class OneOfSerializer : JsonConverter where TOneOf : IOneOf { - public override TOneOf Read( + public override TOneOf? Read( ref Utf8JsonReader reader, - Type typeToConvert, + System.Type typeToConvert, JsonSerializerOptions options ) { @@ -21,10 +21,10 @@ JsonSerializerOptions options { try { - Utf8JsonReader readerCopy = reader; + var readerCopy = reader; var result = JsonSerializer.Deserialize(ref readerCopy, type, options); reader.Skip(); - return (TOneOf)cast.Invoke(null, new[] { result })!; + return (TOneOf)cast.Invoke(null, [result])!; } catch (JsonException) { } } @@ -34,14 +34,14 @@ JsonSerializerOptions options ); } - private static readonly (Type type, MethodInfo cast)[] s_types = GetOneOfTypes(); + private static readonly (System.Type type, MethodInfo cast)[] s_types = GetOneOfTypes(); public override void Write(Utf8JsonWriter writer, TOneOf value, JsonSerializerOptions options) { JsonSerializer.Serialize(writer, value.Value, options); } - private static (Type type, MethodInfo cast)[] GetOneOfTypes() + private static (System.Type type, MethodInfo cast)[] GetOneOfTypes() { var casts = typeof(TOneOf) .GetRuntimeMethods() diff --git a/src/Merge.Client/Core/RawClient.cs b/src/Merge.Client/Core/RawClient.cs index bd0e2e00..82d97b2f 100644 --- a/src/Merge.Client/Core/RawClient.cs +++ b/src/Merge.Client/Core/RawClient.cs @@ -1,143 +1,149 @@ +using System.Net.Http; using System.Text; -using System.Text.Json; -namespace Merge.Client; +namespace Merge.Client.Core; #nullable enable /// /// Utility class for making raw HTTP requests to the API. /// -public class RawClient +public class RawClient( + Dictionary headers, + Dictionary> headerSuppliers, + ClientOptions clientOptions +) { /// /// The http client used to make requests. /// - private readonly ClientOptions _clientOptions; + public readonly ClientOptions Options = clientOptions; /// /// Global headers to be sent with every request. /// - private readonly Dictionary _headers; - - public RawClient(Dictionary headers, ClientOptions clientOptions) - { - _clientOptions = clientOptions; - _headers = headers; - } + private readonly Dictionary _headers = headers; public async Task MakeRequestAsync(BaseApiRequest request) { - var url = this.BuildUrl(request.Path, request.Query); + var url = BuildUrl(request); var httpRequest = new HttpRequestMessage(request.Method, url); if (request.ContentType != null) { request.Headers.Add("Content-Type", request.ContentType); } // Add global headers to the request - foreach (var (key, value) in _headers) + foreach (var header in _headers) + { + httpRequest.Headers.Add(header.Key, header.Value); + } + // Add global headers to the request from supplier + foreach (var header in headerSuppliers) { - httpRequest.Headers.Add(key, value); + httpRequest.Headers.Add(header.Key, header.Value.Invoke()); } // Add request headers to the request - foreach (var (key, value) in request.Headers) + foreach (var header in request.Headers) { - httpRequest.Headers.Add(key, value); + httpRequest.Headers.Add(header.Key, header.Value); } // Add the request body to the request if (request is JsonApiRequest jsonRequest) { if (jsonRequest.Body != null) { - var serializerOptions = new JsonSerializerOptions { WriteIndented = true, }; httpRequest.Content = new StringContent( - JsonSerializer.Serialize(jsonRequest.Body, serializerOptions), + JsonUtils.Serialize(jsonRequest.Body), Encoding.UTF8, "application/json" ); } } - else if (request is StreamApiRequest streamRequest) + else if (request is StreamApiRequest { Body: not null } streamRequest) { - if (streamRequest.Body != null) - { - httpRequest.Content = new StreamContent(streamRequest.Body); - } + httpRequest.Content = new StreamContent(streamRequest.Body); } // Send the request - HttpResponseMessage response = await _clientOptions.HttpClient.SendAsync(httpRequest); + var httpClient = request.Options?.HttpClient ?? Options.HttpClient; + var response = await httpClient.SendAsync(httpRequest); return new ApiResponse { StatusCode = (int)response.StatusCode, Raw = response }; } - public abstract class BaseApiRequest + public record BaseApiRequest { - public HttpMethod Method; + public required string BaseUrl { get; init; } - public string Path; + public required HttpMethod Method { get; init; } - public string? ContentType = null; + public required string Path { get; init; } + + public string? ContentType { get; init; } public Dictionary Query { get; init; } = new(); public Dictionary Headers { get; init; } = new(); - public object RequestOptions { get; init; } + public RequestOptions? Options { get; init; } } /// /// The request object to be sent for streaming uploads. /// - public class StreamApiRequest : BaseApiRequest + public record StreamApiRequest : BaseApiRequest { - public Stream? Body { get; init; } = null; + public Stream? Body { get; init; } } /// /// The request object to be sent for JSON APIs. /// - public class JsonApiRequest : BaseApiRequest + public record JsonApiRequest : BaseApiRequest { - public object? Body { get; init; } = null; + public object? Body { get; init; } } /// /// The response object returned from the API. /// - public class ApiResponse + public record ApiResponse { - public int StatusCode; + public required int StatusCode { get; init; } - public HttpResponseMessage Raw; + public required HttpResponseMessage Raw { get; init; } } - private Dictionary GetHeaders(BaseApiRequest request) + private string BuildUrl(BaseApiRequest request) { - var headers = new Dictionary(); - foreach (var (key, value) in request.Headers) - { - headers.Add(key, value); - } - foreach (var (key, value) in _headers) - { - headers.Add(key, value); - } - return headers; - } - - public string BuildUrl(string path, Dictionary query) - { - var trimmedBaseUrl = _clientOptions.BaseUrl.TrimEnd('/'); - var trimmedBasePath = path.TrimStart('/'); + var baseUrl = request.Options?.BaseUrl ?? request.BaseUrl; + var trimmedBaseUrl = baseUrl.TrimEnd('/'); + var trimmedBasePath = request.Path.TrimStart('/'); var url = $"{trimmedBaseUrl}/{trimmedBasePath}"; - if (query.Count > 0) - { - url += "?"; - foreach (var (key, value) in query) + if (request.Query.Count <= 0) + return url; + url += "?"; + url = request.Query.Aggregate( + url, + (current, queryItem) => { - url += $"{key}={value}&"; + if (queryItem.Value is System.Collections.IEnumerable collection and not string) + { + var items = collection + .Cast() + .Select(value => $"{queryItem.Key}={value}") + .ToList(); + if (items.Any()) + { + current += string.Join("&", items) + "&"; + } + } + else + { + current += $"{queryItem.Key}={queryItem.Value}&"; + } + return current; } - url = url.Substring(0, url.Length - 1); - } + ); + url = url.Substring(0, url.Length - 1); return url; } } diff --git a/src/Merge.Client/Core/RequestOptions.cs b/src/Merge.Client/Core/RequestOptions.cs new file mode 100644 index 00000000..41bf550d --- /dev/null +++ b/src/Merge.Client/Core/RequestOptions.cs @@ -0,0 +1,29 @@ +using System; +using System.Net.Http; + +#nullable enable + +namespace Merge.Client.Core; + +public partial class RequestOptions +{ + /// + /// The Base URL for the API. + /// + public string? BaseUrl { get; init; } + + /// + /// The http client used to make requests. + /// + public HttpClient? HttpClient { get; init; } + + /// + /// The http client used to make requests. + /// + public int? MaxRetries { get; init; } + + /// + /// The timeout for the request. + /// + public TimeSpan? Timeout { get; init; } +} diff --git a/src/Merge.Client/Core/StringEnumSerializer.cs b/src/Merge.Client/Core/StringEnumSerializer.cs index 1e8e72e1..5a7f7e6b 100644 --- a/src/Merge.Client/Core/StringEnumSerializer.cs +++ b/src/Merge.Client/Core/StringEnumSerializer.cs @@ -2,55 +2,48 @@ using System.Text.Json; using System.Text.Json.Serialization; -namespace Merge.Client; +namespace Merge.Client.Core; public class StringEnumSerializer : JsonConverter where TEnum : struct, System.Enum { - private readonly Dictionary _enumToString = new Dictionary(); - private readonly Dictionary _stringToEnum = new Dictionary(); + private readonly Dictionary _enumToString = new(); + private readonly Dictionary _stringToEnum = new(); public StringEnumSerializer() { var type = typeof(TEnum); - var values = System.Enum.GetValues(); + var values = Enum.GetValues(type); foreach (var value in values) { - var enumMember = type.GetMember(value.ToString())[0]; + var enumValue = (TEnum)value; + var enumMember = type.GetMember(enumValue.ToString())[0]; var attr = enumMember .GetCustomAttributes(typeof(EnumMemberAttribute), false) .Cast() .FirstOrDefault(); - _stringToEnum.Add(value.ToString(), value); - - if (attr?.Value != null) - { - _enumToString.Add(value, attr.Value); - _stringToEnum.Add(attr.Value, value); - } - else - { - _enumToString.Add(value, value.ToString()); - } + var stringValue = + attr?.Value + ?? value.ToString() + ?? throw new Exception("Unexpected null enum toString value"); + + _enumToString.Add(enumValue, stringValue); + _stringToEnum.Add(stringValue, enumValue); } } public override TEnum Read( ref Utf8JsonReader reader, - Type typeToConvert, + System.Type typeToConvert, JsonSerializerOptions options ) { - var stringValue = reader.GetString(); - - if (_stringToEnum.TryGetValue(stringValue, out var enumValue)) - { - return enumValue; - } - - return default; + var stringValue = + reader.GetString() + ?? throw new Exception("The JSON value could not be read as a string."); + return _stringToEnum.TryGetValue(stringValue, out var enumValue) ? enumValue : default; } public override void Write(Utf8JsonWriter writer, TEnum value, JsonSerializerOptions options) diff --git a/src/Merge.Client/Crm/AccountDetails/AccountDetailsClient.cs b/src/Merge.Client/Crm/AccountDetails/AccountDetailsClient.cs index 88678902..b5febfdd 100644 --- a/src/Merge.Client/Crm/AccountDetails/AccountDetailsClient.cs +++ b/src/Merge.Client/Crm/AccountDetails/AccountDetailsClient.cs @@ -1,6 +1,6 @@ +using System.Net.Http; using System.Text.Json; -using Merge.Client; -using Merge.Client.Crm; +using Merge.Client.Core; #nullable enable @@ -18,20 +18,34 @@ public AccountDetailsClient(RawClient client) /// /// Get details for a linked account. /// - public async Task RetrieveAsync() + public async Task RetrieveAsync(RequestOptions? options = null) { var response = await _client.MakeRequestAsync( new RawClient.JsonApiRequest { + BaseUrl = _client.Options.BaseUrl, Method = HttpMethod.Get, - Path = "crm/v1/account-details" + Path = "crm/v1/account-details", + Options = options } ); - string responseBody = await response.Raw.Content.ReadAsStringAsync(); - if (response.StatusCode >= 200 && response.StatusCode < 400) + var responseBody = await response.Raw.Content.ReadAsStringAsync(); + if (response.StatusCode is >= 200 and < 400) { - return JsonSerializer.Deserialize(responseBody); + try + { + return JsonUtils.Deserialize(responseBody)!; + } + catch (JsonException e) + { + throw new MergeException("Failed to deserialize response", e); + } } - throw new Exception(responseBody); + + throw new MergeApiException( + $"Error with status code {response.StatusCode}", + response.StatusCode, + JsonUtils.Deserialize(responseBody) + ); } } diff --git a/src/Merge.Client/Crm/AccountToken/AccountTokenClient.cs b/src/Merge.Client/Crm/AccountToken/AccountTokenClient.cs index fb8cd263..7ade166d 100644 --- a/src/Merge.Client/Crm/AccountToken/AccountTokenClient.cs +++ b/src/Merge.Client/Crm/AccountToken/AccountTokenClient.cs @@ -1,6 +1,6 @@ +using System.Net.Http; using System.Text.Json; -using Merge.Client; -using Merge.Client.Crm; +using Merge.Client.Core; #nullable enable @@ -18,20 +18,37 @@ public AccountTokenClient(RawClient client) /// /// Returns the account token for the end user with the provided public token. /// - public async Task RetrieveAsync(string publicToken) + public async Task RetrieveAsync( + string publicToken, + RequestOptions? options = null + ) { var response = await _client.MakeRequestAsync( new RawClient.JsonApiRequest { + BaseUrl = _client.Options.BaseUrl, Method = HttpMethod.Get, - Path = $"crm/v1/account-token/{publicToken}" + Path = $"crm/v1/account-token/{publicToken}", + Options = options } ); - string responseBody = await response.Raw.Content.ReadAsStringAsync(); - if (response.StatusCode >= 200 && response.StatusCode < 400) + var responseBody = await response.Raw.Content.ReadAsStringAsync(); + if (response.StatusCode is >= 200 and < 400) { - return JsonSerializer.Deserialize(responseBody); + try + { + return JsonUtils.Deserialize(responseBody)!; + } + catch (JsonException e) + { + throw new MergeException("Failed to deserialize response", e); + } } - throw new Exception(responseBody); + + throw new MergeApiException( + $"Error with status code {response.StatusCode}", + response.StatusCode, + JsonUtils.Deserialize(responseBody) + ); } } diff --git a/src/Merge.Client/Crm/Accounts/AccountsClient.cs b/src/Merge.Client/Crm/Accounts/AccountsClient.cs index c5fac7a2..39ab9075 100644 --- a/src/Merge.Client/Crm/Accounts/AccountsClient.cs +++ b/src/Merge.Client/Crm/Accounts/AccountsClient.cs @@ -1,6 +1,6 @@ +using System.Net.Http; using System.Text.Json; -using Merge.Client; -using Merge.Client.Crm; +using Merge.Client.Core; #nullable enable @@ -18,16 +18,21 @@ public AccountsClient(RawClient client) /// /// Returns a list of `Account` objects. /// - public async Task ListAsync(AccountsListRequest request) + public async Task ListAsync( + AccountsListRequest request, + RequestOptions? options = null + ) { var _query = new Dictionary() { }; if (request.CreatedAfter != null) { - _query["created_after"] = request.CreatedAfter.Value.ToString("o0"); + _query["created_after"] = request.CreatedAfter.Value.ToString(Constants.DateTimeFormat); } if (request.CreatedBefore != null) { - _query["created_before"] = request.CreatedBefore.Value.ToString("o0"); + _query["created_before"] = request.CreatedBefore.Value.ToString( + Constants.DateTimeFormat + ); } if (request.Cursor != null) { @@ -51,11 +56,15 @@ public async Task ListAsync(AccountsListRequest request) } if (request.ModifiedAfter != null) { - _query["modified_after"] = request.ModifiedAfter.Value.ToString("o0"); + _query["modified_after"] = request.ModifiedAfter.Value.ToString( + Constants.DateTimeFormat + ); } if (request.ModifiedBefore != null) { - _query["modified_before"] = request.ModifiedBefore.Value.ToString("o0"); + _query["modified_before"] = request.ModifiedBefore.Value.ToString( + Constants.DateTimeFormat + ); } if (request.Name != null) { @@ -76,23 +85,40 @@ public async Task ListAsync(AccountsListRequest request) var response = await _client.MakeRequestAsync( new RawClient.JsonApiRequest { + BaseUrl = _client.Options.BaseUrl, Method = HttpMethod.Get, Path = "crm/v1/accounts", - Query = _query + Query = _query, + Options = options } ); - string responseBody = await response.Raw.Content.ReadAsStringAsync(); - if (response.StatusCode >= 200 && response.StatusCode < 400) + var responseBody = await response.Raw.Content.ReadAsStringAsync(); + if (response.StatusCode is >= 200 and < 400) { - return JsonSerializer.Deserialize(responseBody); + try + { + return JsonUtils.Deserialize(responseBody)!; + } + catch (JsonException e) + { + throw new MergeException("Failed to deserialize response", e); + } } - throw new Exception(responseBody); + + throw new MergeApiException( + $"Error with status code {response.StatusCode}", + response.StatusCode, + JsonUtils.Deserialize(responseBody) + ); } /// /// Creates an `Account` object with the given values. /// - public async Task CreateAsync(CrmAccountEndpointRequest request) + public async Task CreateAsync( + CrmAccountEndpointRequest request, + RequestOptions? options = null + ) { var _query = new Dictionary() { }; if (request.IsDebugMode != null) @@ -106,23 +132,41 @@ public async Task CreateAsync(CrmAccountEndpointRequest requ var response = await _client.MakeRequestAsync( new RawClient.JsonApiRequest { + BaseUrl = _client.Options.BaseUrl, Method = HttpMethod.Post, Path = "crm/v1/accounts", - Query = _query + Query = _query, + Options = options } ); - string responseBody = await response.Raw.Content.ReadAsStringAsync(); - if (response.StatusCode >= 200 && response.StatusCode < 400) + var responseBody = await response.Raw.Content.ReadAsStringAsync(); + if (response.StatusCode is >= 200 and < 400) { - return JsonSerializer.Deserialize(responseBody); + try + { + return JsonUtils.Deserialize(responseBody)!; + } + catch (JsonException e) + { + throw new MergeException("Failed to deserialize response", e); + } } - throw new Exception(responseBody); + + throw new MergeApiException( + $"Error with status code {response.StatusCode}", + response.StatusCode, + JsonUtils.Deserialize(responseBody) + ); } /// /// Returns an `Account` object with the given `id`. /// - public async Task RetrieveAsync(string id, AccountsRetrieveRequest request) + public async Task RetrieveAsync( + string id, + AccountsRetrieveRequest request, + RequestOptions? options = null + ) { var _query = new Dictionary() { }; if (request.Expand != null) @@ -140,17 +184,31 @@ public async Task RetrieveAsync(string id, AccountsRetrieveRequest requ var response = await _client.MakeRequestAsync( new RawClient.JsonApiRequest { + BaseUrl = _client.Options.BaseUrl, Method = HttpMethod.Get, Path = $"crm/v1/accounts/{id}", - Query = _query + Query = _query, + Options = options } ); - string responseBody = await response.Raw.Content.ReadAsStringAsync(); - if (response.StatusCode >= 200 && response.StatusCode < 400) + var responseBody = await response.Raw.Content.ReadAsStringAsync(); + if (response.StatusCode is >= 200 and < 400) { - return JsonSerializer.Deserialize(responseBody); + try + { + return JsonUtils.Deserialize(responseBody)!; + } + catch (JsonException e) + { + throw new MergeException("Failed to deserialize response", e); + } } - throw new Exception(responseBody); + + throw new MergeApiException( + $"Error with status code {response.StatusCode}", + response.StatusCode, + JsonUtils.Deserialize(responseBody) + ); } /// @@ -158,7 +216,8 @@ public async Task RetrieveAsync(string id, AccountsRetrieveRequest requ /// public async Task PartialUpdateAsync( string id, - PatchedCrmAccountEndpointRequest request + PatchedCrmAccountEndpointRequest request, + RequestOptions? options = null ) { var _query = new Dictionary() { }; @@ -173,64 +232,110 @@ PatchedCrmAccountEndpointRequest request var response = await _client.MakeRequestAsync( new RawClient.JsonApiRequest { - Method = HttpMethod.Patch, + BaseUrl = _client.Options.BaseUrl, + Method = HttpMethodExtensions.Patch, Path = $"crm/v1/accounts/{id}", - Query = _query + Query = _query, + Options = options } ); - string responseBody = await response.Raw.Content.ReadAsStringAsync(); - if (response.StatusCode >= 200 && response.StatusCode < 400) + var responseBody = await response.Raw.Content.ReadAsStringAsync(); + if (response.StatusCode is >= 200 and < 400) { - return JsonSerializer.Deserialize(responseBody); + try + { + return JsonUtils.Deserialize(responseBody)!; + } + catch (JsonException e) + { + throw new MergeException("Failed to deserialize response", e); + } } - throw new Exception(responseBody); + + throw new MergeApiException( + $"Error with status code {response.StatusCode}", + response.StatusCode, + JsonUtils.Deserialize(responseBody) + ); } /// /// Returns metadata for `CRMAccount` PATCHs. /// - public async Task MetaPatchRetrieveAsync(string id) + public async Task MetaPatchRetrieveAsync( + string id, + RequestOptions? options = null + ) { var response = await _client.MakeRequestAsync( new RawClient.JsonApiRequest { + BaseUrl = _client.Options.BaseUrl, Method = HttpMethod.Get, - Path = $"crm/v1/accounts/meta/patch/{id}" + Path = $"crm/v1/accounts/meta/patch/{id}", + Options = options } ); - string responseBody = await response.Raw.Content.ReadAsStringAsync(); - if (response.StatusCode >= 200 && response.StatusCode < 400) + var responseBody = await response.Raw.Content.ReadAsStringAsync(); + if (response.StatusCode is >= 200 and < 400) { - return JsonSerializer.Deserialize(responseBody); + try + { + return JsonUtils.Deserialize(responseBody)!; + } + catch (JsonException e) + { + throw new MergeException("Failed to deserialize response", e); + } } - throw new Exception(responseBody); + + throw new MergeApiException( + $"Error with status code {response.StatusCode}", + response.StatusCode, + JsonUtils.Deserialize(responseBody) + ); } /// /// Returns metadata for `CRMAccount` POSTs. /// - public async Task MetaPostRetrieveAsync() + public async Task MetaPostRetrieveAsync(RequestOptions? options = null) { var response = await _client.MakeRequestAsync( new RawClient.JsonApiRequest { + BaseUrl = _client.Options.BaseUrl, Method = HttpMethod.Get, - Path = "crm/v1/accounts/meta/post" + Path = "crm/v1/accounts/meta/post", + Options = options } ); - string responseBody = await response.Raw.Content.ReadAsStringAsync(); - if (response.StatusCode >= 200 && response.StatusCode < 400) + var responseBody = await response.Raw.Content.ReadAsStringAsync(); + if (response.StatusCode is >= 200 and < 400) { - return JsonSerializer.Deserialize(responseBody); + try + { + return JsonUtils.Deserialize(responseBody)!; + } + catch (JsonException e) + { + throw new MergeException("Failed to deserialize response", e); + } } - throw new Exception(responseBody); + + throw new MergeApiException( + $"Error with status code {response.StatusCode}", + response.StatusCode, + JsonUtils.Deserialize(responseBody) + ); } /// /// Returns a list of `RemoteFieldClass` objects. /// public async Task RemoteFieldClassesListAsync( - AccountsRemoteFieldClassesListRequest request + AccountsRemoteFieldClassesListRequest request, + RequestOptions? options = null ) { var _query = new Dictionary() { }; @@ -261,16 +366,30 @@ AccountsRemoteFieldClassesListRequest request var response = await _client.MakeRequestAsync( new RawClient.JsonApiRequest { + BaseUrl = _client.Options.BaseUrl, Method = HttpMethod.Get, Path = "crm/v1/accounts/remote-field-classes", - Query = _query + Query = _query, + Options = options } ); - string responseBody = await response.Raw.Content.ReadAsStringAsync(); - if (response.StatusCode >= 200 && response.StatusCode < 400) + var responseBody = await response.Raw.Content.ReadAsStringAsync(); + if (response.StatusCode is >= 200 and < 400) { - return JsonSerializer.Deserialize(responseBody); + try + { + return JsonUtils.Deserialize(responseBody)!; + } + catch (JsonException e) + { + throw new MergeException("Failed to deserialize response", e); + } } - throw new Exception(responseBody); + + throw new MergeApiException( + $"Error with status code {response.StatusCode}", + response.StatusCode, + JsonUtils.Deserialize(responseBody) + ); } } diff --git a/src/Merge.Client/Crm/Accounts/Requests/AccountsListRequest.cs b/src/Merge.Client/Crm/Accounts/Requests/AccountsListRequest.cs index cf06caa4..76e9804b 100644 --- a/src/Merge.Client/Crm/Accounts/Requests/AccountsListRequest.cs +++ b/src/Merge.Client/Crm/Accounts/Requests/AccountsListRequest.cs @@ -1,69 +1,69 @@ namespace Merge.Client.Crm; -public class AccountsListRequest +public record AccountsListRequest { /// /// If provided, will only return objects created after this datetime. /// - public DateTime? CreatedAfter { get; init; } + public DateTime? CreatedAfter { get; set; } /// /// If provided, will only return objects created before this datetime. /// - public DateTime? CreatedBefore { get; init; } + public DateTime? CreatedBefore { get; set; } /// /// The pagination cursor value. /// - public string? Cursor { get; init; } + public string? Cursor { get; set; } /// /// Which relations should be returned in expanded form. Multiple relation names should be comma separated without spaces. /// - public string? Expand { get; init; } + public string? Expand { get; set; } /// /// Whether to include data that was marked as deleted by third party webhooks. /// - public bool? IncludeDeletedData { get; init; } + public bool? IncludeDeletedData { get; set; } /// /// Whether to include the original data Merge fetched from the third-party to produce these models. /// - public bool? IncludeRemoteData { get; init; } + public bool? IncludeRemoteData { get; set; } /// /// Whether to include all remote fields, including fields that Merge did not map to common models, in a normalized format. /// - public bool? IncludeRemoteFields { get; init; } + public bool? IncludeRemoteFields { get; set; } /// /// If provided, only objects synced by Merge after this date time will be returned. /// - public DateTime? ModifiedAfter { get; init; } + public DateTime? ModifiedAfter { get; set; } /// /// If provided, only objects synced by Merge before this date time will be returned. /// - public DateTime? ModifiedBefore { get; init; } + public DateTime? ModifiedBefore { get; set; } /// /// If provided, will only return accounts with this name. /// - public string? Name { get; init; } + public string? Name { get; set; } /// /// If provided, will only return accounts with this owner. /// - public string? OwnerId { get; init; } + public string? OwnerId { get; set; } /// /// Number of results to return per page. /// - public int? PageSize { get; init; } + public int? PageSize { get; set; } /// /// The API provider's ID for the given object. /// - public string? RemoteId { get; init; } + public string? RemoteId { get; set; } } diff --git a/src/Merge.Client/Crm/Accounts/Requests/AccountsRemoteFieldClassesListRequest.cs b/src/Merge.Client/Crm/Accounts/Requests/AccountsRemoteFieldClassesListRequest.cs index fc7ad298..4795472b 100644 --- a/src/Merge.Client/Crm/Accounts/Requests/AccountsRemoteFieldClassesListRequest.cs +++ b/src/Merge.Client/Crm/Accounts/Requests/AccountsRemoteFieldClassesListRequest.cs @@ -1,34 +1,34 @@ namespace Merge.Client.Crm; -public class AccountsRemoteFieldClassesListRequest +public record AccountsRemoteFieldClassesListRequest { /// /// The pagination cursor value. /// - public string? Cursor { get; init; } + public string? Cursor { get; set; } /// /// Whether to include data that was marked as deleted by third party webhooks. /// - public bool? IncludeDeletedData { get; init; } + public bool? IncludeDeletedData { get; set; } /// /// Whether to include the original data Merge fetched from the third-party to produce these models. /// - public bool? IncludeRemoteData { get; init; } + public bool? IncludeRemoteData { get; set; } /// /// Whether to include all remote fields, including fields that Merge did not map to common models, in a normalized format. /// - public bool? IncludeRemoteFields { get; init; } + public bool? IncludeRemoteFields { get; set; } /// /// If provided, will only return remote field classes with this is_common_model_field value /// - public bool? IsCommonModelField { get; init; } + public bool? IsCommonModelField { get; set; } /// /// Number of results to return per page. /// - public int? PageSize { get; init; } + public int? PageSize { get; set; } } diff --git a/src/Merge.Client/Crm/Accounts/Requests/AccountsRetrieveRequest.cs b/src/Merge.Client/Crm/Accounts/Requests/AccountsRetrieveRequest.cs index 70bf5d67..f879a41a 100644 --- a/src/Merge.Client/Crm/Accounts/Requests/AccountsRetrieveRequest.cs +++ b/src/Merge.Client/Crm/Accounts/Requests/AccountsRetrieveRequest.cs @@ -1,19 +1,19 @@ namespace Merge.Client.Crm; -public class AccountsRetrieveRequest +public record AccountsRetrieveRequest { /// /// Which relations should be returned in expanded form. Multiple relation names should be comma separated without spaces. /// - public string? Expand { get; init; } + public string? Expand { get; set; } /// /// Whether to include the original data Merge fetched from the third-party to produce these models. /// - public bool? IncludeRemoteData { get; init; } + public bool? IncludeRemoteData { get; set; } /// /// Whether to include all remote fields, including fields that Merge did not map to common models, in a normalized format. /// - public bool? IncludeRemoteFields { get; init; } + public bool? IncludeRemoteFields { get; set; } } diff --git a/src/Merge.Client/Crm/Accounts/Requests/CrmAccountEndpointRequest.cs b/src/Merge.Client/Crm/Accounts/Requests/CrmAccountEndpointRequest.cs index 95f5b9bf..44e0e722 100644 --- a/src/Merge.Client/Crm/Accounts/Requests/CrmAccountEndpointRequest.cs +++ b/src/Merge.Client/Crm/Accounts/Requests/CrmAccountEndpointRequest.cs @@ -1,20 +1,16 @@ -using Merge.Client.Crm; - -#nullable enable - namespace Merge.Client.Crm; -public class CrmAccountEndpointRequest +public record CrmAccountEndpointRequest { /// /// Whether to include debug fields (such as log file links) in the response. /// - public bool? IsDebugMode { get; init; } + public bool? IsDebugMode { get; set; } /// /// Whether or not third-party updates should be run asynchronously. /// - public bool? RunAsync { get; init; } + public bool? RunAsync { get; set; } - public AccountRequest Model { get; init; } + public required AccountRequest Model { get; set; } } diff --git a/src/Merge.Client/Crm/Accounts/Requests/PatchedCrmAccountEndpointRequest.cs b/src/Merge.Client/Crm/Accounts/Requests/PatchedCrmAccountEndpointRequest.cs index 1adb37e1..de98f9bc 100644 --- a/src/Merge.Client/Crm/Accounts/Requests/PatchedCrmAccountEndpointRequest.cs +++ b/src/Merge.Client/Crm/Accounts/Requests/PatchedCrmAccountEndpointRequest.cs @@ -1,20 +1,16 @@ -using Merge.Client.Crm; - -#nullable enable - namespace Merge.Client.Crm; -public class PatchedCrmAccountEndpointRequest +public record PatchedCrmAccountEndpointRequest { /// /// Whether to include debug fields (such as log file links) in the response. /// - public bool? IsDebugMode { get; init; } + public bool? IsDebugMode { get; set; } /// /// Whether or not third-party updates should be run asynchronously. /// - public bool? RunAsync { get; init; } + public bool? RunAsync { get; set; } - public PatchedAccountRequest Model { get; init; } + public required PatchedAccountRequest Model { get; set; } } diff --git a/src/Merge.Client/Crm/AssociationTypes/AssociationTypesClient.cs b/src/Merge.Client/Crm/AssociationTypes/AssociationTypesClient.cs index 147b43ab..efa5b8de 100644 --- a/src/Merge.Client/Crm/AssociationTypes/AssociationTypesClient.cs +++ b/src/Merge.Client/Crm/AssociationTypes/AssociationTypesClient.cs @@ -1,6 +1,6 @@ +using System.Net.Http; using System.Text.Json; -using Merge.Client; -using Merge.Client.Crm; +using Merge.Client.Core; #nullable enable @@ -20,17 +20,20 @@ public AssociationTypesClient(RawClient client) /// public async Task CustomObjectClassesAssociationTypesListAsync( string customObjectClassId, - CustomObjectClassesAssociationTypesListRequest request + CustomObjectClassesAssociationTypesListRequest request, + RequestOptions? options = null ) { var _query = new Dictionary() { }; if (request.CreatedAfter != null) { - _query["created_after"] = request.CreatedAfter.Value.ToString("o0"); + _query["created_after"] = request.CreatedAfter.Value.ToString(Constants.DateTimeFormat); } if (request.CreatedBefore != null) { - _query["created_before"] = request.CreatedBefore.Value.ToString("o0"); + _query["created_before"] = request.CreatedBefore.Value.ToString( + Constants.DateTimeFormat + ); } if (request.Cursor != null) { @@ -50,11 +53,15 @@ CustomObjectClassesAssociationTypesListRequest request } if (request.ModifiedAfter != null) { - _query["modified_after"] = request.ModifiedAfter.Value.ToString("o0"); + _query["modified_after"] = request.ModifiedAfter.Value.ToString( + Constants.DateTimeFormat + ); } if (request.ModifiedBefore != null) { - _query["modified_before"] = request.ModifiedBefore.Value.ToString("o0"); + _query["modified_before"] = request.ModifiedBefore.Value.ToString( + Constants.DateTimeFormat + ); } if (request.PageSize != null) { @@ -67,17 +74,31 @@ CustomObjectClassesAssociationTypesListRequest request var response = await _client.MakeRequestAsync( new RawClient.JsonApiRequest { + BaseUrl = _client.Options.BaseUrl, Method = HttpMethod.Get, Path = $"crm/v1/custom-object-classes/{customObjectClassId}/association-types", - Query = _query + Query = _query, + Options = options } ); - string responseBody = await response.Raw.Content.ReadAsStringAsync(); - if (response.StatusCode >= 200 && response.StatusCode < 400) + var responseBody = await response.Raw.Content.ReadAsStringAsync(); + if (response.StatusCode is >= 200 and < 400) { - return JsonSerializer.Deserialize(responseBody); + try + { + return JsonUtils.Deserialize(responseBody)!; + } + catch (JsonException e) + { + throw new MergeException("Failed to deserialize response", e); + } } - throw new Exception(responseBody); + + throw new MergeApiException( + $"Error with status code {response.StatusCode}", + response.StatusCode, + JsonUtils.Deserialize(responseBody) + ); } /// @@ -85,7 +106,8 @@ CustomObjectClassesAssociationTypesListRequest request /// public async Task CustomObjectClassesAssociationTypesCreateAsync( string customObjectClassId, - CrmAssociationTypeEndpointRequest request + CrmAssociationTypeEndpointRequest request, + RequestOptions? options = null ) { var _query = new Dictionary() { }; @@ -100,17 +122,31 @@ CrmAssociationTypeEndpointRequest request var response = await _client.MakeRequestAsync( new RawClient.JsonApiRequest { + BaseUrl = _client.Options.BaseUrl, Method = HttpMethod.Post, Path = $"crm/v1/custom-object-classes/{customObjectClassId}/association-types", - Query = _query + Query = _query, + Options = options } ); - string responseBody = await response.Raw.Content.ReadAsStringAsync(); - if (response.StatusCode >= 200 && response.StatusCode < 400) + var responseBody = await response.Raw.Content.ReadAsStringAsync(); + if (response.StatusCode is >= 200 and < 400) { - return JsonSerializer.Deserialize(responseBody); + try + { + return JsonUtils.Deserialize(responseBody)!; + } + catch (JsonException e) + { + throw new MergeException("Failed to deserialize response", e); + } } - throw new Exception(responseBody); + + throw new MergeApiException( + $"Error with status code {response.StatusCode}", + response.StatusCode, + JsonUtils.Deserialize(responseBody) + ); } /// @@ -119,7 +155,8 @@ CrmAssociationTypeEndpointRequest request public async Task CustomObjectClassesAssociationTypesRetrieveAsync( string customObjectClassId, string id, - CustomObjectClassesAssociationTypesRetrieveRequest request + CustomObjectClassesAssociationTypesRetrieveRequest request, + RequestOptions? options = null ) { var _query = new Dictionary() { }; @@ -134,39 +171,68 @@ CustomObjectClassesAssociationTypesRetrieveRequest request var response = await _client.MakeRequestAsync( new RawClient.JsonApiRequest { + BaseUrl = _client.Options.BaseUrl, Method = HttpMethod.Get, Path = $"crm/v1/custom-object-classes/{customObjectClassId}/association-types/{id}", - Query = _query + Query = _query, + Options = options } ); - string responseBody = await response.Raw.Content.ReadAsStringAsync(); - if (response.StatusCode >= 200 && response.StatusCode < 400) + var responseBody = await response.Raw.Content.ReadAsStringAsync(); + if (response.StatusCode is >= 200 and < 400) { - return JsonSerializer.Deserialize(responseBody); + try + { + return JsonUtils.Deserialize(responseBody)!; + } + catch (JsonException e) + { + throw new MergeException("Failed to deserialize response", e); + } } - throw new Exception(responseBody); + + throw new MergeApiException( + $"Error with status code {response.StatusCode}", + response.StatusCode, + JsonUtils.Deserialize(responseBody) + ); } /// /// Returns metadata for `CRMAssociationType` POSTs. /// public async Task CustomObjectClassesAssociationTypesMetaPostRetrieveAsync( - string customObjectClassId + string customObjectClassId, + RequestOptions? options = null ) { var response = await _client.MakeRequestAsync( new RawClient.JsonApiRequest { + BaseUrl = _client.Options.BaseUrl, Method = HttpMethod.Get, Path = - $"crm/v1/custom-object-classes/{customObjectClassId}/association-types/meta/post" + $"crm/v1/custom-object-classes/{customObjectClassId}/association-types/meta/post", + Options = options } ); - string responseBody = await response.Raw.Content.ReadAsStringAsync(); - if (response.StatusCode >= 200 && response.StatusCode < 400) + var responseBody = await response.Raw.Content.ReadAsStringAsync(); + if (response.StatusCode is >= 200 and < 400) { - return JsonSerializer.Deserialize(responseBody); + try + { + return JsonUtils.Deserialize(responseBody)!; + } + catch (JsonException e) + { + throw new MergeException("Failed to deserialize response", e); + } } - throw new Exception(responseBody); + + throw new MergeApiException( + $"Error with status code {response.StatusCode}", + response.StatusCode, + JsonUtils.Deserialize(responseBody) + ); } } diff --git a/src/Merge.Client/Crm/AssociationTypes/Requests/CrmAssociationTypeEndpointRequest.cs b/src/Merge.Client/Crm/AssociationTypes/Requests/CrmAssociationTypeEndpointRequest.cs index b76e6980..26c5b438 100644 --- a/src/Merge.Client/Crm/AssociationTypes/Requests/CrmAssociationTypeEndpointRequest.cs +++ b/src/Merge.Client/Crm/AssociationTypes/Requests/CrmAssociationTypeEndpointRequest.cs @@ -1,20 +1,16 @@ -using Merge.Client.Crm; - -#nullable enable - namespace Merge.Client.Crm; -public class CrmAssociationTypeEndpointRequest +public record CrmAssociationTypeEndpointRequest { /// /// Whether to include debug fields (such as log file links) in the response. /// - public bool? IsDebugMode { get; init; } + public bool? IsDebugMode { get; set; } /// /// Whether or not third-party updates should be run asynchronously. /// - public bool? RunAsync { get; init; } + public bool? RunAsync { get; set; } - public AssociationTypeRequestRequest Model { get; init; } + public required AssociationTypeRequestRequest Model { get; set; } } diff --git a/src/Merge.Client/Crm/AssociationTypes/Requests/CustomObjectClassesAssociationTypesListRequest.cs b/src/Merge.Client/Crm/AssociationTypes/Requests/CustomObjectClassesAssociationTypesListRequest.cs index 0f2f6391..0e2f2d87 100644 --- a/src/Merge.Client/Crm/AssociationTypes/Requests/CustomObjectClassesAssociationTypesListRequest.cs +++ b/src/Merge.Client/Crm/AssociationTypes/Requests/CustomObjectClassesAssociationTypesListRequest.cs @@ -1,54 +1,54 @@ namespace Merge.Client.Crm; -public class CustomObjectClassesAssociationTypesListRequest +public record CustomObjectClassesAssociationTypesListRequest { /// /// If provided, will only return objects created after this datetime. /// - public DateTime? CreatedAfter { get; init; } + public DateTime? CreatedAfter { get; set; } /// /// If provided, will only return objects created before this datetime. /// - public DateTime? CreatedBefore { get; init; } + public DateTime? CreatedBefore { get; set; } /// /// The pagination cursor value. /// - public string? Cursor { get; init; } + public string? Cursor { get; set; } /// /// Which relations should be returned in expanded form. Multiple relation names should be comma separated without spaces. /// - public string? Expand { get; init; } + public string? Expand { get; set; } /// /// Whether to include data that was marked as deleted by third party webhooks. /// - public bool? IncludeDeletedData { get; init; } + public bool? IncludeDeletedData { get; set; } /// /// Whether to include the original data Merge fetched from the third-party to produce these models. /// - public bool? IncludeRemoteData { get; init; } + public bool? IncludeRemoteData { get; set; } /// /// If provided, only objects synced by Merge after this date time will be returned. /// - public DateTime? ModifiedAfter { get; init; } + public DateTime? ModifiedAfter { get; set; } /// /// If provided, only objects synced by Merge before this date time will be returned. /// - public DateTime? ModifiedBefore { get; init; } + public DateTime? ModifiedBefore { get; set; } /// /// Number of results to return per page. /// - public int? PageSize { get; init; } + public int? PageSize { get; set; } /// /// The API provider's ID for the given object. /// - public string? RemoteId { get; init; } + public string? RemoteId { get; set; } } diff --git a/src/Merge.Client/Crm/AssociationTypes/Requests/CustomObjectClassesAssociationTypesRetrieveRequest.cs b/src/Merge.Client/Crm/AssociationTypes/Requests/CustomObjectClassesAssociationTypesRetrieveRequest.cs index 4880361b..42310325 100644 --- a/src/Merge.Client/Crm/AssociationTypes/Requests/CustomObjectClassesAssociationTypesRetrieveRequest.cs +++ b/src/Merge.Client/Crm/AssociationTypes/Requests/CustomObjectClassesAssociationTypesRetrieveRequest.cs @@ -1,14 +1,14 @@ namespace Merge.Client.Crm; -public class CustomObjectClassesAssociationTypesRetrieveRequest +public record CustomObjectClassesAssociationTypesRetrieveRequest { /// /// Which relations should be returned in expanded form. Multiple relation names should be comma separated without spaces. /// - public string? Expand { get; init; } + public string? Expand { get; set; } /// /// Whether to include the original data Merge fetched from the third-party to produce these models. /// - public bool? IncludeRemoteData { get; init; } + public bool? IncludeRemoteData { get; set; } } diff --git a/src/Merge.Client/Crm/Associations/AssociationsClient.cs b/src/Merge.Client/Crm/Associations/AssociationsClient.cs index 4800ffd2..f333c69b 100644 --- a/src/Merge.Client/Crm/Associations/AssociationsClient.cs +++ b/src/Merge.Client/Crm/Associations/AssociationsClient.cs @@ -1,6 +1,6 @@ +using System.Net.Http; using System.Text.Json; -using Merge.Client; -using Merge.Client.Crm; +using Merge.Client.Core; #nullable enable @@ -21,7 +21,8 @@ public AssociationsClient(RawClient client) public async Task CustomObjectClassesCustomObjectsAssociationsListAsync( string customObjectClassId, string objectId, - CustomObjectClassesCustomObjectsAssociationsListRequest request + CustomObjectClassesCustomObjectsAssociationsListRequest request, + RequestOptions? options = null ) { var _query = new Dictionary() { }; @@ -31,11 +32,13 @@ CustomObjectClassesCustomObjectsAssociationsListRequest request } if (request.CreatedAfter != null) { - _query["created_after"] = request.CreatedAfter.Value.ToString("o0"); + _query["created_after"] = request.CreatedAfter.Value.ToString(Constants.DateTimeFormat); } if (request.CreatedBefore != null) { - _query["created_before"] = request.CreatedBefore.Value.ToString("o0"); + _query["created_before"] = request.CreatedBefore.Value.ToString( + Constants.DateTimeFormat + ); } if (request.Cursor != null) { @@ -55,11 +58,15 @@ CustomObjectClassesCustomObjectsAssociationsListRequest request } if (request.ModifiedAfter != null) { - _query["modified_after"] = request.ModifiedAfter.Value.ToString("o0"); + _query["modified_after"] = request.ModifiedAfter.Value.ToString( + Constants.DateTimeFormat + ); } if (request.ModifiedBefore != null) { - _query["modified_before"] = request.ModifiedBefore.Value.ToString("o0"); + _query["modified_before"] = request.ModifiedBefore.Value.ToString( + Constants.DateTimeFormat + ); } if (request.PageSize != null) { @@ -72,18 +79,32 @@ CustomObjectClassesCustomObjectsAssociationsListRequest request var response = await _client.MakeRequestAsync( new RawClient.JsonApiRequest { + BaseUrl = _client.Options.BaseUrl, Method = HttpMethod.Get, Path = $"crm/v1/custom-object-classes/{customObjectClassId}/custom-objects/{objectId}/associations", - Query = _query + Query = _query, + Options = options } ); - string responseBody = await response.Raw.Content.ReadAsStringAsync(); - if (response.StatusCode >= 200 && response.StatusCode < 400) + var responseBody = await response.Raw.Content.ReadAsStringAsync(); + if (response.StatusCode is >= 200 and < 400) { - return JsonSerializer.Deserialize(responseBody); + try + { + return JsonUtils.Deserialize(responseBody)!; + } + catch (JsonException e) + { + throw new MergeException("Failed to deserialize response", e); + } } - throw new Exception(responseBody); + + throw new MergeApiException( + $"Error with status code {response.StatusCode}", + response.StatusCode, + JsonUtils.Deserialize(responseBody) + ); } /// @@ -95,7 +116,8 @@ public async Task CustomObjectClassesCustomObjectsAssociationsUpdat string sourceObjectId, string targetClassId, string targetObjectId, - CustomObjectClassesCustomObjectsAssociationsUpdateRequest request + CustomObjectClassesCustomObjectsAssociationsUpdateRequest request, + RequestOptions? options = null ) { var _query = new Dictionary() { }; @@ -110,17 +132,31 @@ CustomObjectClassesCustomObjectsAssociationsUpdateRequest request var response = await _client.MakeRequestAsync( new RawClient.JsonApiRequest { + BaseUrl = _client.Options.BaseUrl, Method = HttpMethod.Put, Path = $"crm/v1/custom-object-classes/{sourceClassId}/custom-objects/{sourceObjectId}/associations/{targetClassId}/{targetObjectId}/{associationTypeId}", - Query = _query + Query = _query, + Options = options } ); - string responseBody = await response.Raw.Content.ReadAsStringAsync(); - if (response.StatusCode >= 200 && response.StatusCode < 400) + var responseBody = await response.Raw.Content.ReadAsStringAsync(); + if (response.StatusCode is >= 200 and < 400) { - return JsonSerializer.Deserialize(responseBody); + try + { + return JsonUtils.Deserialize(responseBody)!; + } + catch (JsonException e) + { + throw new MergeException("Failed to deserialize response", e); + } } - throw new Exception(responseBody); + + throw new MergeApiException( + $"Error with status code {response.StatusCode}", + response.StatusCode, + JsonUtils.Deserialize(responseBody) + ); } } diff --git a/src/Merge.Client/Crm/Associations/Requests/CustomObjectClassesCustomObjectsAssociationsListRequest.cs b/src/Merge.Client/Crm/Associations/Requests/CustomObjectClassesCustomObjectsAssociationsListRequest.cs index c40ea342..b2ba25b1 100644 --- a/src/Merge.Client/Crm/Associations/Requests/CustomObjectClassesCustomObjectsAssociationsListRequest.cs +++ b/src/Merge.Client/Crm/Associations/Requests/CustomObjectClassesCustomObjectsAssociationsListRequest.cs @@ -1,59 +1,59 @@ namespace Merge.Client.Crm; -public class CustomObjectClassesCustomObjectsAssociationsListRequest +public record CustomObjectClassesCustomObjectsAssociationsListRequest { /// /// If provided, will only return opportunities with this association_type. /// - public string? AssociationTypeId { get; init; } + public string? AssociationTypeId { get; set; } /// /// If provided, will only return objects created after this datetime. /// - public DateTime? CreatedAfter { get; init; } + public DateTime? CreatedAfter { get; set; } /// /// If provided, will only return objects created before this datetime. /// - public DateTime? CreatedBefore { get; init; } + public DateTime? CreatedBefore { get; set; } /// /// The pagination cursor value. /// - public string? Cursor { get; init; } + public string? Cursor { get; set; } /// /// Which relations should be returned in expanded form. Multiple relation names should be comma separated without spaces. /// - public string? Expand { get; init; } + public string? Expand { get; set; } /// /// Whether to include data that was marked as deleted by third party webhooks. /// - public bool? IncludeDeletedData { get; init; } + public bool? IncludeDeletedData { get; set; } /// /// Whether to include the original data Merge fetched from the third-party to produce these models. /// - public bool? IncludeRemoteData { get; init; } + public bool? IncludeRemoteData { get; set; } /// /// If provided, only objects synced by Merge after this date time will be returned. /// - public DateTime? ModifiedAfter { get; init; } + public DateTime? ModifiedAfter { get; set; } /// /// If provided, only objects synced by Merge before this date time will be returned. /// - public DateTime? ModifiedBefore { get; init; } + public DateTime? ModifiedBefore { get; set; } /// /// Number of results to return per page. /// - public int? PageSize { get; init; } + public int? PageSize { get; set; } /// /// The API provider's ID for the given object. /// - public string? RemoteId { get; init; } + public string? RemoteId { get; set; } } diff --git a/src/Merge.Client/Crm/Associations/Requests/CustomObjectClassesCustomObjectsAssociationsUpdateRequest.cs b/src/Merge.Client/Crm/Associations/Requests/CustomObjectClassesCustomObjectsAssociationsUpdateRequest.cs index 8d647666..e182d64f 100644 --- a/src/Merge.Client/Crm/Associations/Requests/CustomObjectClassesCustomObjectsAssociationsUpdateRequest.cs +++ b/src/Merge.Client/Crm/Associations/Requests/CustomObjectClassesCustomObjectsAssociationsUpdateRequest.cs @@ -1,14 +1,14 @@ namespace Merge.Client.Crm; -public class CustomObjectClassesCustomObjectsAssociationsUpdateRequest +public record CustomObjectClassesCustomObjectsAssociationsUpdateRequest { /// /// Whether to include debug fields (such as log file links) in the response. /// - public bool? IsDebugMode { get; init; } + public bool? IsDebugMode { get; set; } /// /// Whether or not third-party updates should be run asynchronously. /// - public bool? RunAsync { get; init; } + public bool? RunAsync { get; set; } } diff --git a/src/Merge.Client/Crm/AsyncPassthrough/AsyncPassthroughClient.cs b/src/Merge.Client/Crm/AsyncPassthrough/AsyncPassthroughClient.cs index 08a19507..8e5af997 100644 --- a/src/Merge.Client/Crm/AsyncPassthrough/AsyncPassthroughClient.cs +++ b/src/Merge.Client/Crm/AsyncPassthrough/AsyncPassthroughClient.cs @@ -1,6 +1,6 @@ +using System.Net.Http; using System.Text.Json; -using Merge.Client; -using Merge.Client.Crm; +using Merge.Client.Core; #nullable enable @@ -18,41 +18,75 @@ public AsyncPassthroughClient(RawClient client) /// /// Asynchronously pull data from an endpoint not currently supported by Merge. /// - public async Task CreateAsync(DataPassthroughRequest request) + public async Task CreateAsync( + DataPassthroughRequest request, + RequestOptions? options = null + ) { var response = await _client.MakeRequestAsync( new RawClient.JsonApiRequest { + BaseUrl = _client.Options.BaseUrl, Method = HttpMethod.Post, Path = "crm/v1/async-passthrough", - Body = request + Body = request, + Options = options } ); - string responseBody = await response.Raw.Content.ReadAsStringAsync(); - if (response.StatusCode >= 200 && response.StatusCode < 400) + var responseBody = await response.Raw.Content.ReadAsStringAsync(); + if (response.StatusCode is >= 200 and < 400) { - return JsonSerializer.Deserialize(responseBody); + try + { + return JsonUtils.Deserialize(responseBody)!; + } + catch (JsonException e) + { + throw new MergeException("Failed to deserialize response", e); + } } - throw new Exception(responseBody); + + throw new MergeApiException( + $"Error with status code {response.StatusCode}", + response.StatusCode, + JsonUtils.Deserialize(responseBody) + ); } /// /// Retrieves data from earlier async-passthrough POST request /// - public async Task RetrieveAsync(string asyncPassthroughReceiptId) + public async Task RetrieveAsync( + string asyncPassthroughReceiptId, + RequestOptions? options = null + ) { var response = await _client.MakeRequestAsync( new RawClient.JsonApiRequest { + BaseUrl = _client.Options.BaseUrl, Method = HttpMethod.Get, - Path = $"crm/v1/async-passthrough/{asyncPassthroughReceiptId}" + Path = $"crm/v1/async-passthrough/{asyncPassthroughReceiptId}", + Options = options } ); - string responseBody = await response.Raw.Content.ReadAsStringAsync(); - if (response.StatusCode >= 200 && response.StatusCode < 400) + var responseBody = await response.Raw.Content.ReadAsStringAsync(); + if (response.StatusCode is >= 200 and < 400) { - return JsonSerializer.Deserialize(responseBody); + try + { + return JsonUtils.Deserialize(responseBody)!; + } + catch (JsonException e) + { + throw new MergeException("Failed to deserialize response", e); + } } - throw new Exception(responseBody); + + throw new MergeApiException( + $"Error with status code {response.StatusCode}", + response.StatusCode, + JsonUtils.Deserialize(responseBody) + ); } } diff --git a/src/Merge.Client/Crm/AuditTrail/AuditTrailClient.cs b/src/Merge.Client/Crm/AuditTrail/AuditTrailClient.cs index e9ac999c..4b1898d3 100644 --- a/src/Merge.Client/Crm/AuditTrail/AuditTrailClient.cs +++ b/src/Merge.Client/Crm/AuditTrail/AuditTrailClient.cs @@ -1,6 +1,6 @@ +using System.Net.Http; using System.Text.Json; -using Merge.Client; -using Merge.Client.Crm; +using Merge.Client.Core; #nullable enable @@ -18,7 +18,10 @@ public AuditTrailClient(RawClient client) /// /// Gets a list of audit trail events. /// - public async Task ListAsync(AuditTrailListRequest request) + public async Task ListAsync( + AuditTrailListRequest request, + RequestOptions? options = null + ) { var _query = new Dictionary() { }; if (request.Cursor != null) @@ -48,16 +51,30 @@ public async Task ListAsync(AuditTrailListRequest re var response = await _client.MakeRequestAsync( new RawClient.JsonApiRequest { + BaseUrl = _client.Options.BaseUrl, Method = HttpMethod.Get, Path = "crm/v1/audit-trail", - Query = _query + Query = _query, + Options = options } ); - string responseBody = await response.Raw.Content.ReadAsStringAsync(); - if (response.StatusCode >= 200 && response.StatusCode < 400) + var responseBody = await response.Raw.Content.ReadAsStringAsync(); + if (response.StatusCode is >= 200 and < 400) { - return JsonSerializer.Deserialize(responseBody); + try + { + return JsonUtils.Deserialize(responseBody)!; + } + catch (JsonException e) + { + throw new MergeException("Failed to deserialize response", e); + } } - throw new Exception(responseBody); + + throw new MergeApiException( + $"Error with status code {response.StatusCode}", + response.StatusCode, + JsonUtils.Deserialize(responseBody) + ); } } diff --git a/src/Merge.Client/Crm/AuditTrail/Requests/AuditTrailListRequest.cs b/src/Merge.Client/Crm/AuditTrail/Requests/AuditTrailListRequest.cs index 21af9f14..1e14ad70 100644 --- a/src/Merge.Client/Crm/AuditTrail/Requests/AuditTrailListRequest.cs +++ b/src/Merge.Client/Crm/AuditTrail/Requests/AuditTrailListRequest.cs @@ -1,34 +1,34 @@ namespace Merge.Client.Crm; -public class AuditTrailListRequest +public record AuditTrailListRequest { /// /// The pagination cursor value. /// - public string? Cursor { get; init; } + public string? Cursor { get; set; } /// /// If included, will only include audit trail events that occurred before this time /// - public string? EndDate { get; init; } + public string? EndDate { get; set; } /// /// If included, will only include events with the given event type. Possible values include: `CREATED_REMOTE_PRODUCTION_API_KEY`, `DELETED_REMOTE_PRODUCTION_API_KEY`, `CREATED_TEST_API_KEY`, `DELETED_TEST_API_KEY`, `REGENERATED_PRODUCTION_API_KEY`, `INVITED_USER`, `TWO_FACTOR_AUTH_ENABLED`, `TWO_FACTOR_AUTH_DISABLED`, `DELETED_LINKED_ACCOUNT`, `CREATED_DESTINATION`, `DELETED_DESTINATION`, `CHANGED_DESTINATION`, `CHANGED_SCOPES`, `CHANGED_PERSONAL_INFORMATION`, `CHANGED_ORGANIZATION_SETTINGS`, `ENABLED_INTEGRATION`, `DISABLED_INTEGRATION`, `ENABLED_CATEGORY`, `DISABLED_CATEGORY`, `CHANGED_PASSWORD`, `RESET_PASSWORD`, `ENABLED_REDACT_UNMAPPED_DATA_FOR_ORGANIZATION`, `ENABLED_REDACT_UNMAPPED_DATA_FOR_LINKED_ACCOUNT`, `DISABLED_REDACT_UNMAPPED_DATA_FOR_ORGANIZATION`, `DISABLED_REDACT_UNMAPPED_DATA_FOR_LINKED_ACCOUNT`, `CREATED_INTEGRATION_WIDE_FIELD_MAPPING`, `CREATED_LINKED_ACCOUNT_FIELD_MAPPING`, `CHANGED_INTEGRATION_WIDE_FIELD_MAPPING`, `CHANGED_LINKED_ACCOUNT_FIELD_MAPPING`, `DELETED_INTEGRATION_WIDE_FIELD_MAPPING`, `DELETED_LINKED_ACCOUNT_FIELD_MAPPING`, `FORCED_LINKED_ACCOUNT_RESYNC`, `MUTED_ISSUE`, `GENERATED_MAGIC_LINK`, `ENABLED_MERGE_WEBHOOK`, `DISABLED_MERGE_WEBHOOK`, `MERGE_WEBHOOK_TARGET_CHANGED`, `END_USER_CREDENTIALS_ACCESSED` /// - public string? EventType { get; init; } + public string? EventType { get; set; } /// /// Number of results to return per page. /// - public int? PageSize { get; init; } + public int? PageSize { get; set; } /// /// If included, will only include audit trail events that occurred after this time /// - public string? StartDate { get; init; } + public string? StartDate { get; set; } /// /// If provided, this will return events associated with the specified user email. Please note that the email address reflects the user's email at the time of the event, and may not be their current email. /// - public string? UserEmail { get; init; } + public string? UserEmail { get; set; } } diff --git a/src/Merge.Client/Crm/AvailableActions/AvailableActionsClient.cs b/src/Merge.Client/Crm/AvailableActions/AvailableActionsClient.cs index 7cceaf68..bebc0468 100644 --- a/src/Merge.Client/Crm/AvailableActions/AvailableActionsClient.cs +++ b/src/Merge.Client/Crm/AvailableActions/AvailableActionsClient.cs @@ -1,6 +1,6 @@ +using System.Net.Http; using System.Text.Json; -using Merge.Client; -using Merge.Client.Crm; +using Merge.Client.Core; #nullable enable @@ -18,20 +18,34 @@ public AvailableActionsClient(RawClient client) /// /// Returns a list of models and actions available for an account. /// - public async Task RetrieveAsync() + public async Task RetrieveAsync(RequestOptions? options = null) { var response = await _client.MakeRequestAsync( new RawClient.JsonApiRequest { + BaseUrl = _client.Options.BaseUrl, Method = HttpMethod.Get, - Path = "crm/v1/available-actions" + Path = "crm/v1/available-actions", + Options = options } ); - string responseBody = await response.Raw.Content.ReadAsStringAsync(); - if (response.StatusCode >= 200 && response.StatusCode < 400) + var responseBody = await response.Raw.Content.ReadAsStringAsync(); + if (response.StatusCode is >= 200 and < 400) { - return JsonSerializer.Deserialize(responseBody); + try + { + return JsonUtils.Deserialize(responseBody)!; + } + catch (JsonException e) + { + throw new MergeException("Failed to deserialize response", e); + } } - throw new Exception(responseBody); + + throw new MergeApiException( + $"Error with status code {response.StatusCode}", + response.StatusCode, + JsonUtils.Deserialize(responseBody) + ); } } diff --git a/src/Merge.Client/Crm/Contacts/ContactsClient.cs b/src/Merge.Client/Crm/Contacts/ContactsClient.cs index 07c71fcd..e35a1e71 100644 --- a/src/Merge.Client/Crm/Contacts/ContactsClient.cs +++ b/src/Merge.Client/Crm/Contacts/ContactsClient.cs @@ -1,6 +1,6 @@ +using System.Net.Http; using System.Text.Json; -using Merge.Client; -using Merge.Client.Crm; +using Merge.Client.Core; #nullable enable @@ -18,7 +18,10 @@ public ContactsClient(RawClient client) /// /// Returns a list of `Contact` objects. /// - public async Task ListAsync(ContactsListRequest request) + public async Task ListAsync( + ContactsListRequest request, + RequestOptions? options = null + ) { var _query = new Dictionary() { }; if (request.AccountId != null) @@ -27,11 +30,13 @@ public async Task ListAsync(ContactsListRequest request) } if (request.CreatedAfter != null) { - _query["created_after"] = request.CreatedAfter.Value.ToString("o0"); + _query["created_after"] = request.CreatedAfter.Value.ToString(Constants.DateTimeFormat); } if (request.CreatedBefore != null) { - _query["created_before"] = request.CreatedBefore.Value.ToString("o0"); + _query["created_before"] = request.CreatedBefore.Value.ToString( + Constants.DateTimeFormat + ); } if (request.Cursor != null) { @@ -59,11 +64,15 @@ public async Task ListAsync(ContactsListRequest request) } if (request.ModifiedAfter != null) { - _query["modified_after"] = request.ModifiedAfter.Value.ToString("o0"); + _query["modified_after"] = request.ModifiedAfter.Value.ToString( + Constants.DateTimeFormat + ); } if (request.ModifiedBefore != null) { - _query["modified_before"] = request.ModifiedBefore.Value.ToString("o0"); + _query["modified_before"] = request.ModifiedBefore.Value.ToString( + Constants.DateTimeFormat + ); } if (request.PageSize != null) { @@ -80,23 +89,40 @@ public async Task ListAsync(ContactsListRequest request) var response = await _client.MakeRequestAsync( new RawClient.JsonApiRequest { + BaseUrl = _client.Options.BaseUrl, Method = HttpMethod.Get, Path = "crm/v1/contacts", - Query = _query + Query = _query, + Options = options } ); - string responseBody = await response.Raw.Content.ReadAsStringAsync(); - if (response.StatusCode >= 200 && response.StatusCode < 400) + var responseBody = await response.Raw.Content.ReadAsStringAsync(); + if (response.StatusCode is >= 200 and < 400) { - return JsonSerializer.Deserialize(responseBody); + try + { + return JsonUtils.Deserialize(responseBody)!; + } + catch (JsonException e) + { + throw new MergeException("Failed to deserialize response", e); + } } - throw new Exception(responseBody); + + throw new MergeApiException( + $"Error with status code {response.StatusCode}", + response.StatusCode, + JsonUtils.Deserialize(responseBody) + ); } /// /// Creates a `Contact` object with the given values. /// - public async Task CreateAsync(CrmContactEndpointRequest request) + public async Task CreateAsync( + CrmContactEndpointRequest request, + RequestOptions? options = null + ) { var _query = new Dictionary() { }; if (request.IsDebugMode != null) @@ -110,23 +136,41 @@ public async Task CreateAsync(CrmContactEndpointRequest requ var response = await _client.MakeRequestAsync( new RawClient.JsonApiRequest { + BaseUrl = _client.Options.BaseUrl, Method = HttpMethod.Post, Path = "crm/v1/contacts", - Query = _query + Query = _query, + Options = options } ); - string responseBody = await response.Raw.Content.ReadAsStringAsync(); - if (response.StatusCode >= 200 && response.StatusCode < 400) + var responseBody = await response.Raw.Content.ReadAsStringAsync(); + if (response.StatusCode is >= 200 and < 400) { - return JsonSerializer.Deserialize(responseBody); + try + { + return JsonUtils.Deserialize(responseBody)!; + } + catch (JsonException e) + { + throw new MergeException("Failed to deserialize response", e); + } } - throw new Exception(responseBody); + + throw new MergeApiException( + $"Error with status code {response.StatusCode}", + response.StatusCode, + JsonUtils.Deserialize(responseBody) + ); } /// /// Returns a `Contact` object with the given `id`. /// - public async Task RetrieveAsync(string id, ContactsRetrieveRequest request) + public async Task RetrieveAsync( + string id, + ContactsRetrieveRequest request, + RequestOptions? options = null + ) { var _query = new Dictionary() { }; if (request.Expand != null) @@ -144,17 +188,31 @@ public async Task RetrieveAsync(string id, ContactsRetrieveRequest requ var response = await _client.MakeRequestAsync( new RawClient.JsonApiRequest { + BaseUrl = _client.Options.BaseUrl, Method = HttpMethod.Get, Path = $"crm/v1/contacts/{id}", - Query = _query + Query = _query, + Options = options } ); - string responseBody = await response.Raw.Content.ReadAsStringAsync(); - if (response.StatusCode >= 200 && response.StatusCode < 400) + var responseBody = await response.Raw.Content.ReadAsStringAsync(); + if (response.StatusCode is >= 200 and < 400) { - return JsonSerializer.Deserialize(responseBody); + try + { + return JsonUtils.Deserialize(responseBody)!; + } + catch (JsonException e) + { + throw new MergeException("Failed to deserialize response", e); + } } - throw new Exception(responseBody); + + throw new MergeApiException( + $"Error with status code {response.StatusCode}", + response.StatusCode, + JsonUtils.Deserialize(responseBody) + ); } /// @@ -162,7 +220,8 @@ public async Task RetrieveAsync(string id, ContactsRetrieveRequest requ /// public async Task PartialUpdateAsync( string id, - PatchedCrmContactEndpointRequest request + PatchedCrmContactEndpointRequest request, + RequestOptions? options = null ) { var _query = new Dictionary() { }; @@ -177,79 +236,141 @@ PatchedCrmContactEndpointRequest request var response = await _client.MakeRequestAsync( new RawClient.JsonApiRequest { - Method = HttpMethod.Patch, + BaseUrl = _client.Options.BaseUrl, + Method = HttpMethodExtensions.Patch, Path = $"crm/v1/contacts/{id}", - Query = _query + Query = _query, + Options = options } ); - string responseBody = await response.Raw.Content.ReadAsStringAsync(); - if (response.StatusCode >= 200 && response.StatusCode < 400) + var responseBody = await response.Raw.Content.ReadAsStringAsync(); + if (response.StatusCode is >= 200 and < 400) { - return JsonSerializer.Deserialize(responseBody); + try + { + return JsonUtils.Deserialize(responseBody)!; + } + catch (JsonException e) + { + throw new MergeException("Failed to deserialize response", e); + } } - throw new Exception(responseBody); + + throw new MergeApiException( + $"Error with status code {response.StatusCode}", + response.StatusCode, + JsonUtils.Deserialize(responseBody) + ); } /// /// Ignores a specific row based on the `model_id` in the url. These records will have their properties set to null, and will not be updated in future syncs. The "reason" and "message" fields in the request body will be stored for audit purposes. /// - public async void IgnoreCreateAsync(string modelId, IgnoreCommonModelRequest request) + public async Task IgnoreCreateAsync( + string modelId, + IgnoreCommonModelRequest request, + RequestOptions? options = null + ) { var response = await _client.MakeRequestAsync( new RawClient.JsonApiRequest { + BaseUrl = _client.Options.BaseUrl, Method = HttpMethod.Post, Path = $"crm/v1/contacts/ignore/{modelId}", - Body = request + Body = request, + Options = options } ); + if (response.StatusCode is >= 200 and < 400) + { + return; + } + var responseBody = await response.Raw.Content.ReadAsStringAsync(); + throw new MergeApiException( + $"Error with status code {response.StatusCode}", + response.StatusCode, + JsonUtils.Deserialize(responseBody) + ); } /// /// Returns metadata for `CRMContact` PATCHs. /// - public async Task MetaPatchRetrieveAsync(string id) + public async Task MetaPatchRetrieveAsync( + string id, + RequestOptions? options = null + ) { var response = await _client.MakeRequestAsync( new RawClient.JsonApiRequest { + BaseUrl = _client.Options.BaseUrl, Method = HttpMethod.Get, - Path = $"crm/v1/contacts/meta/patch/{id}" + Path = $"crm/v1/contacts/meta/patch/{id}", + Options = options } ); - string responseBody = await response.Raw.Content.ReadAsStringAsync(); - if (response.StatusCode >= 200 && response.StatusCode < 400) + var responseBody = await response.Raw.Content.ReadAsStringAsync(); + if (response.StatusCode is >= 200 and < 400) { - return JsonSerializer.Deserialize(responseBody); + try + { + return JsonUtils.Deserialize(responseBody)!; + } + catch (JsonException e) + { + throw new MergeException("Failed to deserialize response", e); + } } - throw new Exception(responseBody); + + throw new MergeApiException( + $"Error with status code {response.StatusCode}", + response.StatusCode, + JsonUtils.Deserialize(responseBody) + ); } /// /// Returns metadata for `CRMContact` POSTs. /// - public async Task MetaPostRetrieveAsync() + public async Task MetaPostRetrieveAsync(RequestOptions? options = null) { var response = await _client.MakeRequestAsync( new RawClient.JsonApiRequest { + BaseUrl = _client.Options.BaseUrl, Method = HttpMethod.Get, - Path = "crm/v1/contacts/meta/post" + Path = "crm/v1/contacts/meta/post", + Options = options } ); - string responseBody = await response.Raw.Content.ReadAsStringAsync(); - if (response.StatusCode >= 200 && response.StatusCode < 400) + var responseBody = await response.Raw.Content.ReadAsStringAsync(); + if (response.StatusCode is >= 200 and < 400) { - return JsonSerializer.Deserialize(responseBody); + try + { + return JsonUtils.Deserialize(responseBody)!; + } + catch (JsonException e) + { + throw new MergeException("Failed to deserialize response", e); + } } - throw new Exception(responseBody); + + throw new MergeApiException( + $"Error with status code {response.StatusCode}", + response.StatusCode, + JsonUtils.Deserialize(responseBody) + ); } /// /// Returns a list of `RemoteFieldClass` objects. /// public async Task RemoteFieldClassesListAsync( - ContactsRemoteFieldClassesListRequest request + ContactsRemoteFieldClassesListRequest request, + RequestOptions? options = null ) { var _query = new Dictionary() { }; @@ -280,16 +401,30 @@ ContactsRemoteFieldClassesListRequest request var response = await _client.MakeRequestAsync( new RawClient.JsonApiRequest { + BaseUrl = _client.Options.BaseUrl, Method = HttpMethod.Get, Path = "crm/v1/contacts/remote-field-classes", - Query = _query + Query = _query, + Options = options } ); - string responseBody = await response.Raw.Content.ReadAsStringAsync(); - if (response.StatusCode >= 200 && response.StatusCode < 400) + var responseBody = await response.Raw.Content.ReadAsStringAsync(); + if (response.StatusCode is >= 200 and < 400) { - return JsonSerializer.Deserialize(responseBody); + try + { + return JsonUtils.Deserialize(responseBody)!; + } + catch (JsonException e) + { + throw new MergeException("Failed to deserialize response", e); + } } - throw new Exception(responseBody); + + throw new MergeApiException( + $"Error with status code {response.StatusCode}", + response.StatusCode, + JsonUtils.Deserialize(responseBody) + ); } } diff --git a/src/Merge.Client/Crm/Contacts/Requests/ContactsListRequest.cs b/src/Merge.Client/Crm/Contacts/Requests/ContactsListRequest.cs index 7b3ff884..2d184759 100644 --- a/src/Merge.Client/Crm/Contacts/Requests/ContactsListRequest.cs +++ b/src/Merge.Client/Crm/Contacts/Requests/ContactsListRequest.cs @@ -1,78 +1,74 @@ -using Merge.Client.Crm; - -#nullable enable - namespace Merge.Client.Crm; -public class ContactsListRequest +public record ContactsListRequest { /// /// If provided, will only return contacts with this account. /// - public string? AccountId { get; init; } + public string? AccountId { get; set; } /// /// If provided, will only return objects created after this datetime. /// - public DateTime? CreatedAfter { get; init; } + public DateTime? CreatedAfter { get; set; } /// /// If provided, will only return objects created before this datetime. /// - public DateTime? CreatedBefore { get; init; } + public DateTime? CreatedBefore { get; set; } /// /// The pagination cursor value. /// - public string? Cursor { get; init; } + public string? Cursor { get; set; } /// /// If provided, will only return contacts matching the email addresses; multiple email_addresses can be separated by commas. /// - public string? EmailAddresses { get; init; } + public string? EmailAddresses { get; set; } /// /// Which relations should be returned in expanded form. Multiple relation names should be comma separated without spaces. /// - public ContactsListRequestExpand? Expand { get; init; } + public ContactsListRequestExpand? Expand { get; set; } /// /// Whether to include data that was marked as deleted by third party webhooks. /// - public bool? IncludeDeletedData { get; init; } + public bool? IncludeDeletedData { get; set; } /// /// Whether to include the original data Merge fetched from the third-party to produce these models. /// - public bool? IncludeRemoteData { get; init; } + public bool? IncludeRemoteData { get; set; } /// /// Whether to include all remote fields, including fields that Merge did not map to common models, in a normalized format. /// - public bool? IncludeRemoteFields { get; init; } + public bool? IncludeRemoteFields { get; set; } /// /// If provided, only objects synced by Merge after this date time will be returned. /// - public DateTime? ModifiedAfter { get; init; } + public DateTime? ModifiedAfter { get; set; } /// /// If provided, only objects synced by Merge before this date time will be returned. /// - public DateTime? ModifiedBefore { get; init; } + public DateTime? ModifiedBefore { get; set; } /// /// Number of results to return per page. /// - public int? PageSize { get; init; } + public int? PageSize { get; set; } /// /// If provided, will only return contacts matching the phone numbers; multiple phone numbers can be separated by commas. /// - public string? PhoneNumbers { get; init; } + public string? PhoneNumbers { get; set; } /// /// The API provider's ID for the given object. /// - public string? RemoteId { get; init; } + public string? RemoteId { get; set; } } diff --git a/src/Merge.Client/Crm/Contacts/Requests/ContactsRemoteFieldClassesListRequest.cs b/src/Merge.Client/Crm/Contacts/Requests/ContactsRemoteFieldClassesListRequest.cs index 28b9202e..c50ae481 100644 --- a/src/Merge.Client/Crm/Contacts/Requests/ContactsRemoteFieldClassesListRequest.cs +++ b/src/Merge.Client/Crm/Contacts/Requests/ContactsRemoteFieldClassesListRequest.cs @@ -1,34 +1,34 @@ namespace Merge.Client.Crm; -public class ContactsRemoteFieldClassesListRequest +public record ContactsRemoteFieldClassesListRequest { /// /// The pagination cursor value. /// - public string? Cursor { get; init; } + public string? Cursor { get; set; } /// /// Whether to include data that was marked as deleted by third party webhooks. /// - public bool? IncludeDeletedData { get; init; } + public bool? IncludeDeletedData { get; set; } /// /// Whether to include the original data Merge fetched from the third-party to produce these models. /// - public bool? IncludeRemoteData { get; init; } + public bool? IncludeRemoteData { get; set; } /// /// Whether to include all remote fields, including fields that Merge did not map to common models, in a normalized format. /// - public bool? IncludeRemoteFields { get; init; } + public bool? IncludeRemoteFields { get; set; } /// /// If provided, will only return remote field classes with this is_common_model_field value /// - public bool? IsCommonModelField { get; init; } + public bool? IsCommonModelField { get; set; } /// /// Number of results to return per page. /// - public int? PageSize { get; init; } + public int? PageSize { get; set; } } diff --git a/src/Merge.Client/Crm/Contacts/Requests/ContactsRetrieveRequest.cs b/src/Merge.Client/Crm/Contacts/Requests/ContactsRetrieveRequest.cs index 2f299953..0a38bf59 100644 --- a/src/Merge.Client/Crm/Contacts/Requests/ContactsRetrieveRequest.cs +++ b/src/Merge.Client/Crm/Contacts/Requests/ContactsRetrieveRequest.cs @@ -1,23 +1,19 @@ -using Merge.Client.Crm; - -#nullable enable - namespace Merge.Client.Crm; -public class ContactsRetrieveRequest +public record ContactsRetrieveRequest { /// /// Which relations should be returned in expanded form. Multiple relation names should be comma separated without spaces. /// - public ContactsRetrieveRequestExpand? Expand { get; init; } + public ContactsRetrieveRequestExpand? Expand { get; set; } /// /// Whether to include the original data Merge fetched from the third-party to produce these models. /// - public bool? IncludeRemoteData { get; init; } + public bool? IncludeRemoteData { get; set; } /// /// Whether to include all remote fields, including fields that Merge did not map to common models, in a normalized format. /// - public bool? IncludeRemoteFields { get; init; } + public bool? IncludeRemoteFields { get; set; } } diff --git a/src/Merge.Client/Crm/Contacts/Requests/CrmContactEndpointRequest.cs b/src/Merge.Client/Crm/Contacts/Requests/CrmContactEndpointRequest.cs index 9dc031e4..0df1a418 100644 --- a/src/Merge.Client/Crm/Contacts/Requests/CrmContactEndpointRequest.cs +++ b/src/Merge.Client/Crm/Contacts/Requests/CrmContactEndpointRequest.cs @@ -1,20 +1,16 @@ -using Merge.Client.Crm; - -#nullable enable - namespace Merge.Client.Crm; -public class CrmContactEndpointRequest +public record CrmContactEndpointRequest { /// /// Whether to include debug fields (such as log file links) in the response. /// - public bool? IsDebugMode { get; init; } + public bool? IsDebugMode { get; set; } /// /// Whether or not third-party updates should be run asynchronously. /// - public bool? RunAsync { get; init; } + public bool? RunAsync { get; set; } - public ContactRequest Model { get; init; } + public required ContactRequest Model { get; set; } } diff --git a/src/Merge.Client/Crm/Contacts/Requests/PatchedCrmContactEndpointRequest.cs b/src/Merge.Client/Crm/Contacts/Requests/PatchedCrmContactEndpointRequest.cs index d399f6d8..dc250e1e 100644 --- a/src/Merge.Client/Crm/Contacts/Requests/PatchedCrmContactEndpointRequest.cs +++ b/src/Merge.Client/Crm/Contacts/Requests/PatchedCrmContactEndpointRequest.cs @@ -1,20 +1,16 @@ -using Merge.Client.Crm; - -#nullable enable - namespace Merge.Client.Crm; -public class PatchedCrmContactEndpointRequest +public record PatchedCrmContactEndpointRequest { /// /// Whether to include debug fields (such as log file links) in the response. /// - public bool? IsDebugMode { get; init; } + public bool? IsDebugMode { get; set; } /// /// Whether or not third-party updates should be run asynchronously. /// - public bool? RunAsync { get; init; } + public bool? RunAsync { get; set; } - public PatchedContactRequest Model { get; init; } + public required PatchedContactRequest Model { get; set; } } diff --git a/src/Merge.Client/Crm/Contacts/Types/ContactsListRequestExpand.cs b/src/Merge.Client/Crm/Contacts/Types/ContactsListRequestExpand.cs index 194de8cf..6cc21f6d 100644 --- a/src/Merge.Client/Crm/Contacts/Types/ContactsListRequestExpand.cs +++ b/src/Merge.Client/Crm/Contacts/Types/ContactsListRequestExpand.cs @@ -1,7 +1,6 @@ using System.Runtime.Serialization; using System.Text.Json.Serialization; using Merge.Client.Core; -using Merge.Client.Crm; #nullable enable diff --git a/src/Merge.Client/Crm/Contacts/Types/ContactsRetrieveRequestExpand.cs b/src/Merge.Client/Crm/Contacts/Types/ContactsRetrieveRequestExpand.cs index cfb04a57..0ee1a697 100644 --- a/src/Merge.Client/Crm/Contacts/Types/ContactsRetrieveRequestExpand.cs +++ b/src/Merge.Client/Crm/Contacts/Types/ContactsRetrieveRequestExpand.cs @@ -1,7 +1,6 @@ using System.Runtime.Serialization; using System.Text.Json.Serialization; using Merge.Client.Core; -using Merge.Client.Crm; #nullable enable diff --git a/src/Merge.Client/Crm/CrmClient.cs b/src/Merge.Client/Crm/CrmClient.cs index 5bd5f70f..78c6c028 100644 --- a/src/Merge.Client/Crm/CrmClient.cs +++ b/src/Merge.Client/Crm/CrmClient.cs @@ -1,5 +1,4 @@ -using Merge.Client; -using Merge.Client.Crm; +using Merge.Client.Core; #nullable enable diff --git a/src/Merge.Client/Crm/CustomObjectClasses/CustomObjectClassesClient.cs b/src/Merge.Client/Crm/CustomObjectClasses/CustomObjectClassesClient.cs index 43894fbf..f5e75e18 100644 --- a/src/Merge.Client/Crm/CustomObjectClasses/CustomObjectClassesClient.cs +++ b/src/Merge.Client/Crm/CustomObjectClasses/CustomObjectClassesClient.cs @@ -1,6 +1,6 @@ +using System.Net.Http; using System.Text.Json; -using Merge.Client; -using Merge.Client.Crm; +using Merge.Client.Core; #nullable enable @@ -19,17 +19,20 @@ public CustomObjectClassesClient(RawClient client) /// Returns a list of `CustomObjectClass` objects. /// public async Task ListAsync( - CustomObjectClassesListRequest request + CustomObjectClassesListRequest request, + RequestOptions? options = null ) { var _query = new Dictionary() { }; if (request.CreatedAfter != null) { - _query["created_after"] = request.CreatedAfter.Value.ToString("o0"); + _query["created_after"] = request.CreatedAfter.Value.ToString(Constants.DateTimeFormat); } if (request.CreatedBefore != null) { - _query["created_before"] = request.CreatedBefore.Value.ToString("o0"); + _query["created_before"] = request.CreatedBefore.Value.ToString( + Constants.DateTimeFormat + ); } if (request.Cursor != null) { @@ -49,11 +52,15 @@ CustomObjectClassesListRequest request } if (request.ModifiedAfter != null) { - _query["modified_after"] = request.ModifiedAfter.Value.ToString("o0"); + _query["modified_after"] = request.ModifiedAfter.Value.ToString( + Constants.DateTimeFormat + ); } if (request.ModifiedBefore != null) { - _query["modified_before"] = request.ModifiedBefore.Value.ToString("o0"); + _query["modified_before"] = request.ModifiedBefore.Value.ToString( + Constants.DateTimeFormat + ); } if (request.PageSize != null) { @@ -66,17 +73,31 @@ CustomObjectClassesListRequest request var response = await _client.MakeRequestAsync( new RawClient.JsonApiRequest { + BaseUrl = _client.Options.BaseUrl, Method = HttpMethod.Get, Path = "crm/v1/custom-object-classes", - Query = _query + Query = _query, + Options = options } ); - string responseBody = await response.Raw.Content.ReadAsStringAsync(); - if (response.StatusCode >= 200 && response.StatusCode < 400) + var responseBody = await response.Raw.Content.ReadAsStringAsync(); + if (response.StatusCode is >= 200 and < 400) { - return JsonSerializer.Deserialize(responseBody); + try + { + return JsonUtils.Deserialize(responseBody)!; + } + catch (JsonException e) + { + throw new MergeException("Failed to deserialize response", e); + } } - throw new Exception(responseBody); + + throw new MergeApiException( + $"Error with status code {response.StatusCode}", + response.StatusCode, + JsonUtils.Deserialize(responseBody) + ); } /// @@ -84,7 +105,8 @@ CustomObjectClassesListRequest request /// public async Task RetrieveAsync( string id, - CustomObjectClassesRetrieveRequest request + CustomObjectClassesRetrieveRequest request, + RequestOptions? options = null ) { var _query = new Dictionary() { }; @@ -99,16 +121,30 @@ CustomObjectClassesRetrieveRequest request var response = await _client.MakeRequestAsync( new RawClient.JsonApiRequest { + BaseUrl = _client.Options.BaseUrl, Method = HttpMethod.Get, Path = $"crm/v1/custom-object-classes/{id}", - Query = _query + Query = _query, + Options = options } ); - string responseBody = await response.Raw.Content.ReadAsStringAsync(); - if (response.StatusCode >= 200 && response.StatusCode < 400) + var responseBody = await response.Raw.Content.ReadAsStringAsync(); + if (response.StatusCode is >= 200 and < 400) { - return JsonSerializer.Deserialize(responseBody); + try + { + return JsonUtils.Deserialize(responseBody)!; + } + catch (JsonException e) + { + throw new MergeException("Failed to deserialize response", e); + } } - throw new Exception(responseBody); + + throw new MergeApiException( + $"Error with status code {response.StatusCode}", + response.StatusCode, + JsonUtils.Deserialize(responseBody) + ); } } diff --git a/src/Merge.Client/Crm/CustomObjectClasses/Requests/CustomObjectClassesListRequest.cs b/src/Merge.Client/Crm/CustomObjectClasses/Requests/CustomObjectClassesListRequest.cs index c1b44523..6a097322 100644 --- a/src/Merge.Client/Crm/CustomObjectClasses/Requests/CustomObjectClassesListRequest.cs +++ b/src/Merge.Client/Crm/CustomObjectClasses/Requests/CustomObjectClassesListRequest.cs @@ -1,54 +1,54 @@ namespace Merge.Client.Crm; -public class CustomObjectClassesListRequest +public record CustomObjectClassesListRequest { /// /// If provided, will only return objects created after this datetime. /// - public DateTime? CreatedAfter { get; init; } + public DateTime? CreatedAfter { get; set; } /// /// If provided, will only return objects created before this datetime. /// - public DateTime? CreatedBefore { get; init; } + public DateTime? CreatedBefore { get; set; } /// /// The pagination cursor value. /// - public string? Cursor { get; init; } + public string? Cursor { get; set; } /// /// Which relations should be returned in expanded form. Multiple relation names should be comma separated without spaces. /// - public string? Expand { get; init; } + public string? Expand { get; set; } /// /// Whether to include data that was marked as deleted by third party webhooks. /// - public bool? IncludeDeletedData { get; init; } + public bool? IncludeDeletedData { get; set; } /// /// Whether to include the original data Merge fetched from the third-party to produce these models. /// - public bool? IncludeRemoteData { get; init; } + public bool? IncludeRemoteData { get; set; } /// /// If provided, only objects synced by Merge after this date time will be returned. /// - public DateTime? ModifiedAfter { get; init; } + public DateTime? ModifiedAfter { get; set; } /// /// If provided, only objects synced by Merge before this date time will be returned. /// - public DateTime? ModifiedBefore { get; init; } + public DateTime? ModifiedBefore { get; set; } /// /// Number of results to return per page. /// - public int? PageSize { get; init; } + public int? PageSize { get; set; } /// /// The API provider's ID for the given object. /// - public string? RemoteId { get; init; } + public string? RemoteId { get; set; } } diff --git a/src/Merge.Client/Crm/CustomObjectClasses/Requests/CustomObjectClassesRetrieveRequest.cs b/src/Merge.Client/Crm/CustomObjectClasses/Requests/CustomObjectClassesRetrieveRequest.cs index 9e015cac..7ab7badf 100644 --- a/src/Merge.Client/Crm/CustomObjectClasses/Requests/CustomObjectClassesRetrieveRequest.cs +++ b/src/Merge.Client/Crm/CustomObjectClasses/Requests/CustomObjectClassesRetrieveRequest.cs @@ -1,14 +1,14 @@ namespace Merge.Client.Crm; -public class CustomObjectClassesRetrieveRequest +public record CustomObjectClassesRetrieveRequest { /// /// Which relations should be returned in expanded form. Multiple relation names should be comma separated without spaces. /// - public string? Expand { get; init; } + public string? Expand { get; set; } /// /// Whether to include the original data Merge fetched from the third-party to produce these models. /// - public bool? IncludeRemoteData { get; init; } + public bool? IncludeRemoteData { get; set; } } diff --git a/src/Merge.Client/Crm/CustomObjects/CustomObjectsClient.cs b/src/Merge.Client/Crm/CustomObjects/CustomObjectsClient.cs index 05cdd50f..16e6952c 100644 --- a/src/Merge.Client/Crm/CustomObjects/CustomObjectsClient.cs +++ b/src/Merge.Client/Crm/CustomObjects/CustomObjectsClient.cs @@ -1,6 +1,6 @@ +using System.Net.Http; using System.Text.Json; -using Merge.Client; -using Merge.Client.Crm; +using Merge.Client.Core; #nullable enable @@ -20,17 +20,20 @@ public CustomObjectsClient(RawClient client) /// public async Task CustomObjectClassesCustomObjectsListAsync( string customObjectClassId, - CustomObjectClassesCustomObjectsListRequest request + CustomObjectClassesCustomObjectsListRequest request, + RequestOptions? options = null ) { var _query = new Dictionary() { }; if (request.CreatedAfter != null) { - _query["created_after"] = request.CreatedAfter.Value.ToString("o0"); + _query["created_after"] = request.CreatedAfter.Value.ToString(Constants.DateTimeFormat); } if (request.CreatedBefore != null) { - _query["created_before"] = request.CreatedBefore.Value.ToString("o0"); + _query["created_before"] = request.CreatedBefore.Value.ToString( + Constants.DateTimeFormat + ); } if (request.Cursor != null) { @@ -50,11 +53,15 @@ CustomObjectClassesCustomObjectsListRequest request } if (request.ModifiedAfter != null) { - _query["modified_after"] = request.ModifiedAfter.Value.ToString("o0"); + _query["modified_after"] = request.ModifiedAfter.Value.ToString( + Constants.DateTimeFormat + ); } if (request.ModifiedBefore != null) { - _query["modified_before"] = request.ModifiedBefore.Value.ToString("o0"); + _query["modified_before"] = request.ModifiedBefore.Value.ToString( + Constants.DateTimeFormat + ); } if (request.PageSize != null) { @@ -67,17 +74,31 @@ CustomObjectClassesCustomObjectsListRequest request var response = await _client.MakeRequestAsync( new RawClient.JsonApiRequest { + BaseUrl = _client.Options.BaseUrl, Method = HttpMethod.Get, Path = $"crm/v1/custom-object-classes/{customObjectClassId}/custom-objects", - Query = _query + Query = _query, + Options = options } ); - string responseBody = await response.Raw.Content.ReadAsStringAsync(); - if (response.StatusCode >= 200 && response.StatusCode < 400) + var responseBody = await response.Raw.Content.ReadAsStringAsync(); + if (response.StatusCode is >= 200 and < 400) { - return JsonSerializer.Deserialize(responseBody); + try + { + return JsonUtils.Deserialize(responseBody)!; + } + catch (JsonException e) + { + throw new MergeException("Failed to deserialize response", e); + } } - throw new Exception(responseBody); + + throw new MergeApiException( + $"Error with status code {response.StatusCode}", + response.StatusCode, + JsonUtils.Deserialize(responseBody) + ); } /// @@ -85,7 +106,8 @@ CustomObjectClassesCustomObjectsListRequest request /// public async Task CustomObjectClassesCustomObjectsCreateAsync( string customObjectClassId, - CrmCustomObjectEndpointRequest request + CrmCustomObjectEndpointRequest request, + RequestOptions? options = null ) { var _query = new Dictionary() { }; @@ -100,17 +122,31 @@ CrmCustomObjectEndpointRequest request var response = await _client.MakeRequestAsync( new RawClient.JsonApiRequest { + BaseUrl = _client.Options.BaseUrl, Method = HttpMethod.Post, Path = $"crm/v1/custom-object-classes/{customObjectClassId}/custom-objects", - Query = _query + Query = _query, + Options = options } ); - string responseBody = await response.Raw.Content.ReadAsStringAsync(); - if (response.StatusCode >= 200 && response.StatusCode < 400) + var responseBody = await response.Raw.Content.ReadAsStringAsync(); + if (response.StatusCode is >= 200 and < 400) { - return JsonSerializer.Deserialize(responseBody); + try + { + return JsonUtils.Deserialize(responseBody)!; + } + catch (JsonException e) + { + throw new MergeException("Failed to deserialize response", e); + } } - throw new Exception(responseBody); + + throw new MergeApiException( + $"Error with status code {response.StatusCode}", + response.StatusCode, + JsonUtils.Deserialize(responseBody) + ); } /// @@ -119,7 +155,8 @@ CrmCustomObjectEndpointRequest request public async Task CustomObjectClassesCustomObjectsRetrieveAsync( string customObjectClassId, string id, - CustomObjectClassesCustomObjectsRetrieveRequest request + CustomObjectClassesCustomObjectsRetrieveRequest request, + RequestOptions? options = null ) { var _query = new Dictionary() { }; @@ -134,47 +171,77 @@ CustomObjectClassesCustomObjectsRetrieveRequest request var response = await _client.MakeRequestAsync( new RawClient.JsonApiRequest { + BaseUrl = _client.Options.BaseUrl, Method = HttpMethod.Get, Path = $"crm/v1/custom-object-classes/{customObjectClassId}/custom-objects/{id}", - Query = _query + Query = _query, + Options = options } ); - string responseBody = await response.Raw.Content.ReadAsStringAsync(); - if (response.StatusCode >= 200 && response.StatusCode < 400) + var responseBody = await response.Raw.Content.ReadAsStringAsync(); + if (response.StatusCode is >= 200 and < 400) { - return JsonSerializer.Deserialize(responseBody); + try + { + return JsonUtils.Deserialize(responseBody)!; + } + catch (JsonException e) + { + throw new MergeException("Failed to deserialize response", e); + } } - throw new Exception(responseBody); + + throw new MergeApiException( + $"Error with status code {response.StatusCode}", + response.StatusCode, + JsonUtils.Deserialize(responseBody) + ); } /// /// Returns metadata for `CRMCustomObject` POSTs. /// public async Task CustomObjectClassesCustomObjectsMetaPostRetrieveAsync( - string customObjectClassId + string customObjectClassId, + RequestOptions? options = null ) { var response = await _client.MakeRequestAsync( new RawClient.JsonApiRequest { + BaseUrl = _client.Options.BaseUrl, Method = HttpMethod.Get, Path = - $"crm/v1/custom-object-classes/{customObjectClassId}/custom-objects/meta/post" + $"crm/v1/custom-object-classes/{customObjectClassId}/custom-objects/meta/post", + Options = options } ); - string responseBody = await response.Raw.Content.ReadAsStringAsync(); - if (response.StatusCode >= 200 && response.StatusCode < 400) + var responseBody = await response.Raw.Content.ReadAsStringAsync(); + if (response.StatusCode is >= 200 and < 400) { - return JsonSerializer.Deserialize(responseBody); + try + { + return JsonUtils.Deserialize(responseBody)!; + } + catch (JsonException e) + { + throw new MergeException("Failed to deserialize response", e); + } } - throw new Exception(responseBody); + + throw new MergeApiException( + $"Error with status code {response.StatusCode}", + response.StatusCode, + JsonUtils.Deserialize(responseBody) + ); } /// /// Returns a list of `RemoteFieldClass` objects. /// public async Task CustomObjectClassesCustomObjectsRemoteFieldClassesListAsync( - CustomObjectClassesCustomObjectsRemoteFieldClassesListRequest request + CustomObjectClassesCustomObjectsRemoteFieldClassesListRequest request, + RequestOptions? options = null ) { var _query = new Dictionary() { }; @@ -205,16 +272,30 @@ CustomObjectClassesCustomObjectsRemoteFieldClassesListRequest request var response = await _client.MakeRequestAsync( new RawClient.JsonApiRequest { + BaseUrl = _client.Options.BaseUrl, Method = HttpMethod.Get, Path = "crm/v1/custom-object-classes/custom-objects/remote-field-classes", - Query = _query + Query = _query, + Options = options } ); - string responseBody = await response.Raw.Content.ReadAsStringAsync(); - if (response.StatusCode >= 200 && response.StatusCode < 400) + var responseBody = await response.Raw.Content.ReadAsStringAsync(); + if (response.StatusCode is >= 200 and < 400) { - return JsonSerializer.Deserialize(responseBody); + try + { + return JsonUtils.Deserialize(responseBody)!; + } + catch (JsonException e) + { + throw new MergeException("Failed to deserialize response", e); + } } - throw new Exception(responseBody); + + throw new MergeApiException( + $"Error with status code {response.StatusCode}", + response.StatusCode, + JsonUtils.Deserialize(responseBody) + ); } } diff --git a/src/Merge.Client/Crm/CustomObjects/Requests/CrmCustomObjectEndpointRequest.cs b/src/Merge.Client/Crm/CustomObjects/Requests/CrmCustomObjectEndpointRequest.cs index 7dc550d5..3b977604 100644 --- a/src/Merge.Client/Crm/CustomObjects/Requests/CrmCustomObjectEndpointRequest.cs +++ b/src/Merge.Client/Crm/CustomObjects/Requests/CrmCustomObjectEndpointRequest.cs @@ -1,20 +1,16 @@ -using Merge.Client.Crm; - -#nullable enable - namespace Merge.Client.Crm; -public class CrmCustomObjectEndpointRequest +public record CrmCustomObjectEndpointRequest { /// /// Whether to include debug fields (such as log file links) in the response. /// - public bool? IsDebugMode { get; init; } + public bool? IsDebugMode { get; set; } /// /// Whether or not third-party updates should be run asynchronously. /// - public bool? RunAsync { get; init; } + public bool? RunAsync { get; set; } - public CustomObjectRequest Model { get; init; } + public required CustomObjectRequest Model { get; set; } } diff --git a/src/Merge.Client/Crm/CustomObjects/Requests/CustomObjectClassesCustomObjectsListRequest.cs b/src/Merge.Client/Crm/CustomObjects/Requests/CustomObjectClassesCustomObjectsListRequest.cs index bd87985b..15848ec5 100644 --- a/src/Merge.Client/Crm/CustomObjects/Requests/CustomObjectClassesCustomObjectsListRequest.cs +++ b/src/Merge.Client/Crm/CustomObjects/Requests/CustomObjectClassesCustomObjectsListRequest.cs @@ -1,54 +1,54 @@ namespace Merge.Client.Crm; -public class CustomObjectClassesCustomObjectsListRequest +public record CustomObjectClassesCustomObjectsListRequest { /// /// If provided, will only return objects created after this datetime. /// - public DateTime? CreatedAfter { get; init; } + public DateTime? CreatedAfter { get; set; } /// /// If provided, will only return objects created before this datetime. /// - public DateTime? CreatedBefore { get; init; } + public DateTime? CreatedBefore { get; set; } /// /// The pagination cursor value. /// - public string? Cursor { get; init; } + public string? Cursor { get; set; } /// /// Whether to include data that was marked as deleted by third party webhooks. /// - public bool? IncludeDeletedData { get; init; } + public bool? IncludeDeletedData { get; set; } /// /// Whether to include the original data Merge fetched from the third-party to produce these models. /// - public bool? IncludeRemoteData { get; init; } + public bool? IncludeRemoteData { get; set; } /// /// Whether to include all remote fields, including fields that Merge did not map to common models, in a normalized format. /// - public bool? IncludeRemoteFields { get; init; } + public bool? IncludeRemoteFields { get; set; } /// /// If provided, only objects synced by Merge after this date time will be returned. /// - public DateTime? ModifiedAfter { get; init; } + public DateTime? ModifiedAfter { get; set; } /// /// If provided, only objects synced by Merge before this date time will be returned. /// - public DateTime? ModifiedBefore { get; init; } + public DateTime? ModifiedBefore { get; set; } /// /// Number of results to return per page. /// - public int? PageSize { get; init; } + public int? PageSize { get; set; } /// /// The API provider's ID for the given object. /// - public string? RemoteId { get; init; } + public string? RemoteId { get; set; } } diff --git a/src/Merge.Client/Crm/CustomObjects/Requests/CustomObjectClassesCustomObjectsRemoteFieldClassesListRequest.cs b/src/Merge.Client/Crm/CustomObjects/Requests/CustomObjectClassesCustomObjectsRemoteFieldClassesListRequest.cs index aac859a5..ce7af16f 100644 --- a/src/Merge.Client/Crm/CustomObjects/Requests/CustomObjectClassesCustomObjectsRemoteFieldClassesListRequest.cs +++ b/src/Merge.Client/Crm/CustomObjects/Requests/CustomObjectClassesCustomObjectsRemoteFieldClassesListRequest.cs @@ -1,34 +1,34 @@ namespace Merge.Client.Crm; -public class CustomObjectClassesCustomObjectsRemoteFieldClassesListRequest +public record CustomObjectClassesCustomObjectsRemoteFieldClassesListRequest { /// /// The pagination cursor value. /// - public string? Cursor { get; init; } + public string? Cursor { get; set; } /// /// Whether to include data that was marked as deleted by third party webhooks. /// - public bool? IncludeDeletedData { get; init; } + public bool? IncludeDeletedData { get; set; } /// /// Whether to include the original data Merge fetched from the third-party to produce these models. /// - public bool? IncludeRemoteData { get; init; } + public bool? IncludeRemoteData { get; set; } /// /// Whether to include all remote fields, including fields that Merge did not map to common models, in a normalized format. /// - public bool? IncludeRemoteFields { get; init; } + public bool? IncludeRemoteFields { get; set; } /// /// If provided, will only return remote field classes with this is_common_model_field value /// - public bool? IsCommonModelField { get; init; } + public bool? IsCommonModelField { get; set; } /// /// Number of results to return per page. /// - public int? PageSize { get; init; } + public int? PageSize { get; set; } } diff --git a/src/Merge.Client/Crm/CustomObjects/Requests/CustomObjectClassesCustomObjectsRetrieveRequest.cs b/src/Merge.Client/Crm/CustomObjects/Requests/CustomObjectClassesCustomObjectsRetrieveRequest.cs index ef71d8d2..c7a7b317 100644 --- a/src/Merge.Client/Crm/CustomObjects/Requests/CustomObjectClassesCustomObjectsRetrieveRequest.cs +++ b/src/Merge.Client/Crm/CustomObjects/Requests/CustomObjectClassesCustomObjectsRetrieveRequest.cs @@ -1,14 +1,14 @@ namespace Merge.Client.Crm; -public class CustomObjectClassesCustomObjectsRetrieveRequest +public record CustomObjectClassesCustomObjectsRetrieveRequest { /// /// Whether to include the original data Merge fetched from the third-party to produce these models. /// - public bool? IncludeRemoteData { get; init; } + public bool? IncludeRemoteData { get; set; } /// /// Whether to include all remote fields, including fields that Merge did not map to common models, in a normalized format. /// - public bool? IncludeRemoteFields { get; init; } + public bool? IncludeRemoteFields { get; set; } } diff --git a/src/Merge.Client/Crm/DeleteAccount/DeleteAccountClient.cs b/src/Merge.Client/Crm/DeleteAccount/DeleteAccountClient.cs index 92df8a08..a9edfa3e 100644 --- a/src/Merge.Client/Crm/DeleteAccount/DeleteAccountClient.cs +++ b/src/Merge.Client/Crm/DeleteAccount/DeleteAccountClient.cs @@ -1,4 +1,5 @@ -using Merge.Client; +using System.Net.Http; +using Merge.Client.Core; #nullable enable @@ -16,14 +17,26 @@ public DeleteAccountClient(RawClient client) /// /// Delete a linked account. /// - public async void DeleteAsync() + public async Task DeleteAsync(RequestOptions? options = null) { var response = await _client.MakeRequestAsync( new RawClient.JsonApiRequest { + BaseUrl = _client.Options.BaseUrl, Method = HttpMethod.Post, - Path = "crm/v1/delete-account" + Path = "crm/v1/delete-account", + Options = options } ); + if (response.StatusCode is >= 200 and < 400) + { + return; + } + var responseBody = await response.Raw.Content.ReadAsStringAsync(); + throw new MergeApiException( + $"Error with status code {response.StatusCode}", + response.StatusCode, + JsonUtils.Deserialize(responseBody) + ); } } diff --git a/src/Merge.Client/Crm/EngagementTypes/EngagementTypesClient.cs b/src/Merge.Client/Crm/EngagementTypes/EngagementTypesClient.cs index 805a1ec9..ba046610 100644 --- a/src/Merge.Client/Crm/EngagementTypes/EngagementTypesClient.cs +++ b/src/Merge.Client/Crm/EngagementTypes/EngagementTypesClient.cs @@ -1,6 +1,6 @@ +using System.Net.Http; using System.Text.Json; -using Merge.Client; -using Merge.Client.Crm; +using Merge.Client.Core; #nullable enable @@ -18,16 +18,21 @@ public EngagementTypesClient(RawClient client) /// /// Returns a list of `EngagementType` objects. /// - public async Task ListAsync(EngagementTypesListRequest request) + public async Task ListAsync( + EngagementTypesListRequest request, + RequestOptions? options = null + ) { var _query = new Dictionary() { }; if (request.CreatedAfter != null) { - _query["created_after"] = request.CreatedAfter.Value.ToString("o0"); + _query["created_after"] = request.CreatedAfter.Value.ToString(Constants.DateTimeFormat); } if (request.CreatedBefore != null) { - _query["created_before"] = request.CreatedBefore.Value.ToString("o0"); + _query["created_before"] = request.CreatedBefore.Value.ToString( + Constants.DateTimeFormat + ); } if (request.Cursor != null) { @@ -47,11 +52,15 @@ public async Task ListAsync(EngagementTypesListRequ } if (request.ModifiedAfter != null) { - _query["modified_after"] = request.ModifiedAfter.Value.ToString("o0"); + _query["modified_after"] = request.ModifiedAfter.Value.ToString( + Constants.DateTimeFormat + ); } if (request.ModifiedBefore != null) { - _query["modified_before"] = request.ModifiedBefore.Value.ToString("o0"); + _query["modified_before"] = request.ModifiedBefore.Value.ToString( + Constants.DateTimeFormat + ); } if (request.PageSize != null) { @@ -64,17 +73,31 @@ public async Task ListAsync(EngagementTypesListRequ var response = await _client.MakeRequestAsync( new RawClient.JsonApiRequest { + BaseUrl = _client.Options.BaseUrl, Method = HttpMethod.Get, Path = "crm/v1/engagement-types", - Query = _query + Query = _query, + Options = options } ); - string responseBody = await response.Raw.Content.ReadAsStringAsync(); - if (response.StatusCode >= 200 && response.StatusCode < 400) + var responseBody = await response.Raw.Content.ReadAsStringAsync(); + if (response.StatusCode is >= 200 and < 400) { - return JsonSerializer.Deserialize(responseBody); + try + { + return JsonUtils.Deserialize(responseBody)!; + } + catch (JsonException e) + { + throw new MergeException("Failed to deserialize response", e); + } } - throw new Exception(responseBody); + + throw new MergeApiException( + $"Error with status code {response.StatusCode}", + response.StatusCode, + JsonUtils.Deserialize(responseBody) + ); } /// @@ -82,7 +105,8 @@ public async Task ListAsync(EngagementTypesListRequ /// public async Task RetrieveAsync( string id, - EngagementTypesRetrieveRequest request + EngagementTypesRetrieveRequest request, + RequestOptions? options = null ) { var _query = new Dictionary() { }; @@ -97,24 +121,39 @@ EngagementTypesRetrieveRequest request var response = await _client.MakeRequestAsync( new RawClient.JsonApiRequest { + BaseUrl = _client.Options.BaseUrl, Method = HttpMethod.Get, Path = $"crm/v1/engagement-types/{id}", - Query = _query + Query = _query, + Options = options } ); - string responseBody = await response.Raw.Content.ReadAsStringAsync(); - if (response.StatusCode >= 200 && response.StatusCode < 400) + var responseBody = await response.Raw.Content.ReadAsStringAsync(); + if (response.StatusCode is >= 200 and < 400) { - return JsonSerializer.Deserialize(responseBody); + try + { + return JsonUtils.Deserialize(responseBody)!; + } + catch (JsonException e) + { + throw new MergeException("Failed to deserialize response", e); + } } - throw new Exception(responseBody); + + throw new MergeApiException( + $"Error with status code {response.StatusCode}", + response.StatusCode, + JsonUtils.Deserialize(responseBody) + ); } /// /// Returns a list of `RemoteFieldClass` objects. /// public async Task RemoteFieldClassesListAsync( - EngagementTypesRemoteFieldClassesListRequest request + EngagementTypesRemoteFieldClassesListRequest request, + RequestOptions? options = null ) { var _query = new Dictionary() { }; @@ -145,16 +184,30 @@ EngagementTypesRemoteFieldClassesListRequest request var response = await _client.MakeRequestAsync( new RawClient.JsonApiRequest { + BaseUrl = _client.Options.BaseUrl, Method = HttpMethod.Get, Path = "crm/v1/engagement-types/remote-field-classes", - Query = _query + Query = _query, + Options = options } ); - string responseBody = await response.Raw.Content.ReadAsStringAsync(); - if (response.StatusCode >= 200 && response.StatusCode < 400) + var responseBody = await response.Raw.Content.ReadAsStringAsync(); + if (response.StatusCode is >= 200 and < 400) { - return JsonSerializer.Deserialize(responseBody); + try + { + return JsonUtils.Deserialize(responseBody)!; + } + catch (JsonException e) + { + throw new MergeException("Failed to deserialize response", e); + } } - throw new Exception(responseBody); + + throw new MergeApiException( + $"Error with status code {response.StatusCode}", + response.StatusCode, + JsonUtils.Deserialize(responseBody) + ); } } diff --git a/src/Merge.Client/Crm/EngagementTypes/Requests/EngagementTypesListRequest.cs b/src/Merge.Client/Crm/EngagementTypes/Requests/EngagementTypesListRequest.cs index 0d348864..8ca09bea 100644 --- a/src/Merge.Client/Crm/EngagementTypes/Requests/EngagementTypesListRequest.cs +++ b/src/Merge.Client/Crm/EngagementTypes/Requests/EngagementTypesListRequest.cs @@ -1,54 +1,54 @@ namespace Merge.Client.Crm; -public class EngagementTypesListRequest +public record EngagementTypesListRequest { /// /// If provided, will only return objects created after this datetime. /// - public DateTime? CreatedAfter { get; init; } + public DateTime? CreatedAfter { get; set; } /// /// If provided, will only return objects created before this datetime. /// - public DateTime? CreatedBefore { get; init; } + public DateTime? CreatedBefore { get; set; } /// /// The pagination cursor value. /// - public string? Cursor { get; init; } + public string? Cursor { get; set; } /// /// Whether to include data that was marked as deleted by third party webhooks. /// - public bool? IncludeDeletedData { get; init; } + public bool? IncludeDeletedData { get; set; } /// /// Whether to include the original data Merge fetched from the third-party to produce these models. /// - public bool? IncludeRemoteData { get; init; } + public bool? IncludeRemoteData { get; set; } /// /// Whether to include all remote fields, including fields that Merge did not map to common models, in a normalized format. /// - public bool? IncludeRemoteFields { get; init; } + public bool? IncludeRemoteFields { get; set; } /// /// If provided, only objects synced by Merge after this date time will be returned. /// - public DateTime? ModifiedAfter { get; init; } + public DateTime? ModifiedAfter { get; set; } /// /// If provided, only objects synced by Merge before this date time will be returned. /// - public DateTime? ModifiedBefore { get; init; } + public DateTime? ModifiedBefore { get; set; } /// /// Number of results to return per page. /// - public int? PageSize { get; init; } + public int? PageSize { get; set; } /// /// The API provider's ID for the given object. /// - public string? RemoteId { get; init; } + public string? RemoteId { get; set; } } diff --git a/src/Merge.Client/Crm/EngagementTypes/Requests/EngagementTypesRemoteFieldClassesListRequest.cs b/src/Merge.Client/Crm/EngagementTypes/Requests/EngagementTypesRemoteFieldClassesListRequest.cs index 4be7e207..2bfd7f69 100644 --- a/src/Merge.Client/Crm/EngagementTypes/Requests/EngagementTypesRemoteFieldClassesListRequest.cs +++ b/src/Merge.Client/Crm/EngagementTypes/Requests/EngagementTypesRemoteFieldClassesListRequest.cs @@ -1,34 +1,34 @@ namespace Merge.Client.Crm; -public class EngagementTypesRemoteFieldClassesListRequest +public record EngagementTypesRemoteFieldClassesListRequest { /// /// The pagination cursor value. /// - public string? Cursor { get; init; } + public string? Cursor { get; set; } /// /// Whether to include data that was marked as deleted by third party webhooks. /// - public bool? IncludeDeletedData { get; init; } + public bool? IncludeDeletedData { get; set; } /// /// Whether to include the original data Merge fetched from the third-party to produce these models. /// - public bool? IncludeRemoteData { get; init; } + public bool? IncludeRemoteData { get; set; } /// /// Whether to include all remote fields, including fields that Merge did not map to common models, in a normalized format. /// - public bool? IncludeRemoteFields { get; init; } + public bool? IncludeRemoteFields { get; set; } /// /// If provided, will only return remote field classes with this is_common_model_field value /// - public bool? IsCommonModelField { get; init; } + public bool? IsCommonModelField { get; set; } /// /// Number of results to return per page. /// - public int? PageSize { get; init; } + public int? PageSize { get; set; } } diff --git a/src/Merge.Client/Crm/EngagementTypes/Requests/EngagementTypesRetrieveRequest.cs b/src/Merge.Client/Crm/EngagementTypes/Requests/EngagementTypesRetrieveRequest.cs index 9c2a3e0b..51c39565 100644 --- a/src/Merge.Client/Crm/EngagementTypes/Requests/EngagementTypesRetrieveRequest.cs +++ b/src/Merge.Client/Crm/EngagementTypes/Requests/EngagementTypesRetrieveRequest.cs @@ -1,14 +1,14 @@ namespace Merge.Client.Crm; -public class EngagementTypesRetrieveRequest +public record EngagementTypesRetrieveRequest { /// /// Whether to include the original data Merge fetched from the third-party to produce these models. /// - public bool? IncludeRemoteData { get; init; } + public bool? IncludeRemoteData { get; set; } /// /// Whether to include all remote fields, including fields that Merge did not map to common models, in a normalized format. /// - public bool? IncludeRemoteFields { get; init; } + public bool? IncludeRemoteFields { get; set; } } diff --git a/src/Merge.Client/Crm/Engagements/EngagementsClient.cs b/src/Merge.Client/Crm/Engagements/EngagementsClient.cs index d673eb27..2ff8e4b6 100644 --- a/src/Merge.Client/Crm/Engagements/EngagementsClient.cs +++ b/src/Merge.Client/Crm/Engagements/EngagementsClient.cs @@ -1,6 +1,6 @@ +using System.Net.Http; using System.Text.Json; -using Merge.Client; -using Merge.Client.Crm; +using Merge.Client.Core; #nullable enable @@ -18,16 +18,21 @@ public EngagementsClient(RawClient client) /// /// Returns a list of `Engagement` objects. /// - public async Task ListAsync(EngagementsListRequest request) + public async Task ListAsync( + EngagementsListRequest request, + RequestOptions? options = null + ) { var _query = new Dictionary() { }; if (request.CreatedAfter != null) { - _query["created_after"] = request.CreatedAfter.Value.ToString("o0"); + _query["created_after"] = request.CreatedAfter.Value.ToString(Constants.DateTimeFormat); } if (request.CreatedBefore != null) { - _query["created_before"] = request.CreatedBefore.Value.ToString("o0"); + _query["created_before"] = request.CreatedBefore.Value.ToString( + Constants.DateTimeFormat + ); } if (request.Cursor != null) { @@ -51,11 +56,15 @@ public async Task ListAsync(EngagementsListRequest requ } if (request.ModifiedAfter != null) { - _query["modified_after"] = request.ModifiedAfter.Value.ToString("o0"); + _query["modified_after"] = request.ModifiedAfter.Value.ToString( + Constants.DateTimeFormat + ); } if (request.ModifiedBefore != null) { - _query["modified_before"] = request.ModifiedBefore.Value.ToString("o0"); + _query["modified_before"] = request.ModifiedBefore.Value.ToString( + Constants.DateTimeFormat + ); } if (request.PageSize != null) { @@ -67,32 +76,51 @@ public async Task ListAsync(EngagementsListRequest requ } if (request.StartedAfter != null) { - _query["started_after"] = request.StartedAfter.Value.ToString("o0"); + _query["started_after"] = request.StartedAfter.Value.ToString(Constants.DateTimeFormat); } if (request.StartedBefore != null) { - _query["started_before"] = request.StartedBefore.Value.ToString("o0"); + _query["started_before"] = request.StartedBefore.Value.ToString( + Constants.DateTimeFormat + ); } var response = await _client.MakeRequestAsync( new RawClient.JsonApiRequest { + BaseUrl = _client.Options.BaseUrl, Method = HttpMethod.Get, Path = "crm/v1/engagements", - Query = _query + Query = _query, + Options = options } ); - string responseBody = await response.Raw.Content.ReadAsStringAsync(); - if (response.StatusCode >= 200 && response.StatusCode < 400) + var responseBody = await response.Raw.Content.ReadAsStringAsync(); + if (response.StatusCode is >= 200 and < 400) { - return JsonSerializer.Deserialize(responseBody); + try + { + return JsonUtils.Deserialize(responseBody)!; + } + catch (JsonException e) + { + throw new MergeException("Failed to deserialize response", e); + } } - throw new Exception(responseBody); + + throw new MergeApiException( + $"Error with status code {response.StatusCode}", + response.StatusCode, + JsonUtils.Deserialize(responseBody) + ); } /// /// Creates an `Engagement` object with the given values. /// - public async Task CreateAsync(EngagementEndpointRequest request) + public async Task CreateAsync( + EngagementEndpointRequest request, + RequestOptions? options = null + ) { var _query = new Dictionary() { }; if (request.IsDebugMode != null) @@ -106,23 +134,41 @@ public async Task CreateAsync(EngagementEndpointRequest requ var response = await _client.MakeRequestAsync( new RawClient.JsonApiRequest { + BaseUrl = _client.Options.BaseUrl, Method = HttpMethod.Post, Path = "crm/v1/engagements", - Query = _query + Query = _query, + Options = options } ); - string responseBody = await response.Raw.Content.ReadAsStringAsync(); - if (response.StatusCode >= 200 && response.StatusCode < 400) + var responseBody = await response.Raw.Content.ReadAsStringAsync(); + if (response.StatusCode is >= 200 and < 400) { - return JsonSerializer.Deserialize(responseBody); + try + { + return JsonUtils.Deserialize(responseBody)!; + } + catch (JsonException e) + { + throw new MergeException("Failed to deserialize response", e); + } } - throw new Exception(responseBody); + + throw new MergeApiException( + $"Error with status code {response.StatusCode}", + response.StatusCode, + JsonUtils.Deserialize(responseBody) + ); } /// /// Returns an `Engagement` object with the given `id`. /// - public async Task RetrieveAsync(string id, EngagementsRetrieveRequest request) + public async Task RetrieveAsync( + string id, + EngagementsRetrieveRequest request, + RequestOptions? options = null + ) { var _query = new Dictionary() { }; if (request.Expand != null) @@ -140,17 +186,31 @@ public async Task RetrieveAsync(string id, EngagementsRetrieveReques var response = await _client.MakeRequestAsync( new RawClient.JsonApiRequest { + BaseUrl = _client.Options.BaseUrl, Method = HttpMethod.Get, Path = $"crm/v1/engagements/{id}", - Query = _query + Query = _query, + Options = options } ); - string responseBody = await response.Raw.Content.ReadAsStringAsync(); - if (response.StatusCode >= 200 && response.StatusCode < 400) + var responseBody = await response.Raw.Content.ReadAsStringAsync(); + if (response.StatusCode is >= 200 and < 400) { - return JsonSerializer.Deserialize(responseBody); + try + { + return JsonUtils.Deserialize(responseBody)!; + } + catch (JsonException e) + { + throw new MergeException("Failed to deserialize response", e); + } } - throw new Exception(responseBody); + + throw new MergeApiException( + $"Error with status code {response.StatusCode}", + response.StatusCode, + JsonUtils.Deserialize(responseBody) + ); } /// @@ -158,7 +218,8 @@ public async Task RetrieveAsync(string id, EngagementsRetrieveReques /// public async Task PartialUpdateAsync( string id, - PatchedEngagementEndpointRequest request + PatchedEngagementEndpointRequest request, + RequestOptions? options = null ) { var _query = new Dictionary() { }; @@ -173,64 +234,110 @@ PatchedEngagementEndpointRequest request var response = await _client.MakeRequestAsync( new RawClient.JsonApiRequest { - Method = HttpMethod.Patch, + BaseUrl = _client.Options.BaseUrl, + Method = HttpMethodExtensions.Patch, Path = $"crm/v1/engagements/{id}", - Query = _query + Query = _query, + Options = options } ); - string responseBody = await response.Raw.Content.ReadAsStringAsync(); - if (response.StatusCode >= 200 && response.StatusCode < 400) + var responseBody = await response.Raw.Content.ReadAsStringAsync(); + if (response.StatusCode is >= 200 and < 400) { - return JsonSerializer.Deserialize(responseBody); + try + { + return JsonUtils.Deserialize(responseBody)!; + } + catch (JsonException e) + { + throw new MergeException("Failed to deserialize response", e); + } } - throw new Exception(responseBody); + + throw new MergeApiException( + $"Error with status code {response.StatusCode}", + response.StatusCode, + JsonUtils.Deserialize(responseBody) + ); } /// /// Returns metadata for `Engagement` PATCHs. /// - public async Task MetaPatchRetrieveAsync(string id) + public async Task MetaPatchRetrieveAsync( + string id, + RequestOptions? options = null + ) { var response = await _client.MakeRequestAsync( new RawClient.JsonApiRequest { + BaseUrl = _client.Options.BaseUrl, Method = HttpMethod.Get, - Path = $"crm/v1/engagements/meta/patch/{id}" + Path = $"crm/v1/engagements/meta/patch/{id}", + Options = options } ); - string responseBody = await response.Raw.Content.ReadAsStringAsync(); - if (response.StatusCode >= 200 && response.StatusCode < 400) + var responseBody = await response.Raw.Content.ReadAsStringAsync(); + if (response.StatusCode is >= 200 and < 400) { - return JsonSerializer.Deserialize(responseBody); + try + { + return JsonUtils.Deserialize(responseBody)!; + } + catch (JsonException e) + { + throw new MergeException("Failed to deserialize response", e); + } } - throw new Exception(responseBody); + + throw new MergeApiException( + $"Error with status code {response.StatusCode}", + response.StatusCode, + JsonUtils.Deserialize(responseBody) + ); } /// /// Returns metadata for `Engagement` POSTs. /// - public async Task MetaPostRetrieveAsync() + public async Task MetaPostRetrieveAsync(RequestOptions? options = null) { var response = await _client.MakeRequestAsync( new RawClient.JsonApiRequest { + BaseUrl = _client.Options.BaseUrl, Method = HttpMethod.Get, - Path = "crm/v1/engagements/meta/post" + Path = "crm/v1/engagements/meta/post", + Options = options } ); - string responseBody = await response.Raw.Content.ReadAsStringAsync(); - if (response.StatusCode >= 200 && response.StatusCode < 400) + var responseBody = await response.Raw.Content.ReadAsStringAsync(); + if (response.StatusCode is >= 200 and < 400) { - return JsonSerializer.Deserialize(responseBody); + try + { + return JsonUtils.Deserialize(responseBody)!; + } + catch (JsonException e) + { + throw new MergeException("Failed to deserialize response", e); + } } - throw new Exception(responseBody); + + throw new MergeApiException( + $"Error with status code {response.StatusCode}", + response.StatusCode, + JsonUtils.Deserialize(responseBody) + ); } /// /// Returns a list of `RemoteFieldClass` objects. /// public async Task RemoteFieldClassesListAsync( - EngagementsRemoteFieldClassesListRequest request + EngagementsRemoteFieldClassesListRequest request, + RequestOptions? options = null ) { var _query = new Dictionary() { }; @@ -261,16 +368,30 @@ EngagementsRemoteFieldClassesListRequest request var response = await _client.MakeRequestAsync( new RawClient.JsonApiRequest { + BaseUrl = _client.Options.BaseUrl, Method = HttpMethod.Get, Path = "crm/v1/engagements/remote-field-classes", - Query = _query + Query = _query, + Options = options } ); - string responseBody = await response.Raw.Content.ReadAsStringAsync(); - if (response.StatusCode >= 200 && response.StatusCode < 400) + var responseBody = await response.Raw.Content.ReadAsStringAsync(); + if (response.StatusCode is >= 200 and < 400) { - return JsonSerializer.Deserialize(responseBody); + try + { + return JsonUtils.Deserialize(responseBody)!; + } + catch (JsonException e) + { + throw new MergeException("Failed to deserialize response", e); + } } - throw new Exception(responseBody); + + throw new MergeApiException( + $"Error with status code {response.StatusCode}", + response.StatusCode, + JsonUtils.Deserialize(responseBody) + ); } } diff --git a/src/Merge.Client/Crm/Engagements/Requests/EngagementEndpointRequest.cs b/src/Merge.Client/Crm/Engagements/Requests/EngagementEndpointRequest.cs index 40892ab7..7d76873e 100644 --- a/src/Merge.Client/Crm/Engagements/Requests/EngagementEndpointRequest.cs +++ b/src/Merge.Client/Crm/Engagements/Requests/EngagementEndpointRequest.cs @@ -1,20 +1,16 @@ -using Merge.Client.Crm; - -#nullable enable - namespace Merge.Client.Crm; -public class EngagementEndpointRequest +public record EngagementEndpointRequest { /// /// Whether to include debug fields (such as log file links) in the response. /// - public bool? IsDebugMode { get; init; } + public bool? IsDebugMode { get; set; } /// /// Whether or not third-party updates should be run asynchronously. /// - public bool? RunAsync { get; init; } + public bool? RunAsync { get; set; } - public EngagementRequest Model { get; init; } + public required EngagementRequest Model { get; set; } } diff --git a/src/Merge.Client/Crm/Engagements/Requests/EngagementsListRequest.cs b/src/Merge.Client/Crm/Engagements/Requests/EngagementsListRequest.cs index 091c896b..58604d8b 100644 --- a/src/Merge.Client/Crm/Engagements/Requests/EngagementsListRequest.cs +++ b/src/Merge.Client/Crm/Engagements/Requests/EngagementsListRequest.cs @@ -1,73 +1,69 @@ -using Merge.Client.Crm; - -#nullable enable - namespace Merge.Client.Crm; -public class EngagementsListRequest +public record EngagementsListRequest { /// /// If provided, will only return objects created after this datetime. /// - public DateTime? CreatedAfter { get; init; } + public DateTime? CreatedAfter { get; set; } /// /// If provided, will only return objects created before this datetime. /// - public DateTime? CreatedBefore { get; init; } + public DateTime? CreatedBefore { get; set; } /// /// The pagination cursor value. /// - public string? Cursor { get; init; } + public string? Cursor { get; set; } /// /// Which relations should be returned in expanded form. Multiple relation names should be comma separated without spaces. /// - public EngagementsListRequestExpand? Expand { get; init; } + public EngagementsListRequestExpand? Expand { get; set; } /// /// Whether to include data that was marked as deleted by third party webhooks. /// - public bool? IncludeDeletedData { get; init; } + public bool? IncludeDeletedData { get; set; } /// /// Whether to include the original data Merge fetched from the third-party to produce these models. /// - public bool? IncludeRemoteData { get; init; } + public bool? IncludeRemoteData { get; set; } /// /// Whether to include all remote fields, including fields that Merge did not map to common models, in a normalized format. /// - public bool? IncludeRemoteFields { get; init; } + public bool? IncludeRemoteFields { get; set; } /// /// If provided, only objects synced by Merge after this date time will be returned. /// - public DateTime? ModifiedAfter { get; init; } + public DateTime? ModifiedAfter { get; set; } /// /// If provided, only objects synced by Merge before this date time will be returned. /// - public DateTime? ModifiedBefore { get; init; } + public DateTime? ModifiedBefore { get; set; } /// /// Number of results to return per page. /// - public int? PageSize { get; init; } + public int? PageSize { get; set; } /// /// The API provider's ID for the given object. /// - public string? RemoteId { get; init; } + public string? RemoteId { get; set; } /// /// If provided, will only return engagements started after this datetime. /// - public DateTime? StartedAfter { get; init; } + public DateTime? StartedAfter { get; set; } /// /// If provided, will only return engagements started before this datetime. /// - public DateTime? StartedBefore { get; init; } + public DateTime? StartedBefore { get; set; } } diff --git a/src/Merge.Client/Crm/Engagements/Requests/EngagementsRemoteFieldClassesListRequest.cs b/src/Merge.Client/Crm/Engagements/Requests/EngagementsRemoteFieldClassesListRequest.cs index f858fec5..732b34c7 100644 --- a/src/Merge.Client/Crm/Engagements/Requests/EngagementsRemoteFieldClassesListRequest.cs +++ b/src/Merge.Client/Crm/Engagements/Requests/EngagementsRemoteFieldClassesListRequest.cs @@ -1,34 +1,34 @@ namespace Merge.Client.Crm; -public class EngagementsRemoteFieldClassesListRequest +public record EngagementsRemoteFieldClassesListRequest { /// /// The pagination cursor value. /// - public string? Cursor { get; init; } + public string? Cursor { get; set; } /// /// Whether to include data that was marked as deleted by third party webhooks. /// - public bool? IncludeDeletedData { get; init; } + public bool? IncludeDeletedData { get; set; } /// /// Whether to include the original data Merge fetched from the third-party to produce these models. /// - public bool? IncludeRemoteData { get; init; } + public bool? IncludeRemoteData { get; set; } /// /// Whether to include all remote fields, including fields that Merge did not map to common models, in a normalized format. /// - public bool? IncludeRemoteFields { get; init; } + public bool? IncludeRemoteFields { get; set; } /// /// If provided, will only return remote field classes with this is_common_model_field value /// - public bool? IsCommonModelField { get; init; } + public bool? IsCommonModelField { get; set; } /// /// Number of results to return per page. /// - public int? PageSize { get; init; } + public int? PageSize { get; set; } } diff --git a/src/Merge.Client/Crm/Engagements/Requests/EngagementsRetrieveRequest.cs b/src/Merge.Client/Crm/Engagements/Requests/EngagementsRetrieveRequest.cs index 950096b1..efd98cf7 100644 --- a/src/Merge.Client/Crm/Engagements/Requests/EngagementsRetrieveRequest.cs +++ b/src/Merge.Client/Crm/Engagements/Requests/EngagementsRetrieveRequest.cs @@ -1,23 +1,19 @@ -using Merge.Client.Crm; - -#nullable enable - namespace Merge.Client.Crm; -public class EngagementsRetrieveRequest +public record EngagementsRetrieveRequest { /// /// Which relations should be returned in expanded form. Multiple relation names should be comma separated without spaces. /// - public EngagementsRetrieveRequestExpand? Expand { get; init; } + public EngagementsRetrieveRequestExpand? Expand { get; set; } /// /// Whether to include the original data Merge fetched from the third-party to produce these models. /// - public bool? IncludeRemoteData { get; init; } + public bool? IncludeRemoteData { get; set; } /// /// Whether to include all remote fields, including fields that Merge did not map to common models, in a normalized format. /// - public bool? IncludeRemoteFields { get; init; } + public bool? IncludeRemoteFields { get; set; } } diff --git a/src/Merge.Client/Crm/Engagements/Requests/PatchedEngagementEndpointRequest.cs b/src/Merge.Client/Crm/Engagements/Requests/PatchedEngagementEndpointRequest.cs index 2f093cec..801eb784 100644 --- a/src/Merge.Client/Crm/Engagements/Requests/PatchedEngagementEndpointRequest.cs +++ b/src/Merge.Client/Crm/Engagements/Requests/PatchedEngagementEndpointRequest.cs @@ -1,20 +1,16 @@ -using Merge.Client.Crm; - -#nullable enable - namespace Merge.Client.Crm; -public class PatchedEngagementEndpointRequest +public record PatchedEngagementEndpointRequest { /// /// Whether to include debug fields (such as log file links) in the response. /// - public bool? IsDebugMode { get; init; } + public bool? IsDebugMode { get; set; } /// /// Whether or not third-party updates should be run asynchronously. /// - public bool? RunAsync { get; init; } + public bool? RunAsync { get; set; } - public PatchedEngagementRequest Model { get; init; } + public required PatchedEngagementRequest Model { get; set; } } diff --git a/src/Merge.Client/Crm/Engagements/Types/EngagementsListRequestExpand.cs b/src/Merge.Client/Crm/Engagements/Types/EngagementsListRequestExpand.cs index 9b925ba9..af747bee 100644 --- a/src/Merge.Client/Crm/Engagements/Types/EngagementsListRequestExpand.cs +++ b/src/Merge.Client/Crm/Engagements/Types/EngagementsListRequestExpand.cs @@ -1,7 +1,6 @@ using System.Runtime.Serialization; using System.Text.Json.Serialization; using Merge.Client.Core; -using Merge.Client.Crm; #nullable enable diff --git a/src/Merge.Client/Crm/Engagements/Types/EngagementsRetrieveRequestExpand.cs b/src/Merge.Client/Crm/Engagements/Types/EngagementsRetrieveRequestExpand.cs index 1e41b9a2..ce927720 100644 --- a/src/Merge.Client/Crm/Engagements/Types/EngagementsRetrieveRequestExpand.cs +++ b/src/Merge.Client/Crm/Engagements/Types/EngagementsRetrieveRequestExpand.cs @@ -1,7 +1,6 @@ using System.Runtime.Serialization; using System.Text.Json.Serialization; using Merge.Client.Core; -using Merge.Client.Crm; #nullable enable diff --git a/src/Merge.Client/Crm/FieldMapping/FieldMappingClient.cs b/src/Merge.Client/Crm/FieldMapping/FieldMappingClient.cs index 64b842c5..a3de0e1b 100644 --- a/src/Merge.Client/Crm/FieldMapping/FieldMappingClient.cs +++ b/src/Merge.Client/Crm/FieldMapping/FieldMappingClient.cs @@ -1,6 +1,6 @@ +using System.Net.Http; using System.Text.Json; -using Merge.Client; -using Merge.Client.Crm; +using Merge.Client.Core; #nullable enable @@ -18,60 +18,112 @@ public FieldMappingClient(RawClient client) /// /// Get all Field Mappings for this Linked Account. Field Mappings are mappings between third-party Remote Fields and user defined Merge fields. [Learn more](https://docs.merge.dev/supplemental-data/field-mappings/overview/). /// - public async Task FieldMappingsRetrieveAsync() + public async Task FieldMappingsRetrieveAsync( + RequestOptions? options = null + ) { var response = await _client.MakeRequestAsync( - new RawClient.JsonApiRequest { Method = HttpMethod.Get, Path = "crm/v1/field-mappings" } + new RawClient.JsonApiRequest + { + BaseUrl = _client.Options.BaseUrl, + Method = HttpMethod.Get, + Path = "crm/v1/field-mappings", + Options = options + } ); - string responseBody = await response.Raw.Content.ReadAsStringAsync(); - if (response.StatusCode >= 200 && response.StatusCode < 400) + var responseBody = await response.Raw.Content.ReadAsStringAsync(); + if (response.StatusCode is >= 200 and < 400) { - return JsonSerializer.Deserialize(responseBody); + try + { + return JsonUtils.Deserialize(responseBody)!; + } + catch (JsonException e) + { + throw new MergeException("Failed to deserialize response", e); + } } - throw new Exception(responseBody); + + throw new MergeApiException( + $"Error with status code {response.StatusCode}", + response.StatusCode, + JsonUtils.Deserialize(responseBody) + ); } /// /// Create new Field Mappings that will be available after the next scheduled sync. This will cause the next sync for this Linked Account to sync **ALL** data from start. /// public async Task FieldMappingsCreateAsync( - CreateFieldMappingRequest request + CreateFieldMappingRequest request, + RequestOptions? options = null ) { var response = await _client.MakeRequestAsync( new RawClient.JsonApiRequest { + BaseUrl = _client.Options.BaseUrl, Method = HttpMethod.Post, Path = "crm/v1/field-mappings", - Body = request + Body = request, + Options = options } ); - string responseBody = await response.Raw.Content.ReadAsStringAsync(); - if (response.StatusCode >= 200 && response.StatusCode < 400) + var responseBody = await response.Raw.Content.ReadAsStringAsync(); + if (response.StatusCode is >= 200 and < 400) { - return JsonSerializer.Deserialize(responseBody); + try + { + return JsonUtils.Deserialize(responseBody)!; + } + catch (JsonException e) + { + throw new MergeException("Failed to deserialize response", e); + } } - throw new Exception(responseBody); + + throw new MergeApiException( + $"Error with status code {response.StatusCode}", + response.StatusCode, + JsonUtils.Deserialize(responseBody) + ); } /// /// Deletes Field Mappings for a Linked Account. All data related to this Field Mapping will be deleted and these changes will be reflected after the next scheduled sync. This will cause the next sync for this Linked Account to sync **ALL** data from start. /// - public async Task FieldMappingsDestroyAsync(string fieldMappingId) + public async Task FieldMappingsDestroyAsync( + string fieldMappingId, + RequestOptions? options = null + ) { var response = await _client.MakeRequestAsync( new RawClient.JsonApiRequest { + BaseUrl = _client.Options.BaseUrl, Method = HttpMethod.Delete, - Path = $"crm/v1/field-mappings/{fieldMappingId}" + Path = $"crm/v1/field-mappings/{fieldMappingId}", + Options = options } ); - string responseBody = await response.Raw.Content.ReadAsStringAsync(); - if (response.StatusCode >= 200 && response.StatusCode < 400) + var responseBody = await response.Raw.Content.ReadAsStringAsync(); + if (response.StatusCode is >= 200 and < 400) { - return JsonSerializer.Deserialize(responseBody); + try + { + return JsonUtils.Deserialize(responseBody)!; + } + catch (JsonException e) + { + throw new MergeException("Failed to deserialize response", e); + } } - throw new Exception(responseBody); + + throw new MergeApiException( + $"Error with status code {response.StatusCode}", + response.StatusCode, + JsonUtils.Deserialize(responseBody) + ); } /// @@ -79,30 +131,46 @@ public async Task FieldMappingsDestroyAsync(string /// public async Task FieldMappingsPartialUpdateAsync( string fieldMappingId, - PatchedEditFieldMappingRequest request + PatchedEditFieldMappingRequest request, + RequestOptions? options = null ) { var response = await _client.MakeRequestAsync( new RawClient.JsonApiRequest { - Method = HttpMethod.Patch, + BaseUrl = _client.Options.BaseUrl, + Method = HttpMethodExtensions.Patch, Path = $"crm/v1/field-mappings/{fieldMappingId}", - Body = request + Body = request, + Options = options } ); - string responseBody = await response.Raw.Content.ReadAsStringAsync(); - if (response.StatusCode >= 200 && response.StatusCode < 400) + var responseBody = await response.Raw.Content.ReadAsStringAsync(); + if (response.StatusCode is >= 200 and < 400) { - return JsonSerializer.Deserialize(responseBody); + try + { + return JsonUtils.Deserialize(responseBody)!; + } + catch (JsonException e) + { + throw new MergeException("Failed to deserialize response", e); + } } - throw new Exception(responseBody); + + throw new MergeApiException( + $"Error with status code {response.StatusCode}", + response.StatusCode, + JsonUtils.Deserialize(responseBody) + ); } /// /// Get all remote fields for a Linked Account. Remote fields are third-party fields that are accessible after initial sync if remote_data is enabled. You can use remote fields to override existing Merge fields or map a new Merge field. [Learn more](https://docs.merge.dev/supplemental-data/field-mappings/overview/). /// public async Task RemoteFieldsRetrieveAsync( - RemoteFieldsRetrieveRequest request + RemoteFieldsRetrieveRequest request, + RequestOptions? options = null ) { var _query = new Dictionary() { }; @@ -117,32 +185,66 @@ RemoteFieldsRetrieveRequest request var response = await _client.MakeRequestAsync( new RawClient.JsonApiRequest { + BaseUrl = _client.Options.BaseUrl, Method = HttpMethod.Get, Path = "crm/v1/remote-fields", - Query = _query + Query = _query, + Options = options } ); - string responseBody = await response.Raw.Content.ReadAsStringAsync(); - if (response.StatusCode >= 200 && response.StatusCode < 400) + var responseBody = await response.Raw.Content.ReadAsStringAsync(); + if (response.StatusCode is >= 200 and < 400) { - return JsonSerializer.Deserialize(responseBody); + try + { + return JsonUtils.Deserialize(responseBody)!; + } + catch (JsonException e) + { + throw new MergeException("Failed to deserialize response", e); + } } - throw new Exception(responseBody); + + throw new MergeApiException( + $"Error with status code {response.StatusCode}", + response.StatusCode, + JsonUtils.Deserialize(responseBody) + ); } /// /// Get all organization-wide Target Fields, this will not include any Linked Account specific Target Fields. Organization-wide Target Fields are additional fields appended to the Merge Common Model for all Linked Accounts in a category. [Learn more](https://docs.merge.dev/supplemental-data/field-mappings/target-fields/). /// - public async Task TargetFieldsRetrieveAsync() + public async Task TargetFieldsRetrieveAsync( + RequestOptions? options = null + ) { var response = await _client.MakeRequestAsync( - new RawClient.JsonApiRequest { Method = HttpMethod.Get, Path = "crm/v1/target-fields" } + new RawClient.JsonApiRequest + { + BaseUrl = _client.Options.BaseUrl, + Method = HttpMethod.Get, + Path = "crm/v1/target-fields", + Options = options + } ); - string responseBody = await response.Raw.Content.ReadAsStringAsync(); - if (response.StatusCode >= 200 && response.StatusCode < 400) + var responseBody = await response.Raw.Content.ReadAsStringAsync(); + if (response.StatusCode is >= 200 and < 400) { - return JsonSerializer.Deserialize(responseBody); + try + { + return JsonUtils.Deserialize(responseBody)!; + } + catch (JsonException e) + { + throw new MergeException("Failed to deserialize response", e); + } } - throw new Exception(responseBody); + + throw new MergeApiException( + $"Error with status code {response.StatusCode}", + response.StatusCode, + JsonUtils.Deserialize(responseBody) + ); } } diff --git a/src/Merge.Client/Crm/FieldMapping/Requests/CreateFieldMappingRequest.cs b/src/Merge.Client/Crm/FieldMapping/Requests/CreateFieldMappingRequest.cs index 5818a5d1..33f313df 100644 --- a/src/Merge.Client/Crm/FieldMapping/Requests/CreateFieldMappingRequest.cs +++ b/src/Merge.Client/Crm/FieldMapping/Requests/CreateFieldMappingRequest.cs @@ -4,41 +4,41 @@ namespace Merge.Client.Crm; -public class CreateFieldMappingRequest +public record CreateFieldMappingRequest { /// /// The name of the target field you want this remote field to map to. /// [JsonPropertyName("target_field_name")] - public string TargetFieldName { get; init; } + public required string TargetFieldName { get; set; } /// /// The description of the target field you want this remote field to map to. /// [JsonPropertyName("target_field_description")] - public string TargetFieldDescription { get; init; } + public required string TargetFieldDescription { get; set; } /// /// The field traversal path of the remote field listed when you hit the GET /remote-fields endpoint. /// [JsonPropertyName("remote_field_traversal_path")] - public IEnumerable RemoteFieldTraversalPath { get; init; } + public IEnumerable RemoteFieldTraversalPath { get; set; } = new List(); /// /// The method of the remote endpoint where the remote field is coming from. /// [JsonPropertyName("remote_method")] - public string RemoteMethod { get; init; } + public required string RemoteMethod { get; set; } /// /// The path of the remote endpoint where the remote field is coming from. /// [JsonPropertyName("remote_url_path")] - public string RemoteUrlPath { get; init; } + public required string RemoteUrlPath { get; set; } /// /// The name of the Common Model that the remote field corresponds to in a given category. /// [JsonPropertyName("common_model_name")] - public string CommonModelName { get; init; } + public required string CommonModelName { get; set; } } diff --git a/src/Merge.Client/Crm/FieldMapping/Requests/PatchedEditFieldMappingRequest.cs b/src/Merge.Client/Crm/FieldMapping/Requests/PatchedEditFieldMappingRequest.cs index aa2267b4..66850be7 100644 --- a/src/Merge.Client/Crm/FieldMapping/Requests/PatchedEditFieldMappingRequest.cs +++ b/src/Merge.Client/Crm/FieldMapping/Requests/PatchedEditFieldMappingRequest.cs @@ -4,23 +4,23 @@ namespace Merge.Client.Crm; -public class PatchedEditFieldMappingRequest +public record PatchedEditFieldMappingRequest { /// /// The field traversal path of the remote field listed when you hit the GET /remote-fields endpoint. /// [JsonPropertyName("remote_field_traversal_path")] - public IEnumerable? RemoteFieldTraversalPath { get; init; } + public IEnumerable? RemoteFieldTraversalPath { get; set; } /// /// The method of the remote endpoint where the remote field is coming from. /// [JsonPropertyName("remote_method")] - public string? RemoteMethod { get; init; } + public string? RemoteMethod { get; set; } /// /// The path of the remote endpoint where the remote field is coming from. /// [JsonPropertyName("remote_url_path")] - public string? RemoteUrlPath { get; init; } + public string? RemoteUrlPath { get; set; } } diff --git a/src/Merge.Client/Crm/FieldMapping/Requests/RemoteFieldsRetrieveRequest.cs b/src/Merge.Client/Crm/FieldMapping/Requests/RemoteFieldsRetrieveRequest.cs index 12dbacdd..5d3c69f2 100644 --- a/src/Merge.Client/Crm/FieldMapping/Requests/RemoteFieldsRetrieveRequest.cs +++ b/src/Merge.Client/Crm/FieldMapping/Requests/RemoteFieldsRetrieveRequest.cs @@ -1,14 +1,14 @@ namespace Merge.Client.Crm; -public class RemoteFieldsRetrieveRequest +public record RemoteFieldsRetrieveRequest { /// /// A comma seperated list of Common Model names. If included, will only return Remote Fields for those Common Models. /// - public string? CommonModels { get; init; } + public string? CommonModels { get; set; } /// /// If true, will include example values, where available, for remote fields in the 3rd party platform. These examples come from active data from your customers. /// - public string? IncludeExampleValues { get; init; } + public string? IncludeExampleValues { get; set; } } diff --git a/src/Merge.Client/Crm/ForceResync/ForceResyncClient.cs b/src/Merge.Client/Crm/ForceResync/ForceResyncClient.cs index b9b1075d..6f6cb3d6 100644 --- a/src/Merge.Client/Crm/ForceResync/ForceResyncClient.cs +++ b/src/Merge.Client/Crm/ForceResync/ForceResyncClient.cs @@ -1,6 +1,6 @@ +using System.Net.Http; using System.Text.Json; -using Merge.Client; -using Merge.Client.Crm; +using Merge.Client.Core; #nullable enable @@ -18,20 +18,36 @@ public ForceResyncClient(RawClient client) /// /// Force re-sync of all models. This is available for all organizations via the dashboard. Force re-sync is also available programmatically via API for monthly, quarterly, and highest sync frequency customers on the Launch, Professional, or Enterprise plans. Doing so will consume a sync credit for the relevant linked account. /// - public async Task> SyncStatusResyncCreateAsync() + public async Task> SyncStatusResyncCreateAsync( + RequestOptions? options = null + ) { var response = await _client.MakeRequestAsync( new RawClient.JsonApiRequest { + BaseUrl = _client.Options.BaseUrl, Method = HttpMethod.Post, - Path = "crm/v1/sync-status/resync" + Path = "crm/v1/sync-status/resync", + Options = options } ); - string responseBody = await response.Raw.Content.ReadAsStringAsync(); - if (response.StatusCode >= 200 && response.StatusCode < 400) + var responseBody = await response.Raw.Content.ReadAsStringAsync(); + if (response.StatusCode is >= 200 and < 400) { - return JsonSerializer.Deserialize>(responseBody); + try + { + return JsonUtils.Deserialize>(responseBody)!; + } + catch (JsonException e) + { + throw new MergeException("Failed to deserialize response", e); + } } - throw new Exception(responseBody); + + throw new MergeApiException( + $"Error with status code {response.StatusCode}", + response.StatusCode, + JsonUtils.Deserialize(responseBody) + ); } } diff --git a/src/Merge.Client/Crm/GenerateKey/GenerateKeyClient.cs b/src/Merge.Client/Crm/GenerateKey/GenerateKeyClient.cs index f1bb1e62..fa2862f8 100644 --- a/src/Merge.Client/Crm/GenerateKey/GenerateKeyClient.cs +++ b/src/Merge.Client/Crm/GenerateKey/GenerateKeyClient.cs @@ -1,6 +1,6 @@ +using System.Net.Http; using System.Text.Json; -using Merge.Client; -using Merge.Client.Crm; +using Merge.Client.Core; #nullable enable @@ -18,21 +18,38 @@ public GenerateKeyClient(RawClient client) /// /// Create a remote key. /// - public async Task CreateAsync(GenerateRemoteKeyRequest request) + public async Task CreateAsync( + GenerateRemoteKeyRequest request, + RequestOptions? options = null + ) { var response = await _client.MakeRequestAsync( new RawClient.JsonApiRequest { + BaseUrl = _client.Options.BaseUrl, Method = HttpMethod.Post, Path = "crm/v1/generate-key", - Body = request + Body = request, + Options = options } ); - string responseBody = await response.Raw.Content.ReadAsStringAsync(); - if (response.StatusCode >= 200 && response.StatusCode < 400) + var responseBody = await response.Raw.Content.ReadAsStringAsync(); + if (response.StatusCode is >= 200 and < 400) { - return JsonSerializer.Deserialize(responseBody); + try + { + return JsonUtils.Deserialize(responseBody)!; + } + catch (JsonException e) + { + throw new MergeException("Failed to deserialize response", e); + } } - throw new Exception(responseBody); + + throw new MergeApiException( + $"Error with status code {response.StatusCode}", + response.StatusCode, + JsonUtils.Deserialize(responseBody) + ); } } diff --git a/src/Merge.Client/Crm/GenerateKey/Requests/GenerateRemoteKeyRequest.cs b/src/Merge.Client/Crm/GenerateKey/Requests/GenerateRemoteKeyRequest.cs index 7c342d38..3d98234e 100644 --- a/src/Merge.Client/Crm/GenerateKey/Requests/GenerateRemoteKeyRequest.cs +++ b/src/Merge.Client/Crm/GenerateKey/Requests/GenerateRemoteKeyRequest.cs @@ -4,11 +4,11 @@ namespace Merge.Client.Crm; -public class GenerateRemoteKeyRequest +public record GenerateRemoteKeyRequest { /// /// The name of the remote key /// [JsonPropertyName("name")] - public string Name { get; init; } + public required string Name { get; set; } } diff --git a/src/Merge.Client/Crm/Issues/IssuesClient.cs b/src/Merge.Client/Crm/Issues/IssuesClient.cs index 6bf9dc12..de8fff6c 100644 --- a/src/Merge.Client/Crm/Issues/IssuesClient.cs +++ b/src/Merge.Client/Crm/Issues/IssuesClient.cs @@ -1,6 +1,6 @@ +using System.Net.Http; using System.Text.Json; -using Merge.Client; -using Merge.Client.Crm; +using Merge.Client.Core; #nullable enable @@ -18,7 +18,10 @@ public IssuesClient(RawClient client) /// /// Gets all issues for Organization. /// - public async Task ListAsync(IssuesListRequest request) + public async Task ListAsync( + IssuesListRequest request, + RequestOptions? options = null + ) { var _query = new Dictionary() { }; if (request.AccountToken != null) @@ -40,13 +43,13 @@ public async Task ListAsync(IssuesListRequest request) if (request.FirstIncidentTimeAfter != null) { _query["first_incident_time_after"] = request.FirstIncidentTimeAfter.Value.ToString( - "o0" + Constants.DateTimeFormat ); } if (request.FirstIncidentTimeBefore != null) { _query["first_incident_time_before"] = request.FirstIncidentTimeBefore.Value.ToString( - "o0" + Constants.DateTimeFormat ); } if (request.IncludeMuted != null) @@ -59,12 +62,14 @@ public async Task ListAsync(IssuesListRequest request) } if (request.LastIncidentTimeAfter != null) { - _query["last_incident_time_after"] = request.LastIncidentTimeAfter.Value.ToString("o0"); + _query["last_incident_time_after"] = request.LastIncidentTimeAfter.Value.ToString( + Constants.DateTimeFormat + ); } if (request.LastIncidentTimeBefore != null) { _query["last_incident_time_before"] = request.LastIncidentTimeBefore.Value.ToString( - "o0" + Constants.DateTimeFormat ); } if (request.LinkedAccountId != null) @@ -86,32 +91,64 @@ public async Task ListAsync(IssuesListRequest request) var response = await _client.MakeRequestAsync( new RawClient.JsonApiRequest { + BaseUrl = _client.Options.BaseUrl, Method = HttpMethod.Get, Path = "crm/v1/issues", - Query = _query + Query = _query, + Options = options } ); - string responseBody = await response.Raw.Content.ReadAsStringAsync(); - if (response.StatusCode >= 200 && response.StatusCode < 400) + var responseBody = await response.Raw.Content.ReadAsStringAsync(); + if (response.StatusCode is >= 200 and < 400) { - return JsonSerializer.Deserialize(responseBody); + try + { + return JsonUtils.Deserialize(responseBody)!; + } + catch (JsonException e) + { + throw new MergeException("Failed to deserialize response", e); + } } - throw new Exception(responseBody); + + throw new MergeApiException( + $"Error with status code {response.StatusCode}", + response.StatusCode, + JsonUtils.Deserialize(responseBody) + ); } /// /// Get a specific issue. /// - public async Task RetrieveAsync(string id) + public async Task RetrieveAsync(string id, RequestOptions? options = null) { var response = await _client.MakeRequestAsync( - new RawClient.JsonApiRequest { Method = HttpMethod.Get, Path = $"crm/v1/issues/{id}" } + new RawClient.JsonApiRequest + { + BaseUrl = _client.Options.BaseUrl, + Method = HttpMethod.Get, + Path = $"crm/v1/issues/{id}", + Options = options + } ); - string responseBody = await response.Raw.Content.ReadAsStringAsync(); - if (response.StatusCode >= 200 && response.StatusCode < 400) + var responseBody = await response.Raw.Content.ReadAsStringAsync(); + if (response.StatusCode is >= 200 and < 400) { - return JsonSerializer.Deserialize(responseBody); + try + { + return JsonUtils.Deserialize(responseBody)!; + } + catch (JsonException e) + { + throw new MergeException("Failed to deserialize response", e); + } } - throw new Exception(responseBody); + + throw new MergeApiException( + $"Error with status code {response.StatusCode}", + response.StatusCode, + JsonUtils.Deserialize(responseBody) + ); } } diff --git a/src/Merge.Client/Crm/Issues/Requests/IssuesListRequest.cs b/src/Merge.Client/Crm/Issues/Requests/IssuesListRequest.cs index 74dcd585..f36b535a 100644 --- a/src/Merge.Client/Crm/Issues/Requests/IssuesListRequest.cs +++ b/src/Merge.Client/Crm/Issues/Requests/IssuesListRequest.cs @@ -1,66 +1,62 @@ -using Merge.Client.Crm; - -#nullable enable - namespace Merge.Client.Crm; -public class IssuesListRequest +public record IssuesListRequest { - public string? AccountToken { get; init; } + public string? AccountToken { get; set; } /// /// The pagination cursor value. /// - public string? Cursor { get; init; } + public string? Cursor { get; set; } /// /// If included, will only include issues whose most recent action occurred before this time /// - public string? EndDate { get; init; } + public string? EndDate { get; set; } - public string? EndUserOrganizationName { get; init; } + public string? EndUserOrganizationName { get; set; } /// /// If provided, will only return issues whose first incident time was after this datetime. /// - public DateTime? FirstIncidentTimeAfter { get; init; } + public DateTime? FirstIncidentTimeAfter { get; set; } /// /// If provided, will only return issues whose first incident time was before this datetime. /// - public DateTime? FirstIncidentTimeBefore { get; init; } + public DateTime? FirstIncidentTimeBefore { get; set; } /// /// If true, will include muted issues /// - public string? IncludeMuted { get; init; } + public string? IncludeMuted { get; set; } - public string? IntegrationName { get; init; } + public string? IntegrationName { get; set; } /// /// If provided, will only return issues whose last incident time was after this datetime. /// - public DateTime? LastIncidentTimeAfter { get; init; } + public DateTime? LastIncidentTimeAfter { get; set; } /// /// If provided, will only return issues whose last incident time was before this datetime. /// - public DateTime? LastIncidentTimeBefore { get; init; } + public DateTime? LastIncidentTimeBefore { get; set; } /// /// If provided, will only include issues pertaining to the linked account passed in. /// - public string? LinkedAccountId { get; init; } + public string? LinkedAccountId { get; set; } /// /// Number of results to return per page. /// - public int? PageSize { get; init; } + public int? PageSize { get; set; } /// /// If included, will only include issues whose most recent action occurred after this time /// - public string? StartDate { get; init; } + public string? StartDate { get; set; } /// /// Status of the issue. Options: ('ONGOING', 'RESOLVED') @@ -68,5 +64,5 @@ public class IssuesListRequest /// - `ONGOING` - ONGOING /// - `RESOLVED` - RESOLVED /// - public IssuesListRequestStatus? Status { get; init; } + public IssuesListRequestStatus? Status { get; set; } } diff --git a/src/Merge.Client/Crm/Issues/Types/IssuesListRequestStatus.cs b/src/Merge.Client/Crm/Issues/Types/IssuesListRequestStatus.cs index a4ef7cc5..85dfcc60 100644 --- a/src/Merge.Client/Crm/Issues/Types/IssuesListRequestStatus.cs +++ b/src/Merge.Client/Crm/Issues/Types/IssuesListRequestStatus.cs @@ -1,7 +1,6 @@ using System.Runtime.Serialization; using System.Text.Json.Serialization; using Merge.Client.Core; -using Merge.Client.Crm; #nullable enable diff --git a/src/Merge.Client/Crm/Leads/LeadsClient.cs b/src/Merge.Client/Crm/Leads/LeadsClient.cs index 930e8a33..0d8207d2 100644 --- a/src/Merge.Client/Crm/Leads/LeadsClient.cs +++ b/src/Merge.Client/Crm/Leads/LeadsClient.cs @@ -1,6 +1,6 @@ +using System.Net.Http; using System.Text.Json; -using Merge.Client; -using Merge.Client.Crm; +using Merge.Client.Core; #nullable enable @@ -18,7 +18,10 @@ public LeadsClient(RawClient client) /// /// Returns a list of `Lead` objects. /// - public async Task ListAsync(LeadsListRequest request) + public async Task ListAsync( + LeadsListRequest request, + RequestOptions? options = null + ) { var _query = new Dictionary() { }; if (request.ConvertedAccountId != null) @@ -31,11 +34,13 @@ public async Task ListAsync(LeadsListRequest request) } if (request.CreatedAfter != null) { - _query["created_after"] = request.CreatedAfter.Value.ToString("o0"); + _query["created_after"] = request.CreatedAfter.Value.ToString(Constants.DateTimeFormat); } if (request.CreatedBefore != null) { - _query["created_before"] = request.CreatedBefore.Value.ToString("o0"); + _query["created_before"] = request.CreatedBefore.Value.ToString( + Constants.DateTimeFormat + ); } if (request.Cursor != null) { @@ -63,11 +68,15 @@ public async Task ListAsync(LeadsListRequest request) } if (request.ModifiedAfter != null) { - _query["modified_after"] = request.ModifiedAfter.Value.ToString("o0"); + _query["modified_after"] = request.ModifiedAfter.Value.ToString( + Constants.DateTimeFormat + ); } if (request.ModifiedBefore != null) { - _query["modified_before"] = request.ModifiedBefore.Value.ToString("o0"); + _query["modified_before"] = request.ModifiedBefore.Value.ToString( + Constants.DateTimeFormat + ); } if (request.OwnerId != null) { @@ -88,23 +97,40 @@ public async Task ListAsync(LeadsListRequest request) var response = await _client.MakeRequestAsync( new RawClient.JsonApiRequest { + BaseUrl = _client.Options.BaseUrl, Method = HttpMethod.Get, Path = "crm/v1/leads", - Query = _query + Query = _query, + Options = options } ); - string responseBody = await response.Raw.Content.ReadAsStringAsync(); - if (response.StatusCode >= 200 && response.StatusCode < 400) + var responseBody = await response.Raw.Content.ReadAsStringAsync(); + if (response.StatusCode is >= 200 and < 400) { - return JsonSerializer.Deserialize(responseBody); + try + { + return JsonUtils.Deserialize(responseBody)!; + } + catch (JsonException e) + { + throw new MergeException("Failed to deserialize response", e); + } } - throw new Exception(responseBody); + + throw new MergeApiException( + $"Error with status code {response.StatusCode}", + response.StatusCode, + JsonUtils.Deserialize(responseBody) + ); } /// /// Creates a `Lead` object with the given values. /// - public async Task CreateAsync(LeadEndpointRequest request) + public async Task CreateAsync( + LeadEndpointRequest request, + RequestOptions? options = null + ) { var _query = new Dictionary() { }; if (request.IsDebugMode != null) @@ -118,23 +144,41 @@ public async Task CreateAsync(LeadEndpointRequest request) var response = await _client.MakeRequestAsync( new RawClient.JsonApiRequest { + BaseUrl = _client.Options.BaseUrl, Method = HttpMethod.Post, Path = "crm/v1/leads", - Query = _query + Query = _query, + Options = options } ); - string responseBody = await response.Raw.Content.ReadAsStringAsync(); - if (response.StatusCode >= 200 && response.StatusCode < 400) + var responseBody = await response.Raw.Content.ReadAsStringAsync(); + if (response.StatusCode is >= 200 and < 400) { - return JsonSerializer.Deserialize(responseBody); + try + { + return JsonUtils.Deserialize(responseBody)!; + } + catch (JsonException e) + { + throw new MergeException("Failed to deserialize response", e); + } } - throw new Exception(responseBody); + + throw new MergeApiException( + $"Error with status code {response.StatusCode}", + response.StatusCode, + JsonUtils.Deserialize(responseBody) + ); } /// /// Returns a `Lead` object with the given `id`. /// - public async Task RetrieveAsync(string id, LeadsRetrieveRequest request) + public async Task RetrieveAsync( + string id, + LeadsRetrieveRequest request, + RequestOptions? options = null + ) { var _query = new Dictionary() { }; if (request.Expand != null) @@ -152,44 +196,73 @@ public async Task RetrieveAsync(string id, LeadsRetrieveRequest request) var response = await _client.MakeRequestAsync( new RawClient.JsonApiRequest { + BaseUrl = _client.Options.BaseUrl, Method = HttpMethod.Get, Path = $"crm/v1/leads/{id}", - Query = _query + Query = _query, + Options = options } ); - string responseBody = await response.Raw.Content.ReadAsStringAsync(); - if (response.StatusCode >= 200 && response.StatusCode < 400) + var responseBody = await response.Raw.Content.ReadAsStringAsync(); + if (response.StatusCode is >= 200 and < 400) { - return JsonSerializer.Deserialize(responseBody); + try + { + return JsonUtils.Deserialize(responseBody)!; + } + catch (JsonException e) + { + throw new MergeException("Failed to deserialize response", e); + } } - throw new Exception(responseBody); + + throw new MergeApiException( + $"Error with status code {response.StatusCode}", + response.StatusCode, + JsonUtils.Deserialize(responseBody) + ); } /// /// Returns metadata for `Lead` POSTs. /// - public async Task MetaPostRetrieveAsync() + public async Task MetaPostRetrieveAsync(RequestOptions? options = null) { var response = await _client.MakeRequestAsync( new RawClient.JsonApiRequest { + BaseUrl = _client.Options.BaseUrl, Method = HttpMethod.Get, - Path = "crm/v1/leads/meta/post" + Path = "crm/v1/leads/meta/post", + Options = options } ); - string responseBody = await response.Raw.Content.ReadAsStringAsync(); - if (response.StatusCode >= 200 && response.StatusCode < 400) + var responseBody = await response.Raw.Content.ReadAsStringAsync(); + if (response.StatusCode is >= 200 and < 400) { - return JsonSerializer.Deserialize(responseBody); + try + { + return JsonUtils.Deserialize(responseBody)!; + } + catch (JsonException e) + { + throw new MergeException("Failed to deserialize response", e); + } } - throw new Exception(responseBody); + + throw new MergeApiException( + $"Error with status code {response.StatusCode}", + response.StatusCode, + JsonUtils.Deserialize(responseBody) + ); } /// /// Returns a list of `RemoteFieldClass` objects. /// public async Task RemoteFieldClassesListAsync( - LeadsRemoteFieldClassesListRequest request + LeadsRemoteFieldClassesListRequest request, + RequestOptions? options = null ) { var _query = new Dictionary() { }; @@ -220,16 +293,30 @@ LeadsRemoteFieldClassesListRequest request var response = await _client.MakeRequestAsync( new RawClient.JsonApiRequest { + BaseUrl = _client.Options.BaseUrl, Method = HttpMethod.Get, Path = "crm/v1/leads/remote-field-classes", - Query = _query + Query = _query, + Options = options } ); - string responseBody = await response.Raw.Content.ReadAsStringAsync(); - if (response.StatusCode >= 200 && response.StatusCode < 400) + var responseBody = await response.Raw.Content.ReadAsStringAsync(); + if (response.StatusCode is >= 200 and < 400) { - return JsonSerializer.Deserialize(responseBody); + try + { + return JsonUtils.Deserialize(responseBody)!; + } + catch (JsonException e) + { + throw new MergeException("Failed to deserialize response", e); + } } - throw new Exception(responseBody); + + throw new MergeApiException( + $"Error with status code {response.StatusCode}", + response.StatusCode, + JsonUtils.Deserialize(responseBody) + ); } } diff --git a/src/Merge.Client/Crm/Leads/Requests/LeadEndpointRequest.cs b/src/Merge.Client/Crm/Leads/Requests/LeadEndpointRequest.cs index 9a61bbaf..f1f3b58d 100644 --- a/src/Merge.Client/Crm/Leads/Requests/LeadEndpointRequest.cs +++ b/src/Merge.Client/Crm/Leads/Requests/LeadEndpointRequest.cs @@ -1,20 +1,16 @@ -using Merge.Client.Crm; - -#nullable enable - namespace Merge.Client.Crm; -public class LeadEndpointRequest +public record LeadEndpointRequest { /// /// Whether to include debug fields (such as log file links) in the response. /// - public bool? IsDebugMode { get; init; } + public bool? IsDebugMode { get; set; } /// /// Whether or not third-party updates should be run asynchronously. /// - public bool? RunAsync { get; init; } + public bool? RunAsync { get; set; } - public LeadRequest Model { get; init; } + public required LeadRequest Model { get; set; } } diff --git a/src/Merge.Client/Crm/Leads/Requests/LeadsListRequest.cs b/src/Merge.Client/Crm/Leads/Requests/LeadsListRequest.cs index 6fcb9c59..e5f4d017 100644 --- a/src/Merge.Client/Crm/Leads/Requests/LeadsListRequest.cs +++ b/src/Merge.Client/Crm/Leads/Requests/LeadsListRequest.cs @@ -1,88 +1,84 @@ -using Merge.Client.Crm; - -#nullable enable - namespace Merge.Client.Crm; -public class LeadsListRequest +public record LeadsListRequest { /// /// If provided, will only return leads with this account. /// - public string? ConvertedAccountId { get; init; } + public string? ConvertedAccountId { get; set; } /// /// If provided, will only return leads with this contact. /// - public string? ConvertedContactId { get; init; } + public string? ConvertedContactId { get; set; } /// /// If provided, will only return objects created after this datetime. /// - public DateTime? CreatedAfter { get; init; } + public DateTime? CreatedAfter { get; set; } /// /// If provided, will only return objects created before this datetime. /// - public DateTime? CreatedBefore { get; init; } + public DateTime? CreatedBefore { get; set; } /// /// The pagination cursor value. /// - public string? Cursor { get; init; } + public string? Cursor { get; set; } /// /// If provided, will only return contacts matching the email addresses; multiple email_addresses can be separated by commas. /// - public string? EmailAddresses { get; init; } + public string? EmailAddresses { get; set; } /// /// Which relations should be returned in expanded form. Multiple relation names should be comma separated without spaces. /// - public LeadsListRequestExpand? Expand { get; init; } + public LeadsListRequestExpand? Expand { get; set; } /// /// Whether to include data that was marked as deleted by third party webhooks. /// - public bool? IncludeDeletedData { get; init; } + public bool? IncludeDeletedData { get; set; } /// /// Whether to include the original data Merge fetched from the third-party to produce these models. /// - public bool? IncludeRemoteData { get; init; } + public bool? IncludeRemoteData { get; set; } /// /// Whether to include all remote fields, including fields that Merge did not map to common models, in a normalized format. /// - public bool? IncludeRemoteFields { get; init; } + public bool? IncludeRemoteFields { get; set; } /// /// If provided, only objects synced by Merge after this date time will be returned. /// - public DateTime? ModifiedAfter { get; init; } + public DateTime? ModifiedAfter { get; set; } /// /// If provided, only objects synced by Merge before this date time will be returned. /// - public DateTime? ModifiedBefore { get; init; } + public DateTime? ModifiedBefore { get; set; } /// /// If provided, will only return leads with this owner. /// - public string? OwnerId { get; init; } + public string? OwnerId { get; set; } /// /// Number of results to return per page. /// - public int? PageSize { get; init; } + public int? PageSize { get; set; } /// /// If provided, will only return contacts matching the phone numbers; multiple phone numbers can be separated by commas. /// - public string? PhoneNumbers { get; init; } + public string? PhoneNumbers { get; set; } /// /// The API provider's ID for the given object. /// - public string? RemoteId { get; init; } + public string? RemoteId { get; set; } } diff --git a/src/Merge.Client/Crm/Leads/Requests/LeadsRemoteFieldClassesListRequest.cs b/src/Merge.Client/Crm/Leads/Requests/LeadsRemoteFieldClassesListRequest.cs index f4c6ab4a..8054e1a8 100644 --- a/src/Merge.Client/Crm/Leads/Requests/LeadsRemoteFieldClassesListRequest.cs +++ b/src/Merge.Client/Crm/Leads/Requests/LeadsRemoteFieldClassesListRequest.cs @@ -1,34 +1,34 @@ namespace Merge.Client.Crm; -public class LeadsRemoteFieldClassesListRequest +public record LeadsRemoteFieldClassesListRequest { /// /// The pagination cursor value. /// - public string? Cursor { get; init; } + public string? Cursor { get; set; } /// /// Whether to include data that was marked as deleted by third party webhooks. /// - public bool? IncludeDeletedData { get; init; } + public bool? IncludeDeletedData { get; set; } /// /// Whether to include the original data Merge fetched from the third-party to produce these models. /// - public bool? IncludeRemoteData { get; init; } + public bool? IncludeRemoteData { get; set; } /// /// Whether to include all remote fields, including fields that Merge did not map to common models, in a normalized format. /// - public bool? IncludeRemoteFields { get; init; } + public bool? IncludeRemoteFields { get; set; } /// /// If provided, will only return remote field classes with this is_common_model_field value /// - public bool? IsCommonModelField { get; init; } + public bool? IsCommonModelField { get; set; } /// /// Number of results to return per page. /// - public int? PageSize { get; init; } + public int? PageSize { get; set; } } diff --git a/src/Merge.Client/Crm/Leads/Requests/LeadsRetrieveRequest.cs b/src/Merge.Client/Crm/Leads/Requests/LeadsRetrieveRequest.cs index a131cfb0..bb868a34 100644 --- a/src/Merge.Client/Crm/Leads/Requests/LeadsRetrieveRequest.cs +++ b/src/Merge.Client/Crm/Leads/Requests/LeadsRetrieveRequest.cs @@ -1,23 +1,19 @@ -using Merge.Client.Crm; - -#nullable enable - namespace Merge.Client.Crm; -public class LeadsRetrieveRequest +public record LeadsRetrieveRequest { /// /// Which relations should be returned in expanded form. Multiple relation names should be comma separated without spaces. /// - public LeadsRetrieveRequestExpand? Expand { get; init; } + public LeadsRetrieveRequestExpand? Expand { get; set; } /// /// Whether to include the original data Merge fetched from the third-party to produce these models. /// - public bool? IncludeRemoteData { get; init; } + public bool? IncludeRemoteData { get; set; } /// /// Whether to include all remote fields, including fields that Merge did not map to common models, in a normalized format. /// - public bool? IncludeRemoteFields { get; init; } + public bool? IncludeRemoteFields { get; set; } } diff --git a/src/Merge.Client/Crm/Leads/Types/LeadsListRequestExpand.cs b/src/Merge.Client/Crm/Leads/Types/LeadsListRequestExpand.cs index 5aa56ede..41b9d79b 100644 --- a/src/Merge.Client/Crm/Leads/Types/LeadsListRequestExpand.cs +++ b/src/Merge.Client/Crm/Leads/Types/LeadsListRequestExpand.cs @@ -1,7 +1,6 @@ using System.Runtime.Serialization; using System.Text.Json.Serialization; using Merge.Client.Core; -using Merge.Client.Crm; #nullable enable diff --git a/src/Merge.Client/Crm/Leads/Types/LeadsRetrieveRequestExpand.cs b/src/Merge.Client/Crm/Leads/Types/LeadsRetrieveRequestExpand.cs index 0243ad2d..be08ce31 100644 --- a/src/Merge.Client/Crm/Leads/Types/LeadsRetrieveRequestExpand.cs +++ b/src/Merge.Client/Crm/Leads/Types/LeadsRetrieveRequestExpand.cs @@ -1,7 +1,6 @@ using System.Runtime.Serialization; using System.Text.Json.Serialization; using Merge.Client.Core; -using Merge.Client.Crm; #nullable enable diff --git a/src/Merge.Client/Crm/LinkToken/LinkTokenClient.cs b/src/Merge.Client/Crm/LinkToken/LinkTokenClient.cs index 7f224669..ec050676 100644 --- a/src/Merge.Client/Crm/LinkToken/LinkTokenClient.cs +++ b/src/Merge.Client/Crm/LinkToken/LinkTokenClient.cs @@ -1,6 +1,6 @@ +using System.Net.Http; using System.Text.Json; -using Merge.Client; -using Merge.Client.Crm; +using Merge.Client.Core; #nullable enable @@ -18,21 +18,38 @@ public LinkTokenClient(RawClient client) /// /// Creates a link token to be used when linking a new end user. /// - public async Task CreateAsync(EndUserDetailsRequest request) + public async Task CreateAsync( + EndUserDetailsRequest request, + RequestOptions? options = null + ) { var response = await _client.MakeRequestAsync( new RawClient.JsonApiRequest { + BaseUrl = _client.Options.BaseUrl, Method = HttpMethod.Post, Path = "crm/v1/link-token", - Body = request + Body = request, + Options = options } ); - string responseBody = await response.Raw.Content.ReadAsStringAsync(); - if (response.StatusCode >= 200 && response.StatusCode < 400) + var responseBody = await response.Raw.Content.ReadAsStringAsync(); + if (response.StatusCode is >= 200 and < 400) { - return JsonSerializer.Deserialize(responseBody); + try + { + return JsonUtils.Deserialize(responseBody)!; + } + catch (JsonException e) + { + throw new MergeException("Failed to deserialize response", e); + } } - throw new Exception(responseBody); + + throw new MergeApiException( + $"Error with status code {response.StatusCode}", + response.StatusCode, + JsonUtils.Deserialize(responseBody) + ); } } diff --git a/src/Merge.Client/Crm/LinkToken/Requests/EndUserDetailsRequest.cs b/src/Merge.Client/Crm/LinkToken/Requests/EndUserDetailsRequest.cs index 268ae3a9..0542c9b4 100644 --- a/src/Merge.Client/Crm/LinkToken/Requests/EndUserDetailsRequest.cs +++ b/src/Merge.Client/Crm/LinkToken/Requests/EndUserDetailsRequest.cs @@ -1,65 +1,64 @@ using System.Text.Json.Serialization; -using Merge.Client.Crm; #nullable enable namespace Merge.Client.Crm; -public class EndUserDetailsRequest +public record EndUserDetailsRequest { /// /// Your end user's email address. This is purely for identification purposes - setting this value will not cause any emails to be sent. /// [JsonPropertyName("end_user_email_address")] - public string EndUserEmailAddress { get; init; } + public required string EndUserEmailAddress { get; set; } /// /// Your end user's organization. /// [JsonPropertyName("end_user_organization_name")] - public string EndUserOrganizationName { get; init; } + public required string EndUserOrganizationName { get; set; } /// /// This unique identifier typically represents the ID for your end user in your product's database. This value must be distinct from other Linked Accounts' unique identifiers. /// [JsonPropertyName("end_user_origin_id")] - public string EndUserOriginId { get; init; } + public required string EndUserOriginId { get; set; } /// /// The integration categories to show in Merge Link. /// [JsonPropertyName("categories")] - public IEnumerable Categories { get; init; } + public IEnumerable Categories { get; set; } = new List(); /// /// The slug of a specific pre-selected integration for this linking flow token. For examples of slugs, see https://docs.merge.dev/guides/merge-link/single-integration/. /// [JsonPropertyName("integration")] - public string? Integration { get; init; } + public string? Integration { get; set; } /// /// An integer number of minutes between [30, 720 or 10080 if for a Magic Link URL] for how long this token is valid. Defaults to 30. /// [JsonPropertyName("link_expiry_mins")] - public int? LinkExpiryMins { get; init; } + public int? LinkExpiryMins { get; set; } /// /// Whether to generate a Magic Link URL. Defaults to false. For more information on Magic Link, see https://merge.dev/blog/integrations-fast-say-hello-to-magic-link. /// [JsonPropertyName("should_create_magic_link_url")] - public bool? ShouldCreateMagicLinkUrl { get; init; } + public bool? ShouldCreateMagicLinkUrl { get; set; } /// /// Whether to generate a Magic Link URL on the Admin Needed screen during the linking flow. Defaults to false. For more information on Magic Link, see https://merge.dev/blog/integrations-fast-say-hello-to-magic-link. /// [JsonPropertyName("hide_admin_magic_link")] - public bool? HideAdminMagicLink { get; init; } + public bool? HideAdminMagicLink { get; set; } /// /// An array of objects to specify the models and fields that will be disabled for a given Linked Account. Each object uses model_id, enabled_actions, and disabled_fields to specify the model, method, and fields that are scoped for a given Linked Account. /// [JsonPropertyName("common_models")] - public IEnumerable? CommonModels { get; init; } + public IEnumerable? CommonModels { get; set; } /// /// When creating a Link Token, you can set permissions for Common Models that will apply to the account that is going to be linked. Any model or field not specified in link token payload will default to existing settings. @@ -68,17 +67,17 @@ public class EndUserDetailsRequest public Dictionary< string, IEnumerable? - >? CategoryCommonModelScopes { get; init; } + >? CategoryCommonModelScopes { get; set; } /// /// The language code for the language to localize Merge Link to. /// [JsonPropertyName("language")] - public string? Language { get; init; } + public string? Language { get; set; } /// /// A JSON object containing integration-specific configuration options. /// [JsonPropertyName("integration_specific_config")] - public Dictionary? IntegrationSpecificConfig { get; init; } + public Dictionary? IntegrationSpecificConfig { get; set; } } diff --git a/src/Merge.Client/Crm/LinkedAccounts/LinkedAccountsClient.cs b/src/Merge.Client/Crm/LinkedAccounts/LinkedAccountsClient.cs index ffa530be..89e61f6f 100644 --- a/src/Merge.Client/Crm/LinkedAccounts/LinkedAccountsClient.cs +++ b/src/Merge.Client/Crm/LinkedAccounts/LinkedAccountsClient.cs @@ -1,6 +1,6 @@ +using System.Net.Http; using System.Text.Json; -using Merge.Client; -using Merge.Client.Crm; +using Merge.Client.Core; #nullable enable @@ -19,7 +19,8 @@ public LinkedAccountsClient(RawClient client) /// List linked accounts for your organization. /// public async Task ListAsync( - LinkedAccountsListRequest request + LinkedAccountsListRequest request, + RequestOptions? options = null ) { var _query = new Dictionary() { }; @@ -78,16 +79,30 @@ LinkedAccountsListRequest request var response = await _client.MakeRequestAsync( new RawClient.JsonApiRequest { + BaseUrl = _client.Options.BaseUrl, Method = HttpMethod.Get, Path = "crm/v1/linked-accounts", - Query = _query + Query = _query, + Options = options } ); - string responseBody = await response.Raw.Content.ReadAsStringAsync(); - if (response.StatusCode >= 200 && response.StatusCode < 400) + var responseBody = await response.Raw.Content.ReadAsStringAsync(); + if (response.StatusCode is >= 200 and < 400) { - return JsonSerializer.Deserialize(responseBody); + try + { + return JsonUtils.Deserialize(responseBody)!; + } + catch (JsonException e) + { + throw new MergeException("Failed to deserialize response", e); + } } - throw new Exception(responseBody); + + throw new MergeApiException( + $"Error with status code {response.StatusCode}", + response.StatusCode, + JsonUtils.Deserialize(responseBody) + ); } } diff --git a/src/Merge.Client/Crm/LinkedAccounts/Requests/LinkedAccountsListRequest.cs b/src/Merge.Client/Crm/LinkedAccounts/Requests/LinkedAccountsListRequest.cs index 47629fb7..a43cf9d4 100644 --- a/src/Merge.Client/Crm/LinkedAccounts/Requests/LinkedAccountsListRequest.cs +++ b/src/Merge.Client/Crm/LinkedAccounts/Requests/LinkedAccountsListRequest.cs @@ -1,10 +1,6 @@ -using Merge.Client.Crm; - -#nullable enable - namespace Merge.Client.Crm; -public class LinkedAccountsListRequest +public record LinkedAccountsListRequest { /// /// Options: `accounting`, `ats`, `crm`, `filestorage`, `hris`, `mktg`, `ticketing` @@ -17,62 +13,62 @@ public class LinkedAccountsListRequest /// - `mktg` - mktg /// - `filestorage` - filestorage /// - public LinkedAccountsListRequestCategory? Category { get; init; } + public LinkedAccountsListRequestCategory? Category { get; set; } /// /// The pagination cursor value. /// - public string? Cursor { get; init; } + public string? Cursor { get; set; } /// /// If provided, will only return linked accounts associated with the given email address. /// - public string? EndUserEmailAddress { get; init; } + public string? EndUserEmailAddress { get; set; } /// /// If provided, will only return linked accounts associated with the given organization name. /// - public string? EndUserOrganizationName { get; init; } + public string? EndUserOrganizationName { get; set; } /// /// If provided, will only return linked accounts associated with the given origin ID. /// - public string? EndUserOriginId { get; init; } + public string? EndUserOriginId { get; set; } /// /// Comma-separated list of EndUser origin IDs, making it possible to specify multiple EndUsers at once. /// - public string? EndUserOriginIds { get; init; } + public string? EndUserOriginIds { get; set; } - public string? Id { get; init; } + public string? Id { get; set; } /// /// Comma-separated list of LinkedAccount IDs, making it possible to specify multiple LinkedAccounts at once. /// - public string? Ids { get; init; } + public string? Ids { get; set; } /// /// If `true`, will include complete production duplicates of the account specified by the `id` query parameter in the response. `id` must be for a complete production linked account. /// - public bool? IncludeDuplicates { get; init; } + public bool? IncludeDuplicates { get; set; } /// /// If provided, will only return linked accounts associated with the given integration name. /// - public string? IntegrationName { get; init; } + public string? IntegrationName { get; set; } /// /// If included, will only include test linked accounts. If not included, will only include non-test linked accounts. /// - public string? IsTestAccount { get; init; } + public string? IsTestAccount { get; set; } /// /// Number of results to return per page. /// - public int? PageSize { get; init; } + public int? PageSize { get; set; } /// /// Filter by status. Options: `COMPLETE`, `INCOMPLETE`, `RELINK_NEEDED` /// - public string? Status { get; init; } + public string? Status { get; set; } } diff --git a/src/Merge.Client/Crm/LinkedAccounts/Types/LinkedAccountsListRequestCategory.cs b/src/Merge.Client/Crm/LinkedAccounts/Types/LinkedAccountsListRequestCategory.cs index abd35aa8..5d7f7270 100644 --- a/src/Merge.Client/Crm/LinkedAccounts/Types/LinkedAccountsListRequestCategory.cs +++ b/src/Merge.Client/Crm/LinkedAccounts/Types/LinkedAccountsListRequestCategory.cs @@ -1,7 +1,6 @@ using System.Runtime.Serialization; using System.Text.Json.Serialization; using Merge.Client.Core; -using Merge.Client.Crm; #nullable enable diff --git a/src/Merge.Client/Crm/Notes/NotesClient.cs b/src/Merge.Client/Crm/Notes/NotesClient.cs index 72aa92ce..404570c2 100644 --- a/src/Merge.Client/Crm/Notes/NotesClient.cs +++ b/src/Merge.Client/Crm/Notes/NotesClient.cs @@ -1,6 +1,6 @@ +using System.Net.Http; using System.Text.Json; -using Merge.Client; -using Merge.Client.Crm; +using Merge.Client.Core; #nullable enable @@ -18,7 +18,10 @@ public NotesClient(RawClient client) /// /// Returns a list of `Note` objects. /// - public async Task ListAsync(NotesListRequest request) + public async Task ListAsync( + NotesListRequest request, + RequestOptions? options = null + ) { var _query = new Dictionary() { }; if (request.AccountId != null) @@ -31,11 +34,13 @@ public async Task ListAsync(NotesListRequest request) } if (request.CreatedAfter != null) { - _query["created_after"] = request.CreatedAfter.Value.ToString("o0"); + _query["created_after"] = request.CreatedAfter.Value.ToString(Constants.DateTimeFormat); } if (request.CreatedBefore != null) { - _query["created_before"] = request.CreatedBefore.Value.ToString("o0"); + _query["created_before"] = request.CreatedBefore.Value.ToString( + Constants.DateTimeFormat + ); } if (request.Cursor != null) { @@ -59,11 +64,15 @@ public async Task ListAsync(NotesListRequest request) } if (request.ModifiedAfter != null) { - _query["modified_after"] = request.ModifiedAfter.Value.ToString("o0"); + _query["modified_after"] = request.ModifiedAfter.Value.ToString( + Constants.DateTimeFormat + ); } if (request.ModifiedBefore != null) { - _query["modified_before"] = request.ModifiedBefore.Value.ToString("o0"); + _query["modified_before"] = request.ModifiedBefore.Value.ToString( + Constants.DateTimeFormat + ); } if (request.OpportunityId != null) { @@ -84,23 +93,40 @@ public async Task ListAsync(NotesListRequest request) var response = await _client.MakeRequestAsync( new RawClient.JsonApiRequest { + BaseUrl = _client.Options.BaseUrl, Method = HttpMethod.Get, Path = "crm/v1/notes", - Query = _query + Query = _query, + Options = options } ); - string responseBody = await response.Raw.Content.ReadAsStringAsync(); - if (response.StatusCode >= 200 && response.StatusCode < 400) + var responseBody = await response.Raw.Content.ReadAsStringAsync(); + if (response.StatusCode is >= 200 and < 400) { - return JsonSerializer.Deserialize(responseBody); + try + { + return JsonUtils.Deserialize(responseBody)!; + } + catch (JsonException e) + { + throw new MergeException("Failed to deserialize response", e); + } } - throw new Exception(responseBody); + + throw new MergeApiException( + $"Error with status code {response.StatusCode}", + response.StatusCode, + JsonUtils.Deserialize(responseBody) + ); } /// /// Creates a `Note` object with the given values. /// - public async Task CreateAsync(NoteEndpointRequest request) + public async Task CreateAsync( + NoteEndpointRequest request, + RequestOptions? options = null + ) { var _query = new Dictionary() { }; if (request.IsDebugMode != null) @@ -114,23 +140,41 @@ public async Task CreateAsync(NoteEndpointRequest request) var response = await _client.MakeRequestAsync( new RawClient.JsonApiRequest { + BaseUrl = _client.Options.BaseUrl, Method = HttpMethod.Post, Path = "crm/v1/notes", - Query = _query + Query = _query, + Options = options } ); - string responseBody = await response.Raw.Content.ReadAsStringAsync(); - if (response.StatusCode >= 200 && response.StatusCode < 400) + var responseBody = await response.Raw.Content.ReadAsStringAsync(); + if (response.StatusCode is >= 200 and < 400) { - return JsonSerializer.Deserialize(responseBody); + try + { + return JsonUtils.Deserialize(responseBody)!; + } + catch (JsonException e) + { + throw new MergeException("Failed to deserialize response", e); + } } - throw new Exception(responseBody); + + throw new MergeApiException( + $"Error with status code {response.StatusCode}", + response.StatusCode, + JsonUtils.Deserialize(responseBody) + ); } /// /// Returns a `Note` object with the given `id`. /// - public async Task RetrieveAsync(string id, NotesRetrieveRequest request) + public async Task RetrieveAsync( + string id, + NotesRetrieveRequest request, + RequestOptions? options = null + ) { var _query = new Dictionary() { }; if (request.Expand != null) @@ -148,44 +192,73 @@ public async Task RetrieveAsync(string id, NotesRetrieveRequest request) var response = await _client.MakeRequestAsync( new RawClient.JsonApiRequest { + BaseUrl = _client.Options.BaseUrl, Method = HttpMethod.Get, Path = $"crm/v1/notes/{id}", - Query = _query + Query = _query, + Options = options } ); - string responseBody = await response.Raw.Content.ReadAsStringAsync(); - if (response.StatusCode >= 200 && response.StatusCode < 400) + var responseBody = await response.Raw.Content.ReadAsStringAsync(); + if (response.StatusCode is >= 200 and < 400) { - return JsonSerializer.Deserialize(responseBody); + try + { + return JsonUtils.Deserialize(responseBody)!; + } + catch (JsonException e) + { + throw new MergeException("Failed to deserialize response", e); + } } - throw new Exception(responseBody); + + throw new MergeApiException( + $"Error with status code {response.StatusCode}", + response.StatusCode, + JsonUtils.Deserialize(responseBody) + ); } /// /// Returns metadata for `Note` POSTs. /// - public async Task MetaPostRetrieveAsync() + public async Task MetaPostRetrieveAsync(RequestOptions? options = null) { var response = await _client.MakeRequestAsync( new RawClient.JsonApiRequest { + BaseUrl = _client.Options.BaseUrl, Method = HttpMethod.Get, - Path = "crm/v1/notes/meta/post" + Path = "crm/v1/notes/meta/post", + Options = options } ); - string responseBody = await response.Raw.Content.ReadAsStringAsync(); - if (response.StatusCode >= 200 && response.StatusCode < 400) + var responseBody = await response.Raw.Content.ReadAsStringAsync(); + if (response.StatusCode is >= 200 and < 400) { - return JsonSerializer.Deserialize(responseBody); + try + { + return JsonUtils.Deserialize(responseBody)!; + } + catch (JsonException e) + { + throw new MergeException("Failed to deserialize response", e); + } } - throw new Exception(responseBody); + + throw new MergeApiException( + $"Error with status code {response.StatusCode}", + response.StatusCode, + JsonUtils.Deserialize(responseBody) + ); } /// /// Returns a list of `RemoteFieldClass` objects. /// public async Task RemoteFieldClassesListAsync( - NotesRemoteFieldClassesListRequest request + NotesRemoteFieldClassesListRequest request, + RequestOptions? options = null ) { var _query = new Dictionary() { }; @@ -216,16 +289,30 @@ NotesRemoteFieldClassesListRequest request var response = await _client.MakeRequestAsync( new RawClient.JsonApiRequest { + BaseUrl = _client.Options.BaseUrl, Method = HttpMethod.Get, Path = "crm/v1/notes/remote-field-classes", - Query = _query + Query = _query, + Options = options } ); - string responseBody = await response.Raw.Content.ReadAsStringAsync(); - if (response.StatusCode >= 200 && response.StatusCode < 400) + var responseBody = await response.Raw.Content.ReadAsStringAsync(); + if (response.StatusCode is >= 200 and < 400) { - return JsonSerializer.Deserialize(responseBody); + try + { + return JsonUtils.Deserialize(responseBody)!; + } + catch (JsonException e) + { + throw new MergeException("Failed to deserialize response", e); + } } - throw new Exception(responseBody); + + throw new MergeApiException( + $"Error with status code {response.StatusCode}", + response.StatusCode, + JsonUtils.Deserialize(responseBody) + ); } } diff --git a/src/Merge.Client/Crm/Notes/Requests/NoteEndpointRequest.cs b/src/Merge.Client/Crm/Notes/Requests/NoteEndpointRequest.cs index 60d75657..796cd1a5 100644 --- a/src/Merge.Client/Crm/Notes/Requests/NoteEndpointRequest.cs +++ b/src/Merge.Client/Crm/Notes/Requests/NoteEndpointRequest.cs @@ -1,20 +1,16 @@ -using Merge.Client.Crm; - -#nullable enable - namespace Merge.Client.Crm; -public class NoteEndpointRequest +public record NoteEndpointRequest { /// /// Whether to include debug fields (such as log file links) in the response. /// - public bool? IsDebugMode { get; init; } + public bool? IsDebugMode { get; set; } /// /// Whether or not third-party updates should be run asynchronously. /// - public bool? RunAsync { get; init; } + public bool? RunAsync { get; set; } - public NoteRequest Model { get; init; } + public required NoteRequest Model { get; set; } } diff --git a/src/Merge.Client/Crm/Notes/Requests/NotesListRequest.cs b/src/Merge.Client/Crm/Notes/Requests/NotesListRequest.cs index 75c88a1f..0d933c89 100644 --- a/src/Merge.Client/Crm/Notes/Requests/NotesListRequest.cs +++ b/src/Merge.Client/Crm/Notes/Requests/NotesListRequest.cs @@ -1,83 +1,79 @@ -using Merge.Client.Crm; - -#nullable enable - namespace Merge.Client.Crm; -public class NotesListRequest +public record NotesListRequest { /// /// If provided, will only return notes with this account. /// - public string? AccountId { get; init; } + public string? AccountId { get; set; } /// /// If provided, will only return notes with this contact. /// - public string? ContactId { get; init; } + public string? ContactId { get; set; } /// /// If provided, will only return objects created after this datetime. /// - public DateTime? CreatedAfter { get; init; } + public DateTime? CreatedAfter { get; set; } /// /// If provided, will only return objects created before this datetime. /// - public DateTime? CreatedBefore { get; init; } + public DateTime? CreatedBefore { get; set; } /// /// The pagination cursor value. /// - public string? Cursor { get; init; } + public string? Cursor { get; set; } /// /// Which relations should be returned in expanded form. Multiple relation names should be comma separated without spaces. /// - public NotesListRequestExpand? Expand { get; init; } + public NotesListRequestExpand? Expand { get; set; } /// /// Whether to include data that was marked as deleted by third party webhooks. /// - public bool? IncludeDeletedData { get; init; } + public bool? IncludeDeletedData { get; set; } /// /// Whether to include the original data Merge fetched from the third-party to produce these models. /// - public bool? IncludeRemoteData { get; init; } + public bool? IncludeRemoteData { get; set; } /// /// Whether to include all remote fields, including fields that Merge did not map to common models, in a normalized format. /// - public bool? IncludeRemoteFields { get; init; } + public bool? IncludeRemoteFields { get; set; } /// /// If provided, only objects synced by Merge after this date time will be returned. /// - public DateTime? ModifiedAfter { get; init; } + public DateTime? ModifiedAfter { get; set; } /// /// If provided, only objects synced by Merge before this date time will be returned. /// - public DateTime? ModifiedBefore { get; init; } + public DateTime? ModifiedBefore { get; set; } /// /// If provided, will only return notes with this opportunity. /// - public string? OpportunityId { get; init; } + public string? OpportunityId { get; set; } /// /// If provided, will only return notes with this owner. /// - public string? OwnerId { get; init; } + public string? OwnerId { get; set; } /// /// Number of results to return per page. /// - public int? PageSize { get; init; } + public int? PageSize { get; set; } /// /// The API provider's ID for the given object. /// - public string? RemoteId { get; init; } + public string? RemoteId { get; set; } } diff --git a/src/Merge.Client/Crm/Notes/Requests/NotesRemoteFieldClassesListRequest.cs b/src/Merge.Client/Crm/Notes/Requests/NotesRemoteFieldClassesListRequest.cs index 5ad7d256..ccf74947 100644 --- a/src/Merge.Client/Crm/Notes/Requests/NotesRemoteFieldClassesListRequest.cs +++ b/src/Merge.Client/Crm/Notes/Requests/NotesRemoteFieldClassesListRequest.cs @@ -1,34 +1,34 @@ namespace Merge.Client.Crm; -public class NotesRemoteFieldClassesListRequest +public record NotesRemoteFieldClassesListRequest { /// /// The pagination cursor value. /// - public string? Cursor { get; init; } + public string? Cursor { get; set; } /// /// Whether to include data that was marked as deleted by third party webhooks. /// - public bool? IncludeDeletedData { get; init; } + public bool? IncludeDeletedData { get; set; } /// /// Whether to include the original data Merge fetched from the third-party to produce these models. /// - public bool? IncludeRemoteData { get; init; } + public bool? IncludeRemoteData { get; set; } /// /// Whether to include all remote fields, including fields that Merge did not map to common models, in a normalized format. /// - public bool? IncludeRemoteFields { get; init; } + public bool? IncludeRemoteFields { get; set; } /// /// If provided, will only return remote field classes with this is_common_model_field value /// - public bool? IsCommonModelField { get; init; } + public bool? IsCommonModelField { get; set; } /// /// Number of results to return per page. /// - public int? PageSize { get; init; } + public int? PageSize { get; set; } } diff --git a/src/Merge.Client/Crm/Notes/Requests/NotesRetrieveRequest.cs b/src/Merge.Client/Crm/Notes/Requests/NotesRetrieveRequest.cs index d4708d8f..80d55b42 100644 --- a/src/Merge.Client/Crm/Notes/Requests/NotesRetrieveRequest.cs +++ b/src/Merge.Client/Crm/Notes/Requests/NotesRetrieveRequest.cs @@ -1,23 +1,19 @@ -using Merge.Client.Crm; - -#nullable enable - namespace Merge.Client.Crm; -public class NotesRetrieveRequest +public record NotesRetrieveRequest { /// /// Which relations should be returned in expanded form. Multiple relation names should be comma separated without spaces. /// - public NotesRetrieveRequestExpand? Expand { get; init; } + public NotesRetrieveRequestExpand? Expand { get; set; } /// /// Whether to include the original data Merge fetched from the third-party to produce these models. /// - public bool? IncludeRemoteData { get; init; } + public bool? IncludeRemoteData { get; set; } /// /// Whether to include all remote fields, including fields that Merge did not map to common models, in a normalized format. /// - public bool? IncludeRemoteFields { get; init; } + public bool? IncludeRemoteFields { get; set; } } diff --git a/src/Merge.Client/Crm/Notes/Types/NotesListRequestExpand.cs b/src/Merge.Client/Crm/Notes/Types/NotesListRequestExpand.cs index 678b28e5..5e1fb732 100644 --- a/src/Merge.Client/Crm/Notes/Types/NotesListRequestExpand.cs +++ b/src/Merge.Client/Crm/Notes/Types/NotesListRequestExpand.cs @@ -1,7 +1,6 @@ using System.Runtime.Serialization; using System.Text.Json.Serialization; using Merge.Client.Core; -using Merge.Client.Crm; #nullable enable diff --git a/src/Merge.Client/Crm/Notes/Types/NotesRetrieveRequestExpand.cs b/src/Merge.Client/Crm/Notes/Types/NotesRetrieveRequestExpand.cs index c5efae76..9001fa43 100644 --- a/src/Merge.Client/Crm/Notes/Types/NotesRetrieveRequestExpand.cs +++ b/src/Merge.Client/Crm/Notes/Types/NotesRetrieveRequestExpand.cs @@ -1,7 +1,6 @@ using System.Runtime.Serialization; using System.Text.Json.Serialization; using Merge.Client.Core; -using Merge.Client.Crm; #nullable enable diff --git a/src/Merge.Client/Crm/Opportunities/OpportunitiesClient.cs b/src/Merge.Client/Crm/Opportunities/OpportunitiesClient.cs index bbaab5f8..38d8e996 100644 --- a/src/Merge.Client/Crm/Opportunities/OpportunitiesClient.cs +++ b/src/Merge.Client/Crm/Opportunities/OpportunitiesClient.cs @@ -1,6 +1,6 @@ +using System.Net.Http; using System.Text.Json; -using Merge.Client; -using Merge.Client.Crm; +using Merge.Client.Core; #nullable enable @@ -18,7 +18,10 @@ public OpportunitiesClient(RawClient client) /// /// Returns a list of `Opportunity` objects. /// - public async Task ListAsync(OpportunitiesListRequest request) + public async Task ListAsync( + OpportunitiesListRequest request, + RequestOptions? options = null + ) { var _query = new Dictionary() { }; if (request.AccountId != null) @@ -27,11 +30,13 @@ public async Task ListAsync(OpportunitiesListRequest r } if (request.CreatedAfter != null) { - _query["created_after"] = request.CreatedAfter.Value.ToString("o0"); + _query["created_after"] = request.CreatedAfter.Value.ToString(Constants.DateTimeFormat); } if (request.CreatedBefore != null) { - _query["created_before"] = request.CreatedBefore.Value.ToString("o0"); + _query["created_before"] = request.CreatedBefore.Value.ToString( + Constants.DateTimeFormat + ); } if (request.Cursor != null) { @@ -55,11 +60,15 @@ public async Task ListAsync(OpportunitiesListRequest r } if (request.ModifiedAfter != null) { - _query["modified_after"] = request.ModifiedAfter.Value.ToString("o0"); + _query["modified_after"] = request.ModifiedAfter.Value.ToString( + Constants.DateTimeFormat + ); } if (request.ModifiedBefore != null) { - _query["modified_before"] = request.ModifiedBefore.Value.ToString("o0"); + _query["modified_before"] = request.ModifiedBefore.Value.ToString( + Constants.DateTimeFormat + ); } if (request.OwnerId != null) { @@ -71,7 +80,9 @@ public async Task ListAsync(OpportunitiesListRequest r } if (request.RemoteCreatedAfter != null) { - _query["remote_created_after"] = request.RemoteCreatedAfter.Value.ToString("o0"); + _query["remote_created_after"] = request.RemoteCreatedAfter.Value.ToString( + Constants.DateTimeFormat + ); } if (request.RemoteFields != null) { @@ -96,23 +107,40 @@ public async Task ListAsync(OpportunitiesListRequest r var response = await _client.MakeRequestAsync( new RawClient.JsonApiRequest { + BaseUrl = _client.Options.BaseUrl, Method = HttpMethod.Get, Path = "crm/v1/opportunities", - Query = _query + Query = _query, + Options = options } ); - string responseBody = await response.Raw.Content.ReadAsStringAsync(); - if (response.StatusCode >= 200 && response.StatusCode < 400) + var responseBody = await response.Raw.Content.ReadAsStringAsync(); + if (response.StatusCode is >= 200 and < 400) { - return JsonSerializer.Deserialize(responseBody); + try + { + return JsonUtils.Deserialize(responseBody)!; + } + catch (JsonException e) + { + throw new MergeException("Failed to deserialize response", e); + } } - throw new Exception(responseBody); + + throw new MergeApiException( + $"Error with status code {response.StatusCode}", + response.StatusCode, + JsonUtils.Deserialize(responseBody) + ); } /// /// Creates an `Opportunity` object with the given values. /// - public async Task CreateAsync(OpportunityEndpointRequest request) + public async Task CreateAsync( + OpportunityEndpointRequest request, + RequestOptions? options = null + ) { var _query = new Dictionary() { }; if (request.IsDebugMode != null) @@ -126,23 +154,41 @@ public async Task CreateAsync(OpportunityEndpointRequest re var response = await _client.MakeRequestAsync( new RawClient.JsonApiRequest { + BaseUrl = _client.Options.BaseUrl, Method = HttpMethod.Post, Path = "crm/v1/opportunities", - Query = _query + Query = _query, + Options = options } ); - string responseBody = await response.Raw.Content.ReadAsStringAsync(); - if (response.StatusCode >= 200 && response.StatusCode < 400) + var responseBody = await response.Raw.Content.ReadAsStringAsync(); + if (response.StatusCode is >= 200 and < 400) { - return JsonSerializer.Deserialize(responseBody); + try + { + return JsonUtils.Deserialize(responseBody)!; + } + catch (JsonException e) + { + throw new MergeException("Failed to deserialize response", e); + } } - throw new Exception(responseBody); + + throw new MergeApiException( + $"Error with status code {response.StatusCode}", + response.StatusCode, + JsonUtils.Deserialize(responseBody) + ); } /// /// Returns an `Opportunity` object with the given `id`. /// - public async Task RetrieveAsync(string id, OpportunitiesRetrieveRequest request) + public async Task RetrieveAsync( + string id, + OpportunitiesRetrieveRequest request, + RequestOptions? options = null + ) { var _query = new Dictionary() { }; if (request.Expand != null) @@ -168,17 +214,31 @@ public async Task RetrieveAsync(string id, OpportunitiesRetrieveReq var response = await _client.MakeRequestAsync( new RawClient.JsonApiRequest { + BaseUrl = _client.Options.BaseUrl, Method = HttpMethod.Get, Path = $"crm/v1/opportunities/{id}", - Query = _query + Query = _query, + Options = options } ); - string responseBody = await response.Raw.Content.ReadAsStringAsync(); - if (response.StatusCode >= 200 && response.StatusCode < 400) + var responseBody = await response.Raw.Content.ReadAsStringAsync(); + if (response.StatusCode is >= 200 and < 400) { - return JsonSerializer.Deserialize(responseBody); + try + { + return JsonUtils.Deserialize(responseBody)!; + } + catch (JsonException e) + { + throw new MergeException("Failed to deserialize response", e); + } } - throw new Exception(responseBody); + + throw new MergeApiException( + $"Error with status code {response.StatusCode}", + response.StatusCode, + JsonUtils.Deserialize(responseBody) + ); } /// @@ -186,7 +246,8 @@ public async Task RetrieveAsync(string id, OpportunitiesRetrieveReq /// public async Task PartialUpdateAsync( string id, - PatchedOpportunityEndpointRequest request + PatchedOpportunityEndpointRequest request, + RequestOptions? options = null ) { var _query = new Dictionary() { }; @@ -201,64 +262,110 @@ PatchedOpportunityEndpointRequest request var response = await _client.MakeRequestAsync( new RawClient.JsonApiRequest { - Method = HttpMethod.Patch, + BaseUrl = _client.Options.BaseUrl, + Method = HttpMethodExtensions.Patch, Path = $"crm/v1/opportunities/{id}", - Query = _query + Query = _query, + Options = options } ); - string responseBody = await response.Raw.Content.ReadAsStringAsync(); - if (response.StatusCode >= 200 && response.StatusCode < 400) + var responseBody = await response.Raw.Content.ReadAsStringAsync(); + if (response.StatusCode is >= 200 and < 400) { - return JsonSerializer.Deserialize(responseBody); + try + { + return JsonUtils.Deserialize(responseBody)!; + } + catch (JsonException e) + { + throw new MergeException("Failed to deserialize response", e); + } } - throw new Exception(responseBody); + + throw new MergeApiException( + $"Error with status code {response.StatusCode}", + response.StatusCode, + JsonUtils.Deserialize(responseBody) + ); } /// /// Returns metadata for `Opportunity` PATCHs. /// - public async Task MetaPatchRetrieveAsync(string id) + public async Task MetaPatchRetrieveAsync( + string id, + RequestOptions? options = null + ) { var response = await _client.MakeRequestAsync( new RawClient.JsonApiRequest { + BaseUrl = _client.Options.BaseUrl, Method = HttpMethod.Get, - Path = $"crm/v1/opportunities/meta/patch/{id}" + Path = $"crm/v1/opportunities/meta/patch/{id}", + Options = options } ); - string responseBody = await response.Raw.Content.ReadAsStringAsync(); - if (response.StatusCode >= 200 && response.StatusCode < 400) + var responseBody = await response.Raw.Content.ReadAsStringAsync(); + if (response.StatusCode is >= 200 and < 400) { - return JsonSerializer.Deserialize(responseBody); + try + { + return JsonUtils.Deserialize(responseBody)!; + } + catch (JsonException e) + { + throw new MergeException("Failed to deserialize response", e); + } } - throw new Exception(responseBody); + + throw new MergeApiException( + $"Error with status code {response.StatusCode}", + response.StatusCode, + JsonUtils.Deserialize(responseBody) + ); } /// /// Returns metadata for `Opportunity` POSTs. /// - public async Task MetaPostRetrieveAsync() + public async Task MetaPostRetrieveAsync(RequestOptions? options = null) { var response = await _client.MakeRequestAsync( new RawClient.JsonApiRequest { + BaseUrl = _client.Options.BaseUrl, Method = HttpMethod.Get, - Path = "crm/v1/opportunities/meta/post" + Path = "crm/v1/opportunities/meta/post", + Options = options } ); - string responseBody = await response.Raw.Content.ReadAsStringAsync(); - if (response.StatusCode >= 200 && response.StatusCode < 400) + var responseBody = await response.Raw.Content.ReadAsStringAsync(); + if (response.StatusCode is >= 200 and < 400) { - return JsonSerializer.Deserialize(responseBody); + try + { + return JsonUtils.Deserialize(responseBody)!; + } + catch (JsonException e) + { + throw new MergeException("Failed to deserialize response", e); + } } - throw new Exception(responseBody); + + throw new MergeApiException( + $"Error with status code {response.StatusCode}", + response.StatusCode, + JsonUtils.Deserialize(responseBody) + ); } /// /// Returns a list of `RemoteFieldClass` objects. /// public async Task RemoteFieldClassesListAsync( - OpportunitiesRemoteFieldClassesListRequest request + OpportunitiesRemoteFieldClassesListRequest request, + RequestOptions? options = null ) { var _query = new Dictionary() { }; @@ -289,16 +396,30 @@ OpportunitiesRemoteFieldClassesListRequest request var response = await _client.MakeRequestAsync( new RawClient.JsonApiRequest { + BaseUrl = _client.Options.BaseUrl, Method = HttpMethod.Get, Path = "crm/v1/opportunities/remote-field-classes", - Query = _query + Query = _query, + Options = options } ); - string responseBody = await response.Raw.Content.ReadAsStringAsync(); - if (response.StatusCode >= 200 && response.StatusCode < 400) + var responseBody = await response.Raw.Content.ReadAsStringAsync(); + if (response.StatusCode is >= 200 and < 400) { - return JsonSerializer.Deserialize(responseBody); + try + { + return JsonUtils.Deserialize(responseBody)!; + } + catch (JsonException e) + { + throw new MergeException("Failed to deserialize response", e); + } } - throw new Exception(responseBody); + + throw new MergeApiException( + $"Error with status code {response.StatusCode}", + response.StatusCode, + JsonUtils.Deserialize(responseBody) + ); } } diff --git a/src/Merge.Client/Crm/Opportunities/Requests/OpportunitiesListRequest.cs b/src/Merge.Client/Crm/Opportunities/Requests/OpportunitiesListRequest.cs index f4549937..476cf2c5 100644 --- a/src/Merge.Client/Crm/Opportunities/Requests/OpportunitiesListRequest.cs +++ b/src/Merge.Client/Crm/Opportunities/Requests/OpportunitiesListRequest.cs @@ -1,95 +1,91 @@ -using Merge.Client.Crm; - -#nullable enable - namespace Merge.Client.Crm; -public class OpportunitiesListRequest +public record OpportunitiesListRequest { /// /// If provided, will only return opportunities with this account. /// - public string? AccountId { get; init; } + public string? AccountId { get; set; } /// /// If provided, will only return objects created after this datetime. /// - public DateTime? CreatedAfter { get; init; } + public DateTime? CreatedAfter { get; set; } /// /// If provided, will only return objects created before this datetime. /// - public DateTime? CreatedBefore { get; init; } + public DateTime? CreatedBefore { get; set; } /// /// The pagination cursor value. /// - public string? Cursor { get; init; } + public string? Cursor { get; set; } /// /// Which relations should be returned in expanded form. Multiple relation names should be comma separated without spaces. /// - public OpportunitiesListRequestExpand? Expand { get; init; } + public OpportunitiesListRequestExpand? Expand { get; set; } /// /// Whether to include data that was marked as deleted by third party webhooks. /// - public bool? IncludeDeletedData { get; init; } + public bool? IncludeDeletedData { get; set; } /// /// Whether to include the original data Merge fetched from the third-party to produce these models. /// - public bool? IncludeRemoteData { get; init; } + public bool? IncludeRemoteData { get; set; } /// /// Whether to include all remote fields, including fields that Merge did not map to common models, in a normalized format. /// - public bool? IncludeRemoteFields { get; init; } + public bool? IncludeRemoteFields { get; set; } /// /// If provided, only objects synced by Merge after this date time will be returned. /// - public DateTime? ModifiedAfter { get; init; } + public DateTime? ModifiedAfter { get; set; } /// /// If provided, only objects synced by Merge before this date time will be returned. /// - public DateTime? ModifiedBefore { get; init; } + public DateTime? ModifiedBefore { get; set; } /// /// If provided, will only return opportunities with this owner. /// - public string? OwnerId { get; init; } + public string? OwnerId { get; set; } /// /// Number of results to return per page. /// - public int? PageSize { get; init; } + public int? PageSize { get; set; } /// /// If provided, will only return opportunities created in the third party platform after this datetime. /// - public DateTime? RemoteCreatedAfter { get; init; } + public DateTime? RemoteCreatedAfter { get; set; } /// /// Deprecated. Use show_enum_origins. /// - public string? RemoteFields { get; init; } + public string? RemoteFields { get; set; } /// /// The API provider's ID for the given object. /// - public string? RemoteId { get; init; } + public string? RemoteId { get; set; } /// /// A comma separated list of enum field names for which you'd like the original values to be returned, instead of Merge's normalized enum values. [Learn more](https://help.merge.dev/en/articles/8950958-show_enum_origins-query-parameter) /// - public string? ShowEnumOrigins { get; init; } + public string? ShowEnumOrigins { get; set; } /// /// If provided, will only return opportunities with this stage. /// - public string? StageId { get; init; } + public string? StageId { get; set; } /// /// If provided, will only return opportunities with this status. Options: ('OPEN', 'WON', 'LOST') @@ -98,5 +94,5 @@ public class OpportunitiesListRequest /// - `WON` - WON /// - `LOST` - LOST /// - public OpportunitiesListRequestStatus? Status { get; init; } + public OpportunitiesListRequestStatus? Status { get; set; } } diff --git a/src/Merge.Client/Crm/Opportunities/Requests/OpportunitiesRemoteFieldClassesListRequest.cs b/src/Merge.Client/Crm/Opportunities/Requests/OpportunitiesRemoteFieldClassesListRequest.cs index ef5c5639..4899527a 100644 --- a/src/Merge.Client/Crm/Opportunities/Requests/OpportunitiesRemoteFieldClassesListRequest.cs +++ b/src/Merge.Client/Crm/Opportunities/Requests/OpportunitiesRemoteFieldClassesListRequest.cs @@ -1,34 +1,34 @@ namespace Merge.Client.Crm; -public class OpportunitiesRemoteFieldClassesListRequest +public record OpportunitiesRemoteFieldClassesListRequest { /// /// The pagination cursor value. /// - public string? Cursor { get; init; } + public string? Cursor { get; set; } /// /// Whether to include data that was marked as deleted by third party webhooks. /// - public bool? IncludeDeletedData { get; init; } + public bool? IncludeDeletedData { get; set; } /// /// Whether to include the original data Merge fetched from the third-party to produce these models. /// - public bool? IncludeRemoteData { get; init; } + public bool? IncludeRemoteData { get; set; } /// /// Whether to include all remote fields, including fields that Merge did not map to common models, in a normalized format. /// - public bool? IncludeRemoteFields { get; init; } + public bool? IncludeRemoteFields { get; set; } /// /// If provided, will only return remote field classes with this is_common_model_field value /// - public bool? IsCommonModelField { get; init; } + public bool? IsCommonModelField { get; set; } /// /// Number of results to return per page. /// - public int? PageSize { get; init; } + public int? PageSize { get; set; } } diff --git a/src/Merge.Client/Crm/Opportunities/Requests/OpportunitiesRetrieveRequest.cs b/src/Merge.Client/Crm/Opportunities/Requests/OpportunitiesRetrieveRequest.cs index 656fc27f..ca245b52 100644 --- a/src/Merge.Client/Crm/Opportunities/Requests/OpportunitiesRetrieveRequest.cs +++ b/src/Merge.Client/Crm/Opportunities/Requests/OpportunitiesRetrieveRequest.cs @@ -1,33 +1,29 @@ -using Merge.Client.Crm; - -#nullable enable - namespace Merge.Client.Crm; -public class OpportunitiesRetrieveRequest +public record OpportunitiesRetrieveRequest { /// /// Which relations should be returned in expanded form. Multiple relation names should be comma separated without spaces. /// - public OpportunitiesRetrieveRequestExpand? Expand { get; init; } + public OpportunitiesRetrieveRequestExpand? Expand { get; set; } /// /// Whether to include the original data Merge fetched from the third-party to produce these models. /// - public bool? IncludeRemoteData { get; init; } + public bool? IncludeRemoteData { get; set; } /// /// Whether to include all remote fields, including fields that Merge did not map to common models, in a normalized format. /// - public bool? IncludeRemoteFields { get; init; } + public bool? IncludeRemoteFields { get; set; } /// /// Deprecated. Use show_enum_origins. /// - public string? RemoteFields { get; init; } + public string? RemoteFields { get; set; } /// /// A comma separated list of enum field names for which you'd like the original values to be returned, instead of Merge's normalized enum values. [Learn more](https://help.merge.dev/en/articles/8950958-show_enum_origins-query-parameter) /// - public string? ShowEnumOrigins { get; init; } + public string? ShowEnumOrigins { get; set; } } diff --git a/src/Merge.Client/Crm/Opportunities/Requests/OpportunityEndpointRequest.cs b/src/Merge.Client/Crm/Opportunities/Requests/OpportunityEndpointRequest.cs index 2121a67f..afcfa0d8 100644 --- a/src/Merge.Client/Crm/Opportunities/Requests/OpportunityEndpointRequest.cs +++ b/src/Merge.Client/Crm/Opportunities/Requests/OpportunityEndpointRequest.cs @@ -1,20 +1,16 @@ -using Merge.Client.Crm; - -#nullable enable - namespace Merge.Client.Crm; -public class OpportunityEndpointRequest +public record OpportunityEndpointRequest { /// /// Whether to include debug fields (such as log file links) in the response. /// - public bool? IsDebugMode { get; init; } + public bool? IsDebugMode { get; set; } /// /// Whether or not third-party updates should be run asynchronously. /// - public bool? RunAsync { get; init; } + public bool? RunAsync { get; set; } - public OpportunityRequest Model { get; init; } + public required OpportunityRequest Model { get; set; } } diff --git a/src/Merge.Client/Crm/Opportunities/Requests/PatchedOpportunityEndpointRequest.cs b/src/Merge.Client/Crm/Opportunities/Requests/PatchedOpportunityEndpointRequest.cs index 7fd8ded7..4b826b00 100644 --- a/src/Merge.Client/Crm/Opportunities/Requests/PatchedOpportunityEndpointRequest.cs +++ b/src/Merge.Client/Crm/Opportunities/Requests/PatchedOpportunityEndpointRequest.cs @@ -1,20 +1,16 @@ -using Merge.Client.Crm; - -#nullable enable - namespace Merge.Client.Crm; -public class PatchedOpportunityEndpointRequest +public record PatchedOpportunityEndpointRequest { /// /// Whether to include debug fields (such as log file links) in the response. /// - public bool? IsDebugMode { get; init; } + public bool? IsDebugMode { get; set; } /// /// Whether or not third-party updates should be run asynchronously. /// - public bool? RunAsync { get; init; } + public bool? RunAsync { get; set; } - public PatchedOpportunityRequest Model { get; init; } + public required PatchedOpportunityRequest Model { get; set; } } diff --git a/src/Merge.Client/Crm/Opportunities/Types/OpportunitiesListRequestExpand.cs b/src/Merge.Client/Crm/Opportunities/Types/OpportunitiesListRequestExpand.cs index 395e222f..c96938a3 100644 --- a/src/Merge.Client/Crm/Opportunities/Types/OpportunitiesListRequestExpand.cs +++ b/src/Merge.Client/Crm/Opportunities/Types/OpportunitiesListRequestExpand.cs @@ -1,7 +1,6 @@ using System.Runtime.Serialization; using System.Text.Json.Serialization; using Merge.Client.Core; -using Merge.Client.Crm; #nullable enable diff --git a/src/Merge.Client/Crm/Opportunities/Types/OpportunitiesListRequestStatus.cs b/src/Merge.Client/Crm/Opportunities/Types/OpportunitiesListRequestStatus.cs index 0ff1584a..c620ff53 100644 --- a/src/Merge.Client/Crm/Opportunities/Types/OpportunitiesListRequestStatus.cs +++ b/src/Merge.Client/Crm/Opportunities/Types/OpportunitiesListRequestStatus.cs @@ -1,7 +1,6 @@ using System.Runtime.Serialization; using System.Text.Json.Serialization; using Merge.Client.Core; -using Merge.Client.Crm; #nullable enable diff --git a/src/Merge.Client/Crm/Opportunities/Types/OpportunitiesRetrieveRequestExpand.cs b/src/Merge.Client/Crm/Opportunities/Types/OpportunitiesRetrieveRequestExpand.cs index b755a284..ada5ae6d 100644 --- a/src/Merge.Client/Crm/Opportunities/Types/OpportunitiesRetrieveRequestExpand.cs +++ b/src/Merge.Client/Crm/Opportunities/Types/OpportunitiesRetrieveRequestExpand.cs @@ -1,7 +1,6 @@ using System.Runtime.Serialization; using System.Text.Json.Serialization; using Merge.Client.Core; -using Merge.Client.Crm; #nullable enable diff --git a/src/Merge.Client/Crm/Passthrough/PassthroughClient.cs b/src/Merge.Client/Crm/Passthrough/PassthroughClient.cs index 77fb0bdc..31018700 100644 --- a/src/Merge.Client/Crm/Passthrough/PassthroughClient.cs +++ b/src/Merge.Client/Crm/Passthrough/PassthroughClient.cs @@ -1,6 +1,6 @@ +using System.Net.Http; using System.Text.Json; -using Merge.Client; -using Merge.Client.Crm; +using Merge.Client.Core; #nullable enable @@ -18,21 +18,38 @@ public PassthroughClient(RawClient client) /// /// Pull data from an endpoint not currently supported by Merge. /// - public async Task CreateAsync(DataPassthroughRequest request) + public async Task CreateAsync( + DataPassthroughRequest request, + RequestOptions? options = null + ) { var response = await _client.MakeRequestAsync( new RawClient.JsonApiRequest { + BaseUrl = _client.Options.BaseUrl, Method = HttpMethod.Post, Path = "crm/v1/passthrough", - Body = request + Body = request, + Options = options } ); - string responseBody = await response.Raw.Content.ReadAsStringAsync(); - if (response.StatusCode >= 200 && response.StatusCode < 400) + var responseBody = await response.Raw.Content.ReadAsStringAsync(); + if (response.StatusCode is >= 200 and < 400) { - return JsonSerializer.Deserialize(responseBody); + try + { + return JsonUtils.Deserialize(responseBody)!; + } + catch (JsonException e) + { + throw new MergeException("Failed to deserialize response", e); + } } - throw new Exception(responseBody); + + throw new MergeApiException( + $"Error with status code {response.StatusCode}", + response.StatusCode, + JsonUtils.Deserialize(responseBody) + ); } } diff --git a/src/Merge.Client/Crm/RegenerateKey/RegenerateKeyClient.cs b/src/Merge.Client/Crm/RegenerateKey/RegenerateKeyClient.cs index e6c7e9e5..01540c05 100644 --- a/src/Merge.Client/Crm/RegenerateKey/RegenerateKeyClient.cs +++ b/src/Merge.Client/Crm/RegenerateKey/RegenerateKeyClient.cs @@ -1,6 +1,6 @@ +using System.Net.Http; using System.Text.Json; -using Merge.Client; -using Merge.Client.Crm; +using Merge.Client.Core; #nullable enable @@ -18,21 +18,38 @@ public RegenerateKeyClient(RawClient client) /// /// Exchange remote keys. /// - public async Task CreateAsync(RemoteKeyForRegenerationRequest request) + public async Task CreateAsync( + RemoteKeyForRegenerationRequest request, + RequestOptions? options = null + ) { var response = await _client.MakeRequestAsync( new RawClient.JsonApiRequest { + BaseUrl = _client.Options.BaseUrl, Method = HttpMethod.Post, Path = "crm/v1/regenerate-key", - Body = request + Body = request, + Options = options } ); - string responseBody = await response.Raw.Content.ReadAsStringAsync(); - if (response.StatusCode >= 200 && response.StatusCode < 400) + var responseBody = await response.Raw.Content.ReadAsStringAsync(); + if (response.StatusCode is >= 200 and < 400) { - return JsonSerializer.Deserialize(responseBody); + try + { + return JsonUtils.Deserialize(responseBody)!; + } + catch (JsonException e) + { + throw new MergeException("Failed to deserialize response", e); + } } - throw new Exception(responseBody); + + throw new MergeApiException( + $"Error with status code {response.StatusCode}", + response.StatusCode, + JsonUtils.Deserialize(responseBody) + ); } } diff --git a/src/Merge.Client/Crm/RegenerateKey/Requests/RemoteKeyForRegenerationRequest.cs b/src/Merge.Client/Crm/RegenerateKey/Requests/RemoteKeyForRegenerationRequest.cs index 9d647d80..67d03c60 100644 --- a/src/Merge.Client/Crm/RegenerateKey/Requests/RemoteKeyForRegenerationRequest.cs +++ b/src/Merge.Client/Crm/RegenerateKey/Requests/RemoteKeyForRegenerationRequest.cs @@ -4,11 +4,11 @@ namespace Merge.Client.Crm; -public class RemoteKeyForRegenerationRequest +public record RemoteKeyForRegenerationRequest { /// /// The name of the remote key /// [JsonPropertyName("name")] - public string Name { get; init; } + public required string Name { get; set; } } diff --git a/src/Merge.Client/Crm/Scopes/Requests/LinkedAccountCommonModelScopeDeserializerRequest.cs b/src/Merge.Client/Crm/Scopes/Requests/LinkedAccountCommonModelScopeDeserializerRequest.cs index f28b71ec..2588b28f 100644 --- a/src/Merge.Client/Crm/Scopes/Requests/LinkedAccountCommonModelScopeDeserializerRequest.cs +++ b/src/Merge.Client/Crm/Scopes/Requests/LinkedAccountCommonModelScopeDeserializerRequest.cs @@ -1,15 +1,15 @@ using System.Text.Json.Serialization; -using Merge.Client.Crm; #nullable enable namespace Merge.Client.Crm; -public class LinkedAccountCommonModelScopeDeserializerRequest +public record LinkedAccountCommonModelScopeDeserializerRequest { /// /// The common models you want to update the scopes for /// [JsonPropertyName("common_models")] - public IEnumerable CommonModels { get; init; } + public IEnumerable CommonModels { get; set; } = + new List(); } diff --git a/src/Merge.Client/Crm/Scopes/ScopesClient.cs b/src/Merge.Client/Crm/Scopes/ScopesClient.cs index f27066d4..c9041696 100644 --- a/src/Merge.Client/Crm/Scopes/ScopesClient.cs +++ b/src/Merge.Client/Crm/Scopes/ScopesClient.cs @@ -1,6 +1,6 @@ +using System.Net.Http; using System.Text.Json; -using Merge.Client; -using Merge.Client.Crm; +using Merge.Client.Core; #nullable enable @@ -18,59 +18,110 @@ public ScopesClient(RawClient client) /// /// Get the default permissions for Merge Common Models and fields across all Linked Accounts of a given category. [Learn more](https://help.merge.dev/en/articles/8828211-common-model-and-field-scopes). /// - public async Task DefaultScopesRetrieveAsync() + public async Task DefaultScopesRetrieveAsync( + RequestOptions? options = null + ) { var response = await _client.MakeRequestAsync( - new RawClient.JsonApiRequest { Method = HttpMethod.Get, Path = "crm/v1/default-scopes" } + new RawClient.JsonApiRequest + { + BaseUrl = _client.Options.BaseUrl, + Method = HttpMethod.Get, + Path = "crm/v1/default-scopes", + Options = options + } ); - string responseBody = await response.Raw.Content.ReadAsStringAsync(); - if (response.StatusCode >= 200 && response.StatusCode < 400) + var responseBody = await response.Raw.Content.ReadAsStringAsync(); + if (response.StatusCode is >= 200 and < 400) { - return JsonSerializer.Deserialize(responseBody); + try + { + return JsonUtils.Deserialize(responseBody)!; + } + catch (JsonException e) + { + throw new MergeException("Failed to deserialize response", e); + } } - throw new Exception(responseBody); + + throw new MergeApiException( + $"Error with status code {response.StatusCode}", + response.StatusCode, + JsonUtils.Deserialize(responseBody) + ); } /// /// Get all available permissions for Merge Common Models and fields for a single Linked Account. [Learn more](https://help.merge.dev/en/articles/8828211-common-model-and-field-scopes). /// - public async Task LinkedAccountScopesRetrieveAsync() + public async Task LinkedAccountScopesRetrieveAsync( + RequestOptions? options = null + ) { var response = await _client.MakeRequestAsync( new RawClient.JsonApiRequest { + BaseUrl = _client.Options.BaseUrl, Method = HttpMethod.Get, - Path = "crm/v1/linked-account-scopes" + Path = "crm/v1/linked-account-scopes", + Options = options } ); - string responseBody = await response.Raw.Content.ReadAsStringAsync(); - if (response.StatusCode >= 200 && response.StatusCode < 400) + var responseBody = await response.Raw.Content.ReadAsStringAsync(); + if (response.StatusCode is >= 200 and < 400) { - return JsonSerializer.Deserialize(responseBody); + try + { + return JsonUtils.Deserialize(responseBody)!; + } + catch (JsonException e) + { + throw new MergeException("Failed to deserialize response", e); + } } - throw new Exception(responseBody); + + throw new MergeApiException( + $"Error with status code {response.StatusCode}", + response.StatusCode, + JsonUtils.Deserialize(responseBody) + ); } /// /// Update permissions for any Common Model or field for a single Linked Account. Any Scopes not set in this POST request will inherit the default Scopes. [Learn more](https://help.merge.dev/en/articles/8828211-common-model-and-field-scopes) /// public async Task LinkedAccountScopesCreateAsync( - LinkedAccountCommonModelScopeDeserializerRequest request + LinkedAccountCommonModelScopeDeserializerRequest request, + RequestOptions? options = null ) { var response = await _client.MakeRequestAsync( new RawClient.JsonApiRequest { + BaseUrl = _client.Options.BaseUrl, Method = HttpMethod.Post, Path = "crm/v1/linked-account-scopes", - Body = request + Body = request, + Options = options } ); - string responseBody = await response.Raw.Content.ReadAsStringAsync(); - if (response.StatusCode >= 200 && response.StatusCode < 400) + var responseBody = await response.Raw.Content.ReadAsStringAsync(); + if (response.StatusCode is >= 200 and < 400) { - return JsonSerializer.Deserialize(responseBody); + try + { + return JsonUtils.Deserialize(responseBody)!; + } + catch (JsonException e) + { + throw new MergeException("Failed to deserialize response", e); + } } - throw new Exception(responseBody); + + throw new MergeApiException( + $"Error with status code {response.StatusCode}", + response.StatusCode, + JsonUtils.Deserialize(responseBody) + ); } } diff --git a/src/Merge.Client/Crm/Stages/Requests/StagesListRequest.cs b/src/Merge.Client/Crm/Stages/Requests/StagesListRequest.cs index 0b1bc4bc..d38aec75 100644 --- a/src/Merge.Client/Crm/Stages/Requests/StagesListRequest.cs +++ b/src/Merge.Client/Crm/Stages/Requests/StagesListRequest.cs @@ -1,54 +1,54 @@ namespace Merge.Client.Crm; -public class StagesListRequest +public record StagesListRequest { /// /// If provided, will only return objects created after this datetime. /// - public DateTime? CreatedAfter { get; init; } + public DateTime? CreatedAfter { get; set; } /// /// If provided, will only return objects created before this datetime. /// - public DateTime? CreatedBefore { get; init; } + public DateTime? CreatedBefore { get; set; } /// /// The pagination cursor value. /// - public string? Cursor { get; init; } + public string? Cursor { get; set; } /// /// Whether to include data that was marked as deleted by third party webhooks. /// - public bool? IncludeDeletedData { get; init; } + public bool? IncludeDeletedData { get; set; } /// /// Whether to include the original data Merge fetched from the third-party to produce these models. /// - public bool? IncludeRemoteData { get; init; } + public bool? IncludeRemoteData { get; set; } /// /// Whether to include all remote fields, including fields that Merge did not map to common models, in a normalized format. /// - public bool? IncludeRemoteFields { get; init; } + public bool? IncludeRemoteFields { get; set; } /// /// If provided, only objects synced by Merge after this date time will be returned. /// - public DateTime? ModifiedAfter { get; init; } + public DateTime? ModifiedAfter { get; set; } /// /// If provided, only objects synced by Merge before this date time will be returned. /// - public DateTime? ModifiedBefore { get; init; } + public DateTime? ModifiedBefore { get; set; } /// /// Number of results to return per page. /// - public int? PageSize { get; init; } + public int? PageSize { get; set; } /// /// The API provider's ID for the given object. /// - public string? RemoteId { get; init; } + public string? RemoteId { get; set; } } diff --git a/src/Merge.Client/Crm/Stages/Requests/StagesRemoteFieldClassesListRequest.cs b/src/Merge.Client/Crm/Stages/Requests/StagesRemoteFieldClassesListRequest.cs index e1ef0585..93eca83d 100644 --- a/src/Merge.Client/Crm/Stages/Requests/StagesRemoteFieldClassesListRequest.cs +++ b/src/Merge.Client/Crm/Stages/Requests/StagesRemoteFieldClassesListRequest.cs @@ -1,34 +1,34 @@ namespace Merge.Client.Crm; -public class StagesRemoteFieldClassesListRequest +public record StagesRemoteFieldClassesListRequest { /// /// The pagination cursor value. /// - public string? Cursor { get; init; } + public string? Cursor { get; set; } /// /// Whether to include data that was marked as deleted by third party webhooks. /// - public bool? IncludeDeletedData { get; init; } + public bool? IncludeDeletedData { get; set; } /// /// Whether to include the original data Merge fetched from the third-party to produce these models. /// - public bool? IncludeRemoteData { get; init; } + public bool? IncludeRemoteData { get; set; } /// /// Whether to include all remote fields, including fields that Merge did not map to common models, in a normalized format. /// - public bool? IncludeRemoteFields { get; init; } + public bool? IncludeRemoteFields { get; set; } /// /// If provided, will only return remote field classes with this is_common_model_field value /// - public bool? IsCommonModelField { get; init; } + public bool? IsCommonModelField { get; set; } /// /// Number of results to return per page. /// - public int? PageSize { get; init; } + public int? PageSize { get; set; } } diff --git a/src/Merge.Client/Crm/Stages/Requests/StagesRetrieveRequest.cs b/src/Merge.Client/Crm/Stages/Requests/StagesRetrieveRequest.cs index 83d94c9a..192a393b 100644 --- a/src/Merge.Client/Crm/Stages/Requests/StagesRetrieveRequest.cs +++ b/src/Merge.Client/Crm/Stages/Requests/StagesRetrieveRequest.cs @@ -1,14 +1,14 @@ namespace Merge.Client.Crm; -public class StagesRetrieveRequest +public record StagesRetrieveRequest { /// /// Whether to include the original data Merge fetched from the third-party to produce these models. /// - public bool? IncludeRemoteData { get; init; } + public bool? IncludeRemoteData { get; set; } /// /// Whether to include all remote fields, including fields that Merge did not map to common models, in a normalized format. /// - public bool? IncludeRemoteFields { get; init; } + public bool? IncludeRemoteFields { get; set; } } diff --git a/src/Merge.Client/Crm/Stages/StagesClient.cs b/src/Merge.Client/Crm/Stages/StagesClient.cs index 065500dc..8ed17c2a 100644 --- a/src/Merge.Client/Crm/Stages/StagesClient.cs +++ b/src/Merge.Client/Crm/Stages/StagesClient.cs @@ -1,6 +1,6 @@ +using System.Net.Http; using System.Text.Json; -using Merge.Client; -using Merge.Client.Crm; +using Merge.Client.Core; #nullable enable @@ -18,16 +18,21 @@ public StagesClient(RawClient client) /// /// Returns a list of `Stage` objects. /// - public async Task ListAsync(StagesListRequest request) + public async Task ListAsync( + StagesListRequest request, + RequestOptions? options = null + ) { var _query = new Dictionary() { }; if (request.CreatedAfter != null) { - _query["created_after"] = request.CreatedAfter.Value.ToString("o0"); + _query["created_after"] = request.CreatedAfter.Value.ToString(Constants.DateTimeFormat); } if (request.CreatedBefore != null) { - _query["created_before"] = request.CreatedBefore.Value.ToString("o0"); + _query["created_before"] = request.CreatedBefore.Value.ToString( + Constants.DateTimeFormat + ); } if (request.Cursor != null) { @@ -47,11 +52,15 @@ public async Task ListAsync(StagesListRequest request) } if (request.ModifiedAfter != null) { - _query["modified_after"] = request.ModifiedAfter.Value.ToString("o0"); + _query["modified_after"] = request.ModifiedAfter.Value.ToString( + Constants.DateTimeFormat + ); } if (request.ModifiedBefore != null) { - _query["modified_before"] = request.ModifiedBefore.Value.ToString("o0"); + _query["modified_before"] = request.ModifiedBefore.Value.ToString( + Constants.DateTimeFormat + ); } if (request.PageSize != null) { @@ -64,23 +73,41 @@ public async Task ListAsync(StagesListRequest request) var response = await _client.MakeRequestAsync( new RawClient.JsonApiRequest { + BaseUrl = _client.Options.BaseUrl, Method = HttpMethod.Get, Path = "crm/v1/stages", - Query = _query + Query = _query, + Options = options } ); - string responseBody = await response.Raw.Content.ReadAsStringAsync(); - if (response.StatusCode >= 200 && response.StatusCode < 400) + var responseBody = await response.Raw.Content.ReadAsStringAsync(); + if (response.StatusCode is >= 200 and < 400) { - return JsonSerializer.Deserialize(responseBody); + try + { + return JsonUtils.Deserialize(responseBody)!; + } + catch (JsonException e) + { + throw new MergeException("Failed to deserialize response", e); + } } - throw new Exception(responseBody); + + throw new MergeApiException( + $"Error with status code {response.StatusCode}", + response.StatusCode, + JsonUtils.Deserialize(responseBody) + ); } /// /// Returns a `Stage` object with the given `id`. /// - public async Task RetrieveAsync(string id, StagesRetrieveRequest request) + public async Task RetrieveAsync( + string id, + StagesRetrieveRequest request, + RequestOptions? options = null + ) { var _query = new Dictionary() { }; if (request.IncludeRemoteData != null) @@ -94,24 +121,39 @@ public async Task RetrieveAsync(string id, StagesRetrieveRequest request) var response = await _client.MakeRequestAsync( new RawClient.JsonApiRequest { + BaseUrl = _client.Options.BaseUrl, Method = HttpMethod.Get, Path = $"crm/v1/stages/{id}", - Query = _query + Query = _query, + Options = options } ); - string responseBody = await response.Raw.Content.ReadAsStringAsync(); - if (response.StatusCode >= 200 && response.StatusCode < 400) + var responseBody = await response.Raw.Content.ReadAsStringAsync(); + if (response.StatusCode is >= 200 and < 400) { - return JsonSerializer.Deserialize(responseBody); + try + { + return JsonUtils.Deserialize(responseBody)!; + } + catch (JsonException e) + { + throw new MergeException("Failed to deserialize response", e); + } } - throw new Exception(responseBody); + + throw new MergeApiException( + $"Error with status code {response.StatusCode}", + response.StatusCode, + JsonUtils.Deserialize(responseBody) + ); } /// /// Returns a list of `RemoteFieldClass` objects. /// public async Task RemoteFieldClassesListAsync( - StagesRemoteFieldClassesListRequest request + StagesRemoteFieldClassesListRequest request, + RequestOptions? options = null ) { var _query = new Dictionary() { }; @@ -142,16 +184,30 @@ StagesRemoteFieldClassesListRequest request var response = await _client.MakeRequestAsync( new RawClient.JsonApiRequest { + BaseUrl = _client.Options.BaseUrl, Method = HttpMethod.Get, Path = "crm/v1/stages/remote-field-classes", - Query = _query + Query = _query, + Options = options } ); - string responseBody = await response.Raw.Content.ReadAsStringAsync(); - if (response.StatusCode >= 200 && response.StatusCode < 400) + var responseBody = await response.Raw.Content.ReadAsStringAsync(); + if (response.StatusCode is >= 200 and < 400) { - return JsonSerializer.Deserialize(responseBody); + try + { + return JsonUtils.Deserialize(responseBody)!; + } + catch (JsonException e) + { + throw new MergeException("Failed to deserialize response", e); + } } - throw new Exception(responseBody); + + throw new MergeApiException( + $"Error with status code {response.StatusCode}", + response.StatusCode, + JsonUtils.Deserialize(responseBody) + ); } } diff --git a/src/Merge.Client/Crm/SyncStatus/Requests/SyncStatusListRequest.cs b/src/Merge.Client/Crm/SyncStatus/Requests/SyncStatusListRequest.cs index 283ec694..7b112636 100644 --- a/src/Merge.Client/Crm/SyncStatus/Requests/SyncStatusListRequest.cs +++ b/src/Merge.Client/Crm/SyncStatus/Requests/SyncStatusListRequest.cs @@ -1,14 +1,14 @@ namespace Merge.Client.Crm; -public class SyncStatusListRequest +public record SyncStatusListRequest { /// /// The pagination cursor value. /// - public string? Cursor { get; init; } + public string? Cursor { get; set; } /// /// Number of results to return per page. /// - public int? PageSize { get; init; } + public int? PageSize { get; set; } } diff --git a/src/Merge.Client/Crm/SyncStatus/SyncStatusClient.cs b/src/Merge.Client/Crm/SyncStatus/SyncStatusClient.cs index bfdd76e4..094d2b55 100644 --- a/src/Merge.Client/Crm/SyncStatus/SyncStatusClient.cs +++ b/src/Merge.Client/Crm/SyncStatus/SyncStatusClient.cs @@ -1,6 +1,6 @@ +using System.Net.Http; using System.Text.Json; -using Merge.Client; -using Merge.Client.Crm; +using Merge.Client.Core; #nullable enable @@ -18,7 +18,10 @@ public SyncStatusClient(RawClient client) /// /// Get syncing status. Possible values: `DISABLED`, `DONE`, `FAILED`, `PARTIALLY_SYNCED`, `PAUSED`, `SYNCING`. Learn more about sync status in our [Help Center](https://help.merge.dev/en/articles/8184193-merge-sync-statuses). /// - public async Task ListAsync(SyncStatusListRequest request) + public async Task ListAsync( + SyncStatusListRequest request, + RequestOptions? options = null + ) { var _query = new Dictionary() { }; if (request.Cursor != null) @@ -32,16 +35,30 @@ public async Task ListAsync(SyncStatusListRequest reque var response = await _client.MakeRequestAsync( new RawClient.JsonApiRequest { + BaseUrl = _client.Options.BaseUrl, Method = HttpMethod.Get, Path = "crm/v1/sync-status", - Query = _query + Query = _query, + Options = options } ); - string responseBody = await response.Raw.Content.ReadAsStringAsync(); - if (response.StatusCode >= 200 && response.StatusCode < 400) + var responseBody = await response.Raw.Content.ReadAsStringAsync(); + if (response.StatusCode is >= 200 and < 400) { - return JsonSerializer.Deserialize(responseBody); + try + { + return JsonUtils.Deserialize(responseBody)!; + } + catch (JsonException e) + { + throw new MergeException("Failed to deserialize response", e); + } } - throw new Exception(responseBody); + + throw new MergeApiException( + $"Error with status code {response.StatusCode}", + response.StatusCode, + JsonUtils.Deserialize(responseBody) + ); } } diff --git a/src/Merge.Client/Crm/Tasks/Requests/PatchedTaskEndpointRequest.cs b/src/Merge.Client/Crm/Tasks/Requests/PatchedTaskEndpointRequest.cs index a4318c8c..8020bde6 100644 --- a/src/Merge.Client/Crm/Tasks/Requests/PatchedTaskEndpointRequest.cs +++ b/src/Merge.Client/Crm/Tasks/Requests/PatchedTaskEndpointRequest.cs @@ -1,20 +1,16 @@ -using Merge.Client.Crm; - -#nullable enable - namespace Merge.Client.Crm; -public class PatchedTaskEndpointRequest +public record PatchedTaskEndpointRequest { /// /// Whether to include debug fields (such as log file links) in the response. /// - public bool? IsDebugMode { get; init; } + public bool? IsDebugMode { get; set; } /// /// Whether or not third-party updates should be run asynchronously. /// - public bool? RunAsync { get; init; } + public bool? RunAsync { get; set; } - public PatchedTaskRequest Model { get; init; } + public required PatchedTaskRequest Model { get; set; } } diff --git a/src/Merge.Client/Crm/Tasks/Requests/TaskEndpointRequest.cs b/src/Merge.Client/Crm/Tasks/Requests/TaskEndpointRequest.cs index f324d8a2..56f20535 100644 --- a/src/Merge.Client/Crm/Tasks/Requests/TaskEndpointRequest.cs +++ b/src/Merge.Client/Crm/Tasks/Requests/TaskEndpointRequest.cs @@ -1,20 +1,16 @@ -using Merge.Client.Crm; - -#nullable enable - namespace Merge.Client.Crm; -public class TaskEndpointRequest +public record TaskEndpointRequest { /// /// Whether to include debug fields (such as log file links) in the response. /// - public bool? IsDebugMode { get; init; } + public bool? IsDebugMode { get; set; } /// /// Whether or not third-party updates should be run asynchronously. /// - public bool? RunAsync { get; init; } + public bool? RunAsync { get; set; } - public TaskRequest Model { get; init; } + public required TaskRequest Model { get; set; } } diff --git a/src/Merge.Client/Crm/Tasks/Requests/TasksListRequest.cs b/src/Merge.Client/Crm/Tasks/Requests/TasksListRequest.cs index 67ebbd8d..3ce1eb91 100644 --- a/src/Merge.Client/Crm/Tasks/Requests/TasksListRequest.cs +++ b/src/Merge.Client/Crm/Tasks/Requests/TasksListRequest.cs @@ -1,63 +1,59 @@ -using Merge.Client.Crm; - -#nullable enable - namespace Merge.Client.Crm; -public class TasksListRequest +public record TasksListRequest { /// /// If provided, will only return objects created after this datetime. /// - public DateTime? CreatedAfter { get; init; } + public DateTime? CreatedAfter { get; set; } /// /// If provided, will only return objects created before this datetime. /// - public DateTime? CreatedBefore { get; init; } + public DateTime? CreatedBefore { get; set; } /// /// The pagination cursor value. /// - public string? Cursor { get; init; } + public string? Cursor { get; set; } /// /// Which relations should be returned in expanded form. Multiple relation names should be comma separated without spaces. /// - public TasksListRequestExpand? Expand { get; init; } + public TasksListRequestExpand? Expand { get; set; } /// /// Whether to include data that was marked as deleted by third party webhooks. /// - public bool? IncludeDeletedData { get; init; } + public bool? IncludeDeletedData { get; set; } /// /// Whether to include the original data Merge fetched from the third-party to produce these models. /// - public bool? IncludeRemoteData { get; init; } + public bool? IncludeRemoteData { get; set; } /// /// Whether to include all remote fields, including fields that Merge did not map to common models, in a normalized format. /// - public bool? IncludeRemoteFields { get; init; } + public bool? IncludeRemoteFields { get; set; } /// /// If provided, only objects synced by Merge after this date time will be returned. /// - public DateTime? ModifiedAfter { get; init; } + public DateTime? ModifiedAfter { get; set; } /// /// If provided, only objects synced by Merge before this date time will be returned. /// - public DateTime? ModifiedBefore { get; init; } + public DateTime? ModifiedBefore { get; set; } /// /// Number of results to return per page. /// - public int? PageSize { get; init; } + public int? PageSize { get; set; } /// /// The API provider's ID for the given object. /// - public string? RemoteId { get; init; } + public string? RemoteId { get; set; } } diff --git a/src/Merge.Client/Crm/Tasks/Requests/TasksRemoteFieldClassesListRequest.cs b/src/Merge.Client/Crm/Tasks/Requests/TasksRemoteFieldClassesListRequest.cs index fcfea338..49cf2826 100644 --- a/src/Merge.Client/Crm/Tasks/Requests/TasksRemoteFieldClassesListRequest.cs +++ b/src/Merge.Client/Crm/Tasks/Requests/TasksRemoteFieldClassesListRequest.cs @@ -1,34 +1,34 @@ namespace Merge.Client.Crm; -public class TasksRemoteFieldClassesListRequest +public record TasksRemoteFieldClassesListRequest { /// /// The pagination cursor value. /// - public string? Cursor { get; init; } + public string? Cursor { get; set; } /// /// Whether to include data that was marked as deleted by third party webhooks. /// - public bool? IncludeDeletedData { get; init; } + public bool? IncludeDeletedData { get; set; } /// /// Whether to include the original data Merge fetched from the third-party to produce these models. /// - public bool? IncludeRemoteData { get; init; } + public bool? IncludeRemoteData { get; set; } /// /// Whether to include all remote fields, including fields that Merge did not map to common models, in a normalized format. /// - public bool? IncludeRemoteFields { get; init; } + public bool? IncludeRemoteFields { get; set; } /// /// If provided, will only return remote field classes with this is_common_model_field value /// - public bool? IsCommonModelField { get; init; } + public bool? IsCommonModelField { get; set; } /// /// Number of results to return per page. /// - public int? PageSize { get; init; } + public int? PageSize { get; set; } } diff --git a/src/Merge.Client/Crm/Tasks/Requests/TasksRetrieveRequest.cs b/src/Merge.Client/Crm/Tasks/Requests/TasksRetrieveRequest.cs index 18a20dff..017bd774 100644 --- a/src/Merge.Client/Crm/Tasks/Requests/TasksRetrieveRequest.cs +++ b/src/Merge.Client/Crm/Tasks/Requests/TasksRetrieveRequest.cs @@ -1,23 +1,19 @@ -using Merge.Client.Crm; - -#nullable enable - namespace Merge.Client.Crm; -public class TasksRetrieveRequest +public record TasksRetrieveRequest { /// /// Which relations should be returned in expanded form. Multiple relation names should be comma separated without spaces. /// - public TasksRetrieveRequestExpand? Expand { get; init; } + public TasksRetrieveRequestExpand? Expand { get; set; } /// /// Whether to include the original data Merge fetched from the third-party to produce these models. /// - public bool? IncludeRemoteData { get; init; } + public bool? IncludeRemoteData { get; set; } /// /// Whether to include all remote fields, including fields that Merge did not map to common models, in a normalized format. /// - public bool? IncludeRemoteFields { get; init; } + public bool? IncludeRemoteFields { get; set; } } diff --git a/src/Merge.Client/Crm/Tasks/TasksClient.cs b/src/Merge.Client/Crm/Tasks/TasksClient.cs index 701b3d32..c9589f31 100644 --- a/src/Merge.Client/Crm/Tasks/TasksClient.cs +++ b/src/Merge.Client/Crm/Tasks/TasksClient.cs @@ -1,6 +1,6 @@ +using System.Net.Http; using System.Text.Json; -using Merge.Client; -using Merge.Client.Crm; +using Merge.Client.Core; #nullable enable @@ -18,16 +18,21 @@ public TasksClient(RawClient client) /// /// Returns a list of `Task` objects. /// - public async Task ListAsync(TasksListRequest request) + public async Task ListAsync( + TasksListRequest request, + RequestOptions? options = null + ) { var _query = new Dictionary() { }; if (request.CreatedAfter != null) { - _query["created_after"] = request.CreatedAfter.Value.ToString("o0"); + _query["created_after"] = request.CreatedAfter.Value.ToString(Constants.DateTimeFormat); } if (request.CreatedBefore != null) { - _query["created_before"] = request.CreatedBefore.Value.ToString("o0"); + _query["created_before"] = request.CreatedBefore.Value.ToString( + Constants.DateTimeFormat + ); } if (request.Cursor != null) { @@ -51,11 +56,15 @@ public async Task ListAsync(TasksListRequest request) } if (request.ModifiedAfter != null) { - _query["modified_after"] = request.ModifiedAfter.Value.ToString("o0"); + _query["modified_after"] = request.ModifiedAfter.Value.ToString( + Constants.DateTimeFormat + ); } if (request.ModifiedBefore != null) { - _query["modified_before"] = request.ModifiedBefore.Value.ToString("o0"); + _query["modified_before"] = request.ModifiedBefore.Value.ToString( + Constants.DateTimeFormat + ); } if (request.PageSize != null) { @@ -68,23 +77,40 @@ public async Task ListAsync(TasksListRequest request) var response = await _client.MakeRequestAsync( new RawClient.JsonApiRequest { + BaseUrl = _client.Options.BaseUrl, Method = HttpMethod.Get, Path = "crm/v1/tasks", - Query = _query + Query = _query, + Options = options } ); - string responseBody = await response.Raw.Content.ReadAsStringAsync(); - if (response.StatusCode >= 200 && response.StatusCode < 400) + var responseBody = await response.Raw.Content.ReadAsStringAsync(); + if (response.StatusCode is >= 200 and < 400) { - return JsonSerializer.Deserialize(responseBody); + try + { + return JsonUtils.Deserialize(responseBody)!; + } + catch (JsonException e) + { + throw new MergeException("Failed to deserialize response", e); + } } - throw new Exception(responseBody); + + throw new MergeApiException( + $"Error with status code {response.StatusCode}", + response.StatusCode, + JsonUtils.Deserialize(responseBody) + ); } /// /// Creates a `Task` object with the given values. /// - public async Task CreateAsync(TaskEndpointRequest request) + public async Task CreateAsync( + TaskEndpointRequest request, + RequestOptions? options = null + ) { var _query = new Dictionary() { }; if (request.IsDebugMode != null) @@ -98,23 +124,41 @@ public async Task CreateAsync(TaskEndpointRequest request) var response = await _client.MakeRequestAsync( new RawClient.JsonApiRequest { + BaseUrl = _client.Options.BaseUrl, Method = HttpMethod.Post, Path = "crm/v1/tasks", - Query = _query + Query = _query, + Options = options } ); - string responseBody = await response.Raw.Content.ReadAsStringAsync(); - if (response.StatusCode >= 200 && response.StatusCode < 400) + var responseBody = await response.Raw.Content.ReadAsStringAsync(); + if (response.StatusCode is >= 200 and < 400) { - return JsonSerializer.Deserialize(responseBody); + try + { + return JsonUtils.Deserialize(responseBody)!; + } + catch (JsonException e) + { + throw new MergeException("Failed to deserialize response", e); + } } - throw new Exception(responseBody); + + throw new MergeApiException( + $"Error with status code {response.StatusCode}", + response.StatusCode, + JsonUtils.Deserialize(responseBody) + ); } /// /// Returns a `Task` object with the given `id`. /// - public async Task RetrieveAsync(string id, TasksRetrieveRequest request) + public async Task RetrieveAsync( + string id, + TasksRetrieveRequest request, + RequestOptions? options = null + ) { var _query = new Dictionary() { }; if (request.Expand != null) @@ -132,17 +176,31 @@ public async Task RetrieveAsync(string id, TasksRetrieveRequest request) var response = await _client.MakeRequestAsync( new RawClient.JsonApiRequest { + BaseUrl = _client.Options.BaseUrl, Method = HttpMethod.Get, Path = $"crm/v1/tasks/{id}", - Query = _query + Query = _query, + Options = options } ); - string responseBody = await response.Raw.Content.ReadAsStringAsync(); - if (response.StatusCode >= 200 && response.StatusCode < 400) + var responseBody = await response.Raw.Content.ReadAsStringAsync(); + if (response.StatusCode is >= 200 and < 400) { - return JsonSerializer.Deserialize(responseBody); + try + { + return JsonUtils.Deserialize(responseBody)!; + } + catch (JsonException e) + { + throw new MergeException("Failed to deserialize response", e); + } } - throw new Exception(responseBody); + + throw new MergeApiException( + $"Error with status code {response.StatusCode}", + response.StatusCode, + JsonUtils.Deserialize(responseBody) + ); } /// @@ -150,7 +208,8 @@ public async Task RetrieveAsync(string id, TasksRetrieveRequest request) /// public async Task PartialUpdateAsync( string id, - PatchedTaskEndpointRequest request + PatchedTaskEndpointRequest request, + RequestOptions? options = null ) { var _query = new Dictionary() { }; @@ -165,64 +224,110 @@ PatchedTaskEndpointRequest request var response = await _client.MakeRequestAsync( new RawClient.JsonApiRequest { - Method = HttpMethod.Patch, + BaseUrl = _client.Options.BaseUrl, + Method = HttpMethodExtensions.Patch, Path = $"crm/v1/tasks/{id}", - Query = _query + Query = _query, + Options = options } ); - string responseBody = await response.Raw.Content.ReadAsStringAsync(); - if (response.StatusCode >= 200 && response.StatusCode < 400) + var responseBody = await response.Raw.Content.ReadAsStringAsync(); + if (response.StatusCode is >= 200 and < 400) { - return JsonSerializer.Deserialize(responseBody); + try + { + return JsonUtils.Deserialize(responseBody)!; + } + catch (JsonException e) + { + throw new MergeException("Failed to deserialize response", e); + } } - throw new Exception(responseBody); + + throw new MergeApiException( + $"Error with status code {response.StatusCode}", + response.StatusCode, + JsonUtils.Deserialize(responseBody) + ); } /// /// Returns metadata for `Task` PATCHs. /// - public async Task MetaPatchRetrieveAsync(string id) + public async Task MetaPatchRetrieveAsync( + string id, + RequestOptions? options = null + ) { var response = await _client.MakeRequestAsync( new RawClient.JsonApiRequest { + BaseUrl = _client.Options.BaseUrl, Method = HttpMethod.Get, - Path = $"crm/v1/tasks/meta/patch/{id}" + Path = $"crm/v1/tasks/meta/patch/{id}", + Options = options } ); - string responseBody = await response.Raw.Content.ReadAsStringAsync(); - if (response.StatusCode >= 200 && response.StatusCode < 400) + var responseBody = await response.Raw.Content.ReadAsStringAsync(); + if (response.StatusCode is >= 200 and < 400) { - return JsonSerializer.Deserialize(responseBody); + try + { + return JsonUtils.Deserialize(responseBody)!; + } + catch (JsonException e) + { + throw new MergeException("Failed to deserialize response", e); + } } - throw new Exception(responseBody); + + throw new MergeApiException( + $"Error with status code {response.StatusCode}", + response.StatusCode, + JsonUtils.Deserialize(responseBody) + ); } /// /// Returns metadata for `Task` POSTs. /// - public async Task MetaPostRetrieveAsync() + public async Task MetaPostRetrieveAsync(RequestOptions? options = null) { var response = await _client.MakeRequestAsync( new RawClient.JsonApiRequest { + BaseUrl = _client.Options.BaseUrl, Method = HttpMethod.Get, - Path = "crm/v1/tasks/meta/post" + Path = "crm/v1/tasks/meta/post", + Options = options } ); - string responseBody = await response.Raw.Content.ReadAsStringAsync(); - if (response.StatusCode >= 200 && response.StatusCode < 400) + var responseBody = await response.Raw.Content.ReadAsStringAsync(); + if (response.StatusCode is >= 200 and < 400) { - return JsonSerializer.Deserialize(responseBody); + try + { + return JsonUtils.Deserialize(responseBody)!; + } + catch (JsonException e) + { + throw new MergeException("Failed to deserialize response", e); + } } - throw new Exception(responseBody); + + throw new MergeApiException( + $"Error with status code {response.StatusCode}", + response.StatusCode, + JsonUtils.Deserialize(responseBody) + ); } /// /// Returns a list of `RemoteFieldClass` objects. /// public async Task RemoteFieldClassesListAsync( - TasksRemoteFieldClassesListRequest request + TasksRemoteFieldClassesListRequest request, + RequestOptions? options = null ) { var _query = new Dictionary() { }; @@ -253,16 +358,30 @@ TasksRemoteFieldClassesListRequest request var response = await _client.MakeRequestAsync( new RawClient.JsonApiRequest { + BaseUrl = _client.Options.BaseUrl, Method = HttpMethod.Get, Path = "crm/v1/tasks/remote-field-classes", - Query = _query + Query = _query, + Options = options } ); - string responseBody = await response.Raw.Content.ReadAsStringAsync(); - if (response.StatusCode >= 200 && response.StatusCode < 400) + var responseBody = await response.Raw.Content.ReadAsStringAsync(); + if (response.StatusCode is >= 200 and < 400) { - return JsonSerializer.Deserialize(responseBody); + try + { + return JsonUtils.Deserialize(responseBody)!; + } + catch (JsonException e) + { + throw new MergeException("Failed to deserialize response", e); + } } - throw new Exception(responseBody); + + throw new MergeApiException( + $"Error with status code {response.StatusCode}", + response.StatusCode, + JsonUtils.Deserialize(responseBody) + ); } } diff --git a/src/Merge.Client/Crm/Tasks/Types/TasksListRequestExpand.cs b/src/Merge.Client/Crm/Tasks/Types/TasksListRequestExpand.cs index 0db96509..d8954715 100644 --- a/src/Merge.Client/Crm/Tasks/Types/TasksListRequestExpand.cs +++ b/src/Merge.Client/Crm/Tasks/Types/TasksListRequestExpand.cs @@ -1,7 +1,6 @@ using System.Runtime.Serialization; using System.Text.Json.Serialization; using Merge.Client.Core; -using Merge.Client.Crm; #nullable enable diff --git a/src/Merge.Client/Crm/Tasks/Types/TasksRetrieveRequestExpand.cs b/src/Merge.Client/Crm/Tasks/Types/TasksRetrieveRequestExpand.cs index 55cc68bf..80bfc9aa 100644 --- a/src/Merge.Client/Crm/Tasks/Types/TasksRetrieveRequestExpand.cs +++ b/src/Merge.Client/Crm/Tasks/Types/TasksRetrieveRequestExpand.cs @@ -1,7 +1,6 @@ using System.Runtime.Serialization; using System.Text.Json.Serialization; using Merge.Client.Core; -using Merge.Client.Crm; #nullable enable diff --git a/src/Merge.Client/Crm/Types/Account.cs b/src/Merge.Client/Crm/Types/Account.cs index c6e22643..3f6c6479 100644 --- a/src/Merge.Client/Crm/Types/Account.cs +++ b/src/Merge.Client/Crm/Types/Account.cs @@ -1,105 +1,104 @@ using System.Text.Json.Serialization; using Merge.Client.Core; -using Merge.Client.Crm; using OneOf; #nullable enable namespace Merge.Client.Crm; -public class Account +public record Account { [JsonPropertyName("id")] - public string? Id { get; init; } + public string? Id { get; set; } /// /// The third-party API ID of the matching object. /// [JsonPropertyName("remote_id")] - public string? RemoteId { get; init; } + public string? RemoteId { get; set; } /// /// The datetime that this object was created by Merge. /// [JsonPropertyName("created_at")] - public DateTime? CreatedAt { get; init; } + public DateTime? CreatedAt { get; set; } /// /// The datetime that this object was modified by Merge. /// [JsonPropertyName("modified_at")] - public DateTime? ModifiedAt { get; init; } + public DateTime? ModifiedAt { get; set; } /// /// The account's owner. /// [JsonPropertyName("owner")] [JsonConverter(typeof(OneOfSerializer>))] - public OneOf? Owner { get; init; } + public OneOf? Owner { get; set; } /// /// The account's name. /// [JsonPropertyName("name")] - public string? Name { get; init; } + public string? Name { get; set; } /// /// The account's description. /// [JsonPropertyName("description")] - public string? Description { get; init; } + public string? Description { get; set; } /// /// The account's industry. /// [JsonPropertyName("industry")] - public string? Industry { get; init; } + public string? Industry { get; set; } /// /// The account's website. /// [JsonPropertyName("website")] - public string? Website { get; init; } + public string? Website { get; set; } /// /// The account's number of employees. /// [JsonPropertyName("number_of_employees")] - public int? NumberOfEmployees { get; init; } + public int? NumberOfEmployees { get; set; } [JsonPropertyName("addresses")] - public IEnumerable
? Addresses { get; init; } + public IEnumerable
? Addresses { get; set; } [JsonPropertyName("phone_numbers")] - public IEnumerable? PhoneNumbers { get; init; } + public IEnumerable? PhoneNumbers { get; set; } /// /// The last date (either most recent or furthest in the future) of when an activity occurs in an account. /// [JsonPropertyName("last_activity_at")] - public DateTime? LastActivityAt { get; init; } + public DateTime? LastActivityAt { get; set; } /// /// When the CRM system account data was last modified by a user with a login. /// [JsonPropertyName("remote_updated_at")] - public DateTime? RemoteUpdatedAt { get; init; } + public DateTime? RemoteUpdatedAt { get; set; } /// /// When the third party's account was created. /// [JsonPropertyName("remote_created_at")] - public DateTime? RemoteCreatedAt { get; init; } + public DateTime? RemoteCreatedAt { get; set; } [JsonPropertyName("remote_was_deleted")] - public bool? RemoteWasDeleted { get; init; } + public bool? RemoteWasDeleted { get; set; } [JsonPropertyName("field_mappings")] - public Dictionary? FieldMappings { get; init; } + public Dictionary? FieldMappings { get; set; } [JsonPropertyName("remote_data")] - public IEnumerable? RemoteData { get; init; } + public IEnumerable? RemoteData { get; set; } [JsonPropertyName("remote_fields")] - public IEnumerable? RemoteFields { get; init; } + public IEnumerable? RemoteFields { get; set; } } diff --git a/src/Merge.Client/Crm/Types/AccountDetails.cs b/src/Merge.Client/Crm/Types/AccountDetails.cs index 7d67acae..88d8be14 100644 --- a/src/Merge.Client/Crm/Types/AccountDetails.cs +++ b/src/Merge.Client/Crm/Types/AccountDetails.cs @@ -1,45 +1,44 @@ using System.Text.Json.Serialization; -using Merge.Client.Crm; #nullable enable namespace Merge.Client.Crm; -public class AccountDetails +public record AccountDetails { [JsonPropertyName("id")] - public string? Id { get; init; } + public string? Id { get; set; } [JsonPropertyName("integration")] - public string? Integration { get; init; } + public string? Integration { get; set; } [JsonPropertyName("integration_slug")] - public string? IntegrationSlug { get; init; } + public string? IntegrationSlug { get; set; } [JsonPropertyName("category")] - public CategoryEnum? Category { get; init; } + public CategoryEnum? Category { get; set; } [JsonPropertyName("end_user_origin_id")] - public string? EndUserOriginId { get; init; } + public string? EndUserOriginId { get; set; } [JsonPropertyName("end_user_organization_name")] - public string? EndUserOrganizationName { get; init; } + public string? EndUserOrganizationName { get; set; } [JsonPropertyName("end_user_email_address")] - public string? EndUserEmailAddress { get; init; } + public string? EndUserEmailAddress { get; set; } [JsonPropertyName("status")] - public string? Status { get; init; } + public string? Status { get; set; } [JsonPropertyName("webhook_listener_url")] - public string? WebhookListenerUrl { get; init; } + public string? WebhookListenerUrl { get; set; } /// /// Whether a Production Linked Account's credentials match another existing Production Linked Account. This field is `null` for Test Linked Accounts, incomplete Production Linked Accounts, and ignored duplicate Production Linked Account sets. /// [JsonPropertyName("is_duplicate")] - public bool? IsDuplicate { get; init; } + public bool? IsDuplicate { get; set; } [JsonPropertyName("account_type")] - public string? AccountType { get; init; } + public string? AccountType { get; set; } } diff --git a/src/Merge.Client/Crm/Types/AccountDetailsAndActions.cs b/src/Merge.Client/Crm/Types/AccountDetailsAndActions.cs index 01ddcd78..4360f8fb 100644 --- a/src/Merge.Client/Crm/Types/AccountDetailsAndActions.cs +++ b/src/Merge.Client/Crm/Types/AccountDetailsAndActions.cs @@ -1,51 +1,50 @@ using System.Text.Json.Serialization; -using Merge.Client.Crm; #nullable enable namespace Merge.Client.Crm; -public class AccountDetailsAndActions +public record AccountDetailsAndActions { [JsonPropertyName("id")] - public string Id { get; init; } + public required string Id { get; set; } [JsonPropertyName("category")] - public CategoryEnum? Category { get; init; } + public CategoryEnum? Category { get; set; } [JsonPropertyName("status")] - public AccountDetailsAndActionsStatusEnum Status { get; init; } + public required AccountDetailsAndActionsStatusEnum Status { get; set; } [JsonPropertyName("status_detail")] - public string? StatusDetail { get; init; } + public string? StatusDetail { get; set; } [JsonPropertyName("end_user_origin_id")] - public string? EndUserOriginId { get; init; } + public string? EndUserOriginId { get; set; } [JsonPropertyName("end_user_organization_name")] - public string EndUserOrganizationName { get; init; } + public required string EndUserOrganizationName { get; set; } [JsonPropertyName("end_user_email_address")] - public string EndUserEmailAddress { get; init; } + public required string EndUserEmailAddress { get; set; } /// /// The tenant or domain the customer has provided access to. /// [JsonPropertyName("subdomain")] - public string? Subdomain { get; init; } + public string? Subdomain { get; set; } [JsonPropertyName("webhook_listener_url")] - public string WebhookListenerUrl { get; init; } + public required string WebhookListenerUrl { get; set; } /// /// Whether a Production Linked Account's credentials match another existing Production Linked Account. This field is `null` for Test Linked Accounts, incomplete Production Linked Accounts, and ignored duplicate Production Linked Account sets. /// [JsonPropertyName("is_duplicate")] - public bool? IsDuplicate { get; init; } + public bool? IsDuplicate { get; set; } [JsonPropertyName("integration")] - public AccountDetailsAndActionsIntegration? Integration { get; init; } + public AccountDetailsAndActionsIntegration? Integration { get; set; } [JsonPropertyName("account_type")] - public string AccountType { get; init; } + public required string AccountType { get; set; } } diff --git a/src/Merge.Client/Crm/Types/AccountDetailsAndActionsIntegration.cs b/src/Merge.Client/Crm/Types/AccountDetailsAndActionsIntegration.cs index b7f468d6..1aadbdea 100644 --- a/src/Merge.Client/Crm/Types/AccountDetailsAndActionsIntegration.cs +++ b/src/Merge.Client/Crm/Types/AccountDetailsAndActionsIntegration.cs @@ -1,33 +1,32 @@ using System.Text.Json.Serialization; -using Merge.Client.Crm; #nullable enable namespace Merge.Client.Crm; -public class AccountDetailsAndActionsIntegration +public record AccountDetailsAndActionsIntegration { [JsonPropertyName("name")] - public string Name { get; init; } + public required string Name { get; set; } [JsonPropertyName("categories")] - public IEnumerable Categories { get; init; } + public IEnumerable Categories { get; set; } = new List(); [JsonPropertyName("image")] - public string? Image { get; init; } + public string? Image { get; set; } [JsonPropertyName("square_image")] - public string? SquareImage { get; init; } + public string? SquareImage { get; set; } [JsonPropertyName("color")] - public string Color { get; init; } + public required string Color { get; set; } [JsonPropertyName("slug")] - public string Slug { get; init; } + public required string Slug { get; set; } [JsonPropertyName("passthrough_available")] - public bool PassthroughAvailable { get; init; } + public required bool PassthroughAvailable { get; set; } [JsonPropertyName("available_model_operations")] - public IEnumerable? AvailableModelOperations { get; init; } + public IEnumerable? AvailableModelOperations { get; set; } } diff --git a/src/Merge.Client/Crm/Types/AccountDetailsAndActionsStatusEnum.cs b/src/Merge.Client/Crm/Types/AccountDetailsAndActionsStatusEnum.cs index 78f8d1b7..9425de58 100644 --- a/src/Merge.Client/Crm/Types/AccountDetailsAndActionsStatusEnum.cs +++ b/src/Merge.Client/Crm/Types/AccountDetailsAndActionsStatusEnum.cs @@ -1,7 +1,6 @@ using System.Runtime.Serialization; using System.Text.Json.Serialization; using Merge.Client.Core; -using Merge.Client.Crm; #nullable enable diff --git a/src/Merge.Client/Crm/Types/AccountIntegration.cs b/src/Merge.Client/Crm/Types/AccountIntegration.cs index b97b316d..eca07914 100644 --- a/src/Merge.Client/Crm/Types/AccountIntegration.cs +++ b/src/Merge.Client/Crm/Types/AccountIntegration.cs @@ -1,66 +1,65 @@ using System.Text.Json.Serialization; -using Merge.Client.Crm; #nullable enable namespace Merge.Client.Crm; -public class AccountIntegration +public record AccountIntegration { /// /// Company name. /// [JsonPropertyName("name")] - public string Name { get; init; } + public required string Name { get; set; } /// /// Optional. This shortened name appears in places with limited space, usually in conjunction with the platform's logo (e.g., Merge Link menu).

Example: Workforce Now (in lieu of ADP Workforce Now), SuccessFactors (in lieu of SAP SuccessFactors) ///
[JsonPropertyName("abbreviated_name")] - public string? AbbreviatedName { get; init; } + public string? AbbreviatedName { get; set; } /// /// Category or categories this integration belongs to. Multiple categories should be comma separated, i.e. [ats, hris]. /// [JsonPropertyName("categories")] - public IEnumerable? Categories { get; init; } + public IEnumerable? Categories { get; set; } /// /// Company logo in rectangular shape. Upload an image with a clear background. /// [JsonPropertyName("image")] - public string? Image { get; init; } + public string? Image { get; set; } /// /// Company logo in square shape. Upload an image with a white background. /// [JsonPropertyName("square_image")] - public string? SquareImage { get; init; } + public string? SquareImage { get; set; } /// /// The color of this integration used for buttons and text throughout the app and landing pages. Choose a darker, saturated color. /// [JsonPropertyName("color")] - public string? Color { get; init; } + public string? Color { get; set; } [JsonPropertyName("slug")] - public string? Slug { get; init; } + public string? Slug { get; set; } /// /// Mapping of API endpoints to documentation urls for support. Example: {'GET': [['/common-model-scopes', 'https://docs.merge.dev/accounting/common-model-scopes/#common_model_scopes_retrieve'],['/common-model-actions', 'https://docs.merge.dev/accounting/common-model-actions/#common_model_actions_retrieve']], 'POST': []} /// [JsonPropertyName("api_endpoints_to_documentation_urls")] - public Dictionary? ApiEndpointsToDocumentationUrls { get; init; } + public Dictionary? ApiEndpointsToDocumentationUrls { get; set; } /// /// Setup guide URL for third party webhook creation. Exposed in Merge Docs. /// [JsonPropertyName("webhook_setup_guide_url")] - public string? WebhookSetupGuideUrl { get; init; } + public string? WebhookSetupGuideUrl { get; set; } /// /// Category or categories this integration is in beta status for. /// [JsonPropertyName("category_beta_status")] - public Dictionary? CategoryBetaStatus { get; init; } + public Dictionary? CategoryBetaStatus { get; set; } } diff --git a/src/Merge.Client/Crm/Types/AccountRequest.cs b/src/Merge.Client/Crm/Types/AccountRequest.cs index b02fe182..f7a441a2 100644 --- a/src/Merge.Client/Crm/Types/AccountRequest.cs +++ b/src/Merge.Client/Crm/Types/AccountRequest.cs @@ -1,66 +1,65 @@ using System.Text.Json.Serialization; using Merge.Client.Core; -using Merge.Client.Crm; using OneOf; #nullable enable namespace Merge.Client.Crm; -public class AccountRequest +public record AccountRequest { /// /// The account's owner. /// [JsonPropertyName("owner")] [JsonConverter(typeof(OneOfSerializer>))] - public OneOf? Owner { get; init; } + public OneOf? Owner { get; set; } /// /// The account's name. /// [JsonPropertyName("name")] - public string? Name { get; init; } + public string? Name { get; set; } /// /// The account's description. /// [JsonPropertyName("description")] - public string? Description { get; init; } + public string? Description { get; set; } /// /// The account's industry. /// [JsonPropertyName("industry")] - public string? Industry { get; init; } + public string? Industry { get; set; } /// /// The account's website. /// [JsonPropertyName("website")] - public string? Website { get; init; } + public string? Website { get; set; } /// /// The account's number of employees. /// [JsonPropertyName("number_of_employees")] - public int? NumberOfEmployees { get; init; } + public int? NumberOfEmployees { get; set; } [JsonPropertyName("addresses")] - public IEnumerable? Addresses { get; init; } + public IEnumerable? Addresses { get; set; } /// /// The last date (either most recent or furthest in the future) of when an activity occurs in an account. /// [JsonPropertyName("last_activity_at")] - public DateTime? LastActivityAt { get; init; } + public DateTime? LastActivityAt { get; set; } [JsonPropertyName("integration_params")] - public Dictionary? IntegrationParams { get; init; } + public Dictionary? IntegrationParams { get; set; } [JsonPropertyName("linked_account_params")] - public Dictionary? LinkedAccountParams { get; init; } + public Dictionary? LinkedAccountParams { get; set; } [JsonPropertyName("remote_fields")] - public IEnumerable? RemoteFields { get; init; } + public IEnumerable? RemoteFields { get; set; } } diff --git a/src/Merge.Client/Crm/Types/AccountToken.cs b/src/Merge.Client/Crm/Types/AccountToken.cs index c0ec11e5..60a322c7 100644 --- a/src/Merge.Client/Crm/Types/AccountToken.cs +++ b/src/Merge.Client/Crm/Types/AccountToken.cs @@ -1,15 +1,14 @@ using System.Text.Json.Serialization; -using Merge.Client.Crm; #nullable enable namespace Merge.Client.Crm; -public class AccountToken +public record AccountToken { [JsonPropertyName("account_token")] - public string AccountToken_ { get; init; } + public required string AccountToken_ { get; set; } [JsonPropertyName("integration")] - public AccountIntegration Integration { get; init; } + public required AccountIntegration Integration { get; set; } } diff --git a/src/Merge.Client/Crm/Types/ActivityTypeEnum.cs b/src/Merge.Client/Crm/Types/ActivityTypeEnum.cs index 23f0d2bf..2fbcd997 100644 --- a/src/Merge.Client/Crm/Types/ActivityTypeEnum.cs +++ b/src/Merge.Client/Crm/Types/ActivityTypeEnum.cs @@ -1,7 +1,6 @@ using System.Runtime.Serialization; using System.Text.Json.Serialization; using Merge.Client.Core; -using Merge.Client.Crm; #nullable enable diff --git a/src/Merge.Client/Crm/Types/Address.cs b/src/Merge.Client/Crm/Types/Address.cs index c6033a19..c3a57603 100644 --- a/src/Merge.Client/Crm/Types/Address.cs +++ b/src/Merge.Client/Crm/Types/Address.cs @@ -1,53 +1,52 @@ using System.Text.Json.Serialization; -using Merge.Client.Crm; #nullable enable namespace Merge.Client.Crm; -public class Address +public record Address { /// /// The datetime that this object was created by Merge. /// [JsonPropertyName("created_at")] - public DateTime? CreatedAt { get; init; } + public DateTime? CreatedAt { get; set; } /// /// The datetime that this object was modified by Merge. /// [JsonPropertyName("modified_at")] - public DateTime? ModifiedAt { get; init; } + public DateTime? ModifiedAt { get; set; } /// /// Line 1 of the address's street. /// [JsonPropertyName("street_1")] - public string? Street1 { get; init; } + public string? Street1 { get; set; } /// /// Line 2 of the address's street. /// [JsonPropertyName("street_2")] - public string? Street2 { get; init; } + public string? Street2 { get; set; } /// /// The address's city. /// [JsonPropertyName("city")] - public string? City { get; init; } + public string? City { get; set; } /// /// The address's state. /// [JsonPropertyName("state")] - public string? State { get; init; } + public string? State { get; set; } /// /// The address's postal code. /// [JsonPropertyName("postal_code")] - public string? PostalCode { get; init; } + public string? PostalCode { get; set; } /// /// The address's country. @@ -303,7 +302,7 @@ public class Address /// - `ZW` - Zimbabwe /// [JsonPropertyName("country")] - public CountryEnum? Country { get; init; } + public CountryEnum? Country { get; set; } /// /// The address type. @@ -312,5 +311,5 @@ public class Address /// - `SHIPPING` - SHIPPING /// [JsonPropertyName("address_type")] - public AddressTypeEnum? AddressType { get; init; } + public AddressTypeEnum? AddressType { get; set; } } diff --git a/src/Merge.Client/Crm/Types/AddressRequest.cs b/src/Merge.Client/Crm/Types/AddressRequest.cs index 8038ff4a..210e6f05 100644 --- a/src/Merge.Client/Crm/Types/AddressRequest.cs +++ b/src/Merge.Client/Crm/Types/AddressRequest.cs @@ -1,41 +1,40 @@ using System.Text.Json.Serialization; -using Merge.Client.Crm; #nullable enable namespace Merge.Client.Crm; -public class AddressRequest +public record AddressRequest { /// /// Line 1 of the address's street. /// [JsonPropertyName("street_1")] - public string? Street1 { get; init; } + public string? Street1 { get; set; } /// /// Line 2 of the address's street. /// [JsonPropertyName("street_2")] - public string? Street2 { get; init; } + public string? Street2 { get; set; } /// /// The address's city. /// [JsonPropertyName("city")] - public string? City { get; init; } + public string? City { get; set; } /// /// The address's state. /// [JsonPropertyName("state")] - public string? State { get; init; } + public string? State { get; set; } /// /// The address's postal code. /// [JsonPropertyName("postal_code")] - public string? PostalCode { get; init; } + public string? PostalCode { get; set; } /// /// The address's country. @@ -291,7 +290,7 @@ public class AddressRequest /// - `ZW` - Zimbabwe /// [JsonPropertyName("country")] - public CountryEnum? Country { get; init; } + public CountryEnum? Country { get; set; } /// /// The address type. @@ -300,11 +299,11 @@ public class AddressRequest /// - `SHIPPING` - SHIPPING /// [JsonPropertyName("address_type")] - public AddressTypeEnum? AddressType { get; init; } + public AddressTypeEnum? AddressType { get; set; } [JsonPropertyName("integration_params")] - public Dictionary? IntegrationParams { get; init; } + public Dictionary? IntegrationParams { get; set; } [JsonPropertyName("linked_account_params")] - public Dictionary? LinkedAccountParams { get; init; } + public Dictionary? LinkedAccountParams { get; set; } } diff --git a/src/Merge.Client/Crm/Types/AddressTypeEnum.cs b/src/Merge.Client/Crm/Types/AddressTypeEnum.cs index b2f5b9a0..2b8419c7 100644 --- a/src/Merge.Client/Crm/Types/AddressTypeEnum.cs +++ b/src/Merge.Client/Crm/Types/AddressTypeEnum.cs @@ -1,7 +1,6 @@ using System.Runtime.Serialization; using System.Text.Json.Serialization; using Merge.Client.Core; -using Merge.Client.Crm; #nullable enable diff --git a/src/Merge.Client/Crm/Types/AdvancedMetadata.cs b/src/Merge.Client/Crm/Types/AdvancedMetadata.cs index 035e2761..d155abd1 100644 --- a/src/Merge.Client/Crm/Types/AdvancedMetadata.cs +++ b/src/Merge.Client/Crm/Types/AdvancedMetadata.cs @@ -4,23 +4,23 @@ namespace Merge.Client.Crm; -public class AdvancedMetadata +public record AdvancedMetadata { [JsonPropertyName("id")] - public string Id { get; init; } + public required string Id { get; set; } [JsonPropertyName("display_name")] - public string? DisplayName { get; init; } + public string? DisplayName { get; set; } [JsonPropertyName("description")] - public string? Description { get; init; } + public string? Description { get; set; } [JsonPropertyName("is_required")] - public bool? IsRequired { get; init; } + public bool? IsRequired { get; set; } [JsonPropertyName("is_custom")] - public bool? IsCustom { get; init; } + public bool? IsCustom { get; set; } [JsonPropertyName("field_choices")] - public IEnumerable? FieldChoices { get; init; } + public IEnumerable? FieldChoices { get; set; } } diff --git a/src/Merge.Client/Crm/Types/Association.cs b/src/Merge.Client/Crm/Types/Association.cs index bfd924a7..d95d4448 100644 --- a/src/Merge.Client/Crm/Types/Association.cs +++ b/src/Merge.Client/Crm/Types/Association.cs @@ -1,36 +1,35 @@ using System.Text.Json.Serialization; using Merge.Client.Core; -using Merge.Client.Crm; using OneOf; #nullable enable namespace Merge.Client.Crm; -public class Association +public record Association { /// /// The datetime that this object was created by Merge. /// [JsonPropertyName("created_at")] - public DateTime? CreatedAt { get; init; } + public DateTime? CreatedAt { get; set; } /// /// The datetime that this object was modified by Merge. /// [JsonPropertyName("modified_at")] - public DateTime? ModifiedAt { get; init; } + public DateTime? ModifiedAt { get; set; } [JsonPropertyName("source_object")] - public string? SourceObject { get; init; } + public string? SourceObject { get; set; } [JsonPropertyName("target_object")] - public string? TargetObject { get; init; } + public string? TargetObject { get; set; } /// /// The association type the association belongs to. /// [JsonPropertyName("association_type")] [JsonConverter(typeof(OneOfSerializer>))] - public OneOf? AssociationType { get; init; } + public OneOf? AssociationType { get; set; } } diff --git a/src/Merge.Client/Crm/Types/AssociationSubType.cs b/src/Merge.Client/Crm/Types/AssociationSubType.cs index 6aa577a5..04fc48e4 100644 --- a/src/Merge.Client/Crm/Types/AssociationSubType.cs +++ b/src/Merge.Client/Crm/Types/AssociationSubType.cs @@ -4,23 +4,23 @@ namespace Merge.Client.Crm; -public class AssociationSubType +public record AssociationSubType { [JsonPropertyName("id")] - public string? Id { get; init; } + public string? Id { get; set; } /// /// The datetime that this object was created by Merge. /// [JsonPropertyName("created_at")] - public DateTime? CreatedAt { get; init; } + public DateTime? CreatedAt { get; set; } /// /// The datetime that this object was modified by Merge. /// [JsonPropertyName("modified_at")] - public DateTime? ModifiedAt { get; init; } + public DateTime? ModifiedAt { get; set; } [JsonPropertyName("origin_type")] - public string? OriginType { get; init; } + public string? OriginType { get; set; } } diff --git a/src/Merge.Client/Crm/Types/AssociationType.cs b/src/Merge.Client/Crm/Types/AssociationType.cs index 824333d4..04a2ce34 100644 --- a/src/Merge.Client/Crm/Types/AssociationType.cs +++ b/src/Merge.Client/Crm/Types/AssociationType.cs @@ -1,51 +1,50 @@ using System.Text.Json.Serialization; -using Merge.Client.Crm; #nullable enable namespace Merge.Client.Crm; -public class AssociationType +public record AssociationType { [JsonPropertyName("id")] - public string? Id { get; init; } + public string? Id { get; set; } /// /// The third-party API ID of the matching object. /// [JsonPropertyName("remote_id")] - public string? RemoteId { get; init; } + public string? RemoteId { get; set; } /// /// The datetime that this object was created by Merge. /// [JsonPropertyName("created_at")] - public DateTime? CreatedAt { get; init; } + public DateTime? CreatedAt { get; set; } /// /// The datetime that this object was modified by Merge. /// [JsonPropertyName("modified_at")] - public DateTime? ModifiedAt { get; init; } + public DateTime? ModifiedAt { get; set; } /// /// The class of the source object (Custom Object or Common Model) for the association type. /// [JsonPropertyName("source_object_class")] - public Dictionary? SourceObjectClass { get; init; } + public Dictionary? SourceObjectClass { get; set; } [JsonPropertyName("target_object_classes")] - public IEnumerable? TargetObjectClasses { get; init; } + public IEnumerable? TargetObjectClasses { get; set; } [JsonPropertyName("remote_key_name")] - public string? RemoteKeyName { get; init; } + public string? RemoteKeyName { get; set; } [JsonPropertyName("display_name")] - public string? DisplayName { get; init; } + public string? DisplayName { get; set; } [JsonPropertyName("cardinality")] - public CardinalityEnum? Cardinality { get; init; } + public CardinalityEnum? Cardinality { get; set; } [JsonPropertyName("is_required")] - public bool? IsRequired { get; init; } + public bool? IsRequired { get; set; } } diff --git a/src/Merge.Client/Crm/Types/AssociationTypeRequestRequest.cs b/src/Merge.Client/Crm/Types/AssociationTypeRequestRequest.cs index be337b53..1c1de489 100644 --- a/src/Merge.Client/Crm/Types/AssociationTypeRequestRequest.cs +++ b/src/Merge.Client/Crm/Types/AssociationTypeRequestRequest.cs @@ -1,27 +1,27 @@ using System.Text.Json.Serialization; -using Merge.Client.Crm; #nullable enable namespace Merge.Client.Crm; -public class AssociationTypeRequestRequest +public record AssociationTypeRequestRequest { [JsonPropertyName("source_object_class")] - public ObjectClassDescriptionRequest SourceObjectClass { get; init; } + public required ObjectClassDescriptionRequest SourceObjectClass { get; set; } [JsonPropertyName("target_object_classes")] - public IEnumerable TargetObjectClasses { get; init; } + public IEnumerable TargetObjectClasses { get; set; } = + new List(); [JsonPropertyName("remote_key_name")] - public string RemoteKeyName { get; init; } + public required string RemoteKeyName { get; set; } [JsonPropertyName("display_name")] - public string? DisplayName { get; init; } + public string? DisplayName { get; set; } [JsonPropertyName("cardinality")] - public CardinalityEnum? Cardinality { get; init; } + public CardinalityEnum? Cardinality { get; set; } [JsonPropertyName("is_required")] - public bool? IsRequired { get; init; } + public bool? IsRequired { get; set; } } diff --git a/src/Merge.Client/Crm/Types/AsyncPassthroughReciept.cs b/src/Merge.Client/Crm/Types/AsyncPassthroughReciept.cs index bbe81d2f..014c77fa 100644 --- a/src/Merge.Client/Crm/Types/AsyncPassthroughReciept.cs +++ b/src/Merge.Client/Crm/Types/AsyncPassthroughReciept.cs @@ -4,8 +4,8 @@ namespace Merge.Client.Crm; -public class AsyncPassthroughReciept +public record AsyncPassthroughReciept { [JsonPropertyName("async_passthrough_receipt_id")] - public string AsyncPassthroughReceiptId { get; init; } + public required string AsyncPassthroughReceiptId { get; set; } } diff --git a/src/Merge.Client/Crm/Types/AuditLogEvent.cs b/src/Merge.Client/Crm/Types/AuditLogEvent.cs index 9a06fccc..0030f088 100644 --- a/src/Merge.Client/Crm/Types/AuditLogEvent.cs +++ b/src/Merge.Client/Crm/Types/AuditLogEvent.cs @@ -1,26 +1,25 @@ using System.Text.Json.Serialization; -using Merge.Client.Crm; #nullable enable namespace Merge.Client.Crm; -public class AuditLogEvent +public record AuditLogEvent { [JsonPropertyName("id")] - public string? Id { get; init; } + public string? Id { get; set; } /// /// The User's full name at the time of this Event occurring. /// [JsonPropertyName("user_name")] - public string? UserName { get; init; } + public string? UserName { get; set; } /// /// The User's email at the time of this Event occurring. /// [JsonPropertyName("user_email")] - public string? UserEmail { get; init; } + public string? UserEmail { get; set; } /// /// Designates the role of the user (or SYSTEM/API if action not taken by a user) at the time of this Event occurring. @@ -33,10 +32,10 @@ public class AuditLogEvent /// - `MERGE_TEAM` - MERGE_TEAM /// [JsonPropertyName("role")] - public RoleEnum Role { get; init; } + public required RoleEnum Role { get; set; } [JsonPropertyName("ip_address")] - public string IpAddress { get; init; } + public required string IpAddress { get; set; } /// /// Designates the type of event that occurred. @@ -81,11 +80,11 @@ public class AuditLogEvent /// - `END_USER_CREDENTIALS_ACCESSED` - END_USER_CREDENTIALS_ACCESSED /// [JsonPropertyName("event_type")] - public EventTypeEnum EventType { get; init; } + public required EventTypeEnum EventType { get; set; } [JsonPropertyName("event_description")] - public string EventDescription { get; init; } + public required string EventDescription { get; set; } [JsonPropertyName("created_at")] - public DateTime? CreatedAt { get; init; } + public DateTime? CreatedAt { get; set; } } diff --git a/src/Merge.Client/Crm/Types/AvailableActions.cs b/src/Merge.Client/Crm/Types/AvailableActions.cs index 124635fd..02339150 100644 --- a/src/Merge.Client/Crm/Types/AvailableActions.cs +++ b/src/Merge.Client/Crm/Types/AvailableActions.cs @@ -1,18 +1,17 @@ using System.Text.Json.Serialization; -using Merge.Client.Crm; #nullable enable namespace Merge.Client.Crm; -public class AvailableActions +public record AvailableActions { [JsonPropertyName("integration")] - public AccountIntegration Integration { get; init; } + public required AccountIntegration Integration { get; set; } [JsonPropertyName("passthrough_available")] - public bool PassthroughAvailable { get; init; } + public required bool PassthroughAvailable { get; set; } [JsonPropertyName("available_model_operations")] - public IEnumerable? AvailableModelOperations { get; init; } + public IEnumerable? AvailableModelOperations { get; set; } } diff --git a/src/Merge.Client/Crm/Types/CardinalityEnum.cs b/src/Merge.Client/Crm/Types/CardinalityEnum.cs index 989949d5..b35778e0 100644 --- a/src/Merge.Client/Crm/Types/CardinalityEnum.cs +++ b/src/Merge.Client/Crm/Types/CardinalityEnum.cs @@ -1,7 +1,6 @@ using System.Runtime.Serialization; using System.Text.Json.Serialization; using Merge.Client.Core; -using Merge.Client.Crm; #nullable enable diff --git a/src/Merge.Client/Crm/Types/CategoriesEnum.cs b/src/Merge.Client/Crm/Types/CategoriesEnum.cs index e8aa0b70..e8f7508c 100644 --- a/src/Merge.Client/Crm/Types/CategoriesEnum.cs +++ b/src/Merge.Client/Crm/Types/CategoriesEnum.cs @@ -1,7 +1,6 @@ using System.Runtime.Serialization; using System.Text.Json.Serialization; using Merge.Client.Core; -using Merge.Client.Crm; #nullable enable diff --git a/src/Merge.Client/Crm/Types/CategoryEnum.cs b/src/Merge.Client/Crm/Types/CategoryEnum.cs index b5b5f861..ad050f11 100644 --- a/src/Merge.Client/Crm/Types/CategoryEnum.cs +++ b/src/Merge.Client/Crm/Types/CategoryEnum.cs @@ -1,7 +1,6 @@ using System.Runtime.Serialization; using System.Text.Json.Serialization; using Merge.Client.Core; -using Merge.Client.Crm; #nullable enable diff --git a/src/Merge.Client/Crm/Types/CommonModelScopeApi.cs b/src/Merge.Client/Crm/Types/CommonModelScopeApi.cs index 4c4fe8f0..5f5765c9 100644 --- a/src/Merge.Client/Crm/Types/CommonModelScopeApi.cs +++ b/src/Merge.Client/Crm/Types/CommonModelScopeApi.cs @@ -1,15 +1,15 @@ using System.Text.Json.Serialization; -using Merge.Client.Crm; #nullable enable namespace Merge.Client.Crm; -public class CommonModelScopeApi +public record CommonModelScopeApi { /// /// The common models you want to update the scopes for /// [JsonPropertyName("common_models")] - public IEnumerable CommonModels { get; init; } + public IEnumerable CommonModels { get; set; } = + new List(); } diff --git a/src/Merge.Client/Crm/Types/CommonModelScopesBodyRequest.cs b/src/Merge.Client/Crm/Types/CommonModelScopesBodyRequest.cs index 7e05b148..b07dedd0 100644 --- a/src/Merge.Client/Crm/Types/CommonModelScopesBodyRequest.cs +++ b/src/Merge.Client/Crm/Types/CommonModelScopesBodyRequest.cs @@ -1,18 +1,18 @@ using System.Text.Json.Serialization; -using Merge.Client.Crm; #nullable enable namespace Merge.Client.Crm; -public class CommonModelScopesBodyRequest +public record CommonModelScopesBodyRequest { [JsonPropertyName("model_id")] - public string ModelId { get; init; } + public required string ModelId { get; set; } [JsonPropertyName("enabled_actions")] - public IEnumerable EnabledActions { get; init; } + public IEnumerable EnabledActions { get; set; } = + new List(); [JsonPropertyName("disabled_fields")] - public IEnumerable DisabledFields { get; init; } + public IEnumerable DisabledFields { get; set; } = new List(); } diff --git a/src/Merge.Client/Crm/Types/Contact.cs b/src/Merge.Client/Crm/Types/Contact.cs index bf7c3ded..7ce7d91a 100644 --- a/src/Merge.Client/Crm/Types/Contact.cs +++ b/src/Merge.Client/Crm/Types/Contact.cs @@ -1,91 +1,90 @@ using System.Text.Json.Serialization; using Merge.Client.Core; -using Merge.Client.Crm; using OneOf; #nullable enable namespace Merge.Client.Crm; -public class Contact +public record Contact { [JsonPropertyName("id")] - public string? Id { get; init; } + public string? Id { get; set; } /// /// The third-party API ID of the matching object. /// [JsonPropertyName("remote_id")] - public string? RemoteId { get; init; } + public string? RemoteId { get; set; } /// /// The datetime that this object was created by Merge. /// [JsonPropertyName("created_at")] - public DateTime? CreatedAt { get; init; } + public DateTime? CreatedAt { get; set; } /// /// The datetime that this object was modified by Merge. /// [JsonPropertyName("modified_at")] - public DateTime? ModifiedAt { get; init; } + public DateTime? ModifiedAt { get; set; } /// /// The contact's first name. /// [JsonPropertyName("first_name")] - public string? FirstName { get; init; } + public string? FirstName { get; set; } /// /// The contact's last name. /// [JsonPropertyName("last_name")] - public string? LastName { get; init; } + public string? LastName { get; set; } /// /// The contact's account. /// [JsonPropertyName("account")] [JsonConverter(typeof(OneOfSerializer>))] - public OneOf? Account { get; init; } + public OneOf? Account { get; set; } /// /// The contact's owner. /// [JsonPropertyName("owner")] [JsonConverter(typeof(OneOfSerializer>))] - public OneOf? Owner { get; init; } + public OneOf? Owner { get; set; } [JsonPropertyName("addresses")] - public IEnumerable
? Addresses { get; init; } + public IEnumerable
? Addresses { get; set; } [JsonPropertyName("email_addresses")] - public IEnumerable? EmailAddresses { get; init; } + public IEnumerable? EmailAddresses { get; set; } [JsonPropertyName("phone_numbers")] - public IEnumerable? PhoneNumbers { get; init; } + public IEnumerable? PhoneNumbers { get; set; } /// /// When the contact's last activity occurred. /// [JsonPropertyName("last_activity_at")] - public DateTime? LastActivityAt { get; init; } + public DateTime? LastActivityAt { get; set; } /// /// When the third party's contact was created. /// [JsonPropertyName("remote_created_at")] - public DateTime? RemoteCreatedAt { get; init; } + public DateTime? RemoteCreatedAt { get; set; } [JsonPropertyName("remote_was_deleted")] - public bool? RemoteWasDeleted { get; init; } + public bool? RemoteWasDeleted { get; set; } [JsonPropertyName("field_mappings")] - public Dictionary? FieldMappings { get; init; } + public Dictionary? FieldMappings { get; set; } [JsonPropertyName("remote_data")] - public IEnumerable? RemoteData { get; init; } + public IEnumerable? RemoteData { get; set; } [JsonPropertyName("remote_fields")] - public IEnumerable? RemoteFields { get; init; } + public IEnumerable? RemoteFields { get; set; } } diff --git a/src/Merge.Client/Crm/Types/ContactRequest.cs b/src/Merge.Client/Crm/Types/ContactRequest.cs index 9e763aeb..7da085c3 100644 --- a/src/Merge.Client/Crm/Types/ContactRequest.cs +++ b/src/Merge.Client/Crm/Types/ContactRequest.cs @@ -1,61 +1,60 @@ using System.Text.Json.Serialization; using Merge.Client.Core; -using Merge.Client.Crm; using OneOf; #nullable enable namespace Merge.Client.Crm; -public class ContactRequest +public record ContactRequest { /// /// The contact's first name. /// [JsonPropertyName("first_name")] - public string? FirstName { get; init; } + public string? FirstName { get; set; } /// /// The contact's last name. /// [JsonPropertyName("last_name")] - public string? LastName { get; init; } + public string? LastName { get; set; } /// /// The contact's account. /// [JsonPropertyName("account")] [JsonConverter(typeof(OneOfSerializer>))] - public OneOf? Account { get; init; } + public OneOf? Account { get; set; } /// /// The contact's owner. /// [JsonPropertyName("owner")] [JsonConverter(typeof(OneOfSerializer>))] - public OneOf? Owner { get; init; } + public OneOf? Owner { get; set; } [JsonPropertyName("addresses")] - public IEnumerable? Addresses { get; init; } + public IEnumerable? Addresses { get; set; } [JsonPropertyName("email_addresses")] - public IEnumerable? EmailAddresses { get; init; } + public IEnumerable? EmailAddresses { get; set; } [JsonPropertyName("phone_numbers")] - public IEnumerable? PhoneNumbers { get; init; } + public IEnumerable? PhoneNumbers { get; set; } /// /// When the contact's last activity occurred. /// [JsonPropertyName("last_activity_at")] - public DateTime? LastActivityAt { get; init; } + public DateTime? LastActivityAt { get; set; } [JsonPropertyName("integration_params")] - public Dictionary? IntegrationParams { get; init; } + public Dictionary? IntegrationParams { get; set; } [JsonPropertyName("linked_account_params")] - public Dictionary? LinkedAccountParams { get; init; } + public Dictionary? LinkedAccountParams { get; set; } [JsonPropertyName("remote_fields")] - public IEnumerable? RemoteFields { get; init; } + public IEnumerable? RemoteFields { get; set; } } diff --git a/src/Merge.Client/Crm/Types/CountryEnum.cs b/src/Merge.Client/Crm/Types/CountryEnum.cs index c4023cbc..e400fd30 100644 --- a/src/Merge.Client/Crm/Types/CountryEnum.cs +++ b/src/Merge.Client/Crm/Types/CountryEnum.cs @@ -1,7 +1,6 @@ using System.Runtime.Serialization; using System.Text.Json.Serialization; using Merge.Client.Core; -using Merge.Client.Crm; #nullable enable diff --git a/src/Merge.Client/Crm/Types/CrmAccountResponse.cs b/src/Merge.Client/Crm/Types/CrmAccountResponse.cs index 576f7efb..d57b0326 100644 --- a/src/Merge.Client/Crm/Types/CrmAccountResponse.cs +++ b/src/Merge.Client/Crm/Types/CrmAccountResponse.cs @@ -1,21 +1,22 @@ using System.Text.Json.Serialization; -using Merge.Client.Crm; #nullable enable namespace Merge.Client.Crm; -public class CrmAccountResponse +public record CrmAccountResponse { [JsonPropertyName("model")] - public Account Model { get; init; } + public required Account Model { get; set; } [JsonPropertyName("warnings")] - public IEnumerable Warnings { get; init; } + public IEnumerable Warnings { get; set; } = + new List(); [JsonPropertyName("errors")] - public IEnumerable Errors { get; init; } + public IEnumerable Errors { get; set; } = + new List(); [JsonPropertyName("logs")] - public IEnumerable? Logs { get; init; } + public IEnumerable? Logs { get; set; } } diff --git a/src/Merge.Client/Crm/Types/CrmAssociationTypeResponse.cs b/src/Merge.Client/Crm/Types/CrmAssociationTypeResponse.cs index 18537d40..40e0e0dc 100644 --- a/src/Merge.Client/Crm/Types/CrmAssociationTypeResponse.cs +++ b/src/Merge.Client/Crm/Types/CrmAssociationTypeResponse.cs @@ -1,21 +1,22 @@ using System.Text.Json.Serialization; -using Merge.Client.Crm; #nullable enable namespace Merge.Client.Crm; -public class CrmAssociationTypeResponse +public record CrmAssociationTypeResponse { [JsonPropertyName("model")] - public AssociationType Model { get; init; } + public required AssociationType Model { get; set; } [JsonPropertyName("warnings")] - public IEnumerable Warnings { get; init; } + public IEnumerable Warnings { get; set; } = + new List(); [JsonPropertyName("errors")] - public IEnumerable Errors { get; init; } + public IEnumerable Errors { get; set; } = + new List(); [JsonPropertyName("logs")] - public IEnumerable? Logs { get; init; } + public IEnumerable? Logs { get; set; } } diff --git a/src/Merge.Client/Crm/Types/CrmContactResponse.cs b/src/Merge.Client/Crm/Types/CrmContactResponse.cs index 4c61af17..0c4647fe 100644 --- a/src/Merge.Client/Crm/Types/CrmContactResponse.cs +++ b/src/Merge.Client/Crm/Types/CrmContactResponse.cs @@ -1,21 +1,22 @@ using System.Text.Json.Serialization; -using Merge.Client.Crm; #nullable enable namespace Merge.Client.Crm; -public class CrmContactResponse +public record CrmContactResponse { [JsonPropertyName("model")] - public Contact Model { get; init; } + public required Contact Model { get; set; } [JsonPropertyName("warnings")] - public IEnumerable Warnings { get; init; } + public IEnumerable Warnings { get; set; } = + new List(); [JsonPropertyName("errors")] - public IEnumerable Errors { get; init; } + public IEnumerable Errors { get; set; } = + new List(); [JsonPropertyName("logs")] - public IEnumerable? Logs { get; init; } + public IEnumerable? Logs { get; set; } } diff --git a/src/Merge.Client/Crm/Types/CrmCustomObjectResponse.cs b/src/Merge.Client/Crm/Types/CrmCustomObjectResponse.cs index 51619d98..779d162d 100644 --- a/src/Merge.Client/Crm/Types/CrmCustomObjectResponse.cs +++ b/src/Merge.Client/Crm/Types/CrmCustomObjectResponse.cs @@ -1,21 +1,22 @@ using System.Text.Json.Serialization; -using Merge.Client.Crm; #nullable enable namespace Merge.Client.Crm; -public class CrmCustomObjectResponse +public record CrmCustomObjectResponse { [JsonPropertyName("model")] - public CustomObject Model { get; init; } + public required CustomObject Model { get; set; } [JsonPropertyName("warnings")] - public IEnumerable Warnings { get; init; } + public IEnumerable Warnings { get; set; } = + new List(); [JsonPropertyName("errors")] - public IEnumerable Errors { get; init; } + public IEnumerable Errors { get; set; } = + new List(); [JsonPropertyName("logs")] - public IEnumerable? Logs { get; init; } + public IEnumerable? Logs { get; set; } } diff --git a/src/Merge.Client/Crm/Types/CustomObject.cs b/src/Merge.Client/Crm/Types/CustomObject.cs index ed7456f9..d1575c43 100644 --- a/src/Merge.Client/Crm/Types/CustomObject.cs +++ b/src/Merge.Client/Crm/Types/CustomObject.cs @@ -1,45 +1,44 @@ using System.Text.Json.Serialization; -using Merge.Client.Crm; #nullable enable namespace Merge.Client.Crm; -public class CustomObject +public record CustomObject { [JsonPropertyName("id")] - public string? Id { get; init; } + public string? Id { get; set; } /// /// The third-party API ID of the matching object. /// [JsonPropertyName("remote_id")] - public string? RemoteId { get; init; } + public string? RemoteId { get; set; } /// /// The datetime that this object was created by Merge. /// [JsonPropertyName("created_at")] - public DateTime? CreatedAt { get; init; } + public DateTime? CreatedAt { get; set; } /// /// The datetime that this object was modified by Merge. /// [JsonPropertyName("modified_at")] - public DateTime? ModifiedAt { get; init; } + public DateTime? ModifiedAt { get; set; } /// /// The custom object class the custom object record belongs to. /// [JsonPropertyName("object_class")] - public string? ObjectClass { get; init; } + public string? ObjectClass { get; set; } /// /// The fields and values contained within the custom object record. /// [JsonPropertyName("fields")] - public Dictionary? Fields { get; init; } + public Dictionary? Fields { get; set; } [JsonPropertyName("remote_fields")] - public IEnumerable? RemoteFields { get; init; } + public IEnumerable? RemoteFields { get; set; } } diff --git a/src/Merge.Client/Crm/Types/CustomObjectClass.cs b/src/Merge.Client/Crm/Types/CustomObjectClass.cs index aaefab48..8ac5ba5b 100644 --- a/src/Merge.Client/Crm/Types/CustomObjectClass.cs +++ b/src/Merge.Client/Crm/Types/CustomObjectClass.cs @@ -1,51 +1,50 @@ using System.Text.Json.Serialization; -using Merge.Client.Crm; #nullable enable namespace Merge.Client.Crm; -public class CustomObjectClass +public record CustomObjectClass { [JsonPropertyName("id")] - public string? Id { get; init; } + public string? Id { get; set; } /// /// The third-party API ID of the matching object. /// [JsonPropertyName("remote_id")] - public string? RemoteId { get; init; } + public string? RemoteId { get; set; } [JsonPropertyName("created_at")] - public DateTime? CreatedAt { get; init; } + public DateTime? CreatedAt { get; set; } [JsonPropertyName("modified_at")] - public DateTime? ModifiedAt { get; init; } + public DateTime? ModifiedAt { get; set; } /// /// The custom object class's name. /// [JsonPropertyName("name")] - public string? Name { get; init; } + public string? Name { get; set; } /// /// The custom object class's description. /// [JsonPropertyName("description")] - public string? Description { get; init; } + public string? Description { get; set; } /// /// The custom object class's singular and plural labels. /// [JsonPropertyName("labels")] - public Dictionary? Labels { get; init; } + public Dictionary? Labels { get; set; } [JsonPropertyName("fields")] - public IEnumerable? Fields { get; init; } + public IEnumerable? Fields { get; set; } /// /// The types of associations with other models that the custom object class can have. /// [JsonPropertyName("association_types")] - public IEnumerable>? AssociationTypes { get; init; } + public IEnumerable>? AssociationTypes { get; set; } } diff --git a/src/Merge.Client/Crm/Types/CustomObjectRequest.cs b/src/Merge.Client/Crm/Types/CustomObjectRequest.cs index c4fa771d..6e70381c 100644 --- a/src/Merge.Client/Crm/Types/CustomObjectRequest.cs +++ b/src/Merge.Client/Crm/Types/CustomObjectRequest.cs @@ -4,8 +4,8 @@ namespace Merge.Client.Crm; -public class CustomObjectRequest +public record CustomObjectRequest { [JsonPropertyName("fields")] - public Dictionary Fields { get; init; } + public Dictionary Fields { get; set; } = new Dictionary(); } diff --git a/src/Merge.Client/Crm/Types/DataPassthroughRequest.cs b/src/Merge.Client/Crm/Types/DataPassthroughRequest.cs index 5a337575..9e660d0a 100644 --- a/src/Merge.Client/Crm/Types/DataPassthroughRequest.cs +++ b/src/Merge.Client/Crm/Types/DataPassthroughRequest.cs @@ -1,51 +1,50 @@ using System.Text.Json.Serialization; -using Merge.Client.Crm; #nullable enable namespace Merge.Client.Crm; -public class DataPassthroughRequest +public record DataPassthroughRequest { [JsonPropertyName("method")] - public MethodEnum Method { get; init; } + public required MethodEnum Method { get; set; } /// /// The path of the request in the third party's platform. /// [JsonPropertyName("path")] - public string Path { get; init; } + public required string Path { get; set; } /// /// An optional override of the third party's base url for the request. /// [JsonPropertyName("base_url_override")] - public string? BaseUrlOverride { get; init; } + public string? BaseUrlOverride { get; set; } /// /// The data with the request. You must include a `request_format` parameter matching the data's format /// [JsonPropertyName("data")] - public string? Data { get; init; } + public string? Data { get; set; } /// /// Pass an array of `MultipartFormField` objects in here instead of using the `data` param if `request_format` is set to `MULTIPART`. /// [JsonPropertyName("multipart_form_data")] - public IEnumerable? MultipartFormData { get; init; } + public IEnumerable? MultipartFormData { get; set; } /// /// The headers to use for the request (Merge will handle the account's authorization headers). `Content-Type` header is required for passthrough. Choose content type corresponding to expected format of receiving server. /// [JsonPropertyName("headers")] - public Dictionary? Headers { get; init; } + public Dictionary? Headers { get; set; } [JsonPropertyName("request_format")] - public RequestFormatEnum? RequestFormat { get; init; } + public RequestFormatEnum? RequestFormat { get; set; } /// /// Optional. If true, the response will always be an object of the form `{"type": T, "value": ...}` where `T` will be one of `string, boolean, number, null, array, object`. /// [JsonPropertyName("normalize_response")] - public bool? NormalizeResponse { get; init; } + public bool? NormalizeResponse { get; set; } } diff --git a/src/Merge.Client/Crm/Types/DebugModeLog.cs b/src/Merge.Client/Crm/Types/DebugModeLog.cs index 12f540ea..10eec682 100644 --- a/src/Merge.Client/Crm/Types/DebugModeLog.cs +++ b/src/Merge.Client/Crm/Types/DebugModeLog.cs @@ -1,18 +1,17 @@ using System.Text.Json.Serialization; -using Merge.Client.Crm; #nullable enable namespace Merge.Client.Crm; -public class DebugModeLog +public record DebugModeLog { [JsonPropertyName("log_id")] - public string LogId { get; init; } + public required string LogId { get; set; } [JsonPropertyName("dashboard_view")] - public string DashboardView { get; init; } + public required string DashboardView { get; set; } [JsonPropertyName("log_summary")] - public DebugModelLogSummary LogSummary { get; init; } + public required DebugModelLogSummary LogSummary { get; set; } } diff --git a/src/Merge.Client/Crm/Types/DebugModelLogSummary.cs b/src/Merge.Client/Crm/Types/DebugModelLogSummary.cs index d7013077..7f59e976 100644 --- a/src/Merge.Client/Crm/Types/DebugModelLogSummary.cs +++ b/src/Merge.Client/Crm/Types/DebugModelLogSummary.cs @@ -4,14 +4,14 @@ namespace Merge.Client.Crm; -public class DebugModelLogSummary +public record DebugModelLogSummary { [JsonPropertyName("url")] - public string Url { get; init; } + public required string Url { get; set; } [JsonPropertyName("method")] - public string Method { get; init; } + public required string Method { get; set; } [JsonPropertyName("status_code")] - public int StatusCode { get; init; } + public required int StatusCode { get; set; } } diff --git a/src/Merge.Client/Crm/Types/DirectionEnum.cs b/src/Merge.Client/Crm/Types/DirectionEnum.cs index aca9cfd5..4fcf393d 100644 --- a/src/Merge.Client/Crm/Types/DirectionEnum.cs +++ b/src/Merge.Client/Crm/Types/DirectionEnum.cs @@ -1,7 +1,6 @@ using System.Runtime.Serialization; using System.Text.Json.Serialization; using Merge.Client.Core; -using Merge.Client.Crm; #nullable enable diff --git a/src/Merge.Client/Crm/Types/EmailAddress.cs b/src/Merge.Client/Crm/Types/EmailAddress.cs index c4ace241..0f2b5208 100644 --- a/src/Merge.Client/Crm/Types/EmailAddress.cs +++ b/src/Merge.Client/Crm/Types/EmailAddress.cs @@ -4,29 +4,29 @@ namespace Merge.Client.Crm; -public class EmailAddress +public record EmailAddress { /// /// The datetime that this object was created by Merge. /// [JsonPropertyName("created_at")] - public DateTime? CreatedAt { get; init; } + public DateTime? CreatedAt { get; set; } /// /// The datetime that this object was modified by Merge. /// [JsonPropertyName("modified_at")] - public DateTime? ModifiedAt { get; init; } + public DateTime? ModifiedAt { get; set; } /// /// The email address. /// [JsonPropertyName("email_address")] - public string? EmailAddress_ { get; init; } + public string? EmailAddress_ { get; set; } /// /// The email address's type. /// [JsonPropertyName("email_address_type")] - public string? EmailAddressType { get; init; } + public string? EmailAddressType { get; set; } } diff --git a/src/Merge.Client/Crm/Types/EmailAddressRequest.cs b/src/Merge.Client/Crm/Types/EmailAddressRequest.cs index c240823c..ee690f6b 100644 --- a/src/Merge.Client/Crm/Types/EmailAddressRequest.cs +++ b/src/Merge.Client/Crm/Types/EmailAddressRequest.cs @@ -4,23 +4,23 @@ namespace Merge.Client.Crm; -public class EmailAddressRequest +public record EmailAddressRequest { /// /// The email address. /// [JsonPropertyName("email_address")] - public string? EmailAddress { get; init; } + public string? EmailAddress { get; set; } /// /// The email address's type. /// [JsonPropertyName("email_address_type")] - public string? EmailAddressType { get; init; } + public string? EmailAddressType { get; set; } [JsonPropertyName("integration_params")] - public Dictionary? IntegrationParams { get; init; } + public Dictionary? IntegrationParams { get; set; } [JsonPropertyName("linked_account_params")] - public Dictionary? LinkedAccountParams { get; init; } + public Dictionary? LinkedAccountParams { get; set; } } diff --git a/src/Merge.Client/Crm/Types/EnabledActionsEnum.cs b/src/Merge.Client/Crm/Types/EnabledActionsEnum.cs index 0ee49464..d0d32a98 100644 --- a/src/Merge.Client/Crm/Types/EnabledActionsEnum.cs +++ b/src/Merge.Client/Crm/Types/EnabledActionsEnum.cs @@ -1,7 +1,6 @@ using System.Runtime.Serialization; using System.Text.Json.Serialization; using Merge.Client.Core; -using Merge.Client.Crm; #nullable enable diff --git a/src/Merge.Client/Crm/Types/EncodingEnum.cs b/src/Merge.Client/Crm/Types/EncodingEnum.cs index a8aed312..9b1922fa 100644 --- a/src/Merge.Client/Crm/Types/EncodingEnum.cs +++ b/src/Merge.Client/Crm/Types/EncodingEnum.cs @@ -1,7 +1,6 @@ using System.Runtime.Serialization; using System.Text.Json.Serialization; using Merge.Client.Core; -using Merge.Client.Crm; #nullable enable diff --git a/src/Merge.Client/Crm/Types/Engagement.cs b/src/Merge.Client/Crm/Types/Engagement.cs index e409ece0..1917144b 100644 --- a/src/Merge.Client/Crm/Types/Engagement.cs +++ b/src/Merge.Client/Crm/Types/Engagement.cs @@ -1,53 +1,52 @@ using System.Text.Json.Serialization; using Merge.Client.Core; -using Merge.Client.Crm; using OneOf; #nullable enable namespace Merge.Client.Crm; -public class Engagement +public record Engagement { [JsonPropertyName("id")] - public string? Id { get; init; } + public string? Id { get; set; } /// /// The third-party API ID of the matching object. /// [JsonPropertyName("remote_id")] - public string? RemoteId { get; init; } + public string? RemoteId { get; set; } /// /// The datetime that this object was created by Merge. /// [JsonPropertyName("created_at")] - public DateTime? CreatedAt { get; init; } + public DateTime? CreatedAt { get; set; } /// /// The datetime that this object was modified by Merge. /// [JsonPropertyName("modified_at")] - public DateTime? ModifiedAt { get; init; } + public DateTime? ModifiedAt { get; set; } /// /// The engagement's owner. /// [JsonPropertyName("owner")] [JsonConverter(typeof(OneOfSerializer>))] - public OneOf? Owner { get; init; } + public OneOf? Owner { get; set; } /// /// The engagement's content. /// [JsonPropertyName("content")] - public string? Content { get; init; } + public string? Content { get; set; } /// /// The engagement's subject. /// [JsonPropertyName("subject")] - public string? Subject { get; init; } + public string? Subject { get; set; } /// /// The engagement's direction. @@ -56,33 +55,33 @@ public class Engagement /// - `OUTBOUND` - OUTBOUND /// [JsonPropertyName("direction")] - public DirectionEnum? Direction { get; init; } + public DirectionEnum? Direction { get; set; } /// /// The engagement type of the engagement. /// [JsonPropertyName("engagement_type")] [JsonConverter(typeof(OneOfSerializer>))] - public OneOf? EngagementType { get; init; } + public OneOf? EngagementType { get; set; } /// /// The time at which the engagement started. /// [JsonPropertyName("start_time")] - public DateTime? StartTime { get; init; } + public DateTime? StartTime { get; set; } /// /// The time at which the engagement ended. /// [JsonPropertyName("end_time")] - public DateTime? EndTime { get; init; } + public DateTime? EndTime { get; set; } /// /// The account of the engagement. /// [JsonPropertyName("account")] [JsonConverter(typeof(OneOfSerializer>))] - public OneOf? Account { get; init; } + public OneOf? Account { get; set; } [JsonPropertyName("contacts")] [JsonConverter( @@ -91,20 +90,20 @@ public class Engagement OneOfSerializer> >) )] - public IEnumerable>? Contacts { get; init; } + public IEnumerable>? Contacts { get; set; } /// /// Indicates whether or not this object has been deleted in the third party platform. /// [JsonPropertyName("remote_was_deleted")] - public bool? RemoteWasDeleted { get; init; } + public bool? RemoteWasDeleted { get; set; } [JsonPropertyName("field_mappings")] - public Dictionary? FieldMappings { get; init; } + public Dictionary? FieldMappings { get; set; } [JsonPropertyName("remote_data")] - public IEnumerable? RemoteData { get; init; } + public IEnumerable? RemoteData { get; set; } [JsonPropertyName("remote_fields")] - public IEnumerable? RemoteFields { get; init; } + public IEnumerable? RemoteFields { get; set; } } diff --git a/src/Merge.Client/Crm/Types/EngagementRequest.cs b/src/Merge.Client/Crm/Types/EngagementRequest.cs index ad075b0d..cb0e62b8 100644 --- a/src/Merge.Client/Crm/Types/EngagementRequest.cs +++ b/src/Merge.Client/Crm/Types/EngagementRequest.cs @@ -1,32 +1,31 @@ using System.Text.Json.Serialization; using Merge.Client.Core; -using Merge.Client.Crm; using OneOf; #nullable enable namespace Merge.Client.Crm; -public class EngagementRequest +public record EngagementRequest { /// /// The engagement's owner. /// [JsonPropertyName("owner")] [JsonConverter(typeof(OneOfSerializer>))] - public OneOf? Owner { get; init; } + public OneOf? Owner { get; set; } /// /// The engagement's content. /// [JsonPropertyName("content")] - public string? Content { get; init; } + public string? Content { get; set; } /// /// The engagement's subject. /// [JsonPropertyName("subject")] - public string? Subject { get; init; } + public string? Subject { get; set; } /// /// The engagement's direction. @@ -35,33 +34,33 @@ public class EngagementRequest /// - `OUTBOUND` - OUTBOUND /// [JsonPropertyName("direction")] - public DirectionEnum? Direction { get; init; } + public DirectionEnum? Direction { get; set; } /// /// The engagement type of the engagement. /// [JsonPropertyName("engagement_type")] [JsonConverter(typeof(OneOfSerializer>))] - public OneOf? EngagementType { get; init; } + public OneOf? EngagementType { get; set; } /// /// The time at which the engagement started. /// [JsonPropertyName("start_time")] - public DateTime? StartTime { get; init; } + public DateTime? StartTime { get; set; } /// /// The time at which the engagement ended. /// [JsonPropertyName("end_time")] - public DateTime? EndTime { get; init; } + public DateTime? EndTime { get; set; } /// /// The account of the engagement. /// [JsonPropertyName("account")] [JsonConverter(typeof(OneOfSerializer>))] - public OneOf? Account { get; init; } + public OneOf? Account { get; set; } [JsonPropertyName("contacts")] [JsonConverter( @@ -70,14 +69,14 @@ public class EngagementRequest OneOfSerializer> >) )] - public IEnumerable>? Contacts { get; init; } + public IEnumerable>? Contacts { get; set; } [JsonPropertyName("integration_params")] - public Dictionary? IntegrationParams { get; init; } + public Dictionary? IntegrationParams { get; set; } [JsonPropertyName("linked_account_params")] - public Dictionary? LinkedAccountParams { get; init; } + public Dictionary? LinkedAccountParams { get; set; } [JsonPropertyName("remote_fields")] - public IEnumerable? RemoteFields { get; init; } + public IEnumerable? RemoteFields { get; set; } } diff --git a/src/Merge.Client/Crm/Types/EngagementResponse.cs b/src/Merge.Client/Crm/Types/EngagementResponse.cs index 76c2fa47..682d03f3 100644 --- a/src/Merge.Client/Crm/Types/EngagementResponse.cs +++ b/src/Merge.Client/Crm/Types/EngagementResponse.cs @@ -1,21 +1,22 @@ using System.Text.Json.Serialization; -using Merge.Client.Crm; #nullable enable namespace Merge.Client.Crm; -public class EngagementResponse +public record EngagementResponse { [JsonPropertyName("model")] - public Engagement Model { get; init; } + public required Engagement Model { get; set; } [JsonPropertyName("warnings")] - public IEnumerable Warnings { get; init; } + public IEnumerable Warnings { get; set; } = + new List(); [JsonPropertyName("errors")] - public IEnumerable Errors { get; init; } + public IEnumerable Errors { get; set; } = + new List(); [JsonPropertyName("logs")] - public IEnumerable? Logs { get; init; } + public IEnumerable? Logs { get; set; } } diff --git a/src/Merge.Client/Crm/Types/EngagementType.cs b/src/Merge.Client/Crm/Types/EngagementType.cs index 436f83c1..6b8b5bee 100644 --- a/src/Merge.Client/Crm/Types/EngagementType.cs +++ b/src/Merge.Client/Crm/Types/EngagementType.cs @@ -1,32 +1,31 @@ using System.Text.Json.Serialization; -using Merge.Client.Crm; #nullable enable namespace Merge.Client.Crm; -public class EngagementType +public record EngagementType { [JsonPropertyName("id")] - public string? Id { get; init; } + public string? Id { get; set; } /// /// The third-party API ID of the matching object. /// [JsonPropertyName("remote_id")] - public string? RemoteId { get; init; } + public string? RemoteId { get; set; } /// /// The datetime that this object was created by Merge. /// [JsonPropertyName("created_at")] - public DateTime? CreatedAt { get; init; } + public DateTime? CreatedAt { get; set; } /// /// The datetime that this object was modified by Merge. /// [JsonPropertyName("modified_at")] - public DateTime? ModifiedAt { get; init; } + public DateTime? ModifiedAt { get; set; } /// /// The engagement type's activity type. @@ -36,14 +35,14 @@ public class EngagementType /// - `EMAIL` - EMAIL /// [JsonPropertyName("activity_type")] - public ActivityTypeEnum? ActivityType { get; init; } + public ActivityTypeEnum? ActivityType { get; set; } /// /// The engagement type's name. /// [JsonPropertyName("name")] - public string? Name { get; init; } + public string? Name { get; set; } [JsonPropertyName("remote_fields")] - public IEnumerable? RemoteFields { get; init; } + public IEnumerable? RemoteFields { get; set; } } diff --git a/src/Merge.Client/Crm/Types/ErrorValidationProblem.cs b/src/Merge.Client/Crm/Types/ErrorValidationProblem.cs index 30dd0766..a4d42d5e 100644 --- a/src/Merge.Client/Crm/Types/ErrorValidationProblem.cs +++ b/src/Merge.Client/Crm/Types/ErrorValidationProblem.cs @@ -1,21 +1,20 @@ using System.Text.Json.Serialization; -using Merge.Client.Crm; #nullable enable namespace Merge.Client.Crm; -public class ErrorValidationProblem +public record ErrorValidationProblem { [JsonPropertyName("source")] - public ValidationProblemSource? Source { get; init; } + public ValidationProblemSource? Source { get; set; } [JsonPropertyName("title")] - public string Title { get; init; } + public required string Title { get; set; } [JsonPropertyName("detail")] - public string Detail { get; init; } + public required string Detail { get; set; } [JsonPropertyName("problem_type")] - public string ProblemType { get; init; } + public required string ProblemType { get; set; } } diff --git a/src/Merge.Client/Crm/Types/EventTypeEnum.cs b/src/Merge.Client/Crm/Types/EventTypeEnum.cs index 3ea2cc56..26085a7f 100644 --- a/src/Merge.Client/Crm/Types/EventTypeEnum.cs +++ b/src/Merge.Client/Crm/Types/EventTypeEnum.cs @@ -1,7 +1,6 @@ using System.Runtime.Serialization; using System.Text.Json.Serialization; using Merge.Client.Core; -using Merge.Client.Crm; #nullable enable diff --git a/src/Merge.Client/Crm/Types/ExternalTargetFieldApi.cs b/src/Merge.Client/Crm/Types/ExternalTargetFieldApi.cs index 695774bc..3375665d 100644 --- a/src/Merge.Client/Crm/Types/ExternalTargetFieldApi.cs +++ b/src/Merge.Client/Crm/Types/ExternalTargetFieldApi.cs @@ -4,14 +4,14 @@ namespace Merge.Client.Crm; -public class ExternalTargetFieldApi +public record ExternalTargetFieldApi { [JsonPropertyName("name")] - public string? Name { get; init; } + public string? Name { get; set; } [JsonPropertyName("description")] - public string? Description { get; init; } + public string? Description { get; set; } [JsonPropertyName("is_mapped")] - public string? IsMapped { get; init; } + public string? IsMapped { get; set; } } diff --git a/src/Merge.Client/Crm/Types/ExternalTargetFieldApiResponse.cs b/src/Merge.Client/Crm/Types/ExternalTargetFieldApiResponse.cs index b8dcc69b..02bcb468 100644 --- a/src/Merge.Client/Crm/Types/ExternalTargetFieldApiResponse.cs +++ b/src/Merge.Client/Crm/Types/ExternalTargetFieldApiResponse.cs @@ -1,36 +1,35 @@ using System.Text.Json.Serialization; -using Merge.Client.Crm; #nullable enable namespace Merge.Client.Crm; -public class ExternalTargetFieldApiResponse +public record ExternalTargetFieldApiResponse { [JsonPropertyName("Account")] - public IEnumerable? Account { get; init; } + public IEnumerable? Account { get; set; } [JsonPropertyName("Contact")] - public IEnumerable? Contact { get; init; } + public IEnumerable? Contact { get; set; } [JsonPropertyName("Lead")] - public IEnumerable? Lead { get; init; } + public IEnumerable? Lead { get; set; } [JsonPropertyName("Note")] - public IEnumerable? Note { get; init; } + public IEnumerable? Note { get; set; } [JsonPropertyName("Opportunity")] - public IEnumerable? Opportunity { get; init; } + public IEnumerable? Opportunity { get; set; } [JsonPropertyName("Stage")] - public IEnumerable? Stage { get; init; } + public IEnumerable? Stage { get; set; } [JsonPropertyName("User")] - public IEnumerable? User { get; init; } + public IEnumerable? User { get; set; } [JsonPropertyName("Task")] - public IEnumerable? Task { get; init; } + public IEnumerable? Task { get; set; } [JsonPropertyName("Engagement")] - public IEnumerable? Engagement { get; init; } + public IEnumerable? Engagement { get; set; } } diff --git a/src/Merge.Client/Crm/Types/FieldFormatEnum.cs b/src/Merge.Client/Crm/Types/FieldFormatEnum.cs index 33f1cfa8..def27214 100644 --- a/src/Merge.Client/Crm/Types/FieldFormatEnum.cs +++ b/src/Merge.Client/Crm/Types/FieldFormatEnum.cs @@ -1,7 +1,6 @@ using System.Runtime.Serialization; using System.Text.Json.Serialization; using Merge.Client.Core; -using Merge.Client.Crm; #nullable enable diff --git a/src/Merge.Client/Crm/Types/FieldMappingApiInstance.cs b/src/Merge.Client/Crm/Types/FieldMappingApiInstance.cs index ce1ea41b..29f15409 100644 --- a/src/Merge.Client/Crm/Types/FieldMappingApiInstance.cs +++ b/src/Merge.Client/Crm/Types/FieldMappingApiInstance.cs @@ -1,21 +1,20 @@ using System.Text.Json.Serialization; -using Merge.Client.Crm; #nullable enable namespace Merge.Client.Crm; -public class FieldMappingApiInstance +public record FieldMappingApiInstance { [JsonPropertyName("id")] - public string? Id { get; init; } + public string? Id { get; set; } [JsonPropertyName("is_integration_wide")] - public bool? IsIntegrationWide { get; init; } + public bool? IsIntegrationWide { get; set; } [JsonPropertyName("target_field")] - public FieldMappingApiInstanceTargetField? TargetField { get; init; } + public FieldMappingApiInstanceTargetField? TargetField { get; set; } [JsonPropertyName("remote_field")] - public FieldMappingApiInstanceRemoteField? RemoteField { get; init; } + public FieldMappingApiInstanceRemoteField? RemoteField { get; set; } } diff --git a/src/Merge.Client/Crm/Types/FieldMappingApiInstanceRemoteField.cs b/src/Merge.Client/Crm/Types/FieldMappingApiInstanceRemoteField.cs index 6c893605..3c410484 100644 --- a/src/Merge.Client/Crm/Types/FieldMappingApiInstanceRemoteField.cs +++ b/src/Merge.Client/Crm/Types/FieldMappingApiInstanceRemoteField.cs @@ -1,18 +1,17 @@ using System.Text.Json.Serialization; -using Merge.Client.Crm; #nullable enable namespace Merge.Client.Crm; -public class FieldMappingApiInstanceRemoteField +public record FieldMappingApiInstanceRemoteField { [JsonPropertyName("remote_key_name")] - public string RemoteKeyName { get; init; } + public required string RemoteKeyName { get; set; } [JsonPropertyName("schema")] - public Dictionary Schema { get; init; } + public Dictionary Schema { get; set; } = new Dictionary(); [JsonPropertyName("remote_endpoint_info")] - public FieldMappingApiInstanceRemoteFieldRemoteEndpointInfo RemoteEndpointInfo { get; init; } + public required FieldMappingApiInstanceRemoteFieldRemoteEndpointInfo RemoteEndpointInfo { get; set; } } diff --git a/src/Merge.Client/Crm/Types/FieldMappingApiInstanceRemoteFieldRemoteEndpointInfo.cs b/src/Merge.Client/Crm/Types/FieldMappingApiInstanceRemoteFieldRemoteEndpointInfo.cs index 77c75b35..2162877b 100644 --- a/src/Merge.Client/Crm/Types/FieldMappingApiInstanceRemoteFieldRemoteEndpointInfo.cs +++ b/src/Merge.Client/Crm/Types/FieldMappingApiInstanceRemoteFieldRemoteEndpointInfo.cs @@ -4,14 +4,14 @@ namespace Merge.Client.Crm; -public class FieldMappingApiInstanceRemoteFieldRemoteEndpointInfo +public record FieldMappingApiInstanceRemoteFieldRemoteEndpointInfo { [JsonPropertyName("method")] - public string? Method { get; init; } + public string? Method { get; set; } [JsonPropertyName("url_path")] - public string? UrlPath { get; init; } + public string? UrlPath { get; set; } [JsonPropertyName("field_traversal_path")] - public IEnumerable? FieldTraversalPath { get; init; } + public IEnumerable? FieldTraversalPath { get; set; } } diff --git a/src/Merge.Client/Crm/Types/FieldMappingApiInstanceResponse.cs b/src/Merge.Client/Crm/Types/FieldMappingApiInstanceResponse.cs index e580002b..775dd703 100644 --- a/src/Merge.Client/Crm/Types/FieldMappingApiInstanceResponse.cs +++ b/src/Merge.Client/Crm/Types/FieldMappingApiInstanceResponse.cs @@ -1,36 +1,35 @@ using System.Text.Json.Serialization; -using Merge.Client.Crm; #nullable enable namespace Merge.Client.Crm; -public class FieldMappingApiInstanceResponse +public record FieldMappingApiInstanceResponse { [JsonPropertyName("Account")] - public IEnumerable? Account { get; init; } + public IEnumerable? Account { get; set; } [JsonPropertyName("Contact")] - public IEnumerable? Contact { get; init; } + public IEnumerable? Contact { get; set; } [JsonPropertyName("Lead")] - public IEnumerable? Lead { get; init; } + public IEnumerable? Lead { get; set; } [JsonPropertyName("Note")] - public IEnumerable? Note { get; init; } + public IEnumerable? Note { get; set; } [JsonPropertyName("Opportunity")] - public IEnumerable? Opportunity { get; init; } + public IEnumerable? Opportunity { get; set; } [JsonPropertyName("Stage")] - public IEnumerable? Stage { get; init; } + public IEnumerable? Stage { get; set; } [JsonPropertyName("User")] - public IEnumerable? User { get; init; } + public IEnumerable? User { get; set; } [JsonPropertyName("Task")] - public IEnumerable? Task { get; init; } + public IEnumerable? Task { get; set; } [JsonPropertyName("Engagement")] - public IEnumerable? Engagement { get; init; } + public IEnumerable? Engagement { get; set; } } diff --git a/src/Merge.Client/Crm/Types/FieldMappingApiInstanceTargetField.cs b/src/Merge.Client/Crm/Types/FieldMappingApiInstanceTargetField.cs index 9bc00ff9..36d9f4e6 100644 --- a/src/Merge.Client/Crm/Types/FieldMappingApiInstanceTargetField.cs +++ b/src/Merge.Client/Crm/Types/FieldMappingApiInstanceTargetField.cs @@ -4,14 +4,14 @@ namespace Merge.Client.Crm; -public class FieldMappingApiInstanceTargetField +public record FieldMappingApiInstanceTargetField { [JsonPropertyName("name")] - public string Name { get; init; } + public required string Name { get; set; } [JsonPropertyName("description")] - public string Description { get; init; } + public required string Description { get; set; } [JsonPropertyName("is_organization_wide")] - public bool IsOrganizationWide { get; init; } + public required bool IsOrganizationWide { get; set; } } diff --git a/src/Merge.Client/Crm/Types/FieldMappingInstanceResponse.cs b/src/Merge.Client/Crm/Types/FieldMappingInstanceResponse.cs index 5c218229..7c44bc2e 100644 --- a/src/Merge.Client/Crm/Types/FieldMappingInstanceResponse.cs +++ b/src/Merge.Client/Crm/Types/FieldMappingInstanceResponse.cs @@ -1,21 +1,22 @@ using System.Text.Json.Serialization; -using Merge.Client.Crm; #nullable enable namespace Merge.Client.Crm; -public class FieldMappingInstanceResponse +public record FieldMappingInstanceResponse { [JsonPropertyName("model")] - public FieldMappingApiInstance Model { get; init; } + public required FieldMappingApiInstance Model { get; set; } [JsonPropertyName("warnings")] - public IEnumerable Warnings { get; init; } + public IEnumerable Warnings { get; set; } = + new List(); [JsonPropertyName("errors")] - public IEnumerable Errors { get; init; } + public IEnumerable Errors { get; set; } = + new List(); [JsonPropertyName("logs")] - public IEnumerable? Logs { get; init; } + public IEnumerable? Logs { get; set; } } diff --git a/src/Merge.Client/Crm/Types/FieldPermissionDeserializer.cs b/src/Merge.Client/Crm/Types/FieldPermissionDeserializer.cs index f404864a..7179d7f0 100644 --- a/src/Merge.Client/Crm/Types/FieldPermissionDeserializer.cs +++ b/src/Merge.Client/Crm/Types/FieldPermissionDeserializer.cs @@ -4,11 +4,11 @@ namespace Merge.Client.Crm; -public class FieldPermissionDeserializer +public record FieldPermissionDeserializer { [JsonPropertyName("enabled")] - public IEnumerable? Enabled { get; init; } + public IEnumerable? Enabled { get; set; } [JsonPropertyName("disabled")] - public IEnumerable? Disabled { get; init; } + public IEnumerable? Disabled { get; set; } } diff --git a/src/Merge.Client/Crm/Types/FieldPermissionDeserializerRequest.cs b/src/Merge.Client/Crm/Types/FieldPermissionDeserializerRequest.cs index 97eab2b6..d604903b 100644 --- a/src/Merge.Client/Crm/Types/FieldPermissionDeserializerRequest.cs +++ b/src/Merge.Client/Crm/Types/FieldPermissionDeserializerRequest.cs @@ -4,11 +4,11 @@ namespace Merge.Client.Crm; -public class FieldPermissionDeserializerRequest +public record FieldPermissionDeserializerRequest { [JsonPropertyName("enabled")] - public IEnumerable? Enabled { get; init; } + public IEnumerable? Enabled { get; set; } [JsonPropertyName("disabled")] - public IEnumerable? Disabled { get; init; } + public IEnumerable? Disabled { get; set; } } diff --git a/src/Merge.Client/Crm/Types/FieldTypeEnum.cs b/src/Merge.Client/Crm/Types/FieldTypeEnum.cs index 3be90a7b..f5f3e7d1 100644 --- a/src/Merge.Client/Crm/Types/FieldTypeEnum.cs +++ b/src/Merge.Client/Crm/Types/FieldTypeEnum.cs @@ -1,7 +1,6 @@ using System.Runtime.Serialization; using System.Text.Json.Serialization; using Merge.Client.Core; -using Merge.Client.Crm; #nullable enable diff --git a/src/Merge.Client/Crm/Types/IgnoreCommonModelRequest.cs b/src/Merge.Client/Crm/Types/IgnoreCommonModelRequest.cs index 4d982b08..e221f9f3 100644 --- a/src/Merge.Client/Crm/Types/IgnoreCommonModelRequest.cs +++ b/src/Merge.Client/Crm/Types/IgnoreCommonModelRequest.cs @@ -1,15 +1,14 @@ using System.Text.Json.Serialization; -using Merge.Client.Crm; #nullable enable namespace Merge.Client.Crm; -public class IgnoreCommonModelRequest +public record IgnoreCommonModelRequest { [JsonPropertyName("reason")] - public ReasonEnum Reason { get; init; } + public required ReasonEnum Reason { get; set; } [JsonPropertyName("message")] - public string? Message { get; init; } + public string? Message { get; set; } } diff --git a/src/Merge.Client/Crm/Types/IndividualCommonModelScopeDeserializer.cs b/src/Merge.Client/Crm/Types/IndividualCommonModelScopeDeserializer.cs index 7afc38fc..353a908d 100644 --- a/src/Merge.Client/Crm/Types/IndividualCommonModelScopeDeserializer.cs +++ b/src/Merge.Client/Crm/Types/IndividualCommonModelScopeDeserializer.cs @@ -1,18 +1,17 @@ using System.Text.Json.Serialization; -using Merge.Client.Crm; #nullable enable namespace Merge.Client.Crm; -public class IndividualCommonModelScopeDeserializer +public record IndividualCommonModelScopeDeserializer { [JsonPropertyName("model_name")] - public string ModelName { get; init; } + public required string ModelName { get; set; } [JsonPropertyName("model_permissions")] - public Dictionary? ModelPermissions { get; init; } + public Dictionary? ModelPermissions { get; set; } [JsonPropertyName("field_permissions")] - public FieldPermissionDeserializer? FieldPermissions { get; init; } + public FieldPermissionDeserializer? FieldPermissions { get; set; } } diff --git a/src/Merge.Client/Crm/Types/IndividualCommonModelScopeDeserializerRequest.cs b/src/Merge.Client/Crm/Types/IndividualCommonModelScopeDeserializerRequest.cs index 539ae559..9ec81b58 100644 --- a/src/Merge.Client/Crm/Types/IndividualCommonModelScopeDeserializerRequest.cs +++ b/src/Merge.Client/Crm/Types/IndividualCommonModelScopeDeserializerRequest.cs @@ -1,18 +1,17 @@ using System.Text.Json.Serialization; -using Merge.Client.Crm; #nullable enable namespace Merge.Client.Crm; -public class IndividualCommonModelScopeDeserializerRequest +public record IndividualCommonModelScopeDeserializerRequest { [JsonPropertyName("model_name")] - public string ModelName { get; init; } + public required string ModelName { get; set; } [JsonPropertyName("model_permissions")] - public Dictionary? ModelPermissions { get; init; } + public Dictionary? ModelPermissions { get; set; } [JsonPropertyName("field_permissions")] - public FieldPermissionDeserializerRequest? FieldPermissions { get; init; } + public FieldPermissionDeserializerRequest? FieldPermissions { get; set; } } diff --git a/src/Merge.Client/Crm/Types/Issue.cs b/src/Merge.Client/Crm/Types/Issue.cs index 9f5b4ec8..95fc56fb 100644 --- a/src/Merge.Client/Crm/Types/Issue.cs +++ b/src/Merge.Client/Crm/Types/Issue.cs @@ -1,14 +1,13 @@ using System.Text.Json.Serialization; -using Merge.Client.Crm; #nullable enable namespace Merge.Client.Crm; -public class Issue +public record Issue { [JsonPropertyName("id")] - public string? Id { get; init; } + public string? Id { get; set; } /// /// Status of the issue. Options: ('ONGOING', 'RESOLVED') @@ -17,23 +16,23 @@ public class Issue /// - `RESOLVED` - RESOLVED /// [JsonPropertyName("status")] - public IssueStatusEnum? Status { get; init; } + public IssueStatusEnum? Status { get; set; } [JsonPropertyName("error_description")] - public string ErrorDescription { get; init; } + public required string ErrorDescription { get; set; } [JsonPropertyName("end_user")] - public Dictionary? EndUser { get; init; } + public Dictionary? EndUser { get; set; } [JsonPropertyName("first_incident_time")] - public DateTime? FirstIncidentTime { get; init; } + public DateTime? FirstIncidentTime { get; set; } [JsonPropertyName("last_incident_time")] - public DateTime? LastIncidentTime { get; init; } + public DateTime? LastIncidentTime { get; set; } [JsonPropertyName("is_muted")] - public bool? IsMuted { get; init; } + public bool? IsMuted { get; set; } [JsonPropertyName("error_details")] - public IEnumerable? ErrorDetails { get; init; } + public IEnumerable? ErrorDetails { get; set; } } diff --git a/src/Merge.Client/Crm/Types/IssueStatusEnum.cs b/src/Merge.Client/Crm/Types/IssueStatusEnum.cs index a089c98c..db32dd27 100644 --- a/src/Merge.Client/Crm/Types/IssueStatusEnum.cs +++ b/src/Merge.Client/Crm/Types/IssueStatusEnum.cs @@ -1,7 +1,6 @@ using System.Runtime.Serialization; using System.Text.Json.Serialization; using Merge.Client.Core; -using Merge.Client.Crm; #nullable enable diff --git a/src/Merge.Client/Crm/Types/ItemFormatEnum.cs b/src/Merge.Client/Crm/Types/ItemFormatEnum.cs index 12120a5d..749970ae 100644 --- a/src/Merge.Client/Crm/Types/ItemFormatEnum.cs +++ b/src/Merge.Client/Crm/Types/ItemFormatEnum.cs @@ -1,7 +1,6 @@ using System.Runtime.Serialization; using System.Text.Json.Serialization; using Merge.Client.Core; -using Merge.Client.Crm; #nullable enable diff --git a/src/Merge.Client/Crm/Types/ItemSchema.cs b/src/Merge.Client/Crm/Types/ItemSchema.cs index c34b07af..9882fed5 100644 --- a/src/Merge.Client/Crm/Types/ItemSchema.cs +++ b/src/Merge.Client/Crm/Types/ItemSchema.cs @@ -1,18 +1,17 @@ using System.Text.Json.Serialization; -using Merge.Client.Crm; #nullable enable namespace Merge.Client.Crm; -public class ItemSchema +public record ItemSchema { [JsonPropertyName("item_type")] - public ItemTypeEnum? ItemType { get; init; } + public ItemTypeEnum? ItemType { get; set; } [JsonPropertyName("item_format")] - public ItemFormatEnum? ItemFormat { get; init; } + public ItemFormatEnum? ItemFormat { get; set; } [JsonPropertyName("item_choices")] - public IEnumerable? ItemChoices { get; init; } + public IEnumerable? ItemChoices { get; set; } } diff --git a/src/Merge.Client/Crm/Types/ItemTypeEnum.cs b/src/Merge.Client/Crm/Types/ItemTypeEnum.cs index 3f3fd31d..1627a949 100644 --- a/src/Merge.Client/Crm/Types/ItemTypeEnum.cs +++ b/src/Merge.Client/Crm/Types/ItemTypeEnum.cs @@ -1,7 +1,6 @@ using System.Runtime.Serialization; using System.Text.Json.Serialization; using Merge.Client.Core; -using Merge.Client.Crm; #nullable enable diff --git a/src/Merge.Client/Crm/Types/Lead.cs b/src/Merge.Client/Crm/Types/Lead.cs index 73cfbeab..1e4a5f03 100644 --- a/src/Merge.Client/Crm/Types/Lead.cs +++ b/src/Merge.Client/Crm/Types/Lead.cs @@ -1,122 +1,121 @@ using System.Text.Json.Serialization; using Merge.Client.Core; -using Merge.Client.Crm; using OneOf; #nullable enable namespace Merge.Client.Crm; -public class Lead +public record Lead { [JsonPropertyName("id")] - public string? Id { get; init; } + public string? Id { get; set; } /// /// The third-party API ID of the matching object. /// [JsonPropertyName("remote_id")] - public string? RemoteId { get; init; } + public string? RemoteId { get; set; } /// /// The datetime that this object was created by Merge. /// [JsonPropertyName("created_at")] - public DateTime? CreatedAt { get; init; } + public DateTime? CreatedAt { get; set; } /// /// The datetime that this object was modified by Merge. /// [JsonPropertyName("modified_at")] - public DateTime? ModifiedAt { get; init; } + public DateTime? ModifiedAt { get; set; } /// /// The lead's owner. /// [JsonPropertyName("owner")] [JsonConverter(typeof(OneOfSerializer>))] - public OneOf? Owner { get; init; } + public OneOf? Owner { get; set; } /// /// The lead's source. /// [JsonPropertyName("lead_source")] - public string? LeadSource { get; init; } + public string? LeadSource { get; set; } /// /// The lead's title. /// [JsonPropertyName("title")] - public string? Title { get; init; } + public string? Title { get; set; } /// /// The lead's company. /// [JsonPropertyName("company")] - public string? Company { get; init; } + public string? Company { get; set; } /// /// The lead's first name. /// [JsonPropertyName("first_name")] - public string? FirstName { get; init; } + public string? FirstName { get; set; } /// /// The lead's last name. /// [JsonPropertyName("last_name")] - public string? LastName { get; init; } + public string? LastName { get; set; } [JsonPropertyName("addresses")] - public IEnumerable
? Addresses { get; init; } + public IEnumerable
? Addresses { get; set; } [JsonPropertyName("email_addresses")] - public IEnumerable? EmailAddresses { get; init; } + public IEnumerable? EmailAddresses { get; set; } [JsonPropertyName("phone_numbers")] - public IEnumerable? PhoneNumbers { get; init; } + public IEnumerable? PhoneNumbers { get; set; } /// /// When the third party's lead was updated. /// [JsonPropertyName("remote_updated_at")] - public DateTime? RemoteUpdatedAt { get; init; } + public DateTime? RemoteUpdatedAt { get; set; } /// /// When the third party's lead was created. /// [JsonPropertyName("remote_created_at")] - public DateTime? RemoteCreatedAt { get; init; } + public DateTime? RemoteCreatedAt { get; set; } /// /// When the lead was converted. /// [JsonPropertyName("converted_date")] - public DateTime? ConvertedDate { get; init; } + public DateTime? ConvertedDate { get; set; } /// /// The contact of the converted lead. /// [JsonPropertyName("converted_contact")] [JsonConverter(typeof(OneOfSerializer>))] - public OneOf? ConvertedContact { get; init; } + public OneOf? ConvertedContact { get; set; } /// /// The account of the converted lead. /// [JsonPropertyName("converted_account")] [JsonConverter(typeof(OneOfSerializer>))] - public OneOf? ConvertedAccount { get; init; } + public OneOf? ConvertedAccount { get; set; } [JsonPropertyName("remote_was_deleted")] - public bool? RemoteWasDeleted { get; init; } + public bool? RemoteWasDeleted { get; set; } [JsonPropertyName("field_mappings")] - public Dictionary? FieldMappings { get; init; } + public Dictionary? FieldMappings { get; set; } [JsonPropertyName("remote_data")] - public IEnumerable? RemoteData { get; init; } + public IEnumerable? RemoteData { get; set; } [JsonPropertyName("remote_fields")] - public IEnumerable? RemoteFields { get; init; } + public IEnumerable? RemoteFields { get; set; } } diff --git a/src/Merge.Client/Crm/Types/LeadRequest.cs b/src/Merge.Client/Crm/Types/LeadRequest.cs index 5ef8d173..aa00f07f 100644 --- a/src/Merge.Client/Crm/Types/LeadRequest.cs +++ b/src/Merge.Client/Crm/Types/LeadRequest.cs @@ -1,86 +1,85 @@ using System.Text.Json.Serialization; using Merge.Client.Core; -using Merge.Client.Crm; using OneOf; #nullable enable namespace Merge.Client.Crm; -public class LeadRequest +public record LeadRequest { /// /// The lead's owner. /// [JsonPropertyName("owner")] [JsonConverter(typeof(OneOfSerializer>))] - public OneOf? Owner { get; init; } + public OneOf? Owner { get; set; } /// /// The lead's source. /// [JsonPropertyName("lead_source")] - public string? LeadSource { get; init; } + public string? LeadSource { get; set; } /// /// The lead's title. /// [JsonPropertyName("title")] - public string? Title { get; init; } + public string? Title { get; set; } /// /// The lead's company. /// [JsonPropertyName("company")] - public string? Company { get; init; } + public string? Company { get; set; } /// /// The lead's first name. /// [JsonPropertyName("first_name")] - public string? FirstName { get; init; } + public string? FirstName { get; set; } /// /// The lead's last name. /// [JsonPropertyName("last_name")] - public string? LastName { get; init; } + public string? LastName { get; set; } [JsonPropertyName("addresses")] - public IEnumerable? Addresses { get; init; } + public IEnumerable? Addresses { get; set; } [JsonPropertyName("email_addresses")] - public IEnumerable? EmailAddresses { get; init; } + public IEnumerable? EmailAddresses { get; set; } [JsonPropertyName("phone_numbers")] - public IEnumerable? PhoneNumbers { get; init; } + public IEnumerable? PhoneNumbers { get; set; } /// /// When the lead was converted. /// [JsonPropertyName("converted_date")] - public DateTime? ConvertedDate { get; init; } + public DateTime? ConvertedDate { get; set; } /// /// The contact of the converted lead. /// [JsonPropertyName("converted_contact")] [JsonConverter(typeof(OneOfSerializer>))] - public OneOf? ConvertedContact { get; init; } + public OneOf? ConvertedContact { get; set; } /// /// The account of the converted lead. /// [JsonPropertyName("converted_account")] [JsonConverter(typeof(OneOfSerializer>))] - public OneOf? ConvertedAccount { get; init; } + public OneOf? ConvertedAccount { get; set; } [JsonPropertyName("integration_params")] - public Dictionary? IntegrationParams { get; init; } + public Dictionary? IntegrationParams { get; set; } [JsonPropertyName("linked_account_params")] - public Dictionary? LinkedAccountParams { get; init; } + public Dictionary? LinkedAccountParams { get; set; } [JsonPropertyName("remote_fields")] - public IEnumerable? RemoteFields { get; init; } + public IEnumerable? RemoteFields { get; set; } } diff --git a/src/Merge.Client/Crm/Types/LeadResponse.cs b/src/Merge.Client/Crm/Types/LeadResponse.cs index 8f5d7f51..cd8c55de 100644 --- a/src/Merge.Client/Crm/Types/LeadResponse.cs +++ b/src/Merge.Client/Crm/Types/LeadResponse.cs @@ -1,21 +1,22 @@ using System.Text.Json.Serialization; -using Merge.Client.Crm; #nullable enable namespace Merge.Client.Crm; -public class LeadResponse +public record LeadResponse { [JsonPropertyName("model")] - public Lead Model { get; init; } + public required Lead Model { get; set; } [JsonPropertyName("warnings")] - public IEnumerable Warnings { get; init; } + public IEnumerable Warnings { get; set; } = + new List(); [JsonPropertyName("errors")] - public IEnumerable Errors { get; init; } + public IEnumerable Errors { get; set; } = + new List(); [JsonPropertyName("logs")] - public IEnumerable? Logs { get; init; } + public IEnumerable? Logs { get; set; } } diff --git a/src/Merge.Client/Crm/Types/LinkToken.cs b/src/Merge.Client/Crm/Types/LinkToken.cs index c743af97..aedc6865 100644 --- a/src/Merge.Client/Crm/Types/LinkToken.cs +++ b/src/Merge.Client/Crm/Types/LinkToken.cs @@ -4,14 +4,14 @@ namespace Merge.Client.Crm; -public class LinkToken +public record LinkToken { [JsonPropertyName("link_token")] - public string LinkToken_ { get; init; } + public required string LinkToken_ { get; set; } [JsonPropertyName("integration_name")] - public string? IntegrationName { get; init; } + public string? IntegrationName { get; set; } [JsonPropertyName("magic_link_url")] - public string? MagicLinkUrl { get; init; } + public string? MagicLinkUrl { get; set; } } diff --git a/src/Merge.Client/Crm/Types/LinkedAccountStatus.cs b/src/Merge.Client/Crm/Types/LinkedAccountStatus.cs index decff321..11d1a264 100644 --- a/src/Merge.Client/Crm/Types/LinkedAccountStatus.cs +++ b/src/Merge.Client/Crm/Types/LinkedAccountStatus.cs @@ -4,11 +4,11 @@ namespace Merge.Client.Crm; -public class LinkedAccountStatus +public record LinkedAccountStatus { [JsonPropertyName("linked_account_status")] - public string LinkedAccountStatus_ { get; init; } + public required string LinkedAccountStatus_ { get; set; } [JsonPropertyName("can_make_request")] - public bool CanMakeRequest { get; init; } + public required bool CanMakeRequest { get; set; } } diff --git a/src/Merge.Client/Crm/Types/MetaResponse.cs b/src/Merge.Client/Crm/Types/MetaResponse.cs index f505e8f7..79028a4c 100644 --- a/src/Merge.Client/Crm/Types/MetaResponse.cs +++ b/src/Merge.Client/Crm/Types/MetaResponse.cs @@ -1,24 +1,24 @@ using System.Text.Json.Serialization; -using Merge.Client.Crm; #nullable enable namespace Merge.Client.Crm; -public class MetaResponse +public record MetaResponse { [JsonPropertyName("request_schema")] - public Dictionary RequestSchema { get; init; } + public Dictionary RequestSchema { get; set; } = + new Dictionary(); [JsonPropertyName("remote_field_classes")] - public Dictionary? RemoteFieldClasses { get; init; } + public Dictionary? RemoteFieldClasses { get; set; } [JsonPropertyName("status")] - public LinkedAccountStatus? Status { get; init; } + public LinkedAccountStatus? Status { get; set; } [JsonPropertyName("has_conditional_params")] - public bool HasConditionalParams { get; init; } + public required bool HasConditionalParams { get; set; } [JsonPropertyName("has_required_linked_account_params")] - public bool HasRequiredLinkedAccountParams { get; init; } + public required bool HasRequiredLinkedAccountParams { get; set; } } diff --git a/src/Merge.Client/Crm/Types/MethodEnum.cs b/src/Merge.Client/Crm/Types/MethodEnum.cs index 23503bca..69959a56 100644 --- a/src/Merge.Client/Crm/Types/MethodEnum.cs +++ b/src/Merge.Client/Crm/Types/MethodEnum.cs @@ -1,7 +1,6 @@ using System.Runtime.Serialization; using System.Text.Json.Serialization; using Merge.Client.Core; -using Merge.Client.Crm; #nullable enable diff --git a/src/Merge.Client/Crm/Types/ModelOperation.cs b/src/Merge.Client/Crm/Types/ModelOperation.cs index 07047afd..de633d95 100644 --- a/src/Merge.Client/Crm/Types/ModelOperation.cs +++ b/src/Merge.Client/Crm/Types/ModelOperation.cs @@ -4,17 +4,17 @@ namespace Merge.Client.Crm; -public class ModelOperation +public record ModelOperation { [JsonPropertyName("model_name")] - public string ModelName { get; init; } + public required string ModelName { get; set; } [JsonPropertyName("available_operations")] - public IEnumerable AvailableOperations { get; init; } + public IEnumerable AvailableOperations { get; set; } = new List(); [JsonPropertyName("required_post_parameters")] - public IEnumerable RequiredPostParameters { get; init; } + public IEnumerable RequiredPostParameters { get; set; } = new List(); [JsonPropertyName("supported_fields")] - public IEnumerable SupportedFields { get; init; } + public IEnumerable SupportedFields { get; set; } = new List(); } diff --git a/src/Merge.Client/Crm/Types/ModelPermissionDeserializer.cs b/src/Merge.Client/Crm/Types/ModelPermissionDeserializer.cs index 943d7768..12225328 100644 --- a/src/Merge.Client/Crm/Types/ModelPermissionDeserializer.cs +++ b/src/Merge.Client/Crm/Types/ModelPermissionDeserializer.cs @@ -4,8 +4,8 @@ namespace Merge.Client.Crm; -public class ModelPermissionDeserializer +public record ModelPermissionDeserializer { [JsonPropertyName("is_enabled")] - public bool? IsEnabled { get; init; } + public bool? IsEnabled { get; set; } } diff --git a/src/Merge.Client/Crm/Types/ModelPermissionDeserializerRequest.cs b/src/Merge.Client/Crm/Types/ModelPermissionDeserializerRequest.cs index 954e45c1..5daec1a1 100644 --- a/src/Merge.Client/Crm/Types/ModelPermissionDeserializerRequest.cs +++ b/src/Merge.Client/Crm/Types/ModelPermissionDeserializerRequest.cs @@ -4,8 +4,8 @@ namespace Merge.Client.Crm; -public class ModelPermissionDeserializerRequest +public record ModelPermissionDeserializerRequest { [JsonPropertyName("is_enabled")] - public bool? IsEnabled { get; init; } + public bool? IsEnabled { get; set; } } diff --git a/src/Merge.Client/Crm/Types/MultipartFormFieldRequest.cs b/src/Merge.Client/Crm/Types/MultipartFormFieldRequest.cs index 54e56b85..8b7484f8 100644 --- a/src/Merge.Client/Crm/Types/MultipartFormFieldRequest.cs +++ b/src/Merge.Client/Crm/Types/MultipartFormFieldRequest.cs @@ -1,23 +1,22 @@ using System.Text.Json.Serialization; -using Merge.Client.Crm; #nullable enable namespace Merge.Client.Crm; -public class MultipartFormFieldRequest +public record MultipartFormFieldRequest { /// /// The name of the form field /// [JsonPropertyName("name")] - public string Name { get; init; } + public required string Name { get; set; } /// /// The data for the form field. /// [JsonPropertyName("data")] - public string Data { get; init; } + public required string Data { get; set; } /// /// The encoding of the value of `data`. Defaults to `RAW` if not defined. @@ -27,17 +26,17 @@ public class MultipartFormFieldRequest /// - `GZIP_BASE64` - GZIP_BASE64 /// [JsonPropertyName("encoding")] - public EncodingEnum? Encoding { get; init; } + public EncodingEnum? Encoding { get; set; } /// /// The file name of the form field, if the field is for a file. /// [JsonPropertyName("file_name")] - public string? FileName { get; init; } + public string? FileName { get; set; } /// /// The MIME type of the file, if the field is for a file. /// [JsonPropertyName("content_type")] - public string? ContentType { get; init; } + public string? ContentType { get; set; } } diff --git a/src/Merge.Client/Crm/Types/Note.cs b/src/Merge.Client/Crm/Types/Note.cs index 25fbf199..e0a1e2f0 100644 --- a/src/Merge.Client/Crm/Types/Note.cs +++ b/src/Merge.Client/Crm/Types/Note.cs @@ -1,90 +1,89 @@ using System.Text.Json.Serialization; using Merge.Client.Core; -using Merge.Client.Crm; using OneOf; #nullable enable namespace Merge.Client.Crm; -public class Note +public record Note { [JsonPropertyName("id")] - public string? Id { get; init; } + public string? Id { get; set; } /// /// The third-party API ID of the matching object. /// [JsonPropertyName("remote_id")] - public string? RemoteId { get; init; } + public string? RemoteId { get; set; } /// /// The datetime that this object was created by Merge. /// [JsonPropertyName("created_at")] - public DateTime? CreatedAt { get; init; } + public DateTime? CreatedAt { get; set; } /// /// The datetime that this object was modified by Merge. /// [JsonPropertyName("modified_at")] - public DateTime? ModifiedAt { get; init; } + public DateTime? ModifiedAt { get; set; } /// /// The note's owner. /// [JsonPropertyName("owner")] [JsonConverter(typeof(OneOfSerializer>))] - public OneOf? Owner { get; init; } + public OneOf? Owner { get; set; } /// /// The note's content. /// [JsonPropertyName("content")] - public string? Content { get; init; } + public string? Content { get; set; } /// /// The note's contact. /// [JsonPropertyName("contact")] [JsonConverter(typeof(OneOfSerializer>))] - public OneOf? Contact { get; init; } + public OneOf? Contact { get; set; } /// /// The note's account. /// [JsonPropertyName("account")] [JsonConverter(typeof(OneOfSerializer>))] - public OneOf? Account { get; init; } + public OneOf? Account { get; set; } /// /// The note's opportunity. /// [JsonPropertyName("opportunity")] [JsonConverter(typeof(OneOfSerializer>))] - public OneOf? Opportunity { get; init; } + public OneOf? Opportunity { get; set; } /// /// When the third party's lead was updated. /// [JsonPropertyName("remote_updated_at")] - public DateTime? RemoteUpdatedAt { get; init; } + public DateTime? RemoteUpdatedAt { get; set; } /// /// When the third party's lead was created. /// [JsonPropertyName("remote_created_at")] - public DateTime? RemoteCreatedAt { get; init; } + public DateTime? RemoteCreatedAt { get; set; } [JsonPropertyName("remote_was_deleted")] - public bool? RemoteWasDeleted { get; init; } + public bool? RemoteWasDeleted { get; set; } [JsonPropertyName("field_mappings")] - public Dictionary? FieldMappings { get; init; } + public Dictionary? FieldMappings { get; set; } [JsonPropertyName("remote_data")] - public IEnumerable? RemoteData { get; init; } + public IEnumerable? RemoteData { get; set; } [JsonPropertyName("remote_fields")] - public IEnumerable? RemoteFields { get; init; } + public IEnumerable? RemoteFields { get; set; } } diff --git a/src/Merge.Client/Crm/Types/NoteRequest.cs b/src/Merge.Client/Crm/Types/NoteRequest.cs index d4729eba..d81df04c 100644 --- a/src/Merge.Client/Crm/Types/NoteRequest.cs +++ b/src/Merge.Client/Crm/Types/NoteRequest.cs @@ -1,54 +1,53 @@ using System.Text.Json.Serialization; using Merge.Client.Core; -using Merge.Client.Crm; using OneOf; #nullable enable namespace Merge.Client.Crm; -public class NoteRequest +public record NoteRequest { /// /// The note's owner. /// [JsonPropertyName("owner")] [JsonConverter(typeof(OneOfSerializer>))] - public OneOf? Owner { get; init; } + public OneOf? Owner { get; set; } /// /// The note's content. /// [JsonPropertyName("content")] - public string? Content { get; init; } + public string? Content { get; set; } /// /// The note's contact. /// [JsonPropertyName("contact")] [JsonConverter(typeof(OneOfSerializer>))] - public OneOf? Contact { get; init; } + public OneOf? Contact { get; set; } /// /// The note's account. /// [JsonPropertyName("account")] [JsonConverter(typeof(OneOfSerializer>))] - public OneOf? Account { get; init; } + public OneOf? Account { get; set; } /// /// The note's opportunity. /// [JsonPropertyName("opportunity")] [JsonConverter(typeof(OneOfSerializer>))] - public OneOf? Opportunity { get; init; } + public OneOf? Opportunity { get; set; } [JsonPropertyName("integration_params")] - public Dictionary? IntegrationParams { get; init; } + public Dictionary? IntegrationParams { get; set; } [JsonPropertyName("linked_account_params")] - public Dictionary? LinkedAccountParams { get; init; } + public Dictionary? LinkedAccountParams { get; set; } [JsonPropertyName("remote_fields")] - public IEnumerable? RemoteFields { get; init; } + public IEnumerable? RemoteFields { get; set; } } diff --git a/src/Merge.Client/Crm/Types/NoteResponse.cs b/src/Merge.Client/Crm/Types/NoteResponse.cs index 30e928a3..fcc5ce7d 100644 --- a/src/Merge.Client/Crm/Types/NoteResponse.cs +++ b/src/Merge.Client/Crm/Types/NoteResponse.cs @@ -1,21 +1,22 @@ using System.Text.Json.Serialization; -using Merge.Client.Crm; #nullable enable namespace Merge.Client.Crm; -public class NoteResponse +public record NoteResponse { [JsonPropertyName("model")] - public Note Model { get; init; } + public required Note Model { get; set; } [JsonPropertyName("warnings")] - public IEnumerable Warnings { get; init; } + public IEnumerable Warnings { get; set; } = + new List(); [JsonPropertyName("errors")] - public IEnumerable Errors { get; init; } + public IEnumerable Errors { get; set; } = + new List(); [JsonPropertyName("logs")] - public IEnumerable? Logs { get; init; } + public IEnumerable? Logs { get; set; } } diff --git a/src/Merge.Client/Crm/Types/ObjectClassDescriptionRequest.cs b/src/Merge.Client/Crm/Types/ObjectClassDescriptionRequest.cs index fd1004ad..710de42b 100644 --- a/src/Merge.Client/Crm/Types/ObjectClassDescriptionRequest.cs +++ b/src/Merge.Client/Crm/Types/ObjectClassDescriptionRequest.cs @@ -1,15 +1,14 @@ using System.Text.Json.Serialization; -using Merge.Client.Crm; #nullable enable namespace Merge.Client.Crm; -public class ObjectClassDescriptionRequest +public record ObjectClassDescriptionRequest { [JsonPropertyName("id")] - public string Id { get; init; } + public required string Id { get; set; } [JsonPropertyName("origin_type")] - public OriginTypeEnum OriginType { get; init; } + public required OriginTypeEnum OriginType { get; set; } } diff --git a/src/Merge.Client/Crm/Types/Opportunity.cs b/src/Merge.Client/Crm/Types/Opportunity.cs index 4766fb8e..b56f2a6c 100644 --- a/src/Merge.Client/Crm/Types/Opportunity.cs +++ b/src/Merge.Client/Crm/Types/Opportunity.cs @@ -1,73 +1,72 @@ using System.Text.Json.Serialization; using Merge.Client.Core; -using Merge.Client.Crm; using OneOf; #nullable enable namespace Merge.Client.Crm; -public class Opportunity +public record Opportunity { [JsonPropertyName("id")] - public string? Id { get; init; } + public string? Id { get; set; } /// /// The third-party API ID of the matching object. /// [JsonPropertyName("remote_id")] - public string? RemoteId { get; init; } + public string? RemoteId { get; set; } /// /// The datetime that this object was created by Merge. /// [JsonPropertyName("created_at")] - public DateTime? CreatedAt { get; init; } + public DateTime? CreatedAt { get; set; } /// /// The datetime that this object was modified by Merge. /// [JsonPropertyName("modified_at")] - public DateTime? ModifiedAt { get; init; } + public DateTime? ModifiedAt { get; set; } /// /// The opportunity's name. /// [JsonPropertyName("name")] - public string? Name { get; init; } + public string? Name { get; set; } /// /// The opportunity's description. /// [JsonPropertyName("description")] - public string? Description { get; init; } + public string? Description { get; set; } /// /// The opportunity's amount. /// [JsonPropertyName("amount")] - public int? Amount { get; init; } + public int? Amount { get; set; } /// /// The opportunity's owner. /// [JsonPropertyName("owner")] [JsonConverter(typeof(OneOfSerializer>))] - public OneOf? Owner { get; init; } + public OneOf? Owner { get; set; } /// /// The account of the opportunity. /// [JsonPropertyName("account")] [JsonConverter(typeof(OneOfSerializer>))] - public OneOf? Account { get; init; } + public OneOf? Account { get; set; } /// /// The stage of the opportunity. /// [JsonPropertyName("stage")] [JsonConverter(typeof(OneOfSerializer>))] - public OneOf? Stage { get; init; } + public OneOf? Stage { get; set; } /// /// The opportunity's status. @@ -77,35 +76,35 @@ public class Opportunity /// - `LOST` - LOST /// [JsonPropertyName("status")] - public OpportunityStatusEnum? Status { get; init; } + public OpportunityStatusEnum? Status { get; set; } /// /// When the opportunity's last activity occurred. /// [JsonPropertyName("last_activity_at")] - public DateTime? LastActivityAt { get; init; } + public DateTime? LastActivityAt { get; set; } /// /// When the opportunity was closed. /// [JsonPropertyName("close_date")] - public DateTime? CloseDate { get; init; } + public DateTime? CloseDate { get; set; } /// /// When the third party's opportunity was created. /// [JsonPropertyName("remote_created_at")] - public DateTime? RemoteCreatedAt { get; init; } + public DateTime? RemoteCreatedAt { get; set; } [JsonPropertyName("remote_was_deleted")] - public bool? RemoteWasDeleted { get; init; } + public bool? RemoteWasDeleted { get; set; } [JsonPropertyName("field_mappings")] - public Dictionary? FieldMappings { get; init; } + public Dictionary? FieldMappings { get; set; } [JsonPropertyName("remote_data")] - public IEnumerable? RemoteData { get; init; } + public IEnumerable? RemoteData { get; set; } [JsonPropertyName("remote_fields")] - public IEnumerable? RemoteFields { get; init; } + public IEnumerable? RemoteFields { get; set; } } diff --git a/src/Merge.Client/Crm/Types/OpportunityRequest.cs b/src/Merge.Client/Crm/Types/OpportunityRequest.cs index b2e6c504..f8fc2c9d 100644 --- a/src/Merge.Client/Crm/Types/OpportunityRequest.cs +++ b/src/Merge.Client/Crm/Types/OpportunityRequest.cs @@ -1,52 +1,51 @@ using System.Text.Json.Serialization; using Merge.Client.Core; -using Merge.Client.Crm; using OneOf; #nullable enable namespace Merge.Client.Crm; -public class OpportunityRequest +public record OpportunityRequest { /// /// The opportunity's name. /// [JsonPropertyName("name")] - public string? Name { get; init; } + public string? Name { get; set; } /// /// The opportunity's description. /// [JsonPropertyName("description")] - public string? Description { get; init; } + public string? Description { get; set; } /// /// The opportunity's amount. /// [JsonPropertyName("amount")] - public int? Amount { get; init; } + public int? Amount { get; set; } /// /// The opportunity's owner. /// [JsonPropertyName("owner")] [JsonConverter(typeof(OneOfSerializer>))] - public OneOf? Owner { get; init; } + public OneOf? Owner { get; set; } /// /// The account of the opportunity. /// [JsonPropertyName("account")] [JsonConverter(typeof(OneOfSerializer>))] - public OneOf? Account { get; init; } + public OneOf? Account { get; set; } /// /// The stage of the opportunity. /// [JsonPropertyName("stage")] [JsonConverter(typeof(OneOfSerializer>))] - public OneOf? Stage { get; init; } + public OneOf? Stage { get; set; } /// /// The opportunity's status. @@ -56,26 +55,26 @@ public class OpportunityRequest /// - `LOST` - LOST /// [JsonPropertyName("status")] - public OpportunityStatusEnum? Status { get; init; } + public OpportunityStatusEnum? Status { get; set; } /// /// When the opportunity's last activity occurred. /// [JsonPropertyName("last_activity_at")] - public DateTime? LastActivityAt { get; init; } + public DateTime? LastActivityAt { get; set; } /// /// When the opportunity was closed. /// [JsonPropertyName("close_date")] - public DateTime? CloseDate { get; init; } + public DateTime? CloseDate { get; set; } [JsonPropertyName("integration_params")] - public Dictionary? IntegrationParams { get; init; } + public Dictionary? IntegrationParams { get; set; } [JsonPropertyName("linked_account_params")] - public Dictionary? LinkedAccountParams { get; init; } + public Dictionary? LinkedAccountParams { get; set; } [JsonPropertyName("remote_fields")] - public IEnumerable? RemoteFields { get; init; } + public IEnumerable? RemoteFields { get; set; } } diff --git a/src/Merge.Client/Crm/Types/OpportunityResponse.cs b/src/Merge.Client/Crm/Types/OpportunityResponse.cs index 45ba8818..d85b660a 100644 --- a/src/Merge.Client/Crm/Types/OpportunityResponse.cs +++ b/src/Merge.Client/Crm/Types/OpportunityResponse.cs @@ -1,21 +1,22 @@ using System.Text.Json.Serialization; -using Merge.Client.Crm; #nullable enable namespace Merge.Client.Crm; -public class OpportunityResponse +public record OpportunityResponse { [JsonPropertyName("model")] - public Opportunity Model { get; init; } + public required Opportunity Model { get; set; } [JsonPropertyName("warnings")] - public IEnumerable Warnings { get; init; } + public IEnumerable Warnings { get; set; } = + new List(); [JsonPropertyName("errors")] - public IEnumerable Errors { get; init; } + public IEnumerable Errors { get; set; } = + new List(); [JsonPropertyName("logs")] - public IEnumerable? Logs { get; init; } + public IEnumerable? Logs { get; set; } } diff --git a/src/Merge.Client/Crm/Types/OpportunityStatusEnum.cs b/src/Merge.Client/Crm/Types/OpportunityStatusEnum.cs index 56d12d51..6d7b08eb 100644 --- a/src/Merge.Client/Crm/Types/OpportunityStatusEnum.cs +++ b/src/Merge.Client/Crm/Types/OpportunityStatusEnum.cs @@ -1,7 +1,6 @@ using System.Runtime.Serialization; using System.Text.Json.Serialization; using Merge.Client.Core; -using Merge.Client.Crm; #nullable enable diff --git a/src/Merge.Client/Crm/Types/OriginTypeEnum.cs b/src/Merge.Client/Crm/Types/OriginTypeEnum.cs index a6a25389..57d5b1f2 100644 --- a/src/Merge.Client/Crm/Types/OriginTypeEnum.cs +++ b/src/Merge.Client/Crm/Types/OriginTypeEnum.cs @@ -1,7 +1,6 @@ using System.Runtime.Serialization; using System.Text.Json.Serialization; using Merge.Client.Core; -using Merge.Client.Crm; #nullable enable diff --git a/src/Merge.Client/Crm/Types/PaginatedAccountDetailsAndActionsList.cs b/src/Merge.Client/Crm/Types/PaginatedAccountDetailsAndActionsList.cs index 9d935700..5429600a 100644 --- a/src/Merge.Client/Crm/Types/PaginatedAccountDetailsAndActionsList.cs +++ b/src/Merge.Client/Crm/Types/PaginatedAccountDetailsAndActionsList.cs @@ -1,18 +1,17 @@ using System.Text.Json.Serialization; -using Merge.Client.Crm; #nullable enable namespace Merge.Client.Crm; -public class PaginatedAccountDetailsAndActionsList +public record PaginatedAccountDetailsAndActionsList { [JsonPropertyName("next")] - public string? Next { get; init; } + public string? Next { get; set; } [JsonPropertyName("previous")] - public string? Previous { get; init; } + public string? Previous { get; set; } [JsonPropertyName("results")] - public IEnumerable? Results { get; init; } + public IEnumerable? Results { get; set; } } diff --git a/src/Merge.Client/Crm/Types/PaginatedAccountList.cs b/src/Merge.Client/Crm/Types/PaginatedAccountList.cs index ff2dc551..7a29c442 100644 --- a/src/Merge.Client/Crm/Types/PaginatedAccountList.cs +++ b/src/Merge.Client/Crm/Types/PaginatedAccountList.cs @@ -1,18 +1,17 @@ using System.Text.Json.Serialization; -using Merge.Client.Crm; #nullable enable namespace Merge.Client.Crm; -public class PaginatedAccountList +public record PaginatedAccountList { [JsonPropertyName("next")] - public string? Next { get; init; } + public string? Next { get; set; } [JsonPropertyName("previous")] - public string? Previous { get; init; } + public string? Previous { get; set; } [JsonPropertyName("results")] - public IEnumerable? Results { get; init; } + public IEnumerable? Results { get; set; } } diff --git a/src/Merge.Client/Crm/Types/PaginatedAssociationList.cs b/src/Merge.Client/Crm/Types/PaginatedAssociationList.cs index 9a486b36..eb0924f6 100644 --- a/src/Merge.Client/Crm/Types/PaginatedAssociationList.cs +++ b/src/Merge.Client/Crm/Types/PaginatedAssociationList.cs @@ -1,18 +1,17 @@ using System.Text.Json.Serialization; -using Merge.Client.Crm; #nullable enable namespace Merge.Client.Crm; -public class PaginatedAssociationList +public record PaginatedAssociationList { [JsonPropertyName("next")] - public string? Next { get; init; } + public string? Next { get; set; } [JsonPropertyName("previous")] - public string? Previous { get; init; } + public string? Previous { get; set; } [JsonPropertyName("results")] - public IEnumerable? Results { get; init; } + public IEnumerable? Results { get; set; } } diff --git a/src/Merge.Client/Crm/Types/PaginatedAssociationTypeList.cs b/src/Merge.Client/Crm/Types/PaginatedAssociationTypeList.cs index 8d1c4e6f..9d769f19 100644 --- a/src/Merge.Client/Crm/Types/PaginatedAssociationTypeList.cs +++ b/src/Merge.Client/Crm/Types/PaginatedAssociationTypeList.cs @@ -1,18 +1,17 @@ using System.Text.Json.Serialization; -using Merge.Client.Crm; #nullable enable namespace Merge.Client.Crm; -public class PaginatedAssociationTypeList +public record PaginatedAssociationTypeList { [JsonPropertyName("next")] - public string? Next { get; init; } + public string? Next { get; set; } [JsonPropertyName("previous")] - public string? Previous { get; init; } + public string? Previous { get; set; } [JsonPropertyName("results")] - public IEnumerable? Results { get; init; } + public IEnumerable? Results { get; set; } } diff --git a/src/Merge.Client/Crm/Types/PaginatedAuditLogEventList.cs b/src/Merge.Client/Crm/Types/PaginatedAuditLogEventList.cs index f1a3150e..762eca2d 100644 --- a/src/Merge.Client/Crm/Types/PaginatedAuditLogEventList.cs +++ b/src/Merge.Client/Crm/Types/PaginatedAuditLogEventList.cs @@ -1,18 +1,17 @@ using System.Text.Json.Serialization; -using Merge.Client.Crm; #nullable enable namespace Merge.Client.Crm; -public class PaginatedAuditLogEventList +public record PaginatedAuditLogEventList { [JsonPropertyName("next")] - public string? Next { get; init; } + public string? Next { get; set; } [JsonPropertyName("previous")] - public string? Previous { get; init; } + public string? Previous { get; set; } [JsonPropertyName("results")] - public IEnumerable? Results { get; init; } + public IEnumerable? Results { get; set; } } diff --git a/src/Merge.Client/Crm/Types/PaginatedContactList.cs b/src/Merge.Client/Crm/Types/PaginatedContactList.cs index 348b2528..9e0f0dd3 100644 --- a/src/Merge.Client/Crm/Types/PaginatedContactList.cs +++ b/src/Merge.Client/Crm/Types/PaginatedContactList.cs @@ -1,18 +1,17 @@ using System.Text.Json.Serialization; -using Merge.Client.Crm; #nullable enable namespace Merge.Client.Crm; -public class PaginatedContactList +public record PaginatedContactList { [JsonPropertyName("next")] - public string? Next { get; init; } + public string? Next { get; set; } [JsonPropertyName("previous")] - public string? Previous { get; init; } + public string? Previous { get; set; } [JsonPropertyName("results")] - public IEnumerable? Results { get; init; } + public IEnumerable? Results { get; set; } } diff --git a/src/Merge.Client/Crm/Types/PaginatedCustomObjectClassList.cs b/src/Merge.Client/Crm/Types/PaginatedCustomObjectClassList.cs index 65e96f9c..5e0d5dc1 100644 --- a/src/Merge.Client/Crm/Types/PaginatedCustomObjectClassList.cs +++ b/src/Merge.Client/Crm/Types/PaginatedCustomObjectClassList.cs @@ -1,18 +1,17 @@ using System.Text.Json.Serialization; -using Merge.Client.Crm; #nullable enable namespace Merge.Client.Crm; -public class PaginatedCustomObjectClassList +public record PaginatedCustomObjectClassList { [JsonPropertyName("next")] - public string? Next { get; init; } + public string? Next { get; set; } [JsonPropertyName("previous")] - public string? Previous { get; init; } + public string? Previous { get; set; } [JsonPropertyName("results")] - public IEnumerable? Results { get; init; } + public IEnumerable? Results { get; set; } } diff --git a/src/Merge.Client/Crm/Types/PaginatedCustomObjectList.cs b/src/Merge.Client/Crm/Types/PaginatedCustomObjectList.cs index 615cd7e9..5283acde 100644 --- a/src/Merge.Client/Crm/Types/PaginatedCustomObjectList.cs +++ b/src/Merge.Client/Crm/Types/PaginatedCustomObjectList.cs @@ -1,18 +1,17 @@ using System.Text.Json.Serialization; -using Merge.Client.Crm; #nullable enable namespace Merge.Client.Crm; -public class PaginatedCustomObjectList +public record PaginatedCustomObjectList { [JsonPropertyName("next")] - public string? Next { get; init; } + public string? Next { get; set; } [JsonPropertyName("previous")] - public string? Previous { get; init; } + public string? Previous { get; set; } [JsonPropertyName("results")] - public IEnumerable? Results { get; init; } + public IEnumerable? Results { get; set; } } diff --git a/src/Merge.Client/Crm/Types/PaginatedEngagementList.cs b/src/Merge.Client/Crm/Types/PaginatedEngagementList.cs index 894bded8..ed551589 100644 --- a/src/Merge.Client/Crm/Types/PaginatedEngagementList.cs +++ b/src/Merge.Client/Crm/Types/PaginatedEngagementList.cs @@ -1,18 +1,17 @@ using System.Text.Json.Serialization; -using Merge.Client.Crm; #nullable enable namespace Merge.Client.Crm; -public class PaginatedEngagementList +public record PaginatedEngagementList { [JsonPropertyName("next")] - public string? Next { get; init; } + public string? Next { get; set; } [JsonPropertyName("previous")] - public string? Previous { get; init; } + public string? Previous { get; set; } [JsonPropertyName("results")] - public IEnumerable? Results { get; init; } + public IEnumerable? Results { get; set; } } diff --git a/src/Merge.Client/Crm/Types/PaginatedEngagementTypeList.cs b/src/Merge.Client/Crm/Types/PaginatedEngagementTypeList.cs index 8da04fd2..0ba66849 100644 --- a/src/Merge.Client/Crm/Types/PaginatedEngagementTypeList.cs +++ b/src/Merge.Client/Crm/Types/PaginatedEngagementTypeList.cs @@ -1,18 +1,17 @@ using System.Text.Json.Serialization; -using Merge.Client.Crm; #nullable enable namespace Merge.Client.Crm; -public class PaginatedEngagementTypeList +public record PaginatedEngagementTypeList { [JsonPropertyName("next")] - public string? Next { get; init; } + public string? Next { get; set; } [JsonPropertyName("previous")] - public string? Previous { get; init; } + public string? Previous { get; set; } [JsonPropertyName("results")] - public IEnumerable? Results { get; init; } + public IEnumerable? Results { get; set; } } diff --git a/src/Merge.Client/Crm/Types/PaginatedIssueList.cs b/src/Merge.Client/Crm/Types/PaginatedIssueList.cs index f4ea203b..1b9f3e14 100644 --- a/src/Merge.Client/Crm/Types/PaginatedIssueList.cs +++ b/src/Merge.Client/Crm/Types/PaginatedIssueList.cs @@ -1,18 +1,17 @@ using System.Text.Json.Serialization; -using Merge.Client.Crm; #nullable enable namespace Merge.Client.Crm; -public class PaginatedIssueList +public record PaginatedIssueList { [JsonPropertyName("next")] - public string? Next { get; init; } + public string? Next { get; set; } [JsonPropertyName("previous")] - public string? Previous { get; init; } + public string? Previous { get; set; } [JsonPropertyName("results")] - public IEnumerable? Results { get; init; } + public IEnumerable? Results { get; set; } } diff --git a/src/Merge.Client/Crm/Types/PaginatedLeadList.cs b/src/Merge.Client/Crm/Types/PaginatedLeadList.cs index 7c9080c3..cdd3ec9b 100644 --- a/src/Merge.Client/Crm/Types/PaginatedLeadList.cs +++ b/src/Merge.Client/Crm/Types/PaginatedLeadList.cs @@ -1,18 +1,17 @@ using System.Text.Json.Serialization; -using Merge.Client.Crm; #nullable enable namespace Merge.Client.Crm; -public class PaginatedLeadList +public record PaginatedLeadList { [JsonPropertyName("next")] - public string? Next { get; init; } + public string? Next { get; set; } [JsonPropertyName("previous")] - public string? Previous { get; init; } + public string? Previous { get; set; } [JsonPropertyName("results")] - public IEnumerable? Results { get; init; } + public IEnumerable? Results { get; set; } } diff --git a/src/Merge.Client/Crm/Types/PaginatedNoteList.cs b/src/Merge.Client/Crm/Types/PaginatedNoteList.cs index a4a1081d..5b017ad3 100644 --- a/src/Merge.Client/Crm/Types/PaginatedNoteList.cs +++ b/src/Merge.Client/Crm/Types/PaginatedNoteList.cs @@ -1,18 +1,17 @@ using System.Text.Json.Serialization; -using Merge.Client.Crm; #nullable enable namespace Merge.Client.Crm; -public class PaginatedNoteList +public record PaginatedNoteList { [JsonPropertyName("next")] - public string? Next { get; init; } + public string? Next { get; set; } [JsonPropertyName("previous")] - public string? Previous { get; init; } + public string? Previous { get; set; } [JsonPropertyName("results")] - public IEnumerable? Results { get; init; } + public IEnumerable? Results { get; set; } } diff --git a/src/Merge.Client/Crm/Types/PaginatedOpportunityList.cs b/src/Merge.Client/Crm/Types/PaginatedOpportunityList.cs index 84c23c1a..0ad371f4 100644 --- a/src/Merge.Client/Crm/Types/PaginatedOpportunityList.cs +++ b/src/Merge.Client/Crm/Types/PaginatedOpportunityList.cs @@ -1,18 +1,17 @@ using System.Text.Json.Serialization; -using Merge.Client.Crm; #nullable enable namespace Merge.Client.Crm; -public class PaginatedOpportunityList +public record PaginatedOpportunityList { [JsonPropertyName("next")] - public string? Next { get; init; } + public string? Next { get; set; } [JsonPropertyName("previous")] - public string? Previous { get; init; } + public string? Previous { get; set; } [JsonPropertyName("results")] - public IEnumerable? Results { get; init; } + public IEnumerable? Results { get; set; } } diff --git a/src/Merge.Client/Crm/Types/PaginatedRemoteFieldClassList.cs b/src/Merge.Client/Crm/Types/PaginatedRemoteFieldClassList.cs index 0ddb87a1..b0a56d13 100644 --- a/src/Merge.Client/Crm/Types/PaginatedRemoteFieldClassList.cs +++ b/src/Merge.Client/Crm/Types/PaginatedRemoteFieldClassList.cs @@ -1,18 +1,17 @@ using System.Text.Json.Serialization; -using Merge.Client.Crm; #nullable enable namespace Merge.Client.Crm; -public class PaginatedRemoteFieldClassList +public record PaginatedRemoteFieldClassList { [JsonPropertyName("next")] - public string? Next { get; init; } + public string? Next { get; set; } [JsonPropertyName("previous")] - public string? Previous { get; init; } + public string? Previous { get; set; } [JsonPropertyName("results")] - public IEnumerable? Results { get; init; } + public IEnumerable? Results { get; set; } } diff --git a/src/Merge.Client/Crm/Types/PaginatedStageList.cs b/src/Merge.Client/Crm/Types/PaginatedStageList.cs index f3674ac0..c99390a2 100644 --- a/src/Merge.Client/Crm/Types/PaginatedStageList.cs +++ b/src/Merge.Client/Crm/Types/PaginatedStageList.cs @@ -1,18 +1,17 @@ using System.Text.Json.Serialization; -using Merge.Client.Crm; #nullable enable namespace Merge.Client.Crm; -public class PaginatedStageList +public record PaginatedStageList { [JsonPropertyName("next")] - public string? Next { get; init; } + public string? Next { get; set; } [JsonPropertyName("previous")] - public string? Previous { get; init; } + public string? Previous { get; set; } [JsonPropertyName("results")] - public IEnumerable? Results { get; init; } + public IEnumerable? Results { get; set; } } diff --git a/src/Merge.Client/Crm/Types/PaginatedSyncStatusList.cs b/src/Merge.Client/Crm/Types/PaginatedSyncStatusList.cs index 3c5d73c4..4832ecc0 100644 --- a/src/Merge.Client/Crm/Types/PaginatedSyncStatusList.cs +++ b/src/Merge.Client/Crm/Types/PaginatedSyncStatusList.cs @@ -1,18 +1,17 @@ using System.Text.Json.Serialization; -using Merge.Client.Crm; #nullable enable namespace Merge.Client.Crm; -public class PaginatedSyncStatusList +public record PaginatedSyncStatusList { [JsonPropertyName("next")] - public string? Next { get; init; } + public string? Next { get; set; } [JsonPropertyName("previous")] - public string? Previous { get; init; } + public string? Previous { get; set; } [JsonPropertyName("results")] - public IEnumerable? Results { get; init; } + public IEnumerable? Results { get; set; } } diff --git a/src/Merge.Client/Crm/Types/PaginatedTaskList.cs b/src/Merge.Client/Crm/Types/PaginatedTaskList.cs index f13e9b29..f295a5af 100644 --- a/src/Merge.Client/Crm/Types/PaginatedTaskList.cs +++ b/src/Merge.Client/Crm/Types/PaginatedTaskList.cs @@ -1,18 +1,17 @@ using System.Text.Json.Serialization; -using Merge.Client.Crm; #nullable enable namespace Merge.Client.Crm; -public class PaginatedTaskList +public record PaginatedTaskList { [JsonPropertyName("next")] - public string? Next { get; init; } + public string? Next { get; set; } [JsonPropertyName("previous")] - public string? Previous { get; init; } + public string? Previous { get; set; } [JsonPropertyName("results")] - public IEnumerable? Results { get; init; } + public IEnumerable? Results { get; set; } } diff --git a/src/Merge.Client/Crm/Types/PaginatedUserList.cs b/src/Merge.Client/Crm/Types/PaginatedUserList.cs index afff304e..f408bde7 100644 --- a/src/Merge.Client/Crm/Types/PaginatedUserList.cs +++ b/src/Merge.Client/Crm/Types/PaginatedUserList.cs @@ -1,18 +1,17 @@ using System.Text.Json.Serialization; -using Merge.Client.Crm; #nullable enable namespace Merge.Client.Crm; -public class PaginatedUserList +public record PaginatedUserList { [JsonPropertyName("next")] - public string? Next { get; init; } + public string? Next { get; set; } [JsonPropertyName("previous")] - public string? Previous { get; init; } + public string? Previous { get; set; } [JsonPropertyName("results")] - public IEnumerable? Results { get; init; } + public IEnumerable? Results { get; set; } } diff --git a/src/Merge.Client/Crm/Types/PatchedAccountRequest.cs b/src/Merge.Client/Crm/Types/PatchedAccountRequest.cs index a3a382a2..dc67ed34 100644 --- a/src/Merge.Client/Crm/Types/PatchedAccountRequest.cs +++ b/src/Merge.Client/Crm/Types/PatchedAccountRequest.cs @@ -1,63 +1,62 @@ using System.Text.Json.Serialization; -using Merge.Client.Crm; #nullable enable namespace Merge.Client.Crm; -public class PatchedAccountRequest +public record PatchedAccountRequest { /// /// The account's owner. /// [JsonPropertyName("owner")] - public string? Owner { get; init; } + public string? Owner { get; set; } /// /// The account's name. /// [JsonPropertyName("name")] - public string? Name { get; init; } + public string? Name { get; set; } /// /// The account's description. /// [JsonPropertyName("description")] - public string? Description { get; init; } + public string? Description { get; set; } /// /// The account's industry. /// [JsonPropertyName("industry")] - public string? Industry { get; init; } + public string? Industry { get; set; } /// /// The account's website. /// [JsonPropertyName("website")] - public string? Website { get; init; } + public string? Website { get; set; } /// /// The account's number of employees. /// [JsonPropertyName("number_of_employees")] - public int? NumberOfEmployees { get; init; } + public int? NumberOfEmployees { get; set; } [JsonPropertyName("addresses")] - public IEnumerable? Addresses { get; init; } + public IEnumerable? Addresses { get; set; } /// /// The last date (either most recent or furthest in the future) of when an activity occurs in an account. /// [JsonPropertyName("last_activity_at")] - public DateTime? LastActivityAt { get; init; } + public DateTime? LastActivityAt { get; set; } [JsonPropertyName("integration_params")] - public Dictionary? IntegrationParams { get; init; } + public Dictionary? IntegrationParams { get; set; } [JsonPropertyName("linked_account_params")] - public Dictionary? LinkedAccountParams { get; init; } + public Dictionary? LinkedAccountParams { get; set; } [JsonPropertyName("remote_fields")] - public IEnumerable? RemoteFields { get; init; } + public IEnumerable? RemoteFields { get; set; } } diff --git a/src/Merge.Client/Crm/Types/PatchedContactRequest.cs b/src/Merge.Client/Crm/Types/PatchedContactRequest.cs index daac940c..21573011 100644 --- a/src/Merge.Client/Crm/Types/PatchedContactRequest.cs +++ b/src/Merge.Client/Crm/Types/PatchedContactRequest.cs @@ -1,60 +1,59 @@ using System.Text.Json.Serialization; using Merge.Client.Core; -using Merge.Client.Crm; using OneOf; #nullable enable namespace Merge.Client.Crm; -public class PatchedContactRequest +public record PatchedContactRequest { /// /// The contact's first name. /// [JsonPropertyName("first_name")] - public string? FirstName { get; init; } + public string? FirstName { get; set; } /// /// The contact's last name. /// [JsonPropertyName("last_name")] - public string? LastName { get; init; } + public string? LastName { get; set; } /// /// The contact's account. /// [JsonPropertyName("account")] - public string? Account { get; init; } + public string? Account { get; set; } /// /// The contact's owner. /// [JsonPropertyName("owner")] [JsonConverter(typeof(OneOfSerializer>))] - public OneOf? Owner { get; init; } + public OneOf? Owner { get; set; } [JsonPropertyName("addresses")] - public IEnumerable? Addresses { get; init; } + public IEnumerable? Addresses { get; set; } [JsonPropertyName("email_addresses")] - public IEnumerable? EmailAddresses { get; init; } + public IEnumerable? EmailAddresses { get; set; } [JsonPropertyName("phone_numbers")] - public IEnumerable? PhoneNumbers { get; init; } + public IEnumerable? PhoneNumbers { get; set; } /// /// When the contact's last activity occurred. /// [JsonPropertyName("last_activity_at")] - public DateTime? LastActivityAt { get; init; } + public DateTime? LastActivityAt { get; set; } [JsonPropertyName("integration_params")] - public Dictionary? IntegrationParams { get; init; } + public Dictionary? IntegrationParams { get; set; } [JsonPropertyName("linked_account_params")] - public Dictionary? LinkedAccountParams { get; init; } + public Dictionary? LinkedAccountParams { get; set; } [JsonPropertyName("remote_fields")] - public IEnumerable? RemoteFields { get; init; } + public IEnumerable? RemoteFields { get; set; } } diff --git a/src/Merge.Client/Crm/Types/PatchedEngagementRequest.cs b/src/Merge.Client/Crm/Types/PatchedEngagementRequest.cs index 6033c796..81325df7 100644 --- a/src/Merge.Client/Crm/Types/PatchedEngagementRequest.cs +++ b/src/Merge.Client/Crm/Types/PatchedEngagementRequest.cs @@ -1,29 +1,28 @@ using System.Text.Json.Serialization; -using Merge.Client.Crm; #nullable enable namespace Merge.Client.Crm; -public class PatchedEngagementRequest +public record PatchedEngagementRequest { /// /// The engagement's owner. /// [JsonPropertyName("owner")] - public string? Owner { get; init; } + public string? Owner { get; set; } /// /// The engagement's content. /// [JsonPropertyName("content")] - public string? Content { get; init; } + public string? Content { get; set; } /// /// The engagement's subject. /// [JsonPropertyName("subject")] - public string? Subject { get; init; } + public string? Subject { get; set; } /// /// The engagement's direction. @@ -32,41 +31,41 @@ public class PatchedEngagementRequest /// - `OUTBOUND` - OUTBOUND /// [JsonPropertyName("direction")] - public DirectionEnum? Direction { get; init; } + public DirectionEnum? Direction { get; set; } /// /// The engagement type of the engagement. /// [JsonPropertyName("engagement_type")] - public string? EngagementType { get; init; } + public string? EngagementType { get; set; } /// /// The time at which the engagement started. /// [JsonPropertyName("start_time")] - public DateTime? StartTime { get; init; } + public DateTime? StartTime { get; set; } /// /// The time at which the engagement ended. /// [JsonPropertyName("end_time")] - public DateTime? EndTime { get; init; } + public DateTime? EndTime { get; set; } /// /// The account of the engagement. /// [JsonPropertyName("account")] - public string? Account { get; init; } + public string? Account { get; set; } [JsonPropertyName("contacts")] - public IEnumerable? Contacts { get; init; } + public IEnumerable? Contacts { get; set; } [JsonPropertyName("integration_params")] - public Dictionary? IntegrationParams { get; init; } + public Dictionary? IntegrationParams { get; set; } [JsonPropertyName("linked_account_params")] - public Dictionary? LinkedAccountParams { get; init; } + public Dictionary? LinkedAccountParams { get; set; } [JsonPropertyName("remote_fields")] - public IEnumerable? RemoteFields { get; init; } + public IEnumerable? RemoteFields { get; set; } } diff --git a/src/Merge.Client/Crm/Types/PatchedOpportunityRequest.cs b/src/Merge.Client/Crm/Types/PatchedOpportunityRequest.cs index 58b59ea4..349513eb 100644 --- a/src/Merge.Client/Crm/Types/PatchedOpportunityRequest.cs +++ b/src/Merge.Client/Crm/Types/PatchedOpportunityRequest.cs @@ -1,47 +1,46 @@ using System.Text.Json.Serialization; -using Merge.Client.Crm; #nullable enable namespace Merge.Client.Crm; -public class PatchedOpportunityRequest +public record PatchedOpportunityRequest { /// /// The opportunity's name. /// [JsonPropertyName("name")] - public string? Name { get; init; } + public string? Name { get; set; } /// /// The opportunity's description. /// [JsonPropertyName("description")] - public string? Description { get; init; } + public string? Description { get; set; } /// /// The opportunity's amount. /// [JsonPropertyName("amount")] - public int? Amount { get; init; } + public int? Amount { get; set; } /// /// The opportunity's owner. /// [JsonPropertyName("owner")] - public string? Owner { get; init; } + public string? Owner { get; set; } /// /// The account of the opportunity. /// [JsonPropertyName("account")] - public string? Account { get; init; } + public string? Account { get; set; } /// /// The stage of the opportunity. /// [JsonPropertyName("stage")] - public string? Stage { get; init; } + public string? Stage { get; set; } /// /// The opportunity's status. @@ -51,26 +50,26 @@ public class PatchedOpportunityRequest /// - `LOST` - LOST /// [JsonPropertyName("status")] - public OpportunityStatusEnum? Status { get; init; } + public OpportunityStatusEnum? Status { get; set; } /// /// When the opportunity's last activity occurred. /// [JsonPropertyName("last_activity_at")] - public DateTime? LastActivityAt { get; init; } + public DateTime? LastActivityAt { get; set; } /// /// When the opportunity was closed. /// [JsonPropertyName("close_date")] - public DateTime? CloseDate { get; init; } + public DateTime? CloseDate { get; set; } [JsonPropertyName("integration_params")] - public Dictionary? IntegrationParams { get; init; } + public Dictionary? IntegrationParams { get; set; } [JsonPropertyName("linked_account_params")] - public Dictionary? LinkedAccountParams { get; init; } + public Dictionary? LinkedAccountParams { get; set; } [JsonPropertyName("remote_fields")] - public IEnumerable? RemoteFields { get; init; } + public IEnumerable? RemoteFields { get; set; } } diff --git a/src/Merge.Client/Crm/Types/PatchedTaskRequest.cs b/src/Merge.Client/Crm/Types/PatchedTaskRequest.cs index 7adfdd9d..c8811475 100644 --- a/src/Merge.Client/Crm/Types/PatchedTaskRequest.cs +++ b/src/Merge.Client/Crm/Types/PatchedTaskRequest.cs @@ -1,53 +1,52 @@ using System.Text.Json.Serialization; -using Merge.Client.Crm; #nullable enable namespace Merge.Client.Crm; -public class PatchedTaskRequest +public record PatchedTaskRequest { /// /// The task's subject. /// [JsonPropertyName("subject")] - public string? Subject { get; init; } + public string? Subject { get; set; } /// /// The task's content. /// [JsonPropertyName("content")] - public string? Content { get; init; } + public string? Content { get; set; } /// /// The task's owner. /// [JsonPropertyName("owner")] - public string? Owner { get; init; } + public string? Owner { get; set; } /// /// The task's account. /// [JsonPropertyName("account")] - public string? Account { get; init; } + public string? Account { get; set; } /// /// The task's opportunity. /// [JsonPropertyName("opportunity")] - public string? Opportunity { get; init; } + public string? Opportunity { get; set; } /// /// When the task is completed. /// [JsonPropertyName("completed_date")] - public DateTime? CompletedDate { get; init; } + public DateTime? CompletedDate { get; set; } /// /// When the task is due. /// [JsonPropertyName("due_date")] - public DateTime? DueDate { get; init; } + public DateTime? DueDate { get; set; } /// /// The task's status. @@ -56,14 +55,14 @@ public class PatchedTaskRequest /// - `CLOSED` - CLOSED /// [JsonPropertyName("status")] - public TaskStatusEnum? Status { get; init; } + public TaskStatusEnum? Status { get; set; } [JsonPropertyName("integration_params")] - public Dictionary? IntegrationParams { get; init; } + public Dictionary? IntegrationParams { get; set; } [JsonPropertyName("linked_account_params")] - public Dictionary? LinkedAccountParams { get; init; } + public Dictionary? LinkedAccountParams { get; set; } [JsonPropertyName("remote_fields")] - public IEnumerable? RemoteFields { get; init; } + public IEnumerable? RemoteFields { get; set; } } diff --git a/src/Merge.Client/Crm/Types/PhoneNumber.cs b/src/Merge.Client/Crm/Types/PhoneNumber.cs index 02a1cf43..0ee2ef8a 100644 --- a/src/Merge.Client/Crm/Types/PhoneNumber.cs +++ b/src/Merge.Client/Crm/Types/PhoneNumber.cs @@ -4,29 +4,29 @@ namespace Merge.Client.Crm; -public class PhoneNumber +public record PhoneNumber { /// /// The datetime that this object was created by Merge. /// [JsonPropertyName("created_at")] - public DateTime? CreatedAt { get; init; } + public DateTime? CreatedAt { get; set; } /// /// The datetime that this object was modified by Merge. /// [JsonPropertyName("modified_at")] - public DateTime? ModifiedAt { get; init; } + public DateTime? ModifiedAt { get; set; } /// /// The phone number. /// [JsonPropertyName("phone_number")] - public string? PhoneNumber_ { get; init; } + public string? PhoneNumber_ { get; set; } /// /// The phone number's type. /// [JsonPropertyName("phone_number_type")] - public string? PhoneNumberType { get; init; } + public string? PhoneNumberType { get; set; } } diff --git a/src/Merge.Client/Crm/Types/PhoneNumberRequest.cs b/src/Merge.Client/Crm/Types/PhoneNumberRequest.cs index f3611c8a..edfd0b31 100644 --- a/src/Merge.Client/Crm/Types/PhoneNumberRequest.cs +++ b/src/Merge.Client/Crm/Types/PhoneNumberRequest.cs @@ -4,23 +4,23 @@ namespace Merge.Client.Crm; -public class PhoneNumberRequest +public record PhoneNumberRequest { /// /// The phone number. /// [JsonPropertyName("phone_number")] - public string? PhoneNumber { get; init; } + public string? PhoneNumber { get; set; } /// /// The phone number's type. /// [JsonPropertyName("phone_number_type")] - public string? PhoneNumberType { get; init; } + public string? PhoneNumberType { get; set; } [JsonPropertyName("integration_params")] - public Dictionary? IntegrationParams { get; init; } + public Dictionary? IntegrationParams { get; set; } [JsonPropertyName("linked_account_params")] - public Dictionary? LinkedAccountParams { get; init; } + public Dictionary? LinkedAccountParams { get; set; } } diff --git a/src/Merge.Client/Crm/Types/ReasonEnum.cs b/src/Merge.Client/Crm/Types/ReasonEnum.cs index 73cd4bd6..1f506263 100644 --- a/src/Merge.Client/Crm/Types/ReasonEnum.cs +++ b/src/Merge.Client/Crm/Types/ReasonEnum.cs @@ -1,7 +1,6 @@ using System.Runtime.Serialization; using System.Text.Json.Serialization; using Merge.Client.Core; -using Merge.Client.Crm; #nullable enable diff --git a/src/Merge.Client/Crm/Types/RemoteData.cs b/src/Merge.Client/Crm/Types/RemoteData.cs index 1558716c..e85cacd9 100644 --- a/src/Merge.Client/Crm/Types/RemoteData.cs +++ b/src/Merge.Client/Crm/Types/RemoteData.cs @@ -4,11 +4,11 @@ namespace Merge.Client.Crm; -public class RemoteData +public record RemoteData { [JsonPropertyName("path")] - public string Path { get; init; } + public required string Path { get; set; } [JsonPropertyName("data")] - public object? Data { get; init; } + public object? Data { get; set; } } diff --git a/src/Merge.Client/Crm/Types/RemoteEndpointInfo.cs b/src/Merge.Client/Crm/Types/RemoteEndpointInfo.cs index 8229c95e..9a0fb9bb 100644 --- a/src/Merge.Client/Crm/Types/RemoteEndpointInfo.cs +++ b/src/Merge.Client/Crm/Types/RemoteEndpointInfo.cs @@ -4,14 +4,14 @@ namespace Merge.Client.Crm; -public class RemoteEndpointInfo +public record RemoteEndpointInfo { [JsonPropertyName("method")] - public string Method { get; init; } + public required string Method { get; set; } [JsonPropertyName("url_path")] - public string UrlPath { get; init; } + public required string UrlPath { get; set; } [JsonPropertyName("field_traversal_path")] - public IEnumerable FieldTraversalPath { get; init; } + public IEnumerable FieldTraversalPath { get; set; } = new List(); } diff --git a/src/Merge.Client/Crm/Types/RemoteField.cs b/src/Merge.Client/Crm/Types/RemoteField.cs index 042a6f47..9edaf95c 100644 --- a/src/Merge.Client/Crm/Types/RemoteField.cs +++ b/src/Merge.Client/Crm/Types/RemoteField.cs @@ -1,18 +1,17 @@ using System.Text.Json.Serialization; using Merge.Client.Core; -using Merge.Client.Crm; using OneOf; #nullable enable namespace Merge.Client.Crm; -public class RemoteField +public record RemoteField { [JsonPropertyName("remote_field_class")] [JsonConverter(typeof(OneOfSerializer>))] - public OneOf RemoteFieldClass { get; init; } + public required OneOf RemoteFieldClass { get; set; } [JsonPropertyName("value")] - public object? Value { get; init; } + public object? Value { get; set; } } diff --git a/src/Merge.Client/Crm/Types/RemoteFieldApi.cs b/src/Merge.Client/Crm/Types/RemoteFieldApi.cs index a2907ce4..93587405 100644 --- a/src/Merge.Client/Crm/Types/RemoteFieldApi.cs +++ b/src/Merge.Client/Crm/Types/RemoteFieldApi.cs @@ -1,30 +1,29 @@ using System.Text.Json.Serialization; using Merge.Client.Core; -using Merge.Client.Crm; using OneOf; #nullable enable namespace Merge.Client.Crm; -public class RemoteFieldApi +public record RemoteFieldApi { [JsonPropertyName("schema")] - public Dictionary Schema { get; init; } + public Dictionary Schema { get; set; } = new Dictionary(); [JsonPropertyName("remote_key_name")] - public string RemoteKeyName { get; init; } + public required string RemoteKeyName { get; set; } [JsonPropertyName("remote_endpoint_info")] - public RemoteEndpointInfo RemoteEndpointInfo { get; init; } + public required RemoteEndpointInfo RemoteEndpointInfo { get; set; } [JsonPropertyName("example_values")] - public IEnumerable? ExampleValues { get; init; } + public IEnumerable? ExampleValues { get; set; } [JsonPropertyName("advanced_metadata")] - public AdvancedMetadata? AdvancedMetadata { get; init; } + public AdvancedMetadata? AdvancedMetadata { get; set; } [JsonPropertyName("coverage")] [JsonConverter(typeof(OneOfSerializer>))] - public OneOf? Coverage { get; init; } + public OneOf? Coverage { get; set; } } diff --git a/src/Merge.Client/Crm/Types/RemoteFieldApiResponse.cs b/src/Merge.Client/Crm/Types/RemoteFieldApiResponse.cs index f6cb5fce..a3e6c4cc 100644 --- a/src/Merge.Client/Crm/Types/RemoteFieldApiResponse.cs +++ b/src/Merge.Client/Crm/Types/RemoteFieldApiResponse.cs @@ -1,36 +1,35 @@ using System.Text.Json.Serialization; -using Merge.Client.Crm; #nullable enable namespace Merge.Client.Crm; -public class RemoteFieldApiResponse +public record RemoteFieldApiResponse { [JsonPropertyName("Account")] - public IEnumerable? Account { get; init; } + public IEnumerable? Account { get; set; } [JsonPropertyName("Contact")] - public IEnumerable? Contact { get; init; } + public IEnumerable? Contact { get; set; } [JsonPropertyName("Lead")] - public IEnumerable? Lead { get; init; } + public IEnumerable? Lead { get; set; } [JsonPropertyName("Note")] - public IEnumerable? Note { get; init; } + public IEnumerable? Note { get; set; } [JsonPropertyName("Opportunity")] - public IEnumerable? Opportunity { get; init; } + public IEnumerable? Opportunity { get; set; } [JsonPropertyName("Stage")] - public IEnumerable? Stage { get; init; } + public IEnumerable? Stage { get; set; } [JsonPropertyName("User")] - public IEnumerable? User { get; init; } + public IEnumerable? User { get; set; } [JsonPropertyName("Task")] - public IEnumerable? Task { get; init; } + public IEnumerable? Task { get; set; } [JsonPropertyName("Engagement")] - public IEnumerable? Engagement { get; init; } + public IEnumerable? Engagement { get; set; } } diff --git a/src/Merge.Client/Crm/Types/RemoteFieldClass.cs b/src/Merge.Client/Crm/Types/RemoteFieldClass.cs index 9319b037..9fc50fbb 100644 --- a/src/Merge.Client/Crm/Types/RemoteFieldClass.cs +++ b/src/Merge.Client/Crm/Types/RemoteFieldClass.cs @@ -1,39 +1,38 @@ using System.Text.Json.Serialization; -using Merge.Client.Crm; #nullable enable namespace Merge.Client.Crm; -public class RemoteFieldClass +public record RemoteFieldClass { [JsonPropertyName("id")] - public string? Id { get; init; } + public string? Id { get; set; } [JsonPropertyName("display_name")] - public string? DisplayName { get; init; } + public string? DisplayName { get; set; } [JsonPropertyName("remote_key_name")] - public string? RemoteKeyName { get; init; } + public string? RemoteKeyName { get; set; } [JsonPropertyName("description")] - public string? Description { get; init; } + public string? Description { get; set; } [JsonPropertyName("is_custom")] - public bool? IsCustom { get; init; } + public bool? IsCustom { get; set; } [JsonPropertyName("is_required")] - public bool? IsRequired { get; init; } + public bool? IsRequired { get; set; } [JsonPropertyName("field_type")] - public FieldTypeEnum? FieldType { get; init; } + public FieldTypeEnum? FieldType { get; set; } [JsonPropertyName("field_format")] - public FieldFormatEnum? FieldFormat { get; init; } + public FieldFormatEnum? FieldFormat { get; set; } [JsonPropertyName("field_choices")] - public IEnumerable? FieldChoices { get; init; } + public IEnumerable? FieldChoices { get; set; } [JsonPropertyName("item_schema")] - public ItemSchema? ItemSchema { get; init; } + public ItemSchema? ItemSchema { get; set; } } diff --git a/src/Merge.Client/Crm/Types/RemoteFieldClassFieldChoicesItem.cs b/src/Merge.Client/Crm/Types/RemoteFieldClassFieldChoicesItem.cs index a8dedc0d..b4481d1e 100644 --- a/src/Merge.Client/Crm/Types/RemoteFieldClassFieldChoicesItem.cs +++ b/src/Merge.Client/Crm/Types/RemoteFieldClassFieldChoicesItem.cs @@ -4,11 +4,11 @@ namespace Merge.Client.Crm; -public class RemoteFieldClassFieldChoicesItem +public record RemoteFieldClassFieldChoicesItem { [JsonPropertyName("value")] - public object? Value { get; init; } + public object? Value { get; set; } [JsonPropertyName("display_name")] - public string? DisplayName { get; init; } + public string? DisplayName { get; set; } } diff --git a/src/Merge.Client/Crm/Types/RemoteFieldClassForCustomObjectClass.cs b/src/Merge.Client/Crm/Types/RemoteFieldClassForCustomObjectClass.cs index 7d27904c..0a90935e 100644 --- a/src/Merge.Client/Crm/Types/RemoteFieldClassForCustomObjectClass.cs +++ b/src/Merge.Client/Crm/Types/RemoteFieldClassForCustomObjectClass.cs @@ -1,45 +1,44 @@ using System.Text.Json.Serialization; -using Merge.Client.Crm; #nullable enable namespace Merge.Client.Crm; -public class RemoteFieldClassForCustomObjectClass +public record RemoteFieldClassForCustomObjectClass { /// /// The datetime that this object was created by Merge. /// [JsonPropertyName("created_at")] - public DateTime? CreatedAt { get; init; } + public DateTime? CreatedAt { get; set; } /// /// The datetime that this object was modified by Merge. /// [JsonPropertyName("modified_at")] - public DateTime? ModifiedAt { get; init; } + public DateTime? ModifiedAt { get; set; } [JsonPropertyName("display_name")] - public string? DisplayName { get; init; } + public string? DisplayName { get; set; } [JsonPropertyName("remote_key_name")] - public string? RemoteKeyName { get; init; } + public string? RemoteKeyName { get; set; } [JsonPropertyName("description")] - public string? Description { get; init; } + public string? Description { get; set; } [JsonPropertyName("is_required")] - public bool? IsRequired { get; init; } + public bool? IsRequired { get; set; } [JsonPropertyName("field_type")] - public FieldTypeEnum? FieldType { get; init; } + public FieldTypeEnum? FieldType { get; set; } [JsonPropertyName("field_format")] - public FieldFormatEnum? FieldFormat { get; init; } + public FieldFormatEnum? FieldFormat { get; set; } [JsonPropertyName("field_choices")] - public IEnumerable? FieldChoices { get; init; } + public IEnumerable? FieldChoices { get; set; } [JsonPropertyName("item_schema")] - public RemoteFieldClassForCustomObjectClassItemSchema? ItemSchema { get; init; } + public RemoteFieldClassForCustomObjectClassItemSchema? ItemSchema { get; set; } } diff --git a/src/Merge.Client/Crm/Types/RemoteFieldClassForCustomObjectClassFieldChoicesItem.cs b/src/Merge.Client/Crm/Types/RemoteFieldClassForCustomObjectClassFieldChoicesItem.cs index 4051bfea..71aeda7f 100644 --- a/src/Merge.Client/Crm/Types/RemoteFieldClassForCustomObjectClassFieldChoicesItem.cs +++ b/src/Merge.Client/Crm/Types/RemoteFieldClassForCustomObjectClassFieldChoicesItem.cs @@ -4,11 +4,11 @@ namespace Merge.Client.Crm; -public class RemoteFieldClassForCustomObjectClassFieldChoicesItem +public record RemoteFieldClassForCustomObjectClassFieldChoicesItem { [JsonPropertyName("value")] - public object? Value { get; init; } + public object? Value { get; set; } [JsonPropertyName("display_name")] - public string? DisplayName { get; init; } + public string? DisplayName { get; set; } } diff --git a/src/Merge.Client/Crm/Types/RemoteFieldClassForCustomObjectClassItemSchema.cs b/src/Merge.Client/Crm/Types/RemoteFieldClassForCustomObjectClassItemSchema.cs index f7d35646..7daf0a75 100644 --- a/src/Merge.Client/Crm/Types/RemoteFieldClassForCustomObjectClassItemSchema.cs +++ b/src/Merge.Client/Crm/Types/RemoteFieldClassForCustomObjectClassItemSchema.cs @@ -4,14 +4,14 @@ namespace Merge.Client.Crm; -public class RemoteFieldClassForCustomObjectClassItemSchema +public record RemoteFieldClassForCustomObjectClassItemSchema { [JsonPropertyName("item_type")] - public string? ItemType { get; init; } + public string? ItemType { get; set; } [JsonPropertyName("item_format")] - public string? ItemFormat { get; init; } + public string? ItemFormat { get; set; } [JsonPropertyName("item_choices")] - public IEnumerable? ItemChoices { get; init; } + public IEnumerable? ItemChoices { get; set; } } diff --git a/src/Merge.Client/Crm/Types/RemoteFieldRequest.cs b/src/Merge.Client/Crm/Types/RemoteFieldRequest.cs index c881ac93..285f21ce 100644 --- a/src/Merge.Client/Crm/Types/RemoteFieldRequest.cs +++ b/src/Merge.Client/Crm/Types/RemoteFieldRequest.cs @@ -1,18 +1,17 @@ using System.Text.Json.Serialization; using Merge.Client.Core; -using Merge.Client.Crm; using OneOf; #nullable enable namespace Merge.Client.Crm; -public class RemoteFieldRequest +public record RemoteFieldRequest { [JsonPropertyName("remote_field_class")] [JsonConverter(typeof(OneOfSerializer>))] - public OneOf RemoteFieldClass { get; init; } + public required OneOf RemoteFieldClass { get; set; } [JsonPropertyName("value")] - public object? Value { get; init; } + public object? Value { get; set; } } diff --git a/src/Merge.Client/Crm/Types/RemoteKey.cs b/src/Merge.Client/Crm/Types/RemoteKey.cs index 1324474e..6fc5e63b 100644 --- a/src/Merge.Client/Crm/Types/RemoteKey.cs +++ b/src/Merge.Client/Crm/Types/RemoteKey.cs @@ -4,11 +4,11 @@ namespace Merge.Client.Crm; -public class RemoteKey +public record RemoteKey { [JsonPropertyName("name")] - public string Name { get; init; } + public required string Name { get; set; } [JsonPropertyName("key")] - public string Key { get; init; } + public required string Key { get; set; } } diff --git a/src/Merge.Client/Crm/Types/RemoteResponse.cs b/src/Merge.Client/Crm/Types/RemoteResponse.cs index 4fd68ed8..b9154fe5 100644 --- a/src/Merge.Client/Crm/Types/RemoteResponse.cs +++ b/src/Merge.Client/Crm/Types/RemoteResponse.cs @@ -1,30 +1,29 @@ using System.Text.Json.Serialization; -using Merge.Client.Crm; #nullable enable namespace Merge.Client.Crm; -public class RemoteResponse +public record RemoteResponse { [JsonPropertyName("method")] - public string Method { get; init; } + public required string Method { get; set; } [JsonPropertyName("path")] - public string Path { get; init; } + public required string Path { get; set; } [JsonPropertyName("status")] - public int Status { get; init; } + public required int Status { get; set; } [JsonPropertyName("response")] - public object Response { get; init; } + public required object Response { get; set; } [JsonPropertyName("response_headers")] - public Dictionary? ResponseHeaders { get; init; } + public Dictionary? ResponseHeaders { get; set; } [JsonPropertyName("response_type")] - public ResponseTypeEnum? ResponseType { get; init; } + public ResponseTypeEnum? ResponseType { get; set; } [JsonPropertyName("headers")] - public Dictionary? Headers { get; init; } + public Dictionary? Headers { get; set; } } diff --git a/src/Merge.Client/Crm/Types/RequestFormatEnum.cs b/src/Merge.Client/Crm/Types/RequestFormatEnum.cs index 7b8257f9..d727c500 100644 --- a/src/Merge.Client/Crm/Types/RequestFormatEnum.cs +++ b/src/Merge.Client/Crm/Types/RequestFormatEnum.cs @@ -1,7 +1,6 @@ using System.Runtime.Serialization; using System.Text.Json.Serialization; using Merge.Client.Core; -using Merge.Client.Crm; #nullable enable diff --git a/src/Merge.Client/Crm/Types/ResponseTypeEnum.cs b/src/Merge.Client/Crm/Types/ResponseTypeEnum.cs index 648cf80a..aa1a4d3d 100644 --- a/src/Merge.Client/Crm/Types/ResponseTypeEnum.cs +++ b/src/Merge.Client/Crm/Types/ResponseTypeEnum.cs @@ -1,7 +1,6 @@ using System.Runtime.Serialization; using System.Text.Json.Serialization; using Merge.Client.Core; -using Merge.Client.Crm; #nullable enable diff --git a/src/Merge.Client/Crm/Types/RoleEnum.cs b/src/Merge.Client/Crm/Types/RoleEnum.cs index ad07e54b..3c0b736e 100644 --- a/src/Merge.Client/Crm/Types/RoleEnum.cs +++ b/src/Merge.Client/Crm/Types/RoleEnum.cs @@ -1,7 +1,6 @@ using System.Runtime.Serialization; using System.Text.Json.Serialization; using Merge.Client.Core; -using Merge.Client.Crm; #nullable enable diff --git a/src/Merge.Client/Crm/Types/SelectiveSyncConfigurationsUsageEnum.cs b/src/Merge.Client/Crm/Types/SelectiveSyncConfigurationsUsageEnum.cs index 362a8a6b..a73d96bf 100644 --- a/src/Merge.Client/Crm/Types/SelectiveSyncConfigurationsUsageEnum.cs +++ b/src/Merge.Client/Crm/Types/SelectiveSyncConfigurationsUsageEnum.cs @@ -1,7 +1,6 @@ using System.Runtime.Serialization; using System.Text.Json.Serialization; using Merge.Client.Core; -using Merge.Client.Crm; #nullable enable diff --git a/src/Merge.Client/Crm/Types/Stage.cs b/src/Merge.Client/Crm/Types/Stage.cs index 0861c732..58d6ffc2 100644 --- a/src/Merge.Client/Crm/Types/Stage.cs +++ b/src/Merge.Client/Crm/Types/Stage.cs @@ -1,51 +1,50 @@ using System.Text.Json.Serialization; -using Merge.Client.Crm; #nullable enable namespace Merge.Client.Crm; -public class Stage +public record Stage { [JsonPropertyName("id")] - public string? Id { get; init; } + public string? Id { get; set; } /// /// The third-party API ID of the matching object. /// [JsonPropertyName("remote_id")] - public string? RemoteId { get; init; } + public string? RemoteId { get; set; } /// /// The datetime that this object was created by Merge. /// [JsonPropertyName("created_at")] - public DateTime? CreatedAt { get; init; } + public DateTime? CreatedAt { get; set; } /// /// The datetime that this object was modified by Merge. /// [JsonPropertyName("modified_at")] - public DateTime? ModifiedAt { get; init; } + public DateTime? ModifiedAt { get; set; } /// /// The stage's name. /// [JsonPropertyName("name")] - public string? Name { get; init; } + public string? Name { get; set; } /// /// Indicates whether or not this object has been deleted in the third party platform. /// [JsonPropertyName("remote_was_deleted")] - public bool? RemoteWasDeleted { get; init; } + public bool? RemoteWasDeleted { get; set; } [JsonPropertyName("field_mappings")] - public Dictionary? FieldMappings { get; init; } + public Dictionary? FieldMappings { get; set; } [JsonPropertyName("remote_data")] - public IEnumerable? RemoteData { get; init; } + public IEnumerable? RemoteData { get; set; } [JsonPropertyName("remote_fields")] - public IEnumerable? RemoteFields { get; init; } + public IEnumerable? RemoteFields { get; set; } } diff --git a/src/Merge.Client/Crm/Types/SyncStatus.cs b/src/Merge.Client/Crm/Types/SyncStatus.cs index 2f803c1e..b84a5d66 100644 --- a/src/Merge.Client/Crm/Types/SyncStatus.cs +++ b/src/Merge.Client/Crm/Types/SyncStatus.cs @@ -1,30 +1,29 @@ using System.Text.Json.Serialization; -using Merge.Client.Crm; #nullable enable namespace Merge.Client.Crm; -public class SyncStatus +public record SyncStatus { [JsonPropertyName("model_name")] - public string ModelName { get; init; } + public required string ModelName { get; set; } [JsonPropertyName("model_id")] - public string ModelId { get; init; } + public required string ModelId { get; set; } [JsonPropertyName("last_sync_start")] - public DateTime? LastSyncStart { get; init; } + public DateTime? LastSyncStart { get; set; } [JsonPropertyName("next_sync_start")] - public DateTime? NextSyncStart { get; init; } + public DateTime? NextSyncStart { get; set; } [JsonPropertyName("status")] - public SyncStatusStatusEnum Status { get; init; } + public required SyncStatusStatusEnum Status { get; set; } [JsonPropertyName("is_initial_sync")] - public bool IsInitialSync { get; init; } + public required bool IsInitialSync { get; set; } [JsonPropertyName("selective_sync_configurations_usage")] - public SelectiveSyncConfigurationsUsageEnum? SelectiveSyncConfigurationsUsage { get; init; } + public SelectiveSyncConfigurationsUsageEnum? SelectiveSyncConfigurationsUsage { get; set; } } diff --git a/src/Merge.Client/Crm/Types/SyncStatusStatusEnum.cs b/src/Merge.Client/Crm/Types/SyncStatusStatusEnum.cs index 9c7cb6ac..0bd30e2d 100644 --- a/src/Merge.Client/Crm/Types/SyncStatusStatusEnum.cs +++ b/src/Merge.Client/Crm/Types/SyncStatusStatusEnum.cs @@ -1,7 +1,6 @@ using System.Runtime.Serialization; using System.Text.Json.Serialization; using Merge.Client.Core; -using Merge.Client.Crm; #nullable enable diff --git a/src/Merge.Client/Crm/Types/Task.cs b/src/Merge.Client/Crm/Types/Task.cs index b15b1785..83bb52fc 100644 --- a/src/Merge.Client/Crm/Types/Task.cs +++ b/src/Merge.Client/Crm/Types/Task.cs @@ -1,79 +1,78 @@ using System.Text.Json.Serialization; using Merge.Client.Core; -using Merge.Client.Crm; using OneOf; #nullable enable namespace Merge.Client.Crm; -public class Task +public record Task { [JsonPropertyName("id")] - public string? Id { get; init; } + public string? Id { get; set; } /// /// The third-party API ID of the matching object. /// [JsonPropertyName("remote_id")] - public string? RemoteId { get; init; } + public string? RemoteId { get; set; } /// /// The datetime that this object was created by Merge. /// [JsonPropertyName("created_at")] - public DateTime? CreatedAt { get; init; } + public DateTime? CreatedAt { get; set; } /// /// The datetime that this object was modified by Merge. /// [JsonPropertyName("modified_at")] - public DateTime? ModifiedAt { get; init; } + public DateTime? ModifiedAt { get; set; } /// /// The task's subject. /// [JsonPropertyName("subject")] - public string? Subject { get; init; } + public string? Subject { get; set; } /// /// The task's content. /// [JsonPropertyName("content")] - public string? Content { get; init; } + public string? Content { get; set; } /// /// The task's owner. /// [JsonPropertyName("owner")] [JsonConverter(typeof(OneOfSerializer>))] - public OneOf? Owner { get; init; } + public OneOf? Owner { get; set; } /// /// The task's account. /// [JsonPropertyName("account")] [JsonConverter(typeof(OneOfSerializer>))] - public OneOf? Account { get; init; } + public OneOf? Account { get; set; } /// /// The task's opportunity. /// [JsonPropertyName("opportunity")] [JsonConverter(typeof(OneOfSerializer>))] - public OneOf? Opportunity { get; init; } + public OneOf? Opportunity { get; set; } /// /// When the task is completed. /// [JsonPropertyName("completed_date")] - public DateTime? CompletedDate { get; init; } + public DateTime? CompletedDate { get; set; } /// /// When the task is due. /// [JsonPropertyName("due_date")] - public DateTime? DueDate { get; init; } + public DateTime? DueDate { get; set; } /// /// The task's status. @@ -82,20 +81,20 @@ public class Task /// - `CLOSED` - CLOSED /// [JsonPropertyName("status")] - public TaskStatusEnum? Status { get; init; } + public TaskStatusEnum? Status { get; set; } /// /// Indicates whether or not this object has been deleted in the third party platform. /// [JsonPropertyName("remote_was_deleted")] - public bool? RemoteWasDeleted { get; init; } + public bool? RemoteWasDeleted { get; set; } [JsonPropertyName("field_mappings")] - public Dictionary? FieldMappings { get; init; } + public Dictionary? FieldMappings { get; set; } [JsonPropertyName("remote_data")] - public IEnumerable? RemoteData { get; init; } + public IEnumerable? RemoteData { get; set; } [JsonPropertyName("remote_fields")] - public IEnumerable? RemoteFields { get; init; } + public IEnumerable? RemoteFields { get; set; } } diff --git a/src/Merge.Client/Crm/Types/TaskRequest.cs b/src/Merge.Client/Crm/Types/TaskRequest.cs index 46b1b87c..bb0b7b50 100644 --- a/src/Merge.Client/Crm/Types/TaskRequest.cs +++ b/src/Merge.Client/Crm/Types/TaskRequest.cs @@ -1,58 +1,57 @@ using System.Text.Json.Serialization; using Merge.Client.Core; -using Merge.Client.Crm; using OneOf; #nullable enable namespace Merge.Client.Crm; -public class TaskRequest +public record TaskRequest { /// /// The task's subject. /// [JsonPropertyName("subject")] - public string? Subject { get; init; } + public string? Subject { get; set; } /// /// The task's content. /// [JsonPropertyName("content")] - public string? Content { get; init; } + public string? Content { get; set; } /// /// The task's owner. /// [JsonPropertyName("owner")] [JsonConverter(typeof(OneOfSerializer>))] - public OneOf? Owner { get; init; } + public OneOf? Owner { get; set; } /// /// The task's account. /// [JsonPropertyName("account")] [JsonConverter(typeof(OneOfSerializer>))] - public OneOf? Account { get; init; } + public OneOf? Account { get; set; } /// /// The task's opportunity. /// [JsonPropertyName("opportunity")] [JsonConverter(typeof(OneOfSerializer>))] - public OneOf? Opportunity { get; init; } + public OneOf? Opportunity { get; set; } /// /// When the task is completed. /// [JsonPropertyName("completed_date")] - public DateTime? CompletedDate { get; init; } + public DateTime? CompletedDate { get; set; } /// /// When the task is due. /// [JsonPropertyName("due_date")] - public DateTime? DueDate { get; init; } + public DateTime? DueDate { get; set; } /// /// The task's status. @@ -61,14 +60,14 @@ public class TaskRequest /// - `CLOSED` - CLOSED /// [JsonPropertyName("status")] - public TaskStatusEnum? Status { get; init; } + public TaskStatusEnum? Status { get; set; } [JsonPropertyName("integration_params")] - public Dictionary? IntegrationParams { get; init; } + public Dictionary? IntegrationParams { get; set; } [JsonPropertyName("linked_account_params")] - public Dictionary? LinkedAccountParams { get; init; } + public Dictionary? LinkedAccountParams { get; set; } [JsonPropertyName("remote_fields")] - public IEnumerable? RemoteFields { get; init; } + public IEnumerable? RemoteFields { get; set; } } diff --git a/src/Merge.Client/Crm/Types/TaskResponse.cs b/src/Merge.Client/Crm/Types/TaskResponse.cs index d167dd50..61a92498 100644 --- a/src/Merge.Client/Crm/Types/TaskResponse.cs +++ b/src/Merge.Client/Crm/Types/TaskResponse.cs @@ -1,21 +1,22 @@ using System.Text.Json.Serialization; -using Merge.Client.Crm; #nullable enable namespace Merge.Client.Crm; -public class TaskResponse +public record TaskResponse { [JsonPropertyName("model")] - public Task Model { get; init; } + public required Task Model { get; set; } [JsonPropertyName("warnings")] - public IEnumerable Warnings { get; init; } + public IEnumerable Warnings { get; set; } = + new List(); [JsonPropertyName("errors")] - public IEnumerable Errors { get; init; } + public IEnumerable Errors { get; set; } = + new List(); [JsonPropertyName("logs")] - public IEnumerable? Logs { get; init; } + public IEnumerable? Logs { get; set; } } diff --git a/src/Merge.Client/Crm/Types/TaskStatusEnum.cs b/src/Merge.Client/Crm/Types/TaskStatusEnum.cs index a6126934..c39bb7d6 100644 --- a/src/Merge.Client/Crm/Types/TaskStatusEnum.cs +++ b/src/Merge.Client/Crm/Types/TaskStatusEnum.cs @@ -1,7 +1,6 @@ using System.Runtime.Serialization; using System.Text.Json.Serialization; using Merge.Client.Core; -using Merge.Client.Crm; #nullable enable diff --git a/src/Merge.Client/Crm/Types/User.cs b/src/Merge.Client/Crm/Types/User.cs index 6a5b4abe..7240fdd2 100644 --- a/src/Merge.Client/Crm/Types/User.cs +++ b/src/Merge.Client/Crm/Types/User.cs @@ -1,63 +1,62 @@ using System.Text.Json.Serialization; -using Merge.Client.Crm; #nullable enable namespace Merge.Client.Crm; -public class User +public record User { [JsonPropertyName("id")] - public string? Id { get; init; } + public string? Id { get; set; } /// /// The third-party API ID of the matching object. /// [JsonPropertyName("remote_id")] - public string? RemoteId { get; init; } + public string? RemoteId { get; set; } /// /// The datetime that this object was created by Merge. /// [JsonPropertyName("created_at")] - public DateTime? CreatedAt { get; init; } + public DateTime? CreatedAt { get; set; } /// /// The datetime that this object was modified by Merge. /// [JsonPropertyName("modified_at")] - public DateTime? ModifiedAt { get; init; } + public DateTime? ModifiedAt { get; set; } /// /// The user's name. /// [JsonPropertyName("name")] - public string? Name { get; init; } + public string? Name { get; set; } /// /// The user's email address. /// [JsonPropertyName("email")] - public string? Email { get; init; } + public string? Email { get; set; } /// /// Whether or not the user is active. /// [JsonPropertyName("is_active")] - public bool? IsActive { get; init; } + public bool? IsActive { get; set; } /// /// Indicates whether or not this object has been deleted in the third party platform. /// [JsonPropertyName("remote_was_deleted")] - public bool? RemoteWasDeleted { get; init; } + public bool? RemoteWasDeleted { get; set; } [JsonPropertyName("field_mappings")] - public Dictionary? FieldMappings { get; init; } + public Dictionary? FieldMappings { get; set; } [JsonPropertyName("remote_data")] - public IEnumerable? RemoteData { get; init; } + public IEnumerable? RemoteData { get; set; } [JsonPropertyName("remote_fields")] - public IEnumerable? RemoteFields { get; init; } + public IEnumerable? RemoteFields { get; set; } } diff --git a/src/Merge.Client/Crm/Types/ValidationProblemSource.cs b/src/Merge.Client/Crm/Types/ValidationProblemSource.cs index 12a7b068..23cad5a2 100644 --- a/src/Merge.Client/Crm/Types/ValidationProblemSource.cs +++ b/src/Merge.Client/Crm/Types/ValidationProblemSource.cs @@ -4,8 +4,8 @@ namespace Merge.Client.Crm; -public class ValidationProblemSource +public record ValidationProblemSource { [JsonPropertyName("pointer")] - public string Pointer { get; init; } + public required string Pointer { get; set; } } diff --git a/src/Merge.Client/Crm/Types/WarningValidationProblem.cs b/src/Merge.Client/Crm/Types/WarningValidationProblem.cs index 44ded968..fba1f934 100644 --- a/src/Merge.Client/Crm/Types/WarningValidationProblem.cs +++ b/src/Merge.Client/Crm/Types/WarningValidationProblem.cs @@ -1,21 +1,20 @@ using System.Text.Json.Serialization; -using Merge.Client.Crm; #nullable enable namespace Merge.Client.Crm; -public class WarningValidationProblem +public record WarningValidationProblem { [JsonPropertyName("source")] - public ValidationProblemSource? Source { get; init; } + public ValidationProblemSource? Source { get; set; } [JsonPropertyName("title")] - public string Title { get; init; } + public required string Title { get; set; } [JsonPropertyName("detail")] - public string Detail { get; init; } + public required string Detail { get; set; } [JsonPropertyName("problem_type")] - public string ProblemType { get; init; } + public required string ProblemType { get; set; } } diff --git a/src/Merge.Client/Crm/Types/WebhookReceiver.cs b/src/Merge.Client/Crm/Types/WebhookReceiver.cs index d4a370d3..f2e9a38b 100644 --- a/src/Merge.Client/Crm/Types/WebhookReceiver.cs +++ b/src/Merge.Client/Crm/Types/WebhookReceiver.cs @@ -4,14 +4,14 @@ namespace Merge.Client.Crm; -public class WebhookReceiver +public record WebhookReceiver { [JsonPropertyName("event")] - public string Event { get; init; } + public required string Event { get; set; } [JsonPropertyName("is_active")] - public bool IsActive { get; init; } + public required bool IsActive { get; set; } [JsonPropertyName("key")] - public string? Key { get; init; } + public string? Key { get; set; } } diff --git a/src/Merge.Client/Crm/Users/Requests/UsersListRequest.cs b/src/Merge.Client/Crm/Users/Requests/UsersListRequest.cs index 0d4fe345..c9c39283 100644 --- a/src/Merge.Client/Crm/Users/Requests/UsersListRequest.cs +++ b/src/Merge.Client/Crm/Users/Requests/UsersListRequest.cs @@ -1,54 +1,54 @@ namespace Merge.Client.Crm; -public class UsersListRequest +public record UsersListRequest { /// /// If provided, will only return objects created after this datetime. /// - public DateTime? CreatedAfter { get; init; } + public DateTime? CreatedAfter { get; set; } /// /// If provided, will only return objects created before this datetime. /// - public DateTime? CreatedBefore { get; init; } + public DateTime? CreatedBefore { get; set; } /// /// The pagination cursor value. /// - public string? Cursor { get; init; } + public string? Cursor { get; set; } /// /// Whether to include data that was marked as deleted by third party webhooks. /// - public bool? IncludeDeletedData { get; init; } + public bool? IncludeDeletedData { get; set; } /// /// Whether to include the original data Merge fetched from the third-party to produce these models. /// - public bool? IncludeRemoteData { get; init; } + public bool? IncludeRemoteData { get; set; } /// /// Whether to include all remote fields, including fields that Merge did not map to common models, in a normalized format. /// - public bool? IncludeRemoteFields { get; init; } + public bool? IncludeRemoteFields { get; set; } /// /// If provided, only objects synced by Merge after this date time will be returned. /// - public DateTime? ModifiedAfter { get; init; } + public DateTime? ModifiedAfter { get; set; } /// /// If provided, only objects synced by Merge before this date time will be returned. /// - public DateTime? ModifiedBefore { get; init; } + public DateTime? ModifiedBefore { get; set; } /// /// Number of results to return per page. /// - public int? PageSize { get; init; } + public int? PageSize { get; set; } /// /// The API provider's ID for the given object. /// - public string? RemoteId { get; init; } + public string? RemoteId { get; set; } } diff --git a/src/Merge.Client/Crm/Users/Requests/UsersRemoteFieldClassesListRequest.cs b/src/Merge.Client/Crm/Users/Requests/UsersRemoteFieldClassesListRequest.cs index 360a5fff..e61e8786 100644 --- a/src/Merge.Client/Crm/Users/Requests/UsersRemoteFieldClassesListRequest.cs +++ b/src/Merge.Client/Crm/Users/Requests/UsersRemoteFieldClassesListRequest.cs @@ -1,34 +1,34 @@ namespace Merge.Client.Crm; -public class UsersRemoteFieldClassesListRequest +public record UsersRemoteFieldClassesListRequest { /// /// The pagination cursor value. /// - public string? Cursor { get; init; } + public string? Cursor { get; set; } /// /// Whether to include data that was marked as deleted by third party webhooks. /// - public bool? IncludeDeletedData { get; init; } + public bool? IncludeDeletedData { get; set; } /// /// Whether to include the original data Merge fetched from the third-party to produce these models. /// - public bool? IncludeRemoteData { get; init; } + public bool? IncludeRemoteData { get; set; } /// /// Whether to include all remote fields, including fields that Merge did not map to common models, in a normalized format. /// - public bool? IncludeRemoteFields { get; init; } + public bool? IncludeRemoteFields { get; set; } /// /// If provided, will only return remote field classes with this is_common_model_field value /// - public bool? IsCommonModelField { get; init; } + public bool? IsCommonModelField { get; set; } /// /// Number of results to return per page. /// - public int? PageSize { get; init; } + public int? PageSize { get; set; } } diff --git a/src/Merge.Client/Crm/Users/Requests/UsersRetrieveRequest.cs b/src/Merge.Client/Crm/Users/Requests/UsersRetrieveRequest.cs index df367740..e5790033 100644 --- a/src/Merge.Client/Crm/Users/Requests/UsersRetrieveRequest.cs +++ b/src/Merge.Client/Crm/Users/Requests/UsersRetrieveRequest.cs @@ -1,14 +1,14 @@ namespace Merge.Client.Crm; -public class UsersRetrieveRequest +public record UsersRetrieveRequest { /// /// Whether to include the original data Merge fetched from the third-party to produce these models. /// - public bool? IncludeRemoteData { get; init; } + public bool? IncludeRemoteData { get; set; } /// /// Whether to include all remote fields, including fields that Merge did not map to common models, in a normalized format. /// - public bool? IncludeRemoteFields { get; init; } + public bool? IncludeRemoteFields { get; set; } } diff --git a/src/Merge.Client/Crm/Users/UsersClient.cs b/src/Merge.Client/Crm/Users/UsersClient.cs index 2857a25e..74da1787 100644 --- a/src/Merge.Client/Crm/Users/UsersClient.cs +++ b/src/Merge.Client/Crm/Users/UsersClient.cs @@ -1,6 +1,6 @@ +using System.Net.Http; using System.Text.Json; -using Merge.Client; -using Merge.Client.Crm; +using Merge.Client.Core; #nullable enable @@ -18,16 +18,21 @@ public UsersClient(RawClient client) /// /// Returns a list of `User` objects. /// - public async Task ListAsync(UsersListRequest request) + public async Task ListAsync( + UsersListRequest request, + RequestOptions? options = null + ) { var _query = new Dictionary() { }; if (request.CreatedAfter != null) { - _query["created_after"] = request.CreatedAfter.Value.ToString("o0"); + _query["created_after"] = request.CreatedAfter.Value.ToString(Constants.DateTimeFormat); } if (request.CreatedBefore != null) { - _query["created_before"] = request.CreatedBefore.Value.ToString("o0"); + _query["created_before"] = request.CreatedBefore.Value.ToString( + Constants.DateTimeFormat + ); } if (request.Cursor != null) { @@ -47,11 +52,15 @@ public async Task ListAsync(UsersListRequest request) } if (request.ModifiedAfter != null) { - _query["modified_after"] = request.ModifiedAfter.Value.ToString("o0"); + _query["modified_after"] = request.ModifiedAfter.Value.ToString( + Constants.DateTimeFormat + ); } if (request.ModifiedBefore != null) { - _query["modified_before"] = request.ModifiedBefore.Value.ToString("o0"); + _query["modified_before"] = request.ModifiedBefore.Value.ToString( + Constants.DateTimeFormat + ); } if (request.PageSize != null) { @@ -64,23 +73,41 @@ public async Task ListAsync(UsersListRequest request) var response = await _client.MakeRequestAsync( new RawClient.JsonApiRequest { + BaseUrl = _client.Options.BaseUrl, Method = HttpMethod.Get, Path = "crm/v1/users", - Query = _query + Query = _query, + Options = options } ); - string responseBody = await response.Raw.Content.ReadAsStringAsync(); - if (response.StatusCode >= 200 && response.StatusCode < 400) + var responseBody = await response.Raw.Content.ReadAsStringAsync(); + if (response.StatusCode is >= 200 and < 400) { - return JsonSerializer.Deserialize(responseBody); + try + { + return JsonUtils.Deserialize(responseBody)!; + } + catch (JsonException e) + { + throw new MergeException("Failed to deserialize response", e); + } } - throw new Exception(responseBody); + + throw new MergeApiException( + $"Error with status code {response.StatusCode}", + response.StatusCode, + JsonUtils.Deserialize(responseBody) + ); } /// /// Returns a `User` object with the given `id`. /// - public async Task RetrieveAsync(string id, UsersRetrieveRequest request) + public async Task RetrieveAsync( + string id, + UsersRetrieveRequest request, + RequestOptions? options = null + ) { var _query = new Dictionary() { }; if (request.IncludeRemoteData != null) @@ -94,39 +121,70 @@ public async Task RetrieveAsync(string id, UsersRetrieveRequest request) var response = await _client.MakeRequestAsync( new RawClient.JsonApiRequest { + BaseUrl = _client.Options.BaseUrl, Method = HttpMethod.Get, Path = $"crm/v1/users/{id}", - Query = _query + Query = _query, + Options = options } ); - string responseBody = await response.Raw.Content.ReadAsStringAsync(); - if (response.StatusCode >= 200 && response.StatusCode < 400) + var responseBody = await response.Raw.Content.ReadAsStringAsync(); + if (response.StatusCode is >= 200 and < 400) { - return JsonSerializer.Deserialize(responseBody); + try + { + return JsonUtils.Deserialize(responseBody)!; + } + catch (JsonException e) + { + throw new MergeException("Failed to deserialize response", e); + } } - throw new Exception(responseBody); + + throw new MergeApiException( + $"Error with status code {response.StatusCode}", + response.StatusCode, + JsonUtils.Deserialize(responseBody) + ); } /// /// Ignores a specific row based on the `model_id` in the url. These records will have their properties set to null, and will not be updated in future syncs. The "reason" and "message" fields in the request body will be stored for audit purposes. /// - public async void IgnoreCreateAsync(string modelId, IgnoreCommonModelRequest request) + public async Task IgnoreCreateAsync( + string modelId, + IgnoreCommonModelRequest request, + RequestOptions? options = null + ) { var response = await _client.MakeRequestAsync( new RawClient.JsonApiRequest { + BaseUrl = _client.Options.BaseUrl, Method = HttpMethod.Post, Path = $"crm/v1/users/ignore/{modelId}", - Body = request + Body = request, + Options = options } ); + if (response.StatusCode is >= 200 and < 400) + { + return; + } + var responseBody = await response.Raw.Content.ReadAsStringAsync(); + throw new MergeApiException( + $"Error with status code {response.StatusCode}", + response.StatusCode, + JsonUtils.Deserialize(responseBody) + ); } /// /// Returns a list of `RemoteFieldClass` objects. /// public async Task RemoteFieldClassesListAsync( - UsersRemoteFieldClassesListRequest request + UsersRemoteFieldClassesListRequest request, + RequestOptions? options = null ) { var _query = new Dictionary() { }; @@ -157,16 +215,30 @@ UsersRemoteFieldClassesListRequest request var response = await _client.MakeRequestAsync( new RawClient.JsonApiRequest { + BaseUrl = _client.Options.BaseUrl, Method = HttpMethod.Get, Path = "crm/v1/users/remote-field-classes", - Query = _query + Query = _query, + Options = options } ); - string responseBody = await response.Raw.Content.ReadAsStringAsync(); - if (response.StatusCode >= 200 && response.StatusCode < 400) + var responseBody = await response.Raw.Content.ReadAsStringAsync(); + if (response.StatusCode is >= 200 and < 400) { - return JsonSerializer.Deserialize(responseBody); + try + { + return JsonUtils.Deserialize(responseBody)!; + } + catch (JsonException e) + { + throw new MergeException("Failed to deserialize response", e); + } } - throw new Exception(responseBody); + + throw new MergeApiException( + $"Error with status code {response.StatusCode}", + response.StatusCode, + JsonUtils.Deserialize(responseBody) + ); } } diff --git a/src/Merge.Client/Crm/WebhookReceivers/Requests/WebhookReceiverRequest.cs b/src/Merge.Client/Crm/WebhookReceivers/Requests/WebhookReceiverRequest.cs index 85a1efd1..bfac8ffc 100644 --- a/src/Merge.Client/Crm/WebhookReceivers/Requests/WebhookReceiverRequest.cs +++ b/src/Merge.Client/Crm/WebhookReceivers/Requests/WebhookReceiverRequest.cs @@ -4,14 +4,14 @@ namespace Merge.Client.Crm; -public class WebhookReceiverRequest +public record WebhookReceiverRequest { [JsonPropertyName("event")] - public string Event { get; init; } + public required string Event { get; set; } [JsonPropertyName("is_active")] - public bool IsActive { get; init; } + public required bool IsActive { get; set; } [JsonPropertyName("key")] - public string? Key { get; init; } + public string? Key { get; set; } } diff --git a/src/Merge.Client/Crm/WebhookReceivers/WebhookReceiversClient.cs b/src/Merge.Client/Crm/WebhookReceivers/WebhookReceiversClient.cs index b8d2c3ba..9f386415 100644 --- a/src/Merge.Client/Crm/WebhookReceivers/WebhookReceiversClient.cs +++ b/src/Merge.Client/Crm/WebhookReceivers/WebhookReceiversClient.cs @@ -1,6 +1,6 @@ +using System.Net.Http; using System.Text.Json; -using Merge.Client; -using Merge.Client.Crm; +using Merge.Client.Core; #nullable enable @@ -18,41 +18,72 @@ public WebhookReceiversClient(RawClient client) /// /// Returns a list of `WebhookReceiver` objects. /// - public async Task> ListAsync() + public async Task> ListAsync(RequestOptions? options = null) { var response = await _client.MakeRequestAsync( new RawClient.JsonApiRequest { + BaseUrl = _client.Options.BaseUrl, Method = HttpMethod.Get, - Path = "crm/v1/webhook-receivers" + Path = "crm/v1/webhook-receivers", + Options = options } ); - string responseBody = await response.Raw.Content.ReadAsStringAsync(); - if (response.StatusCode >= 200 && response.StatusCode < 400) + var responseBody = await response.Raw.Content.ReadAsStringAsync(); + if (response.StatusCode is >= 200 and < 400) { - return JsonSerializer.Deserialize>(responseBody); + try + { + return JsonUtils.Deserialize>(responseBody)!; + } + catch (JsonException e) + { + throw new MergeException("Failed to deserialize response", e); + } } - throw new Exception(responseBody); + + throw new MergeApiException( + $"Error with status code {response.StatusCode}", + response.StatusCode, + JsonUtils.Deserialize(responseBody) + ); } /// /// Creates a `WebhookReceiver` object with the given values. /// - public async Task CreateAsync(WebhookReceiverRequest request) + public async Task CreateAsync( + WebhookReceiverRequest request, + RequestOptions? options = null + ) { var response = await _client.MakeRequestAsync( new RawClient.JsonApiRequest { + BaseUrl = _client.Options.BaseUrl, Method = HttpMethod.Post, Path = "crm/v1/webhook-receivers", - Body = request + Body = request, + Options = options } ); - string responseBody = await response.Raw.Content.ReadAsStringAsync(); - if (response.StatusCode >= 200 && response.StatusCode < 400) + var responseBody = await response.Raw.Content.ReadAsStringAsync(); + if (response.StatusCode is >= 200 and < 400) { - return JsonSerializer.Deserialize(responseBody); + try + { + return JsonUtils.Deserialize(responseBody)!; + } + catch (JsonException e) + { + throw new MergeException("Failed to deserialize response", e); + } } - throw new Exception(responseBody); + + throw new MergeApiException( + $"Error with status code {response.StatusCode}", + response.StatusCode, + JsonUtils.Deserialize(responseBody) + ); } } diff --git a/src/Merge.Client/Filestorage/AccountDetails/AccountDetailsClient.cs b/src/Merge.Client/Filestorage/AccountDetails/AccountDetailsClient.cs index 412a1682..93c6065a 100644 --- a/src/Merge.Client/Filestorage/AccountDetails/AccountDetailsClient.cs +++ b/src/Merge.Client/Filestorage/AccountDetails/AccountDetailsClient.cs @@ -1,6 +1,6 @@ +using System.Net.Http; using System.Text.Json; -using Merge.Client; -using Merge.Client.Filestorage; +using Merge.Client.Core; #nullable enable @@ -18,20 +18,34 @@ public AccountDetailsClient(RawClient client) /// /// Get details for a linked account. /// - public async Task RetrieveAsync() + public async Task RetrieveAsync(RequestOptions? options = null) { var response = await _client.MakeRequestAsync( new RawClient.JsonApiRequest { + BaseUrl = _client.Options.BaseUrl, Method = HttpMethod.Get, - Path = "filestorage/v1/account-details" + Path = "filestorage/v1/account-details", + Options = options } ); - string responseBody = await response.Raw.Content.ReadAsStringAsync(); - if (response.StatusCode >= 200 && response.StatusCode < 400) + var responseBody = await response.Raw.Content.ReadAsStringAsync(); + if (response.StatusCode is >= 200 and < 400) { - return JsonSerializer.Deserialize(responseBody); + try + { + return JsonUtils.Deserialize(responseBody)!; + } + catch (JsonException e) + { + throw new MergeException("Failed to deserialize response", e); + } } - throw new Exception(responseBody); + + throw new MergeApiException( + $"Error with status code {response.StatusCode}", + response.StatusCode, + JsonUtils.Deserialize(responseBody) + ); } } diff --git a/src/Merge.Client/Filestorage/AccountToken/AccountTokenClient.cs b/src/Merge.Client/Filestorage/AccountToken/AccountTokenClient.cs index 64ae04ad..b4a1a412 100644 --- a/src/Merge.Client/Filestorage/AccountToken/AccountTokenClient.cs +++ b/src/Merge.Client/Filestorage/AccountToken/AccountTokenClient.cs @@ -1,6 +1,6 @@ +using System.Net.Http; using System.Text.Json; -using Merge.Client; -using Merge.Client.Filestorage; +using Merge.Client.Core; #nullable enable @@ -18,20 +18,37 @@ public AccountTokenClient(RawClient client) /// /// Returns the account token for the end user with the provided public token. /// - public async Task RetrieveAsync(string publicToken) + public async Task RetrieveAsync( + string publicToken, + RequestOptions? options = null + ) { var response = await _client.MakeRequestAsync( new RawClient.JsonApiRequest { + BaseUrl = _client.Options.BaseUrl, Method = HttpMethod.Get, - Path = $"filestorage/v1/account-token/{publicToken}" + Path = $"filestorage/v1/account-token/{publicToken}", + Options = options } ); - string responseBody = await response.Raw.Content.ReadAsStringAsync(); - if (response.StatusCode >= 200 && response.StatusCode < 400) + var responseBody = await response.Raw.Content.ReadAsStringAsync(); + if (response.StatusCode is >= 200 and < 400) { - return JsonSerializer.Deserialize(responseBody); + try + { + return JsonUtils.Deserialize(responseBody)!; + } + catch (JsonException e) + { + throw new MergeException("Failed to deserialize response", e); + } } - throw new Exception(responseBody); + + throw new MergeApiException( + $"Error with status code {response.StatusCode}", + response.StatusCode, + JsonUtils.Deserialize(responseBody) + ); } } diff --git a/src/Merge.Client/Filestorage/AsyncPassthrough/AsyncPassthroughClient.cs b/src/Merge.Client/Filestorage/AsyncPassthrough/AsyncPassthroughClient.cs index cf05535b..686da4c7 100644 --- a/src/Merge.Client/Filestorage/AsyncPassthrough/AsyncPassthroughClient.cs +++ b/src/Merge.Client/Filestorage/AsyncPassthrough/AsyncPassthroughClient.cs @@ -1,6 +1,6 @@ +using System.Net.Http; using System.Text.Json; -using Merge.Client; -using Merge.Client.Filestorage; +using Merge.Client.Core; #nullable enable @@ -18,41 +18,75 @@ public AsyncPassthroughClient(RawClient client) /// /// Asynchronously pull data from an endpoint not currently supported by Merge. /// - public async Task CreateAsync(DataPassthroughRequest request) + public async Task CreateAsync( + DataPassthroughRequest request, + RequestOptions? options = null + ) { var response = await _client.MakeRequestAsync( new RawClient.JsonApiRequest { + BaseUrl = _client.Options.BaseUrl, Method = HttpMethod.Post, Path = "filestorage/v1/async-passthrough", - Body = request + Body = request, + Options = options } ); - string responseBody = await response.Raw.Content.ReadAsStringAsync(); - if (response.StatusCode >= 200 && response.StatusCode < 400) + var responseBody = await response.Raw.Content.ReadAsStringAsync(); + if (response.StatusCode is >= 200 and < 400) { - return JsonSerializer.Deserialize(responseBody); + try + { + return JsonUtils.Deserialize(responseBody)!; + } + catch (JsonException e) + { + throw new MergeException("Failed to deserialize response", e); + } } - throw new Exception(responseBody); + + throw new MergeApiException( + $"Error with status code {response.StatusCode}", + response.StatusCode, + JsonUtils.Deserialize(responseBody) + ); } /// /// Retrieves data from earlier async-passthrough POST request /// - public async Task RetrieveAsync(string asyncPassthroughReceiptId) + public async Task RetrieveAsync( + string asyncPassthroughReceiptId, + RequestOptions? options = null + ) { var response = await _client.MakeRequestAsync( new RawClient.JsonApiRequest { + BaseUrl = _client.Options.BaseUrl, Method = HttpMethod.Get, - Path = $"filestorage/v1/async-passthrough/{asyncPassthroughReceiptId}" + Path = $"filestorage/v1/async-passthrough/{asyncPassthroughReceiptId}", + Options = options } ); - string responseBody = await response.Raw.Content.ReadAsStringAsync(); - if (response.StatusCode >= 200 && response.StatusCode < 400) + var responseBody = await response.Raw.Content.ReadAsStringAsync(); + if (response.StatusCode is >= 200 and < 400) { - return JsonSerializer.Deserialize(responseBody); + try + { + return JsonUtils.Deserialize(responseBody)!; + } + catch (JsonException e) + { + throw new MergeException("Failed to deserialize response", e); + } } - throw new Exception(responseBody); + + throw new MergeApiException( + $"Error with status code {response.StatusCode}", + response.StatusCode, + JsonUtils.Deserialize(responseBody) + ); } } diff --git a/src/Merge.Client/Filestorage/AuditTrail/AuditTrailClient.cs b/src/Merge.Client/Filestorage/AuditTrail/AuditTrailClient.cs index 412aeeb4..5cd5b66c 100644 --- a/src/Merge.Client/Filestorage/AuditTrail/AuditTrailClient.cs +++ b/src/Merge.Client/Filestorage/AuditTrail/AuditTrailClient.cs @@ -1,6 +1,6 @@ +using System.Net.Http; using System.Text.Json; -using Merge.Client; -using Merge.Client.Filestorage; +using Merge.Client.Core; #nullable enable @@ -18,7 +18,10 @@ public AuditTrailClient(RawClient client) /// /// Gets a list of audit trail events. /// - public async Task ListAsync(AuditTrailListRequest request) + public async Task ListAsync( + AuditTrailListRequest request, + RequestOptions? options = null + ) { var _query = new Dictionary() { }; if (request.Cursor != null) @@ -48,16 +51,30 @@ public async Task ListAsync(AuditTrailListRequest re var response = await _client.MakeRequestAsync( new RawClient.JsonApiRequest { + BaseUrl = _client.Options.BaseUrl, Method = HttpMethod.Get, Path = "filestorage/v1/audit-trail", - Query = _query + Query = _query, + Options = options } ); - string responseBody = await response.Raw.Content.ReadAsStringAsync(); - if (response.StatusCode >= 200 && response.StatusCode < 400) + var responseBody = await response.Raw.Content.ReadAsStringAsync(); + if (response.StatusCode is >= 200 and < 400) { - return JsonSerializer.Deserialize(responseBody); + try + { + return JsonUtils.Deserialize(responseBody)!; + } + catch (JsonException e) + { + throw new MergeException("Failed to deserialize response", e); + } } - throw new Exception(responseBody); + + throw new MergeApiException( + $"Error with status code {response.StatusCode}", + response.StatusCode, + JsonUtils.Deserialize(responseBody) + ); } } diff --git a/src/Merge.Client/Filestorage/AuditTrail/Requests/AuditTrailListRequest.cs b/src/Merge.Client/Filestorage/AuditTrail/Requests/AuditTrailListRequest.cs index 10136bd4..2d649e63 100644 --- a/src/Merge.Client/Filestorage/AuditTrail/Requests/AuditTrailListRequest.cs +++ b/src/Merge.Client/Filestorage/AuditTrail/Requests/AuditTrailListRequest.cs @@ -1,34 +1,34 @@ namespace Merge.Client.Filestorage; -public class AuditTrailListRequest +public record AuditTrailListRequest { /// /// The pagination cursor value. /// - public string? Cursor { get; init; } + public string? Cursor { get; set; } /// /// If included, will only include audit trail events that occurred before this time /// - public string? EndDate { get; init; } + public string? EndDate { get; set; } /// /// If included, will only include events with the given event type. Possible values include: `CREATED_REMOTE_PRODUCTION_API_KEY`, `DELETED_REMOTE_PRODUCTION_API_KEY`, `CREATED_TEST_API_KEY`, `DELETED_TEST_API_KEY`, `REGENERATED_PRODUCTION_API_KEY`, `INVITED_USER`, `TWO_FACTOR_AUTH_ENABLED`, `TWO_FACTOR_AUTH_DISABLED`, `DELETED_LINKED_ACCOUNT`, `CREATED_DESTINATION`, `DELETED_DESTINATION`, `CHANGED_DESTINATION`, `CHANGED_SCOPES`, `CHANGED_PERSONAL_INFORMATION`, `CHANGED_ORGANIZATION_SETTINGS`, `ENABLED_INTEGRATION`, `DISABLED_INTEGRATION`, `ENABLED_CATEGORY`, `DISABLED_CATEGORY`, `CHANGED_PASSWORD`, `RESET_PASSWORD`, `ENABLED_REDACT_UNMAPPED_DATA_FOR_ORGANIZATION`, `ENABLED_REDACT_UNMAPPED_DATA_FOR_LINKED_ACCOUNT`, `DISABLED_REDACT_UNMAPPED_DATA_FOR_ORGANIZATION`, `DISABLED_REDACT_UNMAPPED_DATA_FOR_LINKED_ACCOUNT`, `CREATED_INTEGRATION_WIDE_FIELD_MAPPING`, `CREATED_LINKED_ACCOUNT_FIELD_MAPPING`, `CHANGED_INTEGRATION_WIDE_FIELD_MAPPING`, `CHANGED_LINKED_ACCOUNT_FIELD_MAPPING`, `DELETED_INTEGRATION_WIDE_FIELD_MAPPING`, `DELETED_LINKED_ACCOUNT_FIELD_MAPPING`, `FORCED_LINKED_ACCOUNT_RESYNC`, `MUTED_ISSUE`, `GENERATED_MAGIC_LINK`, `ENABLED_MERGE_WEBHOOK`, `DISABLED_MERGE_WEBHOOK`, `MERGE_WEBHOOK_TARGET_CHANGED`, `END_USER_CREDENTIALS_ACCESSED` /// - public string? EventType { get; init; } + public string? EventType { get; set; } /// /// Number of results to return per page. /// - public int? PageSize { get; init; } + public int? PageSize { get; set; } /// /// If included, will only include audit trail events that occurred after this time /// - public string? StartDate { get; init; } + public string? StartDate { get; set; } /// /// If provided, this will return events associated with the specified user email. Please note that the email address reflects the user's email at the time of the event, and may not be their current email. /// - public string? UserEmail { get; init; } + public string? UserEmail { get; set; } } diff --git a/src/Merge.Client/Filestorage/AvailableActions/AvailableActionsClient.cs b/src/Merge.Client/Filestorage/AvailableActions/AvailableActionsClient.cs index 4294ff7a..1e73a8fd 100644 --- a/src/Merge.Client/Filestorage/AvailableActions/AvailableActionsClient.cs +++ b/src/Merge.Client/Filestorage/AvailableActions/AvailableActionsClient.cs @@ -1,6 +1,6 @@ +using System.Net.Http; using System.Text.Json; -using Merge.Client; -using Merge.Client.Filestorage; +using Merge.Client.Core; #nullable enable @@ -18,20 +18,34 @@ public AvailableActionsClient(RawClient client) /// /// Returns a list of models and actions available for an account. /// - public async Task RetrieveAsync() + public async Task RetrieveAsync(RequestOptions? options = null) { var response = await _client.MakeRequestAsync( new RawClient.JsonApiRequest { + BaseUrl = _client.Options.BaseUrl, Method = HttpMethod.Get, - Path = "filestorage/v1/available-actions" + Path = "filestorage/v1/available-actions", + Options = options } ); - string responseBody = await response.Raw.Content.ReadAsStringAsync(); - if (response.StatusCode >= 200 && response.StatusCode < 400) + var responseBody = await response.Raw.Content.ReadAsStringAsync(); + if (response.StatusCode is >= 200 and < 400) { - return JsonSerializer.Deserialize(responseBody); + try + { + return JsonUtils.Deserialize(responseBody)!; + } + catch (JsonException e) + { + throw new MergeException("Failed to deserialize response", e); + } } - throw new Exception(responseBody); + + throw new MergeApiException( + $"Error with status code {response.StatusCode}", + response.StatusCode, + JsonUtils.Deserialize(responseBody) + ); } } diff --git a/src/Merge.Client/Filestorage/DeleteAccount/DeleteAccountClient.cs b/src/Merge.Client/Filestorage/DeleteAccount/DeleteAccountClient.cs index a43935cf..ecaf7702 100644 --- a/src/Merge.Client/Filestorage/DeleteAccount/DeleteAccountClient.cs +++ b/src/Merge.Client/Filestorage/DeleteAccount/DeleteAccountClient.cs @@ -1,4 +1,5 @@ -using Merge.Client; +using System.Net.Http; +using Merge.Client.Core; #nullable enable @@ -16,14 +17,26 @@ public DeleteAccountClient(RawClient client) /// /// Delete a linked account. /// - public async void DeleteAsync() + public async Task DeleteAsync(RequestOptions? options = null) { var response = await _client.MakeRequestAsync( new RawClient.JsonApiRequest { + BaseUrl = _client.Options.BaseUrl, Method = HttpMethod.Post, - Path = "filestorage/v1/delete-account" + Path = "filestorage/v1/delete-account", + Options = options } ); + if (response.StatusCode is >= 200 and < 400) + { + return; + } + var responseBody = await response.Raw.Content.ReadAsStringAsync(); + throw new MergeApiException( + $"Error with status code {response.StatusCode}", + response.StatusCode, + JsonUtils.Deserialize(responseBody) + ); } } diff --git a/src/Merge.Client/Filestorage/Drives/DrivesClient.cs b/src/Merge.Client/Filestorage/Drives/DrivesClient.cs index f451db63..d56b2728 100644 --- a/src/Merge.Client/Filestorage/Drives/DrivesClient.cs +++ b/src/Merge.Client/Filestorage/Drives/DrivesClient.cs @@ -1,6 +1,6 @@ +using System.Net.Http; using System.Text.Json; -using Merge.Client; -using Merge.Client.Filestorage; +using Merge.Client.Core; #nullable enable @@ -18,16 +18,21 @@ public DrivesClient(RawClient client) /// /// Returns a list of `Drive` objects. /// - public async Task ListAsync(DrivesListRequest request) + public async Task ListAsync( + DrivesListRequest request, + RequestOptions? options = null + ) { var _query = new Dictionary() { }; if (request.CreatedAfter != null) { - _query["created_after"] = request.CreatedAfter.Value.ToString("o0"); + _query["created_after"] = request.CreatedAfter.Value.ToString(Constants.DateTimeFormat); } if (request.CreatedBefore != null) { - _query["created_before"] = request.CreatedBefore.Value.ToString("o0"); + _query["created_before"] = request.CreatedBefore.Value.ToString( + Constants.DateTimeFormat + ); } if (request.Cursor != null) { @@ -43,11 +48,15 @@ public async Task ListAsync(DrivesListRequest request) } if (request.ModifiedAfter != null) { - _query["modified_after"] = request.ModifiedAfter.Value.ToString("o0"); + _query["modified_after"] = request.ModifiedAfter.Value.ToString( + Constants.DateTimeFormat + ); } if (request.ModifiedBefore != null) { - _query["modified_before"] = request.ModifiedBefore.Value.ToString("o0"); + _query["modified_before"] = request.ModifiedBefore.Value.ToString( + Constants.DateTimeFormat + ); } if (request.Name != null) { @@ -64,23 +73,41 @@ public async Task ListAsync(DrivesListRequest request) var response = await _client.MakeRequestAsync( new RawClient.JsonApiRequest { + BaseUrl = _client.Options.BaseUrl, Method = HttpMethod.Get, Path = "filestorage/v1/drives", - Query = _query + Query = _query, + Options = options } ); - string responseBody = await response.Raw.Content.ReadAsStringAsync(); - if (response.StatusCode >= 200 && response.StatusCode < 400) + var responseBody = await response.Raw.Content.ReadAsStringAsync(); + if (response.StatusCode is >= 200 and < 400) { - return JsonSerializer.Deserialize(responseBody); + try + { + return JsonUtils.Deserialize(responseBody)!; + } + catch (JsonException e) + { + throw new MergeException("Failed to deserialize response", e); + } } - throw new Exception(responseBody); + + throw new MergeApiException( + $"Error with status code {response.StatusCode}", + response.StatusCode, + JsonUtils.Deserialize(responseBody) + ); } /// /// Returns a `Drive` object with the given `id`. /// - public async Task RetrieveAsync(string id, DrivesRetrieveRequest request) + public async Task RetrieveAsync( + string id, + DrivesRetrieveRequest request, + RequestOptions? options = null + ) { var _query = new Dictionary() { }; if (request.IncludeRemoteData != null) @@ -90,16 +117,30 @@ public async Task RetrieveAsync(string id, DrivesRetrieveRequest request) var response = await _client.MakeRequestAsync( new RawClient.JsonApiRequest { + BaseUrl = _client.Options.BaseUrl, Method = HttpMethod.Get, Path = $"filestorage/v1/drives/{id}", - Query = _query + Query = _query, + Options = options } ); - string responseBody = await response.Raw.Content.ReadAsStringAsync(); - if (response.StatusCode >= 200 && response.StatusCode < 400) + var responseBody = await response.Raw.Content.ReadAsStringAsync(); + if (response.StatusCode is >= 200 and < 400) { - return JsonSerializer.Deserialize(responseBody); + try + { + return JsonUtils.Deserialize(responseBody)!; + } + catch (JsonException e) + { + throw new MergeException("Failed to deserialize response", e); + } } - throw new Exception(responseBody); + + throw new MergeApiException( + $"Error with status code {response.StatusCode}", + response.StatusCode, + JsonUtils.Deserialize(responseBody) + ); } } diff --git a/src/Merge.Client/Filestorage/Drives/Requests/DrivesListRequest.cs b/src/Merge.Client/Filestorage/Drives/Requests/DrivesListRequest.cs index 227ae14d..ecbddee1 100644 --- a/src/Merge.Client/Filestorage/Drives/Requests/DrivesListRequest.cs +++ b/src/Merge.Client/Filestorage/Drives/Requests/DrivesListRequest.cs @@ -1,54 +1,54 @@ namespace Merge.Client.Filestorage; -public class DrivesListRequest +public record DrivesListRequest { /// /// If provided, will only return objects created after this datetime. /// - public DateTime? CreatedAfter { get; init; } + public DateTime? CreatedAfter { get; set; } /// /// If provided, will only return objects created before this datetime. /// - public DateTime? CreatedBefore { get; init; } + public DateTime? CreatedBefore { get; set; } /// /// The pagination cursor value. /// - public string? Cursor { get; init; } + public string? Cursor { get; set; } /// /// Whether to include data that was marked as deleted by third party webhooks. /// - public bool? IncludeDeletedData { get; init; } + public bool? IncludeDeletedData { get; set; } /// /// Whether to include the original data Merge fetched from the third-party to produce these models. /// - public bool? IncludeRemoteData { get; init; } + public bool? IncludeRemoteData { get; set; } /// /// If provided, only objects synced by Merge after this date time will be returned. /// - public DateTime? ModifiedAfter { get; init; } + public DateTime? ModifiedAfter { get; set; } /// /// If provided, only objects synced by Merge before this date time will be returned. /// - public DateTime? ModifiedBefore { get; init; } + public DateTime? ModifiedBefore { get; set; } /// /// If provided, will only return drives with this name. This performs an exact match. /// - public string? Name { get; init; } + public string? Name { get; set; } /// /// Number of results to return per page. /// - public int? PageSize { get; init; } + public int? PageSize { get; set; } /// /// The API provider's ID for the given object. /// - public string? RemoteId { get; init; } + public string? RemoteId { get; set; } } diff --git a/src/Merge.Client/Filestorage/Drives/Requests/DrivesRetrieveRequest.cs b/src/Merge.Client/Filestorage/Drives/Requests/DrivesRetrieveRequest.cs index b2d5d28b..175349b0 100644 --- a/src/Merge.Client/Filestorage/Drives/Requests/DrivesRetrieveRequest.cs +++ b/src/Merge.Client/Filestorage/Drives/Requests/DrivesRetrieveRequest.cs @@ -1,9 +1,9 @@ namespace Merge.Client.Filestorage; -public class DrivesRetrieveRequest +public record DrivesRetrieveRequest { /// /// Whether to include the original data Merge fetched from the third-party to produce these models. /// - public bool? IncludeRemoteData { get; init; } + public bool? IncludeRemoteData { get; set; } } diff --git a/src/Merge.Client/Filestorage/FieldMapping/FieldMappingClient.cs b/src/Merge.Client/Filestorage/FieldMapping/FieldMappingClient.cs index 6e69bb5b..412e2198 100644 --- a/src/Merge.Client/Filestorage/FieldMapping/FieldMappingClient.cs +++ b/src/Merge.Client/Filestorage/FieldMapping/FieldMappingClient.cs @@ -1,6 +1,6 @@ +using System.Net.Http; using System.Text.Json; -using Merge.Client; -using Merge.Client.Filestorage; +using Merge.Client.Core; #nullable enable @@ -18,64 +18,112 @@ public FieldMappingClient(RawClient client) /// /// Get all Field Mappings for this Linked Account. Field Mappings are mappings between third-party Remote Fields and user defined Merge fields. [Learn more](https://docs.merge.dev/supplemental-data/field-mappings/overview/). /// - public async Task FieldMappingsRetrieveAsync() + public async Task FieldMappingsRetrieveAsync( + RequestOptions? options = null + ) { var response = await _client.MakeRequestAsync( new RawClient.JsonApiRequest { + BaseUrl = _client.Options.BaseUrl, Method = HttpMethod.Get, - Path = "filestorage/v1/field-mappings" + Path = "filestorage/v1/field-mappings", + Options = options } ); - string responseBody = await response.Raw.Content.ReadAsStringAsync(); - if (response.StatusCode >= 200 && response.StatusCode < 400) + var responseBody = await response.Raw.Content.ReadAsStringAsync(); + if (response.StatusCode is >= 200 and < 400) { - return JsonSerializer.Deserialize(responseBody); + try + { + return JsonUtils.Deserialize(responseBody)!; + } + catch (JsonException e) + { + throw new MergeException("Failed to deserialize response", e); + } } - throw new Exception(responseBody); + + throw new MergeApiException( + $"Error with status code {response.StatusCode}", + response.StatusCode, + JsonUtils.Deserialize(responseBody) + ); } /// /// Create new Field Mappings that will be available after the next scheduled sync. This will cause the next sync for this Linked Account to sync **ALL** data from start. /// public async Task FieldMappingsCreateAsync( - CreateFieldMappingRequest request + CreateFieldMappingRequest request, + RequestOptions? options = null ) { var response = await _client.MakeRequestAsync( new RawClient.JsonApiRequest { + BaseUrl = _client.Options.BaseUrl, Method = HttpMethod.Post, Path = "filestorage/v1/field-mappings", - Body = request + Body = request, + Options = options } ); - string responseBody = await response.Raw.Content.ReadAsStringAsync(); - if (response.StatusCode >= 200 && response.StatusCode < 400) + var responseBody = await response.Raw.Content.ReadAsStringAsync(); + if (response.StatusCode is >= 200 and < 400) { - return JsonSerializer.Deserialize(responseBody); + try + { + return JsonUtils.Deserialize(responseBody)!; + } + catch (JsonException e) + { + throw new MergeException("Failed to deserialize response", e); + } } - throw new Exception(responseBody); + + throw new MergeApiException( + $"Error with status code {response.StatusCode}", + response.StatusCode, + JsonUtils.Deserialize(responseBody) + ); } /// /// Deletes Field Mappings for a Linked Account. All data related to this Field Mapping will be deleted and these changes will be reflected after the next scheduled sync. This will cause the next sync for this Linked Account to sync **ALL** data from start. /// - public async Task FieldMappingsDestroyAsync(string fieldMappingId) + public async Task FieldMappingsDestroyAsync( + string fieldMappingId, + RequestOptions? options = null + ) { var response = await _client.MakeRequestAsync( new RawClient.JsonApiRequest { + BaseUrl = _client.Options.BaseUrl, Method = HttpMethod.Delete, - Path = $"filestorage/v1/field-mappings/{fieldMappingId}" + Path = $"filestorage/v1/field-mappings/{fieldMappingId}", + Options = options } ); - string responseBody = await response.Raw.Content.ReadAsStringAsync(); - if (response.StatusCode >= 200 && response.StatusCode < 400) + var responseBody = await response.Raw.Content.ReadAsStringAsync(); + if (response.StatusCode is >= 200 and < 400) { - return JsonSerializer.Deserialize(responseBody); + try + { + return JsonUtils.Deserialize(responseBody)!; + } + catch (JsonException e) + { + throw new MergeException("Failed to deserialize response", e); + } } - throw new Exception(responseBody); + + throw new MergeApiException( + $"Error with status code {response.StatusCode}", + response.StatusCode, + JsonUtils.Deserialize(responseBody) + ); } /// @@ -83,30 +131,46 @@ public async Task FieldMappingsDestroyAsync(string /// public async Task FieldMappingsPartialUpdateAsync( string fieldMappingId, - PatchedEditFieldMappingRequest request + PatchedEditFieldMappingRequest request, + RequestOptions? options = null ) { var response = await _client.MakeRequestAsync( new RawClient.JsonApiRequest { - Method = HttpMethod.Patch, + BaseUrl = _client.Options.BaseUrl, + Method = HttpMethodExtensions.Patch, Path = $"filestorage/v1/field-mappings/{fieldMappingId}", - Body = request + Body = request, + Options = options } ); - string responseBody = await response.Raw.Content.ReadAsStringAsync(); - if (response.StatusCode >= 200 && response.StatusCode < 400) + var responseBody = await response.Raw.Content.ReadAsStringAsync(); + if (response.StatusCode is >= 200 and < 400) { - return JsonSerializer.Deserialize(responseBody); + try + { + return JsonUtils.Deserialize(responseBody)!; + } + catch (JsonException e) + { + throw new MergeException("Failed to deserialize response", e); + } } - throw new Exception(responseBody); + + throw new MergeApiException( + $"Error with status code {response.StatusCode}", + response.StatusCode, + JsonUtils.Deserialize(responseBody) + ); } /// /// Get all remote fields for a Linked Account. Remote fields are third-party fields that are accessible after initial sync if remote_data is enabled. You can use remote fields to override existing Merge fields or map a new Merge field. [Learn more](https://docs.merge.dev/supplemental-data/field-mappings/overview/). /// public async Task RemoteFieldsRetrieveAsync( - RemoteFieldsRetrieveRequest request + RemoteFieldsRetrieveRequest request, + RequestOptions? options = null ) { var _query = new Dictionary() { }; @@ -121,36 +185,66 @@ RemoteFieldsRetrieveRequest request var response = await _client.MakeRequestAsync( new RawClient.JsonApiRequest { + BaseUrl = _client.Options.BaseUrl, Method = HttpMethod.Get, Path = "filestorage/v1/remote-fields", - Query = _query + Query = _query, + Options = options } ); - string responseBody = await response.Raw.Content.ReadAsStringAsync(); - if (response.StatusCode >= 200 && response.StatusCode < 400) + var responseBody = await response.Raw.Content.ReadAsStringAsync(); + if (response.StatusCode is >= 200 and < 400) { - return JsonSerializer.Deserialize(responseBody); + try + { + return JsonUtils.Deserialize(responseBody)!; + } + catch (JsonException e) + { + throw new MergeException("Failed to deserialize response", e); + } } - throw new Exception(responseBody); + + throw new MergeApiException( + $"Error with status code {response.StatusCode}", + response.StatusCode, + JsonUtils.Deserialize(responseBody) + ); } /// /// Get all organization-wide Target Fields, this will not include any Linked Account specific Target Fields. Organization-wide Target Fields are additional fields appended to the Merge Common Model for all Linked Accounts in a category. [Learn more](https://docs.merge.dev/supplemental-data/field-mappings/target-fields/). /// - public async Task TargetFieldsRetrieveAsync() + public async Task TargetFieldsRetrieveAsync( + RequestOptions? options = null + ) { var response = await _client.MakeRequestAsync( new RawClient.JsonApiRequest { + BaseUrl = _client.Options.BaseUrl, Method = HttpMethod.Get, - Path = "filestorage/v1/target-fields" + Path = "filestorage/v1/target-fields", + Options = options } ); - string responseBody = await response.Raw.Content.ReadAsStringAsync(); - if (response.StatusCode >= 200 && response.StatusCode < 400) + var responseBody = await response.Raw.Content.ReadAsStringAsync(); + if (response.StatusCode is >= 200 and < 400) { - return JsonSerializer.Deserialize(responseBody); + try + { + return JsonUtils.Deserialize(responseBody)!; + } + catch (JsonException e) + { + throw new MergeException("Failed to deserialize response", e); + } } - throw new Exception(responseBody); + + throw new MergeApiException( + $"Error with status code {response.StatusCode}", + response.StatusCode, + JsonUtils.Deserialize(responseBody) + ); } } diff --git a/src/Merge.Client/Filestorage/FieldMapping/Requests/CreateFieldMappingRequest.cs b/src/Merge.Client/Filestorage/FieldMapping/Requests/CreateFieldMappingRequest.cs index 9d58c325..cfb3befc 100644 --- a/src/Merge.Client/Filestorage/FieldMapping/Requests/CreateFieldMappingRequest.cs +++ b/src/Merge.Client/Filestorage/FieldMapping/Requests/CreateFieldMappingRequest.cs @@ -4,41 +4,41 @@ namespace Merge.Client.Filestorage; -public class CreateFieldMappingRequest +public record CreateFieldMappingRequest { /// /// The name of the target field you want this remote field to map to. /// [JsonPropertyName("target_field_name")] - public string TargetFieldName { get; init; } + public required string TargetFieldName { get; set; } /// /// The description of the target field you want this remote field to map to. /// [JsonPropertyName("target_field_description")] - public string TargetFieldDescription { get; init; } + public required string TargetFieldDescription { get; set; } /// /// The field traversal path of the remote field listed when you hit the GET /remote-fields endpoint. /// [JsonPropertyName("remote_field_traversal_path")] - public IEnumerable RemoteFieldTraversalPath { get; init; } + public IEnumerable RemoteFieldTraversalPath { get; set; } = new List(); /// /// The method of the remote endpoint where the remote field is coming from. /// [JsonPropertyName("remote_method")] - public string RemoteMethod { get; init; } + public required string RemoteMethod { get; set; } /// /// The path of the remote endpoint where the remote field is coming from. /// [JsonPropertyName("remote_url_path")] - public string RemoteUrlPath { get; init; } + public required string RemoteUrlPath { get; set; } /// /// The name of the Common Model that the remote field corresponds to in a given category. /// [JsonPropertyName("common_model_name")] - public string CommonModelName { get; init; } + public required string CommonModelName { get; set; } } diff --git a/src/Merge.Client/Filestorage/FieldMapping/Requests/PatchedEditFieldMappingRequest.cs b/src/Merge.Client/Filestorage/FieldMapping/Requests/PatchedEditFieldMappingRequest.cs index b4c20f20..3ec64787 100644 --- a/src/Merge.Client/Filestorage/FieldMapping/Requests/PatchedEditFieldMappingRequest.cs +++ b/src/Merge.Client/Filestorage/FieldMapping/Requests/PatchedEditFieldMappingRequest.cs @@ -4,23 +4,23 @@ namespace Merge.Client.Filestorage; -public class PatchedEditFieldMappingRequest +public record PatchedEditFieldMappingRequest { /// /// The field traversal path of the remote field listed when you hit the GET /remote-fields endpoint. /// [JsonPropertyName("remote_field_traversal_path")] - public IEnumerable? RemoteFieldTraversalPath { get; init; } + public IEnumerable? RemoteFieldTraversalPath { get; set; } /// /// The method of the remote endpoint where the remote field is coming from. /// [JsonPropertyName("remote_method")] - public string? RemoteMethod { get; init; } + public string? RemoteMethod { get; set; } /// /// The path of the remote endpoint where the remote field is coming from. /// [JsonPropertyName("remote_url_path")] - public string? RemoteUrlPath { get; init; } + public string? RemoteUrlPath { get; set; } } diff --git a/src/Merge.Client/Filestorage/FieldMapping/Requests/RemoteFieldsRetrieveRequest.cs b/src/Merge.Client/Filestorage/FieldMapping/Requests/RemoteFieldsRetrieveRequest.cs index fe23658d..0cd64a8f 100644 --- a/src/Merge.Client/Filestorage/FieldMapping/Requests/RemoteFieldsRetrieveRequest.cs +++ b/src/Merge.Client/Filestorage/FieldMapping/Requests/RemoteFieldsRetrieveRequest.cs @@ -1,14 +1,14 @@ namespace Merge.Client.Filestorage; -public class RemoteFieldsRetrieveRequest +public record RemoteFieldsRetrieveRequest { /// /// A comma seperated list of Common Model names. If included, will only return Remote Fields for those Common Models. /// - public string? CommonModels { get; init; } + public string? CommonModels { get; set; } /// /// If true, will include example values, where available, for remote fields in the 3rd party platform. These examples come from active data from your customers. /// - public string? IncludeExampleValues { get; init; } + public string? IncludeExampleValues { get; set; } } diff --git a/src/Merge.Client/Filestorage/Files/FilesClient.cs b/src/Merge.Client/Filestorage/Files/FilesClient.cs index 1ddb37cb..e9445e08 100644 --- a/src/Merge.Client/Filestorage/Files/FilesClient.cs +++ b/src/Merge.Client/Filestorage/Files/FilesClient.cs @@ -1,6 +1,6 @@ +using System.Net.Http; using System.Text.Json; -using Merge.Client; -using Merge.Client.Filestorage; +using Merge.Client.Core; #nullable enable @@ -18,16 +18,21 @@ public FilesClient(RawClient client) /// /// Returns a list of `File` objects. /// - public async Task ListAsync(FilesListRequest request) + public async Task ListAsync( + FilesListRequest request, + RequestOptions? options = null + ) { var _query = new Dictionary() { }; if (request.CreatedAfter != null) { - _query["created_after"] = request.CreatedAfter.Value.ToString("o0"); + _query["created_after"] = request.CreatedAfter.Value.ToString(Constants.DateTimeFormat); } if (request.CreatedBefore != null) { - _query["created_before"] = request.CreatedBefore.Value.ToString("o0"); + _query["created_before"] = request.CreatedBefore.Value.ToString( + Constants.DateTimeFormat + ); } if (request.Cursor != null) { @@ -59,11 +64,15 @@ public async Task ListAsync(FilesListRequest request) } if (request.ModifiedAfter != null) { - _query["modified_after"] = request.ModifiedAfter.Value.ToString("o0"); + _query["modified_after"] = request.ModifiedAfter.Value.ToString( + Constants.DateTimeFormat + ); } if (request.ModifiedBefore != null) { - _query["modified_before"] = request.ModifiedBefore.Value.ToString("o0"); + _query["modified_before"] = request.ModifiedBefore.Value.ToString( + Constants.DateTimeFormat + ); } if (request.Name != null) { @@ -80,23 +89,40 @@ public async Task ListAsync(FilesListRequest request) var response = await _client.MakeRequestAsync( new RawClient.JsonApiRequest { + BaseUrl = _client.Options.BaseUrl, Method = HttpMethod.Get, Path = "filestorage/v1/files", - Query = _query + Query = _query, + Options = options } ); - string responseBody = await response.Raw.Content.ReadAsStringAsync(); - if (response.StatusCode >= 200 && response.StatusCode < 400) + var responseBody = await response.Raw.Content.ReadAsStringAsync(); + if (response.StatusCode is >= 200 and < 400) { - return JsonSerializer.Deserialize(responseBody); + try + { + return JsonUtils.Deserialize(responseBody)!; + } + catch (JsonException e) + { + throw new MergeException("Failed to deserialize response", e); + } } - throw new Exception(responseBody); + + throw new MergeApiException( + $"Error with status code {response.StatusCode}", + response.StatusCode, + JsonUtils.Deserialize(responseBody) + ); } /// /// Creates a `File` object with the given values. /// - public async Task CreateAsync(FileStorageFileEndpointRequest request) + public async Task CreateAsync( + FileStorageFileEndpointRequest request, + RequestOptions? options = null + ) { var _query = new Dictionary() { }; if (request.IsDebugMode != null) @@ -110,23 +136,41 @@ public async Task CreateAsync(FileStorageFileEndpointRe var response = await _client.MakeRequestAsync( new RawClient.JsonApiRequest { + BaseUrl = _client.Options.BaseUrl, Method = HttpMethod.Post, Path = "filestorage/v1/files", - Query = _query + Query = _query, + Options = options } ); - string responseBody = await response.Raw.Content.ReadAsStringAsync(); - if (response.StatusCode >= 200 && response.StatusCode < 400) + var responseBody = await response.Raw.Content.ReadAsStringAsync(); + if (response.StatusCode is >= 200 and < 400) { - return JsonSerializer.Deserialize(responseBody); + try + { + return JsonUtils.Deserialize(responseBody)!; + } + catch (JsonException e) + { + throw new MergeException("Failed to deserialize response", e); + } } - throw new Exception(responseBody); + + throw new MergeApiException( + $"Error with status code {response.StatusCode}", + response.StatusCode, + JsonUtils.Deserialize(responseBody) + ); } /// /// Returns a `File` object with the given `id`. /// - public async Task RetrieveAsync(string id, FilesRetrieveRequest request) + public async Task RetrieveAsync( + string id, + FilesRetrieveRequest request, + RequestOptions? options = null + ) { var _query = new Dictionary() { }; if (request.Expand != null) @@ -140,23 +184,41 @@ public async Task RetrieveAsync(string id, FilesRetrieveRequest request) var response = await _client.MakeRequestAsync( new RawClient.JsonApiRequest { + BaseUrl = _client.Options.BaseUrl, Method = HttpMethod.Get, Path = $"filestorage/v1/files/{id}", - Query = _query + Query = _query, + Options = options } ); - string responseBody = await response.Raw.Content.ReadAsStringAsync(); - if (response.StatusCode >= 200 && response.StatusCode < 400) + var responseBody = await response.Raw.Content.ReadAsStringAsync(); + if (response.StatusCode is >= 200 and < 400) { - return JsonSerializer.Deserialize(responseBody); + try + { + return JsonUtils.Deserialize(responseBody)!; + } + catch (JsonException e) + { + throw new MergeException("Failed to deserialize response", e); + } } - throw new Exception(responseBody); + + throw new MergeApiException( + $"Error with status code {response.StatusCode}", + response.StatusCode, + JsonUtils.Deserialize(responseBody) + ); } /// /// Returns the `File` content with the given `id` as a stream of bytes. /// - public async void DownloadRetrieveAsync(string id, FilesDownloadRetrieveRequest request) + public async Task DownloadRetrieveAsync( + string id, + FilesDownloadRetrieveRequest request, + RequestOptions? options = null + ) { var _query = new Dictionary() { }; if (request.MimeType != null) @@ -166,30 +228,52 @@ public async void DownloadRetrieveAsync(string id, FilesDownloadRetrieveRequest var response = await _client.MakeRequestAsync( new RawClient.JsonApiRequest { + BaseUrl = _client.Options.BaseUrl, Method = HttpMethod.Get, Path = $"filestorage/v1/files/{id}/download", - Query = _query + Query = _query, + Options = options } ); + var responseBody = await response.Raw.Content.ReadAsStringAsync(); + throw new MergeApiException( + $"Error with status code {response.StatusCode}", + response.StatusCode, + JsonUtils.Deserialize(responseBody) + ); } /// /// Returns metadata for `FileStorageFile` POSTs. /// - public async Task MetaPostRetrieveAsync() + public async Task MetaPostRetrieveAsync(RequestOptions? options = null) { var response = await _client.MakeRequestAsync( new RawClient.JsonApiRequest { + BaseUrl = _client.Options.BaseUrl, Method = HttpMethod.Get, - Path = "filestorage/v1/files/meta/post" + Path = "filestorage/v1/files/meta/post", + Options = options } ); - string responseBody = await response.Raw.Content.ReadAsStringAsync(); - if (response.StatusCode >= 200 && response.StatusCode < 400) + var responseBody = await response.Raw.Content.ReadAsStringAsync(); + if (response.StatusCode is >= 200 and < 400) { - return JsonSerializer.Deserialize(responseBody); + try + { + return JsonUtils.Deserialize(responseBody)!; + } + catch (JsonException e) + { + throw new MergeException("Failed to deserialize response", e); + } } - throw new Exception(responseBody); + + throw new MergeApiException( + $"Error with status code {response.StatusCode}", + response.StatusCode, + JsonUtils.Deserialize(responseBody) + ); } } diff --git a/src/Merge.Client/Filestorage/Files/Requests/FileStorageFileEndpointRequest.cs b/src/Merge.Client/Filestorage/Files/Requests/FileStorageFileEndpointRequest.cs index 12af152b..4065a682 100644 --- a/src/Merge.Client/Filestorage/Files/Requests/FileStorageFileEndpointRequest.cs +++ b/src/Merge.Client/Filestorage/Files/Requests/FileStorageFileEndpointRequest.cs @@ -1,20 +1,16 @@ -using Merge.Client.Filestorage; - -#nullable enable - namespace Merge.Client.Filestorage; -public class FileStorageFileEndpointRequest +public record FileStorageFileEndpointRequest { /// /// Whether to include debug fields (such as log file links) in the response. /// - public bool? IsDebugMode { get; init; } + public bool? IsDebugMode { get; set; } /// /// Whether or not third-party updates should be run asynchronously. /// - public bool? RunAsync { get; init; } + public bool? RunAsync { get; set; } - public FileRequest Model { get; init; } + public required FileRequest Model { get; set; } } diff --git a/src/Merge.Client/Filestorage/Files/Requests/FilesDownloadRetrieveRequest.cs b/src/Merge.Client/Filestorage/Files/Requests/FilesDownloadRetrieveRequest.cs index 9871f6d3..b1bc5b14 100644 --- a/src/Merge.Client/Filestorage/Files/Requests/FilesDownloadRetrieveRequest.cs +++ b/src/Merge.Client/Filestorage/Files/Requests/FilesDownloadRetrieveRequest.cs @@ -1,9 +1,9 @@ namespace Merge.Client.Filestorage; -public class FilesDownloadRetrieveRequest +public record FilesDownloadRetrieveRequest { /// /// If provided, specifies the export format of the file to be downloaded. For information on supported export formats, please refer to our export format help center article. /// - public string? MimeType { get; init; } + public string? MimeType { get; set; } } diff --git a/src/Merge.Client/Filestorage/Files/Requests/FilesListRequest.cs b/src/Merge.Client/Filestorage/Files/Requests/FilesListRequest.cs index 79687258..0feb3979 100644 --- a/src/Merge.Client/Filestorage/Files/Requests/FilesListRequest.cs +++ b/src/Merge.Client/Filestorage/Files/Requests/FilesListRequest.cs @@ -1,78 +1,74 @@ -using Merge.Client.Filestorage; - -#nullable enable - namespace Merge.Client.Filestorage; -public class FilesListRequest +public record FilesListRequest { /// /// If provided, will only return objects created after this datetime. /// - public DateTime? CreatedAfter { get; init; } + public DateTime? CreatedAfter { get; set; } /// /// If provided, will only return objects created before this datetime. /// - public DateTime? CreatedBefore { get; init; } + public DateTime? CreatedBefore { get; set; } /// /// The pagination cursor value. /// - public string? Cursor { get; init; } + public string? Cursor { get; set; } /// /// Specifying a drive id returns only the files in that drive. Specifying null returns only the files outside the top-level drive. /// - public string? DriveId { get; init; } + public string? DriveId { get; set; } /// /// Which relations should be returned in expanded form. Multiple relation names should be comma separated without spaces. /// - public FilesListRequestExpand? Expand { get; init; } + public FilesListRequestExpand? Expand { get; set; } /// /// Specifying a folder id returns only the files in that folder. Specifying null returns only the files in root directory. /// - public string? FolderId { get; init; } + public string? FolderId { get; set; } /// /// Whether to include data that was marked as deleted by third party webhooks. /// - public bool? IncludeDeletedData { get; init; } + public bool? IncludeDeletedData { get; set; } /// /// Whether to include the original data Merge fetched from the third-party to produce these models. /// - public bool? IncludeRemoteData { get; init; } + public bool? IncludeRemoteData { get; set; } /// /// If provided, will only return files with these mime_types. Multiple values can be separated by commas. /// - public string? MimeType { get; init; } + public string? MimeType { get; set; } /// /// If provided, only objects synced by Merge after this date time will be returned. /// - public DateTime? ModifiedAfter { get; init; } + public DateTime? ModifiedAfter { get; set; } /// /// If provided, only objects synced by Merge before this date time will be returned. /// - public DateTime? ModifiedBefore { get; init; } + public DateTime? ModifiedBefore { get; set; } /// /// If provided, will only return files with this name. This performs an exact match. /// - public string? Name { get; init; } + public string? Name { get; set; } /// /// Number of results to return per page. /// - public int? PageSize { get; init; } + public int? PageSize { get; set; } /// /// The API provider's ID for the given object. /// - public string? RemoteId { get; init; } + public string? RemoteId { get; set; } } diff --git a/src/Merge.Client/Filestorage/Files/Requests/FilesRetrieveRequest.cs b/src/Merge.Client/Filestorage/Files/Requests/FilesRetrieveRequest.cs index e3a1a103..12d6af3d 100644 --- a/src/Merge.Client/Filestorage/Files/Requests/FilesRetrieveRequest.cs +++ b/src/Merge.Client/Filestorage/Files/Requests/FilesRetrieveRequest.cs @@ -1,18 +1,14 @@ -using Merge.Client.Filestorage; - -#nullable enable - namespace Merge.Client.Filestorage; -public class FilesRetrieveRequest +public record FilesRetrieveRequest { /// /// Which relations should be returned in expanded form. Multiple relation names should be comma separated without spaces. /// - public FilesRetrieveRequestExpand? Expand { get; init; } + public FilesRetrieveRequestExpand? Expand { get; set; } /// /// Whether to include the original data Merge fetched from the third-party to produce these models. /// - public bool? IncludeRemoteData { get; init; } + public bool? IncludeRemoteData { get; set; } } diff --git a/src/Merge.Client/Filestorage/Files/Types/FilesListRequestExpand.cs b/src/Merge.Client/Filestorage/Files/Types/FilesListRequestExpand.cs index da845d7b..732c8518 100644 --- a/src/Merge.Client/Filestorage/Files/Types/FilesListRequestExpand.cs +++ b/src/Merge.Client/Filestorage/Files/Types/FilesListRequestExpand.cs @@ -1,7 +1,6 @@ using System.Runtime.Serialization; using System.Text.Json.Serialization; using Merge.Client.Core; -using Merge.Client.Filestorage; #nullable enable diff --git a/src/Merge.Client/Filestorage/Files/Types/FilesRetrieveRequestExpand.cs b/src/Merge.Client/Filestorage/Files/Types/FilesRetrieveRequestExpand.cs index e7344d7e..c7346ef4 100644 --- a/src/Merge.Client/Filestorage/Files/Types/FilesRetrieveRequestExpand.cs +++ b/src/Merge.Client/Filestorage/Files/Types/FilesRetrieveRequestExpand.cs @@ -1,7 +1,6 @@ using System.Runtime.Serialization; using System.Text.Json.Serialization; using Merge.Client.Core; -using Merge.Client.Filestorage; #nullable enable diff --git a/src/Merge.Client/Filestorage/FilestorageClient.cs b/src/Merge.Client/Filestorage/FilestorageClient.cs index 13c285c4..9edca3a4 100644 --- a/src/Merge.Client/Filestorage/FilestorageClient.cs +++ b/src/Merge.Client/Filestorage/FilestorageClient.cs @@ -1,5 +1,4 @@ -using Merge.Client; -using Merge.Client.Filestorage; +using Merge.Client.Core; #nullable enable diff --git a/src/Merge.Client/Filestorage/Folders/FoldersClient.cs b/src/Merge.Client/Filestorage/Folders/FoldersClient.cs index 9204e1f0..650b16ad 100644 --- a/src/Merge.Client/Filestorage/Folders/FoldersClient.cs +++ b/src/Merge.Client/Filestorage/Folders/FoldersClient.cs @@ -1,6 +1,6 @@ +using System.Net.Http; using System.Text.Json; -using Merge.Client; -using Merge.Client.Filestorage; +using Merge.Client.Core; #nullable enable @@ -18,16 +18,21 @@ public FoldersClient(RawClient client) /// /// Returns a list of `Folder` objects. /// - public async Task ListAsync(FoldersListRequest request) + public async Task ListAsync( + FoldersListRequest request, + RequestOptions? options = null + ) { var _query = new Dictionary() { }; if (request.CreatedAfter != null) { - _query["created_after"] = request.CreatedAfter.Value.ToString("o0"); + _query["created_after"] = request.CreatedAfter.Value.ToString(Constants.DateTimeFormat); } if (request.CreatedBefore != null) { - _query["created_before"] = request.CreatedBefore.Value.ToString("o0"); + _query["created_before"] = request.CreatedBefore.Value.ToString( + Constants.DateTimeFormat + ); } if (request.Cursor != null) { @@ -51,11 +56,15 @@ public async Task ListAsync(FoldersListRequest request) } if (request.ModifiedAfter != null) { - _query["modified_after"] = request.ModifiedAfter.Value.ToString("o0"); + _query["modified_after"] = request.ModifiedAfter.Value.ToString( + Constants.DateTimeFormat + ); } if (request.ModifiedBefore != null) { - _query["modified_before"] = request.ModifiedBefore.Value.ToString("o0"); + _query["modified_before"] = request.ModifiedBefore.Value.ToString( + Constants.DateTimeFormat + ); } if (request.Name != null) { @@ -76,24 +85,39 @@ public async Task ListAsync(FoldersListRequest request) var response = await _client.MakeRequestAsync( new RawClient.JsonApiRequest { + BaseUrl = _client.Options.BaseUrl, Method = HttpMethod.Get, Path = "filestorage/v1/folders", - Query = _query + Query = _query, + Options = options } ); - string responseBody = await response.Raw.Content.ReadAsStringAsync(); - if (response.StatusCode >= 200 && response.StatusCode < 400) + var responseBody = await response.Raw.Content.ReadAsStringAsync(); + if (response.StatusCode is >= 200 and < 400) { - return JsonSerializer.Deserialize(responseBody); + try + { + return JsonUtils.Deserialize(responseBody)!; + } + catch (JsonException e) + { + throw new MergeException("Failed to deserialize response", e); + } } - throw new Exception(responseBody); + + throw new MergeApiException( + $"Error with status code {response.StatusCode}", + response.StatusCode, + JsonUtils.Deserialize(responseBody) + ); } /// /// Creates a `Folder` object with the given values. /// public async Task CreateAsync( - FileStorageFolderEndpointRequest request + FileStorageFolderEndpointRequest request, + RequestOptions? options = null ) { var _query = new Dictionary() { }; @@ -108,23 +132,41 @@ FileStorageFolderEndpointRequest request var response = await _client.MakeRequestAsync( new RawClient.JsonApiRequest { + BaseUrl = _client.Options.BaseUrl, Method = HttpMethod.Post, Path = "filestorage/v1/folders", - Query = _query + Query = _query, + Options = options } ); - string responseBody = await response.Raw.Content.ReadAsStringAsync(); - if (response.StatusCode >= 200 && response.StatusCode < 400) + var responseBody = await response.Raw.Content.ReadAsStringAsync(); + if (response.StatusCode is >= 200 and < 400) { - return JsonSerializer.Deserialize(responseBody); + try + { + return JsonUtils.Deserialize(responseBody)!; + } + catch (JsonException e) + { + throw new MergeException("Failed to deserialize response", e); + } } - throw new Exception(responseBody); + + throw new MergeApiException( + $"Error with status code {response.StatusCode}", + response.StatusCode, + JsonUtils.Deserialize(responseBody) + ); } /// /// Returns a `Folder` object with the given `id`. /// - public async Task RetrieveAsync(string id, FoldersRetrieveRequest request) + public async Task RetrieveAsync( + string id, + FoldersRetrieveRequest request, + RequestOptions? options = null + ) { var _query = new Dictionary() { }; if (request.Expand != null) @@ -138,36 +180,64 @@ public async Task RetrieveAsync(string id, FoldersRetrieveRequest reques var response = await _client.MakeRequestAsync( new RawClient.JsonApiRequest { + BaseUrl = _client.Options.BaseUrl, Method = HttpMethod.Get, Path = $"filestorage/v1/folders/{id}", - Query = _query + Query = _query, + Options = options } ); - string responseBody = await response.Raw.Content.ReadAsStringAsync(); - if (response.StatusCode >= 200 && response.StatusCode < 400) + var responseBody = await response.Raw.Content.ReadAsStringAsync(); + if (response.StatusCode is >= 200 and < 400) { - return JsonSerializer.Deserialize(responseBody); + try + { + return JsonUtils.Deserialize(responseBody)!; + } + catch (JsonException e) + { + throw new MergeException("Failed to deserialize response", e); + } } - throw new Exception(responseBody); + + throw new MergeApiException( + $"Error with status code {response.StatusCode}", + response.StatusCode, + JsonUtils.Deserialize(responseBody) + ); } /// /// Returns metadata for `FileStorageFolder` POSTs. /// - public async Task MetaPostRetrieveAsync() + public async Task MetaPostRetrieveAsync(RequestOptions? options = null) { var response = await _client.MakeRequestAsync( new RawClient.JsonApiRequest { + BaseUrl = _client.Options.BaseUrl, Method = HttpMethod.Get, - Path = "filestorage/v1/folders/meta/post" + Path = "filestorage/v1/folders/meta/post", + Options = options } ); - string responseBody = await response.Raw.Content.ReadAsStringAsync(); - if (response.StatusCode >= 200 && response.StatusCode < 400) + var responseBody = await response.Raw.Content.ReadAsStringAsync(); + if (response.StatusCode is >= 200 and < 400) { - return JsonSerializer.Deserialize(responseBody); + try + { + return JsonUtils.Deserialize(responseBody)!; + } + catch (JsonException e) + { + throw new MergeException("Failed to deserialize response", e); + } } - throw new Exception(responseBody); + + throw new MergeApiException( + $"Error with status code {response.StatusCode}", + response.StatusCode, + JsonUtils.Deserialize(responseBody) + ); } } diff --git a/src/Merge.Client/Filestorage/Folders/Requests/FileStorageFolderEndpointRequest.cs b/src/Merge.Client/Filestorage/Folders/Requests/FileStorageFolderEndpointRequest.cs index 49ea9e6c..a6162954 100644 --- a/src/Merge.Client/Filestorage/Folders/Requests/FileStorageFolderEndpointRequest.cs +++ b/src/Merge.Client/Filestorage/Folders/Requests/FileStorageFolderEndpointRequest.cs @@ -1,20 +1,16 @@ -using Merge.Client.Filestorage; - -#nullable enable - namespace Merge.Client.Filestorage; -public class FileStorageFolderEndpointRequest +public record FileStorageFolderEndpointRequest { /// /// Whether to include debug fields (such as log file links) in the response. /// - public bool? IsDebugMode { get; init; } + public bool? IsDebugMode { get; set; } /// /// Whether or not third-party updates should be run asynchronously. /// - public bool? RunAsync { get; init; } + public bool? RunAsync { get; set; } - public FolderRequest Model { get; init; } + public required FolderRequest Model { get; set; } } diff --git a/src/Merge.Client/Filestorage/Folders/Requests/FoldersListRequest.cs b/src/Merge.Client/Filestorage/Folders/Requests/FoldersListRequest.cs index fe3714a9..2c3b633d 100644 --- a/src/Merge.Client/Filestorage/Folders/Requests/FoldersListRequest.cs +++ b/src/Merge.Client/Filestorage/Folders/Requests/FoldersListRequest.cs @@ -1,73 +1,69 @@ -using Merge.Client.Filestorage; - -#nullable enable - namespace Merge.Client.Filestorage; -public class FoldersListRequest +public record FoldersListRequest { /// /// If provided, will only return objects created after this datetime. /// - public DateTime? CreatedAfter { get; init; } + public DateTime? CreatedAfter { get; set; } /// /// If provided, will only return objects created before this datetime. /// - public DateTime? CreatedBefore { get; init; } + public DateTime? CreatedBefore { get; set; } /// /// The pagination cursor value. /// - public string? Cursor { get; init; } + public string? Cursor { get; set; } /// /// If provided, will only return folders in this drive. /// - public string? DriveId { get; init; } + public string? DriveId { get; set; } /// /// Which relations should be returned in expanded form. Multiple relation names should be comma separated without spaces. /// - public FoldersListRequestExpand? Expand { get; init; } + public FoldersListRequestExpand? Expand { get; set; } /// /// Whether to include data that was marked as deleted by third party webhooks. /// - public bool? IncludeDeletedData { get; init; } + public bool? IncludeDeletedData { get; set; } /// /// Whether to include the original data Merge fetched from the third-party to produce these models. /// - public bool? IncludeRemoteData { get; init; } + public bool? IncludeRemoteData { get; set; } /// /// If provided, only objects synced by Merge after this date time will be returned. /// - public DateTime? ModifiedAfter { get; init; } + public DateTime? ModifiedAfter { get; set; } /// /// If provided, only objects synced by Merge before this date time will be returned. /// - public DateTime? ModifiedBefore { get; init; } + public DateTime? ModifiedBefore { get; set; } /// /// If provided, will only return folders with this name. This performs an exact match. /// - public string? Name { get; init; } + public string? Name { get; set; } /// /// Number of results to return per page. /// - public int? PageSize { get; init; } + public int? PageSize { get; set; } /// /// If provided, will only return folders in this parent folder. If null, will return folders in root directory. /// - public string? ParentFolderId { get; init; } + public string? ParentFolderId { get; set; } /// /// The API provider's ID for the given object. /// - public string? RemoteId { get; init; } + public string? RemoteId { get; set; } } diff --git a/src/Merge.Client/Filestorage/Folders/Requests/FoldersRetrieveRequest.cs b/src/Merge.Client/Filestorage/Folders/Requests/FoldersRetrieveRequest.cs index 327595c6..a56234d0 100644 --- a/src/Merge.Client/Filestorage/Folders/Requests/FoldersRetrieveRequest.cs +++ b/src/Merge.Client/Filestorage/Folders/Requests/FoldersRetrieveRequest.cs @@ -1,18 +1,14 @@ -using Merge.Client.Filestorage; - -#nullable enable - namespace Merge.Client.Filestorage; -public class FoldersRetrieveRequest +public record FoldersRetrieveRequest { /// /// Which relations should be returned in expanded form. Multiple relation names should be comma separated without spaces. /// - public FoldersRetrieveRequestExpand? Expand { get; init; } + public FoldersRetrieveRequestExpand? Expand { get; set; } /// /// Whether to include the original data Merge fetched from the third-party to produce these models. /// - public bool? IncludeRemoteData { get; init; } + public bool? IncludeRemoteData { get; set; } } diff --git a/src/Merge.Client/Filestorage/Folders/Types/FoldersListRequestExpand.cs b/src/Merge.Client/Filestorage/Folders/Types/FoldersListRequestExpand.cs index d6ddac62..d1679f63 100644 --- a/src/Merge.Client/Filestorage/Folders/Types/FoldersListRequestExpand.cs +++ b/src/Merge.Client/Filestorage/Folders/Types/FoldersListRequestExpand.cs @@ -1,7 +1,6 @@ using System.Runtime.Serialization; using System.Text.Json.Serialization; using Merge.Client.Core; -using Merge.Client.Filestorage; #nullable enable diff --git a/src/Merge.Client/Filestorage/Folders/Types/FoldersRetrieveRequestExpand.cs b/src/Merge.Client/Filestorage/Folders/Types/FoldersRetrieveRequestExpand.cs index b8932f60..f7bf26f1 100644 --- a/src/Merge.Client/Filestorage/Folders/Types/FoldersRetrieveRequestExpand.cs +++ b/src/Merge.Client/Filestorage/Folders/Types/FoldersRetrieveRequestExpand.cs @@ -1,7 +1,6 @@ using System.Runtime.Serialization; using System.Text.Json.Serialization; using Merge.Client.Core; -using Merge.Client.Filestorage; #nullable enable diff --git a/src/Merge.Client/Filestorage/ForceResync/ForceResyncClient.cs b/src/Merge.Client/Filestorage/ForceResync/ForceResyncClient.cs index bee403dd..0198221d 100644 --- a/src/Merge.Client/Filestorage/ForceResync/ForceResyncClient.cs +++ b/src/Merge.Client/Filestorage/ForceResync/ForceResyncClient.cs @@ -1,6 +1,6 @@ +using System.Net.Http; using System.Text.Json; -using Merge.Client; -using Merge.Client.Filestorage; +using Merge.Client.Core; #nullable enable @@ -18,20 +18,36 @@ public ForceResyncClient(RawClient client) /// /// Force re-sync of all models. This is available for all organizations via the dashboard. Force re-sync is also available programmatically via API for monthly, quarterly, and highest sync frequency customers on the Launch, Professional, or Enterprise plans. Doing so will consume a sync credit for the relevant linked account. /// - public async Task> SyncStatusResyncCreateAsync() + public async Task> SyncStatusResyncCreateAsync( + RequestOptions? options = null + ) { var response = await _client.MakeRequestAsync( new RawClient.JsonApiRequest { + BaseUrl = _client.Options.BaseUrl, Method = HttpMethod.Post, - Path = "filestorage/v1/sync-status/resync" + Path = "filestorage/v1/sync-status/resync", + Options = options } ); - string responseBody = await response.Raw.Content.ReadAsStringAsync(); - if (response.StatusCode >= 200 && response.StatusCode < 400) + var responseBody = await response.Raw.Content.ReadAsStringAsync(); + if (response.StatusCode is >= 200 and < 400) { - return JsonSerializer.Deserialize>(responseBody); + try + { + return JsonUtils.Deserialize>(responseBody)!; + } + catch (JsonException e) + { + throw new MergeException("Failed to deserialize response", e); + } } - throw new Exception(responseBody); + + throw new MergeApiException( + $"Error with status code {response.StatusCode}", + response.StatusCode, + JsonUtils.Deserialize(responseBody) + ); } } diff --git a/src/Merge.Client/Filestorage/GenerateKey/GenerateKeyClient.cs b/src/Merge.Client/Filestorage/GenerateKey/GenerateKeyClient.cs index be89818d..9b1e4b16 100644 --- a/src/Merge.Client/Filestorage/GenerateKey/GenerateKeyClient.cs +++ b/src/Merge.Client/Filestorage/GenerateKey/GenerateKeyClient.cs @@ -1,6 +1,6 @@ +using System.Net.Http; using System.Text.Json; -using Merge.Client; -using Merge.Client.Filestorage; +using Merge.Client.Core; #nullable enable @@ -18,21 +18,38 @@ public GenerateKeyClient(RawClient client) /// /// Create a remote key. /// - public async Task CreateAsync(GenerateRemoteKeyRequest request) + public async Task CreateAsync( + GenerateRemoteKeyRequest request, + RequestOptions? options = null + ) { var response = await _client.MakeRequestAsync( new RawClient.JsonApiRequest { + BaseUrl = _client.Options.BaseUrl, Method = HttpMethod.Post, Path = "filestorage/v1/generate-key", - Body = request + Body = request, + Options = options } ); - string responseBody = await response.Raw.Content.ReadAsStringAsync(); - if (response.StatusCode >= 200 && response.StatusCode < 400) + var responseBody = await response.Raw.Content.ReadAsStringAsync(); + if (response.StatusCode is >= 200 and < 400) { - return JsonSerializer.Deserialize(responseBody); + try + { + return JsonUtils.Deserialize(responseBody)!; + } + catch (JsonException e) + { + throw new MergeException("Failed to deserialize response", e); + } } - throw new Exception(responseBody); + + throw new MergeApiException( + $"Error with status code {response.StatusCode}", + response.StatusCode, + JsonUtils.Deserialize(responseBody) + ); } } diff --git a/src/Merge.Client/Filestorage/GenerateKey/Requests/GenerateRemoteKeyRequest.cs b/src/Merge.Client/Filestorage/GenerateKey/Requests/GenerateRemoteKeyRequest.cs index 34a7ad87..234c6c34 100644 --- a/src/Merge.Client/Filestorage/GenerateKey/Requests/GenerateRemoteKeyRequest.cs +++ b/src/Merge.Client/Filestorage/GenerateKey/Requests/GenerateRemoteKeyRequest.cs @@ -4,11 +4,11 @@ namespace Merge.Client.Filestorage; -public class GenerateRemoteKeyRequest +public record GenerateRemoteKeyRequest { /// /// The name of the remote key /// [JsonPropertyName("name")] - public string Name { get; init; } + public required string Name { get; set; } } diff --git a/src/Merge.Client/Filestorage/Groups/GroupsClient.cs b/src/Merge.Client/Filestorage/Groups/GroupsClient.cs index be0b031c..696e5865 100644 --- a/src/Merge.Client/Filestorage/Groups/GroupsClient.cs +++ b/src/Merge.Client/Filestorage/Groups/GroupsClient.cs @@ -1,6 +1,6 @@ +using System.Net.Http; using System.Text.Json; -using Merge.Client; -using Merge.Client.Filestorage; +using Merge.Client.Core; #nullable enable @@ -18,16 +18,21 @@ public GroupsClient(RawClient client) /// /// Returns a list of `Group` objects. /// - public async Task ListAsync(GroupsListRequest request) + public async Task ListAsync( + GroupsListRequest request, + RequestOptions? options = null + ) { var _query = new Dictionary() { }; if (request.CreatedAfter != null) { - _query["created_after"] = request.CreatedAfter.Value.ToString("o0"); + _query["created_after"] = request.CreatedAfter.Value.ToString(Constants.DateTimeFormat); } if (request.CreatedBefore != null) { - _query["created_before"] = request.CreatedBefore.Value.ToString("o0"); + _query["created_before"] = request.CreatedBefore.Value.ToString( + Constants.DateTimeFormat + ); } if (request.Cursor != null) { @@ -43,11 +48,15 @@ public async Task ListAsync(GroupsListRequest request) } if (request.ModifiedAfter != null) { - _query["modified_after"] = request.ModifiedAfter.Value.ToString("o0"); + _query["modified_after"] = request.ModifiedAfter.Value.ToString( + Constants.DateTimeFormat + ); } if (request.ModifiedBefore != null) { - _query["modified_before"] = request.ModifiedBefore.Value.ToString("o0"); + _query["modified_before"] = request.ModifiedBefore.Value.ToString( + Constants.DateTimeFormat + ); } if (request.PageSize != null) { @@ -60,23 +69,41 @@ public async Task ListAsync(GroupsListRequest request) var response = await _client.MakeRequestAsync( new RawClient.JsonApiRequest { + BaseUrl = _client.Options.BaseUrl, Method = HttpMethod.Get, Path = "filestorage/v1/groups", - Query = _query + Query = _query, + Options = options } ); - string responseBody = await response.Raw.Content.ReadAsStringAsync(); - if (response.StatusCode >= 200 && response.StatusCode < 400) + var responseBody = await response.Raw.Content.ReadAsStringAsync(); + if (response.StatusCode is >= 200 and < 400) { - return JsonSerializer.Deserialize(responseBody); + try + { + return JsonUtils.Deserialize(responseBody)!; + } + catch (JsonException e) + { + throw new MergeException("Failed to deserialize response", e); + } } - throw new Exception(responseBody); + + throw new MergeApiException( + $"Error with status code {response.StatusCode}", + response.StatusCode, + JsonUtils.Deserialize(responseBody) + ); } /// /// Returns a `Group` object with the given `id`. /// - public async Task RetrieveAsync(string id, GroupsRetrieveRequest request) + public async Task RetrieveAsync( + string id, + GroupsRetrieveRequest request, + RequestOptions? options = null + ) { var _query = new Dictionary() { }; if (request.IncludeRemoteData != null) @@ -86,16 +113,30 @@ public async Task RetrieveAsync(string id, GroupsRetrieveRequest request) var response = await _client.MakeRequestAsync( new RawClient.JsonApiRequest { + BaseUrl = _client.Options.BaseUrl, Method = HttpMethod.Get, Path = $"filestorage/v1/groups/{id}", - Query = _query + Query = _query, + Options = options } ); - string responseBody = await response.Raw.Content.ReadAsStringAsync(); - if (response.StatusCode >= 200 && response.StatusCode < 400) + var responseBody = await response.Raw.Content.ReadAsStringAsync(); + if (response.StatusCode is >= 200 and < 400) { - return JsonSerializer.Deserialize(responseBody); + try + { + return JsonUtils.Deserialize(responseBody)!; + } + catch (JsonException e) + { + throw new MergeException("Failed to deserialize response", e); + } } - throw new Exception(responseBody); + + throw new MergeApiException( + $"Error with status code {response.StatusCode}", + response.StatusCode, + JsonUtils.Deserialize(responseBody) + ); } } diff --git a/src/Merge.Client/Filestorage/Groups/Requests/GroupsListRequest.cs b/src/Merge.Client/Filestorage/Groups/Requests/GroupsListRequest.cs index f6032bf4..7546bf61 100644 --- a/src/Merge.Client/Filestorage/Groups/Requests/GroupsListRequest.cs +++ b/src/Merge.Client/Filestorage/Groups/Requests/GroupsListRequest.cs @@ -1,49 +1,49 @@ namespace Merge.Client.Filestorage; -public class GroupsListRequest +public record GroupsListRequest { /// /// If provided, will only return objects created after this datetime. /// - public DateTime? CreatedAfter { get; init; } + public DateTime? CreatedAfter { get; set; } /// /// If provided, will only return objects created before this datetime. /// - public DateTime? CreatedBefore { get; init; } + public DateTime? CreatedBefore { get; set; } /// /// The pagination cursor value. /// - public string? Cursor { get; init; } + public string? Cursor { get; set; } /// /// Whether to include data that was marked as deleted by third party webhooks. /// - public bool? IncludeDeletedData { get; init; } + public bool? IncludeDeletedData { get; set; } /// /// Whether to include the original data Merge fetched from the third-party to produce these models. /// - public bool? IncludeRemoteData { get; init; } + public bool? IncludeRemoteData { get; set; } /// /// If provided, only objects synced by Merge after this date time will be returned. /// - public DateTime? ModifiedAfter { get; init; } + public DateTime? ModifiedAfter { get; set; } /// /// If provided, only objects synced by Merge before this date time will be returned. /// - public DateTime? ModifiedBefore { get; init; } + public DateTime? ModifiedBefore { get; set; } /// /// Number of results to return per page. /// - public int? PageSize { get; init; } + public int? PageSize { get; set; } /// /// The API provider's ID for the given object. /// - public string? RemoteId { get; init; } + public string? RemoteId { get; set; } } diff --git a/src/Merge.Client/Filestorage/Groups/Requests/GroupsRetrieveRequest.cs b/src/Merge.Client/Filestorage/Groups/Requests/GroupsRetrieveRequest.cs index f77f0bc5..76164d26 100644 --- a/src/Merge.Client/Filestorage/Groups/Requests/GroupsRetrieveRequest.cs +++ b/src/Merge.Client/Filestorage/Groups/Requests/GroupsRetrieveRequest.cs @@ -1,9 +1,9 @@ namespace Merge.Client.Filestorage; -public class GroupsRetrieveRequest +public record GroupsRetrieveRequest { /// /// Whether to include the original data Merge fetched from the third-party to produce these models. /// - public bool? IncludeRemoteData { get; init; } + public bool? IncludeRemoteData { get; set; } } diff --git a/src/Merge.Client/Filestorage/Issues/IssuesClient.cs b/src/Merge.Client/Filestorage/Issues/IssuesClient.cs index 21eabe47..21ca912e 100644 --- a/src/Merge.Client/Filestorage/Issues/IssuesClient.cs +++ b/src/Merge.Client/Filestorage/Issues/IssuesClient.cs @@ -1,6 +1,6 @@ +using System.Net.Http; using System.Text.Json; -using Merge.Client; -using Merge.Client.Filestorage; +using Merge.Client.Core; #nullable enable @@ -18,7 +18,10 @@ public IssuesClient(RawClient client) /// /// Gets all issues for Organization. /// - public async Task ListAsync(IssuesListRequest request) + public async Task ListAsync( + IssuesListRequest request, + RequestOptions? options = null + ) { var _query = new Dictionary() { }; if (request.AccountToken != null) @@ -40,13 +43,13 @@ public async Task ListAsync(IssuesListRequest request) if (request.FirstIncidentTimeAfter != null) { _query["first_incident_time_after"] = request.FirstIncidentTimeAfter.Value.ToString( - "o0" + Constants.DateTimeFormat ); } if (request.FirstIncidentTimeBefore != null) { _query["first_incident_time_before"] = request.FirstIncidentTimeBefore.Value.ToString( - "o0" + Constants.DateTimeFormat ); } if (request.IncludeMuted != null) @@ -59,12 +62,14 @@ public async Task ListAsync(IssuesListRequest request) } if (request.LastIncidentTimeAfter != null) { - _query["last_incident_time_after"] = request.LastIncidentTimeAfter.Value.ToString("o0"); + _query["last_incident_time_after"] = request.LastIncidentTimeAfter.Value.ToString( + Constants.DateTimeFormat + ); } if (request.LastIncidentTimeBefore != null) { _query["last_incident_time_before"] = request.LastIncidentTimeBefore.Value.ToString( - "o0" + Constants.DateTimeFormat ); } if (request.LinkedAccountId != null) @@ -86,36 +91,64 @@ public async Task ListAsync(IssuesListRequest request) var response = await _client.MakeRequestAsync( new RawClient.JsonApiRequest { + BaseUrl = _client.Options.BaseUrl, Method = HttpMethod.Get, Path = "filestorage/v1/issues", - Query = _query + Query = _query, + Options = options } ); - string responseBody = await response.Raw.Content.ReadAsStringAsync(); - if (response.StatusCode >= 200 && response.StatusCode < 400) + var responseBody = await response.Raw.Content.ReadAsStringAsync(); + if (response.StatusCode is >= 200 and < 400) { - return JsonSerializer.Deserialize(responseBody); + try + { + return JsonUtils.Deserialize(responseBody)!; + } + catch (JsonException e) + { + throw new MergeException("Failed to deserialize response", e); + } } - throw new Exception(responseBody); + + throw new MergeApiException( + $"Error with status code {response.StatusCode}", + response.StatusCode, + JsonUtils.Deserialize(responseBody) + ); } /// /// Get a specific issue. /// - public async Task RetrieveAsync(string id) + public async Task RetrieveAsync(string id, RequestOptions? options = null) { var response = await _client.MakeRequestAsync( new RawClient.JsonApiRequest { + BaseUrl = _client.Options.BaseUrl, Method = HttpMethod.Get, - Path = $"filestorage/v1/issues/{id}" + Path = $"filestorage/v1/issues/{id}", + Options = options } ); - string responseBody = await response.Raw.Content.ReadAsStringAsync(); - if (response.StatusCode >= 200 && response.StatusCode < 400) + var responseBody = await response.Raw.Content.ReadAsStringAsync(); + if (response.StatusCode is >= 200 and < 400) { - return JsonSerializer.Deserialize(responseBody); + try + { + return JsonUtils.Deserialize(responseBody)!; + } + catch (JsonException e) + { + throw new MergeException("Failed to deserialize response", e); + } } - throw new Exception(responseBody); + + throw new MergeApiException( + $"Error with status code {response.StatusCode}", + response.StatusCode, + JsonUtils.Deserialize(responseBody) + ); } } diff --git a/src/Merge.Client/Filestorage/Issues/Requests/IssuesListRequest.cs b/src/Merge.Client/Filestorage/Issues/Requests/IssuesListRequest.cs index af98361d..f5006e62 100644 --- a/src/Merge.Client/Filestorage/Issues/Requests/IssuesListRequest.cs +++ b/src/Merge.Client/Filestorage/Issues/Requests/IssuesListRequest.cs @@ -1,66 +1,62 @@ -using Merge.Client.Filestorage; - -#nullable enable - namespace Merge.Client.Filestorage; -public class IssuesListRequest +public record IssuesListRequest { - public string? AccountToken { get; init; } + public string? AccountToken { get; set; } /// /// The pagination cursor value. /// - public string? Cursor { get; init; } + public string? Cursor { get; set; } /// /// If included, will only include issues whose most recent action occurred before this time /// - public string? EndDate { get; init; } + public string? EndDate { get; set; } - public string? EndUserOrganizationName { get; init; } + public string? EndUserOrganizationName { get; set; } /// /// If provided, will only return issues whose first incident time was after this datetime. /// - public DateTime? FirstIncidentTimeAfter { get; init; } + public DateTime? FirstIncidentTimeAfter { get; set; } /// /// If provided, will only return issues whose first incident time was before this datetime. /// - public DateTime? FirstIncidentTimeBefore { get; init; } + public DateTime? FirstIncidentTimeBefore { get; set; } /// /// If true, will include muted issues /// - public string? IncludeMuted { get; init; } + public string? IncludeMuted { get; set; } - public string? IntegrationName { get; init; } + public string? IntegrationName { get; set; } /// /// If provided, will only return issues whose last incident time was after this datetime. /// - public DateTime? LastIncidentTimeAfter { get; init; } + public DateTime? LastIncidentTimeAfter { get; set; } /// /// If provided, will only return issues whose last incident time was before this datetime. /// - public DateTime? LastIncidentTimeBefore { get; init; } + public DateTime? LastIncidentTimeBefore { get; set; } /// /// If provided, will only include issues pertaining to the linked account passed in. /// - public string? LinkedAccountId { get; init; } + public string? LinkedAccountId { get; set; } /// /// Number of results to return per page. /// - public int? PageSize { get; init; } + public int? PageSize { get; set; } /// /// If included, will only include issues whose most recent action occurred after this time /// - public string? StartDate { get; init; } + public string? StartDate { get; set; } /// /// Status of the issue. Options: ('ONGOING', 'RESOLVED') @@ -68,5 +64,5 @@ public class IssuesListRequest /// - `ONGOING` - ONGOING /// - `RESOLVED` - RESOLVED /// - public IssuesListRequestStatus? Status { get; init; } + public IssuesListRequestStatus? Status { get; set; } } diff --git a/src/Merge.Client/Filestorage/Issues/Types/IssuesListRequestStatus.cs b/src/Merge.Client/Filestorage/Issues/Types/IssuesListRequestStatus.cs index 2f21c673..9dee1009 100644 --- a/src/Merge.Client/Filestorage/Issues/Types/IssuesListRequestStatus.cs +++ b/src/Merge.Client/Filestorage/Issues/Types/IssuesListRequestStatus.cs @@ -1,7 +1,6 @@ using System.Runtime.Serialization; using System.Text.Json.Serialization; using Merge.Client.Core; -using Merge.Client.Filestorage; #nullable enable diff --git a/src/Merge.Client/Filestorage/LinkToken/LinkTokenClient.cs b/src/Merge.Client/Filestorage/LinkToken/LinkTokenClient.cs index 9cdb75ab..38907e7e 100644 --- a/src/Merge.Client/Filestorage/LinkToken/LinkTokenClient.cs +++ b/src/Merge.Client/Filestorage/LinkToken/LinkTokenClient.cs @@ -1,6 +1,6 @@ +using System.Net.Http; using System.Text.Json; -using Merge.Client; -using Merge.Client.Filestorage; +using Merge.Client.Core; #nullable enable @@ -18,21 +18,38 @@ public LinkTokenClient(RawClient client) /// /// Creates a link token to be used when linking a new end user. /// - public async Task CreateAsync(EndUserDetailsRequest request) + public async Task CreateAsync( + EndUserDetailsRequest request, + RequestOptions? options = null + ) { var response = await _client.MakeRequestAsync( new RawClient.JsonApiRequest { + BaseUrl = _client.Options.BaseUrl, Method = HttpMethod.Post, Path = "filestorage/v1/link-token", - Body = request + Body = request, + Options = options } ); - string responseBody = await response.Raw.Content.ReadAsStringAsync(); - if (response.StatusCode >= 200 && response.StatusCode < 400) + var responseBody = await response.Raw.Content.ReadAsStringAsync(); + if (response.StatusCode is >= 200 and < 400) { - return JsonSerializer.Deserialize(responseBody); + try + { + return JsonUtils.Deserialize(responseBody)!; + } + catch (JsonException e) + { + throw new MergeException("Failed to deserialize response", e); + } } - throw new Exception(responseBody); + + throw new MergeApiException( + $"Error with status code {response.StatusCode}", + response.StatusCode, + JsonUtils.Deserialize(responseBody) + ); } } diff --git a/src/Merge.Client/Filestorage/LinkToken/Requests/EndUserDetailsRequest.cs b/src/Merge.Client/Filestorage/LinkToken/Requests/EndUserDetailsRequest.cs index cd7130d4..292a6a34 100644 --- a/src/Merge.Client/Filestorage/LinkToken/Requests/EndUserDetailsRequest.cs +++ b/src/Merge.Client/Filestorage/LinkToken/Requests/EndUserDetailsRequest.cs @@ -1,65 +1,64 @@ using System.Text.Json.Serialization; -using Merge.Client.Filestorage; #nullable enable namespace Merge.Client.Filestorage; -public class EndUserDetailsRequest +public record EndUserDetailsRequest { /// /// Your end user's email address. This is purely for identification purposes - setting this value will not cause any emails to be sent. /// [JsonPropertyName("end_user_email_address")] - public string EndUserEmailAddress { get; init; } + public required string EndUserEmailAddress { get; set; } /// /// Your end user's organization. /// [JsonPropertyName("end_user_organization_name")] - public string EndUserOrganizationName { get; init; } + public required string EndUserOrganizationName { get; set; } /// /// This unique identifier typically represents the ID for your end user in your product's database. This value must be distinct from other Linked Accounts' unique identifiers. /// [JsonPropertyName("end_user_origin_id")] - public string EndUserOriginId { get; init; } + public required string EndUserOriginId { get; set; } /// /// The integration categories to show in Merge Link. /// [JsonPropertyName("categories")] - public IEnumerable Categories { get; init; } + public IEnumerable Categories { get; set; } = new List(); /// /// The slug of a specific pre-selected integration for this linking flow token. For examples of slugs, see https://docs.merge.dev/guides/merge-link/single-integration/. /// [JsonPropertyName("integration")] - public string? Integration { get; init; } + public string? Integration { get; set; } /// /// An integer number of minutes between [30, 720 or 10080 if for a Magic Link URL] for how long this token is valid. Defaults to 30. /// [JsonPropertyName("link_expiry_mins")] - public int? LinkExpiryMins { get; init; } + public int? LinkExpiryMins { get; set; } /// /// Whether to generate a Magic Link URL. Defaults to false. For more information on Magic Link, see https://merge.dev/blog/integrations-fast-say-hello-to-magic-link. /// [JsonPropertyName("should_create_magic_link_url")] - public bool? ShouldCreateMagicLinkUrl { get; init; } + public bool? ShouldCreateMagicLinkUrl { get; set; } /// /// Whether to generate a Magic Link URL on the Admin Needed screen during the linking flow. Defaults to false. For more information on Magic Link, see https://merge.dev/blog/integrations-fast-say-hello-to-magic-link. /// [JsonPropertyName("hide_admin_magic_link")] - public bool? HideAdminMagicLink { get; init; } + public bool? HideAdminMagicLink { get; set; } /// /// An array of objects to specify the models and fields that will be disabled for a given Linked Account. Each object uses model_id, enabled_actions, and disabled_fields to specify the model, method, and fields that are scoped for a given Linked Account. /// [JsonPropertyName("common_models")] - public IEnumerable? CommonModels { get; init; } + public IEnumerable? CommonModels { get; set; } /// /// When creating a Link Token, you can set permissions for Common Models that will apply to the account that is going to be linked. Any model or field not specified in link token payload will default to existing settings. @@ -68,17 +67,17 @@ public class EndUserDetailsRequest public Dictionary< string, IEnumerable? - >? CategoryCommonModelScopes { get; init; } + >? CategoryCommonModelScopes { get; set; } /// /// The language code for the language to localize Merge Link to. /// [JsonPropertyName("language")] - public string? Language { get; init; } + public string? Language { get; set; } /// /// A JSON object containing integration-specific configuration options. /// [JsonPropertyName("integration_specific_config")] - public Dictionary? IntegrationSpecificConfig { get; init; } + public Dictionary? IntegrationSpecificConfig { get; set; } } diff --git a/src/Merge.Client/Filestorage/LinkedAccounts/LinkedAccountsClient.cs b/src/Merge.Client/Filestorage/LinkedAccounts/LinkedAccountsClient.cs index ce6ae079..986d6332 100644 --- a/src/Merge.Client/Filestorage/LinkedAccounts/LinkedAccountsClient.cs +++ b/src/Merge.Client/Filestorage/LinkedAccounts/LinkedAccountsClient.cs @@ -1,6 +1,6 @@ +using System.Net.Http; using System.Text.Json; -using Merge.Client; -using Merge.Client.Filestorage; +using Merge.Client.Core; #nullable enable @@ -19,7 +19,8 @@ public LinkedAccountsClient(RawClient client) /// List linked accounts for your organization. /// public async Task ListAsync( - LinkedAccountsListRequest request + LinkedAccountsListRequest request, + RequestOptions? options = null ) { var _query = new Dictionary() { }; @@ -78,16 +79,30 @@ LinkedAccountsListRequest request var response = await _client.MakeRequestAsync( new RawClient.JsonApiRequest { + BaseUrl = _client.Options.BaseUrl, Method = HttpMethod.Get, Path = "filestorage/v1/linked-accounts", - Query = _query + Query = _query, + Options = options } ); - string responseBody = await response.Raw.Content.ReadAsStringAsync(); - if (response.StatusCode >= 200 && response.StatusCode < 400) + var responseBody = await response.Raw.Content.ReadAsStringAsync(); + if (response.StatusCode is >= 200 and < 400) { - return JsonSerializer.Deserialize(responseBody); + try + { + return JsonUtils.Deserialize(responseBody)!; + } + catch (JsonException e) + { + throw new MergeException("Failed to deserialize response", e); + } } - throw new Exception(responseBody); + + throw new MergeApiException( + $"Error with status code {response.StatusCode}", + response.StatusCode, + JsonUtils.Deserialize(responseBody) + ); } } diff --git a/src/Merge.Client/Filestorage/LinkedAccounts/Requests/LinkedAccountsListRequest.cs b/src/Merge.Client/Filestorage/LinkedAccounts/Requests/LinkedAccountsListRequest.cs index 9d2743f2..19582a75 100644 --- a/src/Merge.Client/Filestorage/LinkedAccounts/Requests/LinkedAccountsListRequest.cs +++ b/src/Merge.Client/Filestorage/LinkedAccounts/Requests/LinkedAccountsListRequest.cs @@ -1,10 +1,6 @@ -using Merge.Client.Filestorage; - -#nullable enable - namespace Merge.Client.Filestorage; -public class LinkedAccountsListRequest +public record LinkedAccountsListRequest { /// /// Options: `accounting`, `ats`, `crm`, `filestorage`, `hris`, `mktg`, `ticketing` @@ -17,62 +13,62 @@ public class LinkedAccountsListRequest /// - `mktg` - mktg /// - `filestorage` - filestorage /// - public LinkedAccountsListRequestCategory? Category { get; init; } + public LinkedAccountsListRequestCategory? Category { get; set; } /// /// The pagination cursor value. /// - public string? Cursor { get; init; } + public string? Cursor { get; set; } /// /// If provided, will only return linked accounts associated with the given email address. /// - public string? EndUserEmailAddress { get; init; } + public string? EndUserEmailAddress { get; set; } /// /// If provided, will only return linked accounts associated with the given organization name. /// - public string? EndUserOrganizationName { get; init; } + public string? EndUserOrganizationName { get; set; } /// /// If provided, will only return linked accounts associated with the given origin ID. /// - public string? EndUserOriginId { get; init; } + public string? EndUserOriginId { get; set; } /// /// Comma-separated list of EndUser origin IDs, making it possible to specify multiple EndUsers at once. /// - public string? EndUserOriginIds { get; init; } + public string? EndUserOriginIds { get; set; } - public string? Id { get; init; } + public string? Id { get; set; } /// /// Comma-separated list of LinkedAccount IDs, making it possible to specify multiple LinkedAccounts at once. /// - public string? Ids { get; init; } + public string? Ids { get; set; } /// /// If `true`, will include complete production duplicates of the account specified by the `id` query parameter in the response. `id` must be for a complete production linked account. /// - public bool? IncludeDuplicates { get; init; } + public bool? IncludeDuplicates { get; set; } /// /// If provided, will only return linked accounts associated with the given integration name. /// - public string? IntegrationName { get; init; } + public string? IntegrationName { get; set; } /// /// If included, will only include test linked accounts. If not included, will only include non-test linked accounts. /// - public string? IsTestAccount { get; init; } + public string? IsTestAccount { get; set; } /// /// Number of results to return per page. /// - public int? PageSize { get; init; } + public int? PageSize { get; set; } /// /// Filter by status. Options: `COMPLETE`, `INCOMPLETE`, `RELINK_NEEDED` /// - public string? Status { get; init; } + public string? Status { get; set; } } diff --git a/src/Merge.Client/Filestorage/LinkedAccounts/Types/LinkedAccountsListRequestCategory.cs b/src/Merge.Client/Filestorage/LinkedAccounts/Types/LinkedAccountsListRequestCategory.cs index fb0340f2..a17fcaa0 100644 --- a/src/Merge.Client/Filestorage/LinkedAccounts/Types/LinkedAccountsListRequestCategory.cs +++ b/src/Merge.Client/Filestorage/LinkedAccounts/Types/LinkedAccountsListRequestCategory.cs @@ -1,7 +1,6 @@ using System.Runtime.Serialization; using System.Text.Json.Serialization; using Merge.Client.Core; -using Merge.Client.Filestorage; #nullable enable diff --git a/src/Merge.Client/Filestorage/Passthrough/PassthroughClient.cs b/src/Merge.Client/Filestorage/Passthrough/PassthroughClient.cs index 070bb084..a9686660 100644 --- a/src/Merge.Client/Filestorage/Passthrough/PassthroughClient.cs +++ b/src/Merge.Client/Filestorage/Passthrough/PassthroughClient.cs @@ -1,6 +1,6 @@ +using System.Net.Http; using System.Text.Json; -using Merge.Client; -using Merge.Client.Filestorage; +using Merge.Client.Core; #nullable enable @@ -18,21 +18,38 @@ public PassthroughClient(RawClient client) /// /// Pull data from an endpoint not currently supported by Merge. /// - public async Task CreateAsync(DataPassthroughRequest request) + public async Task CreateAsync( + DataPassthroughRequest request, + RequestOptions? options = null + ) { var response = await _client.MakeRequestAsync( new RawClient.JsonApiRequest { + BaseUrl = _client.Options.BaseUrl, Method = HttpMethod.Post, Path = "filestorage/v1/passthrough", - Body = request + Body = request, + Options = options } ); - string responseBody = await response.Raw.Content.ReadAsStringAsync(); - if (response.StatusCode >= 200 && response.StatusCode < 400) + var responseBody = await response.Raw.Content.ReadAsStringAsync(); + if (response.StatusCode is >= 200 and < 400) { - return JsonSerializer.Deserialize(responseBody); + try + { + return JsonUtils.Deserialize(responseBody)!; + } + catch (JsonException e) + { + throw new MergeException("Failed to deserialize response", e); + } } - throw new Exception(responseBody); + + throw new MergeApiException( + $"Error with status code {response.StatusCode}", + response.StatusCode, + JsonUtils.Deserialize(responseBody) + ); } } diff --git a/src/Merge.Client/Filestorage/RegenerateKey/RegenerateKeyClient.cs b/src/Merge.Client/Filestorage/RegenerateKey/RegenerateKeyClient.cs index 0dd676c8..6ea7d6bc 100644 --- a/src/Merge.Client/Filestorage/RegenerateKey/RegenerateKeyClient.cs +++ b/src/Merge.Client/Filestorage/RegenerateKey/RegenerateKeyClient.cs @@ -1,6 +1,6 @@ +using System.Net.Http; using System.Text.Json; -using Merge.Client; -using Merge.Client.Filestorage; +using Merge.Client.Core; #nullable enable @@ -18,21 +18,38 @@ public RegenerateKeyClient(RawClient client) /// /// Exchange remote keys. /// - public async Task CreateAsync(RemoteKeyForRegenerationRequest request) + public async Task CreateAsync( + RemoteKeyForRegenerationRequest request, + RequestOptions? options = null + ) { var response = await _client.MakeRequestAsync( new RawClient.JsonApiRequest { + BaseUrl = _client.Options.BaseUrl, Method = HttpMethod.Post, Path = "filestorage/v1/regenerate-key", - Body = request + Body = request, + Options = options } ); - string responseBody = await response.Raw.Content.ReadAsStringAsync(); - if (response.StatusCode >= 200 && response.StatusCode < 400) + var responseBody = await response.Raw.Content.ReadAsStringAsync(); + if (response.StatusCode is >= 200 and < 400) { - return JsonSerializer.Deserialize(responseBody); + try + { + return JsonUtils.Deserialize(responseBody)!; + } + catch (JsonException e) + { + throw new MergeException("Failed to deserialize response", e); + } } - throw new Exception(responseBody); + + throw new MergeApiException( + $"Error with status code {response.StatusCode}", + response.StatusCode, + JsonUtils.Deserialize(responseBody) + ); } } diff --git a/src/Merge.Client/Filestorage/RegenerateKey/Requests/RemoteKeyForRegenerationRequest.cs b/src/Merge.Client/Filestorage/RegenerateKey/Requests/RemoteKeyForRegenerationRequest.cs index 837f40b0..dcf57b69 100644 --- a/src/Merge.Client/Filestorage/RegenerateKey/Requests/RemoteKeyForRegenerationRequest.cs +++ b/src/Merge.Client/Filestorage/RegenerateKey/Requests/RemoteKeyForRegenerationRequest.cs @@ -4,11 +4,11 @@ namespace Merge.Client.Filestorage; -public class RemoteKeyForRegenerationRequest +public record RemoteKeyForRegenerationRequest { /// /// The name of the remote key /// [JsonPropertyName("name")] - public string Name { get; init; } + public required string Name { get; set; } } diff --git a/src/Merge.Client/Filestorage/Scopes/Requests/LinkedAccountCommonModelScopeDeserializerRequest.cs b/src/Merge.Client/Filestorage/Scopes/Requests/LinkedAccountCommonModelScopeDeserializerRequest.cs index 07eb735c..a728ce6e 100644 --- a/src/Merge.Client/Filestorage/Scopes/Requests/LinkedAccountCommonModelScopeDeserializerRequest.cs +++ b/src/Merge.Client/Filestorage/Scopes/Requests/LinkedAccountCommonModelScopeDeserializerRequest.cs @@ -1,15 +1,15 @@ using System.Text.Json.Serialization; -using Merge.Client.Filestorage; #nullable enable namespace Merge.Client.Filestorage; -public class LinkedAccountCommonModelScopeDeserializerRequest +public record LinkedAccountCommonModelScopeDeserializerRequest { /// /// The common models you want to update the scopes for /// [JsonPropertyName("common_models")] - public IEnumerable CommonModels { get; init; } + public IEnumerable CommonModels { get; set; } = + new List(); } diff --git a/src/Merge.Client/Filestorage/Scopes/ScopesClient.cs b/src/Merge.Client/Filestorage/Scopes/ScopesClient.cs index eed25071..a69c5030 100644 --- a/src/Merge.Client/Filestorage/Scopes/ScopesClient.cs +++ b/src/Merge.Client/Filestorage/Scopes/ScopesClient.cs @@ -1,6 +1,6 @@ +using System.Net.Http; using System.Text.Json; -using Merge.Client; -using Merge.Client.Filestorage; +using Merge.Client.Core; #nullable enable @@ -18,63 +18,110 @@ public ScopesClient(RawClient client) /// /// Get the default permissions for Merge Common Models and fields across all Linked Accounts of a given category. [Learn more](https://help.merge.dev/en/articles/8828211-common-model-and-field-scopes). /// - public async Task DefaultScopesRetrieveAsync() + public async Task DefaultScopesRetrieveAsync( + RequestOptions? options = null + ) { var response = await _client.MakeRequestAsync( new RawClient.JsonApiRequest { + BaseUrl = _client.Options.BaseUrl, Method = HttpMethod.Get, - Path = "filestorage/v1/default-scopes" + Path = "filestorage/v1/default-scopes", + Options = options } ); - string responseBody = await response.Raw.Content.ReadAsStringAsync(); - if (response.StatusCode >= 200 && response.StatusCode < 400) + var responseBody = await response.Raw.Content.ReadAsStringAsync(); + if (response.StatusCode is >= 200 and < 400) { - return JsonSerializer.Deserialize(responseBody); + try + { + return JsonUtils.Deserialize(responseBody)!; + } + catch (JsonException e) + { + throw new MergeException("Failed to deserialize response", e); + } } - throw new Exception(responseBody); + + throw new MergeApiException( + $"Error with status code {response.StatusCode}", + response.StatusCode, + JsonUtils.Deserialize(responseBody) + ); } /// /// Get all available permissions for Merge Common Models and fields for a single Linked Account. [Learn more](https://help.merge.dev/en/articles/8828211-common-model-and-field-scopes). /// - public async Task LinkedAccountScopesRetrieveAsync() + public async Task LinkedAccountScopesRetrieveAsync( + RequestOptions? options = null + ) { var response = await _client.MakeRequestAsync( new RawClient.JsonApiRequest { + BaseUrl = _client.Options.BaseUrl, Method = HttpMethod.Get, - Path = "filestorage/v1/linked-account-scopes" + Path = "filestorage/v1/linked-account-scopes", + Options = options } ); - string responseBody = await response.Raw.Content.ReadAsStringAsync(); - if (response.StatusCode >= 200 && response.StatusCode < 400) + var responseBody = await response.Raw.Content.ReadAsStringAsync(); + if (response.StatusCode is >= 200 and < 400) { - return JsonSerializer.Deserialize(responseBody); + try + { + return JsonUtils.Deserialize(responseBody)!; + } + catch (JsonException e) + { + throw new MergeException("Failed to deserialize response", e); + } } - throw new Exception(responseBody); + + throw new MergeApiException( + $"Error with status code {response.StatusCode}", + response.StatusCode, + JsonUtils.Deserialize(responseBody) + ); } /// /// Update permissions for any Common Model or field for a single Linked Account. Any Scopes not set in this POST request will inherit the default Scopes. [Learn more](https://help.merge.dev/en/articles/8828211-common-model-and-field-scopes) /// public async Task LinkedAccountScopesCreateAsync( - LinkedAccountCommonModelScopeDeserializerRequest request + LinkedAccountCommonModelScopeDeserializerRequest request, + RequestOptions? options = null ) { var response = await _client.MakeRequestAsync( new RawClient.JsonApiRequest { + BaseUrl = _client.Options.BaseUrl, Method = HttpMethod.Post, Path = "filestorage/v1/linked-account-scopes", - Body = request + Body = request, + Options = options } ); - string responseBody = await response.Raw.Content.ReadAsStringAsync(); - if (response.StatusCode >= 200 && response.StatusCode < 400) + var responseBody = await response.Raw.Content.ReadAsStringAsync(); + if (response.StatusCode is >= 200 and < 400) { - return JsonSerializer.Deserialize(responseBody); + try + { + return JsonUtils.Deserialize(responseBody)!; + } + catch (JsonException e) + { + throw new MergeException("Failed to deserialize response", e); + } } - throw new Exception(responseBody); + + throw new MergeApiException( + $"Error with status code {response.StatusCode}", + response.StatusCode, + JsonUtils.Deserialize(responseBody) + ); } } diff --git a/src/Merge.Client/Filestorage/SyncStatus/Requests/SyncStatusListRequest.cs b/src/Merge.Client/Filestorage/SyncStatus/Requests/SyncStatusListRequest.cs index 6732f6a8..c95ea4e1 100644 --- a/src/Merge.Client/Filestorage/SyncStatus/Requests/SyncStatusListRequest.cs +++ b/src/Merge.Client/Filestorage/SyncStatus/Requests/SyncStatusListRequest.cs @@ -1,14 +1,14 @@ namespace Merge.Client.Filestorage; -public class SyncStatusListRequest +public record SyncStatusListRequest { /// /// The pagination cursor value. /// - public string? Cursor { get; init; } + public string? Cursor { get; set; } /// /// Number of results to return per page. /// - public int? PageSize { get; init; } + public int? PageSize { get; set; } } diff --git a/src/Merge.Client/Filestorage/SyncStatus/SyncStatusClient.cs b/src/Merge.Client/Filestorage/SyncStatus/SyncStatusClient.cs index 99a10592..c5c55768 100644 --- a/src/Merge.Client/Filestorage/SyncStatus/SyncStatusClient.cs +++ b/src/Merge.Client/Filestorage/SyncStatus/SyncStatusClient.cs @@ -1,6 +1,6 @@ +using System.Net.Http; using System.Text.Json; -using Merge.Client; -using Merge.Client.Filestorage; +using Merge.Client.Core; #nullable enable @@ -18,7 +18,10 @@ public SyncStatusClient(RawClient client) /// /// Get syncing status. Possible values: `DISABLED`, `DONE`, `FAILED`, `PARTIALLY_SYNCED`, `PAUSED`, `SYNCING`. Learn more about sync status in our [Help Center](https://help.merge.dev/en/articles/8184193-merge-sync-statuses). /// - public async Task ListAsync(SyncStatusListRequest request) + public async Task ListAsync( + SyncStatusListRequest request, + RequestOptions? options = null + ) { var _query = new Dictionary() { }; if (request.Cursor != null) @@ -32,16 +35,30 @@ public async Task ListAsync(SyncStatusListRequest reque var response = await _client.MakeRequestAsync( new RawClient.JsonApiRequest { + BaseUrl = _client.Options.BaseUrl, Method = HttpMethod.Get, Path = "filestorage/v1/sync-status", - Query = _query + Query = _query, + Options = options } ); - string responseBody = await response.Raw.Content.ReadAsStringAsync(); - if (response.StatusCode >= 200 && response.StatusCode < 400) + var responseBody = await response.Raw.Content.ReadAsStringAsync(); + if (response.StatusCode is >= 200 and < 400) { - return JsonSerializer.Deserialize(responseBody); + try + { + return JsonUtils.Deserialize(responseBody)!; + } + catch (JsonException e) + { + throw new MergeException("Failed to deserialize response", e); + } } - throw new Exception(responseBody); + + throw new MergeApiException( + $"Error with status code {response.StatusCode}", + response.StatusCode, + JsonUtils.Deserialize(responseBody) + ); } } diff --git a/src/Merge.Client/Filestorage/Types/AccountDetails.cs b/src/Merge.Client/Filestorage/Types/AccountDetails.cs index 954bc77b..4c55348a 100644 --- a/src/Merge.Client/Filestorage/Types/AccountDetails.cs +++ b/src/Merge.Client/Filestorage/Types/AccountDetails.cs @@ -1,45 +1,44 @@ using System.Text.Json.Serialization; -using Merge.Client.Filestorage; #nullable enable namespace Merge.Client.Filestorage; -public class AccountDetails +public record AccountDetails { [JsonPropertyName("id")] - public string? Id { get; init; } + public string? Id { get; set; } [JsonPropertyName("integration")] - public string? Integration { get; init; } + public string? Integration { get; set; } [JsonPropertyName("integration_slug")] - public string? IntegrationSlug { get; init; } + public string? IntegrationSlug { get; set; } [JsonPropertyName("category")] - public CategoryEnum? Category { get; init; } + public CategoryEnum? Category { get; set; } [JsonPropertyName("end_user_origin_id")] - public string? EndUserOriginId { get; init; } + public string? EndUserOriginId { get; set; } [JsonPropertyName("end_user_organization_name")] - public string? EndUserOrganizationName { get; init; } + public string? EndUserOrganizationName { get; set; } [JsonPropertyName("end_user_email_address")] - public string? EndUserEmailAddress { get; init; } + public string? EndUserEmailAddress { get; set; } [JsonPropertyName("status")] - public string? Status { get; init; } + public string? Status { get; set; } [JsonPropertyName("webhook_listener_url")] - public string? WebhookListenerUrl { get; init; } + public string? WebhookListenerUrl { get; set; } /// /// Whether a Production Linked Account's credentials match another existing Production Linked Account. This field is `null` for Test Linked Accounts, incomplete Production Linked Accounts, and ignored duplicate Production Linked Account sets. /// [JsonPropertyName("is_duplicate")] - public bool? IsDuplicate { get; init; } + public bool? IsDuplicate { get; set; } [JsonPropertyName("account_type")] - public string? AccountType { get; init; } + public string? AccountType { get; set; } } diff --git a/src/Merge.Client/Filestorage/Types/AccountDetailsAndActions.cs b/src/Merge.Client/Filestorage/Types/AccountDetailsAndActions.cs index 0140275e..901a72b2 100644 --- a/src/Merge.Client/Filestorage/Types/AccountDetailsAndActions.cs +++ b/src/Merge.Client/Filestorage/Types/AccountDetailsAndActions.cs @@ -1,51 +1,50 @@ using System.Text.Json.Serialization; -using Merge.Client.Filestorage; #nullable enable namespace Merge.Client.Filestorage; -public class AccountDetailsAndActions +public record AccountDetailsAndActions { [JsonPropertyName("id")] - public string Id { get; init; } + public required string Id { get; set; } [JsonPropertyName("category")] - public CategoryEnum? Category { get; init; } + public CategoryEnum? Category { get; set; } [JsonPropertyName("status")] - public AccountDetailsAndActionsStatusEnum Status { get; init; } + public required AccountDetailsAndActionsStatusEnum Status { get; set; } [JsonPropertyName("status_detail")] - public string? StatusDetail { get; init; } + public string? StatusDetail { get; set; } [JsonPropertyName("end_user_origin_id")] - public string? EndUserOriginId { get; init; } + public string? EndUserOriginId { get; set; } [JsonPropertyName("end_user_organization_name")] - public string EndUserOrganizationName { get; init; } + public required string EndUserOrganizationName { get; set; } [JsonPropertyName("end_user_email_address")] - public string EndUserEmailAddress { get; init; } + public required string EndUserEmailAddress { get; set; } /// /// The tenant or domain the customer has provided access to. /// [JsonPropertyName("subdomain")] - public string? Subdomain { get; init; } + public string? Subdomain { get; set; } [JsonPropertyName("webhook_listener_url")] - public string WebhookListenerUrl { get; init; } + public required string WebhookListenerUrl { get; set; } /// /// Whether a Production Linked Account's credentials match another existing Production Linked Account. This field is `null` for Test Linked Accounts, incomplete Production Linked Accounts, and ignored duplicate Production Linked Account sets. /// [JsonPropertyName("is_duplicate")] - public bool? IsDuplicate { get; init; } + public bool? IsDuplicate { get; set; } [JsonPropertyName("integration")] - public AccountDetailsAndActionsIntegration? Integration { get; init; } + public AccountDetailsAndActionsIntegration? Integration { get; set; } [JsonPropertyName("account_type")] - public string AccountType { get; init; } + public required string AccountType { get; set; } } diff --git a/src/Merge.Client/Filestorage/Types/AccountDetailsAndActionsIntegration.cs b/src/Merge.Client/Filestorage/Types/AccountDetailsAndActionsIntegration.cs index 005277a2..3f7dc9f7 100644 --- a/src/Merge.Client/Filestorage/Types/AccountDetailsAndActionsIntegration.cs +++ b/src/Merge.Client/Filestorage/Types/AccountDetailsAndActionsIntegration.cs @@ -1,33 +1,32 @@ using System.Text.Json.Serialization; -using Merge.Client.Filestorage; #nullable enable namespace Merge.Client.Filestorage; -public class AccountDetailsAndActionsIntegration +public record AccountDetailsAndActionsIntegration { [JsonPropertyName("name")] - public string Name { get; init; } + public required string Name { get; set; } [JsonPropertyName("categories")] - public IEnumerable Categories { get; init; } + public IEnumerable Categories { get; set; } = new List(); [JsonPropertyName("image")] - public string? Image { get; init; } + public string? Image { get; set; } [JsonPropertyName("square_image")] - public string? SquareImage { get; init; } + public string? SquareImage { get; set; } [JsonPropertyName("color")] - public string Color { get; init; } + public required string Color { get; set; } [JsonPropertyName("slug")] - public string Slug { get; init; } + public required string Slug { get; set; } [JsonPropertyName("passthrough_available")] - public bool PassthroughAvailable { get; init; } + public required bool PassthroughAvailable { get; set; } [JsonPropertyName("available_model_operations")] - public IEnumerable? AvailableModelOperations { get; init; } + public IEnumerable? AvailableModelOperations { get; set; } } diff --git a/src/Merge.Client/Filestorage/Types/AccountDetailsAndActionsStatusEnum.cs b/src/Merge.Client/Filestorage/Types/AccountDetailsAndActionsStatusEnum.cs index 92de266e..5bcabf05 100644 --- a/src/Merge.Client/Filestorage/Types/AccountDetailsAndActionsStatusEnum.cs +++ b/src/Merge.Client/Filestorage/Types/AccountDetailsAndActionsStatusEnum.cs @@ -1,7 +1,6 @@ using System.Runtime.Serialization; using System.Text.Json.Serialization; using Merge.Client.Core; -using Merge.Client.Filestorage; #nullable enable diff --git a/src/Merge.Client/Filestorage/Types/AccountIntegration.cs b/src/Merge.Client/Filestorage/Types/AccountIntegration.cs index b32a2004..1ebb2e48 100644 --- a/src/Merge.Client/Filestorage/Types/AccountIntegration.cs +++ b/src/Merge.Client/Filestorage/Types/AccountIntegration.cs @@ -1,66 +1,65 @@ using System.Text.Json.Serialization; -using Merge.Client.Filestorage; #nullable enable namespace Merge.Client.Filestorage; -public class AccountIntegration +public record AccountIntegration { /// /// Company name. /// [JsonPropertyName("name")] - public string Name { get; init; } + public required string Name { get; set; } /// /// Optional. This shortened name appears in places with limited space, usually in conjunction with the platform's logo (e.g., Merge Link menu).

Example: Workforce Now (in lieu of ADP Workforce Now), SuccessFactors (in lieu of SAP SuccessFactors) ///
[JsonPropertyName("abbreviated_name")] - public string? AbbreviatedName { get; init; } + public string? AbbreviatedName { get; set; } /// /// Category or categories this integration belongs to. Multiple categories should be comma separated, i.e. [ats, hris]. /// [JsonPropertyName("categories")] - public IEnumerable? Categories { get; init; } + public IEnumerable? Categories { get; set; } /// /// Company logo in rectangular shape. Upload an image with a clear background. /// [JsonPropertyName("image")] - public string? Image { get; init; } + public string? Image { get; set; } /// /// Company logo in square shape. Upload an image with a white background. /// [JsonPropertyName("square_image")] - public string? SquareImage { get; init; } + public string? SquareImage { get; set; } /// /// The color of this integration used for buttons and text throughout the app and landing pages. Choose a darker, saturated color. /// [JsonPropertyName("color")] - public string? Color { get; init; } + public string? Color { get; set; } [JsonPropertyName("slug")] - public string? Slug { get; init; } + public string? Slug { get; set; } /// /// Mapping of API endpoints to documentation urls for support. Example: {'GET': [['/common-model-scopes', 'https://docs.merge.dev/accounting/common-model-scopes/#common_model_scopes_retrieve'],['/common-model-actions', 'https://docs.merge.dev/accounting/common-model-actions/#common_model_actions_retrieve']], 'POST': []} /// [JsonPropertyName("api_endpoints_to_documentation_urls")] - public Dictionary? ApiEndpointsToDocumentationUrls { get; init; } + public Dictionary? ApiEndpointsToDocumentationUrls { get; set; } /// /// Setup guide URL for third party webhook creation. Exposed in Merge Docs. /// [JsonPropertyName("webhook_setup_guide_url")] - public string? WebhookSetupGuideUrl { get; init; } + public string? WebhookSetupGuideUrl { get; set; } /// /// Category or categories this integration is in beta status for. /// [JsonPropertyName("category_beta_status")] - public Dictionary? CategoryBetaStatus { get; init; } + public Dictionary? CategoryBetaStatus { get; set; } } diff --git a/src/Merge.Client/Filestorage/Types/AccountToken.cs b/src/Merge.Client/Filestorage/Types/AccountToken.cs index ebae9996..80cd646c 100644 --- a/src/Merge.Client/Filestorage/Types/AccountToken.cs +++ b/src/Merge.Client/Filestorage/Types/AccountToken.cs @@ -1,15 +1,14 @@ using System.Text.Json.Serialization; -using Merge.Client.Filestorage; #nullable enable namespace Merge.Client.Filestorage; -public class AccountToken +public record AccountToken { [JsonPropertyName("account_token")] - public string AccountToken_ { get; init; } + public required string AccountToken_ { get; set; } [JsonPropertyName("integration")] - public AccountIntegration Integration { get; init; } + public required AccountIntegration Integration { get; set; } } diff --git a/src/Merge.Client/Filestorage/Types/AdvancedMetadata.cs b/src/Merge.Client/Filestorage/Types/AdvancedMetadata.cs index 110611d0..43bd5408 100644 --- a/src/Merge.Client/Filestorage/Types/AdvancedMetadata.cs +++ b/src/Merge.Client/Filestorage/Types/AdvancedMetadata.cs @@ -4,23 +4,23 @@ namespace Merge.Client.Filestorage; -public class AdvancedMetadata +public record AdvancedMetadata { [JsonPropertyName("id")] - public string Id { get; init; } + public required string Id { get; set; } [JsonPropertyName("display_name")] - public string? DisplayName { get; init; } + public string? DisplayName { get; set; } [JsonPropertyName("description")] - public string? Description { get; init; } + public string? Description { get; set; } [JsonPropertyName("is_required")] - public bool? IsRequired { get; init; } + public bool? IsRequired { get; set; } [JsonPropertyName("is_custom")] - public bool? IsCustom { get; init; } + public bool? IsCustom { get; set; } [JsonPropertyName("field_choices")] - public IEnumerable? FieldChoices { get; init; } + public IEnumerable? FieldChoices { get; set; } } diff --git a/src/Merge.Client/Filestorage/Types/AsyncPassthroughReciept.cs b/src/Merge.Client/Filestorage/Types/AsyncPassthroughReciept.cs index 8a162bdc..556c50f7 100644 --- a/src/Merge.Client/Filestorage/Types/AsyncPassthroughReciept.cs +++ b/src/Merge.Client/Filestorage/Types/AsyncPassthroughReciept.cs @@ -4,8 +4,8 @@ namespace Merge.Client.Filestorage; -public class AsyncPassthroughReciept +public record AsyncPassthroughReciept { [JsonPropertyName("async_passthrough_receipt_id")] - public string AsyncPassthroughReceiptId { get; init; } + public required string AsyncPassthroughReceiptId { get; set; } } diff --git a/src/Merge.Client/Filestorage/Types/AuditLogEvent.cs b/src/Merge.Client/Filestorage/Types/AuditLogEvent.cs index 372bda69..14094d88 100644 --- a/src/Merge.Client/Filestorage/Types/AuditLogEvent.cs +++ b/src/Merge.Client/Filestorage/Types/AuditLogEvent.cs @@ -1,26 +1,25 @@ using System.Text.Json.Serialization; -using Merge.Client.Filestorage; #nullable enable namespace Merge.Client.Filestorage; -public class AuditLogEvent +public record AuditLogEvent { [JsonPropertyName("id")] - public string? Id { get; init; } + public string? Id { get; set; } /// /// The User's full name at the time of this Event occurring. /// [JsonPropertyName("user_name")] - public string? UserName { get; init; } + public string? UserName { get; set; } /// /// The User's email at the time of this Event occurring. /// [JsonPropertyName("user_email")] - public string? UserEmail { get; init; } + public string? UserEmail { get; set; } /// /// Designates the role of the user (or SYSTEM/API if action not taken by a user) at the time of this Event occurring. @@ -33,10 +32,10 @@ public class AuditLogEvent /// - `MERGE_TEAM` - MERGE_TEAM /// [JsonPropertyName("role")] - public RoleEnum Role { get; init; } + public required RoleEnum Role { get; set; } [JsonPropertyName("ip_address")] - public string IpAddress { get; init; } + public required string IpAddress { get; set; } /// /// Designates the type of event that occurred. @@ -81,11 +80,11 @@ public class AuditLogEvent /// - `END_USER_CREDENTIALS_ACCESSED` - END_USER_CREDENTIALS_ACCESSED /// [JsonPropertyName("event_type")] - public EventTypeEnum EventType { get; init; } + public required EventTypeEnum EventType { get; set; } [JsonPropertyName("event_description")] - public string EventDescription { get; init; } + public required string EventDescription { get; set; } [JsonPropertyName("created_at")] - public DateTime? CreatedAt { get; init; } + public DateTime? CreatedAt { get; set; } } diff --git a/src/Merge.Client/Filestorage/Types/AvailableActions.cs b/src/Merge.Client/Filestorage/Types/AvailableActions.cs index a8b570b9..e4e91dfa 100644 --- a/src/Merge.Client/Filestorage/Types/AvailableActions.cs +++ b/src/Merge.Client/Filestorage/Types/AvailableActions.cs @@ -1,18 +1,17 @@ using System.Text.Json.Serialization; -using Merge.Client.Filestorage; #nullable enable namespace Merge.Client.Filestorage; -public class AvailableActions +public record AvailableActions { [JsonPropertyName("integration")] - public AccountIntegration Integration { get; init; } + public required AccountIntegration Integration { get; set; } [JsonPropertyName("passthrough_available")] - public bool PassthroughAvailable { get; init; } + public required bool PassthroughAvailable { get; set; } [JsonPropertyName("available_model_operations")] - public IEnumerable? AvailableModelOperations { get; init; } + public IEnumerable? AvailableModelOperations { get; set; } } diff --git a/src/Merge.Client/Filestorage/Types/CategoriesEnum.cs b/src/Merge.Client/Filestorage/Types/CategoriesEnum.cs index 97d15d1f..b26eb3c8 100644 --- a/src/Merge.Client/Filestorage/Types/CategoriesEnum.cs +++ b/src/Merge.Client/Filestorage/Types/CategoriesEnum.cs @@ -1,7 +1,6 @@ using System.Runtime.Serialization; using System.Text.Json.Serialization; using Merge.Client.Core; -using Merge.Client.Filestorage; #nullable enable diff --git a/src/Merge.Client/Filestorage/Types/CategoryEnum.cs b/src/Merge.Client/Filestorage/Types/CategoryEnum.cs index 8dc31360..ffe0e6b2 100644 --- a/src/Merge.Client/Filestorage/Types/CategoryEnum.cs +++ b/src/Merge.Client/Filestorage/Types/CategoryEnum.cs @@ -1,7 +1,6 @@ using System.Runtime.Serialization; using System.Text.Json.Serialization; using Merge.Client.Core; -using Merge.Client.Filestorage; #nullable enable diff --git a/src/Merge.Client/Filestorage/Types/CommonModelScopeApi.cs b/src/Merge.Client/Filestorage/Types/CommonModelScopeApi.cs index e3708308..a19127fe 100644 --- a/src/Merge.Client/Filestorage/Types/CommonModelScopeApi.cs +++ b/src/Merge.Client/Filestorage/Types/CommonModelScopeApi.cs @@ -1,15 +1,15 @@ using System.Text.Json.Serialization; -using Merge.Client.Filestorage; #nullable enable namespace Merge.Client.Filestorage; -public class CommonModelScopeApi +public record CommonModelScopeApi { /// /// The common models you want to update the scopes for /// [JsonPropertyName("common_models")] - public IEnumerable CommonModels { get; init; } + public IEnumerable CommonModels { get; set; } = + new List(); } diff --git a/src/Merge.Client/Filestorage/Types/CommonModelScopesBodyRequest.cs b/src/Merge.Client/Filestorage/Types/CommonModelScopesBodyRequest.cs index 5d8d93ba..177ab621 100644 --- a/src/Merge.Client/Filestorage/Types/CommonModelScopesBodyRequest.cs +++ b/src/Merge.Client/Filestorage/Types/CommonModelScopesBodyRequest.cs @@ -1,18 +1,18 @@ using System.Text.Json.Serialization; -using Merge.Client.Filestorage; #nullable enable namespace Merge.Client.Filestorage; -public class CommonModelScopesBodyRequest +public record CommonModelScopesBodyRequest { [JsonPropertyName("model_id")] - public string ModelId { get; init; } + public required string ModelId { get; set; } [JsonPropertyName("enabled_actions")] - public IEnumerable EnabledActions { get; init; } + public IEnumerable EnabledActions { get; set; } = + new List(); [JsonPropertyName("disabled_fields")] - public IEnumerable DisabledFields { get; init; } + public IEnumerable DisabledFields { get; set; } = new List(); } diff --git a/src/Merge.Client/Filestorage/Types/DataPassthroughRequest.cs b/src/Merge.Client/Filestorage/Types/DataPassthroughRequest.cs index e9bfd5bf..53a04401 100644 --- a/src/Merge.Client/Filestorage/Types/DataPassthroughRequest.cs +++ b/src/Merge.Client/Filestorage/Types/DataPassthroughRequest.cs @@ -1,51 +1,50 @@ using System.Text.Json.Serialization; -using Merge.Client.Filestorage; #nullable enable namespace Merge.Client.Filestorage; -public class DataPassthroughRequest +public record DataPassthroughRequest { [JsonPropertyName("method")] - public MethodEnum Method { get; init; } + public required MethodEnum Method { get; set; } /// /// The path of the request in the third party's platform. /// [JsonPropertyName("path")] - public string Path { get; init; } + public required string Path { get; set; } /// /// An optional override of the third party's base url for the request. /// [JsonPropertyName("base_url_override")] - public string? BaseUrlOverride { get; init; } + public string? BaseUrlOverride { get; set; } /// /// The data with the request. You must include a `request_format` parameter matching the data's format /// [JsonPropertyName("data")] - public string? Data { get; init; } + public string? Data { get; set; } /// /// Pass an array of `MultipartFormField` objects in here instead of using the `data` param if `request_format` is set to `MULTIPART`. /// [JsonPropertyName("multipart_form_data")] - public IEnumerable? MultipartFormData { get; init; } + public IEnumerable? MultipartFormData { get; set; } /// /// The headers to use for the request (Merge will handle the account's authorization headers). `Content-Type` header is required for passthrough. Choose content type corresponding to expected format of receiving server. /// [JsonPropertyName("headers")] - public Dictionary? Headers { get; init; } + public Dictionary? Headers { get; set; } [JsonPropertyName("request_format")] - public RequestFormatEnum? RequestFormat { get; init; } + public RequestFormatEnum? RequestFormat { get; set; } /// /// Optional. If true, the response will always be an object of the form `{"type": T, "value": ...}` where `T` will be one of `string, boolean, number, null, array, object`. /// [JsonPropertyName("normalize_response")] - public bool? NormalizeResponse { get; init; } + public bool? NormalizeResponse { get; set; } } diff --git a/src/Merge.Client/Filestorage/Types/DebugModeLog.cs b/src/Merge.Client/Filestorage/Types/DebugModeLog.cs index 7774e66b..21a15750 100644 --- a/src/Merge.Client/Filestorage/Types/DebugModeLog.cs +++ b/src/Merge.Client/Filestorage/Types/DebugModeLog.cs @@ -1,18 +1,17 @@ using System.Text.Json.Serialization; -using Merge.Client.Filestorage; #nullable enable namespace Merge.Client.Filestorage; -public class DebugModeLog +public record DebugModeLog { [JsonPropertyName("log_id")] - public string LogId { get; init; } + public required string LogId { get; set; } [JsonPropertyName("dashboard_view")] - public string DashboardView { get; init; } + public required string DashboardView { get; set; } [JsonPropertyName("log_summary")] - public DebugModelLogSummary LogSummary { get; init; } + public required DebugModelLogSummary LogSummary { get; set; } } diff --git a/src/Merge.Client/Filestorage/Types/DebugModelLogSummary.cs b/src/Merge.Client/Filestorage/Types/DebugModelLogSummary.cs index 97937c04..85188fe9 100644 --- a/src/Merge.Client/Filestorage/Types/DebugModelLogSummary.cs +++ b/src/Merge.Client/Filestorage/Types/DebugModelLogSummary.cs @@ -4,14 +4,14 @@ namespace Merge.Client.Filestorage; -public class DebugModelLogSummary +public record DebugModelLogSummary { [JsonPropertyName("url")] - public string Url { get; init; } + public required string Url { get; set; } [JsonPropertyName("method")] - public string Method { get; init; } + public required string Method { get; set; } [JsonPropertyName("status_code")] - public int StatusCode { get; init; } + public required int StatusCode { get; set; } } diff --git a/src/Merge.Client/Filestorage/Types/Drive.cs b/src/Merge.Client/Filestorage/Types/Drive.cs index cf566ca0..12c32ab0 100644 --- a/src/Merge.Client/Filestorage/Types/Drive.cs +++ b/src/Merge.Client/Filestorage/Types/Drive.cs @@ -4,56 +4,56 @@ namespace Merge.Client.Filestorage; -public class Drive +public record Drive { [JsonPropertyName("id")] - public string? Id { get; init; } + public string? Id { get; set; } /// /// The third-party API ID of the matching object. /// [JsonPropertyName("remote_id")] - public string? RemoteId { get; init; } + public string? RemoteId { get; set; } /// /// The datetime that this object was created by Merge. /// [JsonPropertyName("created_at")] - public DateTime? CreatedAt { get; init; } + public DateTime? CreatedAt { get; set; } /// /// The datetime that this object was modified by Merge. /// [JsonPropertyName("modified_at")] - public DateTime? ModifiedAt { get; init; } + public DateTime? ModifiedAt { get; set; } /// /// The drive's name. /// [JsonPropertyName("name")] - public string? Name { get; init; } + public string? Name { get; set; } /// /// When the third party's drive was created. /// [JsonPropertyName("remote_created_at")] - public DateTime? RemoteCreatedAt { get; init; } + public DateTime? RemoteCreatedAt { get; set; } /// /// The drive's url. /// [JsonPropertyName("drive_url")] - public string? DriveUrl { get; init; } + public string? DriveUrl { get; set; } /// /// Indicates whether or not this object has been deleted in the third party platform. /// [JsonPropertyName("remote_was_deleted")] - public bool? RemoteWasDeleted { get; init; } + public bool? RemoteWasDeleted { get; set; } [JsonPropertyName("field_mappings")] - public Dictionary? FieldMappings { get; init; } + public Dictionary? FieldMappings { get; set; } [JsonPropertyName("remote_data")] - public IEnumerable>? RemoteData { get; init; } + public IEnumerable>? RemoteData { get; set; } } diff --git a/src/Merge.Client/Filestorage/Types/EnabledActionsEnum.cs b/src/Merge.Client/Filestorage/Types/EnabledActionsEnum.cs index 0df1d77d..01613d6e 100644 --- a/src/Merge.Client/Filestorage/Types/EnabledActionsEnum.cs +++ b/src/Merge.Client/Filestorage/Types/EnabledActionsEnum.cs @@ -1,7 +1,6 @@ using System.Runtime.Serialization; using System.Text.Json.Serialization; using Merge.Client.Core; -using Merge.Client.Filestorage; #nullable enable diff --git a/src/Merge.Client/Filestorage/Types/EncodingEnum.cs b/src/Merge.Client/Filestorage/Types/EncodingEnum.cs index 90bbf36a..dc9372b7 100644 --- a/src/Merge.Client/Filestorage/Types/EncodingEnum.cs +++ b/src/Merge.Client/Filestorage/Types/EncodingEnum.cs @@ -1,7 +1,6 @@ using System.Runtime.Serialization; using System.Text.Json.Serialization; using Merge.Client.Core; -using Merge.Client.Filestorage; #nullable enable diff --git a/src/Merge.Client/Filestorage/Types/ErrorValidationProblem.cs b/src/Merge.Client/Filestorage/Types/ErrorValidationProblem.cs index 4cea9da1..579501c6 100644 --- a/src/Merge.Client/Filestorage/Types/ErrorValidationProblem.cs +++ b/src/Merge.Client/Filestorage/Types/ErrorValidationProblem.cs @@ -1,21 +1,20 @@ using System.Text.Json.Serialization; -using Merge.Client.Filestorage; #nullable enable namespace Merge.Client.Filestorage; -public class ErrorValidationProblem +public record ErrorValidationProblem { [JsonPropertyName("source")] - public ValidationProblemSource? Source { get; init; } + public ValidationProblemSource? Source { get; set; } [JsonPropertyName("title")] - public string Title { get; init; } + public required string Title { get; set; } [JsonPropertyName("detail")] - public string Detail { get; init; } + public required string Detail { get; set; } [JsonPropertyName("problem_type")] - public string ProblemType { get; init; } + public required string ProblemType { get; set; } } diff --git a/src/Merge.Client/Filestorage/Types/EventTypeEnum.cs b/src/Merge.Client/Filestorage/Types/EventTypeEnum.cs index e6e22483..fd9ebfe9 100644 --- a/src/Merge.Client/Filestorage/Types/EventTypeEnum.cs +++ b/src/Merge.Client/Filestorage/Types/EventTypeEnum.cs @@ -1,7 +1,6 @@ using System.Runtime.Serialization; using System.Text.Json.Serialization; using Merge.Client.Core; -using Merge.Client.Filestorage; #nullable enable diff --git a/src/Merge.Client/Filestorage/Types/ExternalTargetFieldApi.cs b/src/Merge.Client/Filestorage/Types/ExternalTargetFieldApi.cs index 5bb18206..60f23090 100644 --- a/src/Merge.Client/Filestorage/Types/ExternalTargetFieldApi.cs +++ b/src/Merge.Client/Filestorage/Types/ExternalTargetFieldApi.cs @@ -4,14 +4,14 @@ namespace Merge.Client.Filestorage; -public class ExternalTargetFieldApi +public record ExternalTargetFieldApi { [JsonPropertyName("name")] - public string? Name { get; init; } + public string? Name { get; set; } [JsonPropertyName("description")] - public string? Description { get; init; } + public string? Description { get; set; } [JsonPropertyName("is_mapped")] - public string? IsMapped { get; init; } + public string? IsMapped { get; set; } } diff --git a/src/Merge.Client/Filestorage/Types/ExternalTargetFieldApiResponse.cs b/src/Merge.Client/Filestorage/Types/ExternalTargetFieldApiResponse.cs index ee51b7d4..5cf13c8a 100644 --- a/src/Merge.Client/Filestorage/Types/ExternalTargetFieldApiResponse.cs +++ b/src/Merge.Client/Filestorage/Types/ExternalTargetFieldApiResponse.cs @@ -1,24 +1,23 @@ using System.Text.Json.Serialization; -using Merge.Client.Filestorage; #nullable enable namespace Merge.Client.Filestorage; -public class ExternalTargetFieldApiResponse +public record ExternalTargetFieldApiResponse { [JsonPropertyName("File")] - public IEnumerable? File { get; init; } + public IEnumerable? File { get; set; } [JsonPropertyName("Folder")] - public IEnumerable? Folder { get; init; } + public IEnumerable? Folder { get; set; } [JsonPropertyName("Drive")] - public IEnumerable? Drive { get; init; } + public IEnumerable? Drive { get; set; } [JsonPropertyName("Group")] - public IEnumerable? Group { get; init; } + public IEnumerable? Group { get; set; } [JsonPropertyName("User")] - public IEnumerable? User { get; init; } + public IEnumerable? User { get; set; } } diff --git a/src/Merge.Client/Filestorage/Types/FieldMappingApiInstance.cs b/src/Merge.Client/Filestorage/Types/FieldMappingApiInstance.cs index 7cce120f..c2b4b82a 100644 --- a/src/Merge.Client/Filestorage/Types/FieldMappingApiInstance.cs +++ b/src/Merge.Client/Filestorage/Types/FieldMappingApiInstance.cs @@ -1,21 +1,20 @@ using System.Text.Json.Serialization; -using Merge.Client.Filestorage; #nullable enable namespace Merge.Client.Filestorage; -public class FieldMappingApiInstance +public record FieldMappingApiInstance { [JsonPropertyName("id")] - public string? Id { get; init; } + public string? Id { get; set; } [JsonPropertyName("is_integration_wide")] - public bool? IsIntegrationWide { get; init; } + public bool? IsIntegrationWide { get; set; } [JsonPropertyName("target_field")] - public FieldMappingApiInstanceTargetField? TargetField { get; init; } + public FieldMappingApiInstanceTargetField? TargetField { get; set; } [JsonPropertyName("remote_field")] - public FieldMappingApiInstanceRemoteField? RemoteField { get; init; } + public FieldMappingApiInstanceRemoteField? RemoteField { get; set; } } diff --git a/src/Merge.Client/Filestorage/Types/FieldMappingApiInstanceRemoteField.cs b/src/Merge.Client/Filestorage/Types/FieldMappingApiInstanceRemoteField.cs index 911a1be9..d80c4b6f 100644 --- a/src/Merge.Client/Filestorage/Types/FieldMappingApiInstanceRemoteField.cs +++ b/src/Merge.Client/Filestorage/Types/FieldMappingApiInstanceRemoteField.cs @@ -1,18 +1,17 @@ using System.Text.Json.Serialization; -using Merge.Client.Filestorage; #nullable enable namespace Merge.Client.Filestorage; -public class FieldMappingApiInstanceRemoteField +public record FieldMappingApiInstanceRemoteField { [JsonPropertyName("remote_key_name")] - public string RemoteKeyName { get; init; } + public required string RemoteKeyName { get; set; } [JsonPropertyName("schema")] - public Dictionary Schema { get; init; } + public Dictionary Schema { get; set; } = new Dictionary(); [JsonPropertyName("remote_endpoint_info")] - public FieldMappingApiInstanceRemoteFieldRemoteEndpointInfo RemoteEndpointInfo { get; init; } + public required FieldMappingApiInstanceRemoteFieldRemoteEndpointInfo RemoteEndpointInfo { get; set; } } diff --git a/src/Merge.Client/Filestorage/Types/FieldMappingApiInstanceRemoteFieldRemoteEndpointInfo.cs b/src/Merge.Client/Filestorage/Types/FieldMappingApiInstanceRemoteFieldRemoteEndpointInfo.cs index 944670fd..bd583d22 100644 --- a/src/Merge.Client/Filestorage/Types/FieldMappingApiInstanceRemoteFieldRemoteEndpointInfo.cs +++ b/src/Merge.Client/Filestorage/Types/FieldMappingApiInstanceRemoteFieldRemoteEndpointInfo.cs @@ -4,14 +4,14 @@ namespace Merge.Client.Filestorage; -public class FieldMappingApiInstanceRemoteFieldRemoteEndpointInfo +public record FieldMappingApiInstanceRemoteFieldRemoteEndpointInfo { [JsonPropertyName("method")] - public string? Method { get; init; } + public string? Method { get; set; } [JsonPropertyName("url_path")] - public string? UrlPath { get; init; } + public string? UrlPath { get; set; } [JsonPropertyName("field_traversal_path")] - public IEnumerable? FieldTraversalPath { get; init; } + public IEnumerable? FieldTraversalPath { get; set; } } diff --git a/src/Merge.Client/Filestorage/Types/FieldMappingApiInstanceResponse.cs b/src/Merge.Client/Filestorage/Types/FieldMappingApiInstanceResponse.cs index fb9378e5..f9d0f548 100644 --- a/src/Merge.Client/Filestorage/Types/FieldMappingApiInstanceResponse.cs +++ b/src/Merge.Client/Filestorage/Types/FieldMappingApiInstanceResponse.cs @@ -1,24 +1,23 @@ using System.Text.Json.Serialization; -using Merge.Client.Filestorage; #nullable enable namespace Merge.Client.Filestorage; -public class FieldMappingApiInstanceResponse +public record FieldMappingApiInstanceResponse { [JsonPropertyName("File")] - public IEnumerable? File { get; init; } + public IEnumerable? File { get; set; } [JsonPropertyName("Folder")] - public IEnumerable? Folder { get; init; } + public IEnumerable? Folder { get; set; } [JsonPropertyName("Drive")] - public IEnumerable? Drive { get; init; } + public IEnumerable? Drive { get; set; } [JsonPropertyName("Group")] - public IEnumerable? Group { get; init; } + public IEnumerable? Group { get; set; } [JsonPropertyName("User")] - public IEnumerable? User { get; init; } + public IEnumerable? User { get; set; } } diff --git a/src/Merge.Client/Filestorage/Types/FieldMappingApiInstanceTargetField.cs b/src/Merge.Client/Filestorage/Types/FieldMappingApiInstanceTargetField.cs index 9997eb99..b74c9b7b 100644 --- a/src/Merge.Client/Filestorage/Types/FieldMappingApiInstanceTargetField.cs +++ b/src/Merge.Client/Filestorage/Types/FieldMappingApiInstanceTargetField.cs @@ -4,14 +4,14 @@ namespace Merge.Client.Filestorage; -public class FieldMappingApiInstanceTargetField +public record FieldMappingApiInstanceTargetField { [JsonPropertyName("name")] - public string Name { get; init; } + public required string Name { get; set; } [JsonPropertyName("description")] - public string Description { get; init; } + public required string Description { get; set; } [JsonPropertyName("is_organization_wide")] - public bool IsOrganizationWide { get; init; } + public required bool IsOrganizationWide { get; set; } } diff --git a/src/Merge.Client/Filestorage/Types/FieldMappingInstanceResponse.cs b/src/Merge.Client/Filestorage/Types/FieldMappingInstanceResponse.cs index 29b70853..0e6bdfe1 100644 --- a/src/Merge.Client/Filestorage/Types/FieldMappingInstanceResponse.cs +++ b/src/Merge.Client/Filestorage/Types/FieldMappingInstanceResponse.cs @@ -1,21 +1,22 @@ using System.Text.Json.Serialization; -using Merge.Client.Filestorage; #nullable enable namespace Merge.Client.Filestorage; -public class FieldMappingInstanceResponse +public record FieldMappingInstanceResponse { [JsonPropertyName("model")] - public FieldMappingApiInstance Model { get; init; } + public required FieldMappingApiInstance Model { get; set; } [JsonPropertyName("warnings")] - public IEnumerable Warnings { get; init; } + public IEnumerable Warnings { get; set; } = + new List(); [JsonPropertyName("errors")] - public IEnumerable Errors { get; init; } + public IEnumerable Errors { get; set; } = + new List(); [JsonPropertyName("logs")] - public IEnumerable? Logs { get; init; } + public IEnumerable? Logs { get; set; } } diff --git a/src/Merge.Client/Filestorage/Types/FieldPermissionDeserializer.cs b/src/Merge.Client/Filestorage/Types/FieldPermissionDeserializer.cs index 189ea94d..bd72efdb 100644 --- a/src/Merge.Client/Filestorage/Types/FieldPermissionDeserializer.cs +++ b/src/Merge.Client/Filestorage/Types/FieldPermissionDeserializer.cs @@ -4,11 +4,11 @@ namespace Merge.Client.Filestorage; -public class FieldPermissionDeserializer +public record FieldPermissionDeserializer { [JsonPropertyName("enabled")] - public IEnumerable? Enabled { get; init; } + public IEnumerable? Enabled { get; set; } [JsonPropertyName("disabled")] - public IEnumerable? Disabled { get; init; } + public IEnumerable? Disabled { get; set; } } diff --git a/src/Merge.Client/Filestorage/Types/FieldPermissionDeserializerRequest.cs b/src/Merge.Client/Filestorage/Types/FieldPermissionDeserializerRequest.cs index 9c3380b3..8e497a69 100644 --- a/src/Merge.Client/Filestorage/Types/FieldPermissionDeserializerRequest.cs +++ b/src/Merge.Client/Filestorage/Types/FieldPermissionDeserializerRequest.cs @@ -4,11 +4,11 @@ namespace Merge.Client.Filestorage; -public class FieldPermissionDeserializerRequest +public record FieldPermissionDeserializerRequest { [JsonPropertyName("enabled")] - public IEnumerable? Enabled { get; init; } + public IEnumerable? Enabled { get; set; } [JsonPropertyName("disabled")] - public IEnumerable? Disabled { get; init; } + public IEnumerable? Disabled { get; set; } } diff --git a/src/Merge.Client/Filestorage/Types/File.cs b/src/Merge.Client/Filestorage/Types/File.cs index 9fdb9bf6..76592904 100644 --- a/src/Merge.Client/Filestorage/Types/File.cs +++ b/src/Merge.Client/Filestorage/Types/File.cs @@ -1,77 +1,76 @@ using System.Text.Json.Serialization; using Merge.Client.Core; -using Merge.Client.Filestorage; using OneOf; #nullable enable namespace Merge.Client.Filestorage; -public class File +public record File { [JsonPropertyName("id")] - public string? Id { get; init; } + public string? Id { get; set; } /// /// The third-party API ID of the matching object. /// [JsonPropertyName("remote_id")] - public string? RemoteId { get; init; } + public string? RemoteId { get; set; } /// /// The datetime that this object was created by Merge. /// [JsonPropertyName("created_at")] - public DateTime? CreatedAt { get; init; } + public DateTime? CreatedAt { get; set; } /// /// The datetime that this object was modified by Merge. /// [JsonPropertyName("modified_at")] - public DateTime? ModifiedAt { get; init; } + public DateTime? ModifiedAt { get; set; } /// /// The file's name. /// [JsonPropertyName("name")] - public string? Name { get; init; } + public string? Name { get; set; } /// /// The URL to access the file. /// [JsonPropertyName("file_url")] - public string? FileUrl { get; init; } + public string? FileUrl { get; set; } /// /// The URL that produces a thumbnail preview of the file. Typically an image. /// [JsonPropertyName("file_thumbnail_url")] - public string? FileThumbnailUrl { get; init; } + public string? FileThumbnailUrl { get; set; } /// /// The file's size, in bytes. /// [JsonPropertyName("size")] - public int? Size { get; init; } + public long? Size { get; set; } /// /// The file's mime type. /// [JsonPropertyName("mime_type")] - public string? MimeType { get; init; } + public string? MimeType { get; set; } /// /// The file's description. /// [JsonPropertyName("description")] - public string? Description { get; init; } + public string? Description { get; set; } /// /// The folder that the file belongs to. /// [JsonPropertyName("folder")] [JsonConverter(typeof(OneOfSerializer>))] - public OneOf? Folder { get; init; } + public OneOf? Folder { get; set; } /// /// The Permission object is used to represent a user's or group's access to a File or Folder. Permissions are unexpanded by default. Use the query param `expand=permissions` to see more details under `GET /files`. @@ -86,36 +85,36 @@ public OneOf< string, PermissionRequest, IEnumerable> - >? Permissions { get; init; } + >? Permissions { get; set; } /// /// The drive that the file belongs to. /// [JsonPropertyName("drive")] [JsonConverter(typeof(OneOfSerializer>))] - public OneOf? Drive { get; init; } + public OneOf? Drive { get; set; } /// /// When the third party's file was created. /// [JsonPropertyName("remote_created_at")] - public DateTime? RemoteCreatedAt { get; init; } + public DateTime? RemoteCreatedAt { get; set; } /// /// When the third party's file was updated. /// [JsonPropertyName("remote_updated_at")] - public DateTime? RemoteUpdatedAt { get; init; } + public DateTime? RemoteUpdatedAt { get; set; } /// /// Indicates whether or not this object has been deleted in the third party platform. /// [JsonPropertyName("remote_was_deleted")] - public bool? RemoteWasDeleted { get; init; } + public bool? RemoteWasDeleted { get; set; } [JsonPropertyName("field_mappings")] - public Dictionary? FieldMappings { get; init; } + public Dictionary? FieldMappings { get; set; } [JsonPropertyName("remote_data")] - public IEnumerable>? RemoteData { get; init; } + public IEnumerable>? RemoteData { get; set; } } diff --git a/src/Merge.Client/Filestorage/Types/FileRequest.cs b/src/Merge.Client/Filestorage/Types/FileRequest.cs index 7bf02efd..28157dd9 100644 --- a/src/Merge.Client/Filestorage/Types/FileRequest.cs +++ b/src/Merge.Client/Filestorage/Types/FileRequest.cs @@ -1,56 +1,55 @@ using System.Text.Json.Serialization; using Merge.Client.Core; -using Merge.Client.Filestorage; using OneOf; #nullable enable namespace Merge.Client.Filestorage; -public class FileRequest +public record FileRequest { /// /// The file's name. /// [JsonPropertyName("name")] - public string? Name { get; init; } + public string? Name { get; set; } /// /// The URL to access the file. /// [JsonPropertyName("file_url")] - public string? FileUrl { get; init; } + public string? FileUrl { get; set; } /// /// The URL that produces a thumbnail preview of the file. Typically an image. /// [JsonPropertyName("file_thumbnail_url")] - public string? FileThumbnailUrl { get; init; } + public string? FileThumbnailUrl { get; set; } /// /// The file's size, in bytes. /// [JsonPropertyName("size")] - public int? Size { get; init; } + public long? Size { get; set; } /// /// The file's mime type. /// [JsonPropertyName("mime_type")] - public string? MimeType { get; init; } + public string? MimeType { get; set; } /// /// The file's description. /// [JsonPropertyName("description")] - public string? Description { get; init; } + public string? Description { get; set; } /// /// The folder that the file belongs to. /// [JsonPropertyName("folder")] [JsonConverter(typeof(OneOfSerializer>))] - public OneOf? Folder { get; init; } + public OneOf? Folder { get; set; } /// /// The Permission object is used to represent a user's or group's access to a File or Folder. Permissions are unexpanded by default. Use the query param `expand=permissions` to see more details under `GET /files`. @@ -65,18 +64,18 @@ public OneOf< string, PermissionRequest, IEnumerable> - >? Permissions { get; init; } + >? Permissions { get; set; } /// /// The drive that the file belongs to. /// [JsonPropertyName("drive")] [JsonConverter(typeof(OneOfSerializer>))] - public OneOf? Drive { get; init; } + public OneOf? Drive { get; set; } [JsonPropertyName("integration_params")] - public Dictionary? IntegrationParams { get; init; } + public Dictionary? IntegrationParams { get; set; } [JsonPropertyName("linked_account_params")] - public Dictionary? LinkedAccountParams { get; init; } + public Dictionary? LinkedAccountParams { get; set; } } diff --git a/src/Merge.Client/Filestorage/Types/FileStorageFileResponse.cs b/src/Merge.Client/Filestorage/Types/FileStorageFileResponse.cs index a05543f7..44e76a88 100644 --- a/src/Merge.Client/Filestorage/Types/FileStorageFileResponse.cs +++ b/src/Merge.Client/Filestorage/Types/FileStorageFileResponse.cs @@ -1,21 +1,22 @@ using System.Text.Json.Serialization; -using Merge.Client.Filestorage; #nullable enable namespace Merge.Client.Filestorage; -public class FileStorageFileResponse +public record FileStorageFileResponse { [JsonPropertyName("model")] - public File Model { get; init; } + public required File Model { get; set; } [JsonPropertyName("warnings")] - public IEnumerable Warnings { get; init; } + public IEnumerable Warnings { get; set; } = + new List(); [JsonPropertyName("errors")] - public IEnumerable Errors { get; init; } + public IEnumerable Errors { get; set; } = + new List(); [JsonPropertyName("logs")] - public IEnumerable? Logs { get; init; } + public IEnumerable? Logs { get; set; } } diff --git a/src/Merge.Client/Filestorage/Types/FileStorageFolderResponse.cs b/src/Merge.Client/Filestorage/Types/FileStorageFolderResponse.cs index 1f4b0eb1..3b05e21f 100644 --- a/src/Merge.Client/Filestorage/Types/FileStorageFolderResponse.cs +++ b/src/Merge.Client/Filestorage/Types/FileStorageFolderResponse.cs @@ -1,21 +1,22 @@ using System.Text.Json.Serialization; -using Merge.Client.Filestorage; #nullable enable namespace Merge.Client.Filestorage; -public class FileStorageFolderResponse +public record FileStorageFolderResponse { [JsonPropertyName("model")] - public Folder Model { get; init; } + public required Folder Model { get; set; } [JsonPropertyName("warnings")] - public IEnumerable Warnings { get; init; } + public IEnumerable Warnings { get; set; } = + new List(); [JsonPropertyName("errors")] - public IEnumerable Errors { get; init; } + public IEnumerable Errors { get; set; } = + new List(); [JsonPropertyName("logs")] - public IEnumerable? Logs { get; init; } + public IEnumerable? Logs { get; set; } } diff --git a/src/Merge.Client/Filestorage/Types/Folder.cs b/src/Merge.Client/Filestorage/Types/Folder.cs index a040669b..5c1649b4 100644 --- a/src/Merge.Client/Filestorage/Types/Folder.cs +++ b/src/Merge.Client/Filestorage/Types/Folder.cs @@ -1,72 +1,71 @@ using System.Text.Json.Serialization; using Merge.Client.Core; -using Merge.Client.Filestorage; using OneOf; #nullable enable namespace Merge.Client.Filestorage; -public class Folder +public record Folder { [JsonPropertyName("id")] - public string? Id { get; init; } + public string? Id { get; set; } /// /// The third-party API ID of the matching object. /// [JsonPropertyName("remote_id")] - public string? RemoteId { get; init; } + public string? RemoteId { get; set; } /// /// The datetime that this object was created by Merge. /// [JsonPropertyName("created_at")] - public DateTime? CreatedAt { get; init; } + public DateTime? CreatedAt { get; set; } /// /// The datetime that this object was modified by Merge. /// [JsonPropertyName("modified_at")] - public DateTime? ModifiedAt { get; init; } + public DateTime? ModifiedAt { get; set; } /// /// The folder's name. /// [JsonPropertyName("name")] - public string? Name { get; init; } + public string? Name { get; set; } /// /// The URL to access the folder. /// [JsonPropertyName("folder_url")] - public string? FolderUrl { get; init; } + public string? FolderUrl { get; set; } /// /// The folder's size, in bytes. /// [JsonPropertyName("size")] - public int? Size { get; init; } + public long? Size { get; set; } /// /// The folder's description. /// [JsonPropertyName("description")] - public string? Description { get; init; } + public string? Description { get; set; } /// /// The folder that the folder belongs to. /// [JsonPropertyName("parent_folder")] [JsonConverter(typeof(OneOfSerializer>))] - public OneOf? ParentFolder { get; init; } + public OneOf? ParentFolder { get; set; } /// /// The drive that the folder belongs to. /// [JsonPropertyName("drive")] [JsonConverter(typeof(OneOfSerializer>))] - public OneOf? Drive { get; init; } + public OneOf? Drive { get; set; } /// /// The Permission object is used to represent a user's or group's access to a File or Folder. Permissions are unexpanded by default. Use the query param `expand=permissions` to see more details under `GET /folders`. @@ -81,29 +80,29 @@ public OneOf< string, PermissionRequest, IEnumerable> - >? Permissions { get; init; } + >? Permissions { get; set; } /// /// When the third party's folder was created. /// [JsonPropertyName("remote_created_at")] - public DateTime? RemoteCreatedAt { get; init; } + public DateTime? RemoteCreatedAt { get; set; } /// /// When the third party's folder was updated. /// [JsonPropertyName("remote_updated_at")] - public DateTime? RemoteUpdatedAt { get; init; } + public DateTime? RemoteUpdatedAt { get; set; } /// /// Indicates whether or not this object has been deleted in the third party platform. /// [JsonPropertyName("remote_was_deleted")] - public bool? RemoteWasDeleted { get; init; } + public bool? RemoteWasDeleted { get; set; } [JsonPropertyName("field_mappings")] - public Dictionary? FieldMappings { get; init; } + public Dictionary? FieldMappings { get; set; } [JsonPropertyName("remote_data")] - public IEnumerable>? RemoteData { get; init; } + public IEnumerable>? RemoteData { get; set; } } diff --git a/src/Merge.Client/Filestorage/Types/FolderRequest.cs b/src/Merge.Client/Filestorage/Types/FolderRequest.cs index 9fe815f4..3c5dede1 100644 --- a/src/Merge.Client/Filestorage/Types/FolderRequest.cs +++ b/src/Merge.Client/Filestorage/Types/FolderRequest.cs @@ -1,51 +1,50 @@ using System.Text.Json.Serialization; using Merge.Client.Core; -using Merge.Client.Filestorage; using OneOf; #nullable enable namespace Merge.Client.Filestorage; -public class FolderRequest +public record FolderRequest { /// /// The folder's name. /// [JsonPropertyName("name")] - public string? Name { get; init; } + public string? Name { get; set; } /// /// The URL to access the folder. /// [JsonPropertyName("folder_url")] - public string? FolderUrl { get; init; } + public string? FolderUrl { get; set; } /// /// The folder's size, in bytes. /// [JsonPropertyName("size")] - public int? Size { get; init; } + public long? Size { get; set; } /// /// The folder's description. /// [JsonPropertyName("description")] - public string? Description { get; init; } + public string? Description { get; set; } /// /// The folder that the folder belongs to. /// [JsonPropertyName("parent_folder")] [JsonConverter(typeof(OneOfSerializer>))] - public OneOf? ParentFolder { get; init; } + public OneOf? ParentFolder { get; set; } /// /// The drive that the folder belongs to. /// [JsonPropertyName("drive")] [JsonConverter(typeof(OneOfSerializer>))] - public OneOf? Drive { get; init; } + public OneOf? Drive { get; set; } /// /// The Permission object is used to represent a user's or group's access to a File or Folder. Permissions are unexpanded by default. Use the query param `expand=permissions` to see more details under `GET /folders`. @@ -60,11 +59,11 @@ public OneOf< string, PermissionRequest, IEnumerable> - >? Permissions { get; init; } + >? Permissions { get; set; } [JsonPropertyName("integration_params")] - public Dictionary? IntegrationParams { get; init; } + public Dictionary? IntegrationParams { get; set; } [JsonPropertyName("linked_account_params")] - public Dictionary? LinkedAccountParams { get; init; } + public Dictionary? LinkedAccountParams { get; set; } } diff --git a/src/Merge.Client/Filestorage/Types/Group.cs b/src/Merge.Client/Filestorage/Types/Group.cs index 22448012..e2e3ee4f 100644 --- a/src/Merge.Client/Filestorage/Types/Group.cs +++ b/src/Merge.Client/Filestorage/Types/Group.cs @@ -4,50 +4,50 @@ namespace Merge.Client.Filestorage; -public class Group +public record Group { [JsonPropertyName("id")] - public string? Id { get; init; } + public string? Id { get; set; } /// /// The third-party API ID of the matching object. /// [JsonPropertyName("remote_id")] - public string? RemoteId { get; init; } + public string? RemoteId { get; set; } /// /// The datetime that this object was created by Merge. /// [JsonPropertyName("created_at")] - public DateTime? CreatedAt { get; init; } + public DateTime? CreatedAt { get; set; } /// /// The datetime that this object was modified by Merge. /// [JsonPropertyName("modified_at")] - public DateTime? ModifiedAt { get; init; } + public DateTime? ModifiedAt { get; set; } /// /// The group's name. /// [JsonPropertyName("name")] - public string? Name { get; init; } + public string? Name { get; set; } /// /// The users that belong in the group. If null, this typically means it's either a domain or the third-party platform does not surface this information. /// [JsonPropertyName("users")] - public IEnumerable Users { get; init; } + public IEnumerable Users { get; set; } = new List(); /// /// Indicates whether or not this object has been deleted in the third party platform. /// [JsonPropertyName("remote_was_deleted")] - public bool? RemoteWasDeleted { get; init; } + public bool? RemoteWasDeleted { get; set; } [JsonPropertyName("field_mappings")] - public Dictionary? FieldMappings { get; init; } + public Dictionary? FieldMappings { get; set; } [JsonPropertyName("remote_data")] - public IEnumerable>? RemoteData { get; init; } + public IEnumerable>? RemoteData { get; set; } } diff --git a/src/Merge.Client/Filestorage/Types/IndividualCommonModelScopeDeserializer.cs b/src/Merge.Client/Filestorage/Types/IndividualCommonModelScopeDeserializer.cs index b057033e..e684e2fa 100644 --- a/src/Merge.Client/Filestorage/Types/IndividualCommonModelScopeDeserializer.cs +++ b/src/Merge.Client/Filestorage/Types/IndividualCommonModelScopeDeserializer.cs @@ -1,18 +1,17 @@ using System.Text.Json.Serialization; -using Merge.Client.Filestorage; #nullable enable namespace Merge.Client.Filestorage; -public class IndividualCommonModelScopeDeserializer +public record IndividualCommonModelScopeDeserializer { [JsonPropertyName("model_name")] - public string ModelName { get; init; } + public required string ModelName { get; set; } [JsonPropertyName("model_permissions")] - public Dictionary? ModelPermissions { get; init; } + public Dictionary? ModelPermissions { get; set; } [JsonPropertyName("field_permissions")] - public FieldPermissionDeserializer? FieldPermissions { get; init; } + public FieldPermissionDeserializer? FieldPermissions { get; set; } } diff --git a/src/Merge.Client/Filestorage/Types/IndividualCommonModelScopeDeserializerRequest.cs b/src/Merge.Client/Filestorage/Types/IndividualCommonModelScopeDeserializerRequest.cs index 9b606e22..bb00ce73 100644 --- a/src/Merge.Client/Filestorage/Types/IndividualCommonModelScopeDeserializerRequest.cs +++ b/src/Merge.Client/Filestorage/Types/IndividualCommonModelScopeDeserializerRequest.cs @@ -1,18 +1,17 @@ using System.Text.Json.Serialization; -using Merge.Client.Filestorage; #nullable enable namespace Merge.Client.Filestorage; -public class IndividualCommonModelScopeDeserializerRequest +public record IndividualCommonModelScopeDeserializerRequest { [JsonPropertyName("model_name")] - public string ModelName { get; init; } + public required string ModelName { get; set; } [JsonPropertyName("model_permissions")] - public Dictionary? ModelPermissions { get; init; } + public Dictionary? ModelPermissions { get; set; } [JsonPropertyName("field_permissions")] - public FieldPermissionDeserializerRequest? FieldPermissions { get; init; } + public FieldPermissionDeserializerRequest? FieldPermissions { get; set; } } diff --git a/src/Merge.Client/Filestorage/Types/Issue.cs b/src/Merge.Client/Filestorage/Types/Issue.cs index 806f205e..961110a5 100644 --- a/src/Merge.Client/Filestorage/Types/Issue.cs +++ b/src/Merge.Client/Filestorage/Types/Issue.cs @@ -1,14 +1,13 @@ using System.Text.Json.Serialization; -using Merge.Client.Filestorage; #nullable enable namespace Merge.Client.Filestorage; -public class Issue +public record Issue { [JsonPropertyName("id")] - public string? Id { get; init; } + public string? Id { get; set; } /// /// Status of the issue. Options: ('ONGOING', 'RESOLVED') @@ -17,23 +16,23 @@ public class Issue /// - `RESOLVED` - RESOLVED /// [JsonPropertyName("status")] - public IssueStatusEnum? Status { get; init; } + public IssueStatusEnum? Status { get; set; } [JsonPropertyName("error_description")] - public string ErrorDescription { get; init; } + public required string ErrorDescription { get; set; } [JsonPropertyName("end_user")] - public Dictionary? EndUser { get; init; } + public Dictionary? EndUser { get; set; } [JsonPropertyName("first_incident_time")] - public DateTime? FirstIncidentTime { get; init; } + public DateTime? FirstIncidentTime { get; set; } [JsonPropertyName("last_incident_time")] - public DateTime? LastIncidentTime { get; init; } + public DateTime? LastIncidentTime { get; set; } [JsonPropertyName("is_muted")] - public bool? IsMuted { get; init; } + public bool? IsMuted { get; set; } [JsonPropertyName("error_details")] - public IEnumerable? ErrorDetails { get; init; } + public IEnumerable? ErrorDetails { get; set; } } diff --git a/src/Merge.Client/Filestorage/Types/IssueStatusEnum.cs b/src/Merge.Client/Filestorage/Types/IssueStatusEnum.cs index 0b70986e..6c1a89ae 100644 --- a/src/Merge.Client/Filestorage/Types/IssueStatusEnum.cs +++ b/src/Merge.Client/Filestorage/Types/IssueStatusEnum.cs @@ -1,7 +1,6 @@ using System.Runtime.Serialization; using System.Text.Json.Serialization; using Merge.Client.Core; -using Merge.Client.Filestorage; #nullable enable diff --git a/src/Merge.Client/Filestorage/Types/LinkToken.cs b/src/Merge.Client/Filestorage/Types/LinkToken.cs index 8beeedf3..2e562560 100644 --- a/src/Merge.Client/Filestorage/Types/LinkToken.cs +++ b/src/Merge.Client/Filestorage/Types/LinkToken.cs @@ -4,14 +4,14 @@ namespace Merge.Client.Filestorage; -public class LinkToken +public record LinkToken { [JsonPropertyName("link_token")] - public string LinkToken_ { get; init; } + public required string LinkToken_ { get; set; } [JsonPropertyName("integration_name")] - public string? IntegrationName { get; init; } + public string? IntegrationName { get; set; } [JsonPropertyName("magic_link_url")] - public string? MagicLinkUrl { get; init; } + public string? MagicLinkUrl { get; set; } } diff --git a/src/Merge.Client/Filestorage/Types/LinkedAccountStatus.cs b/src/Merge.Client/Filestorage/Types/LinkedAccountStatus.cs index 361fcd21..6726c227 100644 --- a/src/Merge.Client/Filestorage/Types/LinkedAccountStatus.cs +++ b/src/Merge.Client/Filestorage/Types/LinkedAccountStatus.cs @@ -4,11 +4,11 @@ namespace Merge.Client.Filestorage; -public class LinkedAccountStatus +public record LinkedAccountStatus { [JsonPropertyName("linked_account_status")] - public string LinkedAccountStatus_ { get; init; } + public required string LinkedAccountStatus_ { get; set; } [JsonPropertyName("can_make_request")] - public bool CanMakeRequest { get; init; } + public required bool CanMakeRequest { get; set; } } diff --git a/src/Merge.Client/Filestorage/Types/MetaResponse.cs b/src/Merge.Client/Filestorage/Types/MetaResponse.cs index cfef8983..744ffb82 100644 --- a/src/Merge.Client/Filestorage/Types/MetaResponse.cs +++ b/src/Merge.Client/Filestorage/Types/MetaResponse.cs @@ -1,24 +1,24 @@ using System.Text.Json.Serialization; -using Merge.Client.Filestorage; #nullable enable namespace Merge.Client.Filestorage; -public class MetaResponse +public record MetaResponse { [JsonPropertyName("request_schema")] - public Dictionary RequestSchema { get; init; } + public Dictionary RequestSchema { get; set; } = + new Dictionary(); [JsonPropertyName("remote_field_classes")] - public Dictionary? RemoteFieldClasses { get; init; } + public Dictionary? RemoteFieldClasses { get; set; } [JsonPropertyName("status")] - public LinkedAccountStatus? Status { get; init; } + public LinkedAccountStatus? Status { get; set; } [JsonPropertyName("has_conditional_params")] - public bool HasConditionalParams { get; init; } + public required bool HasConditionalParams { get; set; } [JsonPropertyName("has_required_linked_account_params")] - public bool HasRequiredLinkedAccountParams { get; init; } + public required bool HasRequiredLinkedAccountParams { get; set; } } diff --git a/src/Merge.Client/Filestorage/Types/MethodEnum.cs b/src/Merge.Client/Filestorage/Types/MethodEnum.cs index 332de2a6..fde38dfe 100644 --- a/src/Merge.Client/Filestorage/Types/MethodEnum.cs +++ b/src/Merge.Client/Filestorage/Types/MethodEnum.cs @@ -1,7 +1,6 @@ using System.Runtime.Serialization; using System.Text.Json.Serialization; using Merge.Client.Core; -using Merge.Client.Filestorage; #nullable enable diff --git a/src/Merge.Client/Filestorage/Types/ModelOperation.cs b/src/Merge.Client/Filestorage/Types/ModelOperation.cs index a936cf93..ce2cd3c2 100644 --- a/src/Merge.Client/Filestorage/Types/ModelOperation.cs +++ b/src/Merge.Client/Filestorage/Types/ModelOperation.cs @@ -4,17 +4,17 @@ namespace Merge.Client.Filestorage; -public class ModelOperation +public record ModelOperation { [JsonPropertyName("model_name")] - public string ModelName { get; init; } + public required string ModelName { get; set; } [JsonPropertyName("available_operations")] - public IEnumerable AvailableOperations { get; init; } + public IEnumerable AvailableOperations { get; set; } = new List(); [JsonPropertyName("required_post_parameters")] - public IEnumerable RequiredPostParameters { get; init; } + public IEnumerable RequiredPostParameters { get; set; } = new List(); [JsonPropertyName("supported_fields")] - public IEnumerable SupportedFields { get; init; } + public IEnumerable SupportedFields { get; set; } = new List(); } diff --git a/src/Merge.Client/Filestorage/Types/ModelPermissionDeserializer.cs b/src/Merge.Client/Filestorage/Types/ModelPermissionDeserializer.cs index 94daa031..6cceddf4 100644 --- a/src/Merge.Client/Filestorage/Types/ModelPermissionDeserializer.cs +++ b/src/Merge.Client/Filestorage/Types/ModelPermissionDeserializer.cs @@ -4,8 +4,8 @@ namespace Merge.Client.Filestorage; -public class ModelPermissionDeserializer +public record ModelPermissionDeserializer { [JsonPropertyName("is_enabled")] - public bool? IsEnabled { get; init; } + public bool? IsEnabled { get; set; } } diff --git a/src/Merge.Client/Filestorage/Types/ModelPermissionDeserializerRequest.cs b/src/Merge.Client/Filestorage/Types/ModelPermissionDeserializerRequest.cs index a486f5c7..68cf0918 100644 --- a/src/Merge.Client/Filestorage/Types/ModelPermissionDeserializerRequest.cs +++ b/src/Merge.Client/Filestorage/Types/ModelPermissionDeserializerRequest.cs @@ -4,8 +4,8 @@ namespace Merge.Client.Filestorage; -public class ModelPermissionDeserializerRequest +public record ModelPermissionDeserializerRequest { [JsonPropertyName("is_enabled")] - public bool? IsEnabled { get; init; } + public bool? IsEnabled { get; set; } } diff --git a/src/Merge.Client/Filestorage/Types/MultipartFormFieldRequest.cs b/src/Merge.Client/Filestorage/Types/MultipartFormFieldRequest.cs index a2dd32e5..d09405a9 100644 --- a/src/Merge.Client/Filestorage/Types/MultipartFormFieldRequest.cs +++ b/src/Merge.Client/Filestorage/Types/MultipartFormFieldRequest.cs @@ -1,23 +1,22 @@ using System.Text.Json.Serialization; -using Merge.Client.Filestorage; #nullable enable namespace Merge.Client.Filestorage; -public class MultipartFormFieldRequest +public record MultipartFormFieldRequest { /// /// The name of the form field /// [JsonPropertyName("name")] - public string Name { get; init; } + public required string Name { get; set; } /// /// The data for the form field. /// [JsonPropertyName("data")] - public string Data { get; init; } + public required string Data { get; set; } /// /// The encoding of the value of `data`. Defaults to `RAW` if not defined. @@ -27,17 +26,17 @@ public class MultipartFormFieldRequest /// - `GZIP_BASE64` - GZIP_BASE64 /// [JsonPropertyName("encoding")] - public EncodingEnum? Encoding { get; init; } + public EncodingEnum? Encoding { get; set; } /// /// The file name of the form field, if the field is for a file. /// [JsonPropertyName("file_name")] - public string? FileName { get; init; } + public string? FileName { get; set; } /// /// The MIME type of the file, if the field is for a file. /// [JsonPropertyName("content_type")] - public string? ContentType { get; init; } + public string? ContentType { get; set; } } diff --git a/src/Merge.Client/Filestorage/Types/PaginatedAccountDetailsAndActionsList.cs b/src/Merge.Client/Filestorage/Types/PaginatedAccountDetailsAndActionsList.cs index b8d032d8..bc04e583 100644 --- a/src/Merge.Client/Filestorage/Types/PaginatedAccountDetailsAndActionsList.cs +++ b/src/Merge.Client/Filestorage/Types/PaginatedAccountDetailsAndActionsList.cs @@ -1,18 +1,17 @@ using System.Text.Json.Serialization; -using Merge.Client.Filestorage; #nullable enable namespace Merge.Client.Filestorage; -public class PaginatedAccountDetailsAndActionsList +public record PaginatedAccountDetailsAndActionsList { [JsonPropertyName("next")] - public string? Next { get; init; } + public string? Next { get; set; } [JsonPropertyName("previous")] - public string? Previous { get; init; } + public string? Previous { get; set; } [JsonPropertyName("results")] - public IEnumerable? Results { get; init; } + public IEnumerable? Results { get; set; } } diff --git a/src/Merge.Client/Filestorage/Types/PaginatedAuditLogEventList.cs b/src/Merge.Client/Filestorage/Types/PaginatedAuditLogEventList.cs index fd5624ea..d62c69fd 100644 --- a/src/Merge.Client/Filestorage/Types/PaginatedAuditLogEventList.cs +++ b/src/Merge.Client/Filestorage/Types/PaginatedAuditLogEventList.cs @@ -1,18 +1,17 @@ using System.Text.Json.Serialization; -using Merge.Client.Filestorage; #nullable enable namespace Merge.Client.Filestorage; -public class PaginatedAuditLogEventList +public record PaginatedAuditLogEventList { [JsonPropertyName("next")] - public string? Next { get; init; } + public string? Next { get; set; } [JsonPropertyName("previous")] - public string? Previous { get; init; } + public string? Previous { get; set; } [JsonPropertyName("results")] - public IEnumerable? Results { get; init; } + public IEnumerable? Results { get; set; } } diff --git a/src/Merge.Client/Filestorage/Types/PaginatedDriveList.cs b/src/Merge.Client/Filestorage/Types/PaginatedDriveList.cs index b79962e4..bf3b7b18 100644 --- a/src/Merge.Client/Filestorage/Types/PaginatedDriveList.cs +++ b/src/Merge.Client/Filestorage/Types/PaginatedDriveList.cs @@ -1,18 +1,17 @@ using System.Text.Json.Serialization; -using Merge.Client.Filestorage; #nullable enable namespace Merge.Client.Filestorage; -public class PaginatedDriveList +public record PaginatedDriveList { [JsonPropertyName("next")] - public string? Next { get; init; } + public string? Next { get; set; } [JsonPropertyName("previous")] - public string? Previous { get; init; } + public string? Previous { get; set; } [JsonPropertyName("results")] - public IEnumerable? Results { get; init; } + public IEnumerable? Results { get; set; } } diff --git a/src/Merge.Client/Filestorage/Types/PaginatedFileList.cs b/src/Merge.Client/Filestorage/Types/PaginatedFileList.cs index 2cd787e1..ee5dc36f 100644 --- a/src/Merge.Client/Filestorage/Types/PaginatedFileList.cs +++ b/src/Merge.Client/Filestorage/Types/PaginatedFileList.cs @@ -1,18 +1,17 @@ using System.Text.Json.Serialization; -using Merge.Client.Filestorage; #nullable enable namespace Merge.Client.Filestorage; -public class PaginatedFileList +public record PaginatedFileList { [JsonPropertyName("next")] - public string? Next { get; init; } + public string? Next { get; set; } [JsonPropertyName("previous")] - public string? Previous { get; init; } + public string? Previous { get; set; } [JsonPropertyName("results")] - public IEnumerable? Results { get; init; } + public IEnumerable? Results { get; set; } } diff --git a/src/Merge.Client/Filestorage/Types/PaginatedFolderList.cs b/src/Merge.Client/Filestorage/Types/PaginatedFolderList.cs index 28ae07f7..7dddbfbe 100644 --- a/src/Merge.Client/Filestorage/Types/PaginatedFolderList.cs +++ b/src/Merge.Client/Filestorage/Types/PaginatedFolderList.cs @@ -1,18 +1,17 @@ using System.Text.Json.Serialization; -using Merge.Client.Filestorage; #nullable enable namespace Merge.Client.Filestorage; -public class PaginatedFolderList +public record PaginatedFolderList { [JsonPropertyName("next")] - public string? Next { get; init; } + public string? Next { get; set; } [JsonPropertyName("previous")] - public string? Previous { get; init; } + public string? Previous { get; set; } [JsonPropertyName("results")] - public IEnumerable? Results { get; init; } + public IEnumerable? Results { get; set; } } diff --git a/src/Merge.Client/Filestorage/Types/PaginatedGroupList.cs b/src/Merge.Client/Filestorage/Types/PaginatedGroupList.cs index fddb5698..39da993d 100644 --- a/src/Merge.Client/Filestorage/Types/PaginatedGroupList.cs +++ b/src/Merge.Client/Filestorage/Types/PaginatedGroupList.cs @@ -1,18 +1,17 @@ using System.Text.Json.Serialization; -using Merge.Client.Filestorage; #nullable enable namespace Merge.Client.Filestorage; -public class PaginatedGroupList +public record PaginatedGroupList { [JsonPropertyName("next")] - public string? Next { get; init; } + public string? Next { get; set; } [JsonPropertyName("previous")] - public string? Previous { get; init; } + public string? Previous { get; set; } [JsonPropertyName("results")] - public IEnumerable? Results { get; init; } + public IEnumerable? Results { get; set; } } diff --git a/src/Merge.Client/Filestorage/Types/PaginatedIssueList.cs b/src/Merge.Client/Filestorage/Types/PaginatedIssueList.cs index 7b6691da..2c06a582 100644 --- a/src/Merge.Client/Filestorage/Types/PaginatedIssueList.cs +++ b/src/Merge.Client/Filestorage/Types/PaginatedIssueList.cs @@ -1,18 +1,17 @@ using System.Text.Json.Serialization; -using Merge.Client.Filestorage; #nullable enable namespace Merge.Client.Filestorage; -public class PaginatedIssueList +public record PaginatedIssueList { [JsonPropertyName("next")] - public string? Next { get; init; } + public string? Next { get; set; } [JsonPropertyName("previous")] - public string? Previous { get; init; } + public string? Previous { get; set; } [JsonPropertyName("results")] - public IEnumerable? Results { get; init; } + public IEnumerable? Results { get; set; } } diff --git a/src/Merge.Client/Filestorage/Types/PaginatedSyncStatusList.cs b/src/Merge.Client/Filestorage/Types/PaginatedSyncStatusList.cs index 07c94b9d..344c94b4 100644 --- a/src/Merge.Client/Filestorage/Types/PaginatedSyncStatusList.cs +++ b/src/Merge.Client/Filestorage/Types/PaginatedSyncStatusList.cs @@ -1,18 +1,17 @@ using System.Text.Json.Serialization; -using Merge.Client.Filestorage; #nullable enable namespace Merge.Client.Filestorage; -public class PaginatedSyncStatusList +public record PaginatedSyncStatusList { [JsonPropertyName("next")] - public string? Next { get; init; } + public string? Next { get; set; } [JsonPropertyName("previous")] - public string? Previous { get; init; } + public string? Previous { get; set; } [JsonPropertyName("results")] - public IEnumerable? Results { get; init; } + public IEnumerable? Results { get; set; } } diff --git a/src/Merge.Client/Filestorage/Types/PaginatedUserList.cs b/src/Merge.Client/Filestorage/Types/PaginatedUserList.cs index e6aaefe7..9f7cee71 100644 --- a/src/Merge.Client/Filestorage/Types/PaginatedUserList.cs +++ b/src/Merge.Client/Filestorage/Types/PaginatedUserList.cs @@ -1,18 +1,17 @@ using System.Text.Json.Serialization; -using Merge.Client.Filestorage; #nullable enable namespace Merge.Client.Filestorage; -public class PaginatedUserList +public record PaginatedUserList { [JsonPropertyName("next")] - public string? Next { get; init; } + public string? Next { get; set; } [JsonPropertyName("previous")] - public string? Previous { get; init; } + public string? Previous { get; set; } [JsonPropertyName("results")] - public IEnumerable? Results { get; init; } + public IEnumerable? Results { get; set; } } diff --git a/src/Merge.Client/Filestorage/Types/Permission.cs b/src/Merge.Client/Filestorage/Types/Permission.cs index bd27748a..eab7d92d 100644 --- a/src/Merge.Client/Filestorage/Types/Permission.cs +++ b/src/Merge.Client/Filestorage/Types/Permission.cs @@ -1,48 +1,47 @@ using System.Text.Json.Serialization; using Merge.Client.Core; -using Merge.Client.Filestorage; using OneOf; #nullable enable namespace Merge.Client.Filestorage; -public class Permission +public record Permission { [JsonPropertyName("id")] - public string? Id { get; init; } + public string? Id { get; set; } /// /// The third-party API ID of the matching object. /// [JsonPropertyName("remote_id")] - public string? RemoteId { get; init; } + public string? RemoteId { get; set; } /// /// The datetime that this object was created by Merge. /// [JsonPropertyName("created_at")] - public DateTime? CreatedAt { get; init; } + public DateTime? CreatedAt { get; set; } /// /// The datetime that this object was modified by Merge. /// [JsonPropertyName("modified_at")] - public DateTime? ModifiedAt { get; init; } + public DateTime? ModifiedAt { get; set; } /// /// The user that is granted this permission. /// [JsonPropertyName("user")] [JsonConverter(typeof(OneOfSerializer>))] - public OneOf? User { get; init; } + public OneOf? User { get; set; } /// /// The group that is granted this permission. /// [JsonPropertyName("group")] [JsonConverter(typeof(OneOfSerializer>))] - public OneOf? Group { get; init; } + public OneOf? Group { get; set; } /// /// Denotes what type of people have access to the file. @@ -53,11 +52,11 @@ public class Permission /// - `ANYONE` - ANYONE /// [JsonPropertyName("type")] - public TypeEnum? Type { get; init; } + public TypeEnum? Type { get; set; } /// /// The permissions that the user or group has for the File or Folder. It is possible for a user or group to have multiple roles, such as viewing & uploading. Possible values include: `READ`, `WRITE`, `OWNER`. In cases where there is no clear mapping, the original value passed through will be returned. /// [JsonPropertyName("roles")] - public IEnumerable? Roles { get; init; } + public IEnumerable? Roles { get; set; } } diff --git a/src/Merge.Client/Filestorage/Types/PermissionRequest.cs b/src/Merge.Client/Filestorage/Types/PermissionRequest.cs index 93ae144b..3b242153 100644 --- a/src/Merge.Client/Filestorage/Types/PermissionRequest.cs +++ b/src/Merge.Client/Filestorage/Types/PermissionRequest.cs @@ -1,33 +1,32 @@ using System.Text.Json.Serialization; using Merge.Client.Core; -using Merge.Client.Filestorage; using OneOf; #nullable enable namespace Merge.Client.Filestorage; -public class PermissionRequest +public record PermissionRequest { /// /// The third-party API ID of the matching object. /// [JsonPropertyName("remote_id")] - public string? RemoteId { get; init; } + public string? RemoteId { get; set; } /// /// The user that is granted this permission. /// [JsonPropertyName("user")] [JsonConverter(typeof(OneOfSerializer>))] - public OneOf? User { get; init; } + public OneOf? User { get; set; } /// /// The group that is granted this permission. /// [JsonPropertyName("group")] [JsonConverter(typeof(OneOfSerializer>))] - public OneOf? Group { get; init; } + public OneOf? Group { get; set; } /// /// Denotes what type of people have access to the file. @@ -38,17 +37,17 @@ public class PermissionRequest /// - `ANYONE` - ANYONE /// [JsonPropertyName("type")] - public TypeEnum? Type { get; init; } + public TypeEnum? Type { get; set; } /// /// The permissions that the user or group has for the File or Folder. It is possible for a user or group to have multiple roles, such as viewing & uploading. Possible values include: `READ`, `WRITE`, `OWNER`. In cases where there is no clear mapping, the original value passed through will be returned. /// [JsonPropertyName("roles")] - public IEnumerable? Roles { get; init; } + public IEnumerable? Roles { get; set; } [JsonPropertyName("integration_params")] - public Dictionary? IntegrationParams { get; init; } + public Dictionary? IntegrationParams { get; set; } [JsonPropertyName("linked_account_params")] - public Dictionary? LinkedAccountParams { get; init; } + public Dictionary? LinkedAccountParams { get; set; } } diff --git a/src/Merge.Client/Filestorage/Types/RemoteEndpointInfo.cs b/src/Merge.Client/Filestorage/Types/RemoteEndpointInfo.cs index 8c3def5f..aea27c95 100644 --- a/src/Merge.Client/Filestorage/Types/RemoteEndpointInfo.cs +++ b/src/Merge.Client/Filestorage/Types/RemoteEndpointInfo.cs @@ -4,14 +4,14 @@ namespace Merge.Client.Filestorage; -public class RemoteEndpointInfo +public record RemoteEndpointInfo { [JsonPropertyName("method")] - public string Method { get; init; } + public required string Method { get; set; } [JsonPropertyName("url_path")] - public string UrlPath { get; init; } + public required string UrlPath { get; set; } [JsonPropertyName("field_traversal_path")] - public IEnumerable FieldTraversalPath { get; init; } + public IEnumerable FieldTraversalPath { get; set; } = new List(); } diff --git a/src/Merge.Client/Filestorage/Types/RemoteFieldApi.cs b/src/Merge.Client/Filestorage/Types/RemoteFieldApi.cs index 83aeea92..87401fa3 100644 --- a/src/Merge.Client/Filestorage/Types/RemoteFieldApi.cs +++ b/src/Merge.Client/Filestorage/Types/RemoteFieldApi.cs @@ -1,30 +1,29 @@ using System.Text.Json.Serialization; using Merge.Client.Core; -using Merge.Client.Filestorage; using OneOf; #nullable enable namespace Merge.Client.Filestorage; -public class RemoteFieldApi +public record RemoteFieldApi { [JsonPropertyName("schema")] - public Dictionary Schema { get; init; } + public Dictionary Schema { get; set; } = new Dictionary(); [JsonPropertyName("remote_key_name")] - public string RemoteKeyName { get; init; } + public required string RemoteKeyName { get; set; } [JsonPropertyName("remote_endpoint_info")] - public RemoteEndpointInfo RemoteEndpointInfo { get; init; } + public required RemoteEndpointInfo RemoteEndpointInfo { get; set; } [JsonPropertyName("example_values")] - public IEnumerable? ExampleValues { get; init; } + public IEnumerable? ExampleValues { get; set; } [JsonPropertyName("advanced_metadata")] - public AdvancedMetadata? AdvancedMetadata { get; init; } + public AdvancedMetadata? AdvancedMetadata { get; set; } [JsonPropertyName("coverage")] [JsonConverter(typeof(OneOfSerializer>))] - public OneOf? Coverage { get; init; } + public OneOf? Coverage { get; set; } } diff --git a/src/Merge.Client/Filestorage/Types/RemoteFieldApiResponse.cs b/src/Merge.Client/Filestorage/Types/RemoteFieldApiResponse.cs index 9d8a72cc..07b64104 100644 --- a/src/Merge.Client/Filestorage/Types/RemoteFieldApiResponse.cs +++ b/src/Merge.Client/Filestorage/Types/RemoteFieldApiResponse.cs @@ -1,24 +1,23 @@ using System.Text.Json.Serialization; -using Merge.Client.Filestorage; #nullable enable namespace Merge.Client.Filestorage; -public class RemoteFieldApiResponse +public record RemoteFieldApiResponse { [JsonPropertyName("File")] - public IEnumerable? File { get; init; } + public IEnumerable? File { get; set; } [JsonPropertyName("Folder")] - public IEnumerable? Folder { get; init; } + public IEnumerable? Folder { get; set; } [JsonPropertyName("Drive")] - public IEnumerable? Drive { get; init; } + public IEnumerable? Drive { get; set; } [JsonPropertyName("Group")] - public IEnumerable? Group { get; init; } + public IEnumerable? Group { get; set; } [JsonPropertyName("User")] - public IEnumerable? User { get; init; } + public IEnumerable? User { get; set; } } diff --git a/src/Merge.Client/Filestorage/Types/RemoteKey.cs b/src/Merge.Client/Filestorage/Types/RemoteKey.cs index 251416f2..3ac2c423 100644 --- a/src/Merge.Client/Filestorage/Types/RemoteKey.cs +++ b/src/Merge.Client/Filestorage/Types/RemoteKey.cs @@ -4,11 +4,11 @@ namespace Merge.Client.Filestorage; -public class RemoteKey +public record RemoteKey { [JsonPropertyName("name")] - public string Name { get; init; } + public required string Name { get; set; } [JsonPropertyName("key")] - public string Key { get; init; } + public required string Key { get; set; } } diff --git a/src/Merge.Client/Filestorage/Types/RemoteResponse.cs b/src/Merge.Client/Filestorage/Types/RemoteResponse.cs index 8b3abed0..a8c4c147 100644 --- a/src/Merge.Client/Filestorage/Types/RemoteResponse.cs +++ b/src/Merge.Client/Filestorage/Types/RemoteResponse.cs @@ -1,30 +1,29 @@ using System.Text.Json.Serialization; -using Merge.Client.Filestorage; #nullable enable namespace Merge.Client.Filestorage; -public class RemoteResponse +public record RemoteResponse { [JsonPropertyName("method")] - public string Method { get; init; } + public required string Method { get; set; } [JsonPropertyName("path")] - public string Path { get; init; } + public required string Path { get; set; } [JsonPropertyName("status")] - public int Status { get; init; } + public required int Status { get; set; } [JsonPropertyName("response")] - public object Response { get; init; } + public required object Response { get; set; } [JsonPropertyName("response_headers")] - public Dictionary? ResponseHeaders { get; init; } + public Dictionary? ResponseHeaders { get; set; } [JsonPropertyName("response_type")] - public ResponseTypeEnum? ResponseType { get; init; } + public ResponseTypeEnum? ResponseType { get; set; } [JsonPropertyName("headers")] - public Dictionary? Headers { get; init; } + public Dictionary? Headers { get; set; } } diff --git a/src/Merge.Client/Filestorage/Types/RequestFormatEnum.cs b/src/Merge.Client/Filestorage/Types/RequestFormatEnum.cs index d1c168fa..e1da6a1f 100644 --- a/src/Merge.Client/Filestorage/Types/RequestFormatEnum.cs +++ b/src/Merge.Client/Filestorage/Types/RequestFormatEnum.cs @@ -1,7 +1,6 @@ using System.Runtime.Serialization; using System.Text.Json.Serialization; using Merge.Client.Core; -using Merge.Client.Filestorage; #nullable enable diff --git a/src/Merge.Client/Filestorage/Types/ResponseTypeEnum.cs b/src/Merge.Client/Filestorage/Types/ResponseTypeEnum.cs index 3a86e0ea..0785056d 100644 --- a/src/Merge.Client/Filestorage/Types/ResponseTypeEnum.cs +++ b/src/Merge.Client/Filestorage/Types/ResponseTypeEnum.cs @@ -1,7 +1,6 @@ using System.Runtime.Serialization; using System.Text.Json.Serialization; using Merge.Client.Core; -using Merge.Client.Filestorage; #nullable enable diff --git a/src/Merge.Client/Filestorage/Types/RoleEnum.cs b/src/Merge.Client/Filestorage/Types/RoleEnum.cs index f1042caa..7264e60a 100644 --- a/src/Merge.Client/Filestorage/Types/RoleEnum.cs +++ b/src/Merge.Client/Filestorage/Types/RoleEnum.cs @@ -1,7 +1,6 @@ using System.Runtime.Serialization; using System.Text.Json.Serialization; using Merge.Client.Core; -using Merge.Client.Filestorage; #nullable enable diff --git a/src/Merge.Client/Filestorage/Types/RolesEnum.cs b/src/Merge.Client/Filestorage/Types/RolesEnum.cs index e0cd869a..524c1777 100644 --- a/src/Merge.Client/Filestorage/Types/RolesEnum.cs +++ b/src/Merge.Client/Filestorage/Types/RolesEnum.cs @@ -1,7 +1,6 @@ using System.Runtime.Serialization; using System.Text.Json.Serialization; using Merge.Client.Core; -using Merge.Client.Filestorage; #nullable enable diff --git a/src/Merge.Client/Filestorage/Types/SelectiveSyncConfigurationsUsageEnum.cs b/src/Merge.Client/Filestorage/Types/SelectiveSyncConfigurationsUsageEnum.cs index facdd6b5..069ed925 100644 --- a/src/Merge.Client/Filestorage/Types/SelectiveSyncConfigurationsUsageEnum.cs +++ b/src/Merge.Client/Filestorage/Types/SelectiveSyncConfigurationsUsageEnum.cs @@ -1,7 +1,6 @@ using System.Runtime.Serialization; using System.Text.Json.Serialization; using Merge.Client.Core; -using Merge.Client.Filestorage; #nullable enable diff --git a/src/Merge.Client/Filestorage/Types/SyncStatus.cs b/src/Merge.Client/Filestorage/Types/SyncStatus.cs index 398c1e78..bfeef40f 100644 --- a/src/Merge.Client/Filestorage/Types/SyncStatus.cs +++ b/src/Merge.Client/Filestorage/Types/SyncStatus.cs @@ -1,30 +1,29 @@ using System.Text.Json.Serialization; -using Merge.Client.Filestorage; #nullable enable namespace Merge.Client.Filestorage; -public class SyncStatus +public record SyncStatus { [JsonPropertyName("model_name")] - public string ModelName { get; init; } + public required string ModelName { get; set; } [JsonPropertyName("model_id")] - public string ModelId { get; init; } + public required string ModelId { get; set; } [JsonPropertyName("last_sync_start")] - public DateTime? LastSyncStart { get; init; } + public DateTime? LastSyncStart { get; set; } [JsonPropertyName("next_sync_start")] - public DateTime? NextSyncStart { get; init; } + public DateTime? NextSyncStart { get; set; } [JsonPropertyName("status")] - public SyncStatusStatusEnum Status { get; init; } + public required SyncStatusStatusEnum Status { get; set; } [JsonPropertyName("is_initial_sync")] - public bool IsInitialSync { get; init; } + public required bool IsInitialSync { get; set; } [JsonPropertyName("selective_sync_configurations_usage")] - public SelectiveSyncConfigurationsUsageEnum? SelectiveSyncConfigurationsUsage { get; init; } + public SelectiveSyncConfigurationsUsageEnum? SelectiveSyncConfigurationsUsage { get; set; } } diff --git a/src/Merge.Client/Filestorage/Types/SyncStatusStatusEnum.cs b/src/Merge.Client/Filestorage/Types/SyncStatusStatusEnum.cs index 4b450c3c..5747a674 100644 --- a/src/Merge.Client/Filestorage/Types/SyncStatusStatusEnum.cs +++ b/src/Merge.Client/Filestorage/Types/SyncStatusStatusEnum.cs @@ -1,7 +1,6 @@ using System.Runtime.Serialization; using System.Text.Json.Serialization; using Merge.Client.Core; -using Merge.Client.Filestorage; #nullable enable diff --git a/src/Merge.Client/Filestorage/Types/TypeEnum.cs b/src/Merge.Client/Filestorage/Types/TypeEnum.cs index 1e9246c7..2cba4fcb 100644 --- a/src/Merge.Client/Filestorage/Types/TypeEnum.cs +++ b/src/Merge.Client/Filestorage/Types/TypeEnum.cs @@ -1,7 +1,6 @@ using System.Runtime.Serialization; using System.Text.Json.Serialization; using Merge.Client.Core; -using Merge.Client.Filestorage; #nullable enable diff --git a/src/Merge.Client/Filestorage/Types/User.cs b/src/Merge.Client/Filestorage/Types/User.cs index 89f26518..1c4ffe36 100644 --- a/src/Merge.Client/Filestorage/Types/User.cs +++ b/src/Merge.Client/Filestorage/Types/User.cs @@ -4,56 +4,56 @@ namespace Merge.Client.Filestorage; -public class User +public record User { [JsonPropertyName("id")] - public string? Id { get; init; } + public string? Id { get; set; } /// /// The third-party API ID of the matching object. /// [JsonPropertyName("remote_id")] - public string? RemoteId { get; init; } + public string? RemoteId { get; set; } /// /// The datetime that this object was created by Merge. /// [JsonPropertyName("created_at")] - public DateTime? CreatedAt { get; init; } + public DateTime? CreatedAt { get; set; } /// /// The datetime that this object was modified by Merge. /// [JsonPropertyName("modified_at")] - public DateTime? ModifiedAt { get; init; } + public DateTime? ModifiedAt { get; set; } /// /// The user's name. /// [JsonPropertyName("name")] - public string? Name { get; init; } + public string? Name { get; set; } /// /// The user's email address. This is typically used to identify a user across linked accounts. /// [JsonPropertyName("email_address")] - public string? EmailAddress { get; init; } + public string? EmailAddress { get; set; } /// /// Whether the user is the one who linked this account. /// [JsonPropertyName("is_me")] - public bool? IsMe { get; init; } + public bool? IsMe { get; set; } /// /// Indicates whether or not this object has been deleted in the third party platform. /// [JsonPropertyName("remote_was_deleted")] - public bool? RemoteWasDeleted { get; init; } + public bool? RemoteWasDeleted { get; set; } [JsonPropertyName("field_mappings")] - public Dictionary? FieldMappings { get; init; } + public Dictionary? FieldMappings { get; set; } [JsonPropertyName("remote_data")] - public IEnumerable>? RemoteData { get; init; } + public IEnumerable>? RemoteData { get; set; } } diff --git a/src/Merge.Client/Filestorage/Types/ValidationProblemSource.cs b/src/Merge.Client/Filestorage/Types/ValidationProblemSource.cs index d0ee4868..e3482267 100644 --- a/src/Merge.Client/Filestorage/Types/ValidationProblemSource.cs +++ b/src/Merge.Client/Filestorage/Types/ValidationProblemSource.cs @@ -4,8 +4,8 @@ namespace Merge.Client.Filestorage; -public class ValidationProblemSource +public record ValidationProblemSource { [JsonPropertyName("pointer")] - public string Pointer { get; init; } + public required string Pointer { get; set; } } diff --git a/src/Merge.Client/Filestorage/Types/WarningValidationProblem.cs b/src/Merge.Client/Filestorage/Types/WarningValidationProblem.cs index f16524e6..b4bc8931 100644 --- a/src/Merge.Client/Filestorage/Types/WarningValidationProblem.cs +++ b/src/Merge.Client/Filestorage/Types/WarningValidationProblem.cs @@ -1,21 +1,20 @@ using System.Text.Json.Serialization; -using Merge.Client.Filestorage; #nullable enable namespace Merge.Client.Filestorage; -public class WarningValidationProblem +public record WarningValidationProblem { [JsonPropertyName("source")] - public ValidationProblemSource? Source { get; init; } + public ValidationProblemSource? Source { get; set; } [JsonPropertyName("title")] - public string Title { get; init; } + public required string Title { get; set; } [JsonPropertyName("detail")] - public string Detail { get; init; } + public required string Detail { get; set; } [JsonPropertyName("problem_type")] - public string ProblemType { get; init; } + public required string ProblemType { get; set; } } diff --git a/src/Merge.Client/Filestorage/Types/WebhookReceiver.cs b/src/Merge.Client/Filestorage/Types/WebhookReceiver.cs index a38c5ade..eee71ab9 100644 --- a/src/Merge.Client/Filestorage/Types/WebhookReceiver.cs +++ b/src/Merge.Client/Filestorage/Types/WebhookReceiver.cs @@ -4,14 +4,14 @@ namespace Merge.Client.Filestorage; -public class WebhookReceiver +public record WebhookReceiver { [JsonPropertyName("event")] - public string Event { get; init; } + public required string Event { get; set; } [JsonPropertyName("is_active")] - public bool IsActive { get; init; } + public required bool IsActive { get; set; } [JsonPropertyName("key")] - public string? Key { get; init; } + public string? Key { get; set; } } diff --git a/src/Merge.Client/Filestorage/Users/Requests/UsersListRequest.cs b/src/Merge.Client/Filestorage/Users/Requests/UsersListRequest.cs index 2d524277..46f660c5 100644 --- a/src/Merge.Client/Filestorage/Users/Requests/UsersListRequest.cs +++ b/src/Merge.Client/Filestorage/Users/Requests/UsersListRequest.cs @@ -1,54 +1,54 @@ namespace Merge.Client.Filestorage; -public class UsersListRequest +public record UsersListRequest { /// /// If provided, will only return objects created after this datetime. /// - public DateTime? CreatedAfter { get; init; } + public DateTime? CreatedAfter { get; set; } /// /// If provided, will only return objects created before this datetime. /// - public DateTime? CreatedBefore { get; init; } + public DateTime? CreatedBefore { get; set; } /// /// The pagination cursor value. /// - public string? Cursor { get; init; } + public string? Cursor { get; set; } /// /// Whether to include data that was marked as deleted by third party webhooks. /// - public bool? IncludeDeletedData { get; init; } + public bool? IncludeDeletedData { get; set; } /// /// Whether to include the original data Merge fetched from the third-party to produce these models. /// - public bool? IncludeRemoteData { get; init; } + public bool? IncludeRemoteData { get; set; } /// /// If provided, will only return the user object for requestor. /// - public string? IsMe { get; init; } + public string? IsMe { get; set; } /// /// If provided, only objects synced by Merge after this date time will be returned. /// - public DateTime? ModifiedAfter { get; init; } + public DateTime? ModifiedAfter { get; set; } /// /// If provided, only objects synced by Merge before this date time will be returned. /// - public DateTime? ModifiedBefore { get; init; } + public DateTime? ModifiedBefore { get; set; } /// /// Number of results to return per page. /// - public int? PageSize { get; init; } + public int? PageSize { get; set; } /// /// The API provider's ID for the given object. /// - public string? RemoteId { get; init; } + public string? RemoteId { get; set; } } diff --git a/src/Merge.Client/Filestorage/Users/Requests/UsersRetrieveRequest.cs b/src/Merge.Client/Filestorage/Users/Requests/UsersRetrieveRequest.cs index ffb4a463..67d27769 100644 --- a/src/Merge.Client/Filestorage/Users/Requests/UsersRetrieveRequest.cs +++ b/src/Merge.Client/Filestorage/Users/Requests/UsersRetrieveRequest.cs @@ -1,9 +1,9 @@ namespace Merge.Client.Filestorage; -public class UsersRetrieveRequest +public record UsersRetrieveRequest { /// /// Whether to include the original data Merge fetched from the third-party to produce these models. /// - public bool? IncludeRemoteData { get; init; } + public bool? IncludeRemoteData { get; set; } } diff --git a/src/Merge.Client/Filestorage/Users/UsersClient.cs b/src/Merge.Client/Filestorage/Users/UsersClient.cs index 9fdfd26a..424072b6 100644 --- a/src/Merge.Client/Filestorage/Users/UsersClient.cs +++ b/src/Merge.Client/Filestorage/Users/UsersClient.cs @@ -1,6 +1,6 @@ +using System.Net.Http; using System.Text.Json; -using Merge.Client; -using Merge.Client.Filestorage; +using Merge.Client.Core; #nullable enable @@ -18,16 +18,21 @@ public UsersClient(RawClient client) /// /// Returns a list of `User` objects. /// - public async Task ListAsync(UsersListRequest request) + public async Task ListAsync( + UsersListRequest request, + RequestOptions? options = null + ) { var _query = new Dictionary() { }; if (request.CreatedAfter != null) { - _query["created_after"] = request.CreatedAfter.Value.ToString("o0"); + _query["created_after"] = request.CreatedAfter.Value.ToString(Constants.DateTimeFormat); } if (request.CreatedBefore != null) { - _query["created_before"] = request.CreatedBefore.Value.ToString("o0"); + _query["created_before"] = request.CreatedBefore.Value.ToString( + Constants.DateTimeFormat + ); } if (request.Cursor != null) { @@ -47,11 +52,15 @@ public async Task ListAsync(UsersListRequest request) } if (request.ModifiedAfter != null) { - _query["modified_after"] = request.ModifiedAfter.Value.ToString("o0"); + _query["modified_after"] = request.ModifiedAfter.Value.ToString( + Constants.DateTimeFormat + ); } if (request.ModifiedBefore != null) { - _query["modified_before"] = request.ModifiedBefore.Value.ToString("o0"); + _query["modified_before"] = request.ModifiedBefore.Value.ToString( + Constants.DateTimeFormat + ); } if (request.PageSize != null) { @@ -64,23 +73,41 @@ public async Task ListAsync(UsersListRequest request) var response = await _client.MakeRequestAsync( new RawClient.JsonApiRequest { + BaseUrl = _client.Options.BaseUrl, Method = HttpMethod.Get, Path = "filestorage/v1/users", - Query = _query + Query = _query, + Options = options } ); - string responseBody = await response.Raw.Content.ReadAsStringAsync(); - if (response.StatusCode >= 200 && response.StatusCode < 400) + var responseBody = await response.Raw.Content.ReadAsStringAsync(); + if (response.StatusCode is >= 200 and < 400) { - return JsonSerializer.Deserialize(responseBody); + try + { + return JsonUtils.Deserialize(responseBody)!; + } + catch (JsonException e) + { + throw new MergeException("Failed to deserialize response", e); + } } - throw new Exception(responseBody); + + throw new MergeApiException( + $"Error with status code {response.StatusCode}", + response.StatusCode, + JsonUtils.Deserialize(responseBody) + ); } /// /// Returns a `User` object with the given `id`. /// - public async Task RetrieveAsync(string id, UsersRetrieveRequest request) + public async Task RetrieveAsync( + string id, + UsersRetrieveRequest request, + RequestOptions? options = null + ) { var _query = new Dictionary() { }; if (request.IncludeRemoteData != null) @@ -90,16 +117,30 @@ public async Task RetrieveAsync(string id, UsersRetrieveRequest request) var response = await _client.MakeRequestAsync( new RawClient.JsonApiRequest { + BaseUrl = _client.Options.BaseUrl, Method = HttpMethod.Get, Path = $"filestorage/v1/users/{id}", - Query = _query + Query = _query, + Options = options } ); - string responseBody = await response.Raw.Content.ReadAsStringAsync(); - if (response.StatusCode >= 200 && response.StatusCode < 400) + var responseBody = await response.Raw.Content.ReadAsStringAsync(); + if (response.StatusCode is >= 200 and < 400) { - return JsonSerializer.Deserialize(responseBody); + try + { + return JsonUtils.Deserialize(responseBody)!; + } + catch (JsonException e) + { + throw new MergeException("Failed to deserialize response", e); + } } - throw new Exception(responseBody); + + throw new MergeApiException( + $"Error with status code {response.StatusCode}", + response.StatusCode, + JsonUtils.Deserialize(responseBody) + ); } } diff --git a/src/Merge.Client/Filestorage/WebhookReceivers/Requests/WebhookReceiverRequest.cs b/src/Merge.Client/Filestorage/WebhookReceivers/Requests/WebhookReceiverRequest.cs index 489f9777..08812a15 100644 --- a/src/Merge.Client/Filestorage/WebhookReceivers/Requests/WebhookReceiverRequest.cs +++ b/src/Merge.Client/Filestorage/WebhookReceivers/Requests/WebhookReceiverRequest.cs @@ -4,14 +4,14 @@ namespace Merge.Client.Filestorage; -public class WebhookReceiverRequest +public record WebhookReceiverRequest { [JsonPropertyName("event")] - public string Event { get; init; } + public required string Event { get; set; } [JsonPropertyName("is_active")] - public bool IsActive { get; init; } + public required bool IsActive { get; set; } [JsonPropertyName("key")] - public string? Key { get; init; } + public string? Key { get; set; } } diff --git a/src/Merge.Client/Filestorage/WebhookReceivers/WebhookReceiversClient.cs b/src/Merge.Client/Filestorage/WebhookReceivers/WebhookReceiversClient.cs index dcb35d06..8eba40ae 100644 --- a/src/Merge.Client/Filestorage/WebhookReceivers/WebhookReceiversClient.cs +++ b/src/Merge.Client/Filestorage/WebhookReceivers/WebhookReceiversClient.cs @@ -1,6 +1,6 @@ +using System.Net.Http; using System.Text.Json; -using Merge.Client; -using Merge.Client.Filestorage; +using Merge.Client.Core; #nullable enable @@ -18,41 +18,72 @@ public WebhookReceiversClient(RawClient client) /// /// Returns a list of `WebhookReceiver` objects. /// - public async Task> ListAsync() + public async Task> ListAsync(RequestOptions? options = null) { var response = await _client.MakeRequestAsync( new RawClient.JsonApiRequest { + BaseUrl = _client.Options.BaseUrl, Method = HttpMethod.Get, - Path = "filestorage/v1/webhook-receivers" + Path = "filestorage/v1/webhook-receivers", + Options = options } ); - string responseBody = await response.Raw.Content.ReadAsStringAsync(); - if (response.StatusCode >= 200 && response.StatusCode < 400) + var responseBody = await response.Raw.Content.ReadAsStringAsync(); + if (response.StatusCode is >= 200 and < 400) { - return JsonSerializer.Deserialize>(responseBody); + try + { + return JsonUtils.Deserialize>(responseBody)!; + } + catch (JsonException e) + { + throw new MergeException("Failed to deserialize response", e); + } } - throw new Exception(responseBody); + + throw new MergeApiException( + $"Error with status code {response.StatusCode}", + response.StatusCode, + JsonUtils.Deserialize(responseBody) + ); } /// /// Creates a `WebhookReceiver` object with the given values. /// - public async Task CreateAsync(WebhookReceiverRequest request) + public async Task CreateAsync( + WebhookReceiverRequest request, + RequestOptions? options = null + ) { var response = await _client.MakeRequestAsync( new RawClient.JsonApiRequest { + BaseUrl = _client.Options.BaseUrl, Method = HttpMethod.Post, Path = "filestorage/v1/webhook-receivers", - Body = request + Body = request, + Options = options } ); - string responseBody = await response.Raw.Content.ReadAsStringAsync(); - if (response.StatusCode >= 200 && response.StatusCode < 400) + var responseBody = await response.Raw.Content.ReadAsStringAsync(); + if (response.StatusCode is >= 200 and < 400) { - return JsonSerializer.Deserialize(responseBody); + try + { + return JsonUtils.Deserialize(responseBody)!; + } + catch (JsonException e) + { + throw new MergeException("Failed to deserialize response", e); + } } - throw new Exception(responseBody); + + throw new MergeApiException( + $"Error with status code {response.StatusCode}", + response.StatusCode, + JsonUtils.Deserialize(responseBody) + ); } } diff --git a/src/Merge.Client/Hris/AccountDetails/AccountDetailsClient.cs b/src/Merge.Client/Hris/AccountDetails/AccountDetailsClient.cs index c59a1fdc..a43f10e4 100644 --- a/src/Merge.Client/Hris/AccountDetails/AccountDetailsClient.cs +++ b/src/Merge.Client/Hris/AccountDetails/AccountDetailsClient.cs @@ -1,6 +1,6 @@ +using System.Net.Http; using System.Text.Json; -using Merge.Client; -using Merge.Client.Hris; +using Merge.Client.Core; #nullable enable @@ -18,20 +18,34 @@ public AccountDetailsClient(RawClient client) /// /// Get details for a linked account. /// - public async Task RetrieveAsync() + public async Task RetrieveAsync(RequestOptions? options = null) { var response = await _client.MakeRequestAsync( new RawClient.JsonApiRequest { + BaseUrl = _client.Options.BaseUrl, Method = HttpMethod.Get, - Path = "hris/v1/account-details" + Path = "hris/v1/account-details", + Options = options } ); - string responseBody = await response.Raw.Content.ReadAsStringAsync(); - if (response.StatusCode >= 200 && response.StatusCode < 400) + var responseBody = await response.Raw.Content.ReadAsStringAsync(); + if (response.StatusCode is >= 200 and < 400) { - return JsonSerializer.Deserialize(responseBody); + try + { + return JsonUtils.Deserialize(responseBody)!; + } + catch (JsonException e) + { + throw new MergeException("Failed to deserialize response", e); + } } - throw new Exception(responseBody); + + throw new MergeApiException( + $"Error with status code {response.StatusCode}", + response.StatusCode, + JsonUtils.Deserialize(responseBody) + ); } } diff --git a/src/Merge.Client/Hris/AccountToken/AccountTokenClient.cs b/src/Merge.Client/Hris/AccountToken/AccountTokenClient.cs index 51bf2161..7eef999a 100644 --- a/src/Merge.Client/Hris/AccountToken/AccountTokenClient.cs +++ b/src/Merge.Client/Hris/AccountToken/AccountTokenClient.cs @@ -1,6 +1,6 @@ +using System.Net.Http; using System.Text.Json; -using Merge.Client; -using Merge.Client.Hris; +using Merge.Client.Core; #nullable enable @@ -18,20 +18,37 @@ public AccountTokenClient(RawClient client) /// /// Returns the account token for the end user with the provided public token. /// - public async Task RetrieveAsync(string publicToken) + public async Task RetrieveAsync( + string publicToken, + RequestOptions? options = null + ) { var response = await _client.MakeRequestAsync( new RawClient.JsonApiRequest { + BaseUrl = _client.Options.BaseUrl, Method = HttpMethod.Get, - Path = $"hris/v1/account-token/{publicToken}" + Path = $"hris/v1/account-token/{publicToken}", + Options = options } ); - string responseBody = await response.Raw.Content.ReadAsStringAsync(); - if (response.StatusCode >= 200 && response.StatusCode < 400) + var responseBody = await response.Raw.Content.ReadAsStringAsync(); + if (response.StatusCode is >= 200 and < 400) { - return JsonSerializer.Deserialize(responseBody); + try + { + return JsonUtils.Deserialize(responseBody)!; + } + catch (JsonException e) + { + throw new MergeException("Failed to deserialize response", e); + } } - throw new Exception(responseBody); + + throw new MergeApiException( + $"Error with status code {response.StatusCode}", + response.StatusCode, + JsonUtils.Deserialize(responseBody) + ); } } diff --git a/src/Merge.Client/Hris/AsyncPassthrough/AsyncPassthroughClient.cs b/src/Merge.Client/Hris/AsyncPassthrough/AsyncPassthroughClient.cs index 75553113..c3744a44 100644 --- a/src/Merge.Client/Hris/AsyncPassthrough/AsyncPassthroughClient.cs +++ b/src/Merge.Client/Hris/AsyncPassthrough/AsyncPassthroughClient.cs @@ -1,6 +1,6 @@ +using System.Net.Http; using System.Text.Json; -using Merge.Client; -using Merge.Client.Hris; +using Merge.Client.Core; #nullable enable @@ -18,41 +18,75 @@ public AsyncPassthroughClient(RawClient client) /// /// Asynchronously pull data from an endpoint not currently supported by Merge. /// - public async Task CreateAsync(DataPassthroughRequest request) + public async Task CreateAsync( + DataPassthroughRequest request, + RequestOptions? options = null + ) { var response = await _client.MakeRequestAsync( new RawClient.JsonApiRequest { + BaseUrl = _client.Options.BaseUrl, Method = HttpMethod.Post, Path = "hris/v1/async-passthrough", - Body = request + Body = request, + Options = options } ); - string responseBody = await response.Raw.Content.ReadAsStringAsync(); - if (response.StatusCode >= 200 && response.StatusCode < 400) + var responseBody = await response.Raw.Content.ReadAsStringAsync(); + if (response.StatusCode is >= 200 and < 400) { - return JsonSerializer.Deserialize(responseBody); + try + { + return JsonUtils.Deserialize(responseBody)!; + } + catch (JsonException e) + { + throw new MergeException("Failed to deserialize response", e); + } } - throw new Exception(responseBody); + + throw new MergeApiException( + $"Error with status code {response.StatusCode}", + response.StatusCode, + JsonUtils.Deserialize(responseBody) + ); } /// /// Retrieves data from earlier async-passthrough POST request /// - public async Task RetrieveAsync(string asyncPassthroughReceiptId) + public async Task RetrieveAsync( + string asyncPassthroughReceiptId, + RequestOptions? options = null + ) { var response = await _client.MakeRequestAsync( new RawClient.JsonApiRequest { + BaseUrl = _client.Options.BaseUrl, Method = HttpMethod.Get, - Path = $"hris/v1/async-passthrough/{asyncPassthroughReceiptId}" + Path = $"hris/v1/async-passthrough/{asyncPassthroughReceiptId}", + Options = options } ); - string responseBody = await response.Raw.Content.ReadAsStringAsync(); - if (response.StatusCode >= 200 && response.StatusCode < 400) + var responseBody = await response.Raw.Content.ReadAsStringAsync(); + if (response.StatusCode is >= 200 and < 400) { - return JsonSerializer.Deserialize(responseBody); + try + { + return JsonUtils.Deserialize(responseBody)!; + } + catch (JsonException e) + { + throw new MergeException("Failed to deserialize response", e); + } } - throw new Exception(responseBody); + + throw new MergeApiException( + $"Error with status code {response.StatusCode}", + response.StatusCode, + JsonUtils.Deserialize(responseBody) + ); } } diff --git a/src/Merge.Client/Hris/AuditTrail/AuditTrailClient.cs b/src/Merge.Client/Hris/AuditTrail/AuditTrailClient.cs index b532a221..7cd714c7 100644 --- a/src/Merge.Client/Hris/AuditTrail/AuditTrailClient.cs +++ b/src/Merge.Client/Hris/AuditTrail/AuditTrailClient.cs @@ -1,6 +1,6 @@ +using System.Net.Http; using System.Text.Json; -using Merge.Client; -using Merge.Client.Hris; +using Merge.Client.Core; #nullable enable @@ -18,7 +18,10 @@ public AuditTrailClient(RawClient client) /// /// Gets a list of audit trail events. /// - public async Task ListAsync(AuditTrailListRequest request) + public async Task ListAsync( + AuditTrailListRequest request, + RequestOptions? options = null + ) { var _query = new Dictionary() { }; if (request.Cursor != null) @@ -48,16 +51,30 @@ public async Task ListAsync(AuditTrailListRequest re var response = await _client.MakeRequestAsync( new RawClient.JsonApiRequest { + BaseUrl = _client.Options.BaseUrl, Method = HttpMethod.Get, Path = "hris/v1/audit-trail", - Query = _query + Query = _query, + Options = options } ); - string responseBody = await response.Raw.Content.ReadAsStringAsync(); - if (response.StatusCode >= 200 && response.StatusCode < 400) + var responseBody = await response.Raw.Content.ReadAsStringAsync(); + if (response.StatusCode is >= 200 and < 400) { - return JsonSerializer.Deserialize(responseBody); + try + { + return JsonUtils.Deserialize(responseBody)!; + } + catch (JsonException e) + { + throw new MergeException("Failed to deserialize response", e); + } } - throw new Exception(responseBody); + + throw new MergeApiException( + $"Error with status code {response.StatusCode}", + response.StatusCode, + JsonUtils.Deserialize(responseBody) + ); } } diff --git a/src/Merge.Client/Hris/AuditTrail/Requests/AuditTrailListRequest.cs b/src/Merge.Client/Hris/AuditTrail/Requests/AuditTrailListRequest.cs index 9be46ad5..46e389ec 100644 --- a/src/Merge.Client/Hris/AuditTrail/Requests/AuditTrailListRequest.cs +++ b/src/Merge.Client/Hris/AuditTrail/Requests/AuditTrailListRequest.cs @@ -1,34 +1,34 @@ namespace Merge.Client.Hris; -public class AuditTrailListRequest +public record AuditTrailListRequest { /// /// The pagination cursor value. /// - public string? Cursor { get; init; } + public string? Cursor { get; set; } /// /// If included, will only include audit trail events that occurred before this time /// - public string? EndDate { get; init; } + public string? EndDate { get; set; } /// /// If included, will only include events with the given event type. Possible values include: `CREATED_REMOTE_PRODUCTION_API_KEY`, `DELETED_REMOTE_PRODUCTION_API_KEY`, `CREATED_TEST_API_KEY`, `DELETED_TEST_API_KEY`, `REGENERATED_PRODUCTION_API_KEY`, `INVITED_USER`, `TWO_FACTOR_AUTH_ENABLED`, `TWO_FACTOR_AUTH_DISABLED`, `DELETED_LINKED_ACCOUNT`, `CREATED_DESTINATION`, `DELETED_DESTINATION`, `CHANGED_DESTINATION`, `CHANGED_SCOPES`, `CHANGED_PERSONAL_INFORMATION`, `CHANGED_ORGANIZATION_SETTINGS`, `ENABLED_INTEGRATION`, `DISABLED_INTEGRATION`, `ENABLED_CATEGORY`, `DISABLED_CATEGORY`, `CHANGED_PASSWORD`, `RESET_PASSWORD`, `ENABLED_REDACT_UNMAPPED_DATA_FOR_ORGANIZATION`, `ENABLED_REDACT_UNMAPPED_DATA_FOR_LINKED_ACCOUNT`, `DISABLED_REDACT_UNMAPPED_DATA_FOR_ORGANIZATION`, `DISABLED_REDACT_UNMAPPED_DATA_FOR_LINKED_ACCOUNT`, `CREATED_INTEGRATION_WIDE_FIELD_MAPPING`, `CREATED_LINKED_ACCOUNT_FIELD_MAPPING`, `CHANGED_INTEGRATION_WIDE_FIELD_MAPPING`, `CHANGED_LINKED_ACCOUNT_FIELD_MAPPING`, `DELETED_INTEGRATION_WIDE_FIELD_MAPPING`, `DELETED_LINKED_ACCOUNT_FIELD_MAPPING`, `FORCED_LINKED_ACCOUNT_RESYNC`, `MUTED_ISSUE`, `GENERATED_MAGIC_LINK`, `ENABLED_MERGE_WEBHOOK`, `DISABLED_MERGE_WEBHOOK`, `MERGE_WEBHOOK_TARGET_CHANGED`, `END_USER_CREDENTIALS_ACCESSED` /// - public string? EventType { get; init; } + public string? EventType { get; set; } /// /// Number of results to return per page. /// - public int? PageSize { get; init; } + public int? PageSize { get; set; } /// /// If included, will only include audit trail events that occurred after this time /// - public string? StartDate { get; init; } + public string? StartDate { get; set; } /// /// If provided, this will return events associated with the specified user email. Please note that the email address reflects the user's email at the time of the event, and may not be their current email. /// - public string? UserEmail { get; init; } + public string? UserEmail { get; set; } } diff --git a/src/Merge.Client/Hris/AvailableActions/AvailableActionsClient.cs b/src/Merge.Client/Hris/AvailableActions/AvailableActionsClient.cs index 5da0f49d..c11e080f 100644 --- a/src/Merge.Client/Hris/AvailableActions/AvailableActionsClient.cs +++ b/src/Merge.Client/Hris/AvailableActions/AvailableActionsClient.cs @@ -1,6 +1,6 @@ +using System.Net.Http; using System.Text.Json; -using Merge.Client; -using Merge.Client.Hris; +using Merge.Client.Core; #nullable enable @@ -18,20 +18,34 @@ public AvailableActionsClient(RawClient client) /// /// Returns a list of models and actions available for an account. /// - public async Task RetrieveAsync() + public async Task RetrieveAsync(RequestOptions? options = null) { var response = await _client.MakeRequestAsync( new RawClient.JsonApiRequest { + BaseUrl = _client.Options.BaseUrl, Method = HttpMethod.Get, - Path = "hris/v1/available-actions" + Path = "hris/v1/available-actions", + Options = options } ); - string responseBody = await response.Raw.Content.ReadAsStringAsync(); - if (response.StatusCode >= 200 && response.StatusCode < 400) + var responseBody = await response.Raw.Content.ReadAsStringAsync(); + if (response.StatusCode is >= 200 and < 400) { - return JsonSerializer.Deserialize(responseBody); + try + { + return JsonUtils.Deserialize(responseBody)!; + } + catch (JsonException e) + { + throw new MergeException("Failed to deserialize response", e); + } } - throw new Exception(responseBody); + + throw new MergeApiException( + $"Error with status code {response.StatusCode}", + response.StatusCode, + JsonUtils.Deserialize(responseBody) + ); } } diff --git a/src/Merge.Client/Hris/BankInfo/BankInfoClient.cs b/src/Merge.Client/Hris/BankInfo/BankInfoClient.cs index d819204f..d1f8bade 100644 --- a/src/Merge.Client/Hris/BankInfo/BankInfoClient.cs +++ b/src/Merge.Client/Hris/BankInfo/BankInfoClient.cs @@ -1,6 +1,6 @@ +using System.Net.Http; using System.Text.Json; -using Merge.Client; -using Merge.Client.Hris; +using Merge.Client.Core; #nullable enable @@ -18,7 +18,10 @@ public BankInfoClient(RawClient client) /// /// Returns a list of `BankInfo` objects. /// - public async Task ListAsync(BankInfoListRequest request) + public async Task ListAsync( + BankInfoListRequest request, + RequestOptions? options = null + ) { var _query = new Dictionary() { }; if (request.AccountType != null) @@ -31,11 +34,13 @@ public async Task ListAsync(BankInfoListRequest request) } if (request.CreatedAfter != null) { - _query["created_after"] = request.CreatedAfter.Value.ToString("o0"); + _query["created_after"] = request.CreatedAfter.Value.ToString(Constants.DateTimeFormat); } if (request.CreatedBefore != null) { - _query["created_before"] = request.CreatedBefore.Value.ToString("o0"); + _query["created_before"] = request.CreatedBefore.Value.ToString( + Constants.DateTimeFormat + ); } if (request.Cursor != null) { @@ -59,11 +64,15 @@ public async Task ListAsync(BankInfoListRequest request) } if (request.ModifiedAfter != null) { - _query["modified_after"] = request.ModifiedAfter.Value.ToString("o0"); + _query["modified_after"] = request.ModifiedAfter.Value.ToString( + Constants.DateTimeFormat + ); } if (request.ModifiedBefore != null) { - _query["modified_before"] = request.ModifiedBefore.Value.ToString("o0"); + _query["modified_before"] = request.ModifiedBefore.Value.ToString( + Constants.DateTimeFormat + ); } if (request.OrderBy != null) { @@ -88,23 +97,41 @@ public async Task ListAsync(BankInfoListRequest request) var response = await _client.MakeRequestAsync( new RawClient.JsonApiRequest { + BaseUrl = _client.Options.BaseUrl, Method = HttpMethod.Get, Path = "hris/v1/bank-info", - Query = _query + Query = _query, + Options = options } ); - string responseBody = await response.Raw.Content.ReadAsStringAsync(); - if (response.StatusCode >= 200 && response.StatusCode < 400) + var responseBody = await response.Raw.Content.ReadAsStringAsync(); + if (response.StatusCode is >= 200 and < 400) { - return JsonSerializer.Deserialize(responseBody); + try + { + return JsonUtils.Deserialize(responseBody)!; + } + catch (JsonException e) + { + throw new MergeException("Failed to deserialize response", e); + } } - throw new Exception(responseBody); + + throw new MergeApiException( + $"Error with status code {response.StatusCode}", + response.StatusCode, + JsonUtils.Deserialize(responseBody) + ); } /// /// Returns a `BankInfo` object with the given `id`. /// - public async Task RetrieveAsync(string id, BankInfoRetrieveRequest request) + public async Task RetrieveAsync( + string id, + BankInfoRetrieveRequest request, + RequestOptions? options = null + ) { var _query = new Dictionary() { }; if (request.Expand != null) @@ -126,16 +153,30 @@ public async Task RetrieveAsync(string id, BankInfoRetrieveRequest req var response = await _client.MakeRequestAsync( new RawClient.JsonApiRequest { + BaseUrl = _client.Options.BaseUrl, Method = HttpMethod.Get, Path = $"hris/v1/bank-info/{id}", - Query = _query + Query = _query, + Options = options } ); - string responseBody = await response.Raw.Content.ReadAsStringAsync(); - if (response.StatusCode >= 200 && response.StatusCode < 400) + var responseBody = await response.Raw.Content.ReadAsStringAsync(); + if (response.StatusCode is >= 200 and < 400) { - return JsonSerializer.Deserialize(responseBody); + try + { + return JsonUtils.Deserialize(responseBody)!; + } + catch (JsonException e) + { + throw new MergeException("Failed to deserialize response", e); + } } - throw new Exception(responseBody); + + throw new MergeApiException( + $"Error with status code {response.StatusCode}", + response.StatusCode, + JsonUtils.Deserialize(responseBody) + ); } } diff --git a/src/Merge.Client/Hris/BankInfo/Requests/BankInfoListRequest.cs b/src/Merge.Client/Hris/BankInfo/Requests/BankInfoListRequest.cs index ce133cee..9efb1971 100644 --- a/src/Merge.Client/Hris/BankInfo/Requests/BankInfoListRequest.cs +++ b/src/Merge.Client/Hris/BankInfo/Requests/BankInfoListRequest.cs @@ -1,10 +1,6 @@ -using Merge.Client.Hris; - -#nullable enable - namespace Merge.Client.Hris; -public class BankInfoListRequest +public record BankInfoListRequest { /// /// If provided, will only return BankInfo's with this account type. Options: ('SAVINGS', 'CHECKING') @@ -12,80 +8,80 @@ public class BankInfoListRequest /// - `SAVINGS` - SAVINGS /// - `CHECKING` - CHECKING /// - public BankInfoListRequestAccountType? AccountType { get; init; } + public BankInfoListRequestAccountType? AccountType { get; set; } /// /// If provided, will only return BankInfo's with this bank name. /// - public string? BankName { get; init; } + public string? BankName { get; set; } /// /// If provided, will only return objects created after this datetime. /// - public DateTime? CreatedAfter { get; init; } + public DateTime? CreatedAfter { get; set; } /// /// If provided, will only return objects created before this datetime. /// - public DateTime? CreatedBefore { get; init; } + public DateTime? CreatedBefore { get; set; } /// /// The pagination cursor value. /// - public string? Cursor { get; init; } + public string? Cursor { get; set; } /// /// If provided, will only return bank accounts for this employee. /// - public string? EmployeeId { get; init; } + public string? EmployeeId { get; set; } /// /// Which relations should be returned in expanded form. Multiple relation names should be comma separated without spaces. /// - public string? Expand { get; init; } + public string? Expand { get; set; } /// /// Whether to include data that was marked as deleted by third party webhooks. /// - public bool? IncludeDeletedData { get; init; } + public bool? IncludeDeletedData { get; set; } /// /// Whether to include the original data Merge fetched from the third-party to produce these models. /// - public bool? IncludeRemoteData { get; init; } + public bool? IncludeRemoteData { get; set; } /// /// If provided, only objects synced by Merge after this date time will be returned. /// - public DateTime? ModifiedAfter { get; init; } + public DateTime? ModifiedAfter { get; set; } /// /// If provided, only objects synced by Merge before this date time will be returned. /// - public DateTime? ModifiedBefore { get; init; } + public DateTime? ModifiedBefore { get; set; } /// /// Overrides the default ordering for this endpoint. Possible values include: remote_created_at, -remote_created_at. /// - public BankInfoListRequestOrderBy? OrderBy { get; init; } + public BankInfoListRequestOrderBy? OrderBy { get; set; } /// /// Number of results to return per page. /// - public int? PageSize { get; init; } + public int? PageSize { get; set; } /// /// Deprecated. Use show_enum_origins. /// - public string? RemoteFields { get; init; } + public string? RemoteFields { get; set; } /// /// The API provider's ID for the given object. /// - public string? RemoteId { get; init; } + public string? RemoteId { get; set; } /// /// A comma separated list of enum field names for which you'd like the original values to be returned, instead of Merge's normalized enum values. [Learn more](https://help.merge.dev/en/articles/8950958-show_enum_origins-query-parameter) /// - public string? ShowEnumOrigins { get; init; } + public string? ShowEnumOrigins { get; set; } } diff --git a/src/Merge.Client/Hris/BankInfo/Requests/BankInfoRetrieveRequest.cs b/src/Merge.Client/Hris/BankInfo/Requests/BankInfoRetrieveRequest.cs index 43878276..2ca43f88 100644 --- a/src/Merge.Client/Hris/BankInfo/Requests/BankInfoRetrieveRequest.cs +++ b/src/Merge.Client/Hris/BankInfo/Requests/BankInfoRetrieveRequest.cs @@ -1,24 +1,24 @@ namespace Merge.Client.Hris; -public class BankInfoRetrieveRequest +public record BankInfoRetrieveRequest { /// /// Which relations should be returned in expanded form. Multiple relation names should be comma separated without spaces. /// - public string? Expand { get; init; } + public string? Expand { get; set; } /// /// Whether to include the original data Merge fetched from the third-party to produce these models. /// - public bool? IncludeRemoteData { get; init; } + public bool? IncludeRemoteData { get; set; } /// /// Deprecated. Use show_enum_origins. /// - public string? RemoteFields { get; init; } + public string? RemoteFields { get; set; } /// /// A comma separated list of enum field names for which you'd like the original values to be returned, instead of Merge's normalized enum values. [Learn more](https://help.merge.dev/en/articles/8950958-show_enum_origins-query-parameter) /// - public string? ShowEnumOrigins { get; init; } + public string? ShowEnumOrigins { get; set; } } diff --git a/src/Merge.Client/Hris/BankInfo/Types/BankInfoListRequestAccountType.cs b/src/Merge.Client/Hris/BankInfo/Types/BankInfoListRequestAccountType.cs index 0bb9f6c5..7c4b05b5 100644 --- a/src/Merge.Client/Hris/BankInfo/Types/BankInfoListRequestAccountType.cs +++ b/src/Merge.Client/Hris/BankInfo/Types/BankInfoListRequestAccountType.cs @@ -1,7 +1,6 @@ using System.Runtime.Serialization; using System.Text.Json.Serialization; using Merge.Client.Core; -using Merge.Client.Hris; #nullable enable diff --git a/src/Merge.Client/Hris/BankInfo/Types/BankInfoListRequestOrderBy.cs b/src/Merge.Client/Hris/BankInfo/Types/BankInfoListRequestOrderBy.cs index 8a201b06..ba316812 100644 --- a/src/Merge.Client/Hris/BankInfo/Types/BankInfoListRequestOrderBy.cs +++ b/src/Merge.Client/Hris/BankInfo/Types/BankInfoListRequestOrderBy.cs @@ -1,7 +1,6 @@ using System.Runtime.Serialization; using System.Text.Json.Serialization; using Merge.Client.Core; -using Merge.Client.Hris; #nullable enable diff --git a/src/Merge.Client/Hris/Benefits/BenefitsClient.cs b/src/Merge.Client/Hris/Benefits/BenefitsClient.cs index 717cf2ee..3c078727 100644 --- a/src/Merge.Client/Hris/Benefits/BenefitsClient.cs +++ b/src/Merge.Client/Hris/Benefits/BenefitsClient.cs @@ -1,6 +1,6 @@ +using System.Net.Http; using System.Text.Json; -using Merge.Client; -using Merge.Client.Hris; +using Merge.Client.Core; #nullable enable @@ -18,16 +18,21 @@ public BenefitsClient(RawClient client) /// /// Returns a list of `Benefit` objects. /// - public async Task ListAsync(BenefitsListRequest request) + public async Task ListAsync( + BenefitsListRequest request, + RequestOptions? options = null + ) { var _query = new Dictionary() { }; if (request.CreatedAfter != null) { - _query["created_after"] = request.CreatedAfter.Value.ToString("o0"); + _query["created_after"] = request.CreatedAfter.Value.ToString(Constants.DateTimeFormat); } if (request.CreatedBefore != null) { - _query["created_before"] = request.CreatedBefore.Value.ToString("o0"); + _query["created_before"] = request.CreatedBefore.Value.ToString( + Constants.DateTimeFormat + ); } if (request.Cursor != null) { @@ -51,11 +56,15 @@ public async Task ListAsync(BenefitsListRequest request) } if (request.ModifiedAfter != null) { - _query["modified_after"] = request.ModifiedAfter.Value.ToString("o0"); + _query["modified_after"] = request.ModifiedAfter.Value.ToString( + Constants.DateTimeFormat + ); } if (request.ModifiedBefore != null) { - _query["modified_before"] = request.ModifiedBefore.Value.ToString("o0"); + _query["modified_before"] = request.ModifiedBefore.Value.ToString( + Constants.DateTimeFormat + ); } if (request.PageSize != null) { @@ -68,23 +77,41 @@ public async Task ListAsync(BenefitsListRequest request) var response = await _client.MakeRequestAsync( new RawClient.JsonApiRequest { + BaseUrl = _client.Options.BaseUrl, Method = HttpMethod.Get, Path = "hris/v1/benefits", - Query = _query + Query = _query, + Options = options } ); - string responseBody = await response.Raw.Content.ReadAsStringAsync(); - if (response.StatusCode >= 200 && response.StatusCode < 400) + var responseBody = await response.Raw.Content.ReadAsStringAsync(); + if (response.StatusCode is >= 200 and < 400) { - return JsonSerializer.Deserialize(responseBody); + try + { + return JsonUtils.Deserialize(responseBody)!; + } + catch (JsonException e) + { + throw new MergeException("Failed to deserialize response", e); + } } - throw new Exception(responseBody); + + throw new MergeApiException( + $"Error with status code {response.StatusCode}", + response.StatusCode, + JsonUtils.Deserialize(responseBody) + ); } /// /// Returns a `Benefit` object with the given `id`. /// - public async Task RetrieveAsync(string id, BenefitsRetrieveRequest request) + public async Task RetrieveAsync( + string id, + BenefitsRetrieveRequest request, + RequestOptions? options = null + ) { var _query = new Dictionary() { }; if (request.Expand != null) @@ -98,16 +125,30 @@ public async Task RetrieveAsync(string id, BenefitsRetrieveRequest requ var response = await _client.MakeRequestAsync( new RawClient.JsonApiRequest { + BaseUrl = _client.Options.BaseUrl, Method = HttpMethod.Get, Path = $"hris/v1/benefits/{id}", - Query = _query + Query = _query, + Options = options } ); - string responseBody = await response.Raw.Content.ReadAsStringAsync(); - if (response.StatusCode >= 200 && response.StatusCode < 400) + var responseBody = await response.Raw.Content.ReadAsStringAsync(); + if (response.StatusCode is >= 200 and < 400) { - return JsonSerializer.Deserialize(responseBody); + try + { + return JsonUtils.Deserialize(responseBody)!; + } + catch (JsonException e) + { + throw new MergeException("Failed to deserialize response", e); + } } - throw new Exception(responseBody); + + throw new MergeApiException( + $"Error with status code {response.StatusCode}", + response.StatusCode, + JsonUtils.Deserialize(responseBody) + ); } } diff --git a/src/Merge.Client/Hris/Benefits/Requests/BenefitsListRequest.cs b/src/Merge.Client/Hris/Benefits/Requests/BenefitsListRequest.cs index cba30ecf..eee52180 100644 --- a/src/Merge.Client/Hris/Benefits/Requests/BenefitsListRequest.cs +++ b/src/Merge.Client/Hris/Benefits/Requests/BenefitsListRequest.cs @@ -1,59 +1,59 @@ namespace Merge.Client.Hris; -public class BenefitsListRequest +public record BenefitsListRequest { /// /// If provided, will only return objects created after this datetime. /// - public DateTime? CreatedAfter { get; init; } + public DateTime? CreatedAfter { get; set; } /// /// If provided, will only return objects created before this datetime. /// - public DateTime? CreatedBefore { get; init; } + public DateTime? CreatedBefore { get; set; } /// /// The pagination cursor value. /// - public string? Cursor { get; init; } + public string? Cursor { get; set; } /// /// If provided, will return the benefits associated with the employee. /// - public string? EmployeeId { get; init; } + public string? EmployeeId { get; set; } /// /// Which relations should be returned in expanded form. Multiple relation names should be comma separated without spaces. /// - public string? Expand { get; init; } + public string? Expand { get; set; } /// /// Whether to include data that was marked as deleted by third party webhooks. /// - public bool? IncludeDeletedData { get; init; } + public bool? IncludeDeletedData { get; set; } /// /// Whether to include the original data Merge fetched from the third-party to produce these models. /// - public bool? IncludeRemoteData { get; init; } + public bool? IncludeRemoteData { get; set; } /// /// If provided, only objects synced by Merge after this date time will be returned. /// - public DateTime? ModifiedAfter { get; init; } + public DateTime? ModifiedAfter { get; set; } /// /// If provided, only objects synced by Merge before this date time will be returned. /// - public DateTime? ModifiedBefore { get; init; } + public DateTime? ModifiedBefore { get; set; } /// /// Number of results to return per page. /// - public int? PageSize { get; init; } + public int? PageSize { get; set; } /// /// The API provider's ID for the given object. /// - public string? RemoteId { get; init; } + public string? RemoteId { get; set; } } diff --git a/src/Merge.Client/Hris/Benefits/Requests/BenefitsRetrieveRequest.cs b/src/Merge.Client/Hris/Benefits/Requests/BenefitsRetrieveRequest.cs index 256982e1..eafbb628 100644 --- a/src/Merge.Client/Hris/Benefits/Requests/BenefitsRetrieveRequest.cs +++ b/src/Merge.Client/Hris/Benefits/Requests/BenefitsRetrieveRequest.cs @@ -1,14 +1,14 @@ namespace Merge.Client.Hris; -public class BenefitsRetrieveRequest +public record BenefitsRetrieveRequest { /// /// Which relations should be returned in expanded form. Multiple relation names should be comma separated without spaces. /// - public string? Expand { get; init; } + public string? Expand { get; set; } /// /// Whether to include the original data Merge fetched from the third-party to produce these models. /// - public bool? IncludeRemoteData { get; init; } + public bool? IncludeRemoteData { get; set; } } diff --git a/src/Merge.Client/Hris/Companies/CompaniesClient.cs b/src/Merge.Client/Hris/Companies/CompaniesClient.cs index 0f18be3a..d3269781 100644 --- a/src/Merge.Client/Hris/Companies/CompaniesClient.cs +++ b/src/Merge.Client/Hris/Companies/CompaniesClient.cs @@ -1,6 +1,6 @@ +using System.Net.Http; using System.Text.Json; -using Merge.Client; -using Merge.Client.Hris; +using Merge.Client.Core; #nullable enable @@ -18,16 +18,21 @@ public CompaniesClient(RawClient client) /// /// Returns a list of `Company` objects. /// - public async Task ListAsync(CompaniesListRequest request) + public async Task ListAsync( + CompaniesListRequest request, + RequestOptions? options = null + ) { var _query = new Dictionary() { }; if (request.CreatedAfter != null) { - _query["created_after"] = request.CreatedAfter.Value.ToString("o0"); + _query["created_after"] = request.CreatedAfter.Value.ToString(Constants.DateTimeFormat); } if (request.CreatedBefore != null) { - _query["created_before"] = request.CreatedBefore.Value.ToString("o0"); + _query["created_before"] = request.CreatedBefore.Value.ToString( + Constants.DateTimeFormat + ); } if (request.Cursor != null) { @@ -43,11 +48,15 @@ public async Task ListAsync(CompaniesListRequest request) } if (request.ModifiedAfter != null) { - _query["modified_after"] = request.ModifiedAfter.Value.ToString("o0"); + _query["modified_after"] = request.ModifiedAfter.Value.ToString( + Constants.DateTimeFormat + ); } if (request.ModifiedBefore != null) { - _query["modified_before"] = request.ModifiedBefore.Value.ToString("o0"); + _query["modified_before"] = request.ModifiedBefore.Value.ToString( + Constants.DateTimeFormat + ); } if (request.PageSize != null) { @@ -60,23 +69,41 @@ public async Task ListAsync(CompaniesListRequest request) var response = await _client.MakeRequestAsync( new RawClient.JsonApiRequest { + BaseUrl = _client.Options.BaseUrl, Method = HttpMethod.Get, Path = "hris/v1/companies", - Query = _query + Query = _query, + Options = options } ); - string responseBody = await response.Raw.Content.ReadAsStringAsync(); - if (response.StatusCode >= 200 && response.StatusCode < 400) + var responseBody = await response.Raw.Content.ReadAsStringAsync(); + if (response.StatusCode is >= 200 and < 400) { - return JsonSerializer.Deserialize(responseBody); + try + { + return JsonUtils.Deserialize(responseBody)!; + } + catch (JsonException e) + { + throw new MergeException("Failed to deserialize response", e); + } } - throw new Exception(responseBody); + + throw new MergeApiException( + $"Error with status code {response.StatusCode}", + response.StatusCode, + JsonUtils.Deserialize(responseBody) + ); } /// /// Returns a `Company` object with the given `id`. /// - public async Task RetrieveAsync(string id, CompaniesRetrieveRequest request) + public async Task RetrieveAsync( + string id, + CompaniesRetrieveRequest request, + RequestOptions? options = null + ) { var _query = new Dictionary() { }; if (request.IncludeRemoteData != null) @@ -86,16 +113,30 @@ public async Task RetrieveAsync(string id, CompaniesRetrieveRequest req var response = await _client.MakeRequestAsync( new RawClient.JsonApiRequest { + BaseUrl = _client.Options.BaseUrl, Method = HttpMethod.Get, Path = $"hris/v1/companies/{id}", - Query = _query + Query = _query, + Options = options } ); - string responseBody = await response.Raw.Content.ReadAsStringAsync(); - if (response.StatusCode >= 200 && response.StatusCode < 400) + var responseBody = await response.Raw.Content.ReadAsStringAsync(); + if (response.StatusCode is >= 200 and < 400) { - return JsonSerializer.Deserialize(responseBody); + try + { + return JsonUtils.Deserialize(responseBody)!; + } + catch (JsonException e) + { + throw new MergeException("Failed to deserialize response", e); + } } - throw new Exception(responseBody); + + throw new MergeApiException( + $"Error with status code {response.StatusCode}", + response.StatusCode, + JsonUtils.Deserialize(responseBody) + ); } } diff --git a/src/Merge.Client/Hris/Companies/Requests/CompaniesListRequest.cs b/src/Merge.Client/Hris/Companies/Requests/CompaniesListRequest.cs index bd8776eb..eb1bc167 100644 --- a/src/Merge.Client/Hris/Companies/Requests/CompaniesListRequest.cs +++ b/src/Merge.Client/Hris/Companies/Requests/CompaniesListRequest.cs @@ -1,49 +1,49 @@ namespace Merge.Client.Hris; -public class CompaniesListRequest +public record CompaniesListRequest { /// /// If provided, will only return objects created after this datetime. /// - public DateTime? CreatedAfter { get; init; } + public DateTime? CreatedAfter { get; set; } /// /// If provided, will only return objects created before this datetime. /// - public DateTime? CreatedBefore { get; init; } + public DateTime? CreatedBefore { get; set; } /// /// The pagination cursor value. /// - public string? Cursor { get; init; } + public string? Cursor { get; set; } /// /// Whether to include data that was marked as deleted by third party webhooks. /// - public bool? IncludeDeletedData { get; init; } + public bool? IncludeDeletedData { get; set; } /// /// Whether to include the original data Merge fetched from the third-party to produce these models. /// - public bool? IncludeRemoteData { get; init; } + public bool? IncludeRemoteData { get; set; } /// /// If provided, only objects synced by Merge after this date time will be returned. /// - public DateTime? ModifiedAfter { get; init; } + public DateTime? ModifiedAfter { get; set; } /// /// If provided, only objects synced by Merge before this date time will be returned. /// - public DateTime? ModifiedBefore { get; init; } + public DateTime? ModifiedBefore { get; set; } /// /// Number of results to return per page. /// - public int? PageSize { get; init; } + public int? PageSize { get; set; } /// /// The API provider's ID for the given object. /// - public string? RemoteId { get; init; } + public string? RemoteId { get; set; } } diff --git a/src/Merge.Client/Hris/Companies/Requests/CompaniesRetrieveRequest.cs b/src/Merge.Client/Hris/Companies/Requests/CompaniesRetrieveRequest.cs index 252fefa8..b4d8f9d0 100644 --- a/src/Merge.Client/Hris/Companies/Requests/CompaniesRetrieveRequest.cs +++ b/src/Merge.Client/Hris/Companies/Requests/CompaniesRetrieveRequest.cs @@ -1,9 +1,9 @@ namespace Merge.Client.Hris; -public class CompaniesRetrieveRequest +public record CompaniesRetrieveRequest { /// /// Whether to include the original data Merge fetched from the third-party to produce these models. /// - public bool? IncludeRemoteData { get; init; } + public bool? IncludeRemoteData { get; set; } } diff --git a/src/Merge.Client/Hris/DeleteAccount/DeleteAccountClient.cs b/src/Merge.Client/Hris/DeleteAccount/DeleteAccountClient.cs index 7d6df7d9..91ced298 100644 --- a/src/Merge.Client/Hris/DeleteAccount/DeleteAccountClient.cs +++ b/src/Merge.Client/Hris/DeleteAccount/DeleteAccountClient.cs @@ -1,4 +1,5 @@ -using Merge.Client; +using System.Net.Http; +using Merge.Client.Core; #nullable enable @@ -16,14 +17,26 @@ public DeleteAccountClient(RawClient client) /// /// Delete a linked account. /// - public async void DeleteAsync() + public async Task DeleteAsync(RequestOptions? options = null) { var response = await _client.MakeRequestAsync( new RawClient.JsonApiRequest { + BaseUrl = _client.Options.BaseUrl, Method = HttpMethod.Post, - Path = "hris/v1/delete-account" + Path = "hris/v1/delete-account", + Options = options } ); + if (response.StatusCode is >= 200 and < 400) + { + return; + } + var responseBody = await response.Raw.Content.ReadAsStringAsync(); + throw new MergeApiException( + $"Error with status code {response.StatusCode}", + response.StatusCode, + JsonUtils.Deserialize(responseBody) + ); } } diff --git a/src/Merge.Client/Hris/Dependents/DependentsClient.cs b/src/Merge.Client/Hris/Dependents/DependentsClient.cs index 63a90176..461b189b 100644 --- a/src/Merge.Client/Hris/Dependents/DependentsClient.cs +++ b/src/Merge.Client/Hris/Dependents/DependentsClient.cs @@ -1,6 +1,6 @@ +using System.Net.Http; using System.Text.Json; -using Merge.Client; -using Merge.Client.Hris; +using Merge.Client.Core; #nullable enable @@ -18,16 +18,21 @@ public DependentsClient(RawClient client) /// /// Returns a list of `Dependent` objects. /// - public async Task ListAsync(DependentsListRequest request) + public async Task ListAsync( + DependentsListRequest request, + RequestOptions? options = null + ) { var _query = new Dictionary() { }; if (request.CreatedAfter != null) { - _query["created_after"] = request.CreatedAfter.Value.ToString("o0"); + _query["created_after"] = request.CreatedAfter.Value.ToString(Constants.DateTimeFormat); } if (request.CreatedBefore != null) { - _query["created_before"] = request.CreatedBefore.Value.ToString("o0"); + _query["created_before"] = request.CreatedBefore.Value.ToString( + Constants.DateTimeFormat + ); } if (request.Cursor != null) { @@ -47,11 +52,15 @@ public async Task ListAsync(DependentsListRequest reques } if (request.ModifiedAfter != null) { - _query["modified_after"] = request.ModifiedAfter.Value.ToString("o0"); + _query["modified_after"] = request.ModifiedAfter.Value.ToString( + Constants.DateTimeFormat + ); } if (request.ModifiedBefore != null) { - _query["modified_before"] = request.ModifiedBefore.Value.ToString("o0"); + _query["modified_before"] = request.ModifiedBefore.Value.ToString( + Constants.DateTimeFormat + ); } if (request.PageSize != null) { @@ -64,23 +73,41 @@ public async Task ListAsync(DependentsListRequest reques var response = await _client.MakeRequestAsync( new RawClient.JsonApiRequest { + BaseUrl = _client.Options.BaseUrl, Method = HttpMethod.Get, Path = "hris/v1/dependents", - Query = _query + Query = _query, + Options = options } ); - string responseBody = await response.Raw.Content.ReadAsStringAsync(); - if (response.StatusCode >= 200 && response.StatusCode < 400) + var responseBody = await response.Raw.Content.ReadAsStringAsync(); + if (response.StatusCode is >= 200 and < 400) { - return JsonSerializer.Deserialize(responseBody); + try + { + return JsonUtils.Deserialize(responseBody)!; + } + catch (JsonException e) + { + throw new MergeException("Failed to deserialize response", e); + } } - throw new Exception(responseBody); + + throw new MergeApiException( + $"Error with status code {response.StatusCode}", + response.StatusCode, + JsonUtils.Deserialize(responseBody) + ); } /// /// Returns a `Dependent` object with the given `id`. /// - public async Task RetrieveAsync(string id, DependentsRetrieveRequest request) + public async Task RetrieveAsync( + string id, + DependentsRetrieveRequest request, + RequestOptions? options = null + ) { var _query = new Dictionary() { }; if (request.IncludeRemoteData != null) @@ -94,16 +121,30 @@ public async Task RetrieveAsync(string id, DependentsRetrieveRequest var response = await _client.MakeRequestAsync( new RawClient.JsonApiRequest { + BaseUrl = _client.Options.BaseUrl, Method = HttpMethod.Get, Path = $"hris/v1/dependents/{id}", - Query = _query + Query = _query, + Options = options } ); - string responseBody = await response.Raw.Content.ReadAsStringAsync(); - if (response.StatusCode >= 200 && response.StatusCode < 400) + var responseBody = await response.Raw.Content.ReadAsStringAsync(); + if (response.StatusCode is >= 200 and < 400) { - return JsonSerializer.Deserialize(responseBody); + try + { + return JsonUtils.Deserialize(responseBody)!; + } + catch (JsonException e) + { + throw new MergeException("Failed to deserialize response", e); + } } - throw new Exception(responseBody); + + throw new MergeApiException( + $"Error with status code {response.StatusCode}", + response.StatusCode, + JsonUtils.Deserialize(responseBody) + ); } } diff --git a/src/Merge.Client/Hris/Dependents/Requests/DependentsListRequest.cs b/src/Merge.Client/Hris/Dependents/Requests/DependentsListRequest.cs index 52e10e6d..ca99e3f6 100644 --- a/src/Merge.Client/Hris/Dependents/Requests/DependentsListRequest.cs +++ b/src/Merge.Client/Hris/Dependents/Requests/DependentsListRequest.cs @@ -1,54 +1,54 @@ namespace Merge.Client.Hris; -public class DependentsListRequest +public record DependentsListRequest { /// /// If provided, will only return objects created after this datetime. /// - public DateTime? CreatedAfter { get; init; } + public DateTime? CreatedAfter { get; set; } /// /// If provided, will only return objects created before this datetime. /// - public DateTime? CreatedBefore { get; init; } + public DateTime? CreatedBefore { get; set; } /// /// The pagination cursor value. /// - public string? Cursor { get; init; } + public string? Cursor { get; set; } /// /// Whether to include data that was marked as deleted by third party webhooks. /// - public bool? IncludeDeletedData { get; init; } + public bool? IncludeDeletedData { get; set; } /// /// Whether to include the original data Merge fetched from the third-party to produce these models. /// - public bool? IncludeRemoteData { get; init; } + public bool? IncludeRemoteData { get; set; } /// /// Whether to include sensitive fields (such as social security numbers) in the response. /// - public bool? IncludeSensitiveFields { get; init; } + public bool? IncludeSensitiveFields { get; set; } /// /// If provided, only objects synced by Merge after this date time will be returned. /// - public DateTime? ModifiedAfter { get; init; } + public DateTime? ModifiedAfter { get; set; } /// /// If provided, only objects synced by Merge before this date time will be returned. /// - public DateTime? ModifiedBefore { get; init; } + public DateTime? ModifiedBefore { get; set; } /// /// Number of results to return per page. /// - public int? PageSize { get; init; } + public int? PageSize { get; set; } /// /// The API provider's ID for the given object. /// - public string? RemoteId { get; init; } + public string? RemoteId { get; set; } } diff --git a/src/Merge.Client/Hris/Dependents/Requests/DependentsRetrieveRequest.cs b/src/Merge.Client/Hris/Dependents/Requests/DependentsRetrieveRequest.cs index 2e4938e8..92029f07 100644 --- a/src/Merge.Client/Hris/Dependents/Requests/DependentsRetrieveRequest.cs +++ b/src/Merge.Client/Hris/Dependents/Requests/DependentsRetrieveRequest.cs @@ -1,14 +1,14 @@ namespace Merge.Client.Hris; -public class DependentsRetrieveRequest +public record DependentsRetrieveRequest { /// /// Whether to include the original data Merge fetched from the third-party to produce these models. /// - public bool? IncludeRemoteData { get; init; } + public bool? IncludeRemoteData { get; set; } /// /// Whether to include sensitive fields (such as social security numbers) in the response. /// - public bool? IncludeSensitiveFields { get; init; } + public bool? IncludeSensitiveFields { get; set; } } diff --git a/src/Merge.Client/Hris/EmployeePayrollRuns/EmployeePayrollRunsClient.cs b/src/Merge.Client/Hris/EmployeePayrollRuns/EmployeePayrollRunsClient.cs index 83fbbae4..73a27e16 100644 --- a/src/Merge.Client/Hris/EmployeePayrollRuns/EmployeePayrollRunsClient.cs +++ b/src/Merge.Client/Hris/EmployeePayrollRuns/EmployeePayrollRunsClient.cs @@ -1,6 +1,6 @@ +using System.Net.Http; using System.Text.Json; -using Merge.Client; -using Merge.Client.Hris; +using Merge.Client.Core; #nullable enable @@ -19,17 +19,20 @@ public EmployeePayrollRunsClient(RawClient client) /// Returns a list of `EmployeePayrollRun` objects. /// public async Task ListAsync( - EmployeePayrollRunsListRequest request + EmployeePayrollRunsListRequest request, + RequestOptions? options = null ) { var _query = new Dictionary() { }; if (request.CreatedAfter != null) { - _query["created_after"] = request.CreatedAfter.Value.ToString("o0"); + _query["created_after"] = request.CreatedAfter.Value.ToString(Constants.DateTimeFormat); } if (request.CreatedBefore != null) { - _query["created_before"] = request.CreatedBefore.Value.ToString("o0"); + _query["created_before"] = request.CreatedBefore.Value.ToString( + Constants.DateTimeFormat + ); } if (request.Cursor != null) { @@ -41,11 +44,11 @@ EmployeePayrollRunsListRequest request } if (request.EndedAfter != null) { - _query["ended_after"] = request.EndedAfter.Value.ToString("o0"); + _query["ended_after"] = request.EndedAfter.Value.ToString(Constants.DateTimeFormat); } if (request.EndedBefore != null) { - _query["ended_before"] = request.EndedBefore.Value.ToString("o0"); + _query["ended_before"] = request.EndedBefore.Value.ToString(Constants.DateTimeFormat); } if (request.Expand != null) { @@ -61,11 +64,15 @@ EmployeePayrollRunsListRequest request } if (request.ModifiedAfter != null) { - _query["modified_after"] = request.ModifiedAfter.Value.ToString("o0"); + _query["modified_after"] = request.ModifiedAfter.Value.ToString( + Constants.DateTimeFormat + ); } if (request.ModifiedBefore != null) { - _query["modified_before"] = request.ModifiedBefore.Value.ToString("o0"); + _query["modified_before"] = request.ModifiedBefore.Value.ToString( + Constants.DateTimeFormat + ); } if (request.PageSize != null) { @@ -81,26 +88,42 @@ EmployeePayrollRunsListRequest request } if (request.StartedAfter != null) { - _query["started_after"] = request.StartedAfter.Value.ToString("o0"); + _query["started_after"] = request.StartedAfter.Value.ToString(Constants.DateTimeFormat); } if (request.StartedBefore != null) { - _query["started_before"] = request.StartedBefore.Value.ToString("o0"); + _query["started_before"] = request.StartedBefore.Value.ToString( + Constants.DateTimeFormat + ); } var response = await _client.MakeRequestAsync( new RawClient.JsonApiRequest { + BaseUrl = _client.Options.BaseUrl, Method = HttpMethod.Get, Path = "hris/v1/employee-payroll-runs", - Query = _query + Query = _query, + Options = options } ); - string responseBody = await response.Raw.Content.ReadAsStringAsync(); - if (response.StatusCode >= 200 && response.StatusCode < 400) + var responseBody = await response.Raw.Content.ReadAsStringAsync(); + if (response.StatusCode is >= 200 and < 400) { - return JsonSerializer.Deserialize(responseBody); + try + { + return JsonUtils.Deserialize(responseBody)!; + } + catch (JsonException e) + { + throw new MergeException("Failed to deserialize response", e); + } } - throw new Exception(responseBody); + + throw new MergeApiException( + $"Error with status code {response.StatusCode}", + response.StatusCode, + JsonUtils.Deserialize(responseBody) + ); } /// @@ -108,7 +131,8 @@ EmployeePayrollRunsListRequest request /// public async Task RetrieveAsync( string id, - EmployeePayrollRunsRetrieveRequest request + EmployeePayrollRunsRetrieveRequest request, + RequestOptions? options = null ) { var _query = new Dictionary() { }; @@ -123,16 +147,30 @@ EmployeePayrollRunsRetrieveRequest request var response = await _client.MakeRequestAsync( new RawClient.JsonApiRequest { + BaseUrl = _client.Options.BaseUrl, Method = HttpMethod.Get, Path = $"hris/v1/employee-payroll-runs/{id}", - Query = _query + Query = _query, + Options = options } ); - string responseBody = await response.Raw.Content.ReadAsStringAsync(); - if (response.StatusCode >= 200 && response.StatusCode < 400) + var responseBody = await response.Raw.Content.ReadAsStringAsync(); + if (response.StatusCode is >= 200 and < 400) { - return JsonSerializer.Deserialize(responseBody); + try + { + return JsonUtils.Deserialize(responseBody)!; + } + catch (JsonException e) + { + throw new MergeException("Failed to deserialize response", e); + } } - throw new Exception(responseBody); + + throw new MergeApiException( + $"Error with status code {response.StatusCode}", + response.StatusCode, + JsonUtils.Deserialize(responseBody) + ); } } diff --git a/src/Merge.Client/Hris/EmployeePayrollRuns/Requests/EmployeePayrollRunsListRequest.cs b/src/Merge.Client/Hris/EmployeePayrollRuns/Requests/EmployeePayrollRunsListRequest.cs index 54985d82..37ec8c0c 100644 --- a/src/Merge.Client/Hris/EmployeePayrollRuns/Requests/EmployeePayrollRunsListRequest.cs +++ b/src/Merge.Client/Hris/EmployeePayrollRuns/Requests/EmployeePayrollRunsListRequest.cs @@ -1,88 +1,84 @@ -using Merge.Client.Hris; - -#nullable enable - namespace Merge.Client.Hris; -public class EmployeePayrollRunsListRequest +public record EmployeePayrollRunsListRequest { /// /// If provided, will only return objects created after this datetime. /// - public DateTime? CreatedAfter { get; init; } + public DateTime? CreatedAfter { get; set; } /// /// If provided, will only return objects created before this datetime. /// - public DateTime? CreatedBefore { get; init; } + public DateTime? CreatedBefore { get; set; } /// /// The pagination cursor value. /// - public string? Cursor { get; init; } + public string? Cursor { get; set; } /// /// If provided, will only return employee payroll runs for this employee. /// - public string? EmployeeId { get; init; } + public string? EmployeeId { get; set; } /// /// If provided, will only return employee payroll runs ended after this datetime. /// - public DateTime? EndedAfter { get; init; } + public DateTime? EndedAfter { get; set; } /// /// If provided, will only return employee payroll runs ended before this datetime. /// - public DateTime? EndedBefore { get; init; } + public DateTime? EndedBefore { get; set; } /// /// Which relations should be returned in expanded form. Multiple relation names should be comma separated without spaces. /// - public EmployeePayrollRunsListRequestExpand? Expand { get; init; } + public EmployeePayrollRunsListRequestExpand? Expand { get; set; } /// /// Whether to include data that was marked as deleted by third party webhooks. /// - public bool? IncludeDeletedData { get; init; } + public bool? IncludeDeletedData { get; set; } /// /// Whether to include the original data Merge fetched from the third-party to produce these models. /// - public bool? IncludeRemoteData { get; init; } + public bool? IncludeRemoteData { get; set; } /// /// If provided, only objects synced by Merge after this date time will be returned. /// - public DateTime? ModifiedAfter { get; init; } + public DateTime? ModifiedAfter { get; set; } /// /// If provided, only objects synced by Merge before this date time will be returned. /// - public DateTime? ModifiedBefore { get; init; } + public DateTime? ModifiedBefore { get; set; } /// /// Number of results to return per page. /// - public int? PageSize { get; init; } + public int? PageSize { get; set; } /// /// If provided, will only return employee payroll runs for this employee. /// - public string? PayrollRunId { get; init; } + public string? PayrollRunId { get; set; } /// /// The API provider's ID for the given object. /// - public string? RemoteId { get; init; } + public string? RemoteId { get; set; } /// /// If provided, will only return employee payroll runs started after this datetime. /// - public DateTime? StartedAfter { get; init; } + public DateTime? StartedAfter { get; set; } /// /// If provided, will only return employee payroll runs started before this datetime. /// - public DateTime? StartedBefore { get; init; } + public DateTime? StartedBefore { get; set; } } diff --git a/src/Merge.Client/Hris/EmployeePayrollRuns/Requests/EmployeePayrollRunsRetrieveRequest.cs b/src/Merge.Client/Hris/EmployeePayrollRuns/Requests/EmployeePayrollRunsRetrieveRequest.cs index f45a9475..c768e4c8 100644 --- a/src/Merge.Client/Hris/EmployeePayrollRuns/Requests/EmployeePayrollRunsRetrieveRequest.cs +++ b/src/Merge.Client/Hris/EmployeePayrollRuns/Requests/EmployeePayrollRunsRetrieveRequest.cs @@ -1,18 +1,14 @@ -using Merge.Client.Hris; - -#nullable enable - namespace Merge.Client.Hris; -public class EmployeePayrollRunsRetrieveRequest +public record EmployeePayrollRunsRetrieveRequest { /// /// Which relations should be returned in expanded form. Multiple relation names should be comma separated without spaces. /// - public EmployeePayrollRunsRetrieveRequestExpand? Expand { get; init; } + public EmployeePayrollRunsRetrieveRequestExpand? Expand { get; set; } /// /// Whether to include the original data Merge fetched from the third-party to produce these models. /// - public bool? IncludeRemoteData { get; init; } + public bool? IncludeRemoteData { get; set; } } diff --git a/src/Merge.Client/Hris/EmployeePayrollRuns/Types/EmployeePayrollRunsListRequestExpand.cs b/src/Merge.Client/Hris/EmployeePayrollRuns/Types/EmployeePayrollRunsListRequestExpand.cs index 71bde39f..3891e5f6 100644 --- a/src/Merge.Client/Hris/EmployeePayrollRuns/Types/EmployeePayrollRunsListRequestExpand.cs +++ b/src/Merge.Client/Hris/EmployeePayrollRuns/Types/EmployeePayrollRunsListRequestExpand.cs @@ -1,7 +1,6 @@ using System.Runtime.Serialization; using System.Text.Json.Serialization; using Merge.Client.Core; -using Merge.Client.Hris; #nullable enable diff --git a/src/Merge.Client/Hris/EmployeePayrollRuns/Types/EmployeePayrollRunsRetrieveRequestExpand.cs b/src/Merge.Client/Hris/EmployeePayrollRuns/Types/EmployeePayrollRunsRetrieveRequestExpand.cs index 5ce27bf0..909908bc 100644 --- a/src/Merge.Client/Hris/EmployeePayrollRuns/Types/EmployeePayrollRunsRetrieveRequestExpand.cs +++ b/src/Merge.Client/Hris/EmployeePayrollRuns/Types/EmployeePayrollRunsRetrieveRequestExpand.cs @@ -1,7 +1,6 @@ using System.Runtime.Serialization; using System.Text.Json.Serialization; using Merge.Client.Core; -using Merge.Client.Hris; #nullable enable diff --git a/src/Merge.Client/Hris/Employees/EmployeesClient.cs b/src/Merge.Client/Hris/Employees/EmployeesClient.cs index 89750da7..0ebb5e18 100644 --- a/src/Merge.Client/Hris/Employees/EmployeesClient.cs +++ b/src/Merge.Client/Hris/Employees/EmployeesClient.cs @@ -1,6 +1,6 @@ +using System.Net.Http; using System.Text.Json; -using Merge.Client; -using Merge.Client.Hris; +using Merge.Client.Core; #nullable enable @@ -18,7 +18,10 @@ public EmployeesClient(RawClient client) /// /// Returns a list of `Employee` objects. /// - public async Task ListAsync(EmployeesListRequest request) + public async Task ListAsync( + EmployeesListRequest request, + RequestOptions? options = null + ) { var _query = new Dictionary() { }; if (request.CompanyId != null) @@ -27,11 +30,13 @@ public async Task ListAsync(EmployeesListRequest request) } if (request.CreatedAfter != null) { - _query["created_after"] = request.CreatedAfter.Value.ToString("o0"); + _query["created_after"] = request.CreatedAfter.Value.ToString(Constants.DateTimeFormat); } if (request.CreatedBefore != null) { - _query["created_before"] = request.CreatedBefore.Value.ToString("o0"); + _query["created_before"] = request.CreatedBefore.Value.ToString( + Constants.DateTimeFormat + ); } if (request.Cursor != null) { @@ -91,11 +96,15 @@ public async Task ListAsync(EmployeesListRequest request) } if (request.ModifiedAfter != null) { - _query["modified_after"] = request.ModifiedAfter.Value.ToString("o0"); + _query["modified_after"] = request.ModifiedAfter.Value.ToString( + Constants.DateTimeFormat + ); } if (request.ModifiedBefore != null) { - _query["modified_before"] = request.ModifiedBefore.Value.ToString("o0"); + _query["modified_before"] = request.ModifiedBefore.Value.ToString( + Constants.DateTimeFormat + ); } if (request.PageSize != null) { @@ -123,11 +132,13 @@ public async Task ListAsync(EmployeesListRequest request) } if (request.StartedAfter != null) { - _query["started_after"] = request.StartedAfter.Value.ToString("o0"); + _query["started_after"] = request.StartedAfter.Value.ToString(Constants.DateTimeFormat); } if (request.StartedBefore != null) { - _query["started_before"] = request.StartedBefore.Value.ToString("o0"); + _query["started_before"] = request.StartedBefore.Value.ToString( + Constants.DateTimeFormat + ); } if (request.TeamId != null) { @@ -135,11 +146,15 @@ public async Task ListAsync(EmployeesListRequest request) } if (request.TerminatedAfter != null) { - _query["terminated_after"] = request.TerminatedAfter.Value.ToString("o0"); + _query["terminated_after"] = request.TerminatedAfter.Value.ToString( + Constants.DateTimeFormat + ); } if (request.TerminatedBefore != null) { - _query["terminated_before"] = request.TerminatedBefore.Value.ToString("o0"); + _query["terminated_before"] = request.TerminatedBefore.Value.ToString( + Constants.DateTimeFormat + ); } if (request.WorkEmail != null) { @@ -152,23 +167,40 @@ public async Task ListAsync(EmployeesListRequest request) var response = await _client.MakeRequestAsync( new RawClient.JsonApiRequest { + BaseUrl = _client.Options.BaseUrl, Method = HttpMethod.Get, Path = "hris/v1/employees", - Query = _query + Query = _query, + Options = options } ); - string responseBody = await response.Raw.Content.ReadAsStringAsync(); - if (response.StatusCode >= 200 && response.StatusCode < 400) + var responseBody = await response.Raw.Content.ReadAsStringAsync(); + if (response.StatusCode is >= 200 and < 400) { - return JsonSerializer.Deserialize(responseBody); + try + { + return JsonUtils.Deserialize(responseBody)!; + } + catch (JsonException e) + { + throw new MergeException("Failed to deserialize response", e); + } } - throw new Exception(responseBody); + + throw new MergeApiException( + $"Error with status code {response.StatusCode}", + response.StatusCode, + JsonUtils.Deserialize(responseBody) + ); } /// /// Creates an `Employee` object with the given values. /// - public async Task CreateAsync(EmployeeEndpointRequest request) + public async Task CreateAsync( + EmployeeEndpointRequest request, + RequestOptions? options = null + ) { var _query = new Dictionary() { }; if (request.IsDebugMode != null) @@ -182,23 +214,41 @@ public async Task CreateAsync(EmployeeEndpointRequest request) var response = await _client.MakeRequestAsync( new RawClient.JsonApiRequest { + BaseUrl = _client.Options.BaseUrl, Method = HttpMethod.Post, Path = "hris/v1/employees", - Query = _query + Query = _query, + Options = options } ); - string responseBody = await response.Raw.Content.ReadAsStringAsync(); - if (response.StatusCode >= 200 && response.StatusCode < 400) + var responseBody = await response.Raw.Content.ReadAsStringAsync(); + if (response.StatusCode is >= 200 and < 400) { - return JsonSerializer.Deserialize(responseBody); + try + { + return JsonUtils.Deserialize(responseBody)!; + } + catch (JsonException e) + { + throw new MergeException("Failed to deserialize response", e); + } } - throw new Exception(responseBody); + + throw new MergeApiException( + $"Error with status code {response.StatusCode}", + response.StatusCode, + JsonUtils.Deserialize(responseBody) + ); } /// /// Returns an `Employee` object with the given `id`. /// - public async Task RetrieveAsync(string id, EmployeesRetrieveRequest request) + public async Task RetrieveAsync( + string id, + EmployeesRetrieveRequest request, + RequestOptions? options = null + ) { var _query = new Dictionary() { }; if (request.Expand != null) @@ -224,51 +274,95 @@ public async Task RetrieveAsync(string id, EmployeesRetrieveRequest re var response = await _client.MakeRequestAsync( new RawClient.JsonApiRequest { + BaseUrl = _client.Options.BaseUrl, Method = HttpMethod.Get, Path = $"hris/v1/employees/{id}", - Query = _query + Query = _query, + Options = options } ); - string responseBody = await response.Raw.Content.ReadAsStringAsync(); - if (response.StatusCode >= 200 && response.StatusCode < 400) + var responseBody = await response.Raw.Content.ReadAsStringAsync(); + if (response.StatusCode is >= 200 and < 400) { - return JsonSerializer.Deserialize(responseBody); + try + { + return JsonUtils.Deserialize(responseBody)!; + } + catch (JsonException e) + { + throw new MergeException("Failed to deserialize response", e); + } } - throw new Exception(responseBody); + + throw new MergeApiException( + $"Error with status code {response.StatusCode}", + response.StatusCode, + JsonUtils.Deserialize(responseBody) + ); } /// /// Ignores a specific row based on the `model_id` in the url. These records will have their properties set to null, and will not be updated in future syncs. The "reason" and "message" fields in the request body will be stored for audit purposes. /// - public async void IgnoreCreateAsync(string modelId, IgnoreCommonModelRequest request) + public async Task IgnoreCreateAsync( + string modelId, + IgnoreCommonModelRequest request, + RequestOptions? options = null + ) { var response = await _client.MakeRequestAsync( new RawClient.JsonApiRequest { + BaseUrl = _client.Options.BaseUrl, Method = HttpMethod.Post, Path = $"hris/v1/employees/ignore/{modelId}", - Body = request + Body = request, + Options = options } ); + if (response.StatusCode is >= 200 and < 400) + { + return; + } + var responseBody = await response.Raw.Content.ReadAsStringAsync(); + throw new MergeApiException( + $"Error with status code {response.StatusCode}", + response.StatusCode, + JsonUtils.Deserialize(responseBody) + ); } /// /// Returns metadata for `Employee` POSTs. /// - public async Task MetaPostRetrieveAsync() + public async Task MetaPostRetrieveAsync(RequestOptions? options = null) { var response = await _client.MakeRequestAsync( new RawClient.JsonApiRequest { + BaseUrl = _client.Options.BaseUrl, Method = HttpMethod.Get, - Path = "hris/v1/employees/meta/post" + Path = "hris/v1/employees/meta/post", + Options = options } ); - string responseBody = await response.Raw.Content.ReadAsStringAsync(); - if (response.StatusCode >= 200 && response.StatusCode < 400) + var responseBody = await response.Raw.Content.ReadAsStringAsync(); + if (response.StatusCode is >= 200 and < 400) { - return JsonSerializer.Deserialize(responseBody); + try + { + return JsonUtils.Deserialize(responseBody)!; + } + catch (JsonException e) + { + throw new MergeException("Failed to deserialize response", e); + } } - throw new Exception(responseBody); + + throw new MergeApiException( + $"Error with status code {response.StatusCode}", + response.StatusCode, + JsonUtils.Deserialize(responseBody) + ); } } diff --git a/src/Merge.Client/Hris/Employees/Requests/EmployeeEndpointRequest.cs b/src/Merge.Client/Hris/Employees/Requests/EmployeeEndpointRequest.cs index 0cad6f6d..fc2a783d 100644 --- a/src/Merge.Client/Hris/Employees/Requests/EmployeeEndpointRequest.cs +++ b/src/Merge.Client/Hris/Employees/Requests/EmployeeEndpointRequest.cs @@ -1,20 +1,16 @@ -using Merge.Client.Hris; - -#nullable enable - namespace Merge.Client.Hris; -public class EmployeeEndpointRequest +public record EmployeeEndpointRequest { /// /// Whether to include debug fields (such as log file links) in the response. /// - public bool? IsDebugMode { get; init; } + public bool? IsDebugMode { get; set; } /// /// Whether or not third-party updates should be run asynchronously. /// - public bool? RunAsync { get; init; } + public bool? RunAsync { get; set; } - public EmployeeRequest Model { get; init; } + public required EmployeeRequest Model { get; set; } } diff --git a/src/Merge.Client/Hris/Employees/Requests/EmployeesListRequest.cs b/src/Merge.Client/Hris/Employees/Requests/EmployeesListRequest.cs index ad8491a3..4300e781 100644 --- a/src/Merge.Client/Hris/Employees/Requests/EmployeesListRequest.cs +++ b/src/Merge.Client/Hris/Employees/Requests/EmployeesListRequest.cs @@ -1,35 +1,31 @@ -using Merge.Client.Hris; - -#nullable enable - namespace Merge.Client.Hris; -public class EmployeesListRequest +public record EmployeesListRequest { /// /// If provided, will only return employees for this company. /// - public string? CompanyId { get; init; } + public string? CompanyId { get; set; } /// /// If provided, will only return objects created after this datetime. /// - public DateTime? CreatedAfter { get; init; } + public DateTime? CreatedAfter { get; set; } /// /// If provided, will only return objects created before this datetime. /// - public DateTime? CreatedBefore { get; init; } + public DateTime? CreatedBefore { get; set; } /// /// The pagination cursor value. /// - public string? Cursor { get; init; } + public string? Cursor { get; set; } /// /// If provided, will only return employees with this display name. /// - public string? DisplayFullName { get; init; } + public string? DisplayFullName { get; set; } /// /// If provided, will only return employees with this employment status. @@ -38,135 +34,135 @@ public class EmployeesListRequest /// - `PENDING` - PENDING /// - `INACTIVE` - INACTIVE /// - public EmployeesListRequestEmploymentStatus? EmploymentStatus { get; init; } + public EmployeesListRequestEmploymentStatus? EmploymentStatus { get; set; } /// /// If provided, will only return employees that have an employment of the specified employment_type. /// - public string? EmploymentType { get; init; } + public string? EmploymentType { get; set; } /// /// Which relations should be returned in expanded form. Multiple relation names should be comma separated without spaces. /// - public EmployeesListRequestExpand? Expand { get; init; } + public EmployeesListRequestExpand? Expand { get; set; } /// /// If provided, will only return employees with this first name. /// - public string? FirstName { get; init; } + public string? FirstName { get; set; } /// /// If provided, will only return employees matching the group ids; multiple groups can be separated by commas. /// - public string? Groups { get; init; } + public string? Groups { get; set; } /// /// If provided, will only return employees for this home location. /// - public string? HomeLocationId { get; init; } + public string? HomeLocationId { get; set; } /// /// Whether to include data that was marked as deleted by third party webhooks. /// - public bool? IncludeDeletedData { get; init; } + public bool? IncludeDeletedData { get; set; } /// /// Whether to include the original data Merge fetched from the third-party to produce these models. /// - public bool? IncludeRemoteData { get; init; } + public bool? IncludeRemoteData { get; set; } /// /// Whether to include sensitive fields (such as social security numbers) in the response. /// - public bool? IncludeSensitiveFields { get; init; } + public bool? IncludeSensitiveFields { get; set; } /// /// If provided, will only return employees that have an employment of the specified job_title. /// - public string? JobTitle { get; init; } + public string? JobTitle { get; set; } /// /// If provided, will only return employees with this last name. /// - public string? LastName { get; init; } + public string? LastName { get; set; } /// /// If provided, will only return employees for this manager. /// - public string? ManagerId { get; init; } + public string? ManagerId { get; set; } /// /// If provided, only objects synced by Merge after this date time will be returned. /// - public DateTime? ModifiedAfter { get; init; } + public DateTime? ModifiedAfter { get; set; } /// /// If provided, only objects synced by Merge before this date time will be returned. /// - public DateTime? ModifiedBefore { get; init; } + public DateTime? ModifiedBefore { get; set; } /// /// Number of results to return per page. /// - public int? PageSize { get; init; } + public int? PageSize { get; set; } /// /// If provided, will only return employees for this pay group /// - public string? PayGroupId { get; init; } + public string? PayGroupId { get; set; } /// /// If provided, will only return Employees with this personal email /// - public string? PersonalEmail { get; init; } + public string? PersonalEmail { get; set; } /// /// Deprecated. Use show_enum_origins. /// - public EmployeesListRequestRemoteFields? RemoteFields { get; init; } + public EmployeesListRequestRemoteFields? RemoteFields { get; set; } /// /// The API provider's ID for the given object. /// - public string? RemoteId { get; init; } + public string? RemoteId { get; set; } /// /// A comma separated list of enum field names for which you'd like the original values to be returned, instead of Merge's normalized enum values. [Learn more](https://help.merge.dev/en/articles/8950958-show_enum_origins-query-parameter) /// - public EmployeesListRequestShowEnumOrigins? ShowEnumOrigins { get; init; } + public EmployeesListRequestShowEnumOrigins? ShowEnumOrigins { get; set; } /// /// If provided, will only return employees that started after this datetime. /// - public DateTime? StartedAfter { get; init; } + public DateTime? StartedAfter { get; set; } /// /// If provided, will only return employees that started before this datetime. /// - public DateTime? StartedBefore { get; init; } + public DateTime? StartedBefore { get; set; } /// /// If provided, will only return employees for this team. /// - public string? TeamId { get; init; } + public string? TeamId { get; set; } /// /// If provided, will only return employees that were terminated after this datetime. /// - public DateTime? TerminatedAfter { get; init; } + public DateTime? TerminatedAfter { get; set; } /// /// If provided, will only return employees that were terminated before this datetime. /// - public DateTime? TerminatedBefore { get; init; } + public DateTime? TerminatedBefore { get; set; } /// /// If provided, will only return Employees with this work email /// - public string? WorkEmail { get; init; } + public string? WorkEmail { get; set; } /// /// If provided, will only return employees for this location. /// - public string? WorkLocationId { get; init; } + public string? WorkLocationId { get; set; } } diff --git a/src/Merge.Client/Hris/Employees/Requests/EmployeesRetrieveRequest.cs b/src/Merge.Client/Hris/Employees/Requests/EmployeesRetrieveRequest.cs index 502bc16a..9d5224f1 100644 --- a/src/Merge.Client/Hris/Employees/Requests/EmployeesRetrieveRequest.cs +++ b/src/Merge.Client/Hris/Employees/Requests/EmployeesRetrieveRequest.cs @@ -1,33 +1,29 @@ -using Merge.Client.Hris; - -#nullable enable - namespace Merge.Client.Hris; -public class EmployeesRetrieveRequest +public record EmployeesRetrieveRequest { /// /// Which relations should be returned in expanded form. Multiple relation names should be comma separated without spaces. /// - public EmployeesRetrieveRequestExpand? Expand { get; init; } + public EmployeesRetrieveRequestExpand? Expand { get; set; } /// /// Whether to include the original data Merge fetched from the third-party to produce these models. /// - public bool? IncludeRemoteData { get; init; } + public bool? IncludeRemoteData { get; set; } /// /// Whether to include sensitive fields (such as social security numbers) in the response. /// - public bool? IncludeSensitiveFields { get; init; } + public bool? IncludeSensitiveFields { get; set; } /// /// Deprecated. Use show_enum_origins. /// - public EmployeesRetrieveRequestRemoteFields? RemoteFields { get; init; } + public EmployeesRetrieveRequestRemoteFields? RemoteFields { get; set; } /// /// A comma separated list of enum field names for which you'd like the original values to be returned, instead of Merge's normalized enum values. [Learn more](https://help.merge.dev/en/articles/8950958-show_enum_origins-query-parameter) /// - public EmployeesRetrieveRequestShowEnumOrigins? ShowEnumOrigins { get; init; } + public EmployeesRetrieveRequestShowEnumOrigins? ShowEnumOrigins { get; set; } } diff --git a/src/Merge.Client/Hris/Employees/Requests/IgnoreCommonModelRequest.cs b/src/Merge.Client/Hris/Employees/Requests/IgnoreCommonModelRequest.cs index 2a7ad773..2c3e5f18 100644 --- a/src/Merge.Client/Hris/Employees/Requests/IgnoreCommonModelRequest.cs +++ b/src/Merge.Client/Hris/Employees/Requests/IgnoreCommonModelRequest.cs @@ -1,15 +1,14 @@ using System.Text.Json.Serialization; -using Merge.Client.Hris; #nullable enable namespace Merge.Client.Hris; -public class IgnoreCommonModelRequest +public record IgnoreCommonModelRequest { [JsonPropertyName("reason")] - public ReasonEnum Reason { get; init; } + public required ReasonEnum Reason { get; set; } [JsonPropertyName("message")] - public string? Message { get; init; } + public string? Message { get; set; } } diff --git a/src/Merge.Client/Hris/Employees/Types/EmployeesListRequestEmploymentStatus.cs b/src/Merge.Client/Hris/Employees/Types/EmployeesListRequestEmploymentStatus.cs index 5081273d..d79a0edd 100644 --- a/src/Merge.Client/Hris/Employees/Types/EmployeesListRequestEmploymentStatus.cs +++ b/src/Merge.Client/Hris/Employees/Types/EmployeesListRequestEmploymentStatus.cs @@ -1,7 +1,6 @@ using System.Runtime.Serialization; using System.Text.Json.Serialization; using Merge.Client.Core; -using Merge.Client.Hris; #nullable enable diff --git a/src/Merge.Client/Hris/Employees/Types/EmployeesListRequestExpand.cs b/src/Merge.Client/Hris/Employees/Types/EmployeesListRequestExpand.cs index 182fa5a7..3a897937 100644 --- a/src/Merge.Client/Hris/Employees/Types/EmployeesListRequestExpand.cs +++ b/src/Merge.Client/Hris/Employees/Types/EmployeesListRequestExpand.cs @@ -1,7 +1,6 @@ using System.Runtime.Serialization; using System.Text.Json.Serialization; using Merge.Client.Core; -using Merge.Client.Hris; #nullable enable diff --git a/src/Merge.Client/Hris/Employees/Types/EmployeesListRequestRemoteFields.cs b/src/Merge.Client/Hris/Employees/Types/EmployeesListRequestRemoteFields.cs index 39d79f29..1f38fa37 100644 --- a/src/Merge.Client/Hris/Employees/Types/EmployeesListRequestRemoteFields.cs +++ b/src/Merge.Client/Hris/Employees/Types/EmployeesListRequestRemoteFields.cs @@ -1,7 +1,6 @@ using System.Runtime.Serialization; using System.Text.Json.Serialization; using Merge.Client.Core; -using Merge.Client.Hris; #nullable enable diff --git a/src/Merge.Client/Hris/Employees/Types/EmployeesListRequestShowEnumOrigins.cs b/src/Merge.Client/Hris/Employees/Types/EmployeesListRequestShowEnumOrigins.cs index 839f0cf5..2e518d61 100644 --- a/src/Merge.Client/Hris/Employees/Types/EmployeesListRequestShowEnumOrigins.cs +++ b/src/Merge.Client/Hris/Employees/Types/EmployeesListRequestShowEnumOrigins.cs @@ -1,7 +1,6 @@ using System.Runtime.Serialization; using System.Text.Json.Serialization; using Merge.Client.Core; -using Merge.Client.Hris; #nullable enable diff --git a/src/Merge.Client/Hris/Employees/Types/EmployeesRetrieveRequestExpand.cs b/src/Merge.Client/Hris/Employees/Types/EmployeesRetrieveRequestExpand.cs index 218c79e6..23d8cebf 100644 --- a/src/Merge.Client/Hris/Employees/Types/EmployeesRetrieveRequestExpand.cs +++ b/src/Merge.Client/Hris/Employees/Types/EmployeesRetrieveRequestExpand.cs @@ -1,7 +1,6 @@ using System.Runtime.Serialization; using System.Text.Json.Serialization; using Merge.Client.Core; -using Merge.Client.Hris; #nullable enable diff --git a/src/Merge.Client/Hris/Employees/Types/EmployeesRetrieveRequestRemoteFields.cs b/src/Merge.Client/Hris/Employees/Types/EmployeesRetrieveRequestRemoteFields.cs index 4044aec3..a6b51886 100644 --- a/src/Merge.Client/Hris/Employees/Types/EmployeesRetrieveRequestRemoteFields.cs +++ b/src/Merge.Client/Hris/Employees/Types/EmployeesRetrieveRequestRemoteFields.cs @@ -1,7 +1,6 @@ using System.Runtime.Serialization; using System.Text.Json.Serialization; using Merge.Client.Core; -using Merge.Client.Hris; #nullable enable diff --git a/src/Merge.Client/Hris/Employees/Types/EmployeesRetrieveRequestShowEnumOrigins.cs b/src/Merge.Client/Hris/Employees/Types/EmployeesRetrieveRequestShowEnumOrigins.cs index 672072ba..f9e4dfb4 100644 --- a/src/Merge.Client/Hris/Employees/Types/EmployeesRetrieveRequestShowEnumOrigins.cs +++ b/src/Merge.Client/Hris/Employees/Types/EmployeesRetrieveRequestShowEnumOrigins.cs @@ -1,7 +1,6 @@ using System.Runtime.Serialization; using System.Text.Json.Serialization; using Merge.Client.Core; -using Merge.Client.Hris; #nullable enable diff --git a/src/Merge.Client/Hris/EmployerBenefits/EmployerBenefitsClient.cs b/src/Merge.Client/Hris/EmployerBenefits/EmployerBenefitsClient.cs index 802c5963..c028e719 100644 --- a/src/Merge.Client/Hris/EmployerBenefits/EmployerBenefitsClient.cs +++ b/src/Merge.Client/Hris/EmployerBenefits/EmployerBenefitsClient.cs @@ -1,6 +1,6 @@ +using System.Net.Http; using System.Text.Json; -using Merge.Client; -using Merge.Client.Hris; +using Merge.Client.Core; #nullable enable @@ -18,16 +18,21 @@ public EmployerBenefitsClient(RawClient client) /// /// Returns a list of `EmployerBenefit` objects. /// - public async Task ListAsync(EmployerBenefitsListRequest request) + public async Task ListAsync( + EmployerBenefitsListRequest request, + RequestOptions? options = null + ) { var _query = new Dictionary() { }; if (request.CreatedAfter != null) { - _query["created_after"] = request.CreatedAfter.Value.ToString("o0"); + _query["created_after"] = request.CreatedAfter.Value.ToString(Constants.DateTimeFormat); } if (request.CreatedBefore != null) { - _query["created_before"] = request.CreatedBefore.Value.ToString("o0"); + _query["created_before"] = request.CreatedBefore.Value.ToString( + Constants.DateTimeFormat + ); } if (request.Cursor != null) { @@ -43,11 +48,15 @@ public async Task ListAsync(EmployerBenefitsListRe } if (request.ModifiedAfter != null) { - _query["modified_after"] = request.ModifiedAfter.Value.ToString("o0"); + _query["modified_after"] = request.ModifiedAfter.Value.ToString( + Constants.DateTimeFormat + ); } if (request.ModifiedBefore != null) { - _query["modified_before"] = request.ModifiedBefore.Value.ToString("o0"); + _query["modified_before"] = request.ModifiedBefore.Value.ToString( + Constants.DateTimeFormat + ); } if (request.PageSize != null) { @@ -60,17 +69,31 @@ public async Task ListAsync(EmployerBenefitsListRe var response = await _client.MakeRequestAsync( new RawClient.JsonApiRequest { + BaseUrl = _client.Options.BaseUrl, Method = HttpMethod.Get, Path = "hris/v1/employer-benefits", - Query = _query + Query = _query, + Options = options } ); - string responseBody = await response.Raw.Content.ReadAsStringAsync(); - if (response.StatusCode >= 200 && response.StatusCode < 400) + var responseBody = await response.Raw.Content.ReadAsStringAsync(); + if (response.StatusCode is >= 200 and < 400) { - return JsonSerializer.Deserialize(responseBody); + try + { + return JsonUtils.Deserialize(responseBody)!; + } + catch (JsonException e) + { + throw new MergeException("Failed to deserialize response", e); + } } - throw new Exception(responseBody); + + throw new MergeApiException( + $"Error with status code {response.StatusCode}", + response.StatusCode, + JsonUtils.Deserialize(responseBody) + ); } /// @@ -78,7 +101,8 @@ public async Task ListAsync(EmployerBenefitsListRe /// public async Task RetrieveAsync( string id, - EmployerBenefitsRetrieveRequest request + EmployerBenefitsRetrieveRequest request, + RequestOptions? options = null ) { var _query = new Dictionary() { }; @@ -89,16 +113,30 @@ EmployerBenefitsRetrieveRequest request var response = await _client.MakeRequestAsync( new RawClient.JsonApiRequest { + BaseUrl = _client.Options.BaseUrl, Method = HttpMethod.Get, Path = $"hris/v1/employer-benefits/{id}", - Query = _query + Query = _query, + Options = options } ); - string responseBody = await response.Raw.Content.ReadAsStringAsync(); - if (response.StatusCode >= 200 && response.StatusCode < 400) + var responseBody = await response.Raw.Content.ReadAsStringAsync(); + if (response.StatusCode is >= 200 and < 400) { - return JsonSerializer.Deserialize(responseBody); + try + { + return JsonUtils.Deserialize(responseBody)!; + } + catch (JsonException e) + { + throw new MergeException("Failed to deserialize response", e); + } } - throw new Exception(responseBody); + + throw new MergeApiException( + $"Error with status code {response.StatusCode}", + response.StatusCode, + JsonUtils.Deserialize(responseBody) + ); } } diff --git a/src/Merge.Client/Hris/EmployerBenefits/Requests/EmployerBenefitsListRequest.cs b/src/Merge.Client/Hris/EmployerBenefits/Requests/EmployerBenefitsListRequest.cs index 145175a2..cc7e6e22 100644 --- a/src/Merge.Client/Hris/EmployerBenefits/Requests/EmployerBenefitsListRequest.cs +++ b/src/Merge.Client/Hris/EmployerBenefits/Requests/EmployerBenefitsListRequest.cs @@ -1,49 +1,49 @@ namespace Merge.Client.Hris; -public class EmployerBenefitsListRequest +public record EmployerBenefitsListRequest { /// /// If provided, will only return objects created after this datetime. /// - public DateTime? CreatedAfter { get; init; } + public DateTime? CreatedAfter { get; set; } /// /// If provided, will only return objects created before this datetime. /// - public DateTime? CreatedBefore { get; init; } + public DateTime? CreatedBefore { get; set; } /// /// The pagination cursor value. /// - public string? Cursor { get; init; } + public string? Cursor { get; set; } /// /// Whether to include data that was marked as deleted by third party webhooks. /// - public bool? IncludeDeletedData { get; init; } + public bool? IncludeDeletedData { get; set; } /// /// Whether to include the original data Merge fetched from the third-party to produce these models. /// - public bool? IncludeRemoteData { get; init; } + public bool? IncludeRemoteData { get; set; } /// /// If provided, only objects synced by Merge after this date time will be returned. /// - public DateTime? ModifiedAfter { get; init; } + public DateTime? ModifiedAfter { get; set; } /// /// If provided, only objects synced by Merge before this date time will be returned. /// - public DateTime? ModifiedBefore { get; init; } + public DateTime? ModifiedBefore { get; set; } /// /// Number of results to return per page. /// - public int? PageSize { get; init; } + public int? PageSize { get; set; } /// /// The API provider's ID for the given object. /// - public string? RemoteId { get; init; } + public string? RemoteId { get; set; } } diff --git a/src/Merge.Client/Hris/EmployerBenefits/Requests/EmployerBenefitsRetrieveRequest.cs b/src/Merge.Client/Hris/EmployerBenefits/Requests/EmployerBenefitsRetrieveRequest.cs index c2a72493..0868ae54 100644 --- a/src/Merge.Client/Hris/EmployerBenefits/Requests/EmployerBenefitsRetrieveRequest.cs +++ b/src/Merge.Client/Hris/EmployerBenefits/Requests/EmployerBenefitsRetrieveRequest.cs @@ -1,9 +1,9 @@ namespace Merge.Client.Hris; -public class EmployerBenefitsRetrieveRequest +public record EmployerBenefitsRetrieveRequest { /// /// Whether to include the original data Merge fetched from the third-party to produce these models. /// - public bool? IncludeRemoteData { get; init; } + public bool? IncludeRemoteData { get; set; } } diff --git a/src/Merge.Client/Hris/Employments/EmploymentsClient.cs b/src/Merge.Client/Hris/Employments/EmploymentsClient.cs index d4e78ff1..be509513 100644 --- a/src/Merge.Client/Hris/Employments/EmploymentsClient.cs +++ b/src/Merge.Client/Hris/Employments/EmploymentsClient.cs @@ -1,6 +1,6 @@ +using System.Net.Http; using System.Text.Json; -using Merge.Client; -using Merge.Client.Hris; +using Merge.Client.Core; #nullable enable @@ -18,16 +18,21 @@ public EmploymentsClient(RawClient client) /// /// Returns a list of `Employment` objects. /// - public async Task ListAsync(EmploymentsListRequest request) + public async Task ListAsync( + EmploymentsListRequest request, + RequestOptions? options = null + ) { var _query = new Dictionary() { }; if (request.CreatedAfter != null) { - _query["created_after"] = request.CreatedAfter.Value.ToString("o0"); + _query["created_after"] = request.CreatedAfter.Value.ToString(Constants.DateTimeFormat); } if (request.CreatedBefore != null) { - _query["created_before"] = request.CreatedBefore.Value.ToString("o0"); + _query["created_before"] = request.CreatedBefore.Value.ToString( + Constants.DateTimeFormat + ); } if (request.Cursor != null) { @@ -51,11 +56,15 @@ public async Task ListAsync(EmploymentsListRequest requ } if (request.ModifiedAfter != null) { - _query["modified_after"] = request.ModifiedAfter.Value.ToString("o0"); + _query["modified_after"] = request.ModifiedAfter.Value.ToString( + Constants.DateTimeFormat + ); } if (request.ModifiedBefore != null) { - _query["modified_before"] = request.ModifiedBefore.Value.ToString("o0"); + _query["modified_before"] = request.ModifiedBefore.Value.ToString( + Constants.DateTimeFormat + ); } if (request.OrderBy != null) { @@ -80,23 +89,41 @@ public async Task ListAsync(EmploymentsListRequest requ var response = await _client.MakeRequestAsync( new RawClient.JsonApiRequest { + BaseUrl = _client.Options.BaseUrl, Method = HttpMethod.Get, Path = "hris/v1/employments", - Query = _query + Query = _query, + Options = options } ); - string responseBody = await response.Raw.Content.ReadAsStringAsync(); - if (response.StatusCode >= 200 && response.StatusCode < 400) + var responseBody = await response.Raw.Content.ReadAsStringAsync(); + if (response.StatusCode is >= 200 and < 400) { - return JsonSerializer.Deserialize(responseBody); + try + { + return JsonUtils.Deserialize(responseBody)!; + } + catch (JsonException e) + { + throw new MergeException("Failed to deserialize response", e); + } } - throw new Exception(responseBody); + + throw new MergeApiException( + $"Error with status code {response.StatusCode}", + response.StatusCode, + JsonUtils.Deserialize(responseBody) + ); } /// /// Returns an `Employment` object with the given `id`. /// - public async Task RetrieveAsync(string id, EmploymentsRetrieveRequest request) + public async Task RetrieveAsync( + string id, + EmploymentsRetrieveRequest request, + RequestOptions? options = null + ) { var _query = new Dictionary() { }; if (request.Expand != null) @@ -118,16 +145,30 @@ public async Task RetrieveAsync(string id, EmploymentsRetrieveReques var response = await _client.MakeRequestAsync( new RawClient.JsonApiRequest { + BaseUrl = _client.Options.BaseUrl, Method = HttpMethod.Get, Path = $"hris/v1/employments/{id}", - Query = _query + Query = _query, + Options = options } ); - string responseBody = await response.Raw.Content.ReadAsStringAsync(); - if (response.StatusCode >= 200 && response.StatusCode < 400) + var responseBody = await response.Raw.Content.ReadAsStringAsync(); + if (response.StatusCode is >= 200 and < 400) { - return JsonSerializer.Deserialize(responseBody); + try + { + return JsonUtils.Deserialize(responseBody)!; + } + catch (JsonException e) + { + throw new MergeException("Failed to deserialize response", e); + } } - throw new Exception(responseBody); + + throw new MergeApiException( + $"Error with status code {response.StatusCode}", + response.StatusCode, + JsonUtils.Deserialize(responseBody) + ); } } diff --git a/src/Merge.Client/Hris/Employments/Requests/EmploymentsListRequest.cs b/src/Merge.Client/Hris/Employments/Requests/EmploymentsListRequest.cs index fb5f8229..96e2a12c 100644 --- a/src/Merge.Client/Hris/Employments/Requests/EmploymentsListRequest.cs +++ b/src/Merge.Client/Hris/Employments/Requests/EmploymentsListRequest.cs @@ -1,78 +1,74 @@ -using Merge.Client.Hris; - -#nullable enable - namespace Merge.Client.Hris; -public class EmploymentsListRequest +public record EmploymentsListRequest { /// /// If provided, will only return objects created after this datetime. /// - public DateTime? CreatedAfter { get; init; } + public DateTime? CreatedAfter { get; set; } /// /// If provided, will only return objects created before this datetime. /// - public DateTime? CreatedBefore { get; init; } + public DateTime? CreatedBefore { get; set; } /// /// The pagination cursor value. /// - public string? Cursor { get; init; } + public string? Cursor { get; set; } /// /// If provided, will only return employments for this employee. /// - public string? EmployeeId { get; init; } + public string? EmployeeId { get; set; } /// /// Which relations should be returned in expanded form. Multiple relation names should be comma separated without spaces. /// - public EmploymentsListRequestExpand? Expand { get; init; } + public EmploymentsListRequestExpand? Expand { get; set; } /// /// Whether to include data that was marked as deleted by third party webhooks. /// - public bool? IncludeDeletedData { get; init; } + public bool? IncludeDeletedData { get; set; } /// /// Whether to include the original data Merge fetched from the third-party to produce these models. /// - public bool? IncludeRemoteData { get; init; } + public bool? IncludeRemoteData { get; set; } /// /// If provided, only objects synced by Merge after this date time will be returned. /// - public DateTime? ModifiedAfter { get; init; } + public DateTime? ModifiedAfter { get; set; } /// /// If provided, only objects synced by Merge before this date time will be returned. /// - public DateTime? ModifiedBefore { get; init; } + public DateTime? ModifiedBefore { get; set; } /// /// Overrides the default ordering for this endpoint. Possible values include: effective_date, -effective_date. /// - public EmploymentsListRequestOrderBy? OrderBy { get; init; } + public EmploymentsListRequestOrderBy? OrderBy { get; set; } /// /// Number of results to return per page. /// - public int? PageSize { get; init; } + public int? PageSize { get; set; } /// /// Deprecated. Use show_enum_origins. /// - public EmploymentsListRequestRemoteFields? RemoteFields { get; init; } + public EmploymentsListRequestRemoteFields? RemoteFields { get; set; } /// /// The API provider's ID for the given object. /// - public string? RemoteId { get; init; } + public string? RemoteId { get; set; } /// /// A comma separated list of enum field names for which you'd like the original values to be returned, instead of Merge's normalized enum values. [Learn more](https://help.merge.dev/en/articles/8950958-show_enum_origins-query-parameter) /// - public EmploymentsListRequestShowEnumOrigins? ShowEnumOrigins { get; init; } + public EmploymentsListRequestShowEnumOrigins? ShowEnumOrigins { get; set; } } diff --git a/src/Merge.Client/Hris/Employments/Requests/EmploymentsRetrieveRequest.cs b/src/Merge.Client/Hris/Employments/Requests/EmploymentsRetrieveRequest.cs index 004dfebd..b0a05754 100644 --- a/src/Merge.Client/Hris/Employments/Requests/EmploymentsRetrieveRequest.cs +++ b/src/Merge.Client/Hris/Employments/Requests/EmploymentsRetrieveRequest.cs @@ -1,28 +1,24 @@ -using Merge.Client.Hris; - -#nullable enable - namespace Merge.Client.Hris; -public class EmploymentsRetrieveRequest +public record EmploymentsRetrieveRequest { /// /// Which relations should be returned in expanded form. Multiple relation names should be comma separated without spaces. /// - public EmploymentsRetrieveRequestExpand? Expand { get; init; } + public EmploymentsRetrieveRequestExpand? Expand { get; set; } /// /// Whether to include the original data Merge fetched from the third-party to produce these models. /// - public bool? IncludeRemoteData { get; init; } + public bool? IncludeRemoteData { get; set; } /// /// Deprecated. Use show_enum_origins. /// - public EmploymentsRetrieveRequestRemoteFields? RemoteFields { get; init; } + public EmploymentsRetrieveRequestRemoteFields? RemoteFields { get; set; } /// /// A comma separated list of enum field names for which you'd like the original values to be returned, instead of Merge's normalized enum values. [Learn more](https://help.merge.dev/en/articles/8950958-show_enum_origins-query-parameter) /// - public EmploymentsRetrieveRequestShowEnumOrigins? ShowEnumOrigins { get; init; } + public EmploymentsRetrieveRequestShowEnumOrigins? ShowEnumOrigins { get; set; } } diff --git a/src/Merge.Client/Hris/Employments/Types/EmploymentsListRequestExpand.cs b/src/Merge.Client/Hris/Employments/Types/EmploymentsListRequestExpand.cs index fec582ce..1b36658d 100644 --- a/src/Merge.Client/Hris/Employments/Types/EmploymentsListRequestExpand.cs +++ b/src/Merge.Client/Hris/Employments/Types/EmploymentsListRequestExpand.cs @@ -1,7 +1,6 @@ using System.Runtime.Serialization; using System.Text.Json.Serialization; using Merge.Client.Core; -using Merge.Client.Hris; #nullable enable diff --git a/src/Merge.Client/Hris/Employments/Types/EmploymentsListRequestOrderBy.cs b/src/Merge.Client/Hris/Employments/Types/EmploymentsListRequestOrderBy.cs index 57ff60a8..e65bc8c3 100644 --- a/src/Merge.Client/Hris/Employments/Types/EmploymentsListRequestOrderBy.cs +++ b/src/Merge.Client/Hris/Employments/Types/EmploymentsListRequestOrderBy.cs @@ -1,7 +1,6 @@ using System.Runtime.Serialization; using System.Text.Json.Serialization; using Merge.Client.Core; -using Merge.Client.Hris; #nullable enable diff --git a/src/Merge.Client/Hris/Employments/Types/EmploymentsListRequestRemoteFields.cs b/src/Merge.Client/Hris/Employments/Types/EmploymentsListRequestRemoteFields.cs index e51012b0..86a0ba6c 100644 --- a/src/Merge.Client/Hris/Employments/Types/EmploymentsListRequestRemoteFields.cs +++ b/src/Merge.Client/Hris/Employments/Types/EmploymentsListRequestRemoteFields.cs @@ -1,7 +1,6 @@ using System.Runtime.Serialization; using System.Text.Json.Serialization; using Merge.Client.Core; -using Merge.Client.Hris; #nullable enable diff --git a/src/Merge.Client/Hris/Employments/Types/EmploymentsListRequestShowEnumOrigins.cs b/src/Merge.Client/Hris/Employments/Types/EmploymentsListRequestShowEnumOrigins.cs index abe85e9a..a4234c82 100644 --- a/src/Merge.Client/Hris/Employments/Types/EmploymentsListRequestShowEnumOrigins.cs +++ b/src/Merge.Client/Hris/Employments/Types/EmploymentsListRequestShowEnumOrigins.cs @@ -1,7 +1,6 @@ using System.Runtime.Serialization; using System.Text.Json.Serialization; using Merge.Client.Core; -using Merge.Client.Hris; #nullable enable diff --git a/src/Merge.Client/Hris/Employments/Types/EmploymentsRetrieveRequestExpand.cs b/src/Merge.Client/Hris/Employments/Types/EmploymentsRetrieveRequestExpand.cs index a0219888..44a88112 100644 --- a/src/Merge.Client/Hris/Employments/Types/EmploymentsRetrieveRequestExpand.cs +++ b/src/Merge.Client/Hris/Employments/Types/EmploymentsRetrieveRequestExpand.cs @@ -1,7 +1,6 @@ using System.Runtime.Serialization; using System.Text.Json.Serialization; using Merge.Client.Core; -using Merge.Client.Hris; #nullable enable diff --git a/src/Merge.Client/Hris/Employments/Types/EmploymentsRetrieveRequestRemoteFields.cs b/src/Merge.Client/Hris/Employments/Types/EmploymentsRetrieveRequestRemoteFields.cs index 000ef280..e2ea21dc 100644 --- a/src/Merge.Client/Hris/Employments/Types/EmploymentsRetrieveRequestRemoteFields.cs +++ b/src/Merge.Client/Hris/Employments/Types/EmploymentsRetrieveRequestRemoteFields.cs @@ -1,7 +1,6 @@ using System.Runtime.Serialization; using System.Text.Json.Serialization; using Merge.Client.Core; -using Merge.Client.Hris; #nullable enable diff --git a/src/Merge.Client/Hris/Employments/Types/EmploymentsRetrieveRequestShowEnumOrigins.cs b/src/Merge.Client/Hris/Employments/Types/EmploymentsRetrieveRequestShowEnumOrigins.cs index 2b340296..0ea01fe0 100644 --- a/src/Merge.Client/Hris/Employments/Types/EmploymentsRetrieveRequestShowEnumOrigins.cs +++ b/src/Merge.Client/Hris/Employments/Types/EmploymentsRetrieveRequestShowEnumOrigins.cs @@ -1,7 +1,6 @@ using System.Runtime.Serialization; using System.Text.Json.Serialization; using Merge.Client.Core; -using Merge.Client.Hris; #nullable enable diff --git a/src/Merge.Client/Hris/FieldMapping/FieldMappingClient.cs b/src/Merge.Client/Hris/FieldMapping/FieldMappingClient.cs index b0940db6..29282833 100644 --- a/src/Merge.Client/Hris/FieldMapping/FieldMappingClient.cs +++ b/src/Merge.Client/Hris/FieldMapping/FieldMappingClient.cs @@ -1,6 +1,6 @@ +using System.Net.Http; using System.Text.Json; -using Merge.Client; -using Merge.Client.Hris; +using Merge.Client.Core; #nullable enable @@ -18,64 +18,112 @@ public FieldMappingClient(RawClient client) /// /// Get all Field Mappings for this Linked Account. Field Mappings are mappings between third-party Remote Fields and user defined Merge fields. [Learn more](https://docs.merge.dev/supplemental-data/field-mappings/overview/). /// - public async Task FieldMappingsRetrieveAsync() + public async Task FieldMappingsRetrieveAsync( + RequestOptions? options = null + ) { var response = await _client.MakeRequestAsync( new RawClient.JsonApiRequest { + BaseUrl = _client.Options.BaseUrl, Method = HttpMethod.Get, - Path = "hris/v1/field-mappings" + Path = "hris/v1/field-mappings", + Options = options } ); - string responseBody = await response.Raw.Content.ReadAsStringAsync(); - if (response.StatusCode >= 200 && response.StatusCode < 400) + var responseBody = await response.Raw.Content.ReadAsStringAsync(); + if (response.StatusCode is >= 200 and < 400) { - return JsonSerializer.Deserialize(responseBody); + try + { + return JsonUtils.Deserialize(responseBody)!; + } + catch (JsonException e) + { + throw new MergeException("Failed to deserialize response", e); + } } - throw new Exception(responseBody); + + throw new MergeApiException( + $"Error with status code {response.StatusCode}", + response.StatusCode, + JsonUtils.Deserialize(responseBody) + ); } /// /// Create new Field Mappings that will be available after the next scheduled sync. This will cause the next sync for this Linked Account to sync **ALL** data from start. /// public async Task FieldMappingsCreateAsync( - CreateFieldMappingRequest request + CreateFieldMappingRequest request, + RequestOptions? options = null ) { var response = await _client.MakeRequestAsync( new RawClient.JsonApiRequest { + BaseUrl = _client.Options.BaseUrl, Method = HttpMethod.Post, Path = "hris/v1/field-mappings", - Body = request + Body = request, + Options = options } ); - string responseBody = await response.Raw.Content.ReadAsStringAsync(); - if (response.StatusCode >= 200 && response.StatusCode < 400) + var responseBody = await response.Raw.Content.ReadAsStringAsync(); + if (response.StatusCode is >= 200 and < 400) { - return JsonSerializer.Deserialize(responseBody); + try + { + return JsonUtils.Deserialize(responseBody)!; + } + catch (JsonException e) + { + throw new MergeException("Failed to deserialize response", e); + } } - throw new Exception(responseBody); + + throw new MergeApiException( + $"Error with status code {response.StatusCode}", + response.StatusCode, + JsonUtils.Deserialize(responseBody) + ); } /// /// Deletes Field Mappings for a Linked Account. All data related to this Field Mapping will be deleted and these changes will be reflected after the next scheduled sync. This will cause the next sync for this Linked Account to sync **ALL** data from start. /// - public async Task FieldMappingsDestroyAsync(string fieldMappingId) + public async Task FieldMappingsDestroyAsync( + string fieldMappingId, + RequestOptions? options = null + ) { var response = await _client.MakeRequestAsync( new RawClient.JsonApiRequest { + BaseUrl = _client.Options.BaseUrl, Method = HttpMethod.Delete, - Path = $"hris/v1/field-mappings/{fieldMappingId}" + Path = $"hris/v1/field-mappings/{fieldMappingId}", + Options = options } ); - string responseBody = await response.Raw.Content.ReadAsStringAsync(); - if (response.StatusCode >= 200 && response.StatusCode < 400) + var responseBody = await response.Raw.Content.ReadAsStringAsync(); + if (response.StatusCode is >= 200 and < 400) { - return JsonSerializer.Deserialize(responseBody); + try + { + return JsonUtils.Deserialize(responseBody)!; + } + catch (JsonException e) + { + throw new MergeException("Failed to deserialize response", e); + } } - throw new Exception(responseBody); + + throw new MergeApiException( + $"Error with status code {response.StatusCode}", + response.StatusCode, + JsonUtils.Deserialize(responseBody) + ); } /// @@ -83,30 +131,46 @@ public async Task FieldMappingsDestroyAsync(string /// public async Task FieldMappingsPartialUpdateAsync( string fieldMappingId, - PatchedEditFieldMappingRequest request + PatchedEditFieldMappingRequest request, + RequestOptions? options = null ) { var response = await _client.MakeRequestAsync( new RawClient.JsonApiRequest { - Method = HttpMethod.Patch, + BaseUrl = _client.Options.BaseUrl, + Method = HttpMethodExtensions.Patch, Path = $"hris/v1/field-mappings/{fieldMappingId}", - Body = request + Body = request, + Options = options } ); - string responseBody = await response.Raw.Content.ReadAsStringAsync(); - if (response.StatusCode >= 200 && response.StatusCode < 400) + var responseBody = await response.Raw.Content.ReadAsStringAsync(); + if (response.StatusCode is >= 200 and < 400) { - return JsonSerializer.Deserialize(responseBody); + try + { + return JsonUtils.Deserialize(responseBody)!; + } + catch (JsonException e) + { + throw new MergeException("Failed to deserialize response", e); + } } - throw new Exception(responseBody); + + throw new MergeApiException( + $"Error with status code {response.StatusCode}", + response.StatusCode, + JsonUtils.Deserialize(responseBody) + ); } /// /// Get all remote fields for a Linked Account. Remote fields are third-party fields that are accessible after initial sync if remote_data is enabled. You can use remote fields to override existing Merge fields or map a new Merge field. [Learn more](https://docs.merge.dev/supplemental-data/field-mappings/overview/). /// public async Task RemoteFieldsRetrieveAsync( - RemoteFieldsRetrieveRequest request + RemoteFieldsRetrieveRequest request, + RequestOptions? options = null ) { var _query = new Dictionary() { }; @@ -121,32 +185,66 @@ RemoteFieldsRetrieveRequest request var response = await _client.MakeRequestAsync( new RawClient.JsonApiRequest { + BaseUrl = _client.Options.BaseUrl, Method = HttpMethod.Get, Path = "hris/v1/remote-fields", - Query = _query + Query = _query, + Options = options } ); - string responseBody = await response.Raw.Content.ReadAsStringAsync(); - if (response.StatusCode >= 200 && response.StatusCode < 400) + var responseBody = await response.Raw.Content.ReadAsStringAsync(); + if (response.StatusCode is >= 200 and < 400) { - return JsonSerializer.Deserialize(responseBody); + try + { + return JsonUtils.Deserialize(responseBody)!; + } + catch (JsonException e) + { + throw new MergeException("Failed to deserialize response", e); + } } - throw new Exception(responseBody); + + throw new MergeApiException( + $"Error with status code {response.StatusCode}", + response.StatusCode, + JsonUtils.Deserialize(responseBody) + ); } /// /// Get all organization-wide Target Fields, this will not include any Linked Account specific Target Fields. Organization-wide Target Fields are additional fields appended to the Merge Common Model for all Linked Accounts in a category. [Learn more](https://docs.merge.dev/supplemental-data/field-mappings/target-fields/). /// - public async Task TargetFieldsRetrieveAsync() + public async Task TargetFieldsRetrieveAsync( + RequestOptions? options = null + ) { var response = await _client.MakeRequestAsync( - new RawClient.JsonApiRequest { Method = HttpMethod.Get, Path = "hris/v1/target-fields" } + new RawClient.JsonApiRequest + { + BaseUrl = _client.Options.BaseUrl, + Method = HttpMethod.Get, + Path = "hris/v1/target-fields", + Options = options + } ); - string responseBody = await response.Raw.Content.ReadAsStringAsync(); - if (response.StatusCode >= 200 && response.StatusCode < 400) + var responseBody = await response.Raw.Content.ReadAsStringAsync(); + if (response.StatusCode is >= 200 and < 400) { - return JsonSerializer.Deserialize(responseBody); + try + { + return JsonUtils.Deserialize(responseBody)!; + } + catch (JsonException e) + { + throw new MergeException("Failed to deserialize response", e); + } } - throw new Exception(responseBody); + + throw new MergeApiException( + $"Error with status code {response.StatusCode}", + response.StatusCode, + JsonUtils.Deserialize(responseBody) + ); } } diff --git a/src/Merge.Client/Hris/FieldMapping/Requests/CreateFieldMappingRequest.cs b/src/Merge.Client/Hris/FieldMapping/Requests/CreateFieldMappingRequest.cs index f227a764..cfe23450 100644 --- a/src/Merge.Client/Hris/FieldMapping/Requests/CreateFieldMappingRequest.cs +++ b/src/Merge.Client/Hris/FieldMapping/Requests/CreateFieldMappingRequest.cs @@ -4,41 +4,41 @@ namespace Merge.Client.Hris; -public class CreateFieldMappingRequest +public record CreateFieldMappingRequest { /// /// The name of the target field you want this remote field to map to. /// [JsonPropertyName("target_field_name")] - public string TargetFieldName { get; init; } + public required string TargetFieldName { get; set; } /// /// The description of the target field you want this remote field to map to. /// [JsonPropertyName("target_field_description")] - public string TargetFieldDescription { get; init; } + public required string TargetFieldDescription { get; set; } /// /// The field traversal path of the remote field listed when you hit the GET /remote-fields endpoint. /// [JsonPropertyName("remote_field_traversal_path")] - public IEnumerable RemoteFieldTraversalPath { get; init; } + public IEnumerable RemoteFieldTraversalPath { get; set; } = new List(); /// /// The method of the remote endpoint where the remote field is coming from. /// [JsonPropertyName("remote_method")] - public string RemoteMethod { get; init; } + public required string RemoteMethod { get; set; } /// /// The path of the remote endpoint where the remote field is coming from. /// [JsonPropertyName("remote_url_path")] - public string RemoteUrlPath { get; init; } + public required string RemoteUrlPath { get; set; } /// /// The name of the Common Model that the remote field corresponds to in a given category. /// [JsonPropertyName("common_model_name")] - public string CommonModelName { get; init; } + public required string CommonModelName { get; set; } } diff --git a/src/Merge.Client/Hris/FieldMapping/Requests/PatchedEditFieldMappingRequest.cs b/src/Merge.Client/Hris/FieldMapping/Requests/PatchedEditFieldMappingRequest.cs index c8c9255f..3232dd3f 100644 --- a/src/Merge.Client/Hris/FieldMapping/Requests/PatchedEditFieldMappingRequest.cs +++ b/src/Merge.Client/Hris/FieldMapping/Requests/PatchedEditFieldMappingRequest.cs @@ -4,23 +4,23 @@ namespace Merge.Client.Hris; -public class PatchedEditFieldMappingRequest +public record PatchedEditFieldMappingRequest { /// /// The field traversal path of the remote field listed when you hit the GET /remote-fields endpoint. /// [JsonPropertyName("remote_field_traversal_path")] - public IEnumerable? RemoteFieldTraversalPath { get; init; } + public IEnumerable? RemoteFieldTraversalPath { get; set; } /// /// The method of the remote endpoint where the remote field is coming from. /// [JsonPropertyName("remote_method")] - public string? RemoteMethod { get; init; } + public string? RemoteMethod { get; set; } /// /// The path of the remote endpoint where the remote field is coming from. /// [JsonPropertyName("remote_url_path")] - public string? RemoteUrlPath { get; init; } + public string? RemoteUrlPath { get; set; } } diff --git a/src/Merge.Client/Hris/FieldMapping/Requests/RemoteFieldsRetrieveRequest.cs b/src/Merge.Client/Hris/FieldMapping/Requests/RemoteFieldsRetrieveRequest.cs index 10bd6cc8..6b22b59e 100644 --- a/src/Merge.Client/Hris/FieldMapping/Requests/RemoteFieldsRetrieveRequest.cs +++ b/src/Merge.Client/Hris/FieldMapping/Requests/RemoteFieldsRetrieveRequest.cs @@ -1,14 +1,14 @@ namespace Merge.Client.Hris; -public class RemoteFieldsRetrieveRequest +public record RemoteFieldsRetrieveRequest { /// /// A comma seperated list of Common Model names. If included, will only return Remote Fields for those Common Models. /// - public string? CommonModels { get; init; } + public string? CommonModels { get; set; } /// /// If true, will include example values, where available, for remote fields in the 3rd party platform. These examples come from active data from your customers. /// - public string? IncludeExampleValues { get; init; } + public string? IncludeExampleValues { get; set; } } diff --git a/src/Merge.Client/Hris/ForceResync/ForceResyncClient.cs b/src/Merge.Client/Hris/ForceResync/ForceResyncClient.cs index c58a1f5d..cb81dd96 100644 --- a/src/Merge.Client/Hris/ForceResync/ForceResyncClient.cs +++ b/src/Merge.Client/Hris/ForceResync/ForceResyncClient.cs @@ -1,6 +1,6 @@ +using System.Net.Http; using System.Text.Json; -using Merge.Client; -using Merge.Client.Hris; +using Merge.Client.Core; #nullable enable @@ -18,20 +18,36 @@ public ForceResyncClient(RawClient client) /// /// Force re-sync of all models. This is available for all organizations via the dashboard. Force re-sync is also available programmatically via API for monthly, quarterly, and highest sync frequency customers on the Launch, Professional, or Enterprise plans. Doing so will consume a sync credit for the relevant linked account. /// - public async Task> SyncStatusResyncCreateAsync() + public async Task> SyncStatusResyncCreateAsync( + RequestOptions? options = null + ) { var response = await _client.MakeRequestAsync( new RawClient.JsonApiRequest { + BaseUrl = _client.Options.BaseUrl, Method = HttpMethod.Post, - Path = "hris/v1/sync-status/resync" + Path = "hris/v1/sync-status/resync", + Options = options } ); - string responseBody = await response.Raw.Content.ReadAsStringAsync(); - if (response.StatusCode >= 200 && response.StatusCode < 400) + var responseBody = await response.Raw.Content.ReadAsStringAsync(); + if (response.StatusCode is >= 200 and < 400) { - return JsonSerializer.Deserialize>(responseBody); + try + { + return JsonUtils.Deserialize>(responseBody)!; + } + catch (JsonException e) + { + throw new MergeException("Failed to deserialize response", e); + } } - throw new Exception(responseBody); + + throw new MergeApiException( + $"Error with status code {response.StatusCode}", + response.StatusCode, + JsonUtils.Deserialize(responseBody) + ); } } diff --git a/src/Merge.Client/Hris/GenerateKey/GenerateKeyClient.cs b/src/Merge.Client/Hris/GenerateKey/GenerateKeyClient.cs index a60ef0ba..ca76b68e 100644 --- a/src/Merge.Client/Hris/GenerateKey/GenerateKeyClient.cs +++ b/src/Merge.Client/Hris/GenerateKey/GenerateKeyClient.cs @@ -1,6 +1,6 @@ +using System.Net.Http; using System.Text.Json; -using Merge.Client; -using Merge.Client.Hris; +using Merge.Client.Core; #nullable enable @@ -18,21 +18,38 @@ public GenerateKeyClient(RawClient client) /// /// Create a remote key. /// - public async Task CreateAsync(GenerateRemoteKeyRequest request) + public async Task CreateAsync( + GenerateRemoteKeyRequest request, + RequestOptions? options = null + ) { var response = await _client.MakeRequestAsync( new RawClient.JsonApiRequest { + BaseUrl = _client.Options.BaseUrl, Method = HttpMethod.Post, Path = "hris/v1/generate-key", - Body = request + Body = request, + Options = options } ); - string responseBody = await response.Raw.Content.ReadAsStringAsync(); - if (response.StatusCode >= 200 && response.StatusCode < 400) + var responseBody = await response.Raw.Content.ReadAsStringAsync(); + if (response.StatusCode is >= 200 and < 400) { - return JsonSerializer.Deserialize(responseBody); + try + { + return JsonUtils.Deserialize(responseBody)!; + } + catch (JsonException e) + { + throw new MergeException("Failed to deserialize response", e); + } } - throw new Exception(responseBody); + + throw new MergeApiException( + $"Error with status code {response.StatusCode}", + response.StatusCode, + JsonUtils.Deserialize(responseBody) + ); } } diff --git a/src/Merge.Client/Hris/GenerateKey/Requests/GenerateRemoteKeyRequest.cs b/src/Merge.Client/Hris/GenerateKey/Requests/GenerateRemoteKeyRequest.cs index 77e92907..c415f20c 100644 --- a/src/Merge.Client/Hris/GenerateKey/Requests/GenerateRemoteKeyRequest.cs +++ b/src/Merge.Client/Hris/GenerateKey/Requests/GenerateRemoteKeyRequest.cs @@ -4,11 +4,11 @@ namespace Merge.Client.Hris; -public class GenerateRemoteKeyRequest +public record GenerateRemoteKeyRequest { /// /// The name of the remote key /// [JsonPropertyName("name")] - public string Name { get; init; } + public required string Name { get; set; } } diff --git a/src/Merge.Client/Hris/Groups/GroupsClient.cs b/src/Merge.Client/Hris/Groups/GroupsClient.cs index 296ecb87..b97f86b0 100644 --- a/src/Merge.Client/Hris/Groups/GroupsClient.cs +++ b/src/Merge.Client/Hris/Groups/GroupsClient.cs @@ -1,6 +1,6 @@ +using System.Net.Http; using System.Text.Json; -using Merge.Client; -using Merge.Client.Hris; +using Merge.Client.Core; #nullable enable @@ -18,16 +18,21 @@ public GroupsClient(RawClient client) /// /// Returns a list of `Group` objects. /// - public async Task ListAsync(GroupsListRequest request) + public async Task ListAsync( + GroupsListRequest request, + RequestOptions? options = null + ) { var _query = new Dictionary() { }; if (request.CreatedAfter != null) { - _query["created_after"] = request.CreatedAfter.Value.ToString("o0"); + _query["created_after"] = request.CreatedAfter.Value.ToString(Constants.DateTimeFormat); } if (request.CreatedBefore != null) { - _query["created_before"] = request.CreatedBefore.Value.ToString("o0"); + _query["created_before"] = request.CreatedBefore.Value.ToString( + Constants.DateTimeFormat + ); } if (request.Cursor != null) { @@ -47,11 +52,15 @@ public async Task ListAsync(GroupsListRequest request) } if (request.ModifiedAfter != null) { - _query["modified_after"] = request.ModifiedAfter.Value.ToString("o0"); + _query["modified_after"] = request.ModifiedAfter.Value.ToString( + Constants.DateTimeFormat + ); } if (request.ModifiedBefore != null) { - _query["modified_before"] = request.ModifiedBefore.Value.ToString("o0"); + _query["modified_before"] = request.ModifiedBefore.Value.ToString( + Constants.DateTimeFormat + ); } if (request.Names != null) { @@ -80,23 +89,41 @@ public async Task ListAsync(GroupsListRequest request) var response = await _client.MakeRequestAsync( new RawClient.JsonApiRequest { + BaseUrl = _client.Options.BaseUrl, Method = HttpMethod.Get, Path = "hris/v1/groups", - Query = _query + Query = _query, + Options = options } ); - string responseBody = await response.Raw.Content.ReadAsStringAsync(); - if (response.StatusCode >= 200 && response.StatusCode < 400) + var responseBody = await response.Raw.Content.ReadAsStringAsync(); + if (response.StatusCode is >= 200 and < 400) { - return JsonSerializer.Deserialize(responseBody); + try + { + return JsonUtils.Deserialize(responseBody)!; + } + catch (JsonException e) + { + throw new MergeException("Failed to deserialize response", e); + } } - throw new Exception(responseBody); + + throw new MergeApiException( + $"Error with status code {response.StatusCode}", + response.StatusCode, + JsonUtils.Deserialize(responseBody) + ); } /// /// Returns a `Group` object with the given `id`. /// - public async Task RetrieveAsync(string id, GroupsRetrieveRequest request) + public async Task RetrieveAsync( + string id, + GroupsRetrieveRequest request, + RequestOptions? options = null + ) { var _query = new Dictionary() { }; if (request.IncludeRemoteData != null) @@ -114,16 +141,30 @@ public async Task RetrieveAsync(string id, GroupsRetrieveRequest request) var response = await _client.MakeRequestAsync( new RawClient.JsonApiRequest { + BaseUrl = _client.Options.BaseUrl, Method = HttpMethod.Get, Path = $"hris/v1/groups/{id}", - Query = _query + Query = _query, + Options = options } ); - string responseBody = await response.Raw.Content.ReadAsStringAsync(); - if (response.StatusCode >= 200 && response.StatusCode < 400) + var responseBody = await response.Raw.Content.ReadAsStringAsync(); + if (response.StatusCode is >= 200 and < 400) { - return JsonSerializer.Deserialize(responseBody); + try + { + return JsonUtils.Deserialize(responseBody)!; + } + catch (JsonException e) + { + throw new MergeException("Failed to deserialize response", e); + } } - throw new Exception(responseBody); + + throw new MergeApiException( + $"Error with status code {response.StatusCode}", + response.StatusCode, + JsonUtils.Deserialize(responseBody) + ); } } diff --git a/src/Merge.Client/Hris/Groups/Requests/GroupsListRequest.cs b/src/Merge.Client/Hris/Groups/Requests/GroupsListRequest.cs index a4cf8c7f..1007a9a2 100644 --- a/src/Merge.Client/Hris/Groups/Requests/GroupsListRequest.cs +++ b/src/Merge.Client/Hris/Groups/Requests/GroupsListRequest.cs @@ -1,74 +1,74 @@ namespace Merge.Client.Hris; -public class GroupsListRequest +public record GroupsListRequest { /// /// If provided, will only return objects created after this datetime. /// - public DateTime? CreatedAfter { get; init; } + public DateTime? CreatedAfter { get; set; } /// /// If provided, will only return objects created before this datetime. /// - public DateTime? CreatedBefore { get; init; } + public DateTime? CreatedBefore { get; set; } /// /// The pagination cursor value. /// - public string? Cursor { get; init; } + public string? Cursor { get; set; } /// /// Whether to include data that was marked as deleted by third party webhooks. /// - public bool? IncludeDeletedData { get; init; } + public bool? IncludeDeletedData { get; set; } /// /// Whether to include the original data Merge fetched from the third-party to produce these models. /// - public bool? IncludeRemoteData { get; init; } + public bool? IncludeRemoteData { get; set; } /// /// If provided, specifies whether to return only Group objects which refer to a team in the third party platform. Note that this is an opinionated view based on how a team may be represented in the third party platform. /// - public string? IsCommonlyUsedAsTeam { get; init; } + public string? IsCommonlyUsedAsTeam { get; set; } /// /// If provided, only objects synced by Merge after this date time will be returned. /// - public DateTime? ModifiedAfter { get; init; } + public DateTime? ModifiedAfter { get; set; } /// /// If provided, only objects synced by Merge before this date time will be returned. /// - public DateTime? ModifiedBefore { get; init; } + public DateTime? ModifiedBefore { get; set; } /// /// If provided, will only return groups with these names. Multiple values can be separated by commas. /// - public string? Names { get; init; } + public string? Names { get; set; } /// /// Number of results to return per page. /// - public int? PageSize { get; init; } + public int? PageSize { get; set; } /// /// Deprecated. Use show_enum_origins. /// - public string? RemoteFields { get; init; } + public string? RemoteFields { get; set; } /// /// The API provider's ID for the given object. /// - public string? RemoteId { get; init; } + public string? RemoteId { get; set; } /// /// A comma separated list of enum field names for which you'd like the original values to be returned, instead of Merge's normalized enum values. [Learn more](https://help.merge.dev/en/articles/8950958-show_enum_origins-query-parameter) /// - public string? ShowEnumOrigins { get; init; } + public string? ShowEnumOrigins { get; set; } /// /// If provided, will only return groups of these types. Multiple values can be separated by commas. /// - public string? Types { get; init; } + public string? Types { get; set; } } diff --git a/src/Merge.Client/Hris/Groups/Requests/GroupsRetrieveRequest.cs b/src/Merge.Client/Hris/Groups/Requests/GroupsRetrieveRequest.cs index ca9fc360..b2a78620 100644 --- a/src/Merge.Client/Hris/Groups/Requests/GroupsRetrieveRequest.cs +++ b/src/Merge.Client/Hris/Groups/Requests/GroupsRetrieveRequest.cs @@ -1,19 +1,19 @@ namespace Merge.Client.Hris; -public class GroupsRetrieveRequest +public record GroupsRetrieveRequest { /// /// Whether to include the original data Merge fetched from the third-party to produce these models. /// - public bool? IncludeRemoteData { get; init; } + public bool? IncludeRemoteData { get; set; } /// /// Deprecated. Use show_enum_origins. /// - public string? RemoteFields { get; init; } + public string? RemoteFields { get; set; } /// /// A comma separated list of enum field names for which you'd like the original values to be returned, instead of Merge's normalized enum values. [Learn more](https://help.merge.dev/en/articles/8950958-show_enum_origins-query-parameter) /// - public string? ShowEnumOrigins { get; init; } + public string? ShowEnumOrigins { get; set; } } diff --git a/src/Merge.Client/Hris/HrisClient.cs b/src/Merge.Client/Hris/HrisClient.cs index 00f436c4..83eb51ae 100644 --- a/src/Merge.Client/Hris/HrisClient.cs +++ b/src/Merge.Client/Hris/HrisClient.cs @@ -1,5 +1,4 @@ -using Merge.Client; -using Merge.Client.Hris; +using Merge.Client.Core; #nullable enable diff --git a/src/Merge.Client/Hris/Issues/IssuesClient.cs b/src/Merge.Client/Hris/Issues/IssuesClient.cs index 7e8711a8..b0e9ee6b 100644 --- a/src/Merge.Client/Hris/Issues/IssuesClient.cs +++ b/src/Merge.Client/Hris/Issues/IssuesClient.cs @@ -1,6 +1,6 @@ +using System.Net.Http; using System.Text.Json; -using Merge.Client; -using Merge.Client.Hris; +using Merge.Client.Core; #nullable enable @@ -18,7 +18,10 @@ public IssuesClient(RawClient client) /// /// Gets all issues for Organization. /// - public async Task ListAsync(IssuesListRequest request) + public async Task ListAsync( + IssuesListRequest request, + RequestOptions? options = null + ) { var _query = new Dictionary() { }; if (request.AccountToken != null) @@ -40,13 +43,13 @@ public async Task ListAsync(IssuesListRequest request) if (request.FirstIncidentTimeAfter != null) { _query["first_incident_time_after"] = request.FirstIncidentTimeAfter.Value.ToString( - "o0" + Constants.DateTimeFormat ); } if (request.FirstIncidentTimeBefore != null) { _query["first_incident_time_before"] = request.FirstIncidentTimeBefore.Value.ToString( - "o0" + Constants.DateTimeFormat ); } if (request.IncludeMuted != null) @@ -59,12 +62,14 @@ public async Task ListAsync(IssuesListRequest request) } if (request.LastIncidentTimeAfter != null) { - _query["last_incident_time_after"] = request.LastIncidentTimeAfter.Value.ToString("o0"); + _query["last_incident_time_after"] = request.LastIncidentTimeAfter.Value.ToString( + Constants.DateTimeFormat + ); } if (request.LastIncidentTimeBefore != null) { _query["last_incident_time_before"] = request.LastIncidentTimeBefore.Value.ToString( - "o0" + Constants.DateTimeFormat ); } if (request.LinkedAccountId != null) @@ -86,32 +91,64 @@ public async Task ListAsync(IssuesListRequest request) var response = await _client.MakeRequestAsync( new RawClient.JsonApiRequest { + BaseUrl = _client.Options.BaseUrl, Method = HttpMethod.Get, Path = "hris/v1/issues", - Query = _query + Query = _query, + Options = options } ); - string responseBody = await response.Raw.Content.ReadAsStringAsync(); - if (response.StatusCode >= 200 && response.StatusCode < 400) + var responseBody = await response.Raw.Content.ReadAsStringAsync(); + if (response.StatusCode is >= 200 and < 400) { - return JsonSerializer.Deserialize(responseBody); + try + { + return JsonUtils.Deserialize(responseBody)!; + } + catch (JsonException e) + { + throw new MergeException("Failed to deserialize response", e); + } } - throw new Exception(responseBody); + + throw new MergeApiException( + $"Error with status code {response.StatusCode}", + response.StatusCode, + JsonUtils.Deserialize(responseBody) + ); } /// /// Get a specific issue. /// - public async Task RetrieveAsync(string id) + public async Task RetrieveAsync(string id, RequestOptions? options = null) { var response = await _client.MakeRequestAsync( - new RawClient.JsonApiRequest { Method = HttpMethod.Get, Path = $"hris/v1/issues/{id}" } + new RawClient.JsonApiRequest + { + BaseUrl = _client.Options.BaseUrl, + Method = HttpMethod.Get, + Path = $"hris/v1/issues/{id}", + Options = options + } ); - string responseBody = await response.Raw.Content.ReadAsStringAsync(); - if (response.StatusCode >= 200 && response.StatusCode < 400) + var responseBody = await response.Raw.Content.ReadAsStringAsync(); + if (response.StatusCode is >= 200 and < 400) { - return JsonSerializer.Deserialize(responseBody); + try + { + return JsonUtils.Deserialize(responseBody)!; + } + catch (JsonException e) + { + throw new MergeException("Failed to deserialize response", e); + } } - throw new Exception(responseBody); + + throw new MergeApiException( + $"Error with status code {response.StatusCode}", + response.StatusCode, + JsonUtils.Deserialize(responseBody) + ); } } diff --git a/src/Merge.Client/Hris/Issues/Requests/IssuesListRequest.cs b/src/Merge.Client/Hris/Issues/Requests/IssuesListRequest.cs index 48fcf5a2..adf5565b 100644 --- a/src/Merge.Client/Hris/Issues/Requests/IssuesListRequest.cs +++ b/src/Merge.Client/Hris/Issues/Requests/IssuesListRequest.cs @@ -1,66 +1,62 @@ -using Merge.Client.Hris; - -#nullable enable - namespace Merge.Client.Hris; -public class IssuesListRequest +public record IssuesListRequest { - public string? AccountToken { get; init; } + public string? AccountToken { get; set; } /// /// The pagination cursor value. /// - public string? Cursor { get; init; } + public string? Cursor { get; set; } /// /// If included, will only include issues whose most recent action occurred before this time /// - public string? EndDate { get; init; } + public string? EndDate { get; set; } - public string? EndUserOrganizationName { get; init; } + public string? EndUserOrganizationName { get; set; } /// /// If provided, will only return issues whose first incident time was after this datetime. /// - public DateTime? FirstIncidentTimeAfter { get; init; } + public DateTime? FirstIncidentTimeAfter { get; set; } /// /// If provided, will only return issues whose first incident time was before this datetime. /// - public DateTime? FirstIncidentTimeBefore { get; init; } + public DateTime? FirstIncidentTimeBefore { get; set; } /// /// If true, will include muted issues /// - public string? IncludeMuted { get; init; } + public string? IncludeMuted { get; set; } - public string? IntegrationName { get; init; } + public string? IntegrationName { get; set; } /// /// If provided, will only return issues whose last incident time was after this datetime. /// - public DateTime? LastIncidentTimeAfter { get; init; } + public DateTime? LastIncidentTimeAfter { get; set; } /// /// If provided, will only return issues whose last incident time was before this datetime. /// - public DateTime? LastIncidentTimeBefore { get; init; } + public DateTime? LastIncidentTimeBefore { get; set; } /// /// If provided, will only include issues pertaining to the linked account passed in. /// - public string? LinkedAccountId { get; init; } + public string? LinkedAccountId { get; set; } /// /// Number of results to return per page. /// - public int? PageSize { get; init; } + public int? PageSize { get; set; } /// /// If included, will only include issues whose most recent action occurred after this time /// - public string? StartDate { get; init; } + public string? StartDate { get; set; } /// /// Status of the issue. Options: ('ONGOING', 'RESOLVED') @@ -68,5 +64,5 @@ public class IssuesListRequest /// - `ONGOING` - ONGOING /// - `RESOLVED` - RESOLVED /// - public IssuesListRequestStatus? Status { get; init; } + public IssuesListRequestStatus? Status { get; set; } } diff --git a/src/Merge.Client/Hris/Issues/Types/IssuesListRequestStatus.cs b/src/Merge.Client/Hris/Issues/Types/IssuesListRequestStatus.cs index 86f9cfcb..b110c432 100644 --- a/src/Merge.Client/Hris/Issues/Types/IssuesListRequestStatus.cs +++ b/src/Merge.Client/Hris/Issues/Types/IssuesListRequestStatus.cs @@ -1,7 +1,6 @@ using System.Runtime.Serialization; using System.Text.Json.Serialization; using Merge.Client.Core; -using Merge.Client.Hris; #nullable enable diff --git a/src/Merge.Client/Hris/LinkToken/LinkTokenClient.cs b/src/Merge.Client/Hris/LinkToken/LinkTokenClient.cs index 02402e74..22abec37 100644 --- a/src/Merge.Client/Hris/LinkToken/LinkTokenClient.cs +++ b/src/Merge.Client/Hris/LinkToken/LinkTokenClient.cs @@ -1,6 +1,6 @@ +using System.Net.Http; using System.Text.Json; -using Merge.Client; -using Merge.Client.Hris; +using Merge.Client.Core; #nullable enable @@ -18,21 +18,38 @@ public LinkTokenClient(RawClient client) /// /// Creates a link token to be used when linking a new end user. /// - public async Task CreateAsync(EndUserDetailsRequest request) + public async Task CreateAsync( + EndUserDetailsRequest request, + RequestOptions? options = null + ) { var response = await _client.MakeRequestAsync( new RawClient.JsonApiRequest { + BaseUrl = _client.Options.BaseUrl, Method = HttpMethod.Post, Path = "hris/v1/link-token", - Body = request + Body = request, + Options = options } ); - string responseBody = await response.Raw.Content.ReadAsStringAsync(); - if (response.StatusCode >= 200 && response.StatusCode < 400) + var responseBody = await response.Raw.Content.ReadAsStringAsync(); + if (response.StatusCode is >= 200 and < 400) { - return JsonSerializer.Deserialize(responseBody); + try + { + return JsonUtils.Deserialize(responseBody)!; + } + catch (JsonException e) + { + throw new MergeException("Failed to deserialize response", e); + } } - throw new Exception(responseBody); + + throw new MergeApiException( + $"Error with status code {response.StatusCode}", + response.StatusCode, + JsonUtils.Deserialize(responseBody) + ); } } diff --git a/src/Merge.Client/Hris/LinkToken/Requests/EndUserDetailsRequest.cs b/src/Merge.Client/Hris/LinkToken/Requests/EndUserDetailsRequest.cs index fd191bc0..1a24c6c5 100644 --- a/src/Merge.Client/Hris/LinkToken/Requests/EndUserDetailsRequest.cs +++ b/src/Merge.Client/Hris/LinkToken/Requests/EndUserDetailsRequest.cs @@ -1,65 +1,64 @@ using System.Text.Json.Serialization; -using Merge.Client.Hris; #nullable enable namespace Merge.Client.Hris; -public class EndUserDetailsRequest +public record EndUserDetailsRequest { /// /// Your end user's email address. This is purely for identification purposes - setting this value will not cause any emails to be sent. /// [JsonPropertyName("end_user_email_address")] - public string EndUserEmailAddress { get; init; } + public required string EndUserEmailAddress { get; set; } /// /// Your end user's organization. /// [JsonPropertyName("end_user_organization_name")] - public string EndUserOrganizationName { get; init; } + public required string EndUserOrganizationName { get; set; } /// /// This unique identifier typically represents the ID for your end user in your product's database. This value must be distinct from other Linked Accounts' unique identifiers. /// [JsonPropertyName("end_user_origin_id")] - public string EndUserOriginId { get; init; } + public required string EndUserOriginId { get; set; } /// /// The integration categories to show in Merge Link. /// [JsonPropertyName("categories")] - public IEnumerable Categories { get; init; } + public IEnumerable Categories { get; set; } = new List(); /// /// The slug of a specific pre-selected integration for this linking flow token. For examples of slugs, see https://docs.merge.dev/guides/merge-link/single-integration/. /// [JsonPropertyName("integration")] - public string? Integration { get; init; } + public string? Integration { get; set; } /// /// An integer number of minutes between [30, 720 or 10080 if for a Magic Link URL] for how long this token is valid. Defaults to 30. /// [JsonPropertyName("link_expiry_mins")] - public int? LinkExpiryMins { get; init; } + public int? LinkExpiryMins { get; set; } /// /// Whether to generate a Magic Link URL. Defaults to false. For more information on Magic Link, see https://merge.dev/blog/integrations-fast-say-hello-to-magic-link. /// [JsonPropertyName("should_create_magic_link_url")] - public bool? ShouldCreateMagicLinkUrl { get; init; } + public bool? ShouldCreateMagicLinkUrl { get; set; } /// /// Whether to generate a Magic Link URL on the Admin Needed screen during the linking flow. Defaults to false. For more information on Magic Link, see https://merge.dev/blog/integrations-fast-say-hello-to-magic-link. /// [JsonPropertyName("hide_admin_magic_link")] - public bool? HideAdminMagicLink { get; init; } + public bool? HideAdminMagicLink { get; set; } /// /// An array of objects to specify the models and fields that will be disabled for a given Linked Account. Each object uses model_id, enabled_actions, and disabled_fields to specify the model, method, and fields that are scoped for a given Linked Account. /// [JsonPropertyName("common_models")] - public IEnumerable? CommonModels { get; init; } + public IEnumerable? CommonModels { get; set; } /// /// When creating a Link Token, you can set permissions for Common Models that will apply to the account that is going to be linked. Any model or field not specified in link token payload will default to existing settings. @@ -68,17 +67,17 @@ public class EndUserDetailsRequest public Dictionary< string, IEnumerable? - >? CategoryCommonModelScopes { get; init; } + >? CategoryCommonModelScopes { get; set; } /// /// The language code for the language to localize Merge Link to. /// [JsonPropertyName("language")] - public string? Language { get; init; } + public string? Language { get; set; } /// /// A JSON object containing integration-specific configuration options. /// [JsonPropertyName("integration_specific_config")] - public Dictionary? IntegrationSpecificConfig { get; init; } + public Dictionary? IntegrationSpecificConfig { get; set; } } diff --git a/src/Merge.Client/Hris/LinkedAccounts/LinkedAccountsClient.cs b/src/Merge.Client/Hris/LinkedAccounts/LinkedAccountsClient.cs index 7592f55f..fe63e0e3 100644 --- a/src/Merge.Client/Hris/LinkedAccounts/LinkedAccountsClient.cs +++ b/src/Merge.Client/Hris/LinkedAccounts/LinkedAccountsClient.cs @@ -1,6 +1,6 @@ +using System.Net.Http; using System.Text.Json; -using Merge.Client; -using Merge.Client.Hris; +using Merge.Client.Core; #nullable enable @@ -19,7 +19,8 @@ public LinkedAccountsClient(RawClient client) /// List linked accounts for your organization. /// public async Task ListAsync( - LinkedAccountsListRequest request + LinkedAccountsListRequest request, + RequestOptions? options = null ) { var _query = new Dictionary() { }; @@ -78,16 +79,30 @@ LinkedAccountsListRequest request var response = await _client.MakeRequestAsync( new RawClient.JsonApiRequest { + BaseUrl = _client.Options.BaseUrl, Method = HttpMethod.Get, Path = "hris/v1/linked-accounts", - Query = _query + Query = _query, + Options = options } ); - string responseBody = await response.Raw.Content.ReadAsStringAsync(); - if (response.StatusCode >= 200 && response.StatusCode < 400) + var responseBody = await response.Raw.Content.ReadAsStringAsync(); + if (response.StatusCode is >= 200 and < 400) { - return JsonSerializer.Deserialize(responseBody); + try + { + return JsonUtils.Deserialize(responseBody)!; + } + catch (JsonException e) + { + throw new MergeException("Failed to deserialize response", e); + } } - throw new Exception(responseBody); + + throw new MergeApiException( + $"Error with status code {response.StatusCode}", + response.StatusCode, + JsonUtils.Deserialize(responseBody) + ); } } diff --git a/src/Merge.Client/Hris/LinkedAccounts/Requests/LinkedAccountsListRequest.cs b/src/Merge.Client/Hris/LinkedAccounts/Requests/LinkedAccountsListRequest.cs index 4cc054fa..9fb3c746 100644 --- a/src/Merge.Client/Hris/LinkedAccounts/Requests/LinkedAccountsListRequest.cs +++ b/src/Merge.Client/Hris/LinkedAccounts/Requests/LinkedAccountsListRequest.cs @@ -1,10 +1,6 @@ -using Merge.Client.Hris; - -#nullable enable - namespace Merge.Client.Hris; -public class LinkedAccountsListRequest +public record LinkedAccountsListRequest { /// /// Options: `accounting`, `ats`, `crm`, `filestorage`, `hris`, `mktg`, `ticketing` @@ -17,62 +13,62 @@ public class LinkedAccountsListRequest /// - `mktg` - mktg /// - `filestorage` - filestorage /// - public LinkedAccountsListRequestCategory? Category { get; init; } + public LinkedAccountsListRequestCategory? Category { get; set; } /// /// The pagination cursor value. /// - public string? Cursor { get; init; } + public string? Cursor { get; set; } /// /// If provided, will only return linked accounts associated with the given email address. /// - public string? EndUserEmailAddress { get; init; } + public string? EndUserEmailAddress { get; set; } /// /// If provided, will only return linked accounts associated with the given organization name. /// - public string? EndUserOrganizationName { get; init; } + public string? EndUserOrganizationName { get; set; } /// /// If provided, will only return linked accounts associated with the given origin ID. /// - public string? EndUserOriginId { get; init; } + public string? EndUserOriginId { get; set; } /// /// Comma-separated list of EndUser origin IDs, making it possible to specify multiple EndUsers at once. /// - public string? EndUserOriginIds { get; init; } + public string? EndUserOriginIds { get; set; } - public string? Id { get; init; } + public string? Id { get; set; } /// /// Comma-separated list of LinkedAccount IDs, making it possible to specify multiple LinkedAccounts at once. /// - public string? Ids { get; init; } + public string? Ids { get; set; } /// /// If `true`, will include complete production duplicates of the account specified by the `id` query parameter in the response. `id` must be for a complete production linked account. /// - public bool? IncludeDuplicates { get; init; } + public bool? IncludeDuplicates { get; set; } /// /// If provided, will only return linked accounts associated with the given integration name. /// - public string? IntegrationName { get; init; } + public string? IntegrationName { get; set; } /// /// If included, will only include test linked accounts. If not included, will only include non-test linked accounts. /// - public string? IsTestAccount { get; init; } + public string? IsTestAccount { get; set; } /// /// Number of results to return per page. /// - public int? PageSize { get; init; } + public int? PageSize { get; set; } /// /// Filter by status. Options: `COMPLETE`, `INCOMPLETE`, `RELINK_NEEDED` /// - public string? Status { get; init; } + public string? Status { get; set; } } diff --git a/src/Merge.Client/Hris/LinkedAccounts/Types/LinkedAccountsListRequestCategory.cs b/src/Merge.Client/Hris/LinkedAccounts/Types/LinkedAccountsListRequestCategory.cs index 7da8c513..0c79599e 100644 --- a/src/Merge.Client/Hris/LinkedAccounts/Types/LinkedAccountsListRequestCategory.cs +++ b/src/Merge.Client/Hris/LinkedAccounts/Types/LinkedAccountsListRequestCategory.cs @@ -1,7 +1,6 @@ using System.Runtime.Serialization; using System.Text.Json.Serialization; using Merge.Client.Core; -using Merge.Client.Hris; #nullable enable diff --git a/src/Merge.Client/Hris/Locations/LocationsClient.cs b/src/Merge.Client/Hris/Locations/LocationsClient.cs index 9d3b0b06..18af6749 100644 --- a/src/Merge.Client/Hris/Locations/LocationsClient.cs +++ b/src/Merge.Client/Hris/Locations/LocationsClient.cs @@ -1,6 +1,6 @@ +using System.Net.Http; using System.Text.Json; -using Merge.Client; -using Merge.Client.Hris; +using Merge.Client.Core; #nullable enable @@ -18,16 +18,21 @@ public LocationsClient(RawClient client) /// /// Returns a list of `Location` objects. /// - public async Task ListAsync(LocationsListRequest request) + public async Task ListAsync( + LocationsListRequest request, + RequestOptions? options = null + ) { var _query = new Dictionary() { }; if (request.CreatedAfter != null) { - _query["created_after"] = request.CreatedAfter.Value.ToString("o0"); + _query["created_after"] = request.CreatedAfter.Value.ToString(Constants.DateTimeFormat); } if (request.CreatedBefore != null) { - _query["created_before"] = request.CreatedBefore.Value.ToString("o0"); + _query["created_before"] = request.CreatedBefore.Value.ToString( + Constants.DateTimeFormat + ); } if (request.Cursor != null) { @@ -47,11 +52,15 @@ public async Task ListAsync(LocationsListRequest request) } if (request.ModifiedAfter != null) { - _query["modified_after"] = request.ModifiedAfter.Value.ToString("o0"); + _query["modified_after"] = request.ModifiedAfter.Value.ToString( + Constants.DateTimeFormat + ); } if (request.ModifiedBefore != null) { - _query["modified_before"] = request.ModifiedBefore.Value.ToString("o0"); + _query["modified_before"] = request.ModifiedBefore.Value.ToString( + Constants.DateTimeFormat + ); } if (request.PageSize != null) { @@ -72,23 +81,41 @@ public async Task ListAsync(LocationsListRequest request) var response = await _client.MakeRequestAsync( new RawClient.JsonApiRequest { + BaseUrl = _client.Options.BaseUrl, Method = HttpMethod.Get, Path = "hris/v1/locations", - Query = _query + Query = _query, + Options = options } ); - string responseBody = await response.Raw.Content.ReadAsStringAsync(); - if (response.StatusCode >= 200 && response.StatusCode < 400) + var responseBody = await response.Raw.Content.ReadAsStringAsync(); + if (response.StatusCode is >= 200 and < 400) { - return JsonSerializer.Deserialize(responseBody); + try + { + return JsonUtils.Deserialize(responseBody)!; + } + catch (JsonException e) + { + throw new MergeException("Failed to deserialize response", e); + } } - throw new Exception(responseBody); + + throw new MergeApiException( + $"Error with status code {response.StatusCode}", + response.StatusCode, + JsonUtils.Deserialize(responseBody) + ); } /// /// Returns a `Location` object with the given `id`. /// - public async Task RetrieveAsync(string id, LocationsRetrieveRequest request) + public async Task RetrieveAsync( + string id, + LocationsRetrieveRequest request, + RequestOptions? options = null + ) { var _query = new Dictionary() { }; if (request.IncludeRemoteData != null) @@ -106,16 +133,30 @@ public async Task RetrieveAsync(string id, LocationsRetrieveRequest re var response = await _client.MakeRequestAsync( new RawClient.JsonApiRequest { + BaseUrl = _client.Options.BaseUrl, Method = HttpMethod.Get, Path = $"hris/v1/locations/{id}", - Query = _query + Query = _query, + Options = options } ); - string responseBody = await response.Raw.Content.ReadAsStringAsync(); - if (response.StatusCode >= 200 && response.StatusCode < 400) + var responseBody = await response.Raw.Content.ReadAsStringAsync(); + if (response.StatusCode is >= 200 and < 400) { - return JsonSerializer.Deserialize(responseBody); + try + { + return JsonUtils.Deserialize(responseBody)!; + } + catch (JsonException e) + { + throw new MergeException("Failed to deserialize response", e); + } } - throw new Exception(responseBody); + + throw new MergeApiException( + $"Error with status code {response.StatusCode}", + response.StatusCode, + JsonUtils.Deserialize(responseBody) + ); } } diff --git a/src/Merge.Client/Hris/Locations/Requests/LocationsListRequest.cs b/src/Merge.Client/Hris/Locations/Requests/LocationsListRequest.cs index b4f34545..529e7f3c 100644 --- a/src/Merge.Client/Hris/Locations/Requests/LocationsListRequest.cs +++ b/src/Merge.Client/Hris/Locations/Requests/LocationsListRequest.cs @@ -1,35 +1,31 @@ -using Merge.Client.Hris; - -#nullable enable - namespace Merge.Client.Hris; -public class LocationsListRequest +public record LocationsListRequest { /// /// If provided, will only return objects created after this datetime. /// - public DateTime? CreatedAfter { get; init; } + public DateTime? CreatedAfter { get; set; } /// /// If provided, will only return objects created before this datetime. /// - public DateTime? CreatedBefore { get; init; } + public DateTime? CreatedBefore { get; set; } /// /// The pagination cursor value. /// - public string? Cursor { get; init; } + public string? Cursor { get; set; } /// /// Whether to include data that was marked as deleted by third party webhooks. /// - public bool? IncludeDeletedData { get; init; } + public bool? IncludeDeletedData { get; set; } /// /// Whether to include the original data Merge fetched from the third-party to produce these models. /// - public bool? IncludeRemoteData { get; init; } + public bool? IncludeRemoteData { get; set; } /// /// If provided, will only return locations with this location_type @@ -37,35 +33,35 @@ public class LocationsListRequest /// - `HOME` - HOME /// - `WORK` - WORK /// - public LocationsListRequestLocationType? LocationType { get; init; } + public LocationsListRequestLocationType? LocationType { get; set; } /// /// If provided, only objects synced by Merge after this date time will be returned. /// - public DateTime? ModifiedAfter { get; init; } + public DateTime? ModifiedAfter { get; set; } /// /// If provided, only objects synced by Merge before this date time will be returned. /// - public DateTime? ModifiedBefore { get; init; } + public DateTime? ModifiedBefore { get; set; } /// /// Number of results to return per page. /// - public int? PageSize { get; init; } + public int? PageSize { get; set; } /// /// Deprecated. Use show_enum_origins. /// - public string? RemoteFields { get; init; } + public string? RemoteFields { get; set; } /// /// The API provider's ID for the given object. /// - public string? RemoteId { get; init; } + public string? RemoteId { get; set; } /// /// A comma separated list of enum field names for which you'd like the original values to be returned, instead of Merge's normalized enum values. [Learn more](https://help.merge.dev/en/articles/8950958-show_enum_origins-query-parameter) /// - public string? ShowEnumOrigins { get; init; } + public string? ShowEnumOrigins { get; set; } } diff --git a/src/Merge.Client/Hris/Locations/Requests/LocationsRetrieveRequest.cs b/src/Merge.Client/Hris/Locations/Requests/LocationsRetrieveRequest.cs index acde5e21..96d1b0f5 100644 --- a/src/Merge.Client/Hris/Locations/Requests/LocationsRetrieveRequest.cs +++ b/src/Merge.Client/Hris/Locations/Requests/LocationsRetrieveRequest.cs @@ -1,19 +1,19 @@ namespace Merge.Client.Hris; -public class LocationsRetrieveRequest +public record LocationsRetrieveRequest { /// /// Whether to include the original data Merge fetched from the third-party to produce these models. /// - public bool? IncludeRemoteData { get; init; } + public bool? IncludeRemoteData { get; set; } /// /// Deprecated. Use show_enum_origins. /// - public string? RemoteFields { get; init; } + public string? RemoteFields { get; set; } /// /// A comma separated list of enum field names for which you'd like the original values to be returned, instead of Merge's normalized enum values. [Learn more](https://help.merge.dev/en/articles/8950958-show_enum_origins-query-parameter) /// - public string? ShowEnumOrigins { get; init; } + public string? ShowEnumOrigins { get; set; } } diff --git a/src/Merge.Client/Hris/Locations/Types/LocationsListRequestLocationType.cs b/src/Merge.Client/Hris/Locations/Types/LocationsListRequestLocationType.cs index 77a7728d..7510088f 100644 --- a/src/Merge.Client/Hris/Locations/Types/LocationsListRequestLocationType.cs +++ b/src/Merge.Client/Hris/Locations/Types/LocationsListRequestLocationType.cs @@ -1,7 +1,6 @@ using System.Runtime.Serialization; using System.Text.Json.Serialization; using Merge.Client.Core; -using Merge.Client.Hris; #nullable enable diff --git a/src/Merge.Client/Hris/Passthrough/PassthroughClient.cs b/src/Merge.Client/Hris/Passthrough/PassthroughClient.cs index 72d5d071..2cd4b7a5 100644 --- a/src/Merge.Client/Hris/Passthrough/PassthroughClient.cs +++ b/src/Merge.Client/Hris/Passthrough/PassthroughClient.cs @@ -1,6 +1,6 @@ +using System.Net.Http; using System.Text.Json; -using Merge.Client; -using Merge.Client.Hris; +using Merge.Client.Core; #nullable enable @@ -18,21 +18,38 @@ public PassthroughClient(RawClient client) /// /// Pull data from an endpoint not currently supported by Merge. /// - public async Task CreateAsync(DataPassthroughRequest request) + public async Task CreateAsync( + DataPassthroughRequest request, + RequestOptions? options = null + ) { var response = await _client.MakeRequestAsync( new RawClient.JsonApiRequest { + BaseUrl = _client.Options.BaseUrl, Method = HttpMethod.Post, Path = "hris/v1/passthrough", - Body = request + Body = request, + Options = options } ); - string responseBody = await response.Raw.Content.ReadAsStringAsync(); - if (response.StatusCode >= 200 && response.StatusCode < 400) + var responseBody = await response.Raw.Content.ReadAsStringAsync(); + if (response.StatusCode is >= 200 and < 400) { - return JsonSerializer.Deserialize(responseBody); + try + { + return JsonUtils.Deserialize(responseBody)!; + } + catch (JsonException e) + { + throw new MergeException("Failed to deserialize response", e); + } } - throw new Exception(responseBody); + + throw new MergeApiException( + $"Error with status code {response.StatusCode}", + response.StatusCode, + JsonUtils.Deserialize(responseBody) + ); } } diff --git a/src/Merge.Client/Hris/PayGroups/PayGroupsClient.cs b/src/Merge.Client/Hris/PayGroups/PayGroupsClient.cs index c26e0385..a0c389c5 100644 --- a/src/Merge.Client/Hris/PayGroups/PayGroupsClient.cs +++ b/src/Merge.Client/Hris/PayGroups/PayGroupsClient.cs @@ -1,6 +1,6 @@ +using System.Net.Http; using System.Text.Json; -using Merge.Client; -using Merge.Client.Hris; +using Merge.Client.Core; #nullable enable @@ -18,16 +18,21 @@ public PayGroupsClient(RawClient client) /// /// Returns a list of `PayGroup` objects. /// - public async Task ListAsync(PayGroupsListRequest request) + public async Task ListAsync( + PayGroupsListRequest request, + RequestOptions? options = null + ) { var _query = new Dictionary() { }; if (request.CreatedAfter != null) { - _query["created_after"] = request.CreatedAfter.Value.ToString("o0"); + _query["created_after"] = request.CreatedAfter.Value.ToString(Constants.DateTimeFormat); } if (request.CreatedBefore != null) { - _query["created_before"] = request.CreatedBefore.Value.ToString("o0"); + _query["created_before"] = request.CreatedBefore.Value.ToString( + Constants.DateTimeFormat + ); } if (request.Cursor != null) { @@ -43,11 +48,15 @@ public async Task ListAsync(PayGroupsListRequest request) } if (request.ModifiedAfter != null) { - _query["modified_after"] = request.ModifiedAfter.Value.ToString("o0"); + _query["modified_after"] = request.ModifiedAfter.Value.ToString( + Constants.DateTimeFormat + ); } if (request.ModifiedBefore != null) { - _query["modified_before"] = request.ModifiedBefore.Value.ToString("o0"); + _query["modified_before"] = request.ModifiedBefore.Value.ToString( + Constants.DateTimeFormat + ); } if (request.PageSize != null) { @@ -60,23 +69,41 @@ public async Task ListAsync(PayGroupsListRequest request) var response = await _client.MakeRequestAsync( new RawClient.JsonApiRequest { + BaseUrl = _client.Options.BaseUrl, Method = HttpMethod.Get, Path = "hris/v1/pay-groups", - Query = _query + Query = _query, + Options = options } ); - string responseBody = await response.Raw.Content.ReadAsStringAsync(); - if (response.StatusCode >= 200 && response.StatusCode < 400) + var responseBody = await response.Raw.Content.ReadAsStringAsync(); + if (response.StatusCode is >= 200 and < 400) { - return JsonSerializer.Deserialize(responseBody); + try + { + return JsonUtils.Deserialize(responseBody)!; + } + catch (JsonException e) + { + throw new MergeException("Failed to deserialize response", e); + } } - throw new Exception(responseBody); + + throw new MergeApiException( + $"Error with status code {response.StatusCode}", + response.StatusCode, + JsonUtils.Deserialize(responseBody) + ); } /// /// Returns a `PayGroup` object with the given `id`. /// - public async Task RetrieveAsync(string id, PayGroupsRetrieveRequest request) + public async Task RetrieveAsync( + string id, + PayGroupsRetrieveRequest request, + RequestOptions? options = null + ) { var _query = new Dictionary() { }; if (request.IncludeRemoteData != null) @@ -86,16 +113,30 @@ public async Task RetrieveAsync(string id, PayGroupsRetrieveRequest re var response = await _client.MakeRequestAsync( new RawClient.JsonApiRequest { + BaseUrl = _client.Options.BaseUrl, Method = HttpMethod.Get, Path = $"hris/v1/pay-groups/{id}", - Query = _query + Query = _query, + Options = options } ); - string responseBody = await response.Raw.Content.ReadAsStringAsync(); - if (response.StatusCode >= 200 && response.StatusCode < 400) + var responseBody = await response.Raw.Content.ReadAsStringAsync(); + if (response.StatusCode is >= 200 and < 400) { - return JsonSerializer.Deserialize(responseBody); + try + { + return JsonUtils.Deserialize(responseBody)!; + } + catch (JsonException e) + { + throw new MergeException("Failed to deserialize response", e); + } } - throw new Exception(responseBody); + + throw new MergeApiException( + $"Error with status code {response.StatusCode}", + response.StatusCode, + JsonUtils.Deserialize(responseBody) + ); } } diff --git a/src/Merge.Client/Hris/PayGroups/Requests/PayGroupsListRequest.cs b/src/Merge.Client/Hris/PayGroups/Requests/PayGroupsListRequest.cs index 00582f4d..64c4bd44 100644 --- a/src/Merge.Client/Hris/PayGroups/Requests/PayGroupsListRequest.cs +++ b/src/Merge.Client/Hris/PayGroups/Requests/PayGroupsListRequest.cs @@ -1,49 +1,49 @@ namespace Merge.Client.Hris; -public class PayGroupsListRequest +public record PayGroupsListRequest { /// /// If provided, will only return objects created after this datetime. /// - public DateTime? CreatedAfter { get; init; } + public DateTime? CreatedAfter { get; set; } /// /// If provided, will only return objects created before this datetime. /// - public DateTime? CreatedBefore { get; init; } + public DateTime? CreatedBefore { get; set; } /// /// The pagination cursor value. /// - public string? Cursor { get; init; } + public string? Cursor { get; set; } /// /// Whether to include data that was marked as deleted by third party webhooks. /// - public bool? IncludeDeletedData { get; init; } + public bool? IncludeDeletedData { get; set; } /// /// Whether to include the original data Merge fetched from the third-party to produce these models. /// - public bool? IncludeRemoteData { get; init; } + public bool? IncludeRemoteData { get; set; } /// /// If provided, only objects synced by Merge after this date time will be returned. /// - public DateTime? ModifiedAfter { get; init; } + public DateTime? ModifiedAfter { get; set; } /// /// If provided, only objects synced by Merge before this date time will be returned. /// - public DateTime? ModifiedBefore { get; init; } + public DateTime? ModifiedBefore { get; set; } /// /// Number of results to return per page. /// - public int? PageSize { get; init; } + public int? PageSize { get; set; } /// /// The API provider's ID for the given object. /// - public string? RemoteId { get; init; } + public string? RemoteId { get; set; } } diff --git a/src/Merge.Client/Hris/PayGroups/Requests/PayGroupsRetrieveRequest.cs b/src/Merge.Client/Hris/PayGroups/Requests/PayGroupsRetrieveRequest.cs index 2563e9ac..755c1b3e 100644 --- a/src/Merge.Client/Hris/PayGroups/Requests/PayGroupsRetrieveRequest.cs +++ b/src/Merge.Client/Hris/PayGroups/Requests/PayGroupsRetrieveRequest.cs @@ -1,9 +1,9 @@ namespace Merge.Client.Hris; -public class PayGroupsRetrieveRequest +public record PayGroupsRetrieveRequest { /// /// Whether to include the original data Merge fetched from the third-party to produce these models. /// - public bool? IncludeRemoteData { get; init; } + public bool? IncludeRemoteData { get; set; } } diff --git a/src/Merge.Client/Hris/PayrollRuns/PayrollRunsClient.cs b/src/Merge.Client/Hris/PayrollRuns/PayrollRunsClient.cs index e0ac9813..efd1090b 100644 --- a/src/Merge.Client/Hris/PayrollRuns/PayrollRunsClient.cs +++ b/src/Merge.Client/Hris/PayrollRuns/PayrollRunsClient.cs @@ -1,6 +1,6 @@ +using System.Net.Http; using System.Text.Json; -using Merge.Client; -using Merge.Client.Hris; +using Merge.Client.Core; #nullable enable @@ -18,16 +18,21 @@ public PayrollRunsClient(RawClient client) /// /// Returns a list of `PayrollRun` objects. /// - public async Task ListAsync(PayrollRunsListRequest request) + public async Task ListAsync( + PayrollRunsListRequest request, + RequestOptions? options = null + ) { var _query = new Dictionary() { }; if (request.CreatedAfter != null) { - _query["created_after"] = request.CreatedAfter.Value.ToString("o0"); + _query["created_after"] = request.CreatedAfter.Value.ToString(Constants.DateTimeFormat); } if (request.CreatedBefore != null) { - _query["created_before"] = request.CreatedBefore.Value.ToString("o0"); + _query["created_before"] = request.CreatedBefore.Value.ToString( + Constants.DateTimeFormat + ); } if (request.Cursor != null) { @@ -35,11 +40,11 @@ public async Task ListAsync(PayrollRunsListRequest requ } if (request.EndedAfter != null) { - _query["ended_after"] = request.EndedAfter.Value.ToString("o0"); + _query["ended_after"] = request.EndedAfter.Value.ToString(Constants.DateTimeFormat); } if (request.EndedBefore != null) { - _query["ended_before"] = request.EndedBefore.Value.ToString("o0"); + _query["ended_before"] = request.EndedBefore.Value.ToString(Constants.DateTimeFormat); } if (request.IncludeDeletedData != null) { @@ -51,11 +56,15 @@ public async Task ListAsync(PayrollRunsListRequest requ } if (request.ModifiedAfter != null) { - _query["modified_after"] = request.ModifiedAfter.Value.ToString("o0"); + _query["modified_after"] = request.ModifiedAfter.Value.ToString( + Constants.DateTimeFormat + ); } if (request.ModifiedBefore != null) { - _query["modified_before"] = request.ModifiedBefore.Value.ToString("o0"); + _query["modified_before"] = request.ModifiedBefore.Value.ToString( + Constants.DateTimeFormat + ); } if (request.PageSize != null) { @@ -79,32 +88,52 @@ public async Task ListAsync(PayrollRunsListRequest requ } if (request.StartedAfter != null) { - _query["started_after"] = request.StartedAfter.Value.ToString("o0"); + _query["started_after"] = request.StartedAfter.Value.ToString(Constants.DateTimeFormat); } if (request.StartedBefore != null) { - _query["started_before"] = request.StartedBefore.Value.ToString("o0"); + _query["started_before"] = request.StartedBefore.Value.ToString( + Constants.DateTimeFormat + ); } var response = await _client.MakeRequestAsync( new RawClient.JsonApiRequest { + BaseUrl = _client.Options.BaseUrl, Method = HttpMethod.Get, Path = "hris/v1/payroll-runs", - Query = _query + Query = _query, + Options = options } ); - string responseBody = await response.Raw.Content.ReadAsStringAsync(); - if (response.StatusCode >= 200 && response.StatusCode < 400) + var responseBody = await response.Raw.Content.ReadAsStringAsync(); + if (response.StatusCode is >= 200 and < 400) { - return JsonSerializer.Deserialize(responseBody); + try + { + return JsonUtils.Deserialize(responseBody)!; + } + catch (JsonException e) + { + throw new MergeException("Failed to deserialize response", e); + } } - throw new Exception(responseBody); + + throw new MergeApiException( + $"Error with status code {response.StatusCode}", + response.StatusCode, + JsonUtils.Deserialize(responseBody) + ); } /// /// Returns a `PayrollRun` object with the given `id`. /// - public async Task RetrieveAsync(string id, PayrollRunsRetrieveRequest request) + public async Task RetrieveAsync( + string id, + PayrollRunsRetrieveRequest request, + RequestOptions? options = null + ) { var _query = new Dictionary() { }; if (request.IncludeRemoteData != null) @@ -122,16 +151,30 @@ public async Task RetrieveAsync(string id, PayrollRunsRetrieveReques var response = await _client.MakeRequestAsync( new RawClient.JsonApiRequest { + BaseUrl = _client.Options.BaseUrl, Method = HttpMethod.Get, Path = $"hris/v1/payroll-runs/{id}", - Query = _query + Query = _query, + Options = options } ); - string responseBody = await response.Raw.Content.ReadAsStringAsync(); - if (response.StatusCode >= 200 && response.StatusCode < 400) + var responseBody = await response.Raw.Content.ReadAsStringAsync(); + if (response.StatusCode is >= 200 and < 400) { - return JsonSerializer.Deserialize(responseBody); + try + { + return JsonUtils.Deserialize(responseBody)!; + } + catch (JsonException e) + { + throw new MergeException("Failed to deserialize response", e); + } } - throw new Exception(responseBody); + + throw new MergeApiException( + $"Error with status code {response.StatusCode}", + response.StatusCode, + JsonUtils.Deserialize(responseBody) + ); } } diff --git a/src/Merge.Client/Hris/PayrollRuns/Requests/PayrollRunsListRequest.cs b/src/Merge.Client/Hris/PayrollRuns/Requests/PayrollRunsListRequest.cs index 3f0c75d5..e20f0065 100644 --- a/src/Merge.Client/Hris/PayrollRuns/Requests/PayrollRunsListRequest.cs +++ b/src/Merge.Client/Hris/PayrollRuns/Requests/PayrollRunsListRequest.cs @@ -1,70 +1,66 @@ -using Merge.Client.Hris; - -#nullable enable - namespace Merge.Client.Hris; -public class PayrollRunsListRequest +public record PayrollRunsListRequest { /// /// If provided, will only return objects created after this datetime. /// - public DateTime? CreatedAfter { get; init; } + public DateTime? CreatedAfter { get; set; } /// /// If provided, will only return objects created before this datetime. /// - public DateTime? CreatedBefore { get; init; } + public DateTime? CreatedBefore { get; set; } /// /// The pagination cursor value. /// - public string? Cursor { get; init; } + public string? Cursor { get; set; } /// /// If provided, will only return payroll runs ended after this datetime. /// - public DateTime? EndedAfter { get; init; } + public DateTime? EndedAfter { get; set; } /// /// If provided, will only return payroll runs ended before this datetime. /// - public DateTime? EndedBefore { get; init; } + public DateTime? EndedBefore { get; set; } /// /// Whether to include data that was marked as deleted by third party webhooks. /// - public bool? IncludeDeletedData { get; init; } + public bool? IncludeDeletedData { get; set; } /// /// Whether to include the original data Merge fetched from the third-party to produce these models. /// - public bool? IncludeRemoteData { get; init; } + public bool? IncludeRemoteData { get; set; } /// /// If provided, only objects synced by Merge after this date time will be returned. /// - public DateTime? ModifiedAfter { get; init; } + public DateTime? ModifiedAfter { get; set; } /// /// If provided, only objects synced by Merge before this date time will be returned. /// - public DateTime? ModifiedBefore { get; init; } + public DateTime? ModifiedBefore { get; set; } /// /// Number of results to return per page. /// - public int? PageSize { get; init; } + public int? PageSize { get; set; } /// /// Deprecated. Use show_enum_origins. /// - public PayrollRunsListRequestRemoteFields? RemoteFields { get; init; } + public PayrollRunsListRequestRemoteFields? RemoteFields { get; set; } /// /// The API provider's ID for the given object. /// - public string? RemoteId { get; init; } + public string? RemoteId { get; set; } /// /// If provided, will only return PayrollRun's with this status. Options: ('REGULAR', 'OFF_CYCLE', 'CORRECTION', 'TERMINATION', 'SIGN_ON_BONUS') @@ -75,20 +71,20 @@ public class PayrollRunsListRequest /// - `TERMINATION` - TERMINATION /// - `SIGN_ON_BONUS` - SIGN_ON_BONUS /// - public PayrollRunsListRequestRunType? RunType { get; init; } + public PayrollRunsListRequestRunType? RunType { get; set; } /// /// A comma separated list of enum field names for which you'd like the original values to be returned, instead of Merge's normalized enum values. [Learn more](https://help.merge.dev/en/articles/8950958-show_enum_origins-query-parameter) /// - public PayrollRunsListRequestShowEnumOrigins? ShowEnumOrigins { get; init; } + public PayrollRunsListRequestShowEnumOrigins? ShowEnumOrigins { get; set; } /// /// If provided, will only return payroll runs started after this datetime. /// - public DateTime? StartedAfter { get; init; } + public DateTime? StartedAfter { get; set; } /// /// If provided, will only return payroll runs started before this datetime. /// - public DateTime? StartedBefore { get; init; } + public DateTime? StartedBefore { get; set; } } diff --git a/src/Merge.Client/Hris/PayrollRuns/Requests/PayrollRunsRetrieveRequest.cs b/src/Merge.Client/Hris/PayrollRuns/Requests/PayrollRunsRetrieveRequest.cs index 4f86a9a5..a60c78a6 100644 --- a/src/Merge.Client/Hris/PayrollRuns/Requests/PayrollRunsRetrieveRequest.cs +++ b/src/Merge.Client/Hris/PayrollRuns/Requests/PayrollRunsRetrieveRequest.cs @@ -1,23 +1,19 @@ -using Merge.Client.Hris; - -#nullable enable - namespace Merge.Client.Hris; -public class PayrollRunsRetrieveRequest +public record PayrollRunsRetrieveRequest { /// /// Whether to include the original data Merge fetched from the third-party to produce these models. /// - public bool? IncludeRemoteData { get; init; } + public bool? IncludeRemoteData { get; set; } /// /// Deprecated. Use show_enum_origins. /// - public PayrollRunsRetrieveRequestRemoteFields? RemoteFields { get; init; } + public PayrollRunsRetrieveRequestRemoteFields? RemoteFields { get; set; } /// /// A comma separated list of enum field names for which you'd like the original values to be returned, instead of Merge's normalized enum values. [Learn more](https://help.merge.dev/en/articles/8950958-show_enum_origins-query-parameter) /// - public PayrollRunsRetrieveRequestShowEnumOrigins? ShowEnumOrigins { get; init; } + public PayrollRunsRetrieveRequestShowEnumOrigins? ShowEnumOrigins { get; set; } } diff --git a/src/Merge.Client/Hris/PayrollRuns/Types/PayrollRunsListRequestRemoteFields.cs b/src/Merge.Client/Hris/PayrollRuns/Types/PayrollRunsListRequestRemoteFields.cs index dfff450a..cf07a682 100644 --- a/src/Merge.Client/Hris/PayrollRuns/Types/PayrollRunsListRequestRemoteFields.cs +++ b/src/Merge.Client/Hris/PayrollRuns/Types/PayrollRunsListRequestRemoteFields.cs @@ -1,7 +1,6 @@ using System.Runtime.Serialization; using System.Text.Json.Serialization; using Merge.Client.Core; -using Merge.Client.Hris; #nullable enable diff --git a/src/Merge.Client/Hris/PayrollRuns/Types/PayrollRunsListRequestRunType.cs b/src/Merge.Client/Hris/PayrollRuns/Types/PayrollRunsListRequestRunType.cs index b45bd2f1..a1b85da8 100644 --- a/src/Merge.Client/Hris/PayrollRuns/Types/PayrollRunsListRequestRunType.cs +++ b/src/Merge.Client/Hris/PayrollRuns/Types/PayrollRunsListRequestRunType.cs @@ -1,7 +1,6 @@ using System.Runtime.Serialization; using System.Text.Json.Serialization; using Merge.Client.Core; -using Merge.Client.Hris; #nullable enable diff --git a/src/Merge.Client/Hris/PayrollRuns/Types/PayrollRunsListRequestShowEnumOrigins.cs b/src/Merge.Client/Hris/PayrollRuns/Types/PayrollRunsListRequestShowEnumOrigins.cs index 8a269661..0868bc09 100644 --- a/src/Merge.Client/Hris/PayrollRuns/Types/PayrollRunsListRequestShowEnumOrigins.cs +++ b/src/Merge.Client/Hris/PayrollRuns/Types/PayrollRunsListRequestShowEnumOrigins.cs @@ -1,7 +1,6 @@ using System.Runtime.Serialization; using System.Text.Json.Serialization; using Merge.Client.Core; -using Merge.Client.Hris; #nullable enable diff --git a/src/Merge.Client/Hris/PayrollRuns/Types/PayrollRunsRetrieveRequestRemoteFields.cs b/src/Merge.Client/Hris/PayrollRuns/Types/PayrollRunsRetrieveRequestRemoteFields.cs index 8e71ed92..30ac88be 100644 --- a/src/Merge.Client/Hris/PayrollRuns/Types/PayrollRunsRetrieveRequestRemoteFields.cs +++ b/src/Merge.Client/Hris/PayrollRuns/Types/PayrollRunsRetrieveRequestRemoteFields.cs @@ -1,7 +1,6 @@ using System.Runtime.Serialization; using System.Text.Json.Serialization; using Merge.Client.Core; -using Merge.Client.Hris; #nullable enable diff --git a/src/Merge.Client/Hris/PayrollRuns/Types/PayrollRunsRetrieveRequestShowEnumOrigins.cs b/src/Merge.Client/Hris/PayrollRuns/Types/PayrollRunsRetrieveRequestShowEnumOrigins.cs index 125230b6..50876b83 100644 --- a/src/Merge.Client/Hris/PayrollRuns/Types/PayrollRunsRetrieveRequestShowEnumOrigins.cs +++ b/src/Merge.Client/Hris/PayrollRuns/Types/PayrollRunsRetrieveRequestShowEnumOrigins.cs @@ -1,7 +1,6 @@ using System.Runtime.Serialization; using System.Text.Json.Serialization; using Merge.Client.Core; -using Merge.Client.Hris; #nullable enable diff --git a/src/Merge.Client/Hris/RegenerateKey/RegenerateKeyClient.cs b/src/Merge.Client/Hris/RegenerateKey/RegenerateKeyClient.cs index 9ed15ae1..18dae586 100644 --- a/src/Merge.Client/Hris/RegenerateKey/RegenerateKeyClient.cs +++ b/src/Merge.Client/Hris/RegenerateKey/RegenerateKeyClient.cs @@ -1,6 +1,6 @@ +using System.Net.Http; using System.Text.Json; -using Merge.Client; -using Merge.Client.Hris; +using Merge.Client.Core; #nullable enable @@ -18,21 +18,38 @@ public RegenerateKeyClient(RawClient client) /// /// Exchange remote keys. /// - public async Task CreateAsync(RemoteKeyForRegenerationRequest request) + public async Task CreateAsync( + RemoteKeyForRegenerationRequest request, + RequestOptions? options = null + ) { var response = await _client.MakeRequestAsync( new RawClient.JsonApiRequest { + BaseUrl = _client.Options.BaseUrl, Method = HttpMethod.Post, Path = "hris/v1/regenerate-key", - Body = request + Body = request, + Options = options } ); - string responseBody = await response.Raw.Content.ReadAsStringAsync(); - if (response.StatusCode >= 200 && response.StatusCode < 400) + var responseBody = await response.Raw.Content.ReadAsStringAsync(); + if (response.StatusCode is >= 200 and < 400) { - return JsonSerializer.Deserialize(responseBody); + try + { + return JsonUtils.Deserialize(responseBody)!; + } + catch (JsonException e) + { + throw new MergeException("Failed to deserialize response", e); + } } - throw new Exception(responseBody); + + throw new MergeApiException( + $"Error with status code {response.StatusCode}", + response.StatusCode, + JsonUtils.Deserialize(responseBody) + ); } } diff --git a/src/Merge.Client/Hris/RegenerateKey/Requests/RemoteKeyForRegenerationRequest.cs b/src/Merge.Client/Hris/RegenerateKey/Requests/RemoteKeyForRegenerationRequest.cs index 7176a7e0..0f949c65 100644 --- a/src/Merge.Client/Hris/RegenerateKey/Requests/RemoteKeyForRegenerationRequest.cs +++ b/src/Merge.Client/Hris/RegenerateKey/Requests/RemoteKeyForRegenerationRequest.cs @@ -4,11 +4,11 @@ namespace Merge.Client.Hris; -public class RemoteKeyForRegenerationRequest +public record RemoteKeyForRegenerationRequest { /// /// The name of the remote key /// [JsonPropertyName("name")] - public string Name { get; init; } + public required string Name { get; set; } } diff --git a/src/Merge.Client/Hris/Scopes/Requests/LinkedAccountCommonModelScopeDeserializerRequest.cs b/src/Merge.Client/Hris/Scopes/Requests/LinkedAccountCommonModelScopeDeserializerRequest.cs index c4482720..def62b2c 100644 --- a/src/Merge.Client/Hris/Scopes/Requests/LinkedAccountCommonModelScopeDeserializerRequest.cs +++ b/src/Merge.Client/Hris/Scopes/Requests/LinkedAccountCommonModelScopeDeserializerRequest.cs @@ -1,15 +1,15 @@ using System.Text.Json.Serialization; -using Merge.Client.Hris; #nullable enable namespace Merge.Client.Hris; -public class LinkedAccountCommonModelScopeDeserializerRequest +public record LinkedAccountCommonModelScopeDeserializerRequest { /// /// The common models you want to update the scopes for /// [JsonPropertyName("common_models")] - public IEnumerable CommonModels { get; init; } + public IEnumerable CommonModels { get; set; } = + new List(); } diff --git a/src/Merge.Client/Hris/Scopes/ScopesClient.cs b/src/Merge.Client/Hris/Scopes/ScopesClient.cs index ff362f99..51b20957 100644 --- a/src/Merge.Client/Hris/Scopes/ScopesClient.cs +++ b/src/Merge.Client/Hris/Scopes/ScopesClient.cs @@ -1,6 +1,6 @@ +using System.Net.Http; using System.Text.Json; -using Merge.Client; -using Merge.Client.Hris; +using Merge.Client.Core; #nullable enable @@ -18,63 +18,110 @@ public ScopesClient(RawClient client) /// /// Get the default permissions for Merge Common Models and fields across all Linked Accounts of a given category. [Learn more](https://help.merge.dev/en/articles/8828211-common-model-and-field-scopes). /// - public async Task DefaultScopesRetrieveAsync() + public async Task DefaultScopesRetrieveAsync( + RequestOptions? options = null + ) { var response = await _client.MakeRequestAsync( new RawClient.JsonApiRequest { + BaseUrl = _client.Options.BaseUrl, Method = HttpMethod.Get, - Path = "hris/v1/default-scopes" + Path = "hris/v1/default-scopes", + Options = options } ); - string responseBody = await response.Raw.Content.ReadAsStringAsync(); - if (response.StatusCode >= 200 && response.StatusCode < 400) + var responseBody = await response.Raw.Content.ReadAsStringAsync(); + if (response.StatusCode is >= 200 and < 400) { - return JsonSerializer.Deserialize(responseBody); + try + { + return JsonUtils.Deserialize(responseBody)!; + } + catch (JsonException e) + { + throw new MergeException("Failed to deserialize response", e); + } } - throw new Exception(responseBody); + + throw new MergeApiException( + $"Error with status code {response.StatusCode}", + response.StatusCode, + JsonUtils.Deserialize(responseBody) + ); } /// /// Get all available permissions for Merge Common Models and fields for a single Linked Account. [Learn more](https://help.merge.dev/en/articles/8828211-common-model-and-field-scopes). /// - public async Task LinkedAccountScopesRetrieveAsync() + public async Task LinkedAccountScopesRetrieveAsync( + RequestOptions? options = null + ) { var response = await _client.MakeRequestAsync( new RawClient.JsonApiRequest { + BaseUrl = _client.Options.BaseUrl, Method = HttpMethod.Get, - Path = "hris/v1/linked-account-scopes" + Path = "hris/v1/linked-account-scopes", + Options = options } ); - string responseBody = await response.Raw.Content.ReadAsStringAsync(); - if (response.StatusCode >= 200 && response.StatusCode < 400) + var responseBody = await response.Raw.Content.ReadAsStringAsync(); + if (response.StatusCode is >= 200 and < 400) { - return JsonSerializer.Deserialize(responseBody); + try + { + return JsonUtils.Deserialize(responseBody)!; + } + catch (JsonException e) + { + throw new MergeException("Failed to deserialize response", e); + } } - throw new Exception(responseBody); + + throw new MergeApiException( + $"Error with status code {response.StatusCode}", + response.StatusCode, + JsonUtils.Deserialize(responseBody) + ); } /// /// Update permissions for any Common Model or field for a single Linked Account. Any Scopes not set in this POST request will inherit the default Scopes. [Learn more](https://help.merge.dev/en/articles/8828211-common-model-and-field-scopes) /// public async Task LinkedAccountScopesCreateAsync( - LinkedAccountCommonModelScopeDeserializerRequest request + LinkedAccountCommonModelScopeDeserializerRequest request, + RequestOptions? options = null ) { var response = await _client.MakeRequestAsync( new RawClient.JsonApiRequest { + BaseUrl = _client.Options.BaseUrl, Method = HttpMethod.Post, Path = "hris/v1/linked-account-scopes", - Body = request + Body = request, + Options = options } ); - string responseBody = await response.Raw.Content.ReadAsStringAsync(); - if (response.StatusCode >= 200 && response.StatusCode < 400) + var responseBody = await response.Raw.Content.ReadAsStringAsync(); + if (response.StatusCode is >= 200 and < 400) { - return JsonSerializer.Deserialize(responseBody); + try + { + return JsonUtils.Deserialize(responseBody)!; + } + catch (JsonException e) + { + throw new MergeException("Failed to deserialize response", e); + } } - throw new Exception(responseBody); + + throw new MergeApiException( + $"Error with status code {response.StatusCode}", + response.StatusCode, + JsonUtils.Deserialize(responseBody) + ); } } diff --git a/src/Merge.Client/Hris/SyncStatus/Requests/SyncStatusListRequest.cs b/src/Merge.Client/Hris/SyncStatus/Requests/SyncStatusListRequest.cs index b3f49c5c..44418cc4 100644 --- a/src/Merge.Client/Hris/SyncStatus/Requests/SyncStatusListRequest.cs +++ b/src/Merge.Client/Hris/SyncStatus/Requests/SyncStatusListRequest.cs @@ -1,14 +1,14 @@ namespace Merge.Client.Hris; -public class SyncStatusListRequest +public record SyncStatusListRequest { /// /// The pagination cursor value. /// - public string? Cursor { get; init; } + public string? Cursor { get; set; } /// /// Number of results to return per page. /// - public int? PageSize { get; init; } + public int? PageSize { get; set; } } diff --git a/src/Merge.Client/Hris/SyncStatus/SyncStatusClient.cs b/src/Merge.Client/Hris/SyncStatus/SyncStatusClient.cs index 5af0bd55..d2960036 100644 --- a/src/Merge.Client/Hris/SyncStatus/SyncStatusClient.cs +++ b/src/Merge.Client/Hris/SyncStatus/SyncStatusClient.cs @@ -1,6 +1,6 @@ +using System.Net.Http; using System.Text.Json; -using Merge.Client; -using Merge.Client.Hris; +using Merge.Client.Core; #nullable enable @@ -18,7 +18,10 @@ public SyncStatusClient(RawClient client) /// /// Get syncing status. Possible values: `DISABLED`, `DONE`, `FAILED`, `PARTIALLY_SYNCED`, `PAUSED`, `SYNCING`. Learn more about sync status in our [Help Center](https://help.merge.dev/en/articles/8184193-merge-sync-statuses). /// - public async Task ListAsync(SyncStatusListRequest request) + public async Task ListAsync( + SyncStatusListRequest request, + RequestOptions? options = null + ) { var _query = new Dictionary() { }; if (request.Cursor != null) @@ -32,16 +35,30 @@ public async Task ListAsync(SyncStatusListRequest reque var response = await _client.MakeRequestAsync( new RawClient.JsonApiRequest { + BaseUrl = _client.Options.BaseUrl, Method = HttpMethod.Get, Path = "hris/v1/sync-status", - Query = _query + Query = _query, + Options = options } ); - string responseBody = await response.Raw.Content.ReadAsStringAsync(); - if (response.StatusCode >= 200 && response.StatusCode < 400) + var responseBody = await response.Raw.Content.ReadAsStringAsync(); + if (response.StatusCode is >= 200 and < 400) { - return JsonSerializer.Deserialize(responseBody); + try + { + return JsonUtils.Deserialize(responseBody)!; + } + catch (JsonException e) + { + throw new MergeException("Failed to deserialize response", e); + } } - throw new Exception(responseBody); + + throw new MergeApiException( + $"Error with status code {response.StatusCode}", + response.StatusCode, + JsonUtils.Deserialize(responseBody) + ); } } diff --git a/src/Merge.Client/Hris/Teams/Requests/TeamsListRequest.cs b/src/Merge.Client/Hris/Teams/Requests/TeamsListRequest.cs index c26b6a4e..f27fc3bd 100644 --- a/src/Merge.Client/Hris/Teams/Requests/TeamsListRequest.cs +++ b/src/Merge.Client/Hris/Teams/Requests/TeamsListRequest.cs @@ -1,59 +1,59 @@ namespace Merge.Client.Hris; -public class TeamsListRequest +public record TeamsListRequest { /// /// If provided, will only return objects created after this datetime. /// - public DateTime? CreatedAfter { get; init; } + public DateTime? CreatedAfter { get; set; } /// /// If provided, will only return objects created before this datetime. /// - public DateTime? CreatedBefore { get; init; } + public DateTime? CreatedBefore { get; set; } /// /// The pagination cursor value. /// - public string? Cursor { get; init; } + public string? Cursor { get; set; } /// /// Which relations should be returned in expanded form. Multiple relation names should be comma separated without spaces. /// - public string? Expand { get; init; } + public string? Expand { get; set; } /// /// Whether to include data that was marked as deleted by third party webhooks. /// - public bool? IncludeDeletedData { get; init; } + public bool? IncludeDeletedData { get; set; } /// /// Whether to include the original data Merge fetched from the third-party to produce these models. /// - public bool? IncludeRemoteData { get; init; } + public bool? IncludeRemoteData { get; set; } /// /// If provided, only objects synced by Merge after this date time will be returned. /// - public DateTime? ModifiedAfter { get; init; } + public DateTime? ModifiedAfter { get; set; } /// /// If provided, only objects synced by Merge before this date time will be returned. /// - public DateTime? ModifiedBefore { get; init; } + public DateTime? ModifiedBefore { get; set; } /// /// Number of results to return per page. /// - public int? PageSize { get; init; } + public int? PageSize { get; set; } /// /// If provided, will only return teams with this parent team. /// - public string? ParentTeamId { get; init; } + public string? ParentTeamId { get; set; } /// /// The API provider's ID for the given object. /// - public string? RemoteId { get; init; } + public string? RemoteId { get; set; } } diff --git a/src/Merge.Client/Hris/Teams/Requests/TeamsRetrieveRequest.cs b/src/Merge.Client/Hris/Teams/Requests/TeamsRetrieveRequest.cs index aa6ada45..f2ddb4c6 100644 --- a/src/Merge.Client/Hris/Teams/Requests/TeamsRetrieveRequest.cs +++ b/src/Merge.Client/Hris/Teams/Requests/TeamsRetrieveRequest.cs @@ -1,14 +1,14 @@ namespace Merge.Client.Hris; -public class TeamsRetrieveRequest +public record TeamsRetrieveRequest { /// /// Which relations should be returned in expanded form. Multiple relation names should be comma separated without spaces. /// - public string? Expand { get; init; } + public string? Expand { get; set; } /// /// Whether to include the original data Merge fetched from the third-party to produce these models. /// - public bool? IncludeRemoteData { get; init; } + public bool? IncludeRemoteData { get; set; } } diff --git a/src/Merge.Client/Hris/Teams/TeamsClient.cs b/src/Merge.Client/Hris/Teams/TeamsClient.cs index ba9eaa73..efad364c 100644 --- a/src/Merge.Client/Hris/Teams/TeamsClient.cs +++ b/src/Merge.Client/Hris/Teams/TeamsClient.cs @@ -1,6 +1,6 @@ +using System.Net.Http; using System.Text.Json; -using Merge.Client; -using Merge.Client.Hris; +using Merge.Client.Core; #nullable enable @@ -18,16 +18,21 @@ public TeamsClient(RawClient client) /// /// Returns a list of `Team` objects. /// - public async Task ListAsync(TeamsListRequest request) + public async Task ListAsync( + TeamsListRequest request, + RequestOptions? options = null + ) { var _query = new Dictionary() { }; if (request.CreatedAfter != null) { - _query["created_after"] = request.CreatedAfter.Value.ToString("o0"); + _query["created_after"] = request.CreatedAfter.Value.ToString(Constants.DateTimeFormat); } if (request.CreatedBefore != null) { - _query["created_before"] = request.CreatedBefore.Value.ToString("o0"); + _query["created_before"] = request.CreatedBefore.Value.ToString( + Constants.DateTimeFormat + ); } if (request.Cursor != null) { @@ -47,11 +52,15 @@ public async Task ListAsync(TeamsListRequest request) } if (request.ModifiedAfter != null) { - _query["modified_after"] = request.ModifiedAfter.Value.ToString("o0"); + _query["modified_after"] = request.ModifiedAfter.Value.ToString( + Constants.DateTimeFormat + ); } if (request.ModifiedBefore != null) { - _query["modified_before"] = request.ModifiedBefore.Value.ToString("o0"); + _query["modified_before"] = request.ModifiedBefore.Value.ToString( + Constants.DateTimeFormat + ); } if (request.PageSize != null) { @@ -68,23 +77,41 @@ public async Task ListAsync(TeamsListRequest request) var response = await _client.MakeRequestAsync( new RawClient.JsonApiRequest { + BaseUrl = _client.Options.BaseUrl, Method = HttpMethod.Get, Path = "hris/v1/teams", - Query = _query + Query = _query, + Options = options } ); - string responseBody = await response.Raw.Content.ReadAsStringAsync(); - if (response.StatusCode >= 200 && response.StatusCode < 400) + var responseBody = await response.Raw.Content.ReadAsStringAsync(); + if (response.StatusCode is >= 200 and < 400) { - return JsonSerializer.Deserialize(responseBody); + try + { + return JsonUtils.Deserialize(responseBody)!; + } + catch (JsonException e) + { + throw new MergeException("Failed to deserialize response", e); + } } - throw new Exception(responseBody); + + throw new MergeApiException( + $"Error with status code {response.StatusCode}", + response.StatusCode, + JsonUtils.Deserialize(responseBody) + ); } /// /// Returns a `Team` object with the given `id`. /// - public async Task RetrieveAsync(string id, TeamsRetrieveRequest request) + public async Task RetrieveAsync( + string id, + TeamsRetrieveRequest request, + RequestOptions? options = null + ) { var _query = new Dictionary() { }; if (request.Expand != null) @@ -98,16 +125,30 @@ public async Task RetrieveAsync(string id, TeamsRetrieveRequest request) var response = await _client.MakeRequestAsync( new RawClient.JsonApiRequest { + BaseUrl = _client.Options.BaseUrl, Method = HttpMethod.Get, Path = $"hris/v1/teams/{id}", - Query = _query + Query = _query, + Options = options } ); - string responseBody = await response.Raw.Content.ReadAsStringAsync(); - if (response.StatusCode >= 200 && response.StatusCode < 400) + var responseBody = await response.Raw.Content.ReadAsStringAsync(); + if (response.StatusCode is >= 200 and < 400) { - return JsonSerializer.Deserialize(responseBody); + try + { + return JsonUtils.Deserialize(responseBody)!; + } + catch (JsonException e) + { + throw new MergeException("Failed to deserialize response", e); + } } - throw new Exception(responseBody); + + throw new MergeApiException( + $"Error with status code {response.StatusCode}", + response.StatusCode, + JsonUtils.Deserialize(responseBody) + ); } } diff --git a/src/Merge.Client/Hris/TimeOff/Requests/TimeOffEndpointRequest.cs b/src/Merge.Client/Hris/TimeOff/Requests/TimeOffEndpointRequest.cs index 0d7b2abd..34ca3366 100644 --- a/src/Merge.Client/Hris/TimeOff/Requests/TimeOffEndpointRequest.cs +++ b/src/Merge.Client/Hris/TimeOff/Requests/TimeOffEndpointRequest.cs @@ -1,20 +1,16 @@ -using Merge.Client.Hris; - -#nullable enable - namespace Merge.Client.Hris; -public class TimeOffEndpointRequest +public record TimeOffEndpointRequest { /// /// Whether to include debug fields (such as log file links) in the response. /// - public bool? IsDebugMode { get; init; } + public bool? IsDebugMode { get; set; } /// /// Whether or not third-party updates should be run asynchronously. /// - public bool? RunAsync { get; init; } + public bool? RunAsync { get; set; } - public TimeOffRequest Model { get; init; } + public required TimeOffRequest Model { get; set; } } diff --git a/src/Merge.Client/Hris/TimeOff/Requests/TimeOffListRequest.cs b/src/Merge.Client/Hris/TimeOff/Requests/TimeOffListRequest.cs index dc83d724..2a957943 100644 --- a/src/Merge.Client/Hris/TimeOff/Requests/TimeOffListRequest.cs +++ b/src/Merge.Client/Hris/TimeOff/Requests/TimeOffListRequest.cs @@ -1,85 +1,81 @@ -using Merge.Client.Hris; - -#nullable enable - namespace Merge.Client.Hris; -public class TimeOffListRequest +public record TimeOffListRequest { /// /// If provided, will only return time off for this approver. /// - public string? ApproverId { get; init; } + public string? ApproverId { get; set; } /// /// If provided, will only return objects created after this datetime. /// - public DateTime? CreatedAfter { get; init; } + public DateTime? CreatedAfter { get; set; } /// /// If provided, will only return objects created before this datetime. /// - public DateTime? CreatedBefore { get; init; } + public DateTime? CreatedBefore { get; set; } /// /// The pagination cursor value. /// - public string? Cursor { get; init; } + public string? Cursor { get; set; } /// /// If provided, will only return time off for this employee. /// - public string? EmployeeId { get; init; } + public string? EmployeeId { get; set; } /// /// If provided, will only return employees that ended after this datetime. /// - public DateTime? EndedAfter { get; init; } + public DateTime? EndedAfter { get; set; } /// /// If provided, will only return time-offs that ended before this datetime. /// - public DateTime? EndedBefore { get; init; } + public DateTime? EndedBefore { get; set; } /// /// Which relations should be returned in expanded form. Multiple relation names should be comma separated without spaces. /// - public TimeOffListRequestExpand? Expand { get; init; } + public TimeOffListRequestExpand? Expand { get; set; } /// /// Whether to include data that was marked as deleted by third party webhooks. /// - public bool? IncludeDeletedData { get; init; } + public bool? IncludeDeletedData { get; set; } /// /// Whether to include the original data Merge fetched from the third-party to produce these models. /// - public bool? IncludeRemoteData { get; init; } + public bool? IncludeRemoteData { get; set; } /// /// If provided, only objects synced by Merge after this date time will be returned. /// - public DateTime? ModifiedAfter { get; init; } + public DateTime? ModifiedAfter { get; set; } /// /// If provided, only objects synced by Merge before this date time will be returned. /// - public DateTime? ModifiedBefore { get; init; } + public DateTime? ModifiedBefore { get; set; } /// /// Number of results to return per page. /// - public int? PageSize { get; init; } + public int? PageSize { get; set; } /// /// Deprecated. Use show_enum_origins. /// - public TimeOffListRequestRemoteFields? RemoteFields { get; init; } + public TimeOffListRequestRemoteFields? RemoteFields { get; set; } /// /// The API provider's ID for the given object. /// - public string? RemoteId { get; init; } + public string? RemoteId { get; set; } /// /// If provided, will only return TimeOff with this request type. Options: ('VACATION', 'SICK', 'PERSONAL', 'JURY_DUTY', 'VOLUNTEER', 'BEREAVEMENT') @@ -91,22 +87,22 @@ public class TimeOffListRequest /// - `VOLUNTEER` - VOLUNTEER /// - `BEREAVEMENT` - BEREAVEMENT /// - public TimeOffListRequestRequestType? RequestType { get; init; } + public TimeOffListRequestRequestType? RequestType { get; set; } /// /// A comma separated list of enum field names for which you'd like the original values to be returned, instead of Merge's normalized enum values. [Learn more](https://help.merge.dev/en/articles/8950958-show_enum_origins-query-parameter) /// - public TimeOffListRequestShowEnumOrigins? ShowEnumOrigins { get; init; } + public TimeOffListRequestShowEnumOrigins? ShowEnumOrigins { get; set; } /// /// If provided, will only return time-offs that started after this datetime. /// - public DateTime? StartedAfter { get; init; } + public DateTime? StartedAfter { get; set; } /// /// If provided, will only return time-offs that started before this datetime. /// - public DateTime? StartedBefore { get; init; } + public DateTime? StartedBefore { get; set; } /// /// If provided, will only return TimeOff with this status. Options: ('REQUESTED', 'APPROVED', 'DECLINED', 'CANCELLED', 'DELETED') @@ -117,5 +113,5 @@ public class TimeOffListRequest /// - `CANCELLED` - CANCELLED /// - `DELETED` - DELETED /// - public TimeOffListRequestStatus? Status { get; init; } + public TimeOffListRequestStatus? Status { get; set; } } diff --git a/src/Merge.Client/Hris/TimeOff/Requests/TimeOffRetrieveRequest.cs b/src/Merge.Client/Hris/TimeOff/Requests/TimeOffRetrieveRequest.cs index b98a0690..fe5b86b6 100644 --- a/src/Merge.Client/Hris/TimeOff/Requests/TimeOffRetrieveRequest.cs +++ b/src/Merge.Client/Hris/TimeOff/Requests/TimeOffRetrieveRequest.cs @@ -1,28 +1,24 @@ -using Merge.Client.Hris; - -#nullable enable - namespace Merge.Client.Hris; -public class TimeOffRetrieveRequest +public record TimeOffRetrieveRequest { /// /// Which relations should be returned in expanded form. Multiple relation names should be comma separated without spaces. /// - public TimeOffRetrieveRequestExpand? Expand { get; init; } + public TimeOffRetrieveRequestExpand? Expand { get; set; } /// /// Whether to include the original data Merge fetched from the third-party to produce these models. /// - public bool? IncludeRemoteData { get; init; } + public bool? IncludeRemoteData { get; set; } /// /// Deprecated. Use show_enum_origins. /// - public TimeOffRetrieveRequestRemoteFields? RemoteFields { get; init; } + public TimeOffRetrieveRequestRemoteFields? RemoteFields { get; set; } /// /// A comma separated list of enum field names for which you'd like the original values to be returned, instead of Merge's normalized enum values. [Learn more](https://help.merge.dev/en/articles/8950958-show_enum_origins-query-parameter) /// - public TimeOffRetrieveRequestShowEnumOrigins? ShowEnumOrigins { get; init; } + public TimeOffRetrieveRequestShowEnumOrigins? ShowEnumOrigins { get; set; } } diff --git a/src/Merge.Client/Hris/TimeOff/TimeOffClient.cs b/src/Merge.Client/Hris/TimeOff/TimeOffClient.cs index 7a2fe644..2d477fb2 100644 --- a/src/Merge.Client/Hris/TimeOff/TimeOffClient.cs +++ b/src/Merge.Client/Hris/TimeOff/TimeOffClient.cs @@ -1,6 +1,6 @@ +using System.Net.Http; using System.Text.Json; -using Merge.Client; -using Merge.Client.Hris; +using Merge.Client.Core; #nullable enable @@ -18,7 +18,10 @@ public TimeOffClient(RawClient client) /// /// Returns a list of `TimeOff` objects. /// - public async Task ListAsync(TimeOffListRequest request) + public async Task ListAsync( + TimeOffListRequest request, + RequestOptions? options = null + ) { var _query = new Dictionary() { }; if (request.ApproverId != null) @@ -27,11 +30,13 @@ public async Task ListAsync(TimeOffListRequest request) } if (request.CreatedAfter != null) { - _query["created_after"] = request.CreatedAfter.Value.ToString("o0"); + _query["created_after"] = request.CreatedAfter.Value.ToString(Constants.DateTimeFormat); } if (request.CreatedBefore != null) { - _query["created_before"] = request.CreatedBefore.Value.ToString("o0"); + _query["created_before"] = request.CreatedBefore.Value.ToString( + Constants.DateTimeFormat + ); } if (request.Cursor != null) { @@ -43,11 +48,11 @@ public async Task ListAsync(TimeOffListRequest request) } if (request.EndedAfter != null) { - _query["ended_after"] = request.EndedAfter.Value.ToString("o0"); + _query["ended_after"] = request.EndedAfter.Value.ToString(Constants.DateTimeFormat); } if (request.EndedBefore != null) { - _query["ended_before"] = request.EndedBefore.Value.ToString("o0"); + _query["ended_before"] = request.EndedBefore.Value.ToString(Constants.DateTimeFormat); } if (request.Expand != null) { @@ -63,11 +68,15 @@ public async Task ListAsync(TimeOffListRequest request) } if (request.ModifiedAfter != null) { - _query["modified_after"] = request.ModifiedAfter.Value.ToString("o0"); + _query["modified_after"] = request.ModifiedAfter.Value.ToString( + Constants.DateTimeFormat + ); } if (request.ModifiedBefore != null) { - _query["modified_before"] = request.ModifiedBefore.Value.ToString("o0"); + _query["modified_before"] = request.ModifiedBefore.Value.ToString( + Constants.DateTimeFormat + ); } if (request.PageSize != null) { @@ -91,11 +100,13 @@ public async Task ListAsync(TimeOffListRequest request) } if (request.StartedAfter != null) { - _query["started_after"] = request.StartedAfter.Value.ToString("o0"); + _query["started_after"] = request.StartedAfter.Value.ToString(Constants.DateTimeFormat); } if (request.StartedBefore != null) { - _query["started_before"] = request.StartedBefore.Value.ToString("o0"); + _query["started_before"] = request.StartedBefore.Value.ToString( + Constants.DateTimeFormat + ); } if (request.Status != null) { @@ -104,23 +115,40 @@ public async Task ListAsync(TimeOffListRequest request) var response = await _client.MakeRequestAsync( new RawClient.JsonApiRequest { + BaseUrl = _client.Options.BaseUrl, Method = HttpMethod.Get, Path = "hris/v1/time-off", - Query = _query + Query = _query, + Options = options } ); - string responseBody = await response.Raw.Content.ReadAsStringAsync(); - if (response.StatusCode >= 200 && response.StatusCode < 400) + var responseBody = await response.Raw.Content.ReadAsStringAsync(); + if (response.StatusCode is >= 200 and < 400) { - return JsonSerializer.Deserialize(responseBody); + try + { + return JsonUtils.Deserialize(responseBody)!; + } + catch (JsonException e) + { + throw new MergeException("Failed to deserialize response", e); + } } - throw new Exception(responseBody); + + throw new MergeApiException( + $"Error with status code {response.StatusCode}", + response.StatusCode, + JsonUtils.Deserialize(responseBody) + ); } /// /// Creates a `TimeOff` object with the given values. /// - public async Task CreateAsync(TimeOffEndpointRequest request) + public async Task CreateAsync( + TimeOffEndpointRequest request, + RequestOptions? options = null + ) { var _query = new Dictionary() { }; if (request.IsDebugMode != null) @@ -134,23 +162,41 @@ public async Task CreateAsync(TimeOffEndpointRequest request) var response = await _client.MakeRequestAsync( new RawClient.JsonApiRequest { + BaseUrl = _client.Options.BaseUrl, Method = HttpMethod.Post, Path = "hris/v1/time-off", - Query = _query + Query = _query, + Options = options } ); - string responseBody = await response.Raw.Content.ReadAsStringAsync(); - if (response.StatusCode >= 200 && response.StatusCode < 400) + var responseBody = await response.Raw.Content.ReadAsStringAsync(); + if (response.StatusCode is >= 200 and < 400) { - return JsonSerializer.Deserialize(responseBody); + try + { + return JsonUtils.Deserialize(responseBody)!; + } + catch (JsonException e) + { + throw new MergeException("Failed to deserialize response", e); + } } - throw new Exception(responseBody); + + throw new MergeApiException( + $"Error with status code {response.StatusCode}", + response.StatusCode, + JsonUtils.Deserialize(responseBody) + ); } /// /// Returns a `TimeOff` object with the given `id`. /// - public async Task RetrieveAsync(string id, TimeOffRetrieveRequest request) + public async Task RetrieveAsync( + string id, + TimeOffRetrieveRequest request, + RequestOptions? options = null + ) { var _query = new Dictionary() { }; if (request.Expand != null) @@ -172,36 +218,64 @@ public async Task RetrieveAsync(string id, TimeOffRetrieveRequest reque var response = await _client.MakeRequestAsync( new RawClient.JsonApiRequest { + BaseUrl = _client.Options.BaseUrl, Method = HttpMethod.Get, Path = $"hris/v1/time-off/{id}", - Query = _query + Query = _query, + Options = options } ); - string responseBody = await response.Raw.Content.ReadAsStringAsync(); - if (response.StatusCode >= 200 && response.StatusCode < 400) + var responseBody = await response.Raw.Content.ReadAsStringAsync(); + if (response.StatusCode is >= 200 and < 400) { - return JsonSerializer.Deserialize(responseBody); + try + { + return JsonUtils.Deserialize(responseBody)!; + } + catch (JsonException e) + { + throw new MergeException("Failed to deserialize response", e); + } } - throw new Exception(responseBody); + + throw new MergeApiException( + $"Error with status code {response.StatusCode}", + response.StatusCode, + JsonUtils.Deserialize(responseBody) + ); } /// /// Returns metadata for `TimeOff` POSTs. /// - public async Task MetaPostRetrieveAsync() + public async Task MetaPostRetrieveAsync(RequestOptions? options = null) { var response = await _client.MakeRequestAsync( new RawClient.JsonApiRequest { + BaseUrl = _client.Options.BaseUrl, Method = HttpMethod.Get, - Path = "hris/v1/time-off/meta/post" + Path = "hris/v1/time-off/meta/post", + Options = options } ); - string responseBody = await response.Raw.Content.ReadAsStringAsync(); - if (response.StatusCode >= 200 && response.StatusCode < 400) + var responseBody = await response.Raw.Content.ReadAsStringAsync(); + if (response.StatusCode is >= 200 and < 400) { - return JsonSerializer.Deserialize(responseBody); + try + { + return JsonUtils.Deserialize(responseBody)!; + } + catch (JsonException e) + { + throw new MergeException("Failed to deserialize response", e); + } } - throw new Exception(responseBody); + + throw new MergeApiException( + $"Error with status code {response.StatusCode}", + response.StatusCode, + JsonUtils.Deserialize(responseBody) + ); } } diff --git a/src/Merge.Client/Hris/TimeOff/Types/TimeOffListRequestExpand.cs b/src/Merge.Client/Hris/TimeOff/Types/TimeOffListRequestExpand.cs index 60bb69cf..9023b441 100644 --- a/src/Merge.Client/Hris/TimeOff/Types/TimeOffListRequestExpand.cs +++ b/src/Merge.Client/Hris/TimeOff/Types/TimeOffListRequestExpand.cs @@ -1,7 +1,6 @@ using System.Runtime.Serialization; using System.Text.Json.Serialization; using Merge.Client.Core; -using Merge.Client.Hris; #nullable enable diff --git a/src/Merge.Client/Hris/TimeOff/Types/TimeOffListRequestRemoteFields.cs b/src/Merge.Client/Hris/TimeOff/Types/TimeOffListRequestRemoteFields.cs index 6607d014..98348228 100644 --- a/src/Merge.Client/Hris/TimeOff/Types/TimeOffListRequestRemoteFields.cs +++ b/src/Merge.Client/Hris/TimeOff/Types/TimeOffListRequestRemoteFields.cs @@ -1,7 +1,6 @@ using System.Runtime.Serialization; using System.Text.Json.Serialization; using Merge.Client.Core; -using Merge.Client.Hris; #nullable enable diff --git a/src/Merge.Client/Hris/TimeOff/Types/TimeOffListRequestRequestType.cs b/src/Merge.Client/Hris/TimeOff/Types/TimeOffListRequestRequestType.cs index 39875182..8859c5b7 100644 --- a/src/Merge.Client/Hris/TimeOff/Types/TimeOffListRequestRequestType.cs +++ b/src/Merge.Client/Hris/TimeOff/Types/TimeOffListRequestRequestType.cs @@ -1,7 +1,6 @@ using System.Runtime.Serialization; using System.Text.Json.Serialization; using Merge.Client.Core; -using Merge.Client.Hris; #nullable enable diff --git a/src/Merge.Client/Hris/TimeOff/Types/TimeOffListRequestShowEnumOrigins.cs b/src/Merge.Client/Hris/TimeOff/Types/TimeOffListRequestShowEnumOrigins.cs index cb358dd8..d6023861 100644 --- a/src/Merge.Client/Hris/TimeOff/Types/TimeOffListRequestShowEnumOrigins.cs +++ b/src/Merge.Client/Hris/TimeOff/Types/TimeOffListRequestShowEnumOrigins.cs @@ -1,7 +1,6 @@ using System.Runtime.Serialization; using System.Text.Json.Serialization; using Merge.Client.Core; -using Merge.Client.Hris; #nullable enable diff --git a/src/Merge.Client/Hris/TimeOff/Types/TimeOffListRequestStatus.cs b/src/Merge.Client/Hris/TimeOff/Types/TimeOffListRequestStatus.cs index 6f633bb6..986e84a9 100644 --- a/src/Merge.Client/Hris/TimeOff/Types/TimeOffListRequestStatus.cs +++ b/src/Merge.Client/Hris/TimeOff/Types/TimeOffListRequestStatus.cs @@ -1,7 +1,6 @@ using System.Runtime.Serialization; using System.Text.Json.Serialization; using Merge.Client.Core; -using Merge.Client.Hris; #nullable enable diff --git a/src/Merge.Client/Hris/TimeOff/Types/TimeOffRetrieveRequestExpand.cs b/src/Merge.Client/Hris/TimeOff/Types/TimeOffRetrieveRequestExpand.cs index 1971ba7b..2c8b56bb 100644 --- a/src/Merge.Client/Hris/TimeOff/Types/TimeOffRetrieveRequestExpand.cs +++ b/src/Merge.Client/Hris/TimeOff/Types/TimeOffRetrieveRequestExpand.cs @@ -1,7 +1,6 @@ using System.Runtime.Serialization; using System.Text.Json.Serialization; using Merge.Client.Core; -using Merge.Client.Hris; #nullable enable diff --git a/src/Merge.Client/Hris/TimeOff/Types/TimeOffRetrieveRequestRemoteFields.cs b/src/Merge.Client/Hris/TimeOff/Types/TimeOffRetrieveRequestRemoteFields.cs index 69a0acc9..a4b56043 100644 --- a/src/Merge.Client/Hris/TimeOff/Types/TimeOffRetrieveRequestRemoteFields.cs +++ b/src/Merge.Client/Hris/TimeOff/Types/TimeOffRetrieveRequestRemoteFields.cs @@ -1,7 +1,6 @@ using System.Runtime.Serialization; using System.Text.Json.Serialization; using Merge.Client.Core; -using Merge.Client.Hris; #nullable enable diff --git a/src/Merge.Client/Hris/TimeOff/Types/TimeOffRetrieveRequestShowEnumOrigins.cs b/src/Merge.Client/Hris/TimeOff/Types/TimeOffRetrieveRequestShowEnumOrigins.cs index 185136f6..bdb6bb45 100644 --- a/src/Merge.Client/Hris/TimeOff/Types/TimeOffRetrieveRequestShowEnumOrigins.cs +++ b/src/Merge.Client/Hris/TimeOff/Types/TimeOffRetrieveRequestShowEnumOrigins.cs @@ -1,7 +1,6 @@ using System.Runtime.Serialization; using System.Text.Json.Serialization; using Merge.Client.Core; -using Merge.Client.Hris; #nullable enable diff --git a/src/Merge.Client/Hris/TimeOffBalances/Requests/TimeOffBalancesListRequest.cs b/src/Merge.Client/Hris/TimeOffBalances/Requests/TimeOffBalancesListRequest.cs index 755283bd..9681d640 100644 --- a/src/Merge.Client/Hris/TimeOffBalances/Requests/TimeOffBalancesListRequest.cs +++ b/src/Merge.Client/Hris/TimeOffBalances/Requests/TimeOffBalancesListRequest.cs @@ -1,60 +1,56 @@ -using Merge.Client.Hris; - -#nullable enable - namespace Merge.Client.Hris; -public class TimeOffBalancesListRequest +public record TimeOffBalancesListRequest { /// /// If provided, will only return objects created after this datetime. /// - public DateTime? CreatedAfter { get; init; } + public DateTime? CreatedAfter { get; set; } /// /// If provided, will only return objects created before this datetime. /// - public DateTime? CreatedBefore { get; init; } + public DateTime? CreatedBefore { get; set; } /// /// The pagination cursor value. /// - public string? Cursor { get; init; } + public string? Cursor { get; set; } /// /// If provided, will only return time off balances for this employee. /// - public string? EmployeeId { get; init; } + public string? EmployeeId { get; set; } /// /// Which relations should be returned in expanded form. Multiple relation names should be comma separated without spaces. /// - public string? Expand { get; init; } + public string? Expand { get; set; } /// /// Whether to include data that was marked as deleted by third party webhooks. /// - public bool? IncludeDeletedData { get; init; } + public bool? IncludeDeletedData { get; set; } /// /// Whether to include the original data Merge fetched from the third-party to produce these models. /// - public bool? IncludeRemoteData { get; init; } + public bool? IncludeRemoteData { get; set; } /// /// If provided, only objects synced by Merge after this date time will be returned. /// - public DateTime? ModifiedAfter { get; init; } + public DateTime? ModifiedAfter { get; set; } /// /// If provided, only objects synced by Merge before this date time will be returned. /// - public DateTime? ModifiedBefore { get; init; } + public DateTime? ModifiedBefore { get; set; } /// /// Number of results to return per page. /// - public int? PageSize { get; init; } + public int? PageSize { get; set; } /// /// If provided, will only return TimeOffBalance with this policy type. Options: ('VACATION', 'SICK', 'PERSONAL', 'JURY_DUTY', 'VOLUNTEER', 'BEREAVEMENT') @@ -66,20 +62,20 @@ public class TimeOffBalancesListRequest /// - `VOLUNTEER` - VOLUNTEER /// - `BEREAVEMENT` - BEREAVEMENT /// - public TimeOffBalancesListRequestPolicyType? PolicyType { get; init; } + public TimeOffBalancesListRequestPolicyType? PolicyType { get; set; } /// /// Deprecated. Use show_enum_origins. /// - public string? RemoteFields { get; init; } + public string? RemoteFields { get; set; } /// /// The API provider's ID for the given object. /// - public string? RemoteId { get; init; } + public string? RemoteId { get; set; } /// /// A comma separated list of enum field names for which you'd like the original values to be returned, instead of Merge's normalized enum values. [Learn more](https://help.merge.dev/en/articles/8950958-show_enum_origins-query-parameter) /// - public string? ShowEnumOrigins { get; init; } + public string? ShowEnumOrigins { get; set; } } diff --git a/src/Merge.Client/Hris/TimeOffBalances/Requests/TimeOffBalancesRetrieveRequest.cs b/src/Merge.Client/Hris/TimeOffBalances/Requests/TimeOffBalancesRetrieveRequest.cs index 2f67f4bf..ddc791f1 100644 --- a/src/Merge.Client/Hris/TimeOffBalances/Requests/TimeOffBalancesRetrieveRequest.cs +++ b/src/Merge.Client/Hris/TimeOffBalances/Requests/TimeOffBalancesRetrieveRequest.cs @@ -1,24 +1,24 @@ namespace Merge.Client.Hris; -public class TimeOffBalancesRetrieveRequest +public record TimeOffBalancesRetrieveRequest { /// /// Which relations should be returned in expanded form. Multiple relation names should be comma separated without spaces. /// - public string? Expand { get; init; } + public string? Expand { get; set; } /// /// Whether to include the original data Merge fetched from the third-party to produce these models. /// - public bool? IncludeRemoteData { get; init; } + public bool? IncludeRemoteData { get; set; } /// /// Deprecated. Use show_enum_origins. /// - public string? RemoteFields { get; init; } + public string? RemoteFields { get; set; } /// /// A comma separated list of enum field names for which you'd like the original values to be returned, instead of Merge's normalized enum values. [Learn more](https://help.merge.dev/en/articles/8950958-show_enum_origins-query-parameter) /// - public string? ShowEnumOrigins { get; init; } + public string? ShowEnumOrigins { get; set; } } diff --git a/src/Merge.Client/Hris/TimeOffBalances/TimeOffBalancesClient.cs b/src/Merge.Client/Hris/TimeOffBalances/TimeOffBalancesClient.cs index 2f0c383c..90db31c5 100644 --- a/src/Merge.Client/Hris/TimeOffBalances/TimeOffBalancesClient.cs +++ b/src/Merge.Client/Hris/TimeOffBalances/TimeOffBalancesClient.cs @@ -1,6 +1,6 @@ +using System.Net.Http; using System.Text.Json; -using Merge.Client; -using Merge.Client.Hris; +using Merge.Client.Core; #nullable enable @@ -18,16 +18,21 @@ public TimeOffBalancesClient(RawClient client) /// /// Returns a list of `TimeOffBalance` objects. /// - public async Task ListAsync(TimeOffBalancesListRequest request) + public async Task ListAsync( + TimeOffBalancesListRequest request, + RequestOptions? options = null + ) { var _query = new Dictionary() { }; if (request.CreatedAfter != null) { - _query["created_after"] = request.CreatedAfter.Value.ToString("o0"); + _query["created_after"] = request.CreatedAfter.Value.ToString(Constants.DateTimeFormat); } if (request.CreatedBefore != null) { - _query["created_before"] = request.CreatedBefore.Value.ToString("o0"); + _query["created_before"] = request.CreatedBefore.Value.ToString( + Constants.DateTimeFormat + ); } if (request.Cursor != null) { @@ -51,11 +56,15 @@ public async Task ListAsync(TimeOffBalancesListRequ } if (request.ModifiedAfter != null) { - _query["modified_after"] = request.ModifiedAfter.Value.ToString("o0"); + _query["modified_after"] = request.ModifiedAfter.Value.ToString( + Constants.DateTimeFormat + ); } if (request.ModifiedBefore != null) { - _query["modified_before"] = request.ModifiedBefore.Value.ToString("o0"); + _query["modified_before"] = request.ModifiedBefore.Value.ToString( + Constants.DateTimeFormat + ); } if (request.PageSize != null) { @@ -80,17 +89,31 @@ public async Task ListAsync(TimeOffBalancesListRequ var response = await _client.MakeRequestAsync( new RawClient.JsonApiRequest { + BaseUrl = _client.Options.BaseUrl, Method = HttpMethod.Get, Path = "hris/v1/time-off-balances", - Query = _query + Query = _query, + Options = options } ); - string responseBody = await response.Raw.Content.ReadAsStringAsync(); - if (response.StatusCode >= 200 && response.StatusCode < 400) + var responseBody = await response.Raw.Content.ReadAsStringAsync(); + if (response.StatusCode is >= 200 and < 400) { - return JsonSerializer.Deserialize(responseBody); + try + { + return JsonUtils.Deserialize(responseBody)!; + } + catch (JsonException e) + { + throw new MergeException("Failed to deserialize response", e); + } } - throw new Exception(responseBody); + + throw new MergeApiException( + $"Error with status code {response.StatusCode}", + response.StatusCode, + JsonUtils.Deserialize(responseBody) + ); } /// @@ -98,7 +121,8 @@ public async Task ListAsync(TimeOffBalancesListRequ /// public async Task RetrieveAsync( string id, - TimeOffBalancesRetrieveRequest request + TimeOffBalancesRetrieveRequest request, + RequestOptions? options = null ) { var _query = new Dictionary() { }; @@ -121,16 +145,30 @@ TimeOffBalancesRetrieveRequest request var response = await _client.MakeRequestAsync( new RawClient.JsonApiRequest { + BaseUrl = _client.Options.BaseUrl, Method = HttpMethod.Get, Path = $"hris/v1/time-off-balances/{id}", - Query = _query + Query = _query, + Options = options } ); - string responseBody = await response.Raw.Content.ReadAsStringAsync(); - if (response.StatusCode >= 200 && response.StatusCode < 400) + var responseBody = await response.Raw.Content.ReadAsStringAsync(); + if (response.StatusCode is >= 200 and < 400) { - return JsonSerializer.Deserialize(responseBody); + try + { + return JsonUtils.Deserialize(responseBody)!; + } + catch (JsonException e) + { + throw new MergeException("Failed to deserialize response", e); + } } - throw new Exception(responseBody); + + throw new MergeApiException( + $"Error with status code {response.StatusCode}", + response.StatusCode, + JsonUtils.Deserialize(responseBody) + ); } } diff --git a/src/Merge.Client/Hris/TimeOffBalances/Types/TimeOffBalancesListRequestPolicyType.cs b/src/Merge.Client/Hris/TimeOffBalances/Types/TimeOffBalancesListRequestPolicyType.cs index fe886071..2b300a96 100644 --- a/src/Merge.Client/Hris/TimeOffBalances/Types/TimeOffBalancesListRequestPolicyType.cs +++ b/src/Merge.Client/Hris/TimeOffBalances/Types/TimeOffBalancesListRequestPolicyType.cs @@ -1,7 +1,6 @@ using System.Runtime.Serialization; using System.Text.Json.Serialization; using Merge.Client.Core; -using Merge.Client.Hris; #nullable enable diff --git a/src/Merge.Client/Hris/TimesheetEntries/Requests/TimesheetEntriesListRequest.cs b/src/Merge.Client/Hris/TimesheetEntries/Requests/TimesheetEntriesListRequest.cs index f0033472..76619ce2 100644 --- a/src/Merge.Client/Hris/TimesheetEntries/Requests/TimesheetEntriesListRequest.cs +++ b/src/Merge.Client/Hris/TimesheetEntries/Requests/TimesheetEntriesListRequest.cs @@ -1,83 +1,79 @@ -using Merge.Client.Hris; - -#nullable enable - namespace Merge.Client.Hris; -public class TimesheetEntriesListRequest +public record TimesheetEntriesListRequest { /// /// If provided, will only return objects created after this datetime. /// - public DateTime? CreatedAfter { get; init; } + public DateTime? CreatedAfter { get; set; } /// /// If provided, will only return objects created before this datetime. /// - public DateTime? CreatedBefore { get; init; } + public DateTime? CreatedBefore { get; set; } /// /// The pagination cursor value. /// - public string? Cursor { get; init; } + public string? Cursor { get; set; } /// /// If provided, will only return timesheet entries for this employee. /// - public string? EmployeeId { get; init; } + public string? EmployeeId { get; set; } /// /// If provided, will only return timesheet entries ended after this datetime. /// - public string? EndedAfter { get; init; } + public string? EndedAfter { get; set; } /// /// If provided, will only return timesheet entries ended before this datetime. /// - public string? EndedBefore { get; init; } + public string? EndedBefore { get; set; } /// /// Whether to include data that was marked as deleted by third party webhooks. /// - public bool? IncludeDeletedData { get; init; } + public bool? IncludeDeletedData { get; set; } /// /// Whether to include the original data Merge fetched from the third-party to produce these models. /// - public bool? IncludeRemoteData { get; init; } + public bool? IncludeRemoteData { get; set; } /// /// If provided, only objects synced by Merge after this date time will be returned. /// - public DateTime? ModifiedAfter { get; init; } + public DateTime? ModifiedAfter { get; set; } /// /// If provided, only objects synced by Merge before this date time will be returned. /// - public DateTime? ModifiedBefore { get; init; } + public DateTime? ModifiedBefore { get; set; } /// /// Overrides the default ordering for this endpoint. Possible values include: start_time, -start_time. /// - public TimesheetEntriesListRequestOrderBy? OrderBy { get; init; } + public TimesheetEntriesListRequestOrderBy? OrderBy { get; set; } /// /// Number of results to return per page. /// - public int? PageSize { get; init; } + public int? PageSize { get; set; } /// /// The API provider's ID for the given object. /// - public string? RemoteId { get; init; } + public string? RemoteId { get; set; } /// /// If provided, will only return timesheet entries started after this datetime. /// - public string? StartedAfter { get; init; } + public string? StartedAfter { get; set; } /// /// If provided, will only return timesheet entries started before this datetime. /// - public string? StartedBefore { get; init; } + public string? StartedBefore { get; set; } } diff --git a/src/Merge.Client/Hris/TimesheetEntries/Requests/TimesheetEntriesRetrieveRequest.cs b/src/Merge.Client/Hris/TimesheetEntries/Requests/TimesheetEntriesRetrieveRequest.cs index 9031bdec..c29aeea0 100644 --- a/src/Merge.Client/Hris/TimesheetEntries/Requests/TimesheetEntriesRetrieveRequest.cs +++ b/src/Merge.Client/Hris/TimesheetEntries/Requests/TimesheetEntriesRetrieveRequest.cs @@ -1,9 +1,9 @@ namespace Merge.Client.Hris; -public class TimesheetEntriesRetrieveRequest +public record TimesheetEntriesRetrieveRequest { /// /// Whether to include the original data Merge fetched from the third-party to produce these models. /// - public bool? IncludeRemoteData { get; init; } + public bool? IncludeRemoteData { get; set; } } diff --git a/src/Merge.Client/Hris/TimesheetEntries/Requests/TimesheetEntryEndpointRequest.cs b/src/Merge.Client/Hris/TimesheetEntries/Requests/TimesheetEntryEndpointRequest.cs index 2dc1c799..bacc47e8 100644 --- a/src/Merge.Client/Hris/TimesheetEntries/Requests/TimesheetEntryEndpointRequest.cs +++ b/src/Merge.Client/Hris/TimesheetEntries/Requests/TimesheetEntryEndpointRequest.cs @@ -1,20 +1,16 @@ -using Merge.Client.Hris; - -#nullable enable - namespace Merge.Client.Hris; -public class TimesheetEntryEndpointRequest +public record TimesheetEntryEndpointRequest { /// /// Whether to include debug fields (such as log file links) in the response. /// - public bool? IsDebugMode { get; init; } + public bool? IsDebugMode { get; set; } /// /// Whether or not third-party updates should be run asynchronously. /// - public bool? RunAsync { get; init; } + public bool? RunAsync { get; set; } - public TimesheetEntryRequest Model { get; init; } + public required TimesheetEntryRequest Model { get; set; } } diff --git a/src/Merge.Client/Hris/TimesheetEntries/TimesheetEntriesClient.cs b/src/Merge.Client/Hris/TimesheetEntries/TimesheetEntriesClient.cs index ad148af7..0631bb57 100644 --- a/src/Merge.Client/Hris/TimesheetEntries/TimesheetEntriesClient.cs +++ b/src/Merge.Client/Hris/TimesheetEntries/TimesheetEntriesClient.cs @@ -1,6 +1,6 @@ +using System.Net.Http; using System.Text.Json; -using Merge.Client; -using Merge.Client.Hris; +using Merge.Client.Core; #nullable enable @@ -18,16 +18,21 @@ public TimesheetEntriesClient(RawClient client) /// /// Returns a list of `TimesheetEntry` objects. /// - public async Task ListAsync(TimesheetEntriesListRequest request) + public async Task ListAsync( + TimesheetEntriesListRequest request, + RequestOptions? options = null + ) { var _query = new Dictionary() { }; if (request.CreatedAfter != null) { - _query["created_after"] = request.CreatedAfter.Value.ToString("o0"); + _query["created_after"] = request.CreatedAfter.Value.ToString(Constants.DateTimeFormat); } if (request.CreatedBefore != null) { - _query["created_before"] = request.CreatedBefore.Value.ToString("o0"); + _query["created_before"] = request.CreatedBefore.Value.ToString( + Constants.DateTimeFormat + ); } if (request.Cursor != null) { @@ -55,11 +60,15 @@ public async Task ListAsync(TimesheetEntriesListReq } if (request.ModifiedAfter != null) { - _query["modified_after"] = request.ModifiedAfter.Value.ToString("o0"); + _query["modified_after"] = request.ModifiedAfter.Value.ToString( + Constants.DateTimeFormat + ); } if (request.ModifiedBefore != null) { - _query["modified_before"] = request.ModifiedBefore.Value.ToString("o0"); + _query["modified_before"] = request.ModifiedBefore.Value.ToString( + Constants.DateTimeFormat + ); } if (request.OrderBy != null) { @@ -84,23 +93,40 @@ public async Task ListAsync(TimesheetEntriesListReq var response = await _client.MakeRequestAsync( new RawClient.JsonApiRequest { + BaseUrl = _client.Options.BaseUrl, Method = HttpMethod.Get, Path = "hris/v1/timesheet-entries", - Query = _query + Query = _query, + Options = options } ); - string responseBody = await response.Raw.Content.ReadAsStringAsync(); - if (response.StatusCode >= 200 && response.StatusCode < 400) + var responseBody = await response.Raw.Content.ReadAsStringAsync(); + if (response.StatusCode is >= 200 and < 400) { - return JsonSerializer.Deserialize(responseBody); + try + { + return JsonUtils.Deserialize(responseBody)!; + } + catch (JsonException e) + { + throw new MergeException("Failed to deserialize response", e); + } } - throw new Exception(responseBody); + + throw new MergeApiException( + $"Error with status code {response.StatusCode}", + response.StatusCode, + JsonUtils.Deserialize(responseBody) + ); } /// /// Creates a `TimesheetEntry` object with the given values. /// - public async Task CreateAsync(TimesheetEntryEndpointRequest request) + public async Task CreateAsync( + TimesheetEntryEndpointRequest request, + RequestOptions? options = null + ) { var _query = new Dictionary() { }; if (request.IsDebugMode != null) @@ -114,17 +140,31 @@ public async Task CreateAsync(TimesheetEntryEndpointRequ var response = await _client.MakeRequestAsync( new RawClient.JsonApiRequest { + BaseUrl = _client.Options.BaseUrl, Method = HttpMethod.Post, Path = "hris/v1/timesheet-entries", - Query = _query + Query = _query, + Options = options } ); - string responseBody = await response.Raw.Content.ReadAsStringAsync(); - if (response.StatusCode >= 200 && response.StatusCode < 400) + var responseBody = await response.Raw.Content.ReadAsStringAsync(); + if (response.StatusCode is >= 200 and < 400) { - return JsonSerializer.Deserialize(responseBody); + try + { + return JsonUtils.Deserialize(responseBody)!; + } + catch (JsonException e) + { + throw new MergeException("Failed to deserialize response", e); + } } - throw new Exception(responseBody); + + throw new MergeApiException( + $"Error with status code {response.StatusCode}", + response.StatusCode, + JsonUtils.Deserialize(responseBody) + ); } /// @@ -132,7 +172,8 @@ public async Task CreateAsync(TimesheetEntryEndpointRequ /// public async Task RetrieveAsync( string id, - TimesheetEntriesRetrieveRequest request + TimesheetEntriesRetrieveRequest request, + RequestOptions? options = null ) { var _query = new Dictionary() { }; @@ -143,36 +184,64 @@ TimesheetEntriesRetrieveRequest request var response = await _client.MakeRequestAsync( new RawClient.JsonApiRequest { + BaseUrl = _client.Options.BaseUrl, Method = HttpMethod.Get, Path = $"hris/v1/timesheet-entries/{id}", - Query = _query + Query = _query, + Options = options } ); - string responseBody = await response.Raw.Content.ReadAsStringAsync(); - if (response.StatusCode >= 200 && response.StatusCode < 400) + var responseBody = await response.Raw.Content.ReadAsStringAsync(); + if (response.StatusCode is >= 200 and < 400) { - return JsonSerializer.Deserialize(responseBody); + try + { + return JsonUtils.Deserialize(responseBody)!; + } + catch (JsonException e) + { + throw new MergeException("Failed to deserialize response", e); + } } - throw new Exception(responseBody); + + throw new MergeApiException( + $"Error with status code {response.StatusCode}", + response.StatusCode, + JsonUtils.Deserialize(responseBody) + ); } /// /// Returns metadata for `TimesheetEntry` POSTs. /// - public async Task MetaPostRetrieveAsync() + public async Task MetaPostRetrieveAsync(RequestOptions? options = null) { var response = await _client.MakeRequestAsync( new RawClient.JsonApiRequest { + BaseUrl = _client.Options.BaseUrl, Method = HttpMethod.Get, - Path = "hris/v1/timesheet-entries/meta/post" + Path = "hris/v1/timesheet-entries/meta/post", + Options = options } ); - string responseBody = await response.Raw.Content.ReadAsStringAsync(); - if (response.StatusCode >= 200 && response.StatusCode < 400) + var responseBody = await response.Raw.Content.ReadAsStringAsync(); + if (response.StatusCode is >= 200 and < 400) { - return JsonSerializer.Deserialize(responseBody); + try + { + return JsonUtils.Deserialize(responseBody)!; + } + catch (JsonException e) + { + throw new MergeException("Failed to deserialize response", e); + } } - throw new Exception(responseBody); + + throw new MergeApiException( + $"Error with status code {response.StatusCode}", + response.StatusCode, + JsonUtils.Deserialize(responseBody) + ); } } diff --git a/src/Merge.Client/Hris/TimesheetEntries/Types/TimesheetEntriesListRequestOrderBy.cs b/src/Merge.Client/Hris/TimesheetEntries/Types/TimesheetEntriesListRequestOrderBy.cs index 8f613a95..bcdd522b 100644 --- a/src/Merge.Client/Hris/TimesheetEntries/Types/TimesheetEntriesListRequestOrderBy.cs +++ b/src/Merge.Client/Hris/TimesheetEntries/Types/TimesheetEntriesListRequestOrderBy.cs @@ -1,7 +1,6 @@ using System.Runtime.Serialization; using System.Text.Json.Serialization; using Merge.Client.Core; -using Merge.Client.Hris; #nullable enable diff --git a/src/Merge.Client/Hris/Types/AccountDetails.cs b/src/Merge.Client/Hris/Types/AccountDetails.cs index f4ecdf4b..78114d5a 100644 --- a/src/Merge.Client/Hris/Types/AccountDetails.cs +++ b/src/Merge.Client/Hris/Types/AccountDetails.cs @@ -1,45 +1,44 @@ using System.Text.Json.Serialization; -using Merge.Client.Hris; #nullable enable namespace Merge.Client.Hris; -public class AccountDetails +public record AccountDetails { [JsonPropertyName("id")] - public string? Id { get; init; } + public string? Id { get; set; } [JsonPropertyName("integration")] - public string? Integration { get; init; } + public string? Integration { get; set; } [JsonPropertyName("integration_slug")] - public string? IntegrationSlug { get; init; } + public string? IntegrationSlug { get; set; } [JsonPropertyName("category")] - public CategoryEnum? Category { get; init; } + public CategoryEnum? Category { get; set; } [JsonPropertyName("end_user_origin_id")] - public string? EndUserOriginId { get; init; } + public string? EndUserOriginId { get; set; } [JsonPropertyName("end_user_organization_name")] - public string? EndUserOrganizationName { get; init; } + public string? EndUserOrganizationName { get; set; } [JsonPropertyName("end_user_email_address")] - public string? EndUserEmailAddress { get; init; } + public string? EndUserEmailAddress { get; set; } [JsonPropertyName("status")] - public string? Status { get; init; } + public string? Status { get; set; } [JsonPropertyName("webhook_listener_url")] - public string? WebhookListenerUrl { get; init; } + public string? WebhookListenerUrl { get; set; } /// /// Whether a Production Linked Account's credentials match another existing Production Linked Account. This field is `null` for Test Linked Accounts, incomplete Production Linked Accounts, and ignored duplicate Production Linked Account sets. /// [JsonPropertyName("is_duplicate")] - public bool? IsDuplicate { get; init; } + public bool? IsDuplicate { get; set; } [JsonPropertyName("account_type")] - public string? AccountType { get; init; } + public string? AccountType { get; set; } } diff --git a/src/Merge.Client/Hris/Types/AccountDetailsAndActions.cs b/src/Merge.Client/Hris/Types/AccountDetailsAndActions.cs index c15c9b85..daa3882c 100644 --- a/src/Merge.Client/Hris/Types/AccountDetailsAndActions.cs +++ b/src/Merge.Client/Hris/Types/AccountDetailsAndActions.cs @@ -1,51 +1,50 @@ using System.Text.Json.Serialization; -using Merge.Client.Hris; #nullable enable namespace Merge.Client.Hris; -public class AccountDetailsAndActions +public record AccountDetailsAndActions { [JsonPropertyName("id")] - public string Id { get; init; } + public required string Id { get; set; } [JsonPropertyName("category")] - public CategoryEnum? Category { get; init; } + public CategoryEnum? Category { get; set; } [JsonPropertyName("status")] - public AccountDetailsAndActionsStatusEnum Status { get; init; } + public required AccountDetailsAndActionsStatusEnum Status { get; set; } [JsonPropertyName("status_detail")] - public string? StatusDetail { get; init; } + public string? StatusDetail { get; set; } [JsonPropertyName("end_user_origin_id")] - public string? EndUserOriginId { get; init; } + public string? EndUserOriginId { get; set; } [JsonPropertyName("end_user_organization_name")] - public string EndUserOrganizationName { get; init; } + public required string EndUserOrganizationName { get; set; } [JsonPropertyName("end_user_email_address")] - public string EndUserEmailAddress { get; init; } + public required string EndUserEmailAddress { get; set; } /// /// The tenant or domain the customer has provided access to. /// [JsonPropertyName("subdomain")] - public string? Subdomain { get; init; } + public string? Subdomain { get; set; } [JsonPropertyName("webhook_listener_url")] - public string WebhookListenerUrl { get; init; } + public required string WebhookListenerUrl { get; set; } /// /// Whether a Production Linked Account's credentials match another existing Production Linked Account. This field is `null` for Test Linked Accounts, incomplete Production Linked Accounts, and ignored duplicate Production Linked Account sets. /// [JsonPropertyName("is_duplicate")] - public bool? IsDuplicate { get; init; } + public bool? IsDuplicate { get; set; } [JsonPropertyName("integration")] - public AccountDetailsAndActionsIntegration? Integration { get; init; } + public AccountDetailsAndActionsIntegration? Integration { get; set; } [JsonPropertyName("account_type")] - public string AccountType { get; init; } + public required string AccountType { get; set; } } diff --git a/src/Merge.Client/Hris/Types/AccountDetailsAndActionsIntegration.cs b/src/Merge.Client/Hris/Types/AccountDetailsAndActionsIntegration.cs index 54380838..fc0f19f5 100644 --- a/src/Merge.Client/Hris/Types/AccountDetailsAndActionsIntegration.cs +++ b/src/Merge.Client/Hris/Types/AccountDetailsAndActionsIntegration.cs @@ -1,33 +1,32 @@ using System.Text.Json.Serialization; -using Merge.Client.Hris; #nullable enable namespace Merge.Client.Hris; -public class AccountDetailsAndActionsIntegration +public record AccountDetailsAndActionsIntegration { [JsonPropertyName("name")] - public string Name { get; init; } + public required string Name { get; set; } [JsonPropertyName("categories")] - public IEnumerable Categories { get; init; } + public IEnumerable Categories { get; set; } = new List(); [JsonPropertyName("image")] - public string? Image { get; init; } + public string? Image { get; set; } [JsonPropertyName("square_image")] - public string? SquareImage { get; init; } + public string? SquareImage { get; set; } [JsonPropertyName("color")] - public string Color { get; init; } + public required string Color { get; set; } [JsonPropertyName("slug")] - public string Slug { get; init; } + public required string Slug { get; set; } [JsonPropertyName("passthrough_available")] - public bool PassthroughAvailable { get; init; } + public required bool PassthroughAvailable { get; set; } [JsonPropertyName("available_model_operations")] - public IEnumerable? AvailableModelOperations { get; init; } + public IEnumerable? AvailableModelOperations { get; set; } } diff --git a/src/Merge.Client/Hris/Types/AccountDetailsAndActionsStatusEnum.cs b/src/Merge.Client/Hris/Types/AccountDetailsAndActionsStatusEnum.cs index d4056df0..4d215a5a 100644 --- a/src/Merge.Client/Hris/Types/AccountDetailsAndActionsStatusEnum.cs +++ b/src/Merge.Client/Hris/Types/AccountDetailsAndActionsStatusEnum.cs @@ -1,7 +1,6 @@ using System.Runtime.Serialization; using System.Text.Json.Serialization; using Merge.Client.Core; -using Merge.Client.Hris; #nullable enable diff --git a/src/Merge.Client/Hris/Types/AccountIntegration.cs b/src/Merge.Client/Hris/Types/AccountIntegration.cs index 4f7e2461..571bc292 100644 --- a/src/Merge.Client/Hris/Types/AccountIntegration.cs +++ b/src/Merge.Client/Hris/Types/AccountIntegration.cs @@ -1,66 +1,65 @@ using System.Text.Json.Serialization; -using Merge.Client.Hris; #nullable enable namespace Merge.Client.Hris; -public class AccountIntegration +public record AccountIntegration { /// /// Company name. /// [JsonPropertyName("name")] - public string Name { get; init; } + public required string Name { get; set; } /// /// Optional. This shortened name appears in places with limited space, usually in conjunction with the platform's logo (e.g., Merge Link menu).

Example: Workforce Now (in lieu of ADP Workforce Now), SuccessFactors (in lieu of SAP SuccessFactors) ///
[JsonPropertyName("abbreviated_name")] - public string? AbbreviatedName { get; init; } + public string? AbbreviatedName { get; set; } /// /// Category or categories this integration belongs to. Multiple categories should be comma separated, i.e. [ats, hris]. /// [JsonPropertyName("categories")] - public IEnumerable? Categories { get; init; } + public IEnumerable? Categories { get; set; } /// /// Company logo in rectangular shape. Upload an image with a clear background. /// [JsonPropertyName("image")] - public string? Image { get; init; } + public string? Image { get; set; } /// /// Company logo in square shape. Upload an image with a white background. /// [JsonPropertyName("square_image")] - public string? SquareImage { get; init; } + public string? SquareImage { get; set; } /// /// The color of this integration used for buttons and text throughout the app and landing pages. Choose a darker, saturated color. /// [JsonPropertyName("color")] - public string? Color { get; init; } + public string? Color { get; set; } [JsonPropertyName("slug")] - public string? Slug { get; init; } + public string? Slug { get; set; } /// /// Mapping of API endpoints to documentation urls for support. Example: {'GET': [['/common-model-scopes', 'https://docs.merge.dev/accounting/common-model-scopes/#common_model_scopes_retrieve'],['/common-model-actions', 'https://docs.merge.dev/accounting/common-model-actions/#common_model_actions_retrieve']], 'POST': []} /// [JsonPropertyName("api_endpoints_to_documentation_urls")] - public Dictionary? ApiEndpointsToDocumentationUrls { get; init; } + public Dictionary? ApiEndpointsToDocumentationUrls { get; set; } /// /// Setup guide URL for third party webhook creation. Exposed in Merge Docs. /// [JsonPropertyName("webhook_setup_guide_url")] - public string? WebhookSetupGuideUrl { get; init; } + public string? WebhookSetupGuideUrl { get; set; } /// /// Category or categories this integration is in beta status for. /// [JsonPropertyName("category_beta_status")] - public Dictionary? CategoryBetaStatus { get; init; } + public Dictionary? CategoryBetaStatus { get; set; } } diff --git a/src/Merge.Client/Hris/Types/AccountToken.cs b/src/Merge.Client/Hris/Types/AccountToken.cs index 0900db92..823e101c 100644 --- a/src/Merge.Client/Hris/Types/AccountToken.cs +++ b/src/Merge.Client/Hris/Types/AccountToken.cs @@ -1,15 +1,14 @@ using System.Text.Json.Serialization; -using Merge.Client.Hris; #nullable enable namespace Merge.Client.Hris; -public class AccountToken +public record AccountToken { [JsonPropertyName("account_token")] - public string AccountToken_ { get; init; } + public required string AccountToken_ { get; set; } [JsonPropertyName("integration")] - public AccountIntegration Integration { get; init; } + public required AccountIntegration Integration { get; set; } } diff --git a/src/Merge.Client/Hris/Types/AccountTypeEnum.cs b/src/Merge.Client/Hris/Types/AccountTypeEnum.cs index 137d2556..e9406566 100644 --- a/src/Merge.Client/Hris/Types/AccountTypeEnum.cs +++ b/src/Merge.Client/Hris/Types/AccountTypeEnum.cs @@ -1,7 +1,6 @@ using System.Runtime.Serialization; using System.Text.Json.Serialization; using Merge.Client.Core; -using Merge.Client.Hris; #nullable enable diff --git a/src/Merge.Client/Hris/Types/AdvancedMetadata.cs b/src/Merge.Client/Hris/Types/AdvancedMetadata.cs index 813cf505..68c37276 100644 --- a/src/Merge.Client/Hris/Types/AdvancedMetadata.cs +++ b/src/Merge.Client/Hris/Types/AdvancedMetadata.cs @@ -4,23 +4,23 @@ namespace Merge.Client.Hris; -public class AdvancedMetadata +public record AdvancedMetadata { [JsonPropertyName("id")] - public string Id { get; init; } + public required string Id { get; set; } [JsonPropertyName("display_name")] - public string? DisplayName { get; init; } + public string? DisplayName { get; set; } [JsonPropertyName("description")] - public string? Description { get; init; } + public string? Description { get; set; } [JsonPropertyName("is_required")] - public bool? IsRequired { get; init; } + public bool? IsRequired { get; set; } [JsonPropertyName("is_custom")] - public bool? IsCustom { get; init; } + public bool? IsCustom { get; set; } [JsonPropertyName("field_choices")] - public IEnumerable? FieldChoices { get; init; } + public IEnumerable? FieldChoices { get; set; } } diff --git a/src/Merge.Client/Hris/Types/AsyncPassthroughReciept.cs b/src/Merge.Client/Hris/Types/AsyncPassthroughReciept.cs index 2947f020..c4082b85 100644 --- a/src/Merge.Client/Hris/Types/AsyncPassthroughReciept.cs +++ b/src/Merge.Client/Hris/Types/AsyncPassthroughReciept.cs @@ -4,8 +4,8 @@ namespace Merge.Client.Hris; -public class AsyncPassthroughReciept +public record AsyncPassthroughReciept { [JsonPropertyName("async_passthrough_receipt_id")] - public string AsyncPassthroughReceiptId { get; init; } + public required string AsyncPassthroughReceiptId { get; set; } } diff --git a/src/Merge.Client/Hris/Types/AuditLogEvent.cs b/src/Merge.Client/Hris/Types/AuditLogEvent.cs index 0a9b37ea..f6117f10 100644 --- a/src/Merge.Client/Hris/Types/AuditLogEvent.cs +++ b/src/Merge.Client/Hris/Types/AuditLogEvent.cs @@ -1,26 +1,25 @@ using System.Text.Json.Serialization; -using Merge.Client.Hris; #nullable enable namespace Merge.Client.Hris; -public class AuditLogEvent +public record AuditLogEvent { [JsonPropertyName("id")] - public string? Id { get; init; } + public string? Id { get; set; } /// /// The User's full name at the time of this Event occurring. /// [JsonPropertyName("user_name")] - public string? UserName { get; init; } + public string? UserName { get; set; } /// /// The User's email at the time of this Event occurring. /// [JsonPropertyName("user_email")] - public string? UserEmail { get; init; } + public string? UserEmail { get; set; } /// /// Designates the role of the user (or SYSTEM/API if action not taken by a user) at the time of this Event occurring. @@ -33,10 +32,10 @@ public class AuditLogEvent /// - `MERGE_TEAM` - MERGE_TEAM /// [JsonPropertyName("role")] - public RoleEnum Role { get; init; } + public required RoleEnum Role { get; set; } [JsonPropertyName("ip_address")] - public string IpAddress { get; init; } + public required string IpAddress { get; set; } /// /// Designates the type of event that occurred. @@ -81,11 +80,11 @@ public class AuditLogEvent /// - `END_USER_CREDENTIALS_ACCESSED` - END_USER_CREDENTIALS_ACCESSED /// [JsonPropertyName("event_type")] - public EventTypeEnum EventType { get; init; } + public required EventTypeEnum EventType { get; set; } [JsonPropertyName("event_description")] - public string EventDescription { get; init; } + public required string EventDescription { get; set; } [JsonPropertyName("created_at")] - public DateTime? CreatedAt { get; init; } + public DateTime? CreatedAt { get; set; } } diff --git a/src/Merge.Client/Hris/Types/AvailableActions.cs b/src/Merge.Client/Hris/Types/AvailableActions.cs index 0dc6e643..c46c8f1f 100644 --- a/src/Merge.Client/Hris/Types/AvailableActions.cs +++ b/src/Merge.Client/Hris/Types/AvailableActions.cs @@ -1,18 +1,17 @@ using System.Text.Json.Serialization; -using Merge.Client.Hris; #nullable enable namespace Merge.Client.Hris; -public class AvailableActions +public record AvailableActions { [JsonPropertyName("integration")] - public AccountIntegration Integration { get; init; } + public required AccountIntegration Integration { get; set; } [JsonPropertyName("passthrough_available")] - public bool PassthroughAvailable { get; init; } + public required bool PassthroughAvailable { get; set; } [JsonPropertyName("available_model_operations")] - public IEnumerable? AvailableModelOperations { get; init; } + public IEnumerable? AvailableModelOperations { get; set; } } diff --git a/src/Merge.Client/Hris/Types/BankInfo.cs b/src/Merge.Client/Hris/Types/BankInfo.cs index 9b66c254..f9ecb58b 100644 --- a/src/Merge.Client/Hris/Types/BankInfo.cs +++ b/src/Merge.Client/Hris/Types/BankInfo.cs @@ -1,59 +1,58 @@ using System.Text.Json.Serialization; using Merge.Client.Core; -using Merge.Client.Hris; using OneOf; #nullable enable namespace Merge.Client.Hris; -public class BankInfo +public record BankInfo { [JsonPropertyName("id")] - public string? Id { get; init; } + public string? Id { get; set; } /// /// The third-party API ID of the matching object. /// [JsonPropertyName("remote_id")] - public string? RemoteId { get; init; } + public string? RemoteId { get; set; } /// /// The datetime that this object was created by Merge. /// [JsonPropertyName("created_at")] - public DateTime? CreatedAt { get; init; } + public DateTime? CreatedAt { get; set; } /// /// The datetime that this object was modified by Merge. /// [JsonPropertyName("modified_at")] - public DateTime? ModifiedAt { get; init; } + public DateTime? ModifiedAt { get; set; } /// /// The employee with this bank account. /// [JsonPropertyName("employee")] [JsonConverter(typeof(OneOfSerializer>))] - public OneOf? Employee { get; init; } + public OneOf? Employee { get; set; } /// /// The account number. /// [JsonPropertyName("account_number")] - public string? AccountNumber { get; init; } + public string? AccountNumber { get; set; } /// /// The routing number. /// [JsonPropertyName("routing_number")] - public string? RoutingNumber { get; init; } + public string? RoutingNumber { get; set; } /// /// The bank name. /// [JsonPropertyName("bank_name")] - public string? BankName { get; init; } + public string? BankName { get; set; } /// /// The bank account type @@ -62,23 +61,23 @@ public class BankInfo /// - `CHECKING` - CHECKING /// [JsonPropertyName("account_type")] - public AccountTypeEnum? AccountType { get; init; } + public AccountTypeEnum? AccountType { get; set; } /// /// When the matching bank object was created in the third party system. /// [JsonPropertyName("remote_created_at")] - public DateTime? RemoteCreatedAt { get; init; } + public DateTime? RemoteCreatedAt { get; set; } /// /// Indicates whether or not this object has been deleted in the third party platform. /// [JsonPropertyName("remote_was_deleted")] - public bool? RemoteWasDeleted { get; init; } + public bool? RemoteWasDeleted { get; set; } [JsonPropertyName("field_mappings")] - public Dictionary? FieldMappings { get; init; } + public Dictionary? FieldMappings { get; set; } [JsonPropertyName("remote_data")] - public IEnumerable? RemoteData { get; init; } + public IEnumerable? RemoteData { get; set; } } diff --git a/src/Merge.Client/Hris/Types/Benefit.cs b/src/Merge.Client/Hris/Types/Benefit.cs index 13f7804a..8a7c5cac 100644 --- a/src/Merge.Client/Hris/Types/Benefit.cs +++ b/src/Merge.Client/Hris/Types/Benefit.cs @@ -1,93 +1,92 @@ using System.Text.Json.Serialization; using Merge.Client.Core; -using Merge.Client.Hris; using OneOf; #nullable enable namespace Merge.Client.Hris; -public class Benefit +public record Benefit { [JsonPropertyName("id")] - public string? Id { get; init; } + public string? Id { get; set; } /// /// The third-party API ID of the matching object. /// [JsonPropertyName("remote_id")] - public string? RemoteId { get; init; } + public string? RemoteId { get; set; } /// /// The datetime that this object was created by Merge. /// [JsonPropertyName("created_at")] - public DateTime? CreatedAt { get; init; } + public DateTime? CreatedAt { get; set; } /// /// The datetime that this object was modified by Merge. /// [JsonPropertyName("modified_at")] - public DateTime? ModifiedAt { get; init; } + public DateTime? ModifiedAt { get; set; } /// /// The employee on the plan. /// [JsonPropertyName("employee")] [JsonConverter(typeof(OneOfSerializer>))] - public OneOf? Employee { get; init; } + public OneOf? Employee { get; set; } /// /// The name of the benefit provider. /// [JsonPropertyName("provider_name")] - public string? ProviderName { get; init; } + public string? ProviderName { get; set; } /// /// The type of benefit plan /// [JsonPropertyName("benefit_plan_type")] - public string? BenefitPlanType { get; init; } + public string? BenefitPlanType { get; set; } /// /// The employee's contribution. /// [JsonPropertyName("employee_contribution")] - public double? EmployeeContribution { get; init; } + public double? EmployeeContribution { get; set; } /// /// The company's contribution. /// [JsonPropertyName("company_contribution")] - public double? CompanyContribution { get; init; } + public double? CompanyContribution { get; set; } /// /// The day and time the benefit started. /// [JsonPropertyName("start_date")] - public DateTime? StartDate { get; init; } + public DateTime? StartDate { get; set; } /// /// The day and time the benefit ended. /// [JsonPropertyName("end_date")] - public DateTime? EndDate { get; init; } + public DateTime? EndDate { get; set; } /// /// Indicates whether or not this object has been deleted in the third party platform. /// [JsonPropertyName("remote_was_deleted")] - public bool? RemoteWasDeleted { get; init; } + public bool? RemoteWasDeleted { get; set; } /// /// The employer benefit plan the employee is enrolled in. /// [JsonPropertyName("employer_benefit")] - public string? EmployerBenefit { get; init; } + public string? EmployerBenefit { get; set; } [JsonPropertyName("field_mappings")] - public Dictionary? FieldMappings { get; init; } + public Dictionary? FieldMappings { get; set; } [JsonPropertyName("remote_data")] - public IEnumerable? RemoteData { get; init; } + public IEnumerable? RemoteData { get; set; } } diff --git a/src/Merge.Client/Hris/Types/BenefitPlanTypeEnum.cs b/src/Merge.Client/Hris/Types/BenefitPlanTypeEnum.cs index fe74683e..9185ae91 100644 --- a/src/Merge.Client/Hris/Types/BenefitPlanTypeEnum.cs +++ b/src/Merge.Client/Hris/Types/BenefitPlanTypeEnum.cs @@ -1,7 +1,6 @@ using System.Runtime.Serialization; using System.Text.Json.Serialization; using Merge.Client.Core; -using Merge.Client.Hris; #nullable enable diff --git a/src/Merge.Client/Hris/Types/CategoriesEnum.cs b/src/Merge.Client/Hris/Types/CategoriesEnum.cs index b534f4a1..a09d288f 100644 --- a/src/Merge.Client/Hris/Types/CategoriesEnum.cs +++ b/src/Merge.Client/Hris/Types/CategoriesEnum.cs @@ -1,7 +1,6 @@ using System.Runtime.Serialization; using System.Text.Json.Serialization; using Merge.Client.Core; -using Merge.Client.Hris; #nullable enable diff --git a/src/Merge.Client/Hris/Types/CategoryEnum.cs b/src/Merge.Client/Hris/Types/CategoryEnum.cs index b3e98121..7f4c7865 100644 --- a/src/Merge.Client/Hris/Types/CategoryEnum.cs +++ b/src/Merge.Client/Hris/Types/CategoryEnum.cs @@ -1,7 +1,6 @@ using System.Runtime.Serialization; using System.Text.Json.Serialization; using Merge.Client.Core; -using Merge.Client.Hris; #nullable enable diff --git a/src/Merge.Client/Hris/Types/CommonModelScopeApi.cs b/src/Merge.Client/Hris/Types/CommonModelScopeApi.cs index 85503f41..2577f111 100644 --- a/src/Merge.Client/Hris/Types/CommonModelScopeApi.cs +++ b/src/Merge.Client/Hris/Types/CommonModelScopeApi.cs @@ -1,15 +1,15 @@ using System.Text.Json.Serialization; -using Merge.Client.Hris; #nullable enable namespace Merge.Client.Hris; -public class CommonModelScopeApi +public record CommonModelScopeApi { /// /// The common models you want to update the scopes for /// [JsonPropertyName("common_models")] - public IEnumerable CommonModels { get; init; } + public IEnumerable CommonModels { get; set; } = + new List(); } diff --git a/src/Merge.Client/Hris/Types/CommonModelScopesBodyRequest.cs b/src/Merge.Client/Hris/Types/CommonModelScopesBodyRequest.cs index 679324a3..037556e0 100644 --- a/src/Merge.Client/Hris/Types/CommonModelScopesBodyRequest.cs +++ b/src/Merge.Client/Hris/Types/CommonModelScopesBodyRequest.cs @@ -1,18 +1,18 @@ using System.Text.Json.Serialization; -using Merge.Client.Hris; #nullable enable namespace Merge.Client.Hris; -public class CommonModelScopesBodyRequest +public record CommonModelScopesBodyRequest { [JsonPropertyName("model_id")] - public string ModelId { get; init; } + public required string ModelId { get; set; } [JsonPropertyName("enabled_actions")] - public IEnumerable EnabledActions { get; init; } + public IEnumerable EnabledActions { get; set; } = + new List(); [JsonPropertyName("disabled_fields")] - public IEnumerable DisabledFields { get; init; } + public IEnumerable DisabledFields { get; set; } = new List(); } diff --git a/src/Merge.Client/Hris/Types/Company.cs b/src/Merge.Client/Hris/Types/Company.cs index 760f48cd..d5e2c20d 100644 --- a/src/Merge.Client/Hris/Types/Company.cs +++ b/src/Merge.Client/Hris/Types/Company.cs @@ -1,60 +1,59 @@ using System.Text.Json.Serialization; -using Merge.Client.Hris; #nullable enable namespace Merge.Client.Hris; -public class Company +public record Company { [JsonPropertyName("id")] - public string? Id { get; init; } + public string? Id { get; set; } /// /// The third-party API ID of the matching object. /// [JsonPropertyName("remote_id")] - public string? RemoteId { get; init; } + public string? RemoteId { get; set; } /// /// The datetime that this object was created by Merge. /// [JsonPropertyName("created_at")] - public DateTime? CreatedAt { get; init; } + public DateTime? CreatedAt { get; set; } /// /// The datetime that this object was modified by Merge. /// [JsonPropertyName("modified_at")] - public DateTime? ModifiedAt { get; init; } + public DateTime? ModifiedAt { get; set; } /// /// The company's legal name. /// [JsonPropertyName("legal_name")] - public string? LegalName { get; init; } + public string? LegalName { get; set; } /// /// The company's display name. /// [JsonPropertyName("display_name")] - public string? DisplayName { get; init; } + public string? DisplayName { get; set; } /// /// The company's Employer Identification Numbers. /// [JsonPropertyName("eins")] - public IEnumerable? Eins { get; init; } + public IEnumerable? Eins { get; set; } /// /// Indicates whether or not this object has been deleted in the third party platform. /// [JsonPropertyName("remote_was_deleted")] - public bool? RemoteWasDeleted { get; init; } + public bool? RemoteWasDeleted { get; set; } [JsonPropertyName("field_mappings")] - public Dictionary? FieldMappings { get; init; } + public Dictionary? FieldMappings { get; set; } [JsonPropertyName("remote_data")] - public IEnumerable? RemoteData { get; init; } + public IEnumerable? RemoteData { get; set; } } diff --git a/src/Merge.Client/Hris/Types/CountryEnum.cs b/src/Merge.Client/Hris/Types/CountryEnum.cs index b1a73b9e..3eea5c95 100644 --- a/src/Merge.Client/Hris/Types/CountryEnum.cs +++ b/src/Merge.Client/Hris/Types/CountryEnum.cs @@ -1,7 +1,6 @@ using System.Runtime.Serialization; using System.Text.Json.Serialization; using Merge.Client.Core; -using Merge.Client.Hris; #nullable enable diff --git a/src/Merge.Client/Hris/Types/DataPassthroughRequest.cs b/src/Merge.Client/Hris/Types/DataPassthroughRequest.cs index 94725a4a..bc9c4ce3 100644 --- a/src/Merge.Client/Hris/Types/DataPassthroughRequest.cs +++ b/src/Merge.Client/Hris/Types/DataPassthroughRequest.cs @@ -1,51 +1,50 @@ using System.Text.Json.Serialization; -using Merge.Client.Hris; #nullable enable namespace Merge.Client.Hris; -public class DataPassthroughRequest +public record DataPassthroughRequest { [JsonPropertyName("method")] - public MethodEnum Method { get; init; } + public required MethodEnum Method { get; set; } /// /// The path of the request in the third party's platform. /// [JsonPropertyName("path")] - public string Path { get; init; } + public required string Path { get; set; } /// /// An optional override of the third party's base url for the request. /// [JsonPropertyName("base_url_override")] - public string? BaseUrlOverride { get; init; } + public string? BaseUrlOverride { get; set; } /// /// The data with the request. You must include a `request_format` parameter matching the data's format /// [JsonPropertyName("data")] - public string? Data { get; init; } + public string? Data { get; set; } /// /// Pass an array of `MultipartFormField` objects in here instead of using the `data` param if `request_format` is set to `MULTIPART`. /// [JsonPropertyName("multipart_form_data")] - public IEnumerable? MultipartFormData { get; init; } + public IEnumerable? MultipartFormData { get; set; } /// /// The headers to use for the request (Merge will handle the account's authorization headers). `Content-Type` header is required for passthrough. Choose content type corresponding to expected format of receiving server. /// [JsonPropertyName("headers")] - public Dictionary? Headers { get; init; } + public Dictionary? Headers { get; set; } [JsonPropertyName("request_format")] - public RequestFormatEnum? RequestFormat { get; init; } + public RequestFormatEnum? RequestFormat { get; set; } /// /// Optional. If true, the response will always be an object of the form `{"type": T, "value": ...}` where `T` will be one of `string, boolean, number, null, array, object`. /// [JsonPropertyName("normalize_response")] - public bool? NormalizeResponse { get; init; } + public bool? NormalizeResponse { get; set; } } diff --git a/src/Merge.Client/Hris/Types/DebugModeLog.cs b/src/Merge.Client/Hris/Types/DebugModeLog.cs index 00d9fbe1..7a20eb18 100644 --- a/src/Merge.Client/Hris/Types/DebugModeLog.cs +++ b/src/Merge.Client/Hris/Types/DebugModeLog.cs @@ -1,18 +1,17 @@ using System.Text.Json.Serialization; -using Merge.Client.Hris; #nullable enable namespace Merge.Client.Hris; -public class DebugModeLog +public record DebugModeLog { [JsonPropertyName("log_id")] - public string LogId { get; init; } + public required string LogId { get; set; } [JsonPropertyName("dashboard_view")] - public string DashboardView { get; init; } + public required string DashboardView { get; set; } [JsonPropertyName("log_summary")] - public DebugModelLogSummary LogSummary { get; init; } + public required DebugModelLogSummary LogSummary { get; set; } } diff --git a/src/Merge.Client/Hris/Types/DebugModelLogSummary.cs b/src/Merge.Client/Hris/Types/DebugModelLogSummary.cs index 8c696dc3..fde92116 100644 --- a/src/Merge.Client/Hris/Types/DebugModelLogSummary.cs +++ b/src/Merge.Client/Hris/Types/DebugModelLogSummary.cs @@ -4,14 +4,14 @@ namespace Merge.Client.Hris; -public class DebugModelLogSummary +public record DebugModelLogSummary { [JsonPropertyName("url")] - public string Url { get; init; } + public required string Url { get; set; } [JsonPropertyName("method")] - public string Method { get; init; } + public required string Method { get; set; } [JsonPropertyName("status_code")] - public int StatusCode { get; init; } + public required int StatusCode { get; set; } } diff --git a/src/Merge.Client/Hris/Types/Deduction.cs b/src/Merge.Client/Hris/Types/Deduction.cs index ae97d056..160e6239 100644 --- a/src/Merge.Client/Hris/Types/Deduction.cs +++ b/src/Merge.Client/Hris/Types/Deduction.cs @@ -1,63 +1,62 @@ using System.Text.Json.Serialization; -using Merge.Client.Hris; #nullable enable namespace Merge.Client.Hris; -public class Deduction +public record Deduction { [JsonPropertyName("id")] - public string? Id { get; init; } + public string? Id { get; set; } /// /// The third-party API ID of the matching object. /// [JsonPropertyName("remote_id")] - public string? RemoteId { get; init; } + public string? RemoteId { get; set; } /// /// The datetime that this object was created by Merge. /// [JsonPropertyName("created_at")] - public DateTime? CreatedAt { get; init; } + public DateTime? CreatedAt { get; set; } /// /// The datetime that this object was modified by Merge. /// [JsonPropertyName("modified_at")] - public DateTime? ModifiedAt { get; init; } + public DateTime? ModifiedAt { get; set; } [JsonPropertyName("employee_payroll_run")] - public string? EmployeePayrollRun { get; init; } + public string? EmployeePayrollRun { get; set; } /// /// The deduction's name. /// [JsonPropertyName("name")] - public string? Name { get; init; } + public string? Name { get; set; } /// /// The amount of money that is withheld from an employee's gross pay by the employee. /// [JsonPropertyName("employee_deduction")] - public double? EmployeeDeduction { get; init; } + public double? EmployeeDeduction { get; set; } /// /// The amount of money that is withheld on behalf of an employee by the company. /// [JsonPropertyName("company_deduction")] - public double? CompanyDeduction { get; init; } + public double? CompanyDeduction { get; set; } /// /// Indicates whether or not this object has been deleted in the third party platform. /// [JsonPropertyName("remote_was_deleted")] - public bool? RemoteWasDeleted { get; init; } + public bool? RemoteWasDeleted { get; set; } [JsonPropertyName("field_mappings")] - public Dictionary? FieldMappings { get; init; } + public Dictionary? FieldMappings { get; set; } [JsonPropertyName("remote_data")] - public IEnumerable? RemoteData { get; init; } + public IEnumerable? RemoteData { get; set; } } diff --git a/src/Merge.Client/Hris/Types/Dependent.cs b/src/Merge.Client/Hris/Types/Dependent.cs index f8ebbded..5f3e10fc 100644 --- a/src/Merge.Client/Hris/Types/Dependent.cs +++ b/src/Merge.Client/Hris/Types/Dependent.cs @@ -1,50 +1,49 @@ using System.Text.Json.Serialization; -using Merge.Client.Hris; #nullable enable namespace Merge.Client.Hris; -public class Dependent +public record Dependent { [JsonPropertyName("id")] - public string? Id { get; init; } + public string? Id { get; set; } /// /// The third-party API ID of the matching object. /// [JsonPropertyName("remote_id")] - public string? RemoteId { get; init; } + public string? RemoteId { get; set; } /// /// The datetime that this object was created by Merge. /// [JsonPropertyName("created_at")] - public DateTime? CreatedAt { get; init; } + public DateTime? CreatedAt { get; set; } /// /// The datetime that this object was modified by Merge. /// [JsonPropertyName("modified_at")] - public DateTime? ModifiedAt { get; init; } + public DateTime? ModifiedAt { get; set; } /// /// The dependents's first name. /// [JsonPropertyName("first_name")] - public string? FirstName { get; init; } + public string? FirstName { get; set; } /// /// The dependents's middle name. /// [JsonPropertyName("middle_name")] - public string? MiddleName { get; init; } + public string? MiddleName { get; set; } /// /// The dependents's last name. /// [JsonPropertyName("last_name")] - public string? LastName { get; init; } + public string? LastName { get; set; } /// /// The dependent's relationship to the employee. @@ -54,19 +53,19 @@ public class Dependent /// - `DOMESTIC_PARTNER` - DOMESTIC_PARTNER /// [JsonPropertyName("relationship")] - public RelationshipEnum? Relationship { get; init; } + public RelationshipEnum? Relationship { get; set; } /// /// The employee this person is a dependent of. /// [JsonPropertyName("employee")] - public string? Employee { get; init; } + public string? Employee { get; set; } /// /// The dependent's date of birth. /// [JsonPropertyName("date_of_birth")] - public DateTime? DateOfBirth { get; init; } + public DateTime? DateOfBirth { get; set; } /// /// The dependent's gender. @@ -78,41 +77,41 @@ public class Dependent /// - `PREFER_NOT_TO_DISCLOSE` - PREFER_NOT_TO_DISCLOSE /// [JsonPropertyName("gender")] - public GenderEnum? Gender { get; init; } + public GenderEnum? Gender { get; set; } /// /// The dependent's phone number. /// [JsonPropertyName("phone_number")] - public string? PhoneNumber { get; init; } + public string? PhoneNumber { get; set; } /// /// The dependents's home address. /// [JsonPropertyName("home_location")] - public string? HomeLocation { get; init; } + public string? HomeLocation { get; set; } /// /// Whether or not the dependent is a student /// [JsonPropertyName("is_student")] - public bool? IsStudent { get; init; } + public bool? IsStudent { get; set; } /// /// The dependents's social security number. /// [JsonPropertyName("ssn")] - public string? Ssn { get; init; } + public string? Ssn { get; set; } /// /// Indicates whether or not this object has been deleted in the third party platform. /// [JsonPropertyName("remote_was_deleted")] - public bool? RemoteWasDeleted { get; init; } + public bool? RemoteWasDeleted { get; set; } [JsonPropertyName("field_mappings")] - public Dictionary? FieldMappings { get; init; } + public Dictionary? FieldMappings { get; set; } [JsonPropertyName("remote_data")] - public IEnumerable? RemoteData { get; init; } + public IEnumerable? RemoteData { get; set; } } diff --git a/src/Merge.Client/Hris/Types/Earning.cs b/src/Merge.Client/Hris/Types/Earning.cs index 1661daa6..936827f9 100644 --- a/src/Merge.Client/Hris/Types/Earning.cs +++ b/src/Merge.Client/Hris/Types/Earning.cs @@ -1,41 +1,40 @@ using System.Text.Json.Serialization; -using Merge.Client.Hris; #nullable enable namespace Merge.Client.Hris; -public class Earning +public record Earning { [JsonPropertyName("id")] - public string? Id { get; init; } + public string? Id { get; set; } /// /// The third-party API ID of the matching object. /// [JsonPropertyName("remote_id")] - public string? RemoteId { get; init; } + public string? RemoteId { get; set; } /// /// The datetime that this object was created by Merge. /// [JsonPropertyName("created_at")] - public DateTime? CreatedAt { get; init; } + public DateTime? CreatedAt { get; set; } /// /// The datetime that this object was modified by Merge. /// [JsonPropertyName("modified_at")] - public DateTime? ModifiedAt { get; init; } + public DateTime? ModifiedAt { get; set; } [JsonPropertyName("employee_payroll_run")] - public string? EmployeePayrollRun { get; init; } + public string? EmployeePayrollRun { get; set; } /// /// The amount earned. /// [JsonPropertyName("amount")] - public double? Amount { get; init; } + public double? Amount { get; set; } /// /// The type of earning. @@ -46,17 +45,17 @@ public class Earning /// - `BONUS` - BONUS /// [JsonPropertyName("type")] - public EarningTypeEnum? Type { get; init; } + public EarningTypeEnum? Type { get; set; } /// /// Indicates whether or not this object has been deleted in the third party platform. /// [JsonPropertyName("remote_was_deleted")] - public bool? RemoteWasDeleted { get; init; } + public bool? RemoteWasDeleted { get; set; } [JsonPropertyName("field_mappings")] - public Dictionary? FieldMappings { get; init; } + public Dictionary? FieldMappings { get; set; } [JsonPropertyName("remote_data")] - public IEnumerable? RemoteData { get; init; } + public IEnumerable? RemoteData { get; set; } } diff --git a/src/Merge.Client/Hris/Types/EarningTypeEnum.cs b/src/Merge.Client/Hris/Types/EarningTypeEnum.cs index 1b475872..6faae9e8 100644 --- a/src/Merge.Client/Hris/Types/EarningTypeEnum.cs +++ b/src/Merge.Client/Hris/Types/EarningTypeEnum.cs @@ -1,7 +1,6 @@ using System.Runtime.Serialization; using System.Text.Json.Serialization; using Merge.Client.Core; -using Merge.Client.Hris; #nullable enable diff --git a/src/Merge.Client/Hris/Types/Employee.cs b/src/Merge.Client/Hris/Types/Employee.cs index 8bef3814..e4b86491 100644 --- a/src/Merge.Client/Hris/Types/Employee.cs +++ b/src/Merge.Client/Hris/Types/Employee.cs @@ -1,77 +1,76 @@ using System.Text.Json.Serialization; using Merge.Client.Core; -using Merge.Client.Hris; using OneOf; #nullable enable namespace Merge.Client.Hris; -public class Employee +public record Employee { [JsonPropertyName("id")] - public string? Id { get; init; } + public string? Id { get; set; } /// /// The third-party API ID of the matching object. /// [JsonPropertyName("remote_id")] - public string? RemoteId { get; init; } + public string? RemoteId { get; set; } /// /// The datetime that this object was created by Merge. /// [JsonPropertyName("created_at")] - public DateTime? CreatedAt { get; init; } + public DateTime? CreatedAt { get; set; } /// /// The datetime that this object was modified by Merge. /// [JsonPropertyName("modified_at")] - public DateTime? ModifiedAt { get; init; } + public DateTime? ModifiedAt { get; set; } /// /// The employee's number that appears in the third-party integration's UI. /// [JsonPropertyName("employee_number")] - public string? EmployeeNumber { get; init; } + public string? EmployeeNumber { get; set; } /// /// The ID of the employee's company. /// [JsonPropertyName("company")] [JsonConverter(typeof(OneOfSerializer>))] - public OneOf? Company { get; init; } + public OneOf? Company { get; set; } /// /// The employee's first name. /// [JsonPropertyName("first_name")] - public string? FirstName { get; init; } + public string? FirstName { get; set; } /// /// The employee's last name. /// [JsonPropertyName("last_name")] - public string? LastName { get; init; } + public string? LastName { get; set; } /// /// The employee's preferred first name. /// [JsonPropertyName("preferred_name")] - public string? PreferredName { get; init; } + public string? PreferredName { get; set; } /// /// The employee's full name, to use for display purposes. If a preferred first name is available, the full name will include the preferred first name. /// [JsonPropertyName("display_full_name")] - public string? DisplayFullName { get; init; } + public string? DisplayFullName { get; set; } /// /// The employee's username that appears in the remote UI. /// [JsonPropertyName("username")] - public string? Username { get; init; } + public string? Username { get; set; } [JsonPropertyName("groups")] [JsonConverter( @@ -80,25 +79,25 @@ public class Employee OneOfSerializer> >) )] - public IEnumerable>? Groups { get; init; } + public IEnumerable>? Groups { get; set; } /// /// The employee's work email. /// [JsonPropertyName("work_email")] - public string? WorkEmail { get; init; } + public string? WorkEmail { get; set; } /// /// The employee's personal email. /// [JsonPropertyName("personal_email")] - public string? PersonalEmail { get; init; } + public string? PersonalEmail { get; set; } /// /// The employee's mobile phone number. /// [JsonPropertyName("mobile_phone_number")] - public string? MobilePhoneNumber { get; init; } + public string? MobilePhoneNumber { get; set; } /// /// Array of `Employment` IDs for this Employee. @@ -110,48 +109,48 @@ public class Employee OneOfSerializer> >) )] - public IEnumerable>? Employments { get; init; } + public IEnumerable>? Employments { get; set; } /// /// The employee's home address. /// [JsonPropertyName("home_location")] [JsonConverter(typeof(OneOfSerializer>))] - public OneOf? HomeLocation { get; init; } + public OneOf? HomeLocation { get; set; } /// /// The employee's work address. /// [JsonPropertyName("work_location")] [JsonConverter(typeof(OneOfSerializer>))] - public OneOf? WorkLocation { get; init; } + public OneOf? WorkLocation { get; set; } /// /// The employee ID of the employee's manager. /// [JsonPropertyName("manager")] [JsonConverter(typeof(OneOfSerializer>))] - public OneOf? Manager { get; init; } + public OneOf? Manager { get; set; } /// /// The employee's team. /// [JsonPropertyName("team")] [JsonConverter(typeof(OneOfSerializer>))] - public OneOf? Team { get; init; } + public OneOf? Team { get; set; } /// /// The employee's pay group /// [JsonPropertyName("pay_group")] [JsonConverter(typeof(OneOfSerializer>))] - public OneOf? PayGroup { get; init; } + public OneOf? PayGroup { get; set; } /// /// The employee's social security number. /// [JsonPropertyName("ssn")] - public string? Ssn { get; init; } + public string? Ssn { get; set; } /// /// The employee's gender. @@ -163,7 +162,7 @@ public class Employee /// - `PREFER_NOT_TO_DISCLOSE` - PREFER_NOT_TO_DISCLOSE /// [JsonPropertyName("gender")] - public GenderEnum? Gender { get; init; } + public GenderEnum? Gender { get; set; } /// /// The employee's ethnicity. @@ -178,7 +177,7 @@ public class Employee /// - `PREFER_NOT_TO_DISCLOSE` - PREFER_NOT_TO_DISCLOSE /// [JsonPropertyName("ethnicity")] - public EthnicityEnum? Ethnicity { get; init; } + public EthnicityEnum? Ethnicity { get; set; } /// /// The employee's filing status as related to marital status. @@ -190,31 +189,31 @@ public class Employee /// - `QUALIFYING_WIDOW_OR_WIDOWER_WITH_DEPENDENT_CHILD` - QUALIFYING_WIDOW_OR_WIDOWER_WITH_DEPENDENT_CHILD /// [JsonPropertyName("marital_status")] - public MaritalStatusEnum? MaritalStatus { get; init; } + public MaritalStatusEnum? MaritalStatus { get; set; } /// /// The employee's date of birth. /// [JsonPropertyName("date_of_birth")] - public DateTime? DateOfBirth { get; init; } + public DateTime? DateOfBirth { get; set; } /// /// The date that the employee was hired, usually the day that an offer letter is signed. If an employee has multiple hire dates from previous employments, this represents the most recent hire date. Note: If you're looking for the employee's start date, refer to the start_date field. /// [JsonPropertyName("hire_date")] - public DateTime? HireDate { get; init; } + public DateTime? HireDate { get; set; } /// /// The date that the employee started working. If an employee was rehired, the most recent start date will be returned. /// [JsonPropertyName("start_date")] - public DateTime? StartDate { get; init; } + public DateTime? StartDate { get; set; } /// /// When the third party's employee was created. /// [JsonPropertyName("remote_created_at")] - public DateTime? RemoteCreatedAt { get; init; } + public DateTime? RemoteCreatedAt { get; set; } /// /// The employment status of the employee. @@ -224,32 +223,32 @@ public class Employee /// - `INACTIVE` - INACTIVE /// [JsonPropertyName("employment_status")] - public EmploymentStatusEnum? EmploymentStatus { get; init; } + public EmploymentStatusEnum? EmploymentStatus { get; set; } /// /// The employee's termination date. /// [JsonPropertyName("termination_date")] - public DateTime? TerminationDate { get; init; } + public DateTime? TerminationDate { get; set; } /// /// The URL of the employee's avatar image. /// [JsonPropertyName("avatar")] - public string? Avatar { get; init; } + public string? Avatar { get; set; } /// /// Custom fields configured for a given model. /// [JsonPropertyName("custom_fields")] - public Dictionary? CustomFields { get; init; } + public Dictionary? CustomFields { get; set; } [JsonPropertyName("remote_was_deleted")] - public bool? RemoteWasDeleted { get; init; } + public bool? RemoteWasDeleted { get; set; } [JsonPropertyName("field_mappings")] - public Dictionary? FieldMappings { get; init; } + public Dictionary? FieldMappings { get; set; } [JsonPropertyName("remote_data")] - public IEnumerable? RemoteData { get; init; } + public IEnumerable? RemoteData { get; set; } } diff --git a/src/Merge.Client/Hris/Types/EmployeePayrollRun.cs b/src/Merge.Client/Hris/Types/EmployeePayrollRun.cs index 9f21e5fa..5b8ab3c6 100644 --- a/src/Merge.Client/Hris/Types/EmployeePayrollRun.cs +++ b/src/Merge.Client/Hris/Types/EmployeePayrollRun.cs @@ -1,97 +1,96 @@ using System.Text.Json.Serialization; using Merge.Client.Core; -using Merge.Client.Hris; using OneOf; #nullable enable namespace Merge.Client.Hris; -public class EmployeePayrollRun +public record EmployeePayrollRun { [JsonPropertyName("id")] - public string? Id { get; init; } + public string? Id { get; set; } /// /// The third-party API ID of the matching object. /// [JsonPropertyName("remote_id")] - public string? RemoteId { get; init; } + public string? RemoteId { get; set; } /// /// The datetime that this object was created by Merge. /// [JsonPropertyName("created_at")] - public DateTime? CreatedAt { get; init; } + public DateTime? CreatedAt { get; set; } /// /// The datetime that this object was modified by Merge. /// [JsonPropertyName("modified_at")] - public DateTime? ModifiedAt { get; init; } + public DateTime? ModifiedAt { get; set; } /// /// The employee whose payroll is being run. /// [JsonPropertyName("employee")] [JsonConverter(typeof(OneOfSerializer>))] - public OneOf? Employee { get; init; } + public OneOf? Employee { get; set; } /// /// The payroll being run. /// [JsonPropertyName("payroll_run")] [JsonConverter(typeof(OneOfSerializer>))] - public OneOf? PayrollRun { get; init; } + public OneOf? PayrollRun { get; set; } /// /// The total earnings throughout a given period for an employee before any deductions are made. /// [JsonPropertyName("gross_pay")] - public double? GrossPay { get; init; } + public double? GrossPay { get; set; } /// /// The take-home pay throughout a given period for an employee after deductions are made. /// [JsonPropertyName("net_pay")] - public double? NetPay { get; init; } + public double? NetPay { get; set; } /// /// The day and time the payroll run started. /// [JsonPropertyName("start_date")] - public DateTime? StartDate { get; init; } + public DateTime? StartDate { get; set; } /// /// The day and time the payroll run ended. /// [JsonPropertyName("end_date")] - public DateTime? EndDate { get; init; } + public DateTime? EndDate { get; set; } /// /// The day and time the payroll run was checked. /// [JsonPropertyName("check_date")] - public DateTime? CheckDate { get; init; } + public DateTime? CheckDate { get; set; } [JsonPropertyName("earnings")] - public IEnumerable? Earnings { get; init; } + public IEnumerable? Earnings { get; set; } [JsonPropertyName("deductions")] - public IEnumerable? Deductions { get; init; } + public IEnumerable? Deductions { get; set; } [JsonPropertyName("taxes")] - public IEnumerable? Taxes { get; init; } + public IEnumerable? Taxes { get; set; } /// /// Indicates whether or not this object has been deleted in the third party platform. /// [JsonPropertyName("remote_was_deleted")] - public bool? RemoteWasDeleted { get; init; } + public bool? RemoteWasDeleted { get; set; } [JsonPropertyName("field_mappings")] - public Dictionary? FieldMappings { get; init; } + public Dictionary? FieldMappings { get; set; } [JsonPropertyName("remote_data")] - public IEnumerable? RemoteData { get; init; } + public IEnumerable? RemoteData { get; set; } } diff --git a/src/Merge.Client/Hris/Types/EmployeeRequest.cs b/src/Merge.Client/Hris/Types/EmployeeRequest.cs index 8f781fce..db1e32cc 100644 --- a/src/Merge.Client/Hris/Types/EmployeeRequest.cs +++ b/src/Merge.Client/Hris/Types/EmployeeRequest.cs @@ -1,56 +1,55 @@ using System.Text.Json.Serialization; using Merge.Client.Core; -using Merge.Client.Hris; using OneOf; #nullable enable namespace Merge.Client.Hris; -public class EmployeeRequest +public record EmployeeRequest { /// /// The employee's number that appears in the third-party integration's UI. /// [JsonPropertyName("employee_number")] - public string? EmployeeNumber { get; init; } + public string? EmployeeNumber { get; set; } /// /// The ID of the employee's company. /// [JsonPropertyName("company")] [JsonConverter(typeof(OneOfSerializer>))] - public OneOf? Company { get; init; } + public OneOf? Company { get; set; } /// /// The employee's first name. /// [JsonPropertyName("first_name")] - public string? FirstName { get; init; } + public string? FirstName { get; set; } /// /// The employee's last name. /// [JsonPropertyName("last_name")] - public string? LastName { get; init; } + public string? LastName { get; set; } /// /// The employee's preferred first name. /// [JsonPropertyName("preferred_name")] - public string? PreferredName { get; init; } + public string? PreferredName { get; set; } /// /// The employee's full name, to use for display purposes. If a preferred first name is available, the full name will include the preferred first name. /// [JsonPropertyName("display_full_name")] - public string? DisplayFullName { get; init; } + public string? DisplayFullName { get; set; } /// /// The employee's username that appears in the remote UI. /// [JsonPropertyName("username")] - public string? Username { get; init; } + public string? Username { get; set; } [JsonPropertyName("groups")] [JsonConverter( @@ -59,25 +58,25 @@ public class EmployeeRequest OneOfSerializer> >) )] - public IEnumerable>? Groups { get; init; } + public IEnumerable>? Groups { get; set; } /// /// The employee's work email. /// [JsonPropertyName("work_email")] - public string? WorkEmail { get; init; } + public string? WorkEmail { get; set; } /// /// The employee's personal email. /// [JsonPropertyName("personal_email")] - public string? PersonalEmail { get; init; } + public string? PersonalEmail { get; set; } /// /// The employee's mobile phone number. /// [JsonPropertyName("mobile_phone_number")] - public string? MobilePhoneNumber { get; init; } + public string? MobilePhoneNumber { get; set; } /// /// Array of `Employment` IDs for this Employee. @@ -89,48 +88,48 @@ public class EmployeeRequest OneOfSerializer> >) )] - public IEnumerable>? Employments { get; init; } + public IEnumerable>? Employments { get; set; } /// /// The employee's home address. /// [JsonPropertyName("home_location")] [JsonConverter(typeof(OneOfSerializer>))] - public OneOf? HomeLocation { get; init; } + public OneOf? HomeLocation { get; set; } /// /// The employee's work address. /// [JsonPropertyName("work_location")] [JsonConverter(typeof(OneOfSerializer>))] - public OneOf? WorkLocation { get; init; } + public OneOf? WorkLocation { get; set; } /// /// The employee ID of the employee's manager. /// [JsonPropertyName("manager")] [JsonConverter(typeof(OneOfSerializer>))] - public OneOf? Manager { get; init; } + public OneOf? Manager { get; set; } /// /// The employee's team. /// [JsonPropertyName("team")] [JsonConverter(typeof(OneOfSerializer>))] - public OneOf? Team { get; init; } + public OneOf? Team { get; set; } /// /// The employee's pay group /// [JsonPropertyName("pay_group")] [JsonConverter(typeof(OneOfSerializer>))] - public OneOf? PayGroup { get; init; } + public OneOf? PayGroup { get; set; } /// /// The employee's social security number. /// [JsonPropertyName("ssn")] - public string? Ssn { get; init; } + public string? Ssn { get; set; } /// /// The employee's gender. @@ -142,7 +141,7 @@ public class EmployeeRequest /// - `PREFER_NOT_TO_DISCLOSE` - PREFER_NOT_TO_DISCLOSE /// [JsonPropertyName("gender")] - public GenderEnum? Gender { get; init; } + public GenderEnum? Gender { get; set; } /// /// The employee's ethnicity. @@ -157,7 +156,7 @@ public class EmployeeRequest /// - `PREFER_NOT_TO_DISCLOSE` - PREFER_NOT_TO_DISCLOSE /// [JsonPropertyName("ethnicity")] - public EthnicityEnum? Ethnicity { get; init; } + public EthnicityEnum? Ethnicity { get; set; } /// /// The employee's filing status as related to marital status. @@ -169,25 +168,25 @@ public class EmployeeRequest /// - `QUALIFYING_WIDOW_OR_WIDOWER_WITH_DEPENDENT_CHILD` - QUALIFYING_WIDOW_OR_WIDOWER_WITH_DEPENDENT_CHILD /// [JsonPropertyName("marital_status")] - public MaritalStatusEnum? MaritalStatus { get; init; } + public MaritalStatusEnum? MaritalStatus { get; set; } /// /// The employee's date of birth. /// [JsonPropertyName("date_of_birth")] - public DateTime? DateOfBirth { get; init; } + public DateTime? DateOfBirth { get; set; } /// /// The date that the employee was hired, usually the day that an offer letter is signed. If an employee has multiple hire dates from previous employments, this represents the most recent hire date. Note: If you're looking for the employee's start date, refer to the start_date field. /// [JsonPropertyName("hire_date")] - public DateTime? HireDate { get; init; } + public DateTime? HireDate { get; set; } /// /// The date that the employee started working. If an employee was rehired, the most recent start date will be returned. /// [JsonPropertyName("start_date")] - public DateTime? StartDate { get; init; } + public DateTime? StartDate { get; set; } /// /// The employment status of the employee. @@ -197,23 +196,23 @@ public class EmployeeRequest /// - `INACTIVE` - INACTIVE /// [JsonPropertyName("employment_status")] - public EmploymentStatusEnum? EmploymentStatus { get; init; } + public EmploymentStatusEnum? EmploymentStatus { get; set; } /// /// The employee's termination date. /// [JsonPropertyName("termination_date")] - public DateTime? TerminationDate { get; init; } + public DateTime? TerminationDate { get; set; } /// /// The URL of the employee's avatar image. /// [JsonPropertyName("avatar")] - public string? Avatar { get; init; } + public string? Avatar { get; set; } [JsonPropertyName("integration_params")] - public Dictionary? IntegrationParams { get; init; } + public Dictionary? IntegrationParams { get; set; } [JsonPropertyName("linked_account_params")] - public Dictionary? LinkedAccountParams { get; init; } + public Dictionary? LinkedAccountParams { get; set; } } diff --git a/src/Merge.Client/Hris/Types/EmployeeResponse.cs b/src/Merge.Client/Hris/Types/EmployeeResponse.cs index bf704d27..f55c4254 100644 --- a/src/Merge.Client/Hris/Types/EmployeeResponse.cs +++ b/src/Merge.Client/Hris/Types/EmployeeResponse.cs @@ -1,21 +1,22 @@ using System.Text.Json.Serialization; -using Merge.Client.Hris; #nullable enable namespace Merge.Client.Hris; -public class EmployeeResponse +public record EmployeeResponse { [JsonPropertyName("model")] - public Employee Model { get; init; } + public required Employee Model { get; set; } [JsonPropertyName("warnings")] - public IEnumerable Warnings { get; init; } + public IEnumerable Warnings { get; set; } = + new List(); [JsonPropertyName("errors")] - public IEnumerable Errors { get; init; } + public IEnumerable Errors { get; set; } = + new List(); [JsonPropertyName("logs")] - public IEnumerable? Logs { get; init; } + public IEnumerable? Logs { get; set; } } diff --git a/src/Merge.Client/Hris/Types/EmployerBenefit.cs b/src/Merge.Client/Hris/Types/EmployerBenefit.cs index a12183c3..af13b503 100644 --- a/src/Merge.Client/Hris/Types/EmployerBenefit.cs +++ b/src/Merge.Client/Hris/Types/EmployerBenefit.cs @@ -1,32 +1,31 @@ using System.Text.Json.Serialization; -using Merge.Client.Hris; #nullable enable namespace Merge.Client.Hris; -public class EmployerBenefit +public record EmployerBenefit { [JsonPropertyName("id")] - public string? Id { get; init; } + public string? Id { get; set; } /// /// The third-party API ID of the matching object. /// [JsonPropertyName("remote_id")] - public string? RemoteId { get; init; } + public string? RemoteId { get; set; } /// /// The datetime that this object was created by Merge. /// [JsonPropertyName("created_at")] - public DateTime? CreatedAt { get; init; } + public DateTime? CreatedAt { get; set; } /// /// The datetime that this object was modified by Merge. /// [JsonPropertyName("modified_at")] - public DateTime? ModifiedAt { get; init; } + public DateTime? ModifiedAt { get; set; } /// /// The type of benefit plan. @@ -38,35 +37,35 @@ public class EmployerBenefit /// - `OTHER` - OTHER /// [JsonPropertyName("benefit_plan_type")] - public BenefitPlanTypeEnum? BenefitPlanType { get; init; } + public BenefitPlanTypeEnum? BenefitPlanType { get; set; } /// /// The employer benefit's name - typically the carrier or network name. /// [JsonPropertyName("name")] - public string? Name { get; init; } + public string? Name { get; set; } /// /// The employer benefit's description. /// [JsonPropertyName("description")] - public string? Description { get; init; } + public string? Description { get; set; } /// /// The employer benefit's deduction code. /// [JsonPropertyName("deduction_code")] - public string? DeductionCode { get; init; } + public string? DeductionCode { get; set; } /// /// Indicates whether or not this object has been deleted in the third party platform. /// [JsonPropertyName("remote_was_deleted")] - public bool? RemoteWasDeleted { get; init; } + public bool? RemoteWasDeleted { get; set; } [JsonPropertyName("field_mappings")] - public Dictionary? FieldMappings { get; init; } + public Dictionary? FieldMappings { get; set; } [JsonPropertyName("remote_data")] - public IEnumerable>? RemoteData { get; init; } + public IEnumerable>? RemoteData { get; set; } } diff --git a/src/Merge.Client/Hris/Types/Employment.cs b/src/Merge.Client/Hris/Types/Employment.cs index e942b77a..dc01e430 100644 --- a/src/Merge.Client/Hris/Types/Employment.cs +++ b/src/Merge.Client/Hris/Types/Employment.cs @@ -1,53 +1,52 @@ using System.Text.Json.Serialization; using Merge.Client.Core; -using Merge.Client.Hris; using OneOf; #nullable enable namespace Merge.Client.Hris; -public class Employment +public record Employment { [JsonPropertyName("id")] - public string? Id { get; init; } + public string? Id { get; set; } /// /// The third-party API ID of the matching object. /// [JsonPropertyName("remote_id")] - public string? RemoteId { get; init; } + public string? RemoteId { get; set; } /// /// The datetime that this object was created by Merge. /// [JsonPropertyName("created_at")] - public DateTime? CreatedAt { get; init; } + public DateTime? CreatedAt { get; set; } /// /// The datetime that this object was modified by Merge. /// [JsonPropertyName("modified_at")] - public DateTime? ModifiedAt { get; init; } + public DateTime? ModifiedAt { get; set; } /// /// The employee holding this position. /// [JsonPropertyName("employee")] [JsonConverter(typeof(OneOfSerializer>))] - public OneOf? Employee { get; init; } + public OneOf? Employee { get; set; } /// /// The position's title. /// [JsonPropertyName("job_title")] - public string? JobTitle { get; init; } + public string? JobTitle { get; set; } /// /// The position's pay rate in dollars. /// [JsonPropertyName("pay_rate")] - public double? PayRate { get; init; } + public double? PayRate { get; set; } /// /// The time period this pay rate encompasses. @@ -63,7 +62,7 @@ public class Employment /// - `YEAR` - YEAR /// [JsonPropertyName("pay_period")] - public PayPeriodEnum? PayPeriod { get; init; } + public PayPeriodEnum? PayPeriod { get; set; } /// /// The position's pay frequency. @@ -79,7 +78,7 @@ public class Employment /// - `SEMIMONTHLY` - SEMIMONTHLY /// [JsonPropertyName("pay_frequency")] - public PayFrequencyEnum? PayFrequency { get; init; } + public PayFrequencyEnum? PayFrequency { get; set; } /// /// The position's currency code. @@ -392,14 +391,14 @@ public class Employment /// - `ZWL` - Zimbabwean Dollar (2009) /// [JsonPropertyName("pay_currency")] - public PayCurrencyEnum? PayCurrency { get; init; } + public PayCurrencyEnum? PayCurrency { get; set; } /// /// The employment's pay group /// [JsonPropertyName("pay_group")] [JsonConverter(typeof(OneOfSerializer>))] - public OneOf? PayGroup { get; init; } + public OneOf? PayGroup { get; set; } /// /// The position's FLSA status. @@ -410,13 +409,13 @@ public class Employment /// - `OWNER` - OWNER /// [JsonPropertyName("flsa_status")] - public FlsaStatusEnum? FlsaStatus { get; init; } + public FlsaStatusEnum? FlsaStatus { get; set; } /// /// The position's effective date. /// [JsonPropertyName("effective_date")] - public DateTime? EffectiveDate { get; init; } + public DateTime? EffectiveDate { get; set; } /// /// The position's type of employment. @@ -428,17 +427,17 @@ public class Employment /// - `FREELANCE` - FREELANCE /// [JsonPropertyName("employment_type")] - public EmploymentTypeEnum? EmploymentType { get; init; } + public EmploymentTypeEnum? EmploymentType { get; set; } /// /// Indicates whether or not this object has been deleted in the third party platform. /// [JsonPropertyName("remote_was_deleted")] - public bool? RemoteWasDeleted { get; init; } + public bool? RemoteWasDeleted { get; set; } [JsonPropertyName("field_mappings")] - public Dictionary? FieldMappings { get; init; } + public Dictionary? FieldMappings { get; set; } [JsonPropertyName("remote_data")] - public IEnumerable? RemoteData { get; init; } + public IEnumerable? RemoteData { get; set; } } diff --git a/src/Merge.Client/Hris/Types/EmploymentStatusEnum.cs b/src/Merge.Client/Hris/Types/EmploymentStatusEnum.cs index 72cbb783..9e0da61c 100644 --- a/src/Merge.Client/Hris/Types/EmploymentStatusEnum.cs +++ b/src/Merge.Client/Hris/Types/EmploymentStatusEnum.cs @@ -1,7 +1,6 @@ using System.Runtime.Serialization; using System.Text.Json.Serialization; using Merge.Client.Core; -using Merge.Client.Hris; #nullable enable diff --git a/src/Merge.Client/Hris/Types/EmploymentTypeEnum.cs b/src/Merge.Client/Hris/Types/EmploymentTypeEnum.cs index 4e25e5d7..26d17b86 100644 --- a/src/Merge.Client/Hris/Types/EmploymentTypeEnum.cs +++ b/src/Merge.Client/Hris/Types/EmploymentTypeEnum.cs @@ -1,7 +1,6 @@ using System.Runtime.Serialization; using System.Text.Json.Serialization; using Merge.Client.Core; -using Merge.Client.Hris; #nullable enable diff --git a/src/Merge.Client/Hris/Types/EnabledActionsEnum.cs b/src/Merge.Client/Hris/Types/EnabledActionsEnum.cs index 6b1bbe6c..38556e91 100644 --- a/src/Merge.Client/Hris/Types/EnabledActionsEnum.cs +++ b/src/Merge.Client/Hris/Types/EnabledActionsEnum.cs @@ -1,7 +1,6 @@ using System.Runtime.Serialization; using System.Text.Json.Serialization; using Merge.Client.Core; -using Merge.Client.Hris; #nullable enable diff --git a/src/Merge.Client/Hris/Types/EncodingEnum.cs b/src/Merge.Client/Hris/Types/EncodingEnum.cs index 483b5387..3ad255e4 100644 --- a/src/Merge.Client/Hris/Types/EncodingEnum.cs +++ b/src/Merge.Client/Hris/Types/EncodingEnum.cs @@ -1,7 +1,6 @@ using System.Runtime.Serialization; using System.Text.Json.Serialization; using Merge.Client.Core; -using Merge.Client.Hris; #nullable enable diff --git a/src/Merge.Client/Hris/Types/ErrorValidationProblem.cs b/src/Merge.Client/Hris/Types/ErrorValidationProblem.cs index 60c7a104..642995c2 100644 --- a/src/Merge.Client/Hris/Types/ErrorValidationProblem.cs +++ b/src/Merge.Client/Hris/Types/ErrorValidationProblem.cs @@ -1,21 +1,20 @@ using System.Text.Json.Serialization; -using Merge.Client.Hris; #nullable enable namespace Merge.Client.Hris; -public class ErrorValidationProblem +public record ErrorValidationProblem { [JsonPropertyName("source")] - public ValidationProblemSource? Source { get; init; } + public ValidationProblemSource? Source { get; set; } [JsonPropertyName("title")] - public string Title { get; init; } + public required string Title { get; set; } [JsonPropertyName("detail")] - public string Detail { get; init; } + public required string Detail { get; set; } [JsonPropertyName("problem_type")] - public string ProblemType { get; init; } + public required string ProblemType { get; set; } } diff --git a/src/Merge.Client/Hris/Types/EthnicityEnum.cs b/src/Merge.Client/Hris/Types/EthnicityEnum.cs index 4cb05c2a..7926a47e 100644 --- a/src/Merge.Client/Hris/Types/EthnicityEnum.cs +++ b/src/Merge.Client/Hris/Types/EthnicityEnum.cs @@ -1,7 +1,6 @@ using System.Runtime.Serialization; using System.Text.Json.Serialization; using Merge.Client.Core; -using Merge.Client.Hris; #nullable enable diff --git a/src/Merge.Client/Hris/Types/EventTypeEnum.cs b/src/Merge.Client/Hris/Types/EventTypeEnum.cs index 6d73c538..35f4ccf7 100644 --- a/src/Merge.Client/Hris/Types/EventTypeEnum.cs +++ b/src/Merge.Client/Hris/Types/EventTypeEnum.cs @@ -1,7 +1,6 @@ using System.Runtime.Serialization; using System.Text.Json.Serialization; using Merge.Client.Core; -using Merge.Client.Hris; #nullable enable diff --git a/src/Merge.Client/Hris/Types/ExternalTargetFieldApi.cs b/src/Merge.Client/Hris/Types/ExternalTargetFieldApi.cs index f221b005..4314b0ca 100644 --- a/src/Merge.Client/Hris/Types/ExternalTargetFieldApi.cs +++ b/src/Merge.Client/Hris/Types/ExternalTargetFieldApi.cs @@ -4,14 +4,14 @@ namespace Merge.Client.Hris; -public class ExternalTargetFieldApi +public record ExternalTargetFieldApi { [JsonPropertyName("name")] - public string? Name { get; init; } + public string? Name { get; set; } [JsonPropertyName("description")] - public string? Description { get; init; } + public string? Description { get; set; } [JsonPropertyName("is_mapped")] - public string? IsMapped { get; init; } + public string? IsMapped { get; set; } } diff --git a/src/Merge.Client/Hris/Types/ExternalTargetFieldApiResponse.cs b/src/Merge.Client/Hris/Types/ExternalTargetFieldApiResponse.cs index c49e22c0..e357a090 100644 --- a/src/Merge.Client/Hris/Types/ExternalTargetFieldApiResponse.cs +++ b/src/Merge.Client/Hris/Types/ExternalTargetFieldApiResponse.cs @@ -1,57 +1,56 @@ using System.Text.Json.Serialization; -using Merge.Client.Hris; #nullable enable namespace Merge.Client.Hris; -public class ExternalTargetFieldApiResponse +public record ExternalTargetFieldApiResponse { [JsonPropertyName("Benefit")] - public IEnumerable? Benefit { get; init; } + public IEnumerable? Benefit { get; set; } [JsonPropertyName("EmployerBenefit")] - public IEnumerable? EmployerBenefit { get; init; } + public IEnumerable? EmployerBenefit { get; set; } [JsonPropertyName("Company")] - public IEnumerable? Company { get; init; } + public IEnumerable? Company { get; set; } [JsonPropertyName("EmployeePayrollRun")] - public IEnumerable? EmployeePayrollRun { get; init; } + public IEnumerable? EmployeePayrollRun { get; set; } [JsonPropertyName("Employee")] - public IEnumerable? Employee { get; init; } + public IEnumerable? Employee { get; set; } [JsonPropertyName("Employment")] - public IEnumerable? Employment { get; init; } + public IEnumerable? Employment { get; set; } [JsonPropertyName("Location")] - public IEnumerable? Location { get; init; } + public IEnumerable? Location { get; set; } [JsonPropertyName("PayrollRun")] - public IEnumerable? PayrollRun { get; init; } + public IEnumerable? PayrollRun { get; set; } [JsonPropertyName("Team")] - public IEnumerable? Team { get; init; } + public IEnumerable? Team { get; set; } [JsonPropertyName("TimeOff")] - public IEnumerable? TimeOff { get; init; } + public IEnumerable? TimeOff { get; set; } [JsonPropertyName("TimeOffBalance")] - public IEnumerable? TimeOffBalance { get; init; } + public IEnumerable? TimeOffBalance { get; set; } [JsonPropertyName("BankInfo")] - public IEnumerable? BankInfo { get; init; } + public IEnumerable? BankInfo { get; set; } [JsonPropertyName("PayGroup")] - public IEnumerable? PayGroup { get; init; } + public IEnumerable? PayGroup { get; set; } [JsonPropertyName("Group")] - public IEnumerable? Group { get; init; } + public IEnumerable? Group { get; set; } [JsonPropertyName("Dependent")] - public IEnumerable? Dependent { get; init; } + public IEnumerable? Dependent { get; set; } [JsonPropertyName("TimesheetEntry")] - public IEnumerable? TimesheetEntry { get; init; } + public IEnumerable? TimesheetEntry { get; set; } } diff --git a/src/Merge.Client/Hris/Types/FieldMappingApiInstance.cs b/src/Merge.Client/Hris/Types/FieldMappingApiInstance.cs index d7953e73..f3783716 100644 --- a/src/Merge.Client/Hris/Types/FieldMappingApiInstance.cs +++ b/src/Merge.Client/Hris/Types/FieldMappingApiInstance.cs @@ -1,21 +1,20 @@ using System.Text.Json.Serialization; -using Merge.Client.Hris; #nullable enable namespace Merge.Client.Hris; -public class FieldMappingApiInstance +public record FieldMappingApiInstance { [JsonPropertyName("id")] - public string? Id { get; init; } + public string? Id { get; set; } [JsonPropertyName("is_integration_wide")] - public bool? IsIntegrationWide { get; init; } + public bool? IsIntegrationWide { get; set; } [JsonPropertyName("target_field")] - public FieldMappingApiInstanceTargetField? TargetField { get; init; } + public FieldMappingApiInstanceTargetField? TargetField { get; set; } [JsonPropertyName("remote_field")] - public FieldMappingApiInstanceRemoteField? RemoteField { get; init; } + public FieldMappingApiInstanceRemoteField? RemoteField { get; set; } } diff --git a/src/Merge.Client/Hris/Types/FieldMappingApiInstanceRemoteField.cs b/src/Merge.Client/Hris/Types/FieldMappingApiInstanceRemoteField.cs index 2200b7cc..784f62d0 100644 --- a/src/Merge.Client/Hris/Types/FieldMappingApiInstanceRemoteField.cs +++ b/src/Merge.Client/Hris/Types/FieldMappingApiInstanceRemoteField.cs @@ -1,18 +1,17 @@ using System.Text.Json.Serialization; -using Merge.Client.Hris; #nullable enable namespace Merge.Client.Hris; -public class FieldMappingApiInstanceRemoteField +public record FieldMappingApiInstanceRemoteField { [JsonPropertyName("remote_key_name")] - public string RemoteKeyName { get; init; } + public required string RemoteKeyName { get; set; } [JsonPropertyName("schema")] - public Dictionary Schema { get; init; } + public Dictionary Schema { get; set; } = new Dictionary(); [JsonPropertyName("remote_endpoint_info")] - public FieldMappingApiInstanceRemoteFieldRemoteEndpointInfo RemoteEndpointInfo { get; init; } + public required FieldMappingApiInstanceRemoteFieldRemoteEndpointInfo RemoteEndpointInfo { get; set; } } diff --git a/src/Merge.Client/Hris/Types/FieldMappingApiInstanceRemoteFieldRemoteEndpointInfo.cs b/src/Merge.Client/Hris/Types/FieldMappingApiInstanceRemoteFieldRemoteEndpointInfo.cs index f0cc6faa..6ac95e9b 100644 --- a/src/Merge.Client/Hris/Types/FieldMappingApiInstanceRemoteFieldRemoteEndpointInfo.cs +++ b/src/Merge.Client/Hris/Types/FieldMappingApiInstanceRemoteFieldRemoteEndpointInfo.cs @@ -4,14 +4,14 @@ namespace Merge.Client.Hris; -public class FieldMappingApiInstanceRemoteFieldRemoteEndpointInfo +public record FieldMappingApiInstanceRemoteFieldRemoteEndpointInfo { [JsonPropertyName("method")] - public string? Method { get; init; } + public string? Method { get; set; } [JsonPropertyName("url_path")] - public string? UrlPath { get; init; } + public string? UrlPath { get; set; } [JsonPropertyName("field_traversal_path")] - public IEnumerable? FieldTraversalPath { get; init; } + public IEnumerable? FieldTraversalPath { get; set; } } diff --git a/src/Merge.Client/Hris/Types/FieldMappingApiInstanceResponse.cs b/src/Merge.Client/Hris/Types/FieldMappingApiInstanceResponse.cs index 5ab6cfbb..72f70a49 100644 --- a/src/Merge.Client/Hris/Types/FieldMappingApiInstanceResponse.cs +++ b/src/Merge.Client/Hris/Types/FieldMappingApiInstanceResponse.cs @@ -1,57 +1,56 @@ using System.Text.Json.Serialization; -using Merge.Client.Hris; #nullable enable namespace Merge.Client.Hris; -public class FieldMappingApiInstanceResponse +public record FieldMappingApiInstanceResponse { [JsonPropertyName("Benefit")] - public IEnumerable? Benefit { get; init; } + public IEnumerable? Benefit { get; set; } [JsonPropertyName("EmployerBenefit")] - public IEnumerable? EmployerBenefit { get; init; } + public IEnumerable? EmployerBenefit { get; set; } [JsonPropertyName("Company")] - public IEnumerable? Company { get; init; } + public IEnumerable? Company { get; set; } [JsonPropertyName("EmployeePayrollRun")] - public IEnumerable? EmployeePayrollRun { get; init; } + public IEnumerable? EmployeePayrollRun { get; set; } [JsonPropertyName("Employee")] - public IEnumerable? Employee { get; init; } + public IEnumerable? Employee { get; set; } [JsonPropertyName("Employment")] - public IEnumerable? Employment { get; init; } + public IEnumerable? Employment { get; set; } [JsonPropertyName("Location")] - public IEnumerable? Location { get; init; } + public IEnumerable? Location { get; set; } [JsonPropertyName("PayrollRun")] - public IEnumerable? PayrollRun { get; init; } + public IEnumerable? PayrollRun { get; set; } [JsonPropertyName("Team")] - public IEnumerable? Team { get; init; } + public IEnumerable? Team { get; set; } [JsonPropertyName("TimeOff")] - public IEnumerable? TimeOff { get; init; } + public IEnumerable? TimeOff { get; set; } [JsonPropertyName("TimeOffBalance")] - public IEnumerable? TimeOffBalance { get; init; } + public IEnumerable? TimeOffBalance { get; set; } [JsonPropertyName("BankInfo")] - public IEnumerable? BankInfo { get; init; } + public IEnumerable? BankInfo { get; set; } [JsonPropertyName("PayGroup")] - public IEnumerable? PayGroup { get; init; } + public IEnumerable? PayGroup { get; set; } [JsonPropertyName("Group")] - public IEnumerable? Group { get; init; } + public IEnumerable? Group { get; set; } [JsonPropertyName("Dependent")] - public IEnumerable? Dependent { get; init; } + public IEnumerable? Dependent { get; set; } [JsonPropertyName("TimesheetEntry")] - public IEnumerable? TimesheetEntry { get; init; } + public IEnumerable? TimesheetEntry { get; set; } } diff --git a/src/Merge.Client/Hris/Types/FieldMappingApiInstanceTargetField.cs b/src/Merge.Client/Hris/Types/FieldMappingApiInstanceTargetField.cs index b536a11c..8f4237f2 100644 --- a/src/Merge.Client/Hris/Types/FieldMappingApiInstanceTargetField.cs +++ b/src/Merge.Client/Hris/Types/FieldMappingApiInstanceTargetField.cs @@ -4,14 +4,14 @@ namespace Merge.Client.Hris; -public class FieldMappingApiInstanceTargetField +public record FieldMappingApiInstanceTargetField { [JsonPropertyName("name")] - public string Name { get; init; } + public required string Name { get; set; } [JsonPropertyName("description")] - public string Description { get; init; } + public required string Description { get; set; } [JsonPropertyName("is_organization_wide")] - public bool IsOrganizationWide { get; init; } + public required bool IsOrganizationWide { get; set; } } diff --git a/src/Merge.Client/Hris/Types/FieldMappingInstanceResponse.cs b/src/Merge.Client/Hris/Types/FieldMappingInstanceResponse.cs index b27afe2c..3fec4504 100644 --- a/src/Merge.Client/Hris/Types/FieldMappingInstanceResponse.cs +++ b/src/Merge.Client/Hris/Types/FieldMappingInstanceResponse.cs @@ -1,21 +1,22 @@ using System.Text.Json.Serialization; -using Merge.Client.Hris; #nullable enable namespace Merge.Client.Hris; -public class FieldMappingInstanceResponse +public record FieldMappingInstanceResponse { [JsonPropertyName("model")] - public FieldMappingApiInstance Model { get; init; } + public required FieldMappingApiInstance Model { get; set; } [JsonPropertyName("warnings")] - public IEnumerable Warnings { get; init; } + public IEnumerable Warnings { get; set; } = + new List(); [JsonPropertyName("errors")] - public IEnumerable Errors { get; init; } + public IEnumerable Errors { get; set; } = + new List(); [JsonPropertyName("logs")] - public IEnumerable? Logs { get; init; } + public IEnumerable? Logs { get; set; } } diff --git a/src/Merge.Client/Hris/Types/FieldPermissionDeserializer.cs b/src/Merge.Client/Hris/Types/FieldPermissionDeserializer.cs index c2a359ed..d81cf212 100644 --- a/src/Merge.Client/Hris/Types/FieldPermissionDeserializer.cs +++ b/src/Merge.Client/Hris/Types/FieldPermissionDeserializer.cs @@ -4,11 +4,11 @@ namespace Merge.Client.Hris; -public class FieldPermissionDeserializer +public record FieldPermissionDeserializer { [JsonPropertyName("enabled")] - public IEnumerable? Enabled { get; init; } + public IEnumerable? Enabled { get; set; } [JsonPropertyName("disabled")] - public IEnumerable? Disabled { get; init; } + public IEnumerable? Disabled { get; set; } } diff --git a/src/Merge.Client/Hris/Types/FieldPermissionDeserializerRequest.cs b/src/Merge.Client/Hris/Types/FieldPermissionDeserializerRequest.cs index f2d228a4..e9995334 100644 --- a/src/Merge.Client/Hris/Types/FieldPermissionDeserializerRequest.cs +++ b/src/Merge.Client/Hris/Types/FieldPermissionDeserializerRequest.cs @@ -4,11 +4,11 @@ namespace Merge.Client.Hris; -public class FieldPermissionDeserializerRequest +public record FieldPermissionDeserializerRequest { [JsonPropertyName("enabled")] - public IEnumerable? Enabled { get; init; } + public IEnumerable? Enabled { get; set; } [JsonPropertyName("disabled")] - public IEnumerable? Disabled { get; init; } + public IEnumerable? Disabled { get; set; } } diff --git a/src/Merge.Client/Hris/Types/FlsaStatusEnum.cs b/src/Merge.Client/Hris/Types/FlsaStatusEnum.cs index d16aa9ad..267b31e1 100644 --- a/src/Merge.Client/Hris/Types/FlsaStatusEnum.cs +++ b/src/Merge.Client/Hris/Types/FlsaStatusEnum.cs @@ -1,7 +1,6 @@ using System.Runtime.Serialization; using System.Text.Json.Serialization; using Merge.Client.Core; -using Merge.Client.Hris; #nullable enable diff --git a/src/Merge.Client/Hris/Types/GenderEnum.cs b/src/Merge.Client/Hris/Types/GenderEnum.cs index cab6f8cb..296b4c3a 100644 --- a/src/Merge.Client/Hris/Types/GenderEnum.cs +++ b/src/Merge.Client/Hris/Types/GenderEnum.cs @@ -1,7 +1,6 @@ using System.Runtime.Serialization; using System.Text.Json.Serialization; using Merge.Client.Core; -using Merge.Client.Hris; #nullable enable diff --git a/src/Merge.Client/Hris/Types/Group.cs b/src/Merge.Client/Hris/Types/Group.cs index 704ecf1f..75fb2b3d 100644 --- a/src/Merge.Client/Hris/Types/Group.cs +++ b/src/Merge.Client/Hris/Types/Group.cs @@ -1,44 +1,43 @@ using System.Text.Json.Serialization; -using Merge.Client.Hris; #nullable enable namespace Merge.Client.Hris; -public class Group +public record Group { [JsonPropertyName("id")] - public string? Id { get; init; } + public string? Id { get; set; } /// /// The third-party API ID of the matching object. /// [JsonPropertyName("remote_id")] - public string? RemoteId { get; init; } + public string? RemoteId { get; set; } /// /// The datetime that this object was created by Merge. /// [JsonPropertyName("created_at")] - public DateTime? CreatedAt { get; init; } + public DateTime? CreatedAt { get; set; } /// /// The datetime that this object was modified by Merge. /// [JsonPropertyName("modified_at")] - public DateTime? ModifiedAt { get; init; } + public DateTime? ModifiedAt { get; set; } /// /// The parent group for this group. /// [JsonPropertyName("parent_group")] - public string? ParentGroup { get; init; } + public string? ParentGroup { get; set; } /// /// The group name. /// [JsonPropertyName("name")] - public string? Name { get; init; } + public string? Name { get; set; } /// /// The Group type returned directly from the third-party. @@ -50,23 +49,23 @@ public class Group /// - `GROUP` - GROUP /// [JsonPropertyName("type")] - public GroupTypeEnum? Type { get; init; } + public GroupTypeEnum? Type { get; set; } /// /// Indicates whether or not this object has been deleted in the third party platform. /// [JsonPropertyName("remote_was_deleted")] - public bool? RemoteWasDeleted { get; init; } + public bool? RemoteWasDeleted { get; set; } /// /// Indicates whether the Group refers to a team in the third party platform. Note that this is an opinionated view based on how Merge observes most organizations representing teams in each third party platform. If your customer uses a platform different from most, there is a chance this will not be correct. /// [JsonPropertyName("is_commonly_used_as_team")] - public bool? IsCommonlyUsedAsTeam { get; init; } + public bool? IsCommonlyUsedAsTeam { get; set; } [JsonPropertyName("field_mappings")] - public Dictionary? FieldMappings { get; init; } + public Dictionary? FieldMappings { get; set; } [JsonPropertyName("remote_data")] - public IEnumerable? RemoteData { get; init; } + public IEnumerable? RemoteData { get; set; } } diff --git a/src/Merge.Client/Hris/Types/GroupTypeEnum.cs b/src/Merge.Client/Hris/Types/GroupTypeEnum.cs index e02b3300..925e8e91 100644 --- a/src/Merge.Client/Hris/Types/GroupTypeEnum.cs +++ b/src/Merge.Client/Hris/Types/GroupTypeEnum.cs @@ -1,7 +1,6 @@ using System.Runtime.Serialization; using System.Text.Json.Serialization; using Merge.Client.Core; -using Merge.Client.Hris; #nullable enable diff --git a/src/Merge.Client/Hris/Types/IndividualCommonModelScopeDeserializer.cs b/src/Merge.Client/Hris/Types/IndividualCommonModelScopeDeserializer.cs index e218ffe7..da01d2c6 100644 --- a/src/Merge.Client/Hris/Types/IndividualCommonModelScopeDeserializer.cs +++ b/src/Merge.Client/Hris/Types/IndividualCommonModelScopeDeserializer.cs @@ -1,18 +1,17 @@ using System.Text.Json.Serialization; -using Merge.Client.Hris; #nullable enable namespace Merge.Client.Hris; -public class IndividualCommonModelScopeDeserializer +public record IndividualCommonModelScopeDeserializer { [JsonPropertyName("model_name")] - public string ModelName { get; init; } + public required string ModelName { get; set; } [JsonPropertyName("model_permissions")] - public Dictionary? ModelPermissions { get; init; } + public Dictionary? ModelPermissions { get; set; } [JsonPropertyName("field_permissions")] - public FieldPermissionDeserializer? FieldPermissions { get; init; } + public FieldPermissionDeserializer? FieldPermissions { get; set; } } diff --git a/src/Merge.Client/Hris/Types/IndividualCommonModelScopeDeserializerRequest.cs b/src/Merge.Client/Hris/Types/IndividualCommonModelScopeDeserializerRequest.cs index 384c65cf..760b6424 100644 --- a/src/Merge.Client/Hris/Types/IndividualCommonModelScopeDeserializerRequest.cs +++ b/src/Merge.Client/Hris/Types/IndividualCommonModelScopeDeserializerRequest.cs @@ -1,18 +1,17 @@ using System.Text.Json.Serialization; -using Merge.Client.Hris; #nullable enable namespace Merge.Client.Hris; -public class IndividualCommonModelScopeDeserializerRequest +public record IndividualCommonModelScopeDeserializerRequest { [JsonPropertyName("model_name")] - public string ModelName { get; init; } + public required string ModelName { get; set; } [JsonPropertyName("model_permissions")] - public Dictionary? ModelPermissions { get; init; } + public Dictionary? ModelPermissions { get; set; } [JsonPropertyName("field_permissions")] - public FieldPermissionDeserializerRequest? FieldPermissions { get; init; } + public FieldPermissionDeserializerRequest? FieldPermissions { get; set; } } diff --git a/src/Merge.Client/Hris/Types/Issue.cs b/src/Merge.Client/Hris/Types/Issue.cs index 9a481fef..d95948c3 100644 --- a/src/Merge.Client/Hris/Types/Issue.cs +++ b/src/Merge.Client/Hris/Types/Issue.cs @@ -1,14 +1,13 @@ using System.Text.Json.Serialization; -using Merge.Client.Hris; #nullable enable namespace Merge.Client.Hris; -public class Issue +public record Issue { [JsonPropertyName("id")] - public string? Id { get; init; } + public string? Id { get; set; } /// /// Status of the issue. Options: ('ONGOING', 'RESOLVED') @@ -17,23 +16,23 @@ public class Issue /// - `RESOLVED` - RESOLVED /// [JsonPropertyName("status")] - public IssueStatusEnum? Status { get; init; } + public IssueStatusEnum? Status { get; set; } [JsonPropertyName("error_description")] - public string ErrorDescription { get; init; } + public required string ErrorDescription { get; set; } [JsonPropertyName("end_user")] - public Dictionary? EndUser { get; init; } + public Dictionary? EndUser { get; set; } [JsonPropertyName("first_incident_time")] - public DateTime? FirstIncidentTime { get; init; } + public DateTime? FirstIncidentTime { get; set; } [JsonPropertyName("last_incident_time")] - public DateTime? LastIncidentTime { get; init; } + public DateTime? LastIncidentTime { get; set; } [JsonPropertyName("is_muted")] - public bool? IsMuted { get; init; } + public bool? IsMuted { get; set; } [JsonPropertyName("error_details")] - public IEnumerable? ErrorDetails { get; init; } + public IEnumerable? ErrorDetails { get; set; } } diff --git a/src/Merge.Client/Hris/Types/IssueStatusEnum.cs b/src/Merge.Client/Hris/Types/IssueStatusEnum.cs index b27c99f9..9f0d9abc 100644 --- a/src/Merge.Client/Hris/Types/IssueStatusEnum.cs +++ b/src/Merge.Client/Hris/Types/IssueStatusEnum.cs @@ -1,7 +1,6 @@ using System.Runtime.Serialization; using System.Text.Json.Serialization; using Merge.Client.Core; -using Merge.Client.Hris; #nullable enable diff --git a/src/Merge.Client/Hris/Types/LinkToken.cs b/src/Merge.Client/Hris/Types/LinkToken.cs index 248da605..9d234159 100644 --- a/src/Merge.Client/Hris/Types/LinkToken.cs +++ b/src/Merge.Client/Hris/Types/LinkToken.cs @@ -4,14 +4,14 @@ namespace Merge.Client.Hris; -public class LinkToken +public record LinkToken { [JsonPropertyName("link_token")] - public string LinkToken_ { get; init; } + public required string LinkToken_ { get; set; } [JsonPropertyName("integration_name")] - public string? IntegrationName { get; init; } + public string? IntegrationName { get; set; } [JsonPropertyName("magic_link_url")] - public string? MagicLinkUrl { get; init; } + public string? MagicLinkUrl { get; set; } } diff --git a/src/Merge.Client/Hris/Types/LinkedAccountStatus.cs b/src/Merge.Client/Hris/Types/LinkedAccountStatus.cs index c26c4242..00f35cbb 100644 --- a/src/Merge.Client/Hris/Types/LinkedAccountStatus.cs +++ b/src/Merge.Client/Hris/Types/LinkedAccountStatus.cs @@ -4,11 +4,11 @@ namespace Merge.Client.Hris; -public class LinkedAccountStatus +public record LinkedAccountStatus { [JsonPropertyName("linked_account_status")] - public string LinkedAccountStatus_ { get; init; } + public required string LinkedAccountStatus_ { get; set; } [JsonPropertyName("can_make_request")] - public bool CanMakeRequest { get; init; } + public required bool CanMakeRequest { get; set; } } diff --git a/src/Merge.Client/Hris/Types/Location.cs b/src/Merge.Client/Hris/Types/Location.cs index 9d1ef1bc..34b173c8 100644 --- a/src/Merge.Client/Hris/Types/Location.cs +++ b/src/Merge.Client/Hris/Types/Location.cs @@ -1,74 +1,73 @@ using System.Text.Json.Serialization; -using Merge.Client.Hris; #nullable enable namespace Merge.Client.Hris; -public class Location +public record Location { [JsonPropertyName("id")] - public string? Id { get; init; } + public string? Id { get; set; } /// /// The third-party API ID of the matching object. /// [JsonPropertyName("remote_id")] - public string? RemoteId { get; init; } + public string? RemoteId { get; set; } /// /// The datetime that this object was created by Merge. /// [JsonPropertyName("created_at")] - public DateTime? CreatedAt { get; init; } + public DateTime? CreatedAt { get; set; } /// /// The datetime that this object was modified by Merge. /// [JsonPropertyName("modified_at")] - public DateTime? ModifiedAt { get; init; } + public DateTime? ModifiedAt { get; set; } /// /// The location's name. /// [JsonPropertyName("name")] - public string? Name { get; init; } + public string? Name { get; set; } /// /// The location's phone number. /// [JsonPropertyName("phone_number")] - public string? PhoneNumber { get; init; } + public string? PhoneNumber { get; set; } /// /// Line 1 of the location's street address. /// [JsonPropertyName("street_1")] - public string? Street1 { get; init; } + public string? Street1 { get; set; } /// /// Line 2 of the location's street address. /// [JsonPropertyName("street_2")] - public string? Street2 { get; init; } + public string? Street2 { get; set; } /// /// The location's city. /// [JsonPropertyName("city")] - public string? City { get; init; } + public string? City { get; set; } /// /// The location's state. Represents a region if outside of the US. /// [JsonPropertyName("state")] - public string? State { get; init; } + public string? State { get; set; } /// /// The location's zip code or postal code. /// [JsonPropertyName("zip_code")] - public string? ZipCode { get; init; } + public string? ZipCode { get; set; } /// /// The location's country. @@ -324,7 +323,7 @@ public class Location /// - `ZW` - Zimbabwe /// [JsonPropertyName("country")] - public CountryEnum? Country { get; init; } + public CountryEnum? Country { get; set; } /// /// The location's type. Can be either WORK or HOME @@ -333,17 +332,17 @@ public class Location /// - `WORK` - WORK /// [JsonPropertyName("location_type")] - public LocationTypeEnum? LocationType { get; init; } + public LocationTypeEnum? LocationType { get; set; } /// /// Indicates whether or not this object has been deleted in the third party platform. /// [JsonPropertyName("remote_was_deleted")] - public bool? RemoteWasDeleted { get; init; } + public bool? RemoteWasDeleted { get; set; } [JsonPropertyName("field_mappings")] - public Dictionary? FieldMappings { get; init; } + public Dictionary? FieldMappings { get; set; } [JsonPropertyName("remote_data")] - public IEnumerable? RemoteData { get; init; } + public IEnumerable? RemoteData { get; set; } } diff --git a/src/Merge.Client/Hris/Types/LocationTypeEnum.cs b/src/Merge.Client/Hris/Types/LocationTypeEnum.cs index 607c3e2f..e785e699 100644 --- a/src/Merge.Client/Hris/Types/LocationTypeEnum.cs +++ b/src/Merge.Client/Hris/Types/LocationTypeEnum.cs @@ -1,7 +1,6 @@ using System.Runtime.Serialization; using System.Text.Json.Serialization; using Merge.Client.Core; -using Merge.Client.Hris; #nullable enable diff --git a/src/Merge.Client/Hris/Types/MaritalStatusEnum.cs b/src/Merge.Client/Hris/Types/MaritalStatusEnum.cs index 74b126cf..4de14eaa 100644 --- a/src/Merge.Client/Hris/Types/MaritalStatusEnum.cs +++ b/src/Merge.Client/Hris/Types/MaritalStatusEnum.cs @@ -1,7 +1,6 @@ using System.Runtime.Serialization; using System.Text.Json.Serialization; using Merge.Client.Core; -using Merge.Client.Hris; #nullable enable diff --git a/src/Merge.Client/Hris/Types/MetaResponse.cs b/src/Merge.Client/Hris/Types/MetaResponse.cs index e83af02f..2ba25647 100644 --- a/src/Merge.Client/Hris/Types/MetaResponse.cs +++ b/src/Merge.Client/Hris/Types/MetaResponse.cs @@ -1,24 +1,24 @@ using System.Text.Json.Serialization; -using Merge.Client.Hris; #nullable enable namespace Merge.Client.Hris; -public class MetaResponse +public record MetaResponse { [JsonPropertyName("request_schema")] - public Dictionary RequestSchema { get; init; } + public Dictionary RequestSchema { get; set; } = + new Dictionary(); [JsonPropertyName("remote_field_classes")] - public Dictionary? RemoteFieldClasses { get; init; } + public Dictionary? RemoteFieldClasses { get; set; } [JsonPropertyName("status")] - public LinkedAccountStatus? Status { get; init; } + public LinkedAccountStatus? Status { get; set; } [JsonPropertyName("has_conditional_params")] - public bool HasConditionalParams { get; init; } + public required bool HasConditionalParams { get; set; } [JsonPropertyName("has_required_linked_account_params")] - public bool HasRequiredLinkedAccountParams { get; init; } + public required bool HasRequiredLinkedAccountParams { get; set; } } diff --git a/src/Merge.Client/Hris/Types/MethodEnum.cs b/src/Merge.Client/Hris/Types/MethodEnum.cs index 2143a24f..8bb50635 100644 --- a/src/Merge.Client/Hris/Types/MethodEnum.cs +++ b/src/Merge.Client/Hris/Types/MethodEnum.cs @@ -1,7 +1,6 @@ using System.Runtime.Serialization; using System.Text.Json.Serialization; using Merge.Client.Core; -using Merge.Client.Hris; #nullable enable diff --git a/src/Merge.Client/Hris/Types/ModelOperation.cs b/src/Merge.Client/Hris/Types/ModelOperation.cs index ea5c0eaa..773f94ad 100644 --- a/src/Merge.Client/Hris/Types/ModelOperation.cs +++ b/src/Merge.Client/Hris/Types/ModelOperation.cs @@ -4,17 +4,17 @@ namespace Merge.Client.Hris; -public class ModelOperation +public record ModelOperation { [JsonPropertyName("model_name")] - public string ModelName { get; init; } + public required string ModelName { get; set; } [JsonPropertyName("available_operations")] - public IEnumerable AvailableOperations { get; init; } + public IEnumerable AvailableOperations { get; set; } = new List(); [JsonPropertyName("required_post_parameters")] - public IEnumerable RequiredPostParameters { get; init; } + public IEnumerable RequiredPostParameters { get; set; } = new List(); [JsonPropertyName("supported_fields")] - public IEnumerable SupportedFields { get; init; } + public IEnumerable SupportedFields { get; set; } = new List(); } diff --git a/src/Merge.Client/Hris/Types/ModelPermissionDeserializer.cs b/src/Merge.Client/Hris/Types/ModelPermissionDeserializer.cs index 7c57b65a..c0ba5c9c 100644 --- a/src/Merge.Client/Hris/Types/ModelPermissionDeserializer.cs +++ b/src/Merge.Client/Hris/Types/ModelPermissionDeserializer.cs @@ -4,8 +4,8 @@ namespace Merge.Client.Hris; -public class ModelPermissionDeserializer +public record ModelPermissionDeserializer { [JsonPropertyName("is_enabled")] - public bool? IsEnabled { get; init; } + public bool? IsEnabled { get; set; } } diff --git a/src/Merge.Client/Hris/Types/ModelPermissionDeserializerRequest.cs b/src/Merge.Client/Hris/Types/ModelPermissionDeserializerRequest.cs index c874e0eb..26018dd5 100644 --- a/src/Merge.Client/Hris/Types/ModelPermissionDeserializerRequest.cs +++ b/src/Merge.Client/Hris/Types/ModelPermissionDeserializerRequest.cs @@ -4,8 +4,8 @@ namespace Merge.Client.Hris; -public class ModelPermissionDeserializerRequest +public record ModelPermissionDeserializerRequest { [JsonPropertyName("is_enabled")] - public bool? IsEnabled { get; init; } + public bool? IsEnabled { get; set; } } diff --git a/src/Merge.Client/Hris/Types/MultipartFormFieldRequest.cs b/src/Merge.Client/Hris/Types/MultipartFormFieldRequest.cs index ae59a133..10f51b75 100644 --- a/src/Merge.Client/Hris/Types/MultipartFormFieldRequest.cs +++ b/src/Merge.Client/Hris/Types/MultipartFormFieldRequest.cs @@ -1,23 +1,22 @@ using System.Text.Json.Serialization; -using Merge.Client.Hris; #nullable enable namespace Merge.Client.Hris; -public class MultipartFormFieldRequest +public record MultipartFormFieldRequest { /// /// The name of the form field /// [JsonPropertyName("name")] - public string Name { get; init; } + public required string Name { get; set; } /// /// The data for the form field. /// [JsonPropertyName("data")] - public string Data { get; init; } + public required string Data { get; set; } /// /// The encoding of the value of `data`. Defaults to `RAW` if not defined. @@ -27,17 +26,17 @@ public class MultipartFormFieldRequest /// - `GZIP_BASE64` - GZIP_BASE64 /// [JsonPropertyName("encoding")] - public EncodingEnum? Encoding { get; init; } + public EncodingEnum? Encoding { get; set; } /// /// The file name of the form field, if the field is for a file. /// [JsonPropertyName("file_name")] - public string? FileName { get; init; } + public string? FileName { get; set; } /// /// The MIME type of the file, if the field is for a file. /// [JsonPropertyName("content_type")] - public string? ContentType { get; init; } + public string? ContentType { get; set; } } diff --git a/src/Merge.Client/Hris/Types/PaginatedAccountDetailsAndActionsList.cs b/src/Merge.Client/Hris/Types/PaginatedAccountDetailsAndActionsList.cs index e3803566..8d3442c5 100644 --- a/src/Merge.Client/Hris/Types/PaginatedAccountDetailsAndActionsList.cs +++ b/src/Merge.Client/Hris/Types/PaginatedAccountDetailsAndActionsList.cs @@ -1,18 +1,17 @@ using System.Text.Json.Serialization; -using Merge.Client.Hris; #nullable enable namespace Merge.Client.Hris; -public class PaginatedAccountDetailsAndActionsList +public record PaginatedAccountDetailsAndActionsList { [JsonPropertyName("next")] - public string? Next { get; init; } + public string? Next { get; set; } [JsonPropertyName("previous")] - public string? Previous { get; init; } + public string? Previous { get; set; } [JsonPropertyName("results")] - public IEnumerable? Results { get; init; } + public IEnumerable? Results { get; set; } } diff --git a/src/Merge.Client/Hris/Types/PaginatedAuditLogEventList.cs b/src/Merge.Client/Hris/Types/PaginatedAuditLogEventList.cs index 07422e59..f99b36b9 100644 --- a/src/Merge.Client/Hris/Types/PaginatedAuditLogEventList.cs +++ b/src/Merge.Client/Hris/Types/PaginatedAuditLogEventList.cs @@ -1,18 +1,17 @@ using System.Text.Json.Serialization; -using Merge.Client.Hris; #nullable enable namespace Merge.Client.Hris; -public class PaginatedAuditLogEventList +public record PaginatedAuditLogEventList { [JsonPropertyName("next")] - public string? Next { get; init; } + public string? Next { get; set; } [JsonPropertyName("previous")] - public string? Previous { get; init; } + public string? Previous { get; set; } [JsonPropertyName("results")] - public IEnumerable? Results { get; init; } + public IEnumerable? Results { get; set; } } diff --git a/src/Merge.Client/Hris/Types/PaginatedBankInfoList.cs b/src/Merge.Client/Hris/Types/PaginatedBankInfoList.cs index dbbb8e44..73d0877a 100644 --- a/src/Merge.Client/Hris/Types/PaginatedBankInfoList.cs +++ b/src/Merge.Client/Hris/Types/PaginatedBankInfoList.cs @@ -1,18 +1,17 @@ using System.Text.Json.Serialization; -using Merge.Client.Hris; #nullable enable namespace Merge.Client.Hris; -public class PaginatedBankInfoList +public record PaginatedBankInfoList { [JsonPropertyName("next")] - public string? Next { get; init; } + public string? Next { get; set; } [JsonPropertyName("previous")] - public string? Previous { get; init; } + public string? Previous { get; set; } [JsonPropertyName("results")] - public IEnumerable? Results { get; init; } + public IEnumerable? Results { get; set; } } diff --git a/src/Merge.Client/Hris/Types/PaginatedBenefitList.cs b/src/Merge.Client/Hris/Types/PaginatedBenefitList.cs index 00af22fa..54fc96f9 100644 --- a/src/Merge.Client/Hris/Types/PaginatedBenefitList.cs +++ b/src/Merge.Client/Hris/Types/PaginatedBenefitList.cs @@ -1,18 +1,17 @@ using System.Text.Json.Serialization; -using Merge.Client.Hris; #nullable enable namespace Merge.Client.Hris; -public class PaginatedBenefitList +public record PaginatedBenefitList { [JsonPropertyName("next")] - public string? Next { get; init; } + public string? Next { get; set; } [JsonPropertyName("previous")] - public string? Previous { get; init; } + public string? Previous { get; set; } [JsonPropertyName("results")] - public IEnumerable? Results { get; init; } + public IEnumerable? Results { get; set; } } diff --git a/src/Merge.Client/Hris/Types/PaginatedCompanyList.cs b/src/Merge.Client/Hris/Types/PaginatedCompanyList.cs index be772d18..3775bcd3 100644 --- a/src/Merge.Client/Hris/Types/PaginatedCompanyList.cs +++ b/src/Merge.Client/Hris/Types/PaginatedCompanyList.cs @@ -1,18 +1,17 @@ using System.Text.Json.Serialization; -using Merge.Client.Hris; #nullable enable namespace Merge.Client.Hris; -public class PaginatedCompanyList +public record PaginatedCompanyList { [JsonPropertyName("next")] - public string? Next { get; init; } + public string? Next { get; set; } [JsonPropertyName("previous")] - public string? Previous { get; init; } + public string? Previous { get; set; } [JsonPropertyName("results")] - public IEnumerable? Results { get; init; } + public IEnumerable? Results { get; set; } } diff --git a/src/Merge.Client/Hris/Types/PaginatedDependentList.cs b/src/Merge.Client/Hris/Types/PaginatedDependentList.cs index 5a563cc9..413eb1a0 100644 --- a/src/Merge.Client/Hris/Types/PaginatedDependentList.cs +++ b/src/Merge.Client/Hris/Types/PaginatedDependentList.cs @@ -1,18 +1,17 @@ using System.Text.Json.Serialization; -using Merge.Client.Hris; #nullable enable namespace Merge.Client.Hris; -public class PaginatedDependentList +public record PaginatedDependentList { [JsonPropertyName("next")] - public string? Next { get; init; } + public string? Next { get; set; } [JsonPropertyName("previous")] - public string? Previous { get; init; } + public string? Previous { get; set; } [JsonPropertyName("results")] - public IEnumerable? Results { get; init; } + public IEnumerable? Results { get; set; } } diff --git a/src/Merge.Client/Hris/Types/PaginatedEmployeeList.cs b/src/Merge.Client/Hris/Types/PaginatedEmployeeList.cs index eaa3ae6e..32e3d752 100644 --- a/src/Merge.Client/Hris/Types/PaginatedEmployeeList.cs +++ b/src/Merge.Client/Hris/Types/PaginatedEmployeeList.cs @@ -1,18 +1,17 @@ using System.Text.Json.Serialization; -using Merge.Client.Hris; #nullable enable namespace Merge.Client.Hris; -public class PaginatedEmployeeList +public record PaginatedEmployeeList { [JsonPropertyName("next")] - public string? Next { get; init; } + public string? Next { get; set; } [JsonPropertyName("previous")] - public string? Previous { get; init; } + public string? Previous { get; set; } [JsonPropertyName("results")] - public IEnumerable? Results { get; init; } + public IEnumerable? Results { get; set; } } diff --git a/src/Merge.Client/Hris/Types/PaginatedEmployeePayrollRunList.cs b/src/Merge.Client/Hris/Types/PaginatedEmployeePayrollRunList.cs index 41aa137c..eb9d4f82 100644 --- a/src/Merge.Client/Hris/Types/PaginatedEmployeePayrollRunList.cs +++ b/src/Merge.Client/Hris/Types/PaginatedEmployeePayrollRunList.cs @@ -1,18 +1,17 @@ using System.Text.Json.Serialization; -using Merge.Client.Hris; #nullable enable namespace Merge.Client.Hris; -public class PaginatedEmployeePayrollRunList +public record PaginatedEmployeePayrollRunList { [JsonPropertyName("next")] - public string? Next { get; init; } + public string? Next { get; set; } [JsonPropertyName("previous")] - public string? Previous { get; init; } + public string? Previous { get; set; } [JsonPropertyName("results")] - public IEnumerable? Results { get; init; } + public IEnumerable? Results { get; set; } } diff --git a/src/Merge.Client/Hris/Types/PaginatedEmployerBenefitList.cs b/src/Merge.Client/Hris/Types/PaginatedEmployerBenefitList.cs index d0786896..417f564b 100644 --- a/src/Merge.Client/Hris/Types/PaginatedEmployerBenefitList.cs +++ b/src/Merge.Client/Hris/Types/PaginatedEmployerBenefitList.cs @@ -1,18 +1,17 @@ using System.Text.Json.Serialization; -using Merge.Client.Hris; #nullable enable namespace Merge.Client.Hris; -public class PaginatedEmployerBenefitList +public record PaginatedEmployerBenefitList { [JsonPropertyName("next")] - public string? Next { get; init; } + public string? Next { get; set; } [JsonPropertyName("previous")] - public string? Previous { get; init; } + public string? Previous { get; set; } [JsonPropertyName("results")] - public IEnumerable? Results { get; init; } + public IEnumerable? Results { get; set; } } diff --git a/src/Merge.Client/Hris/Types/PaginatedEmploymentList.cs b/src/Merge.Client/Hris/Types/PaginatedEmploymentList.cs index a72ac5d3..9e2573f2 100644 --- a/src/Merge.Client/Hris/Types/PaginatedEmploymentList.cs +++ b/src/Merge.Client/Hris/Types/PaginatedEmploymentList.cs @@ -1,18 +1,17 @@ using System.Text.Json.Serialization; -using Merge.Client.Hris; #nullable enable namespace Merge.Client.Hris; -public class PaginatedEmploymentList +public record PaginatedEmploymentList { [JsonPropertyName("next")] - public string? Next { get; init; } + public string? Next { get; set; } [JsonPropertyName("previous")] - public string? Previous { get; init; } + public string? Previous { get; set; } [JsonPropertyName("results")] - public IEnumerable? Results { get; init; } + public IEnumerable? Results { get; set; } } diff --git a/src/Merge.Client/Hris/Types/PaginatedGroupList.cs b/src/Merge.Client/Hris/Types/PaginatedGroupList.cs index 758dc80f..52219e9a 100644 --- a/src/Merge.Client/Hris/Types/PaginatedGroupList.cs +++ b/src/Merge.Client/Hris/Types/PaginatedGroupList.cs @@ -1,18 +1,17 @@ using System.Text.Json.Serialization; -using Merge.Client.Hris; #nullable enable namespace Merge.Client.Hris; -public class PaginatedGroupList +public record PaginatedGroupList { [JsonPropertyName("next")] - public string? Next { get; init; } + public string? Next { get; set; } [JsonPropertyName("previous")] - public string? Previous { get; init; } + public string? Previous { get; set; } [JsonPropertyName("results")] - public IEnumerable? Results { get; init; } + public IEnumerable? Results { get; set; } } diff --git a/src/Merge.Client/Hris/Types/PaginatedIssueList.cs b/src/Merge.Client/Hris/Types/PaginatedIssueList.cs index 13ab659d..13462523 100644 --- a/src/Merge.Client/Hris/Types/PaginatedIssueList.cs +++ b/src/Merge.Client/Hris/Types/PaginatedIssueList.cs @@ -1,18 +1,17 @@ using System.Text.Json.Serialization; -using Merge.Client.Hris; #nullable enable namespace Merge.Client.Hris; -public class PaginatedIssueList +public record PaginatedIssueList { [JsonPropertyName("next")] - public string? Next { get; init; } + public string? Next { get; set; } [JsonPropertyName("previous")] - public string? Previous { get; init; } + public string? Previous { get; set; } [JsonPropertyName("results")] - public IEnumerable? Results { get; init; } + public IEnumerable? Results { get; set; } } diff --git a/src/Merge.Client/Hris/Types/PaginatedLocationList.cs b/src/Merge.Client/Hris/Types/PaginatedLocationList.cs index 2d523a2f..335df34f 100644 --- a/src/Merge.Client/Hris/Types/PaginatedLocationList.cs +++ b/src/Merge.Client/Hris/Types/PaginatedLocationList.cs @@ -1,18 +1,17 @@ using System.Text.Json.Serialization; -using Merge.Client.Hris; #nullable enable namespace Merge.Client.Hris; -public class PaginatedLocationList +public record PaginatedLocationList { [JsonPropertyName("next")] - public string? Next { get; init; } + public string? Next { get; set; } [JsonPropertyName("previous")] - public string? Previous { get; init; } + public string? Previous { get; set; } [JsonPropertyName("results")] - public IEnumerable? Results { get; init; } + public IEnumerable? Results { get; set; } } diff --git a/src/Merge.Client/Hris/Types/PaginatedPayGroupList.cs b/src/Merge.Client/Hris/Types/PaginatedPayGroupList.cs index 6b766a61..372b883b 100644 --- a/src/Merge.Client/Hris/Types/PaginatedPayGroupList.cs +++ b/src/Merge.Client/Hris/Types/PaginatedPayGroupList.cs @@ -1,18 +1,17 @@ using System.Text.Json.Serialization; -using Merge.Client.Hris; #nullable enable namespace Merge.Client.Hris; -public class PaginatedPayGroupList +public record PaginatedPayGroupList { [JsonPropertyName("next")] - public string? Next { get; init; } + public string? Next { get; set; } [JsonPropertyName("previous")] - public string? Previous { get; init; } + public string? Previous { get; set; } [JsonPropertyName("results")] - public IEnumerable? Results { get; init; } + public IEnumerable? Results { get; set; } } diff --git a/src/Merge.Client/Hris/Types/PaginatedPayrollRunList.cs b/src/Merge.Client/Hris/Types/PaginatedPayrollRunList.cs index c10a8c3b..07e8023d 100644 --- a/src/Merge.Client/Hris/Types/PaginatedPayrollRunList.cs +++ b/src/Merge.Client/Hris/Types/PaginatedPayrollRunList.cs @@ -1,18 +1,17 @@ using System.Text.Json.Serialization; -using Merge.Client.Hris; #nullable enable namespace Merge.Client.Hris; -public class PaginatedPayrollRunList +public record PaginatedPayrollRunList { [JsonPropertyName("next")] - public string? Next { get; init; } + public string? Next { get; set; } [JsonPropertyName("previous")] - public string? Previous { get; init; } + public string? Previous { get; set; } [JsonPropertyName("results")] - public IEnumerable? Results { get; init; } + public IEnumerable? Results { get; set; } } diff --git a/src/Merge.Client/Hris/Types/PaginatedSyncStatusList.cs b/src/Merge.Client/Hris/Types/PaginatedSyncStatusList.cs index 4a4fb250..7c29b4fa 100644 --- a/src/Merge.Client/Hris/Types/PaginatedSyncStatusList.cs +++ b/src/Merge.Client/Hris/Types/PaginatedSyncStatusList.cs @@ -1,18 +1,17 @@ using System.Text.Json.Serialization; -using Merge.Client.Hris; #nullable enable namespace Merge.Client.Hris; -public class PaginatedSyncStatusList +public record PaginatedSyncStatusList { [JsonPropertyName("next")] - public string? Next { get; init; } + public string? Next { get; set; } [JsonPropertyName("previous")] - public string? Previous { get; init; } + public string? Previous { get; set; } [JsonPropertyName("results")] - public IEnumerable? Results { get; init; } + public IEnumerable? Results { get; set; } } diff --git a/src/Merge.Client/Hris/Types/PaginatedTeamList.cs b/src/Merge.Client/Hris/Types/PaginatedTeamList.cs index 03722b71..b54c9f59 100644 --- a/src/Merge.Client/Hris/Types/PaginatedTeamList.cs +++ b/src/Merge.Client/Hris/Types/PaginatedTeamList.cs @@ -1,18 +1,17 @@ using System.Text.Json.Serialization; -using Merge.Client.Hris; #nullable enable namespace Merge.Client.Hris; -public class PaginatedTeamList +public record PaginatedTeamList { [JsonPropertyName("next")] - public string? Next { get; init; } + public string? Next { get; set; } [JsonPropertyName("previous")] - public string? Previous { get; init; } + public string? Previous { get; set; } [JsonPropertyName("results")] - public IEnumerable? Results { get; init; } + public IEnumerable? Results { get; set; } } diff --git a/src/Merge.Client/Hris/Types/PaginatedTimeOffBalanceList.cs b/src/Merge.Client/Hris/Types/PaginatedTimeOffBalanceList.cs index 69f62fb6..2f45ca33 100644 --- a/src/Merge.Client/Hris/Types/PaginatedTimeOffBalanceList.cs +++ b/src/Merge.Client/Hris/Types/PaginatedTimeOffBalanceList.cs @@ -1,18 +1,17 @@ using System.Text.Json.Serialization; -using Merge.Client.Hris; #nullable enable namespace Merge.Client.Hris; -public class PaginatedTimeOffBalanceList +public record PaginatedTimeOffBalanceList { [JsonPropertyName("next")] - public string? Next { get; init; } + public string? Next { get; set; } [JsonPropertyName("previous")] - public string? Previous { get; init; } + public string? Previous { get; set; } [JsonPropertyName("results")] - public IEnumerable? Results { get; init; } + public IEnumerable? Results { get; set; } } diff --git a/src/Merge.Client/Hris/Types/PaginatedTimeOffList.cs b/src/Merge.Client/Hris/Types/PaginatedTimeOffList.cs index cfa16209..b76d2c3b 100644 --- a/src/Merge.Client/Hris/Types/PaginatedTimeOffList.cs +++ b/src/Merge.Client/Hris/Types/PaginatedTimeOffList.cs @@ -1,18 +1,17 @@ using System.Text.Json.Serialization; -using Merge.Client.Hris; #nullable enable namespace Merge.Client.Hris; -public class PaginatedTimeOffList +public record PaginatedTimeOffList { [JsonPropertyName("next")] - public string? Next { get; init; } + public string? Next { get; set; } [JsonPropertyName("previous")] - public string? Previous { get; init; } + public string? Previous { get; set; } [JsonPropertyName("results")] - public IEnumerable? Results { get; init; } + public IEnumerable? Results { get; set; } } diff --git a/src/Merge.Client/Hris/Types/PaginatedTimesheetEntryList.cs b/src/Merge.Client/Hris/Types/PaginatedTimesheetEntryList.cs index 4688caba..596a16ad 100644 --- a/src/Merge.Client/Hris/Types/PaginatedTimesheetEntryList.cs +++ b/src/Merge.Client/Hris/Types/PaginatedTimesheetEntryList.cs @@ -1,18 +1,17 @@ using System.Text.Json.Serialization; -using Merge.Client.Hris; #nullable enable namespace Merge.Client.Hris; -public class PaginatedTimesheetEntryList +public record PaginatedTimesheetEntryList { [JsonPropertyName("next")] - public string? Next { get; init; } + public string? Next { get; set; } [JsonPropertyName("previous")] - public string? Previous { get; init; } + public string? Previous { get; set; } [JsonPropertyName("results")] - public IEnumerable? Results { get; init; } + public IEnumerable? Results { get; set; } } diff --git a/src/Merge.Client/Hris/Types/PayCurrencyEnum.cs b/src/Merge.Client/Hris/Types/PayCurrencyEnum.cs index f061bb8a..168fb3bf 100644 --- a/src/Merge.Client/Hris/Types/PayCurrencyEnum.cs +++ b/src/Merge.Client/Hris/Types/PayCurrencyEnum.cs @@ -1,7 +1,6 @@ using System.Runtime.Serialization; using System.Text.Json.Serialization; using Merge.Client.Core; -using Merge.Client.Hris; #nullable enable diff --git a/src/Merge.Client/Hris/Types/PayFrequencyEnum.cs b/src/Merge.Client/Hris/Types/PayFrequencyEnum.cs index 0477cfb9..51a3182d 100644 --- a/src/Merge.Client/Hris/Types/PayFrequencyEnum.cs +++ b/src/Merge.Client/Hris/Types/PayFrequencyEnum.cs @@ -1,7 +1,6 @@ using System.Runtime.Serialization; using System.Text.Json.Serialization; using Merge.Client.Core; -using Merge.Client.Hris; #nullable enable diff --git a/src/Merge.Client/Hris/Types/PayGroup.cs b/src/Merge.Client/Hris/Types/PayGroup.cs index 4b3ddc35..dce4bd99 100644 --- a/src/Merge.Client/Hris/Types/PayGroup.cs +++ b/src/Merge.Client/Hris/Types/PayGroup.cs @@ -1,48 +1,47 @@ using System.Text.Json.Serialization; -using Merge.Client.Hris; #nullable enable namespace Merge.Client.Hris; -public class PayGroup +public record PayGroup { [JsonPropertyName("id")] - public string? Id { get; init; } + public string? Id { get; set; } /// /// The third-party API ID of the matching object. /// [JsonPropertyName("remote_id")] - public string? RemoteId { get; init; } + public string? RemoteId { get; set; } /// /// The datetime that this object was created by Merge. /// [JsonPropertyName("created_at")] - public DateTime? CreatedAt { get; init; } + public DateTime? CreatedAt { get; set; } /// /// The datetime that this object was modified by Merge. /// [JsonPropertyName("modified_at")] - public DateTime? ModifiedAt { get; init; } + public DateTime? ModifiedAt { get; set; } /// /// The pay group name. /// [JsonPropertyName("pay_group_name")] - public string? PayGroupName { get; init; } + public string? PayGroupName { get; set; } /// /// Indicates whether or not this object has been deleted in the third party platform. /// [JsonPropertyName("remote_was_deleted")] - public bool? RemoteWasDeleted { get; init; } + public bool? RemoteWasDeleted { get; set; } [JsonPropertyName("field_mappings")] - public Dictionary? FieldMappings { get; init; } + public Dictionary? FieldMappings { get; set; } [JsonPropertyName("remote_data")] - public IEnumerable? RemoteData { get; init; } + public IEnumerable? RemoteData { get; set; } } diff --git a/src/Merge.Client/Hris/Types/PayPeriodEnum.cs b/src/Merge.Client/Hris/Types/PayPeriodEnum.cs index 5e908e8c..64a73a8f 100644 --- a/src/Merge.Client/Hris/Types/PayPeriodEnum.cs +++ b/src/Merge.Client/Hris/Types/PayPeriodEnum.cs @@ -1,7 +1,6 @@ using System.Runtime.Serialization; using System.Text.Json.Serialization; using Merge.Client.Core; -using Merge.Client.Hris; #nullable enable diff --git a/src/Merge.Client/Hris/Types/PayrollRun.cs b/src/Merge.Client/Hris/Types/PayrollRun.cs index 47ef258d..5199e028 100644 --- a/src/Merge.Client/Hris/Types/PayrollRun.cs +++ b/src/Merge.Client/Hris/Types/PayrollRun.cs @@ -1,32 +1,31 @@ using System.Text.Json.Serialization; -using Merge.Client.Hris; #nullable enable namespace Merge.Client.Hris; -public class PayrollRun +public record PayrollRun { [JsonPropertyName("id")] - public string? Id { get; init; } + public string? Id { get; set; } /// /// The third-party API ID of the matching object. /// [JsonPropertyName("remote_id")] - public string? RemoteId { get; init; } + public string? RemoteId { get; set; } /// /// The datetime that this object was created by Merge. /// [JsonPropertyName("created_at")] - public DateTime? CreatedAt { get; init; } + public DateTime? CreatedAt { get; set; } /// /// The datetime that this object was modified by Merge. /// [JsonPropertyName("modified_at")] - public DateTime? ModifiedAt { get; init; } + public DateTime? ModifiedAt { get; set; } /// /// The state of the payroll run @@ -38,7 +37,7 @@ public class PayrollRun /// - `CLOSED` - CLOSED /// [JsonPropertyName("run_state")] - public RunStateEnum? RunState { get; init; } + public RunStateEnum? RunState { get; set; } /// /// The type of the payroll run @@ -50,35 +49,35 @@ public class PayrollRun /// - `SIGN_ON_BONUS` - SIGN_ON_BONUS /// [JsonPropertyName("run_type")] - public RunTypeEnum? RunType { get; init; } + public RunTypeEnum? RunType { get; set; } /// /// The day and time the payroll run started. /// [JsonPropertyName("start_date")] - public DateTime? StartDate { get; init; } + public DateTime? StartDate { get; set; } /// /// The day and time the payroll run ended. /// [JsonPropertyName("end_date")] - public DateTime? EndDate { get; init; } + public DateTime? EndDate { get; set; } /// /// The day and time the payroll run was checked. /// [JsonPropertyName("check_date")] - public DateTime? CheckDate { get; init; } + public DateTime? CheckDate { get; set; } /// /// Indicates whether or not this object has been deleted in the third party platform. /// [JsonPropertyName("remote_was_deleted")] - public bool? RemoteWasDeleted { get; init; } + public bool? RemoteWasDeleted { get; set; } [JsonPropertyName("field_mappings")] - public Dictionary? FieldMappings { get; init; } + public Dictionary? FieldMappings { get; set; } [JsonPropertyName("remote_data")] - public IEnumerable? RemoteData { get; init; } + public IEnumerable? RemoteData { get; set; } } diff --git a/src/Merge.Client/Hris/Types/PolicyTypeEnum.cs b/src/Merge.Client/Hris/Types/PolicyTypeEnum.cs index 34bb6864..c225ff54 100644 --- a/src/Merge.Client/Hris/Types/PolicyTypeEnum.cs +++ b/src/Merge.Client/Hris/Types/PolicyTypeEnum.cs @@ -1,7 +1,6 @@ using System.Runtime.Serialization; using System.Text.Json.Serialization; using Merge.Client.Core; -using Merge.Client.Hris; #nullable enable diff --git a/src/Merge.Client/Hris/Types/ReasonEnum.cs b/src/Merge.Client/Hris/Types/ReasonEnum.cs index 554c430e..c39af6a2 100644 --- a/src/Merge.Client/Hris/Types/ReasonEnum.cs +++ b/src/Merge.Client/Hris/Types/ReasonEnum.cs @@ -1,7 +1,6 @@ using System.Runtime.Serialization; using System.Text.Json.Serialization; using Merge.Client.Core; -using Merge.Client.Hris; #nullable enable diff --git a/src/Merge.Client/Hris/Types/RelationshipEnum.cs b/src/Merge.Client/Hris/Types/RelationshipEnum.cs index 1a45484c..850df5ef 100644 --- a/src/Merge.Client/Hris/Types/RelationshipEnum.cs +++ b/src/Merge.Client/Hris/Types/RelationshipEnum.cs @@ -1,7 +1,6 @@ using System.Runtime.Serialization; using System.Text.Json.Serialization; using Merge.Client.Core; -using Merge.Client.Hris; #nullable enable diff --git a/src/Merge.Client/Hris/Types/RemoteData.cs b/src/Merge.Client/Hris/Types/RemoteData.cs index fc5dcc31..94ebdc20 100644 --- a/src/Merge.Client/Hris/Types/RemoteData.cs +++ b/src/Merge.Client/Hris/Types/RemoteData.cs @@ -4,11 +4,11 @@ namespace Merge.Client.Hris; -public class RemoteData +public record RemoteData { [JsonPropertyName("path")] - public string Path { get; init; } + public required string Path { get; set; } [JsonPropertyName("data")] - public object? Data { get; init; } + public object? Data { get; set; } } diff --git a/src/Merge.Client/Hris/Types/RemoteEndpointInfo.cs b/src/Merge.Client/Hris/Types/RemoteEndpointInfo.cs index a1438f3e..21738c9f 100644 --- a/src/Merge.Client/Hris/Types/RemoteEndpointInfo.cs +++ b/src/Merge.Client/Hris/Types/RemoteEndpointInfo.cs @@ -4,14 +4,14 @@ namespace Merge.Client.Hris; -public class RemoteEndpointInfo +public record RemoteEndpointInfo { [JsonPropertyName("method")] - public string Method { get; init; } + public required string Method { get; set; } [JsonPropertyName("url_path")] - public string UrlPath { get; init; } + public required string UrlPath { get; set; } [JsonPropertyName("field_traversal_path")] - public IEnumerable FieldTraversalPath { get; init; } + public IEnumerable FieldTraversalPath { get; set; } = new List(); } diff --git a/src/Merge.Client/Hris/Types/RemoteFieldApi.cs b/src/Merge.Client/Hris/Types/RemoteFieldApi.cs index 7079ede0..a9903736 100644 --- a/src/Merge.Client/Hris/Types/RemoteFieldApi.cs +++ b/src/Merge.Client/Hris/Types/RemoteFieldApi.cs @@ -1,30 +1,29 @@ using System.Text.Json.Serialization; using Merge.Client.Core; -using Merge.Client.Hris; using OneOf; #nullable enable namespace Merge.Client.Hris; -public class RemoteFieldApi +public record RemoteFieldApi { [JsonPropertyName("schema")] - public Dictionary Schema { get; init; } + public Dictionary Schema { get; set; } = new Dictionary(); [JsonPropertyName("remote_key_name")] - public string RemoteKeyName { get; init; } + public required string RemoteKeyName { get; set; } [JsonPropertyName("remote_endpoint_info")] - public RemoteEndpointInfo RemoteEndpointInfo { get; init; } + public required RemoteEndpointInfo RemoteEndpointInfo { get; set; } [JsonPropertyName("example_values")] - public IEnumerable? ExampleValues { get; init; } + public IEnumerable? ExampleValues { get; set; } [JsonPropertyName("advanced_metadata")] - public AdvancedMetadata? AdvancedMetadata { get; init; } + public AdvancedMetadata? AdvancedMetadata { get; set; } [JsonPropertyName("coverage")] [JsonConverter(typeof(OneOfSerializer>))] - public OneOf? Coverage { get; init; } + public OneOf? Coverage { get; set; } } diff --git a/src/Merge.Client/Hris/Types/RemoteFieldApiResponse.cs b/src/Merge.Client/Hris/Types/RemoteFieldApiResponse.cs index ff2feb28..e3661d1d 100644 --- a/src/Merge.Client/Hris/Types/RemoteFieldApiResponse.cs +++ b/src/Merge.Client/Hris/Types/RemoteFieldApiResponse.cs @@ -1,57 +1,56 @@ using System.Text.Json.Serialization; -using Merge.Client.Hris; #nullable enable namespace Merge.Client.Hris; -public class RemoteFieldApiResponse +public record RemoteFieldApiResponse { [JsonPropertyName("Benefit")] - public IEnumerable? Benefit { get; init; } + public IEnumerable? Benefit { get; set; } [JsonPropertyName("EmployerBenefit")] - public IEnumerable? EmployerBenefit { get; init; } + public IEnumerable? EmployerBenefit { get; set; } [JsonPropertyName("Company")] - public IEnumerable? Company { get; init; } + public IEnumerable? Company { get; set; } [JsonPropertyName("EmployeePayrollRun")] - public IEnumerable? EmployeePayrollRun { get; init; } + public IEnumerable? EmployeePayrollRun { get; set; } [JsonPropertyName("Employee")] - public IEnumerable? Employee { get; init; } + public IEnumerable? Employee { get; set; } [JsonPropertyName("Employment")] - public IEnumerable? Employment { get; init; } + public IEnumerable? Employment { get; set; } [JsonPropertyName("Location")] - public IEnumerable? Location { get; init; } + public IEnumerable? Location { get; set; } [JsonPropertyName("PayrollRun")] - public IEnumerable? PayrollRun { get; init; } + public IEnumerable? PayrollRun { get; set; } [JsonPropertyName("Team")] - public IEnumerable? Team { get; init; } + public IEnumerable? Team { get; set; } [JsonPropertyName("TimeOff")] - public IEnumerable? TimeOff { get; init; } + public IEnumerable? TimeOff { get; set; } [JsonPropertyName("TimeOffBalance")] - public IEnumerable? TimeOffBalance { get; init; } + public IEnumerable? TimeOffBalance { get; set; } [JsonPropertyName("BankInfo")] - public IEnumerable? BankInfo { get; init; } + public IEnumerable? BankInfo { get; set; } [JsonPropertyName("PayGroup")] - public IEnumerable? PayGroup { get; init; } + public IEnumerable? PayGroup { get; set; } [JsonPropertyName("Group")] - public IEnumerable? Group { get; init; } + public IEnumerable? Group { get; set; } [JsonPropertyName("Dependent")] - public IEnumerable? Dependent { get; init; } + public IEnumerable? Dependent { get; set; } [JsonPropertyName("TimesheetEntry")] - public IEnumerable? TimesheetEntry { get; init; } + public IEnumerable? TimesheetEntry { get; set; } } diff --git a/src/Merge.Client/Hris/Types/RemoteKey.cs b/src/Merge.Client/Hris/Types/RemoteKey.cs index cfa92123..8bf25ebd 100644 --- a/src/Merge.Client/Hris/Types/RemoteKey.cs +++ b/src/Merge.Client/Hris/Types/RemoteKey.cs @@ -4,11 +4,11 @@ namespace Merge.Client.Hris; -public class RemoteKey +public record RemoteKey { [JsonPropertyName("name")] - public string Name { get; init; } + public required string Name { get; set; } [JsonPropertyName("key")] - public string Key { get; init; } + public required string Key { get; set; } } diff --git a/src/Merge.Client/Hris/Types/RemoteResponse.cs b/src/Merge.Client/Hris/Types/RemoteResponse.cs index 6dbc3e81..c1777a2c 100644 --- a/src/Merge.Client/Hris/Types/RemoteResponse.cs +++ b/src/Merge.Client/Hris/Types/RemoteResponse.cs @@ -1,30 +1,29 @@ using System.Text.Json.Serialization; -using Merge.Client.Hris; #nullable enable namespace Merge.Client.Hris; -public class RemoteResponse +public record RemoteResponse { [JsonPropertyName("method")] - public string Method { get; init; } + public required string Method { get; set; } [JsonPropertyName("path")] - public string Path { get; init; } + public required string Path { get; set; } [JsonPropertyName("status")] - public int Status { get; init; } + public required int Status { get; set; } [JsonPropertyName("response")] - public object Response { get; init; } + public required object Response { get; set; } [JsonPropertyName("response_headers")] - public Dictionary? ResponseHeaders { get; init; } + public Dictionary? ResponseHeaders { get; set; } [JsonPropertyName("response_type")] - public ResponseTypeEnum? ResponseType { get; init; } + public ResponseTypeEnum? ResponseType { get; set; } [JsonPropertyName("headers")] - public Dictionary? Headers { get; init; } + public Dictionary? Headers { get; set; } } diff --git a/src/Merge.Client/Hris/Types/RequestFormatEnum.cs b/src/Merge.Client/Hris/Types/RequestFormatEnum.cs index 6522cc32..88f9bba9 100644 --- a/src/Merge.Client/Hris/Types/RequestFormatEnum.cs +++ b/src/Merge.Client/Hris/Types/RequestFormatEnum.cs @@ -1,7 +1,6 @@ using System.Runtime.Serialization; using System.Text.Json.Serialization; using Merge.Client.Core; -using Merge.Client.Hris; #nullable enable diff --git a/src/Merge.Client/Hris/Types/RequestTypeEnum.cs b/src/Merge.Client/Hris/Types/RequestTypeEnum.cs index 381c282a..bac23b36 100644 --- a/src/Merge.Client/Hris/Types/RequestTypeEnum.cs +++ b/src/Merge.Client/Hris/Types/RequestTypeEnum.cs @@ -1,7 +1,6 @@ using System.Runtime.Serialization; using System.Text.Json.Serialization; using Merge.Client.Core; -using Merge.Client.Hris; #nullable enable diff --git a/src/Merge.Client/Hris/Types/ResponseTypeEnum.cs b/src/Merge.Client/Hris/Types/ResponseTypeEnum.cs index c1ba7308..cc51856c 100644 --- a/src/Merge.Client/Hris/Types/ResponseTypeEnum.cs +++ b/src/Merge.Client/Hris/Types/ResponseTypeEnum.cs @@ -1,7 +1,6 @@ using System.Runtime.Serialization; using System.Text.Json.Serialization; using Merge.Client.Core; -using Merge.Client.Hris; #nullable enable diff --git a/src/Merge.Client/Hris/Types/RoleEnum.cs b/src/Merge.Client/Hris/Types/RoleEnum.cs index 0d2904c8..3fe43bfa 100644 --- a/src/Merge.Client/Hris/Types/RoleEnum.cs +++ b/src/Merge.Client/Hris/Types/RoleEnum.cs @@ -1,7 +1,6 @@ using System.Runtime.Serialization; using System.Text.Json.Serialization; using Merge.Client.Core; -using Merge.Client.Hris; #nullable enable diff --git a/src/Merge.Client/Hris/Types/RunStateEnum.cs b/src/Merge.Client/Hris/Types/RunStateEnum.cs index c92601cb..55a6246d 100644 --- a/src/Merge.Client/Hris/Types/RunStateEnum.cs +++ b/src/Merge.Client/Hris/Types/RunStateEnum.cs @@ -1,7 +1,6 @@ using System.Runtime.Serialization; using System.Text.Json.Serialization; using Merge.Client.Core; -using Merge.Client.Hris; #nullable enable diff --git a/src/Merge.Client/Hris/Types/RunTypeEnum.cs b/src/Merge.Client/Hris/Types/RunTypeEnum.cs index 9a7bb606..ad0ea5a4 100644 --- a/src/Merge.Client/Hris/Types/RunTypeEnum.cs +++ b/src/Merge.Client/Hris/Types/RunTypeEnum.cs @@ -1,7 +1,6 @@ using System.Runtime.Serialization; using System.Text.Json.Serialization; using Merge.Client.Core; -using Merge.Client.Hris; #nullable enable diff --git a/src/Merge.Client/Hris/Types/SelectiveSyncConfigurationsUsageEnum.cs b/src/Merge.Client/Hris/Types/SelectiveSyncConfigurationsUsageEnum.cs index 058501e9..40b6f08b 100644 --- a/src/Merge.Client/Hris/Types/SelectiveSyncConfigurationsUsageEnum.cs +++ b/src/Merge.Client/Hris/Types/SelectiveSyncConfigurationsUsageEnum.cs @@ -1,7 +1,6 @@ using System.Runtime.Serialization; using System.Text.Json.Serialization; using Merge.Client.Core; -using Merge.Client.Hris; #nullable enable diff --git a/src/Merge.Client/Hris/Types/SyncStatus.cs b/src/Merge.Client/Hris/Types/SyncStatus.cs index 86d08a21..9d69d9a3 100644 --- a/src/Merge.Client/Hris/Types/SyncStatus.cs +++ b/src/Merge.Client/Hris/Types/SyncStatus.cs @@ -1,30 +1,29 @@ using System.Text.Json.Serialization; -using Merge.Client.Hris; #nullable enable namespace Merge.Client.Hris; -public class SyncStatus +public record SyncStatus { [JsonPropertyName("model_name")] - public string ModelName { get; init; } + public required string ModelName { get; set; } [JsonPropertyName("model_id")] - public string ModelId { get; init; } + public required string ModelId { get; set; } [JsonPropertyName("last_sync_start")] - public DateTime? LastSyncStart { get; init; } + public DateTime? LastSyncStart { get; set; } [JsonPropertyName("next_sync_start")] - public DateTime? NextSyncStart { get; init; } + public DateTime? NextSyncStart { get; set; } [JsonPropertyName("status")] - public SyncStatusStatusEnum Status { get; init; } + public required SyncStatusStatusEnum Status { get; set; } [JsonPropertyName("is_initial_sync")] - public bool IsInitialSync { get; init; } + public required bool IsInitialSync { get; set; } [JsonPropertyName("selective_sync_configurations_usage")] - public SelectiveSyncConfigurationsUsageEnum? SelectiveSyncConfigurationsUsage { get; init; } + public SelectiveSyncConfigurationsUsageEnum? SelectiveSyncConfigurationsUsage { get; set; } } diff --git a/src/Merge.Client/Hris/Types/SyncStatusStatusEnum.cs b/src/Merge.Client/Hris/Types/SyncStatusStatusEnum.cs index e8c54ae0..9cf1b6f9 100644 --- a/src/Merge.Client/Hris/Types/SyncStatusStatusEnum.cs +++ b/src/Merge.Client/Hris/Types/SyncStatusStatusEnum.cs @@ -1,7 +1,6 @@ using System.Runtime.Serialization; using System.Text.Json.Serialization; using Merge.Client.Core; -using Merge.Client.Hris; #nullable enable diff --git a/src/Merge.Client/Hris/Types/Tax.cs b/src/Merge.Client/Hris/Types/Tax.cs index 1512271b..87fe8589 100644 --- a/src/Merge.Client/Hris/Types/Tax.cs +++ b/src/Merge.Client/Hris/Types/Tax.cs @@ -1,63 +1,62 @@ using System.Text.Json.Serialization; -using Merge.Client.Hris; #nullable enable namespace Merge.Client.Hris; -public class Tax +public record Tax { [JsonPropertyName("id")] - public string? Id { get; init; } + public string? Id { get; set; } /// /// The third-party API ID of the matching object. /// [JsonPropertyName("remote_id")] - public string? RemoteId { get; init; } + public string? RemoteId { get; set; } /// /// The datetime that this object was created by Merge. /// [JsonPropertyName("created_at")] - public DateTime? CreatedAt { get; init; } + public DateTime? CreatedAt { get; set; } /// /// The datetime that this object was modified by Merge. /// [JsonPropertyName("modified_at")] - public DateTime? ModifiedAt { get; init; } + public DateTime? ModifiedAt { get; set; } [JsonPropertyName("employee_payroll_run")] - public string? EmployeePayrollRun { get; init; } + public string? EmployeePayrollRun { get; set; } /// /// The tax's name. /// [JsonPropertyName("name")] - public string? Name { get; init; } + public string? Name { get; set; } /// /// The tax amount. /// [JsonPropertyName("amount")] - public double? Amount { get; init; } + public double? Amount { get; set; } /// /// Whether or not the employer is responsible for paying the tax. /// [JsonPropertyName("employer_tax")] - public bool? EmployerTax { get; init; } + public bool? EmployerTax { get; set; } /// /// Indicates whether or not this object has been deleted in the third party platform. /// [JsonPropertyName("remote_was_deleted")] - public bool? RemoteWasDeleted { get; init; } + public bool? RemoteWasDeleted { get; set; } [JsonPropertyName("field_mappings")] - public Dictionary? FieldMappings { get; init; } + public Dictionary? FieldMappings { get; set; } [JsonPropertyName("remote_data")] - public IEnumerable? RemoteData { get; init; } + public IEnumerable? RemoteData { get; set; } } diff --git a/src/Merge.Client/Hris/Types/Team.cs b/src/Merge.Client/Hris/Types/Team.cs index 13d944e2..e29710e1 100644 --- a/src/Merge.Client/Hris/Types/Team.cs +++ b/src/Merge.Client/Hris/Types/Team.cs @@ -1,57 +1,56 @@ using System.Text.Json.Serialization; using Merge.Client.Core; -using Merge.Client.Hris; using OneOf; #nullable enable namespace Merge.Client.Hris; -public class Team +public record Team { [JsonPropertyName("id")] - public string? Id { get; init; } + public string? Id { get; set; } /// /// The third-party API ID of the matching object. /// [JsonPropertyName("remote_id")] - public string? RemoteId { get; init; } + public string? RemoteId { get; set; } /// /// The datetime that this object was created by Merge. /// [JsonPropertyName("created_at")] - public DateTime? CreatedAt { get; init; } + public DateTime? CreatedAt { get; set; } /// /// The datetime that this object was modified by Merge. /// [JsonPropertyName("modified_at")] - public DateTime? ModifiedAt { get; init; } + public DateTime? ModifiedAt { get; set; } /// /// The team's name. /// [JsonPropertyName("name")] - public string? Name { get; init; } + public string? Name { get; set; } /// /// The team's parent team. /// [JsonPropertyName("parent_team")] [JsonConverter(typeof(OneOfSerializer>))] - public OneOf? ParentTeam { get; init; } + public OneOf? ParentTeam { get; set; } /// /// Indicates whether or not this object has been deleted in the third party platform. /// [JsonPropertyName("remote_was_deleted")] - public bool? RemoteWasDeleted { get; init; } + public bool? RemoteWasDeleted { get; set; } [JsonPropertyName("field_mappings")] - public Dictionary? FieldMappings { get; init; } + public Dictionary? FieldMappings { get; set; } [JsonPropertyName("remote_data")] - public IEnumerable? RemoteData { get; init; } + public IEnumerable? RemoteData { get; set; } } diff --git a/src/Merge.Client/Hris/Types/TimeOff.cs b/src/Merge.Client/Hris/Types/TimeOff.cs index ce31c9cd..a136dff4 100644 --- a/src/Merge.Client/Hris/Types/TimeOff.cs +++ b/src/Merge.Client/Hris/Types/TimeOff.cs @@ -1,48 +1,47 @@ using System.Text.Json.Serialization; using Merge.Client.Core; -using Merge.Client.Hris; using OneOf; #nullable enable namespace Merge.Client.Hris; -public class TimeOff +public record TimeOff { [JsonPropertyName("id")] - public string? Id { get; init; } + public string? Id { get; set; } /// /// The third-party API ID of the matching object. /// [JsonPropertyName("remote_id")] - public string? RemoteId { get; init; } + public string? RemoteId { get; set; } /// /// The datetime that this object was created by Merge. /// [JsonPropertyName("created_at")] - public DateTime? CreatedAt { get; init; } + public DateTime? CreatedAt { get; set; } /// /// The datetime that this object was modified by Merge. /// [JsonPropertyName("modified_at")] - public DateTime? ModifiedAt { get; init; } + public DateTime? ModifiedAt { get; set; } /// /// The employee requesting time off. /// [JsonPropertyName("employee")] [JsonConverter(typeof(OneOfSerializer>))] - public OneOf? Employee { get; init; } + public OneOf? Employee { get; set; } /// /// The Merge ID of the employee with the ability to approve the time off request. /// [JsonPropertyName("approver")] [JsonConverter(typeof(OneOfSerializer>))] - public OneOf? Approver { get; init; } + public OneOf? Approver { get; set; } /// /// The status of this time off request. @@ -54,13 +53,13 @@ public class TimeOff /// - `DELETED` - DELETED /// [JsonPropertyName("status")] - public TimeOffStatusEnum? Status { get; init; } + public TimeOffStatusEnum? Status { get; set; } /// /// The employee note for this time off request. /// [JsonPropertyName("employee_note")] - public string? EmployeeNote { get; init; } + public string? EmployeeNote { get; set; } /// /// The measurement that the third-party integration uses to count time requested. @@ -69,13 +68,13 @@ public class TimeOff /// - `DAYS` - DAYS /// [JsonPropertyName("units")] - public UnitsEnum? Units { get; init; } + public UnitsEnum? Units { get; set; } /// /// The time off quantity measured by the prescribed “units”. /// [JsonPropertyName("amount")] - public double? Amount { get; init; } + public double? Amount { get; set; } /// /// The type of time off request. @@ -88,26 +87,26 @@ public class TimeOff /// - `BEREAVEMENT` - BEREAVEMENT /// [JsonPropertyName("request_type")] - public RequestTypeEnum? RequestType { get; init; } + public RequestTypeEnum? RequestType { get; set; } /// /// The day and time of the start of the time requested off. /// [JsonPropertyName("start_time")] - public DateTime? StartTime { get; init; } + public DateTime? StartTime { get; set; } /// /// The day and time of the end of the time requested off. /// [JsonPropertyName("end_time")] - public DateTime? EndTime { get; init; } + public DateTime? EndTime { get; set; } [JsonPropertyName("remote_was_deleted")] - public bool? RemoteWasDeleted { get; init; } + public bool? RemoteWasDeleted { get; set; } [JsonPropertyName("field_mappings")] - public Dictionary? FieldMappings { get; init; } + public Dictionary? FieldMappings { get; set; } [JsonPropertyName("remote_data")] - public IEnumerable? RemoteData { get; init; } + public IEnumerable? RemoteData { get; set; } } diff --git a/src/Merge.Client/Hris/Types/TimeOffBalance.cs b/src/Merge.Client/Hris/Types/TimeOffBalance.cs index a59f8730..84bdf6ec 100644 --- a/src/Merge.Client/Hris/Types/TimeOffBalance.cs +++ b/src/Merge.Client/Hris/Types/TimeOffBalance.cs @@ -1,53 +1,52 @@ using System.Text.Json.Serialization; using Merge.Client.Core; -using Merge.Client.Hris; using OneOf; #nullable enable namespace Merge.Client.Hris; -public class TimeOffBalance +public record TimeOffBalance { [JsonPropertyName("id")] - public string? Id { get; init; } + public string? Id { get; set; } /// /// The third-party API ID of the matching object. /// [JsonPropertyName("remote_id")] - public string? RemoteId { get; init; } + public string? RemoteId { get; set; } /// /// The datetime that this object was created by Merge. /// [JsonPropertyName("created_at")] - public DateTime? CreatedAt { get; init; } + public DateTime? CreatedAt { get; set; } /// /// The datetime that this object was modified by Merge. /// [JsonPropertyName("modified_at")] - public DateTime? ModifiedAt { get; init; } + public DateTime? ModifiedAt { get; set; } /// /// The employee the balance belongs to. /// [JsonPropertyName("employee")] [JsonConverter(typeof(OneOfSerializer>))] - public OneOf? Employee { get; init; } + public OneOf? Employee { get; set; } /// /// The current remaining PTO balance, always measured in terms of hours. /// [JsonPropertyName("balance")] - public double? Balance { get; init; } + public double? Balance { get; set; } /// /// The amount of PTO used in terms of hours. /// [JsonPropertyName("used")] - public double? Used { get; init; } + public double? Used { get; set; } /// /// The policy type of this time off balance. @@ -60,17 +59,17 @@ public class TimeOffBalance /// - `BEREAVEMENT` - BEREAVEMENT /// [JsonPropertyName("policy_type")] - public PolicyTypeEnum? PolicyType { get; init; } + public PolicyTypeEnum? PolicyType { get; set; } /// /// Indicates whether or not this object has been deleted in the third party platform. /// [JsonPropertyName("remote_was_deleted")] - public bool? RemoteWasDeleted { get; init; } + public bool? RemoteWasDeleted { get; set; } [JsonPropertyName("field_mappings")] - public Dictionary? FieldMappings { get; init; } + public Dictionary? FieldMappings { get; set; } [JsonPropertyName("remote_data")] - public IEnumerable? RemoteData { get; init; } + public IEnumerable? RemoteData { get; set; } } diff --git a/src/Merge.Client/Hris/Types/TimeOffRequest.cs b/src/Merge.Client/Hris/Types/TimeOffRequest.cs index c2c334f9..4bbe2e69 100644 --- a/src/Merge.Client/Hris/Types/TimeOffRequest.cs +++ b/src/Merge.Client/Hris/Types/TimeOffRequest.cs @@ -1,27 +1,26 @@ using System.Text.Json.Serialization; using Merge.Client.Core; -using Merge.Client.Hris; using OneOf; #nullable enable namespace Merge.Client.Hris; -public class TimeOffRequest +public record TimeOffRequest { /// /// The employee requesting time off. /// [JsonPropertyName("employee")] [JsonConverter(typeof(OneOfSerializer>))] - public OneOf? Employee { get; init; } + public OneOf? Employee { get; set; } /// /// The Merge ID of the employee with the ability to approve the time off request. /// [JsonPropertyName("approver")] [JsonConverter(typeof(OneOfSerializer>))] - public OneOf? Approver { get; init; } + public OneOf? Approver { get; set; } /// /// The status of this time off request. @@ -33,13 +32,13 @@ public class TimeOffRequest /// - `DELETED` - DELETED /// [JsonPropertyName("status")] - public TimeOffStatusEnum? Status { get; init; } + public TimeOffStatusEnum? Status { get; set; } /// /// The employee note for this time off request. /// [JsonPropertyName("employee_note")] - public string? EmployeeNote { get; init; } + public string? EmployeeNote { get; set; } /// /// The measurement that the third-party integration uses to count time requested. @@ -48,13 +47,13 @@ public class TimeOffRequest /// - `DAYS` - DAYS /// [JsonPropertyName("units")] - public UnitsEnum? Units { get; init; } + public UnitsEnum? Units { get; set; } /// /// The time off quantity measured by the prescribed “units”. /// [JsonPropertyName("amount")] - public double? Amount { get; init; } + public double? Amount { get; set; } /// /// The type of time off request. @@ -67,23 +66,23 @@ public class TimeOffRequest /// - `BEREAVEMENT` - BEREAVEMENT /// [JsonPropertyName("request_type")] - public RequestTypeEnum? RequestType { get; init; } + public RequestTypeEnum? RequestType { get; set; } /// /// The day and time of the start of the time requested off. /// [JsonPropertyName("start_time")] - public DateTime? StartTime { get; init; } + public DateTime? StartTime { get; set; } /// /// The day and time of the end of the time requested off. /// [JsonPropertyName("end_time")] - public DateTime? EndTime { get; init; } + public DateTime? EndTime { get; set; } [JsonPropertyName("integration_params")] - public Dictionary? IntegrationParams { get; init; } + public Dictionary? IntegrationParams { get; set; } [JsonPropertyName("linked_account_params")] - public Dictionary? LinkedAccountParams { get; init; } + public Dictionary? LinkedAccountParams { get; set; } } diff --git a/src/Merge.Client/Hris/Types/TimeOffResponse.cs b/src/Merge.Client/Hris/Types/TimeOffResponse.cs index 4be5270c..4d70f5b6 100644 --- a/src/Merge.Client/Hris/Types/TimeOffResponse.cs +++ b/src/Merge.Client/Hris/Types/TimeOffResponse.cs @@ -1,21 +1,22 @@ using System.Text.Json.Serialization; -using Merge.Client.Hris; #nullable enable namespace Merge.Client.Hris; -public class TimeOffResponse +public record TimeOffResponse { [JsonPropertyName("model")] - public TimeOff Model { get; init; } + public required TimeOff Model { get; set; } [JsonPropertyName("warnings")] - public IEnumerable Warnings { get; init; } + public IEnumerable Warnings { get; set; } = + new List(); [JsonPropertyName("errors")] - public IEnumerable Errors { get; init; } + public IEnumerable Errors { get; set; } = + new List(); [JsonPropertyName("logs")] - public IEnumerable? Logs { get; init; } + public IEnumerable? Logs { get; set; } } diff --git a/src/Merge.Client/Hris/Types/TimeOffStatusEnum.cs b/src/Merge.Client/Hris/Types/TimeOffStatusEnum.cs index fba74e83..202e931a 100644 --- a/src/Merge.Client/Hris/Types/TimeOffStatusEnum.cs +++ b/src/Merge.Client/Hris/Types/TimeOffStatusEnum.cs @@ -1,7 +1,6 @@ using System.Runtime.Serialization; using System.Text.Json.Serialization; using Merge.Client.Core; -using Merge.Client.Hris; #nullable enable diff --git a/src/Merge.Client/Hris/Types/TimesheetEntry.cs b/src/Merge.Client/Hris/Types/TimesheetEntry.cs index 005c66cc..335b0a5a 100644 --- a/src/Merge.Client/Hris/Types/TimesheetEntry.cs +++ b/src/Merge.Client/Hris/Types/TimesheetEntry.cs @@ -4,62 +4,62 @@ namespace Merge.Client.Hris; -public class TimesheetEntry +public record TimesheetEntry { [JsonPropertyName("id")] - public string? Id { get; init; } + public string? Id { get; set; } /// /// The third-party API ID of the matching object. /// [JsonPropertyName("remote_id")] - public string? RemoteId { get; init; } + public string? RemoteId { get; set; } /// /// The datetime that this object was created by Merge. /// [JsonPropertyName("created_at")] - public DateTime? CreatedAt { get; init; } + public DateTime? CreatedAt { get; set; } /// /// The datetime that this object was modified by Merge. /// [JsonPropertyName("modified_at")] - public DateTime? ModifiedAt { get; init; } + public DateTime? ModifiedAt { get; set; } /// /// The employee the timesheet entry is for. /// [JsonPropertyName("employee")] - public string? Employee { get; init; } + public string? Employee { get; set; } /// /// The number of hours logged by the employee. /// [JsonPropertyName("hours_worked")] - public double? HoursWorked { get; init; } + public double? HoursWorked { get; set; } /// /// The time at which the employee started work. /// [JsonPropertyName("start_time")] - public DateTime? StartTime { get; init; } + public DateTime? StartTime { get; set; } /// /// The time at which the employee ended work. /// [JsonPropertyName("end_time")] - public DateTime? EndTime { get; init; } + public DateTime? EndTime { get; set; } /// /// Indicates whether or not this object has been deleted in the third party platform. /// [JsonPropertyName("remote_was_deleted")] - public bool? RemoteWasDeleted { get; init; } + public bool? RemoteWasDeleted { get; set; } [JsonPropertyName("field_mappings")] - public Dictionary? FieldMappings { get; init; } + public Dictionary? FieldMappings { get; set; } [JsonPropertyName("remote_data")] - public IEnumerable>? RemoteData { get; init; } + public IEnumerable>? RemoteData { get; set; } } diff --git a/src/Merge.Client/Hris/Types/TimesheetEntryRequest.cs b/src/Merge.Client/Hris/Types/TimesheetEntryRequest.cs index 25c451bd..3d167aa6 100644 --- a/src/Merge.Client/Hris/Types/TimesheetEntryRequest.cs +++ b/src/Merge.Client/Hris/Types/TimesheetEntryRequest.cs @@ -4,35 +4,35 @@ namespace Merge.Client.Hris; -public class TimesheetEntryRequest +public record TimesheetEntryRequest { /// /// The employee the timesheet entry is for. /// [JsonPropertyName("employee")] - public string? Employee { get; init; } + public string? Employee { get; set; } /// /// The number of hours logged by the employee. /// [JsonPropertyName("hours_worked")] - public double? HoursWorked { get; init; } + public double? HoursWorked { get; set; } /// /// The time at which the employee started work. /// [JsonPropertyName("start_time")] - public DateTime? StartTime { get; init; } + public DateTime? StartTime { get; set; } /// /// The time at which the employee ended work. /// [JsonPropertyName("end_time")] - public DateTime? EndTime { get; init; } + public DateTime? EndTime { get; set; } [JsonPropertyName("integration_params")] - public Dictionary? IntegrationParams { get; init; } + public Dictionary? IntegrationParams { get; set; } [JsonPropertyName("linked_account_params")] - public Dictionary? LinkedAccountParams { get; init; } + public Dictionary? LinkedAccountParams { get; set; } } diff --git a/src/Merge.Client/Hris/Types/TimesheetEntryResponse.cs b/src/Merge.Client/Hris/Types/TimesheetEntryResponse.cs index 096636f3..49b312f6 100644 --- a/src/Merge.Client/Hris/Types/TimesheetEntryResponse.cs +++ b/src/Merge.Client/Hris/Types/TimesheetEntryResponse.cs @@ -1,21 +1,22 @@ using System.Text.Json.Serialization; -using Merge.Client.Hris; #nullable enable namespace Merge.Client.Hris; -public class TimesheetEntryResponse +public record TimesheetEntryResponse { [JsonPropertyName("model")] - public TimesheetEntry Model { get; init; } + public required TimesheetEntry Model { get; set; } [JsonPropertyName("warnings")] - public IEnumerable Warnings { get; init; } + public IEnumerable Warnings { get; set; } = + new List(); [JsonPropertyName("errors")] - public IEnumerable Errors { get; init; } + public IEnumerable Errors { get; set; } = + new List(); [JsonPropertyName("logs")] - public IEnumerable? Logs { get; init; } + public IEnumerable? Logs { get; set; } } diff --git a/src/Merge.Client/Hris/Types/UnitsEnum.cs b/src/Merge.Client/Hris/Types/UnitsEnum.cs index 69abfbe4..e6a6b4dc 100644 --- a/src/Merge.Client/Hris/Types/UnitsEnum.cs +++ b/src/Merge.Client/Hris/Types/UnitsEnum.cs @@ -1,7 +1,6 @@ using System.Runtime.Serialization; using System.Text.Json.Serialization; using Merge.Client.Core; -using Merge.Client.Hris; #nullable enable diff --git a/src/Merge.Client/Hris/Types/ValidationProblemSource.cs b/src/Merge.Client/Hris/Types/ValidationProblemSource.cs index 6ece4026..996c4902 100644 --- a/src/Merge.Client/Hris/Types/ValidationProblemSource.cs +++ b/src/Merge.Client/Hris/Types/ValidationProblemSource.cs @@ -4,8 +4,8 @@ namespace Merge.Client.Hris; -public class ValidationProblemSource +public record ValidationProblemSource { [JsonPropertyName("pointer")] - public string Pointer { get; init; } + public required string Pointer { get; set; } } diff --git a/src/Merge.Client/Hris/Types/WarningValidationProblem.cs b/src/Merge.Client/Hris/Types/WarningValidationProblem.cs index e50f6b26..154b4e72 100644 --- a/src/Merge.Client/Hris/Types/WarningValidationProblem.cs +++ b/src/Merge.Client/Hris/Types/WarningValidationProblem.cs @@ -1,21 +1,20 @@ using System.Text.Json.Serialization; -using Merge.Client.Hris; #nullable enable namespace Merge.Client.Hris; -public class WarningValidationProblem +public record WarningValidationProblem { [JsonPropertyName("source")] - public ValidationProblemSource? Source { get; init; } + public ValidationProblemSource? Source { get; set; } [JsonPropertyName("title")] - public string Title { get; init; } + public required string Title { get; set; } [JsonPropertyName("detail")] - public string Detail { get; init; } + public required string Detail { get; set; } [JsonPropertyName("problem_type")] - public string ProblemType { get; init; } + public required string ProblemType { get; set; } } diff --git a/src/Merge.Client/Hris/Types/WebhookReceiver.cs b/src/Merge.Client/Hris/Types/WebhookReceiver.cs index 1593691a..5edf540b 100644 --- a/src/Merge.Client/Hris/Types/WebhookReceiver.cs +++ b/src/Merge.Client/Hris/Types/WebhookReceiver.cs @@ -4,14 +4,14 @@ namespace Merge.Client.Hris; -public class WebhookReceiver +public record WebhookReceiver { [JsonPropertyName("event")] - public string Event { get; init; } + public required string Event { get; set; } [JsonPropertyName("is_active")] - public bool IsActive { get; init; } + public required bool IsActive { get; set; } [JsonPropertyName("key")] - public string? Key { get; init; } + public string? Key { get; set; } } diff --git a/src/Merge.Client/Hris/WebhookReceivers/Requests/WebhookReceiverRequest.cs b/src/Merge.Client/Hris/WebhookReceivers/Requests/WebhookReceiverRequest.cs index 54722558..8b365291 100644 --- a/src/Merge.Client/Hris/WebhookReceivers/Requests/WebhookReceiverRequest.cs +++ b/src/Merge.Client/Hris/WebhookReceivers/Requests/WebhookReceiverRequest.cs @@ -4,14 +4,14 @@ namespace Merge.Client.Hris; -public class WebhookReceiverRequest +public record WebhookReceiverRequest { [JsonPropertyName("event")] - public string Event { get; init; } + public required string Event { get; set; } [JsonPropertyName("is_active")] - public bool IsActive { get; init; } + public required bool IsActive { get; set; } [JsonPropertyName("key")] - public string? Key { get; init; } + public string? Key { get; set; } } diff --git a/src/Merge.Client/Hris/WebhookReceivers/WebhookReceiversClient.cs b/src/Merge.Client/Hris/WebhookReceivers/WebhookReceiversClient.cs index 06b7f302..2bcf82fe 100644 --- a/src/Merge.Client/Hris/WebhookReceivers/WebhookReceiversClient.cs +++ b/src/Merge.Client/Hris/WebhookReceivers/WebhookReceiversClient.cs @@ -1,6 +1,6 @@ +using System.Net.Http; using System.Text.Json; -using Merge.Client; -using Merge.Client.Hris; +using Merge.Client.Core; #nullable enable @@ -18,41 +18,72 @@ public WebhookReceiversClient(RawClient client) /// /// Returns a list of `WebhookReceiver` objects. /// - public async Task> ListAsync() + public async Task> ListAsync(RequestOptions? options = null) { var response = await _client.MakeRequestAsync( new RawClient.JsonApiRequest { + BaseUrl = _client.Options.BaseUrl, Method = HttpMethod.Get, - Path = "hris/v1/webhook-receivers" + Path = "hris/v1/webhook-receivers", + Options = options } ); - string responseBody = await response.Raw.Content.ReadAsStringAsync(); - if (response.StatusCode >= 200 && response.StatusCode < 400) + var responseBody = await response.Raw.Content.ReadAsStringAsync(); + if (response.StatusCode is >= 200 and < 400) { - return JsonSerializer.Deserialize>(responseBody); + try + { + return JsonUtils.Deserialize>(responseBody)!; + } + catch (JsonException e) + { + throw new MergeException("Failed to deserialize response", e); + } } - throw new Exception(responseBody); + + throw new MergeApiException( + $"Error with status code {response.StatusCode}", + response.StatusCode, + JsonUtils.Deserialize(responseBody) + ); } /// /// Creates a `WebhookReceiver` object with the given values. /// - public async Task CreateAsync(WebhookReceiverRequest request) + public async Task CreateAsync( + WebhookReceiverRequest request, + RequestOptions? options = null + ) { var response = await _client.MakeRequestAsync( new RawClient.JsonApiRequest { + BaseUrl = _client.Options.BaseUrl, Method = HttpMethod.Post, Path = "hris/v1/webhook-receivers", - Body = request + Body = request, + Options = options } ); - string responseBody = await response.Raw.Content.ReadAsStringAsync(); - if (response.StatusCode >= 200 && response.StatusCode < 400) + var responseBody = await response.Raw.Content.ReadAsStringAsync(); + if (response.StatusCode is >= 200 and < 400) { - return JsonSerializer.Deserialize(responseBody); + try + { + return JsonUtils.Deserialize(responseBody)!; + } + catch (JsonException e) + { + throw new MergeException("Failed to deserialize response", e); + } } - throw new Exception(responseBody); + + throw new MergeApiException( + $"Error with status code {response.StatusCode}", + response.StatusCode, + JsonUtils.Deserialize(responseBody) + ); } } diff --git a/src/Merge.Client/Merge.Client.csproj b/src/Merge.Client/Merge.Client.csproj index 85287d57..8bca6ff3 100644 --- a/src/Merge.Client/Merge.Client.csproj +++ b/src/Merge.Client/Merge.Client.csproj @@ -1,19 +1,41 @@ - + - net8.0;net7.0;net6.0; + net462;net8.0;net7.0;net6.0;netstandard2.0 enable false - 0.1.0 + 12 + enable + 0.2.0 README.md LICENSE https://github.com/merge-api/merge-csharp-client + + + true + + + + + + + + + + + + + runtime; build; native; contentfiles; analyzers; buildtransitive + all + + - + + diff --git a/src/Merge.Client/Merge.cs b/src/Merge.Client/Merge.cs index cb6030ec..ca9e74aa 100644 --- a/src/Merge.Client/Merge.cs +++ b/src/Merge.Client/Merge.cs @@ -1,6 +1,7 @@ -using Merge.Client; +using System; using Merge.Client.Accounting; using Merge.Client.Ats; +using Merge.Client.Core; using Merge.Client.Crm; using Merge.Client.Filestorage; using Merge.Client.Hris; @@ -15,9 +16,9 @@ public partial class Merge private RawClient _client; public Merge( - string apiKey = null, + string? apiKey = null, string? accountToken = null, - ClientOptions clientOptions = null + ClientOptions? clientOptions = null ) { _client = new RawClient( @@ -27,37 +28,28 @@ public Merge( { "X-Account-Token", accountToken }, { "X-Fern-Language", "C#" }, { "X-Fern-SDK-Name", "Merge.Client" }, - { "X-Fern-SDK-Version", "0.1.0" }, + { "X-Fern-SDK-Version", "0.2.0" }, }, + new Dictionary>() { }, clientOptions ?? new ClientOptions() ); + Filestorage = new FilestorageClient(_client); Ats = new AtsClient(_client); Crm = new CrmClient(_client); - Filestorage = new FilestorageClient(_client); - Ticketing = new TicketingClient(_client); Hris = new HrisClient(_client); + Ticketing = new TicketingClient(_client); Accounting = new AccountingClient(_client); } - public AtsClient Ats { get; } + public FilestorageClient Filestorage { get; init; } - public CrmClient Crm { get; } + public AtsClient Ats { get; init; } - public FilestorageClient Filestorage { get; } + public CrmClient Crm { get; init; } - public TicketingClient Ticketing { get; } + public HrisClient Hris { get; init; } - public HrisClient Hris { get; } + public TicketingClient Ticketing { get; init; } - public AccountingClient Accounting { get; } - - private string GetFromEnvironmentOrThrow(string env, string message) - { - var value = System.Environment.GetEnvironmentVariable(env); - if (value == null) - { - throw new Exception(message); - } - return value; - } + public AccountingClient Accounting { get; init; } } diff --git a/src/Merge.Client/Ticketing/AccountDetails/AccountDetailsClient.cs b/src/Merge.Client/Ticketing/AccountDetails/AccountDetailsClient.cs index f2fea22d..82e357fb 100644 --- a/src/Merge.Client/Ticketing/AccountDetails/AccountDetailsClient.cs +++ b/src/Merge.Client/Ticketing/AccountDetails/AccountDetailsClient.cs @@ -1,6 +1,6 @@ +using System.Net.Http; using System.Text.Json; -using Merge.Client; -using Merge.Client.Ticketing; +using Merge.Client.Core; #nullable enable @@ -18,20 +18,34 @@ public AccountDetailsClient(RawClient client) /// /// Get details for a linked account. /// - public async Task RetrieveAsync() + public async Task RetrieveAsync(RequestOptions? options = null) { var response = await _client.MakeRequestAsync( new RawClient.JsonApiRequest { + BaseUrl = _client.Options.BaseUrl, Method = HttpMethod.Get, - Path = "ticketing/v1/account-details" + Path = "ticketing/v1/account-details", + Options = options } ); - string responseBody = await response.Raw.Content.ReadAsStringAsync(); - if (response.StatusCode >= 200 && response.StatusCode < 400) + var responseBody = await response.Raw.Content.ReadAsStringAsync(); + if (response.StatusCode is >= 200 and < 400) { - return JsonSerializer.Deserialize(responseBody); + try + { + return JsonUtils.Deserialize(responseBody)!; + } + catch (JsonException e) + { + throw new MergeException("Failed to deserialize response", e); + } } - throw new Exception(responseBody); + + throw new MergeApiException( + $"Error with status code {response.StatusCode}", + response.StatusCode, + JsonUtils.Deserialize(responseBody) + ); } } diff --git a/src/Merge.Client/Ticketing/AccountToken/AccountTokenClient.cs b/src/Merge.Client/Ticketing/AccountToken/AccountTokenClient.cs index 74a43715..ff4041d1 100644 --- a/src/Merge.Client/Ticketing/AccountToken/AccountTokenClient.cs +++ b/src/Merge.Client/Ticketing/AccountToken/AccountTokenClient.cs @@ -1,6 +1,6 @@ +using System.Net.Http; using System.Text.Json; -using Merge.Client; -using Merge.Client.Ticketing; +using Merge.Client.Core; #nullable enable @@ -18,20 +18,37 @@ public AccountTokenClient(RawClient client) /// /// Returns the account token for the end user with the provided public token. /// - public async Task RetrieveAsync(string publicToken) + public async Task RetrieveAsync( + string publicToken, + RequestOptions? options = null + ) { var response = await _client.MakeRequestAsync( new RawClient.JsonApiRequest { + BaseUrl = _client.Options.BaseUrl, Method = HttpMethod.Get, - Path = $"ticketing/v1/account-token/{publicToken}" + Path = $"ticketing/v1/account-token/{publicToken}", + Options = options } ); - string responseBody = await response.Raw.Content.ReadAsStringAsync(); - if (response.StatusCode >= 200 && response.StatusCode < 400) + var responseBody = await response.Raw.Content.ReadAsStringAsync(); + if (response.StatusCode is >= 200 and < 400) { - return JsonSerializer.Deserialize(responseBody); + try + { + return JsonUtils.Deserialize(responseBody)!; + } + catch (JsonException e) + { + throw new MergeException("Failed to deserialize response", e); + } } - throw new Exception(responseBody); + + throw new MergeApiException( + $"Error with status code {response.StatusCode}", + response.StatusCode, + JsonUtils.Deserialize(responseBody) + ); } } diff --git a/src/Merge.Client/Ticketing/Accounts/AccountsClient.cs b/src/Merge.Client/Ticketing/Accounts/AccountsClient.cs index d521553a..b88fa0ca 100644 --- a/src/Merge.Client/Ticketing/Accounts/AccountsClient.cs +++ b/src/Merge.Client/Ticketing/Accounts/AccountsClient.cs @@ -1,6 +1,6 @@ +using System.Net.Http; using System.Text.Json; -using Merge.Client; -using Merge.Client.Ticketing; +using Merge.Client.Core; #nullable enable @@ -18,16 +18,21 @@ public AccountsClient(RawClient client) /// /// Returns a list of `Account` objects. /// - public async Task ListAsync(AccountsListRequest request) + public async Task ListAsync( + AccountsListRequest request, + RequestOptions? options = null + ) { var _query = new Dictionary() { }; if (request.CreatedAfter != null) { - _query["created_after"] = request.CreatedAfter.Value.ToString("o0"); + _query["created_after"] = request.CreatedAfter.Value.ToString(Constants.DateTimeFormat); } if (request.CreatedBefore != null) { - _query["created_before"] = request.CreatedBefore.Value.ToString("o0"); + _query["created_before"] = request.CreatedBefore.Value.ToString( + Constants.DateTimeFormat + ); } if (request.Cursor != null) { @@ -43,11 +48,15 @@ public async Task ListAsync(AccountsListRequest request) } if (request.ModifiedAfter != null) { - _query["modified_after"] = request.ModifiedAfter.Value.ToString("o0"); + _query["modified_after"] = request.ModifiedAfter.Value.ToString( + Constants.DateTimeFormat + ); } if (request.ModifiedBefore != null) { - _query["modified_before"] = request.ModifiedBefore.Value.ToString("o0"); + _query["modified_before"] = request.ModifiedBefore.Value.ToString( + Constants.DateTimeFormat + ); } if (request.PageSize != null) { @@ -60,23 +69,41 @@ public async Task ListAsync(AccountsListRequest request) var response = await _client.MakeRequestAsync( new RawClient.JsonApiRequest { + BaseUrl = _client.Options.BaseUrl, Method = HttpMethod.Get, Path = "ticketing/v1/accounts", - Query = _query + Query = _query, + Options = options } ); - string responseBody = await response.Raw.Content.ReadAsStringAsync(); - if (response.StatusCode >= 200 && response.StatusCode < 400) + var responseBody = await response.Raw.Content.ReadAsStringAsync(); + if (response.StatusCode is >= 200 and < 400) { - return JsonSerializer.Deserialize(responseBody); + try + { + return JsonUtils.Deserialize(responseBody)!; + } + catch (JsonException e) + { + throw new MergeException("Failed to deserialize response", e); + } } - throw new Exception(responseBody); + + throw new MergeApiException( + $"Error with status code {response.StatusCode}", + response.StatusCode, + JsonUtils.Deserialize(responseBody) + ); } /// /// Returns an `Account` object with the given `id`. /// - public async Task RetrieveAsync(string id, AccountsRetrieveRequest request) + public async Task RetrieveAsync( + string id, + AccountsRetrieveRequest request, + RequestOptions? options = null + ) { var _query = new Dictionary() { }; if (request.IncludeRemoteData != null) @@ -86,16 +113,30 @@ public async Task RetrieveAsync(string id, AccountsRetrieveRequest requ var response = await _client.MakeRequestAsync( new RawClient.JsonApiRequest { + BaseUrl = _client.Options.BaseUrl, Method = HttpMethod.Get, Path = $"ticketing/v1/accounts/{id}", - Query = _query + Query = _query, + Options = options } ); - string responseBody = await response.Raw.Content.ReadAsStringAsync(); - if (response.StatusCode >= 200 && response.StatusCode < 400) + var responseBody = await response.Raw.Content.ReadAsStringAsync(); + if (response.StatusCode is >= 200 and < 400) { - return JsonSerializer.Deserialize(responseBody); + try + { + return JsonUtils.Deserialize(responseBody)!; + } + catch (JsonException e) + { + throw new MergeException("Failed to deserialize response", e); + } } - throw new Exception(responseBody); + + throw new MergeApiException( + $"Error with status code {response.StatusCode}", + response.StatusCode, + JsonUtils.Deserialize(responseBody) + ); } } diff --git a/src/Merge.Client/Ticketing/Accounts/Requests/AccountsListRequest.cs b/src/Merge.Client/Ticketing/Accounts/Requests/AccountsListRequest.cs index 2b4ff22f..80c825ec 100644 --- a/src/Merge.Client/Ticketing/Accounts/Requests/AccountsListRequest.cs +++ b/src/Merge.Client/Ticketing/Accounts/Requests/AccountsListRequest.cs @@ -1,49 +1,49 @@ namespace Merge.Client.Ticketing; -public class AccountsListRequest +public record AccountsListRequest { /// /// If provided, will only return objects created after this datetime. /// - public DateTime? CreatedAfter { get; init; } + public DateTime? CreatedAfter { get; set; } /// /// If provided, will only return objects created before this datetime. /// - public DateTime? CreatedBefore { get; init; } + public DateTime? CreatedBefore { get; set; } /// /// The pagination cursor value. /// - public string? Cursor { get; init; } + public string? Cursor { get; set; } /// /// Whether to include data that was marked as deleted by third party webhooks. /// - public bool? IncludeDeletedData { get; init; } + public bool? IncludeDeletedData { get; set; } /// /// Whether to include the original data Merge fetched from the third-party to produce these models. /// - public bool? IncludeRemoteData { get; init; } + public bool? IncludeRemoteData { get; set; } /// /// If provided, only objects synced by Merge after this date time will be returned. /// - public DateTime? ModifiedAfter { get; init; } + public DateTime? ModifiedAfter { get; set; } /// /// If provided, only objects synced by Merge before this date time will be returned. /// - public DateTime? ModifiedBefore { get; init; } + public DateTime? ModifiedBefore { get; set; } /// /// Number of results to return per page. /// - public int? PageSize { get; init; } + public int? PageSize { get; set; } /// /// The API provider's ID for the given object. /// - public string? RemoteId { get; init; } + public string? RemoteId { get; set; } } diff --git a/src/Merge.Client/Ticketing/Accounts/Requests/AccountsRetrieveRequest.cs b/src/Merge.Client/Ticketing/Accounts/Requests/AccountsRetrieveRequest.cs index 4a7a239d..24cceda9 100644 --- a/src/Merge.Client/Ticketing/Accounts/Requests/AccountsRetrieveRequest.cs +++ b/src/Merge.Client/Ticketing/Accounts/Requests/AccountsRetrieveRequest.cs @@ -1,9 +1,9 @@ namespace Merge.Client.Ticketing; -public class AccountsRetrieveRequest +public record AccountsRetrieveRequest { /// /// Whether to include the original data Merge fetched from the third-party to produce these models. /// - public bool? IncludeRemoteData { get; init; } + public bool? IncludeRemoteData { get; set; } } diff --git a/src/Merge.Client/Ticketing/AsyncPassthrough/AsyncPassthroughClient.cs b/src/Merge.Client/Ticketing/AsyncPassthrough/AsyncPassthroughClient.cs index 90db7cca..a6043bc2 100644 --- a/src/Merge.Client/Ticketing/AsyncPassthrough/AsyncPassthroughClient.cs +++ b/src/Merge.Client/Ticketing/AsyncPassthrough/AsyncPassthroughClient.cs @@ -1,6 +1,6 @@ +using System.Net.Http; using System.Text.Json; -using Merge.Client; -using Merge.Client.Ticketing; +using Merge.Client.Core; #nullable enable @@ -18,41 +18,75 @@ public AsyncPassthroughClient(RawClient client) /// /// Asynchronously pull data from an endpoint not currently supported by Merge. /// - public async Task CreateAsync(DataPassthroughRequest request) + public async Task CreateAsync( + DataPassthroughRequest request, + RequestOptions? options = null + ) { var response = await _client.MakeRequestAsync( new RawClient.JsonApiRequest { + BaseUrl = _client.Options.BaseUrl, Method = HttpMethod.Post, Path = "ticketing/v1/async-passthrough", - Body = request + Body = request, + Options = options } ); - string responseBody = await response.Raw.Content.ReadAsStringAsync(); - if (response.StatusCode >= 200 && response.StatusCode < 400) + var responseBody = await response.Raw.Content.ReadAsStringAsync(); + if (response.StatusCode is >= 200 and < 400) { - return JsonSerializer.Deserialize(responseBody); + try + { + return JsonUtils.Deserialize(responseBody)!; + } + catch (JsonException e) + { + throw new MergeException("Failed to deserialize response", e); + } } - throw new Exception(responseBody); + + throw new MergeApiException( + $"Error with status code {response.StatusCode}", + response.StatusCode, + JsonUtils.Deserialize(responseBody) + ); } /// /// Retrieves data from earlier async-passthrough POST request /// - public async Task RetrieveAsync(string asyncPassthroughReceiptId) + public async Task RetrieveAsync( + string asyncPassthroughReceiptId, + RequestOptions? options = null + ) { var response = await _client.MakeRequestAsync( new RawClient.JsonApiRequest { + BaseUrl = _client.Options.BaseUrl, Method = HttpMethod.Get, - Path = $"ticketing/v1/async-passthrough/{asyncPassthroughReceiptId}" + Path = $"ticketing/v1/async-passthrough/{asyncPassthroughReceiptId}", + Options = options } ); - string responseBody = await response.Raw.Content.ReadAsStringAsync(); - if (response.StatusCode >= 200 && response.StatusCode < 400) + var responseBody = await response.Raw.Content.ReadAsStringAsync(); + if (response.StatusCode is >= 200 and < 400) { - return JsonSerializer.Deserialize(responseBody); + try + { + return JsonUtils.Deserialize(responseBody)!; + } + catch (JsonException e) + { + throw new MergeException("Failed to deserialize response", e); + } } - throw new Exception(responseBody); + + throw new MergeApiException( + $"Error with status code {response.StatusCode}", + response.StatusCode, + JsonUtils.Deserialize(responseBody) + ); } } diff --git a/src/Merge.Client/Ticketing/Attachments/AttachmentsClient.cs b/src/Merge.Client/Ticketing/Attachments/AttachmentsClient.cs index 052e990f..15388ef8 100644 --- a/src/Merge.Client/Ticketing/Attachments/AttachmentsClient.cs +++ b/src/Merge.Client/Ticketing/Attachments/AttachmentsClient.cs @@ -1,6 +1,6 @@ +using System.Net.Http; using System.Text.Json; -using Merge.Client; -using Merge.Client.Ticketing; +using Merge.Client.Core; #nullable enable @@ -18,16 +18,21 @@ public AttachmentsClient(RawClient client) /// /// Returns a list of `Attachment` objects. /// - public async Task ListAsync(AttachmentsListRequest request) + public async Task ListAsync( + AttachmentsListRequest request, + RequestOptions? options = null + ) { var _query = new Dictionary() { }; if (request.CreatedAfter != null) { - _query["created_after"] = request.CreatedAfter.Value.ToString("o0"); + _query["created_after"] = request.CreatedAfter.Value.ToString(Constants.DateTimeFormat); } if (request.CreatedBefore != null) { - _query["created_before"] = request.CreatedBefore.Value.ToString("o0"); + _query["created_before"] = request.CreatedBefore.Value.ToString( + Constants.DateTimeFormat + ); } if (request.Cursor != null) { @@ -47,11 +52,15 @@ public async Task ListAsync(AttachmentsListRequest requ } if (request.ModifiedAfter != null) { - _query["modified_after"] = request.ModifiedAfter.Value.ToString("o0"); + _query["modified_after"] = request.ModifiedAfter.Value.ToString( + Constants.DateTimeFormat + ); } if (request.ModifiedBefore != null) { - _query["modified_before"] = request.ModifiedBefore.Value.ToString("o0"); + _query["modified_before"] = request.ModifiedBefore.Value.ToString( + Constants.DateTimeFormat + ); } if (request.PageSize != null) { @@ -59,7 +68,9 @@ public async Task ListAsync(AttachmentsListRequest requ } if (request.RemoteCreatedAfter != null) { - _query["remote_created_after"] = request.RemoteCreatedAfter.Value.ToString("o0"); + _query["remote_created_after"] = request.RemoteCreatedAfter.Value.ToString( + Constants.DateTimeFormat + ); } if (request.RemoteId != null) { @@ -72,24 +83,39 @@ public async Task ListAsync(AttachmentsListRequest requ var response = await _client.MakeRequestAsync( new RawClient.JsonApiRequest { + BaseUrl = _client.Options.BaseUrl, Method = HttpMethod.Get, Path = "ticketing/v1/attachments", - Query = _query + Query = _query, + Options = options } ); - string responseBody = await response.Raw.Content.ReadAsStringAsync(); - if (response.StatusCode >= 200 && response.StatusCode < 400) + var responseBody = await response.Raw.Content.ReadAsStringAsync(); + if (response.StatusCode is >= 200 and < 400) { - return JsonSerializer.Deserialize(responseBody); + try + { + return JsonUtils.Deserialize(responseBody)!; + } + catch (JsonException e) + { + throw new MergeException("Failed to deserialize response", e); + } } - throw new Exception(responseBody); + + throw new MergeApiException( + $"Error with status code {response.StatusCode}", + response.StatusCode, + JsonUtils.Deserialize(responseBody) + ); } /// /// Creates an `Attachment` object with the given values. /// public async Task CreateAsync( - TicketingAttachmentEndpointRequest request + TicketingAttachmentEndpointRequest request, + RequestOptions? options = null ) { var _query = new Dictionary() { }; @@ -104,23 +130,41 @@ TicketingAttachmentEndpointRequest request var response = await _client.MakeRequestAsync( new RawClient.JsonApiRequest { + BaseUrl = _client.Options.BaseUrl, Method = HttpMethod.Post, Path = "ticketing/v1/attachments", - Query = _query + Query = _query, + Options = options } ); - string responseBody = await response.Raw.Content.ReadAsStringAsync(); - if (response.StatusCode >= 200 && response.StatusCode < 400) + var responseBody = await response.Raw.Content.ReadAsStringAsync(); + if (response.StatusCode is >= 200 and < 400) { - return JsonSerializer.Deserialize(responseBody); + try + { + return JsonUtils.Deserialize(responseBody)!; + } + catch (JsonException e) + { + throw new MergeException("Failed to deserialize response", e); + } } - throw new Exception(responseBody); + + throw new MergeApiException( + $"Error with status code {response.StatusCode}", + response.StatusCode, + JsonUtils.Deserialize(responseBody) + ); } /// /// Returns an `Attachment` object with the given `id`. /// - public async Task RetrieveAsync(string id, AttachmentsRetrieveRequest request) + public async Task RetrieveAsync( + string id, + AttachmentsRetrieveRequest request, + RequestOptions? options = null + ) { var _query = new Dictionary() { }; if (request.Expand != null) @@ -134,23 +178,41 @@ public async Task RetrieveAsync(string id, AttachmentsRetrieveReques var response = await _client.MakeRequestAsync( new RawClient.JsonApiRequest { + BaseUrl = _client.Options.BaseUrl, Method = HttpMethod.Get, Path = $"ticketing/v1/attachments/{id}", - Query = _query + Query = _query, + Options = options } ); - string responseBody = await response.Raw.Content.ReadAsStringAsync(); - if (response.StatusCode >= 200 && response.StatusCode < 400) + var responseBody = await response.Raw.Content.ReadAsStringAsync(); + if (response.StatusCode is >= 200 and < 400) { - return JsonSerializer.Deserialize(responseBody); + try + { + return JsonUtils.Deserialize(responseBody)!; + } + catch (JsonException e) + { + throw new MergeException("Failed to deserialize response", e); + } } - throw new Exception(responseBody); + + throw new MergeApiException( + $"Error with status code {response.StatusCode}", + response.StatusCode, + JsonUtils.Deserialize(responseBody) + ); } /// /// Returns the `File` content with the given `id` as a stream of bytes. /// - public async void DownloadRetrieveAsync(string id, AttachmentsDownloadRetrieveRequest request) + public async Task DownloadRetrieveAsync( + string id, + AttachmentsDownloadRetrieveRequest request, + RequestOptions? options = null + ) { var _query = new Dictionary() { }; if (request.MimeType != null) @@ -160,30 +222,52 @@ public async void DownloadRetrieveAsync(string id, AttachmentsDownloadRetrieveRe var response = await _client.MakeRequestAsync( new RawClient.JsonApiRequest { + BaseUrl = _client.Options.BaseUrl, Method = HttpMethod.Get, Path = $"ticketing/v1/attachments/{id}/download", - Query = _query + Query = _query, + Options = options } ); + var responseBody = await response.Raw.Content.ReadAsStringAsync(); + throw new MergeApiException( + $"Error with status code {response.StatusCode}", + response.StatusCode, + JsonUtils.Deserialize(responseBody) + ); } /// /// Returns metadata for `TicketingAttachment` POSTs. /// - public async Task MetaPostRetrieveAsync() + public async Task MetaPostRetrieveAsync(RequestOptions? options = null) { var response = await _client.MakeRequestAsync( new RawClient.JsonApiRequest { + BaseUrl = _client.Options.BaseUrl, Method = HttpMethod.Get, - Path = "ticketing/v1/attachments/meta/post" + Path = "ticketing/v1/attachments/meta/post", + Options = options } ); - string responseBody = await response.Raw.Content.ReadAsStringAsync(); - if (response.StatusCode >= 200 && response.StatusCode < 400) + var responseBody = await response.Raw.Content.ReadAsStringAsync(); + if (response.StatusCode is >= 200 and < 400) { - return JsonSerializer.Deserialize(responseBody); + try + { + return JsonUtils.Deserialize(responseBody)!; + } + catch (JsonException e) + { + throw new MergeException("Failed to deserialize response", e); + } } - throw new Exception(responseBody); + + throw new MergeApiException( + $"Error with status code {response.StatusCode}", + response.StatusCode, + JsonUtils.Deserialize(responseBody) + ); } } diff --git a/src/Merge.Client/Ticketing/Attachments/Requests/AttachmentsDownloadRetrieveRequest.cs b/src/Merge.Client/Ticketing/Attachments/Requests/AttachmentsDownloadRetrieveRequest.cs index aae8df8e..deefb1de 100644 --- a/src/Merge.Client/Ticketing/Attachments/Requests/AttachmentsDownloadRetrieveRequest.cs +++ b/src/Merge.Client/Ticketing/Attachments/Requests/AttachmentsDownloadRetrieveRequest.cs @@ -1,9 +1,9 @@ namespace Merge.Client.Ticketing; -public class AttachmentsDownloadRetrieveRequest +public record AttachmentsDownloadRetrieveRequest { /// /// If provided, specifies the export format of the file to be downloaded. For information on supported export formats, please refer to our export format help center article. /// - public string? MimeType { get; init; } + public string? MimeType { get; set; } } diff --git a/src/Merge.Client/Ticketing/Attachments/Requests/AttachmentsListRequest.cs b/src/Merge.Client/Ticketing/Attachments/Requests/AttachmentsListRequest.cs index 1f596019..534dc3ad 100644 --- a/src/Merge.Client/Ticketing/Attachments/Requests/AttachmentsListRequest.cs +++ b/src/Merge.Client/Ticketing/Attachments/Requests/AttachmentsListRequest.cs @@ -1,64 +1,64 @@ namespace Merge.Client.Ticketing; -public class AttachmentsListRequest +public record AttachmentsListRequest { /// /// If provided, will only return objects created after this datetime. /// - public DateTime? CreatedAfter { get; init; } + public DateTime? CreatedAfter { get; set; } /// /// If provided, will only return objects created before this datetime. /// - public DateTime? CreatedBefore { get; init; } + public DateTime? CreatedBefore { get; set; } /// /// The pagination cursor value. /// - public string? Cursor { get; init; } + public string? Cursor { get; set; } /// /// Which relations should be returned in expanded form. Multiple relation names should be comma separated without spaces. /// - public string? Expand { get; init; } + public string? Expand { get; set; } /// /// Whether to include data that was marked as deleted by third party webhooks. /// - public bool? IncludeDeletedData { get; init; } + public bool? IncludeDeletedData { get; set; } /// /// Whether to include the original data Merge fetched from the third-party to produce these models. /// - public bool? IncludeRemoteData { get; init; } + public bool? IncludeRemoteData { get; set; } /// /// If provided, only objects synced by Merge after this date time will be returned. /// - public DateTime? ModifiedAfter { get; init; } + public DateTime? ModifiedAfter { get; set; } /// /// If provided, only objects synced by Merge before this date time will be returned. /// - public DateTime? ModifiedBefore { get; init; } + public DateTime? ModifiedBefore { get; set; } /// /// Number of results to return per page. /// - public int? PageSize { get; init; } + public int? PageSize { get; set; } /// /// If provided, will only return attachments created in the third party platform after this datetime. /// - public DateTime? RemoteCreatedAfter { get; init; } + public DateTime? RemoteCreatedAfter { get; set; } /// /// The API provider's ID for the given object. /// - public string? RemoteId { get; init; } + public string? RemoteId { get; set; } /// /// If provided, will only return comments for this ticket. /// - public string? TicketId { get; init; } + public string? TicketId { get; set; } } diff --git a/src/Merge.Client/Ticketing/Attachments/Requests/AttachmentsRetrieveRequest.cs b/src/Merge.Client/Ticketing/Attachments/Requests/AttachmentsRetrieveRequest.cs index ba666767..2777bb97 100644 --- a/src/Merge.Client/Ticketing/Attachments/Requests/AttachmentsRetrieveRequest.cs +++ b/src/Merge.Client/Ticketing/Attachments/Requests/AttachmentsRetrieveRequest.cs @@ -1,14 +1,14 @@ namespace Merge.Client.Ticketing; -public class AttachmentsRetrieveRequest +public record AttachmentsRetrieveRequest { /// /// Which relations should be returned in expanded form. Multiple relation names should be comma separated without spaces. /// - public string? Expand { get; init; } + public string? Expand { get; set; } /// /// Whether to include the original data Merge fetched from the third-party to produce these models. /// - public bool? IncludeRemoteData { get; init; } + public bool? IncludeRemoteData { get; set; } } diff --git a/src/Merge.Client/Ticketing/Attachments/Requests/TicketingAttachmentEndpointRequest.cs b/src/Merge.Client/Ticketing/Attachments/Requests/TicketingAttachmentEndpointRequest.cs index f35dfd62..284616e7 100644 --- a/src/Merge.Client/Ticketing/Attachments/Requests/TicketingAttachmentEndpointRequest.cs +++ b/src/Merge.Client/Ticketing/Attachments/Requests/TicketingAttachmentEndpointRequest.cs @@ -1,20 +1,16 @@ -using Merge.Client.Ticketing; - -#nullable enable - namespace Merge.Client.Ticketing; -public class TicketingAttachmentEndpointRequest +public record TicketingAttachmentEndpointRequest { /// /// Whether to include debug fields (such as log file links) in the response. /// - public bool? IsDebugMode { get; init; } + public bool? IsDebugMode { get; set; } /// /// Whether or not third-party updates should be run asynchronously. /// - public bool? RunAsync { get; init; } + public bool? RunAsync { get; set; } - public AttachmentRequest Model { get; init; } + public required AttachmentRequest Model { get; set; } } diff --git a/src/Merge.Client/Ticketing/AuditTrail/AuditTrailClient.cs b/src/Merge.Client/Ticketing/AuditTrail/AuditTrailClient.cs index 8c8b17ab..5101b0b9 100644 --- a/src/Merge.Client/Ticketing/AuditTrail/AuditTrailClient.cs +++ b/src/Merge.Client/Ticketing/AuditTrail/AuditTrailClient.cs @@ -1,6 +1,6 @@ +using System.Net.Http; using System.Text.Json; -using Merge.Client; -using Merge.Client.Ticketing; +using Merge.Client.Core; #nullable enable @@ -18,7 +18,10 @@ public AuditTrailClient(RawClient client) /// /// Gets a list of audit trail events. /// - public async Task ListAsync(AuditTrailListRequest request) + public async Task ListAsync( + AuditTrailListRequest request, + RequestOptions? options = null + ) { var _query = new Dictionary() { }; if (request.Cursor != null) @@ -48,16 +51,30 @@ public async Task ListAsync(AuditTrailListRequest re var response = await _client.MakeRequestAsync( new RawClient.JsonApiRequest { + BaseUrl = _client.Options.BaseUrl, Method = HttpMethod.Get, Path = "ticketing/v1/audit-trail", - Query = _query + Query = _query, + Options = options } ); - string responseBody = await response.Raw.Content.ReadAsStringAsync(); - if (response.StatusCode >= 200 && response.StatusCode < 400) + var responseBody = await response.Raw.Content.ReadAsStringAsync(); + if (response.StatusCode is >= 200 and < 400) { - return JsonSerializer.Deserialize(responseBody); + try + { + return JsonUtils.Deserialize(responseBody)!; + } + catch (JsonException e) + { + throw new MergeException("Failed to deserialize response", e); + } } - throw new Exception(responseBody); + + throw new MergeApiException( + $"Error with status code {response.StatusCode}", + response.StatusCode, + JsonUtils.Deserialize(responseBody) + ); } } diff --git a/src/Merge.Client/Ticketing/AuditTrail/Requests/AuditTrailListRequest.cs b/src/Merge.Client/Ticketing/AuditTrail/Requests/AuditTrailListRequest.cs index 0d2d3fce..c4087def 100644 --- a/src/Merge.Client/Ticketing/AuditTrail/Requests/AuditTrailListRequest.cs +++ b/src/Merge.Client/Ticketing/AuditTrail/Requests/AuditTrailListRequest.cs @@ -1,34 +1,34 @@ namespace Merge.Client.Ticketing; -public class AuditTrailListRequest +public record AuditTrailListRequest { /// /// The pagination cursor value. /// - public string? Cursor { get; init; } + public string? Cursor { get; set; } /// /// If included, will only include audit trail events that occurred before this time /// - public string? EndDate { get; init; } + public string? EndDate { get; set; } /// /// If included, will only include events with the given event type. Possible values include: `CREATED_REMOTE_PRODUCTION_API_KEY`, `DELETED_REMOTE_PRODUCTION_API_KEY`, `CREATED_TEST_API_KEY`, `DELETED_TEST_API_KEY`, `REGENERATED_PRODUCTION_API_KEY`, `INVITED_USER`, `TWO_FACTOR_AUTH_ENABLED`, `TWO_FACTOR_AUTH_DISABLED`, `DELETED_LINKED_ACCOUNT`, `CREATED_DESTINATION`, `DELETED_DESTINATION`, `CHANGED_DESTINATION`, `CHANGED_SCOPES`, `CHANGED_PERSONAL_INFORMATION`, `CHANGED_ORGANIZATION_SETTINGS`, `ENABLED_INTEGRATION`, `DISABLED_INTEGRATION`, `ENABLED_CATEGORY`, `DISABLED_CATEGORY`, `CHANGED_PASSWORD`, `RESET_PASSWORD`, `ENABLED_REDACT_UNMAPPED_DATA_FOR_ORGANIZATION`, `ENABLED_REDACT_UNMAPPED_DATA_FOR_LINKED_ACCOUNT`, `DISABLED_REDACT_UNMAPPED_DATA_FOR_ORGANIZATION`, `DISABLED_REDACT_UNMAPPED_DATA_FOR_LINKED_ACCOUNT`, `CREATED_INTEGRATION_WIDE_FIELD_MAPPING`, `CREATED_LINKED_ACCOUNT_FIELD_MAPPING`, `CHANGED_INTEGRATION_WIDE_FIELD_MAPPING`, `CHANGED_LINKED_ACCOUNT_FIELD_MAPPING`, `DELETED_INTEGRATION_WIDE_FIELD_MAPPING`, `DELETED_LINKED_ACCOUNT_FIELD_MAPPING`, `FORCED_LINKED_ACCOUNT_RESYNC`, `MUTED_ISSUE`, `GENERATED_MAGIC_LINK`, `ENABLED_MERGE_WEBHOOK`, `DISABLED_MERGE_WEBHOOK`, `MERGE_WEBHOOK_TARGET_CHANGED`, `END_USER_CREDENTIALS_ACCESSED` /// - public string? EventType { get; init; } + public string? EventType { get; set; } /// /// Number of results to return per page. /// - public int? PageSize { get; init; } + public int? PageSize { get; set; } /// /// If included, will only include audit trail events that occurred after this time /// - public string? StartDate { get; init; } + public string? StartDate { get; set; } /// /// If provided, this will return events associated with the specified user email. Please note that the email address reflects the user's email at the time of the event, and may not be their current email. /// - public string? UserEmail { get; init; } + public string? UserEmail { get; set; } } diff --git a/src/Merge.Client/Ticketing/AvailableActions/AvailableActionsClient.cs b/src/Merge.Client/Ticketing/AvailableActions/AvailableActionsClient.cs index 4e83c87a..73bb0c60 100644 --- a/src/Merge.Client/Ticketing/AvailableActions/AvailableActionsClient.cs +++ b/src/Merge.Client/Ticketing/AvailableActions/AvailableActionsClient.cs @@ -1,6 +1,6 @@ +using System.Net.Http; using System.Text.Json; -using Merge.Client; -using Merge.Client.Ticketing; +using Merge.Client.Core; #nullable enable @@ -18,20 +18,34 @@ public AvailableActionsClient(RawClient client) /// /// Returns a list of models and actions available for an account. /// - public async Task RetrieveAsync() + public async Task RetrieveAsync(RequestOptions? options = null) { var response = await _client.MakeRequestAsync( new RawClient.JsonApiRequest { + BaseUrl = _client.Options.BaseUrl, Method = HttpMethod.Get, - Path = "ticketing/v1/available-actions" + Path = "ticketing/v1/available-actions", + Options = options } ); - string responseBody = await response.Raw.Content.ReadAsStringAsync(); - if (response.StatusCode >= 200 && response.StatusCode < 400) + var responseBody = await response.Raw.Content.ReadAsStringAsync(); + if (response.StatusCode is >= 200 and < 400) { - return JsonSerializer.Deserialize(responseBody); + try + { + return JsonUtils.Deserialize(responseBody)!; + } + catch (JsonException e) + { + throw new MergeException("Failed to deserialize response", e); + } } - throw new Exception(responseBody); + + throw new MergeApiException( + $"Error with status code {response.StatusCode}", + response.StatusCode, + JsonUtils.Deserialize(responseBody) + ); } } diff --git a/src/Merge.Client/Ticketing/Collections/CollectionsClient.cs b/src/Merge.Client/Ticketing/Collections/CollectionsClient.cs index 1e6e3e25..8df765e9 100644 --- a/src/Merge.Client/Ticketing/Collections/CollectionsClient.cs +++ b/src/Merge.Client/Ticketing/Collections/CollectionsClient.cs @@ -1,6 +1,6 @@ +using System.Net.Http; using System.Text.Json; -using Merge.Client; -using Merge.Client.Ticketing; +using Merge.Client.Core; #nullable enable @@ -18,7 +18,10 @@ public CollectionsClient(RawClient client) /// /// Returns a list of `Collection` objects. /// - public async Task ListAsync(CollectionsListRequest request) + public async Task ListAsync( + CollectionsListRequest request, + RequestOptions? options = null + ) { var _query = new Dictionary() { }; if (request.CollectionType != null) @@ -27,11 +30,13 @@ public async Task ListAsync(CollectionsListRequest requ } if (request.CreatedAfter != null) { - _query["created_after"] = request.CreatedAfter.Value.ToString("o0"); + _query["created_after"] = request.CreatedAfter.Value.ToString(Constants.DateTimeFormat); } if (request.CreatedBefore != null) { - _query["created_before"] = request.CreatedBefore.Value.ToString("o0"); + _query["created_before"] = request.CreatedBefore.Value.ToString( + Constants.DateTimeFormat + ); } if (request.Cursor != null) { @@ -51,11 +56,15 @@ public async Task ListAsync(CollectionsListRequest requ } if (request.ModifiedAfter != null) { - _query["modified_after"] = request.ModifiedAfter.Value.ToString("o0"); + _query["modified_after"] = request.ModifiedAfter.Value.ToString( + Constants.DateTimeFormat + ); } if (request.ModifiedBefore != null) { - _query["modified_before"] = request.ModifiedBefore.Value.ToString("o0"); + _query["modified_before"] = request.ModifiedBefore.Value.ToString( + Constants.DateTimeFormat + ); } if (request.PageSize != null) { @@ -80,23 +89,41 @@ public async Task ListAsync(CollectionsListRequest requ var response = await _client.MakeRequestAsync( new RawClient.JsonApiRequest { + BaseUrl = _client.Options.BaseUrl, Method = HttpMethod.Get, Path = "ticketing/v1/collections", - Query = _query + Query = _query, + Options = options } ); - string responseBody = await response.Raw.Content.ReadAsStringAsync(); - if (response.StatusCode >= 200 && response.StatusCode < 400) + var responseBody = await response.Raw.Content.ReadAsStringAsync(); + if (response.StatusCode is >= 200 and < 400) { - return JsonSerializer.Deserialize(responseBody); + try + { + return JsonUtils.Deserialize(responseBody)!; + } + catch (JsonException e) + { + throw new MergeException("Failed to deserialize response", e); + } } - throw new Exception(responseBody); + + throw new MergeApiException( + $"Error with status code {response.StatusCode}", + response.StatusCode, + JsonUtils.Deserialize(responseBody) + ); } /// /// Returns a `Collection` object with the given `id`. /// - public async Task RetrieveAsync(string id, CollectionsRetrieveRequest request) + public async Task RetrieveAsync( + string id, + CollectionsRetrieveRequest request, + RequestOptions? options = null + ) { var _query = new Dictionary() { }; if (request.Expand != null) @@ -118,17 +145,31 @@ public async Task RetrieveAsync(string id, CollectionsRetrieveReques var response = await _client.MakeRequestAsync( new RawClient.JsonApiRequest { + BaseUrl = _client.Options.BaseUrl, Method = HttpMethod.Get, Path = $"ticketing/v1/collections/{id}", - Query = _query + Query = _query, + Options = options } ); - string responseBody = await response.Raw.Content.ReadAsStringAsync(); - if (response.StatusCode >= 200 && response.StatusCode < 400) + var responseBody = await response.Raw.Content.ReadAsStringAsync(); + if (response.StatusCode is >= 200 and < 400) { - return JsonSerializer.Deserialize(responseBody); + try + { + return JsonUtils.Deserialize(responseBody)!; + } + catch (JsonException e) + { + throw new MergeException("Failed to deserialize response", e); + } } - throw new Exception(responseBody); + + throw new MergeApiException( + $"Error with status code {response.StatusCode}", + response.StatusCode, + JsonUtils.Deserialize(responseBody) + ); } /// @@ -136,7 +177,8 @@ public async Task RetrieveAsync(string id, CollectionsRetrieveReques /// public async Task UsersListAsync( string parentId, - CollectionsUsersListRequest request + CollectionsUsersListRequest request, + RequestOptions? options = null ) { var _query = new Dictionary() { }; @@ -163,16 +205,30 @@ CollectionsUsersListRequest request var response = await _client.MakeRequestAsync( new RawClient.JsonApiRequest { + BaseUrl = _client.Options.BaseUrl, Method = HttpMethod.Get, Path = $"ticketing/v1/collections/{parentId}/users", - Query = _query + Query = _query, + Options = options } ); - string responseBody = await response.Raw.Content.ReadAsStringAsync(); - if (response.StatusCode >= 200 && response.StatusCode < 400) + var responseBody = await response.Raw.Content.ReadAsStringAsync(); + if (response.StatusCode is >= 200 and < 400) { - return JsonSerializer.Deserialize(responseBody); + try + { + return JsonUtils.Deserialize(responseBody)!; + } + catch (JsonException e) + { + throw new MergeException("Failed to deserialize response", e); + } } - throw new Exception(responseBody); + + throw new MergeApiException( + $"Error with status code {response.StatusCode}", + response.StatusCode, + JsonUtils.Deserialize(responseBody) + ); } } diff --git a/src/Merge.Client/Ticketing/Collections/Requests/CollectionsListRequest.cs b/src/Merge.Client/Ticketing/Collections/Requests/CollectionsListRequest.cs index 42e46e1b..ec690b3a 100644 --- a/src/Merge.Client/Ticketing/Collections/Requests/CollectionsListRequest.cs +++ b/src/Merge.Client/Ticketing/Collections/Requests/CollectionsListRequest.cs @@ -1,74 +1,74 @@ namespace Merge.Client.Ticketing; -public class CollectionsListRequest +public record CollectionsListRequest { /// /// If provided, will only return collections of the given type. /// - public string? CollectionType { get; init; } + public string? CollectionType { get; set; } /// /// If provided, will only return objects created after this datetime. /// - public DateTime? CreatedAfter { get; init; } + public DateTime? CreatedAfter { get; set; } /// /// If provided, will only return objects created before this datetime. /// - public DateTime? CreatedBefore { get; init; } + public DateTime? CreatedBefore { get; set; } /// /// The pagination cursor value. /// - public string? Cursor { get; init; } + public string? Cursor { get; set; } /// /// Which relations should be returned in expanded form. Multiple relation names should be comma separated without spaces. /// - public string? Expand { get; init; } + public string? Expand { get; set; } /// /// Whether to include data that was marked as deleted by third party webhooks. /// - public bool? IncludeDeletedData { get; init; } + public bool? IncludeDeletedData { get; set; } /// /// Whether to include the original data Merge fetched from the third-party to produce these models. /// - public bool? IncludeRemoteData { get; init; } + public bool? IncludeRemoteData { get; set; } /// /// If provided, only objects synced by Merge after this date time will be returned. /// - public DateTime? ModifiedAfter { get; init; } + public DateTime? ModifiedAfter { get; set; } /// /// If provided, only objects synced by Merge before this date time will be returned. /// - public DateTime? ModifiedBefore { get; init; } + public DateTime? ModifiedBefore { get; set; } /// /// Number of results to return per page. /// - public int? PageSize { get; init; } + public int? PageSize { get; set; } /// /// If provided, will only return collections whose parent collection matches the given id. /// - public string? ParentCollectionId { get; init; } + public string? ParentCollectionId { get; set; } /// /// Deprecated. Use show_enum_origins. /// - public string? RemoteFields { get; init; } + public string? RemoteFields { get; set; } /// /// The API provider's ID for the given object. /// - public string? RemoteId { get; init; } + public string? RemoteId { get; set; } /// /// A comma separated list of enum field names for which you'd like the original values to be returned, instead of Merge's normalized enum values. [Learn more](https://help.merge.dev/en/articles/8950958-show_enum_origins-query-parameter) /// - public string? ShowEnumOrigins { get; init; } + public string? ShowEnumOrigins { get; set; } } diff --git a/src/Merge.Client/Ticketing/Collections/Requests/CollectionsRetrieveRequest.cs b/src/Merge.Client/Ticketing/Collections/Requests/CollectionsRetrieveRequest.cs index e706c385..132cfbc0 100644 --- a/src/Merge.Client/Ticketing/Collections/Requests/CollectionsRetrieveRequest.cs +++ b/src/Merge.Client/Ticketing/Collections/Requests/CollectionsRetrieveRequest.cs @@ -1,24 +1,24 @@ namespace Merge.Client.Ticketing; -public class CollectionsRetrieveRequest +public record CollectionsRetrieveRequest { /// /// Which relations should be returned in expanded form. Multiple relation names should be comma separated without spaces. /// - public string? Expand { get; init; } + public string? Expand { get; set; } /// /// Whether to include the original data Merge fetched from the third-party to produce these models. /// - public bool? IncludeRemoteData { get; init; } + public bool? IncludeRemoteData { get; set; } /// /// Deprecated. Use show_enum_origins. /// - public string? RemoteFields { get; init; } + public string? RemoteFields { get; set; } /// /// A comma separated list of enum field names for which you'd like the original values to be returned, instead of Merge's normalized enum values. [Learn more](https://help.merge.dev/en/articles/8950958-show_enum_origins-query-parameter) /// - public string? ShowEnumOrigins { get; init; } + public string? ShowEnumOrigins { get; set; } } diff --git a/src/Merge.Client/Ticketing/Collections/Requests/CollectionsUsersListRequest.cs b/src/Merge.Client/Ticketing/Collections/Requests/CollectionsUsersListRequest.cs index 8573dd3d..0a593cbc 100644 --- a/src/Merge.Client/Ticketing/Collections/Requests/CollectionsUsersListRequest.cs +++ b/src/Merge.Client/Ticketing/Collections/Requests/CollectionsUsersListRequest.cs @@ -1,33 +1,29 @@ -using Merge.Client.Ticketing; - -#nullable enable - namespace Merge.Client.Ticketing; -public class CollectionsUsersListRequest +public record CollectionsUsersListRequest { /// /// The pagination cursor value. /// - public string? Cursor { get; init; } + public string? Cursor { get; set; } /// /// Which relations should be returned in expanded form. Multiple relation names should be comma separated without spaces. /// - public CollectionsUsersListRequestExpand? Expand { get; init; } + public CollectionsUsersListRequestExpand? Expand { get; set; } /// /// Whether to include data that was marked as deleted by third party webhooks. /// - public bool? IncludeDeletedData { get; init; } + public bool? IncludeDeletedData { get; set; } /// /// Whether to include the original data Merge fetched from the third-party to produce these models. /// - public bool? IncludeRemoteData { get; init; } + public bool? IncludeRemoteData { get; set; } /// /// Number of results to return per page. /// - public int? PageSize { get; init; } + public int? PageSize { get; set; } } diff --git a/src/Merge.Client/Ticketing/Collections/Types/CollectionsUsersListRequestExpand.cs b/src/Merge.Client/Ticketing/Collections/Types/CollectionsUsersListRequestExpand.cs index 54bf16b6..b4560665 100644 --- a/src/Merge.Client/Ticketing/Collections/Types/CollectionsUsersListRequestExpand.cs +++ b/src/Merge.Client/Ticketing/Collections/Types/CollectionsUsersListRequestExpand.cs @@ -1,7 +1,6 @@ using System.Runtime.Serialization; using System.Text.Json.Serialization; using Merge.Client.Core; -using Merge.Client.Ticketing; #nullable enable diff --git a/src/Merge.Client/Ticketing/Comments/CommentsClient.cs b/src/Merge.Client/Ticketing/Comments/CommentsClient.cs index d353ca2a..17dfb339 100644 --- a/src/Merge.Client/Ticketing/Comments/CommentsClient.cs +++ b/src/Merge.Client/Ticketing/Comments/CommentsClient.cs @@ -1,6 +1,6 @@ +using System.Net.Http; using System.Text.Json; -using Merge.Client; -using Merge.Client.Ticketing; +using Merge.Client.Core; #nullable enable @@ -18,16 +18,21 @@ public CommentsClient(RawClient client) /// /// Returns a list of `Comment` objects. /// - public async Task ListAsync(CommentsListRequest request) + public async Task ListAsync( + CommentsListRequest request, + RequestOptions? options = null + ) { var _query = new Dictionary() { }; if (request.CreatedAfter != null) { - _query["created_after"] = request.CreatedAfter.Value.ToString("o0"); + _query["created_after"] = request.CreatedAfter.Value.ToString(Constants.DateTimeFormat); } if (request.CreatedBefore != null) { - _query["created_before"] = request.CreatedBefore.Value.ToString("o0"); + _query["created_before"] = request.CreatedBefore.Value.ToString( + Constants.DateTimeFormat + ); } if (request.Cursor != null) { @@ -47,11 +52,15 @@ public async Task ListAsync(CommentsListRequest request) } if (request.ModifiedAfter != null) { - _query["modified_after"] = request.ModifiedAfter.Value.ToString("o0"); + _query["modified_after"] = request.ModifiedAfter.Value.ToString( + Constants.DateTimeFormat + ); } if (request.ModifiedBefore != null) { - _query["modified_before"] = request.ModifiedBefore.Value.ToString("o0"); + _query["modified_before"] = request.ModifiedBefore.Value.ToString( + Constants.DateTimeFormat + ); } if (request.PageSize != null) { @@ -59,7 +68,9 @@ public async Task ListAsync(CommentsListRequest request) } if (request.RemoteCreatedAfter != null) { - _query["remote_created_after"] = request.RemoteCreatedAfter.Value.ToString("o0"); + _query["remote_created_after"] = request.RemoteCreatedAfter.Value.ToString( + Constants.DateTimeFormat + ); } if (request.RemoteId != null) { @@ -72,23 +83,40 @@ public async Task ListAsync(CommentsListRequest request) var response = await _client.MakeRequestAsync( new RawClient.JsonApiRequest { + BaseUrl = _client.Options.BaseUrl, Method = HttpMethod.Get, Path = "ticketing/v1/comments", - Query = _query + Query = _query, + Options = options } ); - string responseBody = await response.Raw.Content.ReadAsStringAsync(); - if (response.StatusCode >= 200 && response.StatusCode < 400) + var responseBody = await response.Raw.Content.ReadAsStringAsync(); + if (response.StatusCode is >= 200 and < 400) { - return JsonSerializer.Deserialize(responseBody); + try + { + return JsonUtils.Deserialize(responseBody)!; + } + catch (JsonException e) + { + throw new MergeException("Failed to deserialize response", e); + } } - throw new Exception(responseBody); + + throw new MergeApiException( + $"Error with status code {response.StatusCode}", + response.StatusCode, + JsonUtils.Deserialize(responseBody) + ); } /// /// Creates a `Comment` object with the given values. /// - public async Task CreateAsync(CommentEndpointRequest request) + public async Task CreateAsync( + CommentEndpointRequest request, + RequestOptions? options = null + ) { var _query = new Dictionary() { }; if (request.IsDebugMode != null) @@ -102,23 +130,41 @@ public async Task CreateAsync(CommentEndpointRequest request) var response = await _client.MakeRequestAsync( new RawClient.JsonApiRequest { + BaseUrl = _client.Options.BaseUrl, Method = HttpMethod.Post, Path = "ticketing/v1/comments", - Query = _query + Query = _query, + Options = options } ); - string responseBody = await response.Raw.Content.ReadAsStringAsync(); - if (response.StatusCode >= 200 && response.StatusCode < 400) + var responseBody = await response.Raw.Content.ReadAsStringAsync(); + if (response.StatusCode is >= 200 and < 400) { - return JsonSerializer.Deserialize(responseBody); + try + { + return JsonUtils.Deserialize(responseBody)!; + } + catch (JsonException e) + { + throw new MergeException("Failed to deserialize response", e); + } } - throw new Exception(responseBody); + + throw new MergeApiException( + $"Error with status code {response.StatusCode}", + response.StatusCode, + JsonUtils.Deserialize(responseBody) + ); } /// /// Returns a `Comment` object with the given `id`. /// - public async Task RetrieveAsync(string id, CommentsRetrieveRequest request) + public async Task RetrieveAsync( + string id, + CommentsRetrieveRequest request, + RequestOptions? options = null + ) { var _query = new Dictionary() { }; if (request.Expand != null) @@ -132,36 +178,64 @@ public async Task RetrieveAsync(string id, CommentsRetrieveRequest requ var response = await _client.MakeRequestAsync( new RawClient.JsonApiRequest { + BaseUrl = _client.Options.BaseUrl, Method = HttpMethod.Get, Path = $"ticketing/v1/comments/{id}", - Query = _query + Query = _query, + Options = options } ); - string responseBody = await response.Raw.Content.ReadAsStringAsync(); - if (response.StatusCode >= 200 && response.StatusCode < 400) + var responseBody = await response.Raw.Content.ReadAsStringAsync(); + if (response.StatusCode is >= 200 and < 400) { - return JsonSerializer.Deserialize(responseBody); + try + { + return JsonUtils.Deserialize(responseBody)!; + } + catch (JsonException e) + { + throw new MergeException("Failed to deserialize response", e); + } } - throw new Exception(responseBody); + + throw new MergeApiException( + $"Error with status code {response.StatusCode}", + response.StatusCode, + JsonUtils.Deserialize(responseBody) + ); } /// /// Returns metadata for `Comment` POSTs. /// - public async Task MetaPostRetrieveAsync() + public async Task MetaPostRetrieveAsync(RequestOptions? options = null) { var response = await _client.MakeRequestAsync( new RawClient.JsonApiRequest { + BaseUrl = _client.Options.BaseUrl, Method = HttpMethod.Get, - Path = "ticketing/v1/comments/meta/post" + Path = "ticketing/v1/comments/meta/post", + Options = options } ); - string responseBody = await response.Raw.Content.ReadAsStringAsync(); - if (response.StatusCode >= 200 && response.StatusCode < 400) + var responseBody = await response.Raw.Content.ReadAsStringAsync(); + if (response.StatusCode is >= 200 and < 400) { - return JsonSerializer.Deserialize(responseBody); + try + { + return JsonUtils.Deserialize(responseBody)!; + } + catch (JsonException e) + { + throw new MergeException("Failed to deserialize response", e); + } } - throw new Exception(responseBody); + + throw new MergeApiException( + $"Error with status code {response.StatusCode}", + response.StatusCode, + JsonUtils.Deserialize(responseBody) + ); } } diff --git a/src/Merge.Client/Ticketing/Comments/Requests/CommentEndpointRequest.cs b/src/Merge.Client/Ticketing/Comments/Requests/CommentEndpointRequest.cs index 1d4875c7..8a9ff8ec 100644 --- a/src/Merge.Client/Ticketing/Comments/Requests/CommentEndpointRequest.cs +++ b/src/Merge.Client/Ticketing/Comments/Requests/CommentEndpointRequest.cs @@ -1,20 +1,16 @@ -using Merge.Client.Ticketing; - -#nullable enable - namespace Merge.Client.Ticketing; -public class CommentEndpointRequest +public record CommentEndpointRequest { /// /// Whether to include debug fields (such as log file links) in the response. /// - public bool? IsDebugMode { get; init; } + public bool? IsDebugMode { get; set; } /// /// Whether or not third-party updates should be run asynchronously. /// - public bool? RunAsync { get; init; } + public bool? RunAsync { get; set; } - public CommentRequest Model { get; init; } + public required CommentRequest Model { get; set; } } diff --git a/src/Merge.Client/Ticketing/Comments/Requests/CommentsListRequest.cs b/src/Merge.Client/Ticketing/Comments/Requests/CommentsListRequest.cs index 2d6bfd81..cc90874e 100644 --- a/src/Merge.Client/Ticketing/Comments/Requests/CommentsListRequest.cs +++ b/src/Merge.Client/Ticketing/Comments/Requests/CommentsListRequest.cs @@ -1,68 +1,64 @@ -using Merge.Client.Ticketing; - -#nullable enable - namespace Merge.Client.Ticketing; -public class CommentsListRequest +public record CommentsListRequest { /// /// If provided, will only return objects created after this datetime. /// - public DateTime? CreatedAfter { get; init; } + public DateTime? CreatedAfter { get; set; } /// /// If provided, will only return objects created before this datetime. /// - public DateTime? CreatedBefore { get; init; } + public DateTime? CreatedBefore { get; set; } /// /// The pagination cursor value. /// - public string? Cursor { get; init; } + public string? Cursor { get; set; } /// /// Which relations should be returned in expanded form. Multiple relation names should be comma separated without spaces. /// - public CommentsListRequestExpand? Expand { get; init; } + public CommentsListRequestExpand? Expand { get; set; } /// /// Whether to include data that was marked as deleted by third party webhooks. /// - public bool? IncludeDeletedData { get; init; } + public bool? IncludeDeletedData { get; set; } /// /// Whether to include the original data Merge fetched from the third-party to produce these models. /// - public bool? IncludeRemoteData { get; init; } + public bool? IncludeRemoteData { get; set; } /// /// If provided, only objects synced by Merge after this date time will be returned. /// - public DateTime? ModifiedAfter { get; init; } + public DateTime? ModifiedAfter { get; set; } /// /// If provided, only objects synced by Merge before this date time will be returned. /// - public DateTime? ModifiedBefore { get; init; } + public DateTime? ModifiedBefore { get; set; } /// /// Number of results to return per page. /// - public int? PageSize { get; init; } + public int? PageSize { get; set; } /// /// If provided, will only return Comments created in the third party platform after this datetime. /// - public DateTime? RemoteCreatedAfter { get; init; } + public DateTime? RemoteCreatedAfter { get; set; } /// /// The API provider's ID for the given object. /// - public string? RemoteId { get; init; } + public string? RemoteId { get; set; } /// /// If provided, will only return comments for this ticket. /// - public string? TicketId { get; init; } + public string? TicketId { get; set; } } diff --git a/src/Merge.Client/Ticketing/Comments/Requests/CommentsRetrieveRequest.cs b/src/Merge.Client/Ticketing/Comments/Requests/CommentsRetrieveRequest.cs index ed6ae163..7c66ed2b 100644 --- a/src/Merge.Client/Ticketing/Comments/Requests/CommentsRetrieveRequest.cs +++ b/src/Merge.Client/Ticketing/Comments/Requests/CommentsRetrieveRequest.cs @@ -1,18 +1,14 @@ -using Merge.Client.Ticketing; - -#nullable enable - namespace Merge.Client.Ticketing; -public class CommentsRetrieveRequest +public record CommentsRetrieveRequest { /// /// Which relations should be returned in expanded form. Multiple relation names should be comma separated without spaces. /// - public CommentsRetrieveRequestExpand? Expand { get; init; } + public CommentsRetrieveRequestExpand? Expand { get; set; } /// /// Whether to include the original data Merge fetched from the third-party to produce these models. /// - public bool? IncludeRemoteData { get; init; } + public bool? IncludeRemoteData { get; set; } } diff --git a/src/Merge.Client/Ticketing/Comments/Types/CommentsListRequestExpand.cs b/src/Merge.Client/Ticketing/Comments/Types/CommentsListRequestExpand.cs index 76009843..ad45ed4e 100644 --- a/src/Merge.Client/Ticketing/Comments/Types/CommentsListRequestExpand.cs +++ b/src/Merge.Client/Ticketing/Comments/Types/CommentsListRequestExpand.cs @@ -1,7 +1,6 @@ using System.Runtime.Serialization; using System.Text.Json.Serialization; using Merge.Client.Core; -using Merge.Client.Ticketing; #nullable enable diff --git a/src/Merge.Client/Ticketing/Comments/Types/CommentsRetrieveRequestExpand.cs b/src/Merge.Client/Ticketing/Comments/Types/CommentsRetrieveRequestExpand.cs index d52e4c78..4a689e41 100644 --- a/src/Merge.Client/Ticketing/Comments/Types/CommentsRetrieveRequestExpand.cs +++ b/src/Merge.Client/Ticketing/Comments/Types/CommentsRetrieveRequestExpand.cs @@ -1,7 +1,6 @@ using System.Runtime.Serialization; using System.Text.Json.Serialization; using Merge.Client.Core; -using Merge.Client.Ticketing; #nullable enable diff --git a/src/Merge.Client/Ticketing/Contacts/ContactsClient.cs b/src/Merge.Client/Ticketing/Contacts/ContactsClient.cs index e810c466..4bb5a102 100644 --- a/src/Merge.Client/Ticketing/Contacts/ContactsClient.cs +++ b/src/Merge.Client/Ticketing/Contacts/ContactsClient.cs @@ -1,6 +1,6 @@ +using System.Net.Http; using System.Text.Json; -using Merge.Client; -using Merge.Client.Ticketing; +using Merge.Client.Core; #nullable enable @@ -18,16 +18,21 @@ public ContactsClient(RawClient client) /// /// Returns a list of `Contact` objects. /// - public async Task ListAsync(ContactsListRequest request) + public async Task ListAsync( + ContactsListRequest request, + RequestOptions? options = null + ) { var _query = new Dictionary() { }; if (request.CreatedAfter != null) { - _query["created_after"] = request.CreatedAfter.Value.ToString("o0"); + _query["created_after"] = request.CreatedAfter.Value.ToString(Constants.DateTimeFormat); } if (request.CreatedBefore != null) { - _query["created_before"] = request.CreatedBefore.Value.ToString("o0"); + _query["created_before"] = request.CreatedBefore.Value.ToString( + Constants.DateTimeFormat + ); } if (request.Cursor != null) { @@ -47,11 +52,15 @@ public async Task ListAsync(ContactsListRequest request) } if (request.ModifiedAfter != null) { - _query["modified_after"] = request.ModifiedAfter.Value.ToString("o0"); + _query["modified_after"] = request.ModifiedAfter.Value.ToString( + Constants.DateTimeFormat + ); } if (request.ModifiedBefore != null) { - _query["modified_before"] = request.ModifiedBefore.Value.ToString("o0"); + _query["modified_before"] = request.ModifiedBefore.Value.ToString( + Constants.DateTimeFormat + ); } if (request.PageSize != null) { @@ -64,23 +73,40 @@ public async Task ListAsync(ContactsListRequest request) var response = await _client.MakeRequestAsync( new RawClient.JsonApiRequest { + BaseUrl = _client.Options.BaseUrl, Method = HttpMethod.Get, Path = "ticketing/v1/contacts", - Query = _query + Query = _query, + Options = options } ); - string responseBody = await response.Raw.Content.ReadAsStringAsync(); - if (response.StatusCode >= 200 && response.StatusCode < 400) + var responseBody = await response.Raw.Content.ReadAsStringAsync(); + if (response.StatusCode is >= 200 and < 400) { - return JsonSerializer.Deserialize(responseBody); + try + { + return JsonUtils.Deserialize(responseBody)!; + } + catch (JsonException e) + { + throw new MergeException("Failed to deserialize response", e); + } } - throw new Exception(responseBody); + + throw new MergeApiException( + $"Error with status code {response.StatusCode}", + response.StatusCode, + JsonUtils.Deserialize(responseBody) + ); } /// /// Creates a `Contact` object with the given values. /// - public async Task CreateAsync(TicketingContactEndpointRequest request) + public async Task CreateAsync( + TicketingContactEndpointRequest request, + RequestOptions? options = null + ) { var _query = new Dictionary() { }; if (request.IsDebugMode != null) @@ -94,23 +120,41 @@ public async Task CreateAsync(TicketingContactEndpoint var response = await _client.MakeRequestAsync( new RawClient.JsonApiRequest { + BaseUrl = _client.Options.BaseUrl, Method = HttpMethod.Post, Path = "ticketing/v1/contacts", - Query = _query + Query = _query, + Options = options } ); - string responseBody = await response.Raw.Content.ReadAsStringAsync(); - if (response.StatusCode >= 200 && response.StatusCode < 400) + var responseBody = await response.Raw.Content.ReadAsStringAsync(); + if (response.StatusCode is >= 200 and < 400) { - return JsonSerializer.Deserialize(responseBody); + try + { + return JsonUtils.Deserialize(responseBody)!; + } + catch (JsonException e) + { + throw new MergeException("Failed to deserialize response", e); + } } - throw new Exception(responseBody); + + throw new MergeApiException( + $"Error with status code {response.StatusCode}", + response.StatusCode, + JsonUtils.Deserialize(responseBody) + ); } /// /// Returns a `Contact` object with the given `id`. /// - public async Task RetrieveAsync(string id, ContactsRetrieveRequest request) + public async Task RetrieveAsync( + string id, + ContactsRetrieveRequest request, + RequestOptions? options = null + ) { var _query = new Dictionary() { }; if (request.Expand != null) @@ -124,36 +168,64 @@ public async Task RetrieveAsync(string id, ContactsRetrieveRequest requ var response = await _client.MakeRequestAsync( new RawClient.JsonApiRequest { + BaseUrl = _client.Options.BaseUrl, Method = HttpMethod.Get, Path = $"ticketing/v1/contacts/{id}", - Query = _query + Query = _query, + Options = options } ); - string responseBody = await response.Raw.Content.ReadAsStringAsync(); - if (response.StatusCode >= 200 && response.StatusCode < 400) + var responseBody = await response.Raw.Content.ReadAsStringAsync(); + if (response.StatusCode is >= 200 and < 400) { - return JsonSerializer.Deserialize(responseBody); + try + { + return JsonUtils.Deserialize(responseBody)!; + } + catch (JsonException e) + { + throw new MergeException("Failed to deserialize response", e); + } } - throw new Exception(responseBody); + + throw new MergeApiException( + $"Error with status code {response.StatusCode}", + response.StatusCode, + JsonUtils.Deserialize(responseBody) + ); } /// /// Returns metadata for `TicketingContact` POSTs. /// - public async Task MetaPostRetrieveAsync() + public async Task MetaPostRetrieveAsync(RequestOptions? options = null) { var response = await _client.MakeRequestAsync( new RawClient.JsonApiRequest { + BaseUrl = _client.Options.BaseUrl, Method = HttpMethod.Get, - Path = "ticketing/v1/contacts/meta/post" + Path = "ticketing/v1/contacts/meta/post", + Options = options } ); - string responseBody = await response.Raw.Content.ReadAsStringAsync(); - if (response.StatusCode >= 200 && response.StatusCode < 400) + var responseBody = await response.Raw.Content.ReadAsStringAsync(); + if (response.StatusCode is >= 200 and < 400) { - return JsonSerializer.Deserialize(responseBody); + try + { + return JsonUtils.Deserialize(responseBody)!; + } + catch (JsonException e) + { + throw new MergeException("Failed to deserialize response", e); + } } - throw new Exception(responseBody); + + throw new MergeApiException( + $"Error with status code {response.StatusCode}", + response.StatusCode, + JsonUtils.Deserialize(responseBody) + ); } } diff --git a/src/Merge.Client/Ticketing/Contacts/Requests/ContactsListRequest.cs b/src/Merge.Client/Ticketing/Contacts/Requests/ContactsListRequest.cs index 3cc2dadc..1643e5e2 100644 --- a/src/Merge.Client/Ticketing/Contacts/Requests/ContactsListRequest.cs +++ b/src/Merge.Client/Ticketing/Contacts/Requests/ContactsListRequest.cs @@ -1,54 +1,54 @@ namespace Merge.Client.Ticketing; -public class ContactsListRequest +public record ContactsListRequest { /// /// If provided, will only return objects created after this datetime. /// - public DateTime? CreatedAfter { get; init; } + public DateTime? CreatedAfter { get; set; } /// /// If provided, will only return objects created before this datetime. /// - public DateTime? CreatedBefore { get; init; } + public DateTime? CreatedBefore { get; set; } /// /// The pagination cursor value. /// - public string? Cursor { get; init; } + public string? Cursor { get; set; } /// /// Which relations should be returned in expanded form. Multiple relation names should be comma separated without spaces. /// - public string? Expand { get; init; } + public string? Expand { get; set; } /// /// Whether to include data that was marked as deleted by third party webhooks. /// - public bool? IncludeDeletedData { get; init; } + public bool? IncludeDeletedData { get; set; } /// /// Whether to include the original data Merge fetched from the third-party to produce these models. /// - public bool? IncludeRemoteData { get; init; } + public bool? IncludeRemoteData { get; set; } /// /// If provided, only objects synced by Merge after this date time will be returned. /// - public DateTime? ModifiedAfter { get; init; } + public DateTime? ModifiedAfter { get; set; } /// /// If provided, only objects synced by Merge before this date time will be returned. /// - public DateTime? ModifiedBefore { get; init; } + public DateTime? ModifiedBefore { get; set; } /// /// Number of results to return per page. /// - public int? PageSize { get; init; } + public int? PageSize { get; set; } /// /// The API provider's ID for the given object. /// - public string? RemoteId { get; init; } + public string? RemoteId { get; set; } } diff --git a/src/Merge.Client/Ticketing/Contacts/Requests/ContactsRetrieveRequest.cs b/src/Merge.Client/Ticketing/Contacts/Requests/ContactsRetrieveRequest.cs index c7990768..d069d1fa 100644 --- a/src/Merge.Client/Ticketing/Contacts/Requests/ContactsRetrieveRequest.cs +++ b/src/Merge.Client/Ticketing/Contacts/Requests/ContactsRetrieveRequest.cs @@ -1,14 +1,14 @@ namespace Merge.Client.Ticketing; -public class ContactsRetrieveRequest +public record ContactsRetrieveRequest { /// /// Which relations should be returned in expanded form. Multiple relation names should be comma separated without spaces. /// - public string? Expand { get; init; } + public string? Expand { get; set; } /// /// Whether to include the original data Merge fetched from the third-party to produce these models. /// - public bool? IncludeRemoteData { get; init; } + public bool? IncludeRemoteData { get; set; } } diff --git a/src/Merge.Client/Ticketing/Contacts/Requests/TicketingContactEndpointRequest.cs b/src/Merge.Client/Ticketing/Contacts/Requests/TicketingContactEndpointRequest.cs index bda26072..c13a84c0 100644 --- a/src/Merge.Client/Ticketing/Contacts/Requests/TicketingContactEndpointRequest.cs +++ b/src/Merge.Client/Ticketing/Contacts/Requests/TicketingContactEndpointRequest.cs @@ -1,20 +1,16 @@ -using Merge.Client.Ticketing; - -#nullable enable - namespace Merge.Client.Ticketing; -public class TicketingContactEndpointRequest +public record TicketingContactEndpointRequest { /// /// Whether to include debug fields (such as log file links) in the response. /// - public bool? IsDebugMode { get; init; } + public bool? IsDebugMode { get; set; } /// /// Whether or not third-party updates should be run asynchronously. /// - public bool? RunAsync { get; init; } + public bool? RunAsync { get; set; } - public ContactRequest Model { get; init; } + public required ContactRequest Model { get; set; } } diff --git a/src/Merge.Client/Ticketing/DeleteAccount/DeleteAccountClient.cs b/src/Merge.Client/Ticketing/DeleteAccount/DeleteAccountClient.cs index 7ff0180e..fcb39a7e 100644 --- a/src/Merge.Client/Ticketing/DeleteAccount/DeleteAccountClient.cs +++ b/src/Merge.Client/Ticketing/DeleteAccount/DeleteAccountClient.cs @@ -1,4 +1,5 @@ -using Merge.Client; +using System.Net.Http; +using Merge.Client.Core; #nullable enable @@ -16,14 +17,26 @@ public DeleteAccountClient(RawClient client) /// /// Delete a linked account. /// - public async void DeleteAsync() + public async Task DeleteAsync(RequestOptions? options = null) { var response = await _client.MakeRequestAsync( new RawClient.JsonApiRequest { + BaseUrl = _client.Options.BaseUrl, Method = HttpMethod.Post, - Path = "ticketing/v1/delete-account" + Path = "ticketing/v1/delete-account", + Options = options } ); + if (response.StatusCode is >= 200 and < 400) + { + return; + } + var responseBody = await response.Raw.Content.ReadAsStringAsync(); + throw new MergeApiException( + $"Error with status code {response.StatusCode}", + response.StatusCode, + JsonUtils.Deserialize(responseBody) + ); } } diff --git a/src/Merge.Client/Ticketing/FieldMapping/FieldMappingClient.cs b/src/Merge.Client/Ticketing/FieldMapping/FieldMappingClient.cs index 7a936880..b8f67c8b 100644 --- a/src/Merge.Client/Ticketing/FieldMapping/FieldMappingClient.cs +++ b/src/Merge.Client/Ticketing/FieldMapping/FieldMappingClient.cs @@ -1,6 +1,6 @@ +using System.Net.Http; using System.Text.Json; -using Merge.Client; -using Merge.Client.Ticketing; +using Merge.Client.Core; #nullable enable @@ -18,64 +18,112 @@ public FieldMappingClient(RawClient client) /// /// Get all Field Mappings for this Linked Account. Field Mappings are mappings between third-party Remote Fields and user defined Merge fields. [Learn more](https://docs.merge.dev/supplemental-data/field-mappings/overview/). /// - public async Task FieldMappingsRetrieveAsync() + public async Task FieldMappingsRetrieveAsync( + RequestOptions? options = null + ) { var response = await _client.MakeRequestAsync( new RawClient.JsonApiRequest { + BaseUrl = _client.Options.BaseUrl, Method = HttpMethod.Get, - Path = "ticketing/v1/field-mappings" + Path = "ticketing/v1/field-mappings", + Options = options } ); - string responseBody = await response.Raw.Content.ReadAsStringAsync(); - if (response.StatusCode >= 200 && response.StatusCode < 400) + var responseBody = await response.Raw.Content.ReadAsStringAsync(); + if (response.StatusCode is >= 200 and < 400) { - return JsonSerializer.Deserialize(responseBody); + try + { + return JsonUtils.Deserialize(responseBody)!; + } + catch (JsonException e) + { + throw new MergeException("Failed to deserialize response", e); + } } - throw new Exception(responseBody); + + throw new MergeApiException( + $"Error with status code {response.StatusCode}", + response.StatusCode, + JsonUtils.Deserialize(responseBody) + ); } /// /// Create new Field Mappings that will be available after the next scheduled sync. This will cause the next sync for this Linked Account to sync **ALL** data from start. /// public async Task FieldMappingsCreateAsync( - CreateFieldMappingRequest request + CreateFieldMappingRequest request, + RequestOptions? options = null ) { var response = await _client.MakeRequestAsync( new RawClient.JsonApiRequest { + BaseUrl = _client.Options.BaseUrl, Method = HttpMethod.Post, Path = "ticketing/v1/field-mappings", - Body = request + Body = request, + Options = options } ); - string responseBody = await response.Raw.Content.ReadAsStringAsync(); - if (response.StatusCode >= 200 && response.StatusCode < 400) + var responseBody = await response.Raw.Content.ReadAsStringAsync(); + if (response.StatusCode is >= 200 and < 400) { - return JsonSerializer.Deserialize(responseBody); + try + { + return JsonUtils.Deserialize(responseBody)!; + } + catch (JsonException e) + { + throw new MergeException("Failed to deserialize response", e); + } } - throw new Exception(responseBody); + + throw new MergeApiException( + $"Error with status code {response.StatusCode}", + response.StatusCode, + JsonUtils.Deserialize(responseBody) + ); } /// /// Deletes Field Mappings for a Linked Account. All data related to this Field Mapping will be deleted and these changes will be reflected after the next scheduled sync. This will cause the next sync for this Linked Account to sync **ALL** data from start. /// - public async Task FieldMappingsDestroyAsync(string fieldMappingId) + public async Task FieldMappingsDestroyAsync( + string fieldMappingId, + RequestOptions? options = null + ) { var response = await _client.MakeRequestAsync( new RawClient.JsonApiRequest { + BaseUrl = _client.Options.BaseUrl, Method = HttpMethod.Delete, - Path = $"ticketing/v1/field-mappings/{fieldMappingId}" + Path = $"ticketing/v1/field-mappings/{fieldMappingId}", + Options = options } ); - string responseBody = await response.Raw.Content.ReadAsStringAsync(); - if (response.StatusCode >= 200 && response.StatusCode < 400) + var responseBody = await response.Raw.Content.ReadAsStringAsync(); + if (response.StatusCode is >= 200 and < 400) { - return JsonSerializer.Deserialize(responseBody); + try + { + return JsonUtils.Deserialize(responseBody)!; + } + catch (JsonException e) + { + throw new MergeException("Failed to deserialize response", e); + } } - throw new Exception(responseBody); + + throw new MergeApiException( + $"Error with status code {response.StatusCode}", + response.StatusCode, + JsonUtils.Deserialize(responseBody) + ); } /// @@ -83,30 +131,46 @@ public async Task FieldMappingsDestroyAsync(string /// public async Task FieldMappingsPartialUpdateAsync( string fieldMappingId, - PatchedEditFieldMappingRequest request + PatchedEditFieldMappingRequest request, + RequestOptions? options = null ) { var response = await _client.MakeRequestAsync( new RawClient.JsonApiRequest { - Method = HttpMethod.Patch, + BaseUrl = _client.Options.BaseUrl, + Method = HttpMethodExtensions.Patch, Path = $"ticketing/v1/field-mappings/{fieldMappingId}", - Body = request + Body = request, + Options = options } ); - string responseBody = await response.Raw.Content.ReadAsStringAsync(); - if (response.StatusCode >= 200 && response.StatusCode < 400) + var responseBody = await response.Raw.Content.ReadAsStringAsync(); + if (response.StatusCode is >= 200 and < 400) { - return JsonSerializer.Deserialize(responseBody); + try + { + return JsonUtils.Deserialize(responseBody)!; + } + catch (JsonException e) + { + throw new MergeException("Failed to deserialize response", e); + } } - throw new Exception(responseBody); + + throw new MergeApiException( + $"Error with status code {response.StatusCode}", + response.StatusCode, + JsonUtils.Deserialize(responseBody) + ); } /// /// Get all remote fields for a Linked Account. Remote fields are third-party fields that are accessible after initial sync if remote_data is enabled. You can use remote fields to override existing Merge fields or map a new Merge field. [Learn more](https://docs.merge.dev/supplemental-data/field-mappings/overview/). /// public async Task RemoteFieldsRetrieveAsync( - RemoteFieldsRetrieveRequest request + RemoteFieldsRetrieveRequest request, + RequestOptions? options = null ) { var _query = new Dictionary() { }; @@ -121,36 +185,66 @@ RemoteFieldsRetrieveRequest request var response = await _client.MakeRequestAsync( new RawClient.JsonApiRequest { + BaseUrl = _client.Options.BaseUrl, Method = HttpMethod.Get, Path = "ticketing/v1/remote-fields", - Query = _query + Query = _query, + Options = options } ); - string responseBody = await response.Raw.Content.ReadAsStringAsync(); - if (response.StatusCode >= 200 && response.StatusCode < 400) + var responseBody = await response.Raw.Content.ReadAsStringAsync(); + if (response.StatusCode is >= 200 and < 400) { - return JsonSerializer.Deserialize(responseBody); + try + { + return JsonUtils.Deserialize(responseBody)!; + } + catch (JsonException e) + { + throw new MergeException("Failed to deserialize response", e); + } } - throw new Exception(responseBody); + + throw new MergeApiException( + $"Error with status code {response.StatusCode}", + response.StatusCode, + JsonUtils.Deserialize(responseBody) + ); } /// /// Get all organization-wide Target Fields, this will not include any Linked Account specific Target Fields. Organization-wide Target Fields are additional fields appended to the Merge Common Model for all Linked Accounts in a category. [Learn more](https://docs.merge.dev/supplemental-data/field-mappings/target-fields/). /// - public async Task TargetFieldsRetrieveAsync() + public async Task TargetFieldsRetrieveAsync( + RequestOptions? options = null + ) { var response = await _client.MakeRequestAsync( new RawClient.JsonApiRequest { + BaseUrl = _client.Options.BaseUrl, Method = HttpMethod.Get, - Path = "ticketing/v1/target-fields" + Path = "ticketing/v1/target-fields", + Options = options } ); - string responseBody = await response.Raw.Content.ReadAsStringAsync(); - if (response.StatusCode >= 200 && response.StatusCode < 400) + var responseBody = await response.Raw.Content.ReadAsStringAsync(); + if (response.StatusCode is >= 200 and < 400) { - return JsonSerializer.Deserialize(responseBody); + try + { + return JsonUtils.Deserialize(responseBody)!; + } + catch (JsonException e) + { + throw new MergeException("Failed to deserialize response", e); + } } - throw new Exception(responseBody); + + throw new MergeApiException( + $"Error with status code {response.StatusCode}", + response.StatusCode, + JsonUtils.Deserialize(responseBody) + ); } } diff --git a/src/Merge.Client/Ticketing/FieldMapping/Requests/CreateFieldMappingRequest.cs b/src/Merge.Client/Ticketing/FieldMapping/Requests/CreateFieldMappingRequest.cs index 32f5f932..037bc991 100644 --- a/src/Merge.Client/Ticketing/FieldMapping/Requests/CreateFieldMappingRequest.cs +++ b/src/Merge.Client/Ticketing/FieldMapping/Requests/CreateFieldMappingRequest.cs @@ -4,41 +4,41 @@ namespace Merge.Client.Ticketing; -public class CreateFieldMappingRequest +public record CreateFieldMappingRequest { /// /// The name of the target field you want this remote field to map to. /// [JsonPropertyName("target_field_name")] - public string TargetFieldName { get; init; } + public required string TargetFieldName { get; set; } /// /// The description of the target field you want this remote field to map to. /// [JsonPropertyName("target_field_description")] - public string TargetFieldDescription { get; init; } + public required string TargetFieldDescription { get; set; } /// /// The field traversal path of the remote field listed when you hit the GET /remote-fields endpoint. /// [JsonPropertyName("remote_field_traversal_path")] - public IEnumerable RemoteFieldTraversalPath { get; init; } + public IEnumerable RemoteFieldTraversalPath { get; set; } = new List(); /// /// The method of the remote endpoint where the remote field is coming from. /// [JsonPropertyName("remote_method")] - public string RemoteMethod { get; init; } + public required string RemoteMethod { get; set; } /// /// The path of the remote endpoint where the remote field is coming from. /// [JsonPropertyName("remote_url_path")] - public string RemoteUrlPath { get; init; } + public required string RemoteUrlPath { get; set; } /// /// The name of the Common Model that the remote field corresponds to in a given category. /// [JsonPropertyName("common_model_name")] - public string CommonModelName { get; init; } + public required string CommonModelName { get; set; } } diff --git a/src/Merge.Client/Ticketing/FieldMapping/Requests/PatchedEditFieldMappingRequest.cs b/src/Merge.Client/Ticketing/FieldMapping/Requests/PatchedEditFieldMappingRequest.cs index 57139667..b8b41b3f 100644 --- a/src/Merge.Client/Ticketing/FieldMapping/Requests/PatchedEditFieldMappingRequest.cs +++ b/src/Merge.Client/Ticketing/FieldMapping/Requests/PatchedEditFieldMappingRequest.cs @@ -4,23 +4,23 @@ namespace Merge.Client.Ticketing; -public class PatchedEditFieldMappingRequest +public record PatchedEditFieldMappingRequest { /// /// The field traversal path of the remote field listed when you hit the GET /remote-fields endpoint. /// [JsonPropertyName("remote_field_traversal_path")] - public IEnumerable? RemoteFieldTraversalPath { get; init; } + public IEnumerable? RemoteFieldTraversalPath { get; set; } /// /// The method of the remote endpoint where the remote field is coming from. /// [JsonPropertyName("remote_method")] - public string? RemoteMethod { get; init; } + public string? RemoteMethod { get; set; } /// /// The path of the remote endpoint where the remote field is coming from. /// [JsonPropertyName("remote_url_path")] - public string? RemoteUrlPath { get; init; } + public string? RemoteUrlPath { get; set; } } diff --git a/src/Merge.Client/Ticketing/FieldMapping/Requests/RemoteFieldsRetrieveRequest.cs b/src/Merge.Client/Ticketing/FieldMapping/Requests/RemoteFieldsRetrieveRequest.cs index 6904b27a..7795fcf9 100644 --- a/src/Merge.Client/Ticketing/FieldMapping/Requests/RemoteFieldsRetrieveRequest.cs +++ b/src/Merge.Client/Ticketing/FieldMapping/Requests/RemoteFieldsRetrieveRequest.cs @@ -1,14 +1,14 @@ namespace Merge.Client.Ticketing; -public class RemoteFieldsRetrieveRequest +public record RemoteFieldsRetrieveRequest { /// /// A comma seperated list of Common Model names. If included, will only return Remote Fields for those Common Models. /// - public string? CommonModels { get; init; } + public string? CommonModels { get; set; } /// /// If true, will include example values, where available, for remote fields in the 3rd party platform. These examples come from active data from your customers. /// - public string? IncludeExampleValues { get; init; } + public string? IncludeExampleValues { get; set; } } diff --git a/src/Merge.Client/Ticketing/ForceResync/ForceResyncClient.cs b/src/Merge.Client/Ticketing/ForceResync/ForceResyncClient.cs index dc6c4671..899ecf7f 100644 --- a/src/Merge.Client/Ticketing/ForceResync/ForceResyncClient.cs +++ b/src/Merge.Client/Ticketing/ForceResync/ForceResyncClient.cs @@ -1,6 +1,6 @@ +using System.Net.Http; using System.Text.Json; -using Merge.Client; -using Merge.Client.Ticketing; +using Merge.Client.Core; #nullable enable @@ -18,20 +18,36 @@ public ForceResyncClient(RawClient client) /// /// Force re-sync of all models. This is available for all organizations via the dashboard. Force re-sync is also available programmatically via API for monthly, quarterly, and highest sync frequency customers on the Launch, Professional, or Enterprise plans. Doing so will consume a sync credit for the relevant linked account. /// - public async Task> SyncStatusResyncCreateAsync() + public async Task> SyncStatusResyncCreateAsync( + RequestOptions? options = null + ) { var response = await _client.MakeRequestAsync( new RawClient.JsonApiRequest { + BaseUrl = _client.Options.BaseUrl, Method = HttpMethod.Post, - Path = "ticketing/v1/sync-status/resync" + Path = "ticketing/v1/sync-status/resync", + Options = options } ); - string responseBody = await response.Raw.Content.ReadAsStringAsync(); - if (response.StatusCode >= 200 && response.StatusCode < 400) + var responseBody = await response.Raw.Content.ReadAsStringAsync(); + if (response.StatusCode is >= 200 and < 400) { - return JsonSerializer.Deserialize>(responseBody); + try + { + return JsonUtils.Deserialize>(responseBody)!; + } + catch (JsonException e) + { + throw new MergeException("Failed to deserialize response", e); + } } - throw new Exception(responseBody); + + throw new MergeApiException( + $"Error with status code {response.StatusCode}", + response.StatusCode, + JsonUtils.Deserialize(responseBody) + ); } } diff --git a/src/Merge.Client/Ticketing/GenerateKey/GenerateKeyClient.cs b/src/Merge.Client/Ticketing/GenerateKey/GenerateKeyClient.cs index 83db7b7f..f651c498 100644 --- a/src/Merge.Client/Ticketing/GenerateKey/GenerateKeyClient.cs +++ b/src/Merge.Client/Ticketing/GenerateKey/GenerateKeyClient.cs @@ -1,6 +1,6 @@ +using System.Net.Http; using System.Text.Json; -using Merge.Client; -using Merge.Client.Ticketing; +using Merge.Client.Core; #nullable enable @@ -18,21 +18,38 @@ public GenerateKeyClient(RawClient client) /// /// Create a remote key. /// - public async Task CreateAsync(GenerateRemoteKeyRequest request) + public async Task CreateAsync( + GenerateRemoteKeyRequest request, + RequestOptions? options = null + ) { var response = await _client.MakeRequestAsync( new RawClient.JsonApiRequest { + BaseUrl = _client.Options.BaseUrl, Method = HttpMethod.Post, Path = "ticketing/v1/generate-key", - Body = request + Body = request, + Options = options } ); - string responseBody = await response.Raw.Content.ReadAsStringAsync(); - if (response.StatusCode >= 200 && response.StatusCode < 400) + var responseBody = await response.Raw.Content.ReadAsStringAsync(); + if (response.StatusCode is >= 200 and < 400) { - return JsonSerializer.Deserialize(responseBody); + try + { + return JsonUtils.Deserialize(responseBody)!; + } + catch (JsonException e) + { + throw new MergeException("Failed to deserialize response", e); + } } - throw new Exception(responseBody); + + throw new MergeApiException( + $"Error with status code {response.StatusCode}", + response.StatusCode, + JsonUtils.Deserialize(responseBody) + ); } } diff --git a/src/Merge.Client/Ticketing/GenerateKey/Requests/GenerateRemoteKeyRequest.cs b/src/Merge.Client/Ticketing/GenerateKey/Requests/GenerateRemoteKeyRequest.cs index 0aa9b55e..1a4566d8 100644 --- a/src/Merge.Client/Ticketing/GenerateKey/Requests/GenerateRemoteKeyRequest.cs +++ b/src/Merge.Client/Ticketing/GenerateKey/Requests/GenerateRemoteKeyRequest.cs @@ -4,11 +4,11 @@ namespace Merge.Client.Ticketing; -public class GenerateRemoteKeyRequest +public record GenerateRemoteKeyRequest { /// /// The name of the remote key /// [JsonPropertyName("name")] - public string Name { get; init; } + public required string Name { get; set; } } diff --git a/src/Merge.Client/Ticketing/Issues/IssuesClient.cs b/src/Merge.Client/Ticketing/Issues/IssuesClient.cs index 8c3dc816..bec701a4 100644 --- a/src/Merge.Client/Ticketing/Issues/IssuesClient.cs +++ b/src/Merge.Client/Ticketing/Issues/IssuesClient.cs @@ -1,6 +1,6 @@ +using System.Net.Http; using System.Text.Json; -using Merge.Client; -using Merge.Client.Ticketing; +using Merge.Client.Core; #nullable enable @@ -18,7 +18,10 @@ public IssuesClient(RawClient client) /// /// Gets all issues for Organization. /// - public async Task ListAsync(IssuesListRequest request) + public async Task ListAsync( + IssuesListRequest request, + RequestOptions? options = null + ) { var _query = new Dictionary() { }; if (request.AccountToken != null) @@ -40,13 +43,13 @@ public async Task ListAsync(IssuesListRequest request) if (request.FirstIncidentTimeAfter != null) { _query["first_incident_time_after"] = request.FirstIncidentTimeAfter.Value.ToString( - "o0" + Constants.DateTimeFormat ); } if (request.FirstIncidentTimeBefore != null) { _query["first_incident_time_before"] = request.FirstIncidentTimeBefore.Value.ToString( - "o0" + Constants.DateTimeFormat ); } if (request.IncludeMuted != null) @@ -59,12 +62,14 @@ public async Task ListAsync(IssuesListRequest request) } if (request.LastIncidentTimeAfter != null) { - _query["last_incident_time_after"] = request.LastIncidentTimeAfter.Value.ToString("o0"); + _query["last_incident_time_after"] = request.LastIncidentTimeAfter.Value.ToString( + Constants.DateTimeFormat + ); } if (request.LastIncidentTimeBefore != null) { _query["last_incident_time_before"] = request.LastIncidentTimeBefore.Value.ToString( - "o0" + Constants.DateTimeFormat ); } if (request.LinkedAccountId != null) @@ -86,36 +91,64 @@ public async Task ListAsync(IssuesListRequest request) var response = await _client.MakeRequestAsync( new RawClient.JsonApiRequest { + BaseUrl = _client.Options.BaseUrl, Method = HttpMethod.Get, Path = "ticketing/v1/issues", - Query = _query + Query = _query, + Options = options } ); - string responseBody = await response.Raw.Content.ReadAsStringAsync(); - if (response.StatusCode >= 200 && response.StatusCode < 400) + var responseBody = await response.Raw.Content.ReadAsStringAsync(); + if (response.StatusCode is >= 200 and < 400) { - return JsonSerializer.Deserialize(responseBody); + try + { + return JsonUtils.Deserialize(responseBody)!; + } + catch (JsonException e) + { + throw new MergeException("Failed to deserialize response", e); + } } - throw new Exception(responseBody); + + throw new MergeApiException( + $"Error with status code {response.StatusCode}", + response.StatusCode, + JsonUtils.Deserialize(responseBody) + ); } /// /// Get a specific issue. /// - public async Task RetrieveAsync(string id) + public async Task RetrieveAsync(string id, RequestOptions? options = null) { var response = await _client.MakeRequestAsync( new RawClient.JsonApiRequest { + BaseUrl = _client.Options.BaseUrl, Method = HttpMethod.Get, - Path = $"ticketing/v1/issues/{id}" + Path = $"ticketing/v1/issues/{id}", + Options = options } ); - string responseBody = await response.Raw.Content.ReadAsStringAsync(); - if (response.StatusCode >= 200 && response.StatusCode < 400) + var responseBody = await response.Raw.Content.ReadAsStringAsync(); + if (response.StatusCode is >= 200 and < 400) { - return JsonSerializer.Deserialize(responseBody); + try + { + return JsonUtils.Deserialize(responseBody)!; + } + catch (JsonException e) + { + throw new MergeException("Failed to deserialize response", e); + } } - throw new Exception(responseBody); + + throw new MergeApiException( + $"Error with status code {response.StatusCode}", + response.StatusCode, + JsonUtils.Deserialize(responseBody) + ); } } diff --git a/src/Merge.Client/Ticketing/Issues/Requests/IssuesListRequest.cs b/src/Merge.Client/Ticketing/Issues/Requests/IssuesListRequest.cs index 136a3888..f3810fc8 100644 --- a/src/Merge.Client/Ticketing/Issues/Requests/IssuesListRequest.cs +++ b/src/Merge.Client/Ticketing/Issues/Requests/IssuesListRequest.cs @@ -1,66 +1,62 @@ -using Merge.Client.Ticketing; - -#nullable enable - namespace Merge.Client.Ticketing; -public class IssuesListRequest +public record IssuesListRequest { - public string? AccountToken { get; init; } + public string? AccountToken { get; set; } /// /// The pagination cursor value. /// - public string? Cursor { get; init; } + public string? Cursor { get; set; } /// /// If included, will only include issues whose most recent action occurred before this time /// - public string? EndDate { get; init; } + public string? EndDate { get; set; } - public string? EndUserOrganizationName { get; init; } + public string? EndUserOrganizationName { get; set; } /// /// If provided, will only return issues whose first incident time was after this datetime. /// - public DateTime? FirstIncidentTimeAfter { get; init; } + public DateTime? FirstIncidentTimeAfter { get; set; } /// /// If provided, will only return issues whose first incident time was before this datetime. /// - public DateTime? FirstIncidentTimeBefore { get; init; } + public DateTime? FirstIncidentTimeBefore { get; set; } /// /// If true, will include muted issues /// - public string? IncludeMuted { get; init; } + public string? IncludeMuted { get; set; } - public string? IntegrationName { get; init; } + public string? IntegrationName { get; set; } /// /// If provided, will only return issues whose last incident time was after this datetime. /// - public DateTime? LastIncidentTimeAfter { get; init; } + public DateTime? LastIncidentTimeAfter { get; set; } /// /// If provided, will only return issues whose last incident time was before this datetime. /// - public DateTime? LastIncidentTimeBefore { get; init; } + public DateTime? LastIncidentTimeBefore { get; set; } /// /// If provided, will only include issues pertaining to the linked account passed in. /// - public string? LinkedAccountId { get; init; } + public string? LinkedAccountId { get; set; } /// /// Number of results to return per page. /// - public int? PageSize { get; init; } + public int? PageSize { get; set; } /// /// If included, will only include issues whose most recent action occurred after this time /// - public string? StartDate { get; init; } + public string? StartDate { get; set; } /// /// Status of the issue. Options: ('ONGOING', 'RESOLVED') @@ -68,5 +64,5 @@ public class IssuesListRequest /// - `ONGOING` - ONGOING /// - `RESOLVED` - RESOLVED /// - public IssuesListRequestStatus? Status { get; init; } + public IssuesListRequestStatus? Status { get; set; } } diff --git a/src/Merge.Client/Ticketing/Issues/Types/IssuesListRequestStatus.cs b/src/Merge.Client/Ticketing/Issues/Types/IssuesListRequestStatus.cs index b18e3b67..86887745 100644 --- a/src/Merge.Client/Ticketing/Issues/Types/IssuesListRequestStatus.cs +++ b/src/Merge.Client/Ticketing/Issues/Types/IssuesListRequestStatus.cs @@ -1,7 +1,6 @@ using System.Runtime.Serialization; using System.Text.Json.Serialization; using Merge.Client.Core; -using Merge.Client.Ticketing; #nullable enable diff --git a/src/Merge.Client/Ticketing/LinkToken/LinkTokenClient.cs b/src/Merge.Client/Ticketing/LinkToken/LinkTokenClient.cs index 8de3a90e..97d3a99b 100644 --- a/src/Merge.Client/Ticketing/LinkToken/LinkTokenClient.cs +++ b/src/Merge.Client/Ticketing/LinkToken/LinkTokenClient.cs @@ -1,6 +1,6 @@ +using System.Net.Http; using System.Text.Json; -using Merge.Client; -using Merge.Client.Ticketing; +using Merge.Client.Core; #nullable enable @@ -18,21 +18,38 @@ public LinkTokenClient(RawClient client) /// /// Creates a link token to be used when linking a new end user. /// - public async Task CreateAsync(EndUserDetailsRequest request) + public async Task CreateAsync( + EndUserDetailsRequest request, + RequestOptions? options = null + ) { var response = await _client.MakeRequestAsync( new RawClient.JsonApiRequest { + BaseUrl = _client.Options.BaseUrl, Method = HttpMethod.Post, Path = "ticketing/v1/link-token", - Body = request + Body = request, + Options = options } ); - string responseBody = await response.Raw.Content.ReadAsStringAsync(); - if (response.StatusCode >= 200 && response.StatusCode < 400) + var responseBody = await response.Raw.Content.ReadAsStringAsync(); + if (response.StatusCode is >= 200 and < 400) { - return JsonSerializer.Deserialize(responseBody); + try + { + return JsonUtils.Deserialize(responseBody)!; + } + catch (JsonException e) + { + throw new MergeException("Failed to deserialize response", e); + } } - throw new Exception(responseBody); + + throw new MergeApiException( + $"Error with status code {response.StatusCode}", + response.StatusCode, + JsonUtils.Deserialize(responseBody) + ); } } diff --git a/src/Merge.Client/Ticketing/LinkToken/Requests/EndUserDetailsRequest.cs b/src/Merge.Client/Ticketing/LinkToken/Requests/EndUserDetailsRequest.cs index 5444c2c7..785482c5 100644 --- a/src/Merge.Client/Ticketing/LinkToken/Requests/EndUserDetailsRequest.cs +++ b/src/Merge.Client/Ticketing/LinkToken/Requests/EndUserDetailsRequest.cs @@ -1,65 +1,64 @@ using System.Text.Json.Serialization; -using Merge.Client.Ticketing; #nullable enable namespace Merge.Client.Ticketing; -public class EndUserDetailsRequest +public record EndUserDetailsRequest { /// /// Your end user's email address. This is purely for identification purposes - setting this value will not cause any emails to be sent. /// [JsonPropertyName("end_user_email_address")] - public string EndUserEmailAddress { get; init; } + public required string EndUserEmailAddress { get; set; } /// /// Your end user's organization. /// [JsonPropertyName("end_user_organization_name")] - public string EndUserOrganizationName { get; init; } + public required string EndUserOrganizationName { get; set; } /// /// This unique identifier typically represents the ID for your end user in your product's database. This value must be distinct from other Linked Accounts' unique identifiers. /// [JsonPropertyName("end_user_origin_id")] - public string EndUserOriginId { get; init; } + public required string EndUserOriginId { get; set; } /// /// The integration categories to show in Merge Link. /// [JsonPropertyName("categories")] - public IEnumerable Categories { get; init; } + public IEnumerable Categories { get; set; } = new List(); /// /// The slug of a specific pre-selected integration for this linking flow token. For examples of slugs, see https://docs.merge.dev/guides/merge-link/single-integration/. /// [JsonPropertyName("integration")] - public string? Integration { get; init; } + public string? Integration { get; set; } /// /// An integer number of minutes between [30, 720 or 10080 if for a Magic Link URL] for how long this token is valid. Defaults to 30. /// [JsonPropertyName("link_expiry_mins")] - public int? LinkExpiryMins { get; init; } + public int? LinkExpiryMins { get; set; } /// /// Whether to generate a Magic Link URL. Defaults to false. For more information on Magic Link, see https://merge.dev/blog/integrations-fast-say-hello-to-magic-link. /// [JsonPropertyName("should_create_magic_link_url")] - public bool? ShouldCreateMagicLinkUrl { get; init; } + public bool? ShouldCreateMagicLinkUrl { get; set; } /// /// Whether to generate a Magic Link URL on the Admin Needed screen during the linking flow. Defaults to false. For more information on Magic Link, see https://merge.dev/blog/integrations-fast-say-hello-to-magic-link. /// [JsonPropertyName("hide_admin_magic_link")] - public bool? HideAdminMagicLink { get; init; } + public bool? HideAdminMagicLink { get; set; } /// /// An array of objects to specify the models and fields that will be disabled for a given Linked Account. Each object uses model_id, enabled_actions, and disabled_fields to specify the model, method, and fields that are scoped for a given Linked Account. /// [JsonPropertyName("common_models")] - public IEnumerable? CommonModels { get; init; } + public IEnumerable? CommonModels { get; set; } /// /// When creating a Link Token, you can set permissions for Common Models that will apply to the account that is going to be linked. Any model or field not specified in link token payload will default to existing settings. @@ -68,17 +67,17 @@ public class EndUserDetailsRequest public Dictionary< string, IEnumerable? - >? CategoryCommonModelScopes { get; init; } + >? CategoryCommonModelScopes { get; set; } /// /// The language code for the language to localize Merge Link to. /// [JsonPropertyName("language")] - public string? Language { get; init; } + public string? Language { get; set; } /// /// A JSON object containing integration-specific configuration options. /// [JsonPropertyName("integration_specific_config")] - public Dictionary? IntegrationSpecificConfig { get; init; } + public Dictionary? IntegrationSpecificConfig { get; set; } } diff --git a/src/Merge.Client/Ticketing/LinkedAccounts/LinkedAccountsClient.cs b/src/Merge.Client/Ticketing/LinkedAccounts/LinkedAccountsClient.cs index 4de4c97d..c2c73f83 100644 --- a/src/Merge.Client/Ticketing/LinkedAccounts/LinkedAccountsClient.cs +++ b/src/Merge.Client/Ticketing/LinkedAccounts/LinkedAccountsClient.cs @@ -1,6 +1,6 @@ +using System.Net.Http; using System.Text.Json; -using Merge.Client; -using Merge.Client.Ticketing; +using Merge.Client.Core; #nullable enable @@ -19,7 +19,8 @@ public LinkedAccountsClient(RawClient client) /// List linked accounts for your organization. /// public async Task ListAsync( - LinkedAccountsListRequest request + LinkedAccountsListRequest request, + RequestOptions? options = null ) { var _query = new Dictionary() { }; @@ -78,16 +79,30 @@ LinkedAccountsListRequest request var response = await _client.MakeRequestAsync( new RawClient.JsonApiRequest { + BaseUrl = _client.Options.BaseUrl, Method = HttpMethod.Get, Path = "ticketing/v1/linked-accounts", - Query = _query + Query = _query, + Options = options } ); - string responseBody = await response.Raw.Content.ReadAsStringAsync(); - if (response.StatusCode >= 200 && response.StatusCode < 400) + var responseBody = await response.Raw.Content.ReadAsStringAsync(); + if (response.StatusCode is >= 200 and < 400) { - return JsonSerializer.Deserialize(responseBody); + try + { + return JsonUtils.Deserialize(responseBody)!; + } + catch (JsonException e) + { + throw new MergeException("Failed to deserialize response", e); + } } - throw new Exception(responseBody); + + throw new MergeApiException( + $"Error with status code {response.StatusCode}", + response.StatusCode, + JsonUtils.Deserialize(responseBody) + ); } } diff --git a/src/Merge.Client/Ticketing/LinkedAccounts/Requests/LinkedAccountsListRequest.cs b/src/Merge.Client/Ticketing/LinkedAccounts/Requests/LinkedAccountsListRequest.cs index 54e880dd..baefd025 100644 --- a/src/Merge.Client/Ticketing/LinkedAccounts/Requests/LinkedAccountsListRequest.cs +++ b/src/Merge.Client/Ticketing/LinkedAccounts/Requests/LinkedAccountsListRequest.cs @@ -1,10 +1,6 @@ -using Merge.Client.Ticketing; - -#nullable enable - namespace Merge.Client.Ticketing; -public class LinkedAccountsListRequest +public record LinkedAccountsListRequest { /// /// Options: `accounting`, `ats`, `crm`, `filestorage`, `hris`, `mktg`, `ticketing` @@ -17,62 +13,62 @@ public class LinkedAccountsListRequest /// - `mktg` - mktg /// - `filestorage` - filestorage /// - public LinkedAccountsListRequestCategory? Category { get; init; } + public LinkedAccountsListRequestCategory? Category { get; set; } /// /// The pagination cursor value. /// - public string? Cursor { get; init; } + public string? Cursor { get; set; } /// /// If provided, will only return linked accounts associated with the given email address. /// - public string? EndUserEmailAddress { get; init; } + public string? EndUserEmailAddress { get; set; } /// /// If provided, will only return linked accounts associated with the given organization name. /// - public string? EndUserOrganizationName { get; init; } + public string? EndUserOrganizationName { get; set; } /// /// If provided, will only return linked accounts associated with the given origin ID. /// - public string? EndUserOriginId { get; init; } + public string? EndUserOriginId { get; set; } /// /// Comma-separated list of EndUser origin IDs, making it possible to specify multiple EndUsers at once. /// - public string? EndUserOriginIds { get; init; } + public string? EndUserOriginIds { get; set; } - public string? Id { get; init; } + public string? Id { get; set; } /// /// Comma-separated list of LinkedAccount IDs, making it possible to specify multiple LinkedAccounts at once. /// - public string? Ids { get; init; } + public string? Ids { get; set; } /// /// If `true`, will include complete production duplicates of the account specified by the `id` query parameter in the response. `id` must be for a complete production linked account. /// - public bool? IncludeDuplicates { get; init; } + public bool? IncludeDuplicates { get; set; } /// /// If provided, will only return linked accounts associated with the given integration name. /// - public string? IntegrationName { get; init; } + public string? IntegrationName { get; set; } /// /// If included, will only include test linked accounts. If not included, will only include non-test linked accounts. /// - public string? IsTestAccount { get; init; } + public string? IsTestAccount { get; set; } /// /// Number of results to return per page. /// - public int? PageSize { get; init; } + public int? PageSize { get; set; } /// /// Filter by status. Options: `COMPLETE`, `INCOMPLETE`, `RELINK_NEEDED` /// - public string? Status { get; init; } + public string? Status { get; set; } } diff --git a/src/Merge.Client/Ticketing/LinkedAccounts/Types/LinkedAccountsListRequestCategory.cs b/src/Merge.Client/Ticketing/LinkedAccounts/Types/LinkedAccountsListRequestCategory.cs index f42d008d..f06cdd8d 100644 --- a/src/Merge.Client/Ticketing/LinkedAccounts/Types/LinkedAccountsListRequestCategory.cs +++ b/src/Merge.Client/Ticketing/LinkedAccounts/Types/LinkedAccountsListRequestCategory.cs @@ -1,7 +1,6 @@ using System.Runtime.Serialization; using System.Text.Json.Serialization; using Merge.Client.Core; -using Merge.Client.Ticketing; #nullable enable diff --git a/src/Merge.Client/Ticketing/Passthrough/PassthroughClient.cs b/src/Merge.Client/Ticketing/Passthrough/PassthroughClient.cs index 072e866e..5f39b625 100644 --- a/src/Merge.Client/Ticketing/Passthrough/PassthroughClient.cs +++ b/src/Merge.Client/Ticketing/Passthrough/PassthroughClient.cs @@ -1,6 +1,6 @@ +using System.Net.Http; using System.Text.Json; -using Merge.Client; -using Merge.Client.Ticketing; +using Merge.Client.Core; #nullable enable @@ -18,21 +18,38 @@ public PassthroughClient(RawClient client) /// /// Pull data from an endpoint not currently supported by Merge. /// - public async Task CreateAsync(DataPassthroughRequest request) + public async Task CreateAsync( + DataPassthroughRequest request, + RequestOptions? options = null + ) { var response = await _client.MakeRequestAsync( new RawClient.JsonApiRequest { + BaseUrl = _client.Options.BaseUrl, Method = HttpMethod.Post, Path = "ticketing/v1/passthrough", - Body = request + Body = request, + Options = options } ); - string responseBody = await response.Raw.Content.ReadAsStringAsync(); - if (response.StatusCode >= 200 && response.StatusCode < 400) + var responseBody = await response.Raw.Content.ReadAsStringAsync(); + if (response.StatusCode is >= 200 and < 400) { - return JsonSerializer.Deserialize(responseBody); + try + { + return JsonUtils.Deserialize(responseBody)!; + } + catch (JsonException e) + { + throw new MergeException("Failed to deserialize response", e); + } } - throw new Exception(responseBody); + + throw new MergeApiException( + $"Error with status code {response.StatusCode}", + response.StatusCode, + JsonUtils.Deserialize(responseBody) + ); } } diff --git a/src/Merge.Client/Ticketing/Projects/ProjectsClient.cs b/src/Merge.Client/Ticketing/Projects/ProjectsClient.cs index ba3277b7..fd272d55 100644 --- a/src/Merge.Client/Ticketing/Projects/ProjectsClient.cs +++ b/src/Merge.Client/Ticketing/Projects/ProjectsClient.cs @@ -1,6 +1,6 @@ +using System.Net.Http; using System.Text.Json; -using Merge.Client; -using Merge.Client.Ticketing; +using Merge.Client.Core; #nullable enable @@ -18,16 +18,21 @@ public ProjectsClient(RawClient client) /// /// Returns a list of `Project` objects. /// - public async Task ListAsync(ProjectsListRequest request) + public async Task ListAsync( + ProjectsListRequest request, + RequestOptions? options = null + ) { var _query = new Dictionary() { }; if (request.CreatedAfter != null) { - _query["created_after"] = request.CreatedAfter.Value.ToString("o0"); + _query["created_after"] = request.CreatedAfter.Value.ToString(Constants.DateTimeFormat); } if (request.CreatedBefore != null) { - _query["created_before"] = request.CreatedBefore.Value.ToString("o0"); + _query["created_before"] = request.CreatedBefore.Value.ToString( + Constants.DateTimeFormat + ); } if (request.Cursor != null) { @@ -43,11 +48,15 @@ public async Task ListAsync(ProjectsListRequest request) } if (request.ModifiedAfter != null) { - _query["modified_after"] = request.ModifiedAfter.Value.ToString("o0"); + _query["modified_after"] = request.ModifiedAfter.Value.ToString( + Constants.DateTimeFormat + ); } if (request.ModifiedBefore != null) { - _query["modified_before"] = request.ModifiedBefore.Value.ToString("o0"); + _query["modified_before"] = request.ModifiedBefore.Value.ToString( + Constants.DateTimeFormat + ); } if (request.PageSize != null) { @@ -60,23 +69,41 @@ public async Task ListAsync(ProjectsListRequest request) var response = await _client.MakeRequestAsync( new RawClient.JsonApiRequest { + BaseUrl = _client.Options.BaseUrl, Method = HttpMethod.Get, Path = "ticketing/v1/projects", - Query = _query + Query = _query, + Options = options } ); - string responseBody = await response.Raw.Content.ReadAsStringAsync(); - if (response.StatusCode >= 200 && response.StatusCode < 400) + var responseBody = await response.Raw.Content.ReadAsStringAsync(); + if (response.StatusCode is >= 200 and < 400) { - return JsonSerializer.Deserialize(responseBody); + try + { + return JsonUtils.Deserialize(responseBody)!; + } + catch (JsonException e) + { + throw new MergeException("Failed to deserialize response", e); + } } - throw new Exception(responseBody); + + throw new MergeApiException( + $"Error with status code {response.StatusCode}", + response.StatusCode, + JsonUtils.Deserialize(responseBody) + ); } /// /// Returns a `Project` object with the given `id`. /// - public async Task RetrieveAsync(string id, ProjectsRetrieveRequest request) + public async Task RetrieveAsync( + string id, + ProjectsRetrieveRequest request, + RequestOptions? options = null + ) { var _query = new Dictionary() { }; if (request.IncludeRemoteData != null) @@ -86,17 +113,31 @@ public async Task RetrieveAsync(string id, ProjectsRetrieveRequest requ var response = await _client.MakeRequestAsync( new RawClient.JsonApiRequest { + BaseUrl = _client.Options.BaseUrl, Method = HttpMethod.Get, Path = $"ticketing/v1/projects/{id}", - Query = _query + Query = _query, + Options = options } ); - string responseBody = await response.Raw.Content.ReadAsStringAsync(); - if (response.StatusCode >= 200 && response.StatusCode < 400) + var responseBody = await response.Raw.Content.ReadAsStringAsync(); + if (response.StatusCode is >= 200 and < 400) { - return JsonSerializer.Deserialize(responseBody); + try + { + return JsonUtils.Deserialize(responseBody)!; + } + catch (JsonException e) + { + throw new MergeException("Failed to deserialize response", e); + } } - throw new Exception(responseBody); + + throw new MergeApiException( + $"Error with status code {response.StatusCode}", + response.StatusCode, + JsonUtils.Deserialize(responseBody) + ); } /// @@ -104,7 +145,8 @@ public async Task RetrieveAsync(string id, ProjectsRetrieveRequest requ /// public async Task UsersListAsync( string parentId, - ProjectsUsersListRequest request + ProjectsUsersListRequest request, + RequestOptions? options = null ) { var _query = new Dictionary() { }; @@ -131,16 +173,30 @@ ProjectsUsersListRequest request var response = await _client.MakeRequestAsync( new RawClient.JsonApiRequest { + BaseUrl = _client.Options.BaseUrl, Method = HttpMethod.Get, Path = $"ticketing/v1/projects/{parentId}/users", - Query = _query + Query = _query, + Options = options } ); - string responseBody = await response.Raw.Content.ReadAsStringAsync(); - if (response.StatusCode >= 200 && response.StatusCode < 400) + var responseBody = await response.Raw.Content.ReadAsStringAsync(); + if (response.StatusCode is >= 200 and < 400) { - return JsonSerializer.Deserialize(responseBody); + try + { + return JsonUtils.Deserialize(responseBody)!; + } + catch (JsonException e) + { + throw new MergeException("Failed to deserialize response", e); + } } - throw new Exception(responseBody); + + throw new MergeApiException( + $"Error with status code {response.StatusCode}", + response.StatusCode, + JsonUtils.Deserialize(responseBody) + ); } } diff --git a/src/Merge.Client/Ticketing/Projects/Requests/ProjectsListRequest.cs b/src/Merge.Client/Ticketing/Projects/Requests/ProjectsListRequest.cs index 99605745..9e2201c4 100644 --- a/src/Merge.Client/Ticketing/Projects/Requests/ProjectsListRequest.cs +++ b/src/Merge.Client/Ticketing/Projects/Requests/ProjectsListRequest.cs @@ -1,49 +1,49 @@ namespace Merge.Client.Ticketing; -public class ProjectsListRequest +public record ProjectsListRequest { /// /// If provided, will only return objects created after this datetime. /// - public DateTime? CreatedAfter { get; init; } + public DateTime? CreatedAfter { get; set; } /// /// If provided, will only return objects created before this datetime. /// - public DateTime? CreatedBefore { get; init; } + public DateTime? CreatedBefore { get; set; } /// /// The pagination cursor value. /// - public string? Cursor { get; init; } + public string? Cursor { get; set; } /// /// Whether to include data that was marked as deleted by third party webhooks. /// - public bool? IncludeDeletedData { get; init; } + public bool? IncludeDeletedData { get; set; } /// /// Whether to include the original data Merge fetched from the third-party to produce these models. /// - public bool? IncludeRemoteData { get; init; } + public bool? IncludeRemoteData { get; set; } /// /// If provided, only objects synced by Merge after this date time will be returned. /// - public DateTime? ModifiedAfter { get; init; } + public DateTime? ModifiedAfter { get; set; } /// /// If provided, only objects synced by Merge before this date time will be returned. /// - public DateTime? ModifiedBefore { get; init; } + public DateTime? ModifiedBefore { get; set; } /// /// Number of results to return per page. /// - public int? PageSize { get; init; } + public int? PageSize { get; set; } /// /// The API provider's ID for the given object. /// - public string? RemoteId { get; init; } + public string? RemoteId { get; set; } } diff --git a/src/Merge.Client/Ticketing/Projects/Requests/ProjectsRetrieveRequest.cs b/src/Merge.Client/Ticketing/Projects/Requests/ProjectsRetrieveRequest.cs index 63e6871b..94d173bb 100644 --- a/src/Merge.Client/Ticketing/Projects/Requests/ProjectsRetrieveRequest.cs +++ b/src/Merge.Client/Ticketing/Projects/Requests/ProjectsRetrieveRequest.cs @@ -1,9 +1,9 @@ namespace Merge.Client.Ticketing; -public class ProjectsRetrieveRequest +public record ProjectsRetrieveRequest { /// /// Whether to include the original data Merge fetched from the third-party to produce these models. /// - public bool? IncludeRemoteData { get; init; } + public bool? IncludeRemoteData { get; set; } } diff --git a/src/Merge.Client/Ticketing/Projects/Requests/ProjectsUsersListRequest.cs b/src/Merge.Client/Ticketing/Projects/Requests/ProjectsUsersListRequest.cs index 864df043..93044729 100644 --- a/src/Merge.Client/Ticketing/Projects/Requests/ProjectsUsersListRequest.cs +++ b/src/Merge.Client/Ticketing/Projects/Requests/ProjectsUsersListRequest.cs @@ -1,33 +1,29 @@ -using Merge.Client.Ticketing; - -#nullable enable - namespace Merge.Client.Ticketing; -public class ProjectsUsersListRequest +public record ProjectsUsersListRequest { /// /// The pagination cursor value. /// - public string? Cursor { get; init; } + public string? Cursor { get; set; } /// /// Which relations should be returned in expanded form. Multiple relation names should be comma separated without spaces. /// - public ProjectsUsersListRequestExpand? Expand { get; init; } + public ProjectsUsersListRequestExpand? Expand { get; set; } /// /// Whether to include data that was marked as deleted by third party webhooks. /// - public bool? IncludeDeletedData { get; init; } + public bool? IncludeDeletedData { get; set; } /// /// Whether to include the original data Merge fetched from the third-party to produce these models. /// - public bool? IncludeRemoteData { get; init; } + public bool? IncludeRemoteData { get; set; } /// /// Number of results to return per page. /// - public int? PageSize { get; init; } + public int? PageSize { get; set; } } diff --git a/src/Merge.Client/Ticketing/Projects/Types/ProjectsUsersListRequestExpand.cs b/src/Merge.Client/Ticketing/Projects/Types/ProjectsUsersListRequestExpand.cs index af87a736..dee66fca 100644 --- a/src/Merge.Client/Ticketing/Projects/Types/ProjectsUsersListRequestExpand.cs +++ b/src/Merge.Client/Ticketing/Projects/Types/ProjectsUsersListRequestExpand.cs @@ -1,7 +1,6 @@ using System.Runtime.Serialization; using System.Text.Json.Serialization; using Merge.Client.Core; -using Merge.Client.Ticketing; #nullable enable diff --git a/src/Merge.Client/Ticketing/RegenerateKey/RegenerateKeyClient.cs b/src/Merge.Client/Ticketing/RegenerateKey/RegenerateKeyClient.cs index d401e18d..a1c65c31 100644 --- a/src/Merge.Client/Ticketing/RegenerateKey/RegenerateKeyClient.cs +++ b/src/Merge.Client/Ticketing/RegenerateKey/RegenerateKeyClient.cs @@ -1,6 +1,6 @@ +using System.Net.Http; using System.Text.Json; -using Merge.Client; -using Merge.Client.Ticketing; +using Merge.Client.Core; #nullable enable @@ -18,21 +18,38 @@ public RegenerateKeyClient(RawClient client) /// /// Exchange remote keys. /// - public async Task CreateAsync(RemoteKeyForRegenerationRequest request) + public async Task CreateAsync( + RemoteKeyForRegenerationRequest request, + RequestOptions? options = null + ) { var response = await _client.MakeRequestAsync( new RawClient.JsonApiRequest { + BaseUrl = _client.Options.BaseUrl, Method = HttpMethod.Post, Path = "ticketing/v1/regenerate-key", - Body = request + Body = request, + Options = options } ); - string responseBody = await response.Raw.Content.ReadAsStringAsync(); - if (response.StatusCode >= 200 && response.StatusCode < 400) + var responseBody = await response.Raw.Content.ReadAsStringAsync(); + if (response.StatusCode is >= 200 and < 400) { - return JsonSerializer.Deserialize(responseBody); + try + { + return JsonUtils.Deserialize(responseBody)!; + } + catch (JsonException e) + { + throw new MergeException("Failed to deserialize response", e); + } } - throw new Exception(responseBody); + + throw new MergeApiException( + $"Error with status code {response.StatusCode}", + response.StatusCode, + JsonUtils.Deserialize(responseBody) + ); } } diff --git a/src/Merge.Client/Ticketing/RegenerateKey/Requests/RemoteKeyForRegenerationRequest.cs b/src/Merge.Client/Ticketing/RegenerateKey/Requests/RemoteKeyForRegenerationRequest.cs index 18e26d60..80d88cf1 100644 --- a/src/Merge.Client/Ticketing/RegenerateKey/Requests/RemoteKeyForRegenerationRequest.cs +++ b/src/Merge.Client/Ticketing/RegenerateKey/Requests/RemoteKeyForRegenerationRequest.cs @@ -4,11 +4,11 @@ namespace Merge.Client.Ticketing; -public class RemoteKeyForRegenerationRequest +public record RemoteKeyForRegenerationRequest { /// /// The name of the remote key /// [JsonPropertyName("name")] - public string Name { get; init; } + public required string Name { get; set; } } diff --git a/src/Merge.Client/Ticketing/Roles/Requests/RolesListRequest.cs b/src/Merge.Client/Ticketing/Roles/Requests/RolesListRequest.cs index 26ad60a2..15b849ed 100644 --- a/src/Merge.Client/Ticketing/Roles/Requests/RolesListRequest.cs +++ b/src/Merge.Client/Ticketing/Roles/Requests/RolesListRequest.cs @@ -1,49 +1,49 @@ namespace Merge.Client.Ticketing; -public class RolesListRequest +public record RolesListRequest { /// /// If provided, will only return objects created after this datetime. /// - public DateTime? CreatedAfter { get; init; } + public DateTime? CreatedAfter { get; set; } /// /// If provided, will only return objects created before this datetime. /// - public DateTime? CreatedBefore { get; init; } + public DateTime? CreatedBefore { get; set; } /// /// The pagination cursor value. /// - public string? Cursor { get; init; } + public string? Cursor { get; set; } /// /// Whether to include data that was marked as deleted by third party webhooks. /// - public bool? IncludeDeletedData { get; init; } + public bool? IncludeDeletedData { get; set; } /// /// Whether to include the original data Merge fetched from the third-party to produce these models. /// - public bool? IncludeRemoteData { get; init; } + public bool? IncludeRemoteData { get; set; } /// /// If provided, only objects synced by Merge after this date time will be returned. /// - public DateTime? ModifiedAfter { get; init; } + public DateTime? ModifiedAfter { get; set; } /// /// If provided, only objects synced by Merge before this date time will be returned. /// - public DateTime? ModifiedBefore { get; init; } + public DateTime? ModifiedBefore { get; set; } /// /// Number of results to return per page. /// - public int? PageSize { get; init; } + public int? PageSize { get; set; } /// /// The API provider's ID for the given object. /// - public string? RemoteId { get; init; } + public string? RemoteId { get; set; } } diff --git a/src/Merge.Client/Ticketing/Roles/Requests/RolesRetrieveRequest.cs b/src/Merge.Client/Ticketing/Roles/Requests/RolesRetrieveRequest.cs index a2f146b1..4d0fdadc 100644 --- a/src/Merge.Client/Ticketing/Roles/Requests/RolesRetrieveRequest.cs +++ b/src/Merge.Client/Ticketing/Roles/Requests/RolesRetrieveRequest.cs @@ -1,9 +1,9 @@ namespace Merge.Client.Ticketing; -public class RolesRetrieveRequest +public record RolesRetrieveRequest { /// /// Whether to include the original data Merge fetched from the third-party to produce these models. /// - public bool? IncludeRemoteData { get; init; } + public bool? IncludeRemoteData { get; set; } } diff --git a/src/Merge.Client/Ticketing/Roles/RolesClient.cs b/src/Merge.Client/Ticketing/Roles/RolesClient.cs index 39fab211..b49a01f4 100644 --- a/src/Merge.Client/Ticketing/Roles/RolesClient.cs +++ b/src/Merge.Client/Ticketing/Roles/RolesClient.cs @@ -1,6 +1,6 @@ +using System.Net.Http; using System.Text.Json; -using Merge.Client; -using Merge.Client.Ticketing; +using Merge.Client.Core; #nullable enable @@ -18,16 +18,21 @@ public RolesClient(RawClient client) /// /// Returns a list of `Role` objects. /// - public async Task ListAsync(RolesListRequest request) + public async Task ListAsync( + RolesListRequest request, + RequestOptions? options = null + ) { var _query = new Dictionary() { }; if (request.CreatedAfter != null) { - _query["created_after"] = request.CreatedAfter.Value.ToString("o0"); + _query["created_after"] = request.CreatedAfter.Value.ToString(Constants.DateTimeFormat); } if (request.CreatedBefore != null) { - _query["created_before"] = request.CreatedBefore.Value.ToString("o0"); + _query["created_before"] = request.CreatedBefore.Value.ToString( + Constants.DateTimeFormat + ); } if (request.Cursor != null) { @@ -43,11 +48,15 @@ public async Task ListAsync(RolesListRequest request) } if (request.ModifiedAfter != null) { - _query["modified_after"] = request.ModifiedAfter.Value.ToString("o0"); + _query["modified_after"] = request.ModifiedAfter.Value.ToString( + Constants.DateTimeFormat + ); } if (request.ModifiedBefore != null) { - _query["modified_before"] = request.ModifiedBefore.Value.ToString("o0"); + _query["modified_before"] = request.ModifiedBefore.Value.ToString( + Constants.DateTimeFormat + ); } if (request.PageSize != null) { @@ -60,23 +69,41 @@ public async Task ListAsync(RolesListRequest request) var response = await _client.MakeRequestAsync( new RawClient.JsonApiRequest { + BaseUrl = _client.Options.BaseUrl, Method = HttpMethod.Get, Path = "ticketing/v1/roles", - Query = _query + Query = _query, + Options = options } ); - string responseBody = await response.Raw.Content.ReadAsStringAsync(); - if (response.StatusCode >= 200 && response.StatusCode < 400) + var responseBody = await response.Raw.Content.ReadAsStringAsync(); + if (response.StatusCode is >= 200 and < 400) { - return JsonSerializer.Deserialize(responseBody); + try + { + return JsonUtils.Deserialize(responseBody)!; + } + catch (JsonException e) + { + throw new MergeException("Failed to deserialize response", e); + } } - throw new Exception(responseBody); + + throw new MergeApiException( + $"Error with status code {response.StatusCode}", + response.StatusCode, + JsonUtils.Deserialize(responseBody) + ); } /// /// Returns a `Role` object with the given `id`. /// - public async Task RetrieveAsync(string id, RolesRetrieveRequest request) + public async Task RetrieveAsync( + string id, + RolesRetrieveRequest request, + RequestOptions? options = null + ) { var _query = new Dictionary() { }; if (request.IncludeRemoteData != null) @@ -86,16 +113,30 @@ public async Task RetrieveAsync(string id, RolesRetrieveRequest request) var response = await _client.MakeRequestAsync( new RawClient.JsonApiRequest { + BaseUrl = _client.Options.BaseUrl, Method = HttpMethod.Get, Path = $"ticketing/v1/roles/{id}", - Query = _query + Query = _query, + Options = options } ); - string responseBody = await response.Raw.Content.ReadAsStringAsync(); - if (response.StatusCode >= 200 && response.StatusCode < 400) + var responseBody = await response.Raw.Content.ReadAsStringAsync(); + if (response.StatusCode is >= 200 and < 400) { - return JsonSerializer.Deserialize(responseBody); + try + { + return JsonUtils.Deserialize(responseBody)!; + } + catch (JsonException e) + { + throw new MergeException("Failed to deserialize response", e); + } } - throw new Exception(responseBody); + + throw new MergeApiException( + $"Error with status code {response.StatusCode}", + response.StatusCode, + JsonUtils.Deserialize(responseBody) + ); } } diff --git a/src/Merge.Client/Ticketing/Scopes/Requests/LinkedAccountCommonModelScopeDeserializerRequest.cs b/src/Merge.Client/Ticketing/Scopes/Requests/LinkedAccountCommonModelScopeDeserializerRequest.cs index 7e94d7ed..62c8944a 100644 --- a/src/Merge.Client/Ticketing/Scopes/Requests/LinkedAccountCommonModelScopeDeserializerRequest.cs +++ b/src/Merge.Client/Ticketing/Scopes/Requests/LinkedAccountCommonModelScopeDeserializerRequest.cs @@ -1,15 +1,15 @@ using System.Text.Json.Serialization; -using Merge.Client.Ticketing; #nullable enable namespace Merge.Client.Ticketing; -public class LinkedAccountCommonModelScopeDeserializerRequest +public record LinkedAccountCommonModelScopeDeserializerRequest { /// /// The common models you want to update the scopes for /// [JsonPropertyName("common_models")] - public IEnumerable CommonModels { get; init; } + public IEnumerable CommonModels { get; set; } = + new List(); } diff --git a/src/Merge.Client/Ticketing/Scopes/ScopesClient.cs b/src/Merge.Client/Ticketing/Scopes/ScopesClient.cs index 5198b892..afaab075 100644 --- a/src/Merge.Client/Ticketing/Scopes/ScopesClient.cs +++ b/src/Merge.Client/Ticketing/Scopes/ScopesClient.cs @@ -1,6 +1,6 @@ +using System.Net.Http; using System.Text.Json; -using Merge.Client; -using Merge.Client.Ticketing; +using Merge.Client.Core; #nullable enable @@ -18,63 +18,110 @@ public ScopesClient(RawClient client) /// /// Get the default permissions for Merge Common Models and fields across all Linked Accounts of a given category. [Learn more](https://help.merge.dev/en/articles/8828211-common-model-and-field-scopes). /// - public async Task DefaultScopesRetrieveAsync() + public async Task DefaultScopesRetrieveAsync( + RequestOptions? options = null + ) { var response = await _client.MakeRequestAsync( new RawClient.JsonApiRequest { + BaseUrl = _client.Options.BaseUrl, Method = HttpMethod.Get, - Path = "ticketing/v1/default-scopes" + Path = "ticketing/v1/default-scopes", + Options = options } ); - string responseBody = await response.Raw.Content.ReadAsStringAsync(); - if (response.StatusCode >= 200 && response.StatusCode < 400) + var responseBody = await response.Raw.Content.ReadAsStringAsync(); + if (response.StatusCode is >= 200 and < 400) { - return JsonSerializer.Deserialize(responseBody); + try + { + return JsonUtils.Deserialize(responseBody)!; + } + catch (JsonException e) + { + throw new MergeException("Failed to deserialize response", e); + } } - throw new Exception(responseBody); + + throw new MergeApiException( + $"Error with status code {response.StatusCode}", + response.StatusCode, + JsonUtils.Deserialize(responseBody) + ); } /// /// Get all available permissions for Merge Common Models and fields for a single Linked Account. [Learn more](https://help.merge.dev/en/articles/8828211-common-model-and-field-scopes). /// - public async Task LinkedAccountScopesRetrieveAsync() + public async Task LinkedAccountScopesRetrieveAsync( + RequestOptions? options = null + ) { var response = await _client.MakeRequestAsync( new RawClient.JsonApiRequest { + BaseUrl = _client.Options.BaseUrl, Method = HttpMethod.Get, - Path = "ticketing/v1/linked-account-scopes" + Path = "ticketing/v1/linked-account-scopes", + Options = options } ); - string responseBody = await response.Raw.Content.ReadAsStringAsync(); - if (response.StatusCode >= 200 && response.StatusCode < 400) + var responseBody = await response.Raw.Content.ReadAsStringAsync(); + if (response.StatusCode is >= 200 and < 400) { - return JsonSerializer.Deserialize(responseBody); + try + { + return JsonUtils.Deserialize(responseBody)!; + } + catch (JsonException e) + { + throw new MergeException("Failed to deserialize response", e); + } } - throw new Exception(responseBody); + + throw new MergeApiException( + $"Error with status code {response.StatusCode}", + response.StatusCode, + JsonUtils.Deserialize(responseBody) + ); } /// /// Update permissions for any Common Model or field for a single Linked Account. Any Scopes not set in this POST request will inherit the default Scopes. [Learn more](https://help.merge.dev/en/articles/8828211-common-model-and-field-scopes) /// public async Task LinkedAccountScopesCreateAsync( - LinkedAccountCommonModelScopeDeserializerRequest request + LinkedAccountCommonModelScopeDeserializerRequest request, + RequestOptions? options = null ) { var response = await _client.MakeRequestAsync( new RawClient.JsonApiRequest { + BaseUrl = _client.Options.BaseUrl, Method = HttpMethod.Post, Path = "ticketing/v1/linked-account-scopes", - Body = request + Body = request, + Options = options } ); - string responseBody = await response.Raw.Content.ReadAsStringAsync(); - if (response.StatusCode >= 200 && response.StatusCode < 400) + var responseBody = await response.Raw.Content.ReadAsStringAsync(); + if (response.StatusCode is >= 200 and < 400) { - return JsonSerializer.Deserialize(responseBody); + try + { + return JsonUtils.Deserialize(responseBody)!; + } + catch (JsonException e) + { + throw new MergeException("Failed to deserialize response", e); + } } - throw new Exception(responseBody); + + throw new MergeApiException( + $"Error with status code {response.StatusCode}", + response.StatusCode, + JsonUtils.Deserialize(responseBody) + ); } } diff --git a/src/Merge.Client/Ticketing/SyncStatus/Requests/SyncStatusListRequest.cs b/src/Merge.Client/Ticketing/SyncStatus/Requests/SyncStatusListRequest.cs index 67d6381b..4bd3c83b 100644 --- a/src/Merge.Client/Ticketing/SyncStatus/Requests/SyncStatusListRequest.cs +++ b/src/Merge.Client/Ticketing/SyncStatus/Requests/SyncStatusListRequest.cs @@ -1,14 +1,14 @@ namespace Merge.Client.Ticketing; -public class SyncStatusListRequest +public record SyncStatusListRequest { /// /// The pagination cursor value. /// - public string? Cursor { get; init; } + public string? Cursor { get; set; } /// /// Number of results to return per page. /// - public int? PageSize { get; init; } + public int? PageSize { get; set; } } diff --git a/src/Merge.Client/Ticketing/SyncStatus/SyncStatusClient.cs b/src/Merge.Client/Ticketing/SyncStatus/SyncStatusClient.cs index f4c0d075..93143e20 100644 --- a/src/Merge.Client/Ticketing/SyncStatus/SyncStatusClient.cs +++ b/src/Merge.Client/Ticketing/SyncStatus/SyncStatusClient.cs @@ -1,6 +1,6 @@ +using System.Net.Http; using System.Text.Json; -using Merge.Client; -using Merge.Client.Ticketing; +using Merge.Client.Core; #nullable enable @@ -18,7 +18,10 @@ public SyncStatusClient(RawClient client) /// /// Get syncing status. Possible values: `DISABLED`, `DONE`, `FAILED`, `PARTIALLY_SYNCED`, `PAUSED`, `SYNCING`. Learn more about sync status in our [Help Center](https://help.merge.dev/en/articles/8184193-merge-sync-statuses). /// - public async Task ListAsync(SyncStatusListRequest request) + public async Task ListAsync( + SyncStatusListRequest request, + RequestOptions? options = null + ) { var _query = new Dictionary() { }; if (request.Cursor != null) @@ -32,16 +35,30 @@ public async Task ListAsync(SyncStatusListRequest reque var response = await _client.MakeRequestAsync( new RawClient.JsonApiRequest { + BaseUrl = _client.Options.BaseUrl, Method = HttpMethod.Get, Path = "ticketing/v1/sync-status", - Query = _query + Query = _query, + Options = options } ); - string responseBody = await response.Raw.Content.ReadAsStringAsync(); - if (response.StatusCode >= 200 && response.StatusCode < 400) + var responseBody = await response.Raw.Content.ReadAsStringAsync(); + if (response.StatusCode is >= 200 and < 400) { - return JsonSerializer.Deserialize(responseBody); + try + { + return JsonUtils.Deserialize(responseBody)!; + } + catch (JsonException e) + { + throw new MergeException("Failed to deserialize response", e); + } } - throw new Exception(responseBody); + + throw new MergeApiException( + $"Error with status code {response.StatusCode}", + response.StatusCode, + JsonUtils.Deserialize(responseBody) + ); } } diff --git a/src/Merge.Client/Ticketing/Tags/Requests/TagsListRequest.cs b/src/Merge.Client/Ticketing/Tags/Requests/TagsListRequest.cs index 2a12f0e5..c6793f1c 100644 --- a/src/Merge.Client/Ticketing/Tags/Requests/TagsListRequest.cs +++ b/src/Merge.Client/Ticketing/Tags/Requests/TagsListRequest.cs @@ -1,49 +1,49 @@ namespace Merge.Client.Ticketing; -public class TagsListRequest +public record TagsListRequest { /// /// If provided, will only return objects created after this datetime. /// - public DateTime? CreatedAfter { get; init; } + public DateTime? CreatedAfter { get; set; } /// /// If provided, will only return objects created before this datetime. /// - public DateTime? CreatedBefore { get; init; } + public DateTime? CreatedBefore { get; set; } /// /// The pagination cursor value. /// - public string? Cursor { get; init; } + public string? Cursor { get; set; } /// /// Whether to include data that was marked as deleted by third party webhooks. /// - public bool? IncludeDeletedData { get; init; } + public bool? IncludeDeletedData { get; set; } /// /// Whether to include the original data Merge fetched from the third-party to produce these models. /// - public bool? IncludeRemoteData { get; init; } + public bool? IncludeRemoteData { get; set; } /// /// If provided, only objects synced by Merge after this date time will be returned. /// - public DateTime? ModifiedAfter { get; init; } + public DateTime? ModifiedAfter { get; set; } /// /// If provided, only objects synced by Merge before this date time will be returned. /// - public DateTime? ModifiedBefore { get; init; } + public DateTime? ModifiedBefore { get; set; } /// /// Number of results to return per page. /// - public int? PageSize { get; init; } + public int? PageSize { get; set; } /// /// The API provider's ID for the given object. /// - public string? RemoteId { get; init; } + public string? RemoteId { get; set; } } diff --git a/src/Merge.Client/Ticketing/Tags/Requests/TagsRetrieveRequest.cs b/src/Merge.Client/Ticketing/Tags/Requests/TagsRetrieveRequest.cs index 14651aa9..d5678e3e 100644 --- a/src/Merge.Client/Ticketing/Tags/Requests/TagsRetrieveRequest.cs +++ b/src/Merge.Client/Ticketing/Tags/Requests/TagsRetrieveRequest.cs @@ -1,9 +1,9 @@ namespace Merge.Client.Ticketing; -public class TagsRetrieveRequest +public record TagsRetrieveRequest { /// /// Whether to include the original data Merge fetched from the third-party to produce these models. /// - public bool? IncludeRemoteData { get; init; } + public bool? IncludeRemoteData { get; set; } } diff --git a/src/Merge.Client/Ticketing/Tags/TagsClient.cs b/src/Merge.Client/Ticketing/Tags/TagsClient.cs index b91fd440..7d22afcc 100644 --- a/src/Merge.Client/Ticketing/Tags/TagsClient.cs +++ b/src/Merge.Client/Ticketing/Tags/TagsClient.cs @@ -1,6 +1,6 @@ +using System.Net.Http; using System.Text.Json; -using Merge.Client; -using Merge.Client.Ticketing; +using Merge.Client.Core; #nullable enable @@ -18,16 +18,21 @@ public TagsClient(RawClient client) /// /// Returns a list of `Tag` objects. /// - public async Task ListAsync(TagsListRequest request) + public async Task ListAsync( + TagsListRequest request, + RequestOptions? options = null + ) { var _query = new Dictionary() { }; if (request.CreatedAfter != null) { - _query["created_after"] = request.CreatedAfter.Value.ToString("o0"); + _query["created_after"] = request.CreatedAfter.Value.ToString(Constants.DateTimeFormat); } if (request.CreatedBefore != null) { - _query["created_before"] = request.CreatedBefore.Value.ToString("o0"); + _query["created_before"] = request.CreatedBefore.Value.ToString( + Constants.DateTimeFormat + ); } if (request.Cursor != null) { @@ -43,11 +48,15 @@ public async Task ListAsync(TagsListRequest request) } if (request.ModifiedAfter != null) { - _query["modified_after"] = request.ModifiedAfter.Value.ToString("o0"); + _query["modified_after"] = request.ModifiedAfter.Value.ToString( + Constants.DateTimeFormat + ); } if (request.ModifiedBefore != null) { - _query["modified_before"] = request.ModifiedBefore.Value.ToString("o0"); + _query["modified_before"] = request.ModifiedBefore.Value.ToString( + Constants.DateTimeFormat + ); } if (request.PageSize != null) { @@ -60,23 +69,41 @@ public async Task ListAsync(TagsListRequest request) var response = await _client.MakeRequestAsync( new RawClient.JsonApiRequest { + BaseUrl = _client.Options.BaseUrl, Method = HttpMethod.Get, Path = "ticketing/v1/tags", - Query = _query + Query = _query, + Options = options } ); - string responseBody = await response.Raw.Content.ReadAsStringAsync(); - if (response.StatusCode >= 200 && response.StatusCode < 400) + var responseBody = await response.Raw.Content.ReadAsStringAsync(); + if (response.StatusCode is >= 200 and < 400) { - return JsonSerializer.Deserialize(responseBody); + try + { + return JsonUtils.Deserialize(responseBody)!; + } + catch (JsonException e) + { + throw new MergeException("Failed to deserialize response", e); + } } - throw new Exception(responseBody); + + throw new MergeApiException( + $"Error with status code {response.StatusCode}", + response.StatusCode, + JsonUtils.Deserialize(responseBody) + ); } /// /// Returns a `Tag` object with the given `id`. /// - public async Task RetrieveAsync(string id, TagsRetrieveRequest request) + public async Task RetrieveAsync( + string id, + TagsRetrieveRequest request, + RequestOptions? options = null + ) { var _query = new Dictionary() { }; if (request.IncludeRemoteData != null) @@ -86,16 +113,30 @@ public async Task RetrieveAsync(string id, TagsRetrieveRequest request) var response = await _client.MakeRequestAsync( new RawClient.JsonApiRequest { + BaseUrl = _client.Options.BaseUrl, Method = HttpMethod.Get, Path = $"ticketing/v1/tags/{id}", - Query = _query + Query = _query, + Options = options } ); - string responseBody = await response.Raw.Content.ReadAsStringAsync(); - if (response.StatusCode >= 200 && response.StatusCode < 400) + var responseBody = await response.Raw.Content.ReadAsStringAsync(); + if (response.StatusCode is >= 200 and < 400) { - return JsonSerializer.Deserialize(responseBody); + try + { + return JsonUtils.Deserialize(responseBody)!; + } + catch (JsonException e) + { + throw new MergeException("Failed to deserialize response", e); + } } - throw new Exception(responseBody); + + throw new MergeApiException( + $"Error with status code {response.StatusCode}", + response.StatusCode, + JsonUtils.Deserialize(responseBody) + ); } } diff --git a/src/Merge.Client/Ticketing/Teams/Requests/TeamsListRequest.cs b/src/Merge.Client/Ticketing/Teams/Requests/TeamsListRequest.cs index 1dd16e0c..90bcc709 100644 --- a/src/Merge.Client/Ticketing/Teams/Requests/TeamsListRequest.cs +++ b/src/Merge.Client/Ticketing/Teams/Requests/TeamsListRequest.cs @@ -1,49 +1,49 @@ namespace Merge.Client.Ticketing; -public class TeamsListRequest +public record TeamsListRequest { /// /// If provided, will only return objects created after this datetime. /// - public DateTime? CreatedAfter { get; init; } + public DateTime? CreatedAfter { get; set; } /// /// If provided, will only return objects created before this datetime. /// - public DateTime? CreatedBefore { get; init; } + public DateTime? CreatedBefore { get; set; } /// /// The pagination cursor value. /// - public string? Cursor { get; init; } + public string? Cursor { get; set; } /// /// Whether to include data that was marked as deleted by third party webhooks. /// - public bool? IncludeDeletedData { get; init; } + public bool? IncludeDeletedData { get; set; } /// /// Whether to include the original data Merge fetched from the third-party to produce these models. /// - public bool? IncludeRemoteData { get; init; } + public bool? IncludeRemoteData { get; set; } /// /// If provided, only objects synced by Merge after this date time will be returned. /// - public DateTime? ModifiedAfter { get; init; } + public DateTime? ModifiedAfter { get; set; } /// /// If provided, only objects synced by Merge before this date time will be returned. /// - public DateTime? ModifiedBefore { get; init; } + public DateTime? ModifiedBefore { get; set; } /// /// Number of results to return per page. /// - public int? PageSize { get; init; } + public int? PageSize { get; set; } /// /// The API provider's ID for the given object. /// - public string? RemoteId { get; init; } + public string? RemoteId { get; set; } } diff --git a/src/Merge.Client/Ticketing/Teams/Requests/TeamsRetrieveRequest.cs b/src/Merge.Client/Ticketing/Teams/Requests/TeamsRetrieveRequest.cs index c4491c1f..ae5763cd 100644 --- a/src/Merge.Client/Ticketing/Teams/Requests/TeamsRetrieveRequest.cs +++ b/src/Merge.Client/Ticketing/Teams/Requests/TeamsRetrieveRequest.cs @@ -1,9 +1,9 @@ namespace Merge.Client.Ticketing; -public class TeamsRetrieveRequest +public record TeamsRetrieveRequest { /// /// Whether to include the original data Merge fetched from the third-party to produce these models. /// - public bool? IncludeRemoteData { get; init; } + public bool? IncludeRemoteData { get; set; } } diff --git a/src/Merge.Client/Ticketing/Teams/TeamsClient.cs b/src/Merge.Client/Ticketing/Teams/TeamsClient.cs index 29e00c9a..0bf59bbc 100644 --- a/src/Merge.Client/Ticketing/Teams/TeamsClient.cs +++ b/src/Merge.Client/Ticketing/Teams/TeamsClient.cs @@ -1,6 +1,6 @@ +using System.Net.Http; using System.Text.Json; -using Merge.Client; -using Merge.Client.Ticketing; +using Merge.Client.Core; #nullable enable @@ -18,16 +18,21 @@ public TeamsClient(RawClient client) /// /// Returns a list of `Team` objects. /// - public async Task ListAsync(TeamsListRequest request) + public async Task ListAsync( + TeamsListRequest request, + RequestOptions? options = null + ) { var _query = new Dictionary() { }; if (request.CreatedAfter != null) { - _query["created_after"] = request.CreatedAfter.Value.ToString("o0"); + _query["created_after"] = request.CreatedAfter.Value.ToString(Constants.DateTimeFormat); } if (request.CreatedBefore != null) { - _query["created_before"] = request.CreatedBefore.Value.ToString("o0"); + _query["created_before"] = request.CreatedBefore.Value.ToString( + Constants.DateTimeFormat + ); } if (request.Cursor != null) { @@ -43,11 +48,15 @@ public async Task ListAsync(TeamsListRequest request) } if (request.ModifiedAfter != null) { - _query["modified_after"] = request.ModifiedAfter.Value.ToString("o0"); + _query["modified_after"] = request.ModifiedAfter.Value.ToString( + Constants.DateTimeFormat + ); } if (request.ModifiedBefore != null) { - _query["modified_before"] = request.ModifiedBefore.Value.ToString("o0"); + _query["modified_before"] = request.ModifiedBefore.Value.ToString( + Constants.DateTimeFormat + ); } if (request.PageSize != null) { @@ -60,23 +69,41 @@ public async Task ListAsync(TeamsListRequest request) var response = await _client.MakeRequestAsync( new RawClient.JsonApiRequest { + BaseUrl = _client.Options.BaseUrl, Method = HttpMethod.Get, Path = "ticketing/v1/teams", - Query = _query + Query = _query, + Options = options } ); - string responseBody = await response.Raw.Content.ReadAsStringAsync(); - if (response.StatusCode >= 200 && response.StatusCode < 400) + var responseBody = await response.Raw.Content.ReadAsStringAsync(); + if (response.StatusCode is >= 200 and < 400) { - return JsonSerializer.Deserialize(responseBody); + try + { + return JsonUtils.Deserialize(responseBody)!; + } + catch (JsonException e) + { + throw new MergeException("Failed to deserialize response", e); + } } - throw new Exception(responseBody); + + throw new MergeApiException( + $"Error with status code {response.StatusCode}", + response.StatusCode, + JsonUtils.Deserialize(responseBody) + ); } /// /// Returns a `Team` object with the given `id`. /// - public async Task RetrieveAsync(string id, TeamsRetrieveRequest request) + public async Task RetrieveAsync( + string id, + TeamsRetrieveRequest request, + RequestOptions? options = null + ) { var _query = new Dictionary() { }; if (request.IncludeRemoteData != null) @@ -86,16 +113,30 @@ public async Task RetrieveAsync(string id, TeamsRetrieveRequest request) var response = await _client.MakeRequestAsync( new RawClient.JsonApiRequest { + BaseUrl = _client.Options.BaseUrl, Method = HttpMethod.Get, Path = $"ticketing/v1/teams/{id}", - Query = _query + Query = _query, + Options = options } ); - string responseBody = await response.Raw.Content.ReadAsStringAsync(); - if (response.StatusCode >= 200 && response.StatusCode < 400) + var responseBody = await response.Raw.Content.ReadAsStringAsync(); + if (response.StatusCode is >= 200 and < 400) { - return JsonSerializer.Deserialize(responseBody); + try + { + return JsonUtils.Deserialize(responseBody)!; + } + catch (JsonException e) + { + throw new MergeException("Failed to deserialize response", e); + } } - throw new Exception(responseBody); + + throw new MergeApiException( + $"Error with status code {response.StatusCode}", + response.StatusCode, + JsonUtils.Deserialize(responseBody) + ); } } diff --git a/src/Merge.Client/Ticketing/TicketingClient.cs b/src/Merge.Client/Ticketing/TicketingClient.cs index ab07bb3c..ab1cca82 100644 --- a/src/Merge.Client/Ticketing/TicketingClient.cs +++ b/src/Merge.Client/Ticketing/TicketingClient.cs @@ -1,5 +1,4 @@ -using Merge.Client; -using Merge.Client.Ticketing; +using Merge.Client.Core; #nullable enable diff --git a/src/Merge.Client/Ticketing/Tickets/Requests/PatchedTicketEndpointRequest.cs b/src/Merge.Client/Ticketing/Tickets/Requests/PatchedTicketEndpointRequest.cs index dd008f88..d3fd76ba 100644 --- a/src/Merge.Client/Ticketing/Tickets/Requests/PatchedTicketEndpointRequest.cs +++ b/src/Merge.Client/Ticketing/Tickets/Requests/PatchedTicketEndpointRequest.cs @@ -1,20 +1,16 @@ -using Merge.Client.Ticketing; - -#nullable enable - namespace Merge.Client.Ticketing; -public class PatchedTicketEndpointRequest +public record PatchedTicketEndpointRequest { /// /// Whether to include debug fields (such as log file links) in the response. /// - public bool? IsDebugMode { get; init; } + public bool? IsDebugMode { get; set; } /// /// Whether or not third-party updates should be run asynchronously. /// - public bool? RunAsync { get; init; } + public bool? RunAsync { get; set; } - public PatchedTicketRequest Model { get; init; } + public required PatchedTicketRequest Model { get; set; } } diff --git a/src/Merge.Client/Ticketing/Tickets/Requests/TicketEndpointRequest.cs b/src/Merge.Client/Ticketing/Tickets/Requests/TicketEndpointRequest.cs index 670c61d2..8872898f 100644 --- a/src/Merge.Client/Ticketing/Tickets/Requests/TicketEndpointRequest.cs +++ b/src/Merge.Client/Ticketing/Tickets/Requests/TicketEndpointRequest.cs @@ -1,20 +1,16 @@ -using Merge.Client.Ticketing; - -#nullable enable - namespace Merge.Client.Ticketing; -public class TicketEndpointRequest +public record TicketEndpointRequest { /// /// Whether to include debug fields (such as log file links) in the response. /// - public bool? IsDebugMode { get; init; } + public bool? IsDebugMode { get; set; } /// /// Whether or not third-party updates should be run asynchronously. /// - public bool? RunAsync { get; init; } + public bool? RunAsync { get; set; } - public TicketRequest Model { get; init; } + public required TicketRequest Model { get; set; } } diff --git a/src/Merge.Client/Ticketing/Tickets/Requests/TicketsCollaboratorsListRequest.cs b/src/Merge.Client/Ticketing/Tickets/Requests/TicketsCollaboratorsListRequest.cs index 68b270ad..c1580a21 100644 --- a/src/Merge.Client/Ticketing/Tickets/Requests/TicketsCollaboratorsListRequest.cs +++ b/src/Merge.Client/Ticketing/Tickets/Requests/TicketsCollaboratorsListRequest.cs @@ -1,33 +1,29 @@ -using Merge.Client.Ticketing; - -#nullable enable - namespace Merge.Client.Ticketing; -public class TicketsCollaboratorsListRequest +public record TicketsCollaboratorsListRequest { /// /// The pagination cursor value. /// - public string? Cursor { get; init; } + public string? Cursor { get; set; } /// /// Which relations should be returned in expanded form. Multiple relation names should be comma separated without spaces. /// - public TicketsCollaboratorsListRequestExpand? Expand { get; init; } + public TicketsCollaboratorsListRequestExpand? Expand { get; set; } /// /// Whether to include data that was marked as deleted by third party webhooks. /// - public bool? IncludeDeletedData { get; init; } + public bool? IncludeDeletedData { get; set; } /// /// Whether to include the original data Merge fetched from the third-party to produce these models. /// - public bool? IncludeRemoteData { get; init; } + public bool? IncludeRemoteData { get; set; } /// /// Number of results to return per page. /// - public int? PageSize { get; init; } + public int? PageSize { get; set; } } diff --git a/src/Merge.Client/Ticketing/Tickets/Requests/TicketsListRequest.cs b/src/Merge.Client/Ticketing/Tickets/Requests/TicketsListRequest.cs index 3ea6d10a..129dd6dd 100644 --- a/src/Merge.Client/Ticketing/Tickets/Requests/TicketsListRequest.cs +++ b/src/Merge.Client/Ticketing/Tickets/Requests/TicketsListRequest.cs @@ -1,105 +1,101 @@ -using Merge.Client.Ticketing; - -#nullable enable - namespace Merge.Client.Ticketing; -public class TicketsListRequest +public record TicketsListRequest { /// /// If provided, will only return tickets for this account. /// - public string? AccountId { get; init; } + public string? AccountId { get; set; } /// /// If provided, will only return tickets assigned to the assignee_ids; multiple assignee_ids can be separated by commas. /// - public string? AssigneeIds { get; init; } + public string? AssigneeIds { get; set; } /// /// If provided, will only return tickets assigned to the collection_ids; multiple collection_ids can be separated by commas. /// - public string? CollectionIds { get; init; } + public string? CollectionIds { get; set; } /// /// If provided, will only return tickets completed after this datetime. /// - public DateTime? CompletedAfter { get; init; } + public DateTime? CompletedAfter { get; set; } /// /// If provided, will only return tickets completed before this datetime. /// - public DateTime? CompletedBefore { get; init; } + public DateTime? CompletedBefore { get; set; } /// /// If provided, will only return tickets for this contact. /// - public string? ContactId { get; init; } + public string? ContactId { get; set; } /// /// If provided, will only return objects created after this datetime. /// - public DateTime? CreatedAfter { get; init; } + public DateTime? CreatedAfter { get; set; } /// /// If provided, will only return objects created before this datetime. /// - public DateTime? CreatedBefore { get; init; } + public DateTime? CreatedBefore { get; set; } /// /// The pagination cursor value. /// - public string? Cursor { get; init; } + public string? Cursor { get; set; } /// /// If provided, will only return tickets due after this datetime. /// - public DateTime? DueAfter { get; init; } + public DateTime? DueAfter { get; set; } /// /// If provided, will only return tickets due before this datetime. /// - public DateTime? DueBefore { get; init; } + public DateTime? DueBefore { get; set; } /// /// Which relations should be returned in expanded form. Multiple relation names should be comma separated without spaces. /// - public TicketsListRequestExpand? Expand { get; init; } + public TicketsListRequestExpand? Expand { get; set; } /// /// Whether to include data that was marked as deleted by third party webhooks. /// - public bool? IncludeDeletedData { get; init; } + public bool? IncludeDeletedData { get; set; } /// /// Whether to include the original data Merge fetched from the third-party to produce these models. /// - public bool? IncludeRemoteData { get; init; } + public bool? IncludeRemoteData { get; set; } /// /// Whether to include all remote fields, including fields that Merge did not map to common models, in a normalized format. /// - public bool? IncludeRemoteFields { get; init; } + public bool? IncludeRemoteFields { get; set; } /// /// If provided, only objects synced by Merge after this date time will be returned. /// - public DateTime? ModifiedAfter { get; init; } + public DateTime? ModifiedAfter { get; set; } /// /// If provided, only objects synced by Merge before this date time will be returned. /// - public DateTime? ModifiedBefore { get; init; } + public DateTime? ModifiedBefore { get; set; } /// /// Number of results to return per page. /// - public int? PageSize { get; init; } + public int? PageSize { get; set; } /// /// If provided, will only return sub tickets of the parent_ticket_id. /// - public string? ParentTicketId { get; init; } + public string? ParentTicketId { get; set; } /// /// If provided, will only return tickets of this priority. @@ -109,42 +105,42 @@ public class TicketsListRequest /// - `NORMAL` - NORMAL /// - `LOW` - LOW /// - public TicketsListRequestPriority? Priority { get; init; } + public TicketsListRequestPriority? Priority { get; set; } /// /// If provided, will only return tickets created in the third party platform after this datetime. /// - public DateTime? RemoteCreatedAfter { get; init; } + public DateTime? RemoteCreatedAfter { get; set; } /// /// If provided, will only return tickets created in the third party platform before this datetime. /// - public DateTime? RemoteCreatedBefore { get; init; } + public DateTime? RemoteCreatedBefore { get; set; } /// /// Deprecated. Use show_enum_origins. /// - public TicketsListRequestRemoteFields? RemoteFields { get; init; } + public TicketsListRequestRemoteFields? RemoteFields { get; set; } /// /// The API provider's ID for the given object. /// - public string? RemoteId { get; init; } + public string? RemoteId { get; set; } /// /// If provided, will only return tickets updated in the third party platform after this datetime. /// - public DateTime? RemoteUpdatedAfter { get; init; } + public DateTime? RemoteUpdatedAfter { get; set; } /// /// If provided, will only return tickets updated in the third party platform before this datetime. /// - public DateTime? RemoteUpdatedBefore { get; init; } + public DateTime? RemoteUpdatedBefore { get; set; } /// /// A comma separated list of enum field names for which you'd like the original values to be returned, instead of Merge's normalized enum values. [Learn more](https://help.merge.dev/en/articles/8950958-show_enum_origins-query-parameter) /// - public TicketsListRequestShowEnumOrigins? ShowEnumOrigins { get; init; } + public TicketsListRequestShowEnumOrigins? ShowEnumOrigins { get; set; } /// /// If provided, will only return tickets of this status. @@ -154,20 +150,20 @@ public class TicketsListRequest /// - `IN_PROGRESS` - IN_PROGRESS /// - `ON_HOLD` - ON_HOLD /// - public TicketsListRequestStatus? Status { get; init; } + public TicketsListRequestStatus? Status { get; set; } /// /// If provided, will only return tickets matching the tags; multiple tags can be separated by commas. /// - public string? Tags { get; init; } + public string? Tags { get; set; } /// /// If provided, will only return tickets of this type. /// - public string? TicketType { get; init; } + public string? TicketType { get; set; } /// /// If provided, will only return tickets where the URL matches or contains the substring /// - public string? TicketUrl { get; init; } + public string? TicketUrl { get; set; } } diff --git a/src/Merge.Client/Ticketing/Tickets/Requests/TicketsRemoteFieldClassesListRequest.cs b/src/Merge.Client/Ticketing/Tickets/Requests/TicketsRemoteFieldClassesListRequest.cs index f15fc9ba..5cda3726 100644 --- a/src/Merge.Client/Ticketing/Tickets/Requests/TicketsRemoteFieldClassesListRequest.cs +++ b/src/Merge.Client/Ticketing/Tickets/Requests/TicketsRemoteFieldClassesListRequest.cs @@ -1,29 +1,29 @@ namespace Merge.Client.Ticketing; -public class TicketsRemoteFieldClassesListRequest +public record TicketsRemoteFieldClassesListRequest { /// /// The pagination cursor value. /// - public string? Cursor { get; init; } + public string? Cursor { get; set; } /// /// Whether to include data that was marked as deleted by third party webhooks. /// - public bool? IncludeDeletedData { get; init; } + public bool? IncludeDeletedData { get; set; } /// /// Whether to include the original data Merge fetched from the third-party to produce these models. /// - public bool? IncludeRemoteData { get; init; } + public bool? IncludeRemoteData { get; set; } /// /// If provided, will only return remote field classes with this is_common_model_field value /// - public bool? IsCommonModelField { get; init; } + public bool? IsCommonModelField { get; set; } /// /// Number of results to return per page. /// - public int? PageSize { get; init; } + public int? PageSize { get; set; } } diff --git a/src/Merge.Client/Ticketing/Tickets/Requests/TicketsRetrieveRequest.cs b/src/Merge.Client/Ticketing/Tickets/Requests/TicketsRetrieveRequest.cs index aab92375..988377d6 100644 --- a/src/Merge.Client/Ticketing/Tickets/Requests/TicketsRetrieveRequest.cs +++ b/src/Merge.Client/Ticketing/Tickets/Requests/TicketsRetrieveRequest.cs @@ -1,33 +1,29 @@ -using Merge.Client.Ticketing; - -#nullable enable - namespace Merge.Client.Ticketing; -public class TicketsRetrieveRequest +public record TicketsRetrieveRequest { /// /// Which relations should be returned in expanded form. Multiple relation names should be comma separated without spaces. /// - public TicketsRetrieveRequestExpand? Expand { get; init; } + public TicketsRetrieveRequestExpand? Expand { get; set; } /// /// Whether to include the original data Merge fetched from the third-party to produce these models. /// - public bool? IncludeRemoteData { get; init; } + public bool? IncludeRemoteData { get; set; } /// /// Whether to include all remote fields, including fields that Merge did not map to common models, in a normalized format. /// - public bool? IncludeRemoteFields { get; init; } + public bool? IncludeRemoteFields { get; set; } /// /// Deprecated. Use show_enum_origins. /// - public TicketsRetrieveRequestRemoteFields? RemoteFields { get; init; } + public TicketsRetrieveRequestRemoteFields? RemoteFields { get; set; } /// /// A comma separated list of enum field names for which you'd like the original values to be returned, instead of Merge's normalized enum values. [Learn more](https://help.merge.dev/en/articles/8950958-show_enum_origins-query-parameter) /// - public TicketsRetrieveRequestShowEnumOrigins? ShowEnumOrigins { get; init; } + public TicketsRetrieveRequestShowEnumOrigins? ShowEnumOrigins { get; set; } } diff --git a/src/Merge.Client/Ticketing/Tickets/TicketsClient.cs b/src/Merge.Client/Ticketing/Tickets/TicketsClient.cs index 58a6822e..09cbfebe 100644 --- a/src/Merge.Client/Ticketing/Tickets/TicketsClient.cs +++ b/src/Merge.Client/Ticketing/Tickets/TicketsClient.cs @@ -1,6 +1,6 @@ +using System.Net.Http; using System.Text.Json; -using Merge.Client; -using Merge.Client.Ticketing; +using Merge.Client.Core; #nullable enable @@ -18,7 +18,10 @@ public TicketsClient(RawClient client) /// /// Returns a list of `Ticket` objects. /// - public async Task ListAsync(TicketsListRequest request) + public async Task ListAsync( + TicketsListRequest request, + RequestOptions? options = null + ) { var _query = new Dictionary() { }; if (request.AccountId != null) @@ -35,11 +38,15 @@ public async Task ListAsync(TicketsListRequest request) } if (request.CompletedAfter != null) { - _query["completed_after"] = request.CompletedAfter.Value.ToString("o0"); + _query["completed_after"] = request.CompletedAfter.Value.ToString( + Constants.DateTimeFormat + ); } if (request.CompletedBefore != null) { - _query["completed_before"] = request.CompletedBefore.Value.ToString("o0"); + _query["completed_before"] = request.CompletedBefore.Value.ToString( + Constants.DateTimeFormat + ); } if (request.ContactId != null) { @@ -47,11 +54,13 @@ public async Task ListAsync(TicketsListRequest request) } if (request.CreatedAfter != null) { - _query["created_after"] = request.CreatedAfter.Value.ToString("o0"); + _query["created_after"] = request.CreatedAfter.Value.ToString(Constants.DateTimeFormat); } if (request.CreatedBefore != null) { - _query["created_before"] = request.CreatedBefore.Value.ToString("o0"); + _query["created_before"] = request.CreatedBefore.Value.ToString( + Constants.DateTimeFormat + ); } if (request.Cursor != null) { @@ -59,11 +68,11 @@ public async Task ListAsync(TicketsListRequest request) } if (request.DueAfter != null) { - _query["due_after"] = request.DueAfter.Value.ToString("o0"); + _query["due_after"] = request.DueAfter.Value.ToString(Constants.DateTimeFormat); } if (request.DueBefore != null) { - _query["due_before"] = request.DueBefore.Value.ToString("o0"); + _query["due_before"] = request.DueBefore.Value.ToString(Constants.DateTimeFormat); } if (request.Expand != null) { @@ -83,11 +92,15 @@ public async Task ListAsync(TicketsListRequest request) } if (request.ModifiedAfter != null) { - _query["modified_after"] = request.ModifiedAfter.Value.ToString("o0"); + _query["modified_after"] = request.ModifiedAfter.Value.ToString( + Constants.DateTimeFormat + ); } if (request.ModifiedBefore != null) { - _query["modified_before"] = request.ModifiedBefore.Value.ToString("o0"); + _query["modified_before"] = request.ModifiedBefore.Value.ToString( + Constants.DateTimeFormat + ); } if (request.PageSize != null) { @@ -103,11 +116,15 @@ public async Task ListAsync(TicketsListRequest request) } if (request.RemoteCreatedAfter != null) { - _query["remote_created_after"] = request.RemoteCreatedAfter.Value.ToString("o0"); + _query["remote_created_after"] = request.RemoteCreatedAfter.Value.ToString( + Constants.DateTimeFormat + ); } if (request.RemoteCreatedBefore != null) { - _query["remote_created_before"] = request.RemoteCreatedBefore.Value.ToString("o0"); + _query["remote_created_before"] = request.RemoteCreatedBefore.Value.ToString( + Constants.DateTimeFormat + ); } if (request.RemoteFields != null) { @@ -119,11 +136,15 @@ public async Task ListAsync(TicketsListRequest request) } if (request.RemoteUpdatedAfter != null) { - _query["remote_updated_after"] = request.RemoteUpdatedAfter.Value.ToString("o0"); + _query["remote_updated_after"] = request.RemoteUpdatedAfter.Value.ToString( + Constants.DateTimeFormat + ); } if (request.RemoteUpdatedBefore != null) { - _query["remote_updated_before"] = request.RemoteUpdatedBefore.Value.ToString("o0"); + _query["remote_updated_before"] = request.RemoteUpdatedBefore.Value.ToString( + Constants.DateTimeFormat + ); } if (request.ShowEnumOrigins != null) { @@ -148,23 +169,40 @@ public async Task ListAsync(TicketsListRequest request) var response = await _client.MakeRequestAsync( new RawClient.JsonApiRequest { + BaseUrl = _client.Options.BaseUrl, Method = HttpMethod.Get, Path = "ticketing/v1/tickets", - Query = _query + Query = _query, + Options = options } ); - string responseBody = await response.Raw.Content.ReadAsStringAsync(); - if (response.StatusCode >= 200 && response.StatusCode < 400) + var responseBody = await response.Raw.Content.ReadAsStringAsync(); + if (response.StatusCode is >= 200 and < 400) { - return JsonSerializer.Deserialize(responseBody); + try + { + return JsonUtils.Deserialize(responseBody)!; + } + catch (JsonException e) + { + throw new MergeException("Failed to deserialize response", e); + } } - throw new Exception(responseBody); + + throw new MergeApiException( + $"Error with status code {response.StatusCode}", + response.StatusCode, + JsonUtils.Deserialize(responseBody) + ); } /// /// Creates a `Ticket` object with the given values. /// - public async Task CreateAsync(TicketEndpointRequest request) + public async Task CreateAsync( + TicketEndpointRequest request, + RequestOptions? options = null + ) { var _query = new Dictionary() { }; if (request.IsDebugMode != null) @@ -178,23 +216,41 @@ public async Task CreateAsync(TicketEndpointRequest request) var response = await _client.MakeRequestAsync( new RawClient.JsonApiRequest { + BaseUrl = _client.Options.BaseUrl, Method = HttpMethod.Post, Path = "ticketing/v1/tickets", - Query = _query + Query = _query, + Options = options } ); - string responseBody = await response.Raw.Content.ReadAsStringAsync(); - if (response.StatusCode >= 200 && response.StatusCode < 400) + var responseBody = await response.Raw.Content.ReadAsStringAsync(); + if (response.StatusCode is >= 200 and < 400) { - return JsonSerializer.Deserialize(responseBody); + try + { + return JsonUtils.Deserialize(responseBody)!; + } + catch (JsonException e) + { + throw new MergeException("Failed to deserialize response", e); + } } - throw new Exception(responseBody); + + throw new MergeApiException( + $"Error with status code {response.StatusCode}", + response.StatusCode, + JsonUtils.Deserialize(responseBody) + ); } /// /// Returns a `Ticket` object with the given `id`. /// - public async Task RetrieveAsync(string id, TicketsRetrieveRequest request) + public async Task RetrieveAsync( + string id, + TicketsRetrieveRequest request, + RequestOptions? options = null + ) { var _query = new Dictionary() { }; if (request.Expand != null) @@ -220,17 +276,31 @@ public async Task RetrieveAsync(string id, TicketsRetrieveRequest reques var response = await _client.MakeRequestAsync( new RawClient.JsonApiRequest { + BaseUrl = _client.Options.BaseUrl, Method = HttpMethod.Get, Path = $"ticketing/v1/tickets/{id}", - Query = _query + Query = _query, + Options = options } ); - string responseBody = await response.Raw.Content.ReadAsStringAsync(); - if (response.StatusCode >= 200 && response.StatusCode < 400) + var responseBody = await response.Raw.Content.ReadAsStringAsync(); + if (response.StatusCode is >= 200 and < 400) { - return JsonSerializer.Deserialize(responseBody); + try + { + return JsonUtils.Deserialize(responseBody)!; + } + catch (JsonException e) + { + throw new MergeException("Failed to deserialize response", e); + } } - throw new Exception(responseBody); + + throw new MergeApiException( + $"Error with status code {response.StatusCode}", + response.StatusCode, + JsonUtils.Deserialize(responseBody) + ); } /// @@ -238,7 +308,8 @@ public async Task RetrieveAsync(string id, TicketsRetrieveRequest reques /// public async Task PartialUpdateAsync( string id, - PatchedTicketEndpointRequest request + PatchedTicketEndpointRequest request, + RequestOptions? options = null ) { var _query = new Dictionary() { }; @@ -253,17 +324,31 @@ PatchedTicketEndpointRequest request var response = await _client.MakeRequestAsync( new RawClient.JsonApiRequest { - Method = HttpMethod.Patch, + BaseUrl = _client.Options.BaseUrl, + Method = HttpMethodExtensions.Patch, Path = $"ticketing/v1/tickets/{id}", - Query = _query + Query = _query, + Options = options } ); - string responseBody = await response.Raw.Content.ReadAsStringAsync(); - if (response.StatusCode >= 200 && response.StatusCode < 400) + var responseBody = await response.Raw.Content.ReadAsStringAsync(); + if (response.StatusCode is >= 200 and < 400) { - return JsonSerializer.Deserialize(responseBody); + try + { + return JsonUtils.Deserialize(responseBody)!; + } + catch (JsonException e) + { + throw new MergeException("Failed to deserialize response", e); + } } - throw new Exception(responseBody); + + throw new MergeApiException( + $"Error with status code {response.StatusCode}", + response.StatusCode, + JsonUtils.Deserialize(responseBody) + ); } /// @@ -271,7 +356,8 @@ PatchedTicketEndpointRequest request /// public async Task CollaboratorsListAsync( string parentId, - TicketsCollaboratorsListRequest request + TicketsCollaboratorsListRequest request, + RequestOptions? options = null ) { var _query = new Dictionary() { }; @@ -298,64 +384,110 @@ TicketsCollaboratorsListRequest request var response = await _client.MakeRequestAsync( new RawClient.JsonApiRequest { + BaseUrl = _client.Options.BaseUrl, Method = HttpMethod.Get, Path = $"ticketing/v1/tickets/{parentId}/collaborators", - Query = _query + Query = _query, + Options = options } ); - string responseBody = await response.Raw.Content.ReadAsStringAsync(); - if (response.StatusCode >= 200 && response.StatusCode < 400) + var responseBody = await response.Raw.Content.ReadAsStringAsync(); + if (response.StatusCode is >= 200 and < 400) { - return JsonSerializer.Deserialize(responseBody); + try + { + return JsonUtils.Deserialize(responseBody)!; + } + catch (JsonException e) + { + throw new MergeException("Failed to deserialize response", e); + } } - throw new Exception(responseBody); + + throw new MergeApiException( + $"Error with status code {response.StatusCode}", + response.StatusCode, + JsonUtils.Deserialize(responseBody) + ); } /// /// Returns metadata for `Ticket` PATCHs. /// - public async Task MetaPatchRetrieveAsync(string id) + public async Task MetaPatchRetrieveAsync( + string id, + RequestOptions? options = null + ) { var response = await _client.MakeRequestAsync( new RawClient.JsonApiRequest { + BaseUrl = _client.Options.BaseUrl, Method = HttpMethod.Get, - Path = $"ticketing/v1/tickets/meta/patch/{id}" + Path = $"ticketing/v1/tickets/meta/patch/{id}", + Options = options } ); - string responseBody = await response.Raw.Content.ReadAsStringAsync(); - if (response.StatusCode >= 200 && response.StatusCode < 400) + var responseBody = await response.Raw.Content.ReadAsStringAsync(); + if (response.StatusCode is >= 200 and < 400) { - return JsonSerializer.Deserialize(responseBody); + try + { + return JsonUtils.Deserialize(responseBody)!; + } + catch (JsonException e) + { + throw new MergeException("Failed to deserialize response", e); + } } - throw new Exception(responseBody); + + throw new MergeApiException( + $"Error with status code {response.StatusCode}", + response.StatusCode, + JsonUtils.Deserialize(responseBody) + ); } /// /// Returns metadata for `Ticket` POSTs. /// - public async Task MetaPostRetrieveAsync() + public async Task MetaPostRetrieveAsync(RequestOptions? options = null) { var response = await _client.MakeRequestAsync( new RawClient.JsonApiRequest { + BaseUrl = _client.Options.BaseUrl, Method = HttpMethod.Get, - Path = "ticketing/v1/tickets/meta/post" + Path = "ticketing/v1/tickets/meta/post", + Options = options } ); - string responseBody = await response.Raw.Content.ReadAsStringAsync(); - if (response.StatusCode >= 200 && response.StatusCode < 400) + var responseBody = await response.Raw.Content.ReadAsStringAsync(); + if (response.StatusCode is >= 200 and < 400) { - return JsonSerializer.Deserialize(responseBody); + try + { + return JsonUtils.Deserialize(responseBody)!; + } + catch (JsonException e) + { + throw new MergeException("Failed to deserialize response", e); + } } - throw new Exception(responseBody); + + throw new MergeApiException( + $"Error with status code {response.StatusCode}", + response.StatusCode, + JsonUtils.Deserialize(responseBody) + ); } /// /// Returns a list of `RemoteFieldClass` objects. /// public async Task RemoteFieldClassesListAsync( - TicketsRemoteFieldClassesListRequest request + TicketsRemoteFieldClassesListRequest request, + RequestOptions? options = null ) { var _query = new Dictionary() { }; @@ -382,16 +514,30 @@ TicketsRemoteFieldClassesListRequest request var response = await _client.MakeRequestAsync( new RawClient.JsonApiRequest { + BaseUrl = _client.Options.BaseUrl, Method = HttpMethod.Get, Path = "ticketing/v1/tickets/remote-field-classes", - Query = _query + Query = _query, + Options = options } ); - string responseBody = await response.Raw.Content.ReadAsStringAsync(); - if (response.StatusCode >= 200 && response.StatusCode < 400) + var responseBody = await response.Raw.Content.ReadAsStringAsync(); + if (response.StatusCode is >= 200 and < 400) { - return JsonSerializer.Deserialize(responseBody); + try + { + return JsonUtils.Deserialize(responseBody)!; + } + catch (JsonException e) + { + throw new MergeException("Failed to deserialize response", e); + } } - throw new Exception(responseBody); + + throw new MergeApiException( + $"Error with status code {response.StatusCode}", + response.StatusCode, + JsonUtils.Deserialize(responseBody) + ); } } diff --git a/src/Merge.Client/Ticketing/Tickets/Types/TicketsCollaboratorsListRequestExpand.cs b/src/Merge.Client/Ticketing/Tickets/Types/TicketsCollaboratorsListRequestExpand.cs index dc04d0a4..faa38048 100644 --- a/src/Merge.Client/Ticketing/Tickets/Types/TicketsCollaboratorsListRequestExpand.cs +++ b/src/Merge.Client/Ticketing/Tickets/Types/TicketsCollaboratorsListRequestExpand.cs @@ -1,7 +1,6 @@ using System.Runtime.Serialization; using System.Text.Json.Serialization; using Merge.Client.Core; -using Merge.Client.Ticketing; #nullable enable diff --git a/src/Merge.Client/Ticketing/Tickets/Types/TicketsListRequestExpand.cs b/src/Merge.Client/Ticketing/Tickets/Types/TicketsListRequestExpand.cs index 2e257794..0f324a47 100644 --- a/src/Merge.Client/Ticketing/Tickets/Types/TicketsListRequestExpand.cs +++ b/src/Merge.Client/Ticketing/Tickets/Types/TicketsListRequestExpand.cs @@ -1,7 +1,6 @@ using System.Runtime.Serialization; using System.Text.Json.Serialization; using Merge.Client.Core; -using Merge.Client.Ticketing; #nullable enable diff --git a/src/Merge.Client/Ticketing/Tickets/Types/TicketsListRequestPriority.cs b/src/Merge.Client/Ticketing/Tickets/Types/TicketsListRequestPriority.cs index d4dc155e..7a5d2ae5 100644 --- a/src/Merge.Client/Ticketing/Tickets/Types/TicketsListRequestPriority.cs +++ b/src/Merge.Client/Ticketing/Tickets/Types/TicketsListRequestPriority.cs @@ -1,7 +1,6 @@ using System.Runtime.Serialization; using System.Text.Json.Serialization; using Merge.Client.Core; -using Merge.Client.Ticketing; #nullable enable diff --git a/src/Merge.Client/Ticketing/Tickets/Types/TicketsListRequestRemoteFields.cs b/src/Merge.Client/Ticketing/Tickets/Types/TicketsListRequestRemoteFields.cs index 76cbf3a7..2c8de532 100644 --- a/src/Merge.Client/Ticketing/Tickets/Types/TicketsListRequestRemoteFields.cs +++ b/src/Merge.Client/Ticketing/Tickets/Types/TicketsListRequestRemoteFields.cs @@ -1,7 +1,6 @@ using System.Runtime.Serialization; using System.Text.Json.Serialization; using Merge.Client.Core; -using Merge.Client.Ticketing; #nullable enable diff --git a/src/Merge.Client/Ticketing/Tickets/Types/TicketsListRequestShowEnumOrigins.cs b/src/Merge.Client/Ticketing/Tickets/Types/TicketsListRequestShowEnumOrigins.cs index 05e11600..9ee1d4fe 100644 --- a/src/Merge.Client/Ticketing/Tickets/Types/TicketsListRequestShowEnumOrigins.cs +++ b/src/Merge.Client/Ticketing/Tickets/Types/TicketsListRequestShowEnumOrigins.cs @@ -1,7 +1,6 @@ using System.Runtime.Serialization; using System.Text.Json.Serialization; using Merge.Client.Core; -using Merge.Client.Ticketing; #nullable enable diff --git a/src/Merge.Client/Ticketing/Tickets/Types/TicketsListRequestStatus.cs b/src/Merge.Client/Ticketing/Tickets/Types/TicketsListRequestStatus.cs index 5903abe2..70a5b8f8 100644 --- a/src/Merge.Client/Ticketing/Tickets/Types/TicketsListRequestStatus.cs +++ b/src/Merge.Client/Ticketing/Tickets/Types/TicketsListRequestStatus.cs @@ -1,7 +1,6 @@ using System.Runtime.Serialization; using System.Text.Json.Serialization; using Merge.Client.Core; -using Merge.Client.Ticketing; #nullable enable diff --git a/src/Merge.Client/Ticketing/Tickets/Types/TicketsRetrieveRequestExpand.cs b/src/Merge.Client/Ticketing/Tickets/Types/TicketsRetrieveRequestExpand.cs index 57f39173..f9e6709c 100644 --- a/src/Merge.Client/Ticketing/Tickets/Types/TicketsRetrieveRequestExpand.cs +++ b/src/Merge.Client/Ticketing/Tickets/Types/TicketsRetrieveRequestExpand.cs @@ -1,7 +1,6 @@ using System.Runtime.Serialization; using System.Text.Json.Serialization; using Merge.Client.Core; -using Merge.Client.Ticketing; #nullable enable diff --git a/src/Merge.Client/Ticketing/Tickets/Types/TicketsRetrieveRequestRemoteFields.cs b/src/Merge.Client/Ticketing/Tickets/Types/TicketsRetrieveRequestRemoteFields.cs index 0301f612..6c8ac56d 100644 --- a/src/Merge.Client/Ticketing/Tickets/Types/TicketsRetrieveRequestRemoteFields.cs +++ b/src/Merge.Client/Ticketing/Tickets/Types/TicketsRetrieveRequestRemoteFields.cs @@ -1,7 +1,6 @@ using System.Runtime.Serialization; using System.Text.Json.Serialization; using Merge.Client.Core; -using Merge.Client.Ticketing; #nullable enable diff --git a/src/Merge.Client/Ticketing/Tickets/Types/TicketsRetrieveRequestShowEnumOrigins.cs b/src/Merge.Client/Ticketing/Tickets/Types/TicketsRetrieveRequestShowEnumOrigins.cs index 2df8e594..6986f9e3 100644 --- a/src/Merge.Client/Ticketing/Tickets/Types/TicketsRetrieveRequestShowEnumOrigins.cs +++ b/src/Merge.Client/Ticketing/Tickets/Types/TicketsRetrieveRequestShowEnumOrigins.cs @@ -1,7 +1,6 @@ using System.Runtime.Serialization; using System.Text.Json.Serialization; using Merge.Client.Core; -using Merge.Client.Ticketing; #nullable enable diff --git a/src/Merge.Client/Ticketing/Types/AccessLevelEnum.cs b/src/Merge.Client/Ticketing/Types/AccessLevelEnum.cs index 11310259..24608e0c 100644 --- a/src/Merge.Client/Ticketing/Types/AccessLevelEnum.cs +++ b/src/Merge.Client/Ticketing/Types/AccessLevelEnum.cs @@ -1,7 +1,6 @@ using System.Runtime.Serialization; using System.Text.Json.Serialization; using Merge.Client.Core; -using Merge.Client.Ticketing; #nullable enable diff --git a/src/Merge.Client/Ticketing/Types/Account.cs b/src/Merge.Client/Ticketing/Types/Account.cs index f64b910b..3b4115c1 100644 --- a/src/Merge.Client/Ticketing/Types/Account.cs +++ b/src/Merge.Client/Ticketing/Types/Account.cs @@ -1,54 +1,53 @@ using System.Text.Json.Serialization; -using Merge.Client.Ticketing; #nullable enable namespace Merge.Client.Ticketing; -public class Account +public record Account { [JsonPropertyName("id")] - public string? Id { get; init; } + public string? Id { get; set; } /// /// The third-party API ID of the matching object. /// [JsonPropertyName("remote_id")] - public string? RemoteId { get; init; } + public string? RemoteId { get; set; } /// /// The datetime that this object was created by Merge. /// [JsonPropertyName("created_at")] - public DateTime? CreatedAt { get; init; } + public DateTime? CreatedAt { get; set; } /// /// The datetime that this object was modified by Merge. /// [JsonPropertyName("modified_at")] - public DateTime? ModifiedAt { get; init; } + public DateTime? ModifiedAt { get; set; } /// /// The account's name. /// [JsonPropertyName("name")] - public string? Name { get; init; } + public string? Name { get; set; } /// /// The account's domain names. /// [JsonPropertyName("domains")] - public IEnumerable? Domains { get; init; } + public IEnumerable? Domains { get; set; } /// /// Indicates whether or not this object has been deleted in the third party platform. /// [JsonPropertyName("remote_was_deleted")] - public bool? RemoteWasDeleted { get; init; } + public bool? RemoteWasDeleted { get; set; } [JsonPropertyName("field_mappings")] - public Dictionary? FieldMappings { get; init; } + public Dictionary? FieldMappings { get; set; } [JsonPropertyName("remote_data")] - public IEnumerable? RemoteData { get; init; } + public IEnumerable? RemoteData { get; set; } } diff --git a/src/Merge.Client/Ticketing/Types/AccountDetails.cs b/src/Merge.Client/Ticketing/Types/AccountDetails.cs index daccbddb..d906db55 100644 --- a/src/Merge.Client/Ticketing/Types/AccountDetails.cs +++ b/src/Merge.Client/Ticketing/Types/AccountDetails.cs @@ -1,45 +1,44 @@ using System.Text.Json.Serialization; -using Merge.Client.Ticketing; #nullable enable namespace Merge.Client.Ticketing; -public class AccountDetails +public record AccountDetails { [JsonPropertyName("id")] - public string? Id { get; init; } + public string? Id { get; set; } [JsonPropertyName("integration")] - public string? Integration { get; init; } + public string? Integration { get; set; } [JsonPropertyName("integration_slug")] - public string? IntegrationSlug { get; init; } + public string? IntegrationSlug { get; set; } [JsonPropertyName("category")] - public CategoryEnum? Category { get; init; } + public CategoryEnum? Category { get; set; } [JsonPropertyName("end_user_origin_id")] - public string? EndUserOriginId { get; init; } + public string? EndUserOriginId { get; set; } [JsonPropertyName("end_user_organization_name")] - public string? EndUserOrganizationName { get; init; } + public string? EndUserOrganizationName { get; set; } [JsonPropertyName("end_user_email_address")] - public string? EndUserEmailAddress { get; init; } + public string? EndUserEmailAddress { get; set; } [JsonPropertyName("status")] - public string? Status { get; init; } + public string? Status { get; set; } [JsonPropertyName("webhook_listener_url")] - public string? WebhookListenerUrl { get; init; } + public string? WebhookListenerUrl { get; set; } /// /// Whether a Production Linked Account's credentials match another existing Production Linked Account. This field is `null` for Test Linked Accounts, incomplete Production Linked Accounts, and ignored duplicate Production Linked Account sets. /// [JsonPropertyName("is_duplicate")] - public bool? IsDuplicate { get; init; } + public bool? IsDuplicate { get; set; } [JsonPropertyName("account_type")] - public string? AccountType { get; init; } + public string? AccountType { get; set; } } diff --git a/src/Merge.Client/Ticketing/Types/AccountDetailsAndActions.cs b/src/Merge.Client/Ticketing/Types/AccountDetailsAndActions.cs index 1d801a12..13293a16 100644 --- a/src/Merge.Client/Ticketing/Types/AccountDetailsAndActions.cs +++ b/src/Merge.Client/Ticketing/Types/AccountDetailsAndActions.cs @@ -1,51 +1,50 @@ using System.Text.Json.Serialization; -using Merge.Client.Ticketing; #nullable enable namespace Merge.Client.Ticketing; -public class AccountDetailsAndActions +public record AccountDetailsAndActions { [JsonPropertyName("id")] - public string Id { get; init; } + public required string Id { get; set; } [JsonPropertyName("category")] - public CategoryEnum? Category { get; init; } + public CategoryEnum? Category { get; set; } [JsonPropertyName("status")] - public AccountDetailsAndActionsStatusEnum Status { get; init; } + public required AccountDetailsAndActionsStatusEnum Status { get; set; } [JsonPropertyName("status_detail")] - public string? StatusDetail { get; init; } + public string? StatusDetail { get; set; } [JsonPropertyName("end_user_origin_id")] - public string? EndUserOriginId { get; init; } + public string? EndUserOriginId { get; set; } [JsonPropertyName("end_user_organization_name")] - public string EndUserOrganizationName { get; init; } + public required string EndUserOrganizationName { get; set; } [JsonPropertyName("end_user_email_address")] - public string EndUserEmailAddress { get; init; } + public required string EndUserEmailAddress { get; set; } /// /// The tenant or domain the customer has provided access to. /// [JsonPropertyName("subdomain")] - public string? Subdomain { get; init; } + public string? Subdomain { get; set; } [JsonPropertyName("webhook_listener_url")] - public string WebhookListenerUrl { get; init; } + public required string WebhookListenerUrl { get; set; } /// /// Whether a Production Linked Account's credentials match another existing Production Linked Account. This field is `null` for Test Linked Accounts, incomplete Production Linked Accounts, and ignored duplicate Production Linked Account sets. /// [JsonPropertyName("is_duplicate")] - public bool? IsDuplicate { get; init; } + public bool? IsDuplicate { get; set; } [JsonPropertyName("integration")] - public AccountDetailsAndActionsIntegration? Integration { get; init; } + public AccountDetailsAndActionsIntegration? Integration { get; set; } [JsonPropertyName("account_type")] - public string AccountType { get; init; } + public required string AccountType { get; set; } } diff --git a/src/Merge.Client/Ticketing/Types/AccountDetailsAndActionsIntegration.cs b/src/Merge.Client/Ticketing/Types/AccountDetailsAndActionsIntegration.cs index e1e98e77..acf21d97 100644 --- a/src/Merge.Client/Ticketing/Types/AccountDetailsAndActionsIntegration.cs +++ b/src/Merge.Client/Ticketing/Types/AccountDetailsAndActionsIntegration.cs @@ -1,33 +1,32 @@ using System.Text.Json.Serialization; -using Merge.Client.Ticketing; #nullable enable namespace Merge.Client.Ticketing; -public class AccountDetailsAndActionsIntegration +public record AccountDetailsAndActionsIntegration { [JsonPropertyName("name")] - public string Name { get; init; } + public required string Name { get; set; } [JsonPropertyName("categories")] - public IEnumerable Categories { get; init; } + public IEnumerable Categories { get; set; } = new List(); [JsonPropertyName("image")] - public string? Image { get; init; } + public string? Image { get; set; } [JsonPropertyName("square_image")] - public string? SquareImage { get; init; } + public string? SquareImage { get; set; } [JsonPropertyName("color")] - public string Color { get; init; } + public required string Color { get; set; } [JsonPropertyName("slug")] - public string Slug { get; init; } + public required string Slug { get; set; } [JsonPropertyName("passthrough_available")] - public bool PassthroughAvailable { get; init; } + public required bool PassthroughAvailable { get; set; } [JsonPropertyName("available_model_operations")] - public IEnumerable? AvailableModelOperations { get; init; } + public IEnumerable? AvailableModelOperations { get; set; } } diff --git a/src/Merge.Client/Ticketing/Types/AccountDetailsAndActionsStatusEnum.cs b/src/Merge.Client/Ticketing/Types/AccountDetailsAndActionsStatusEnum.cs index f7e0e2ab..03350e77 100644 --- a/src/Merge.Client/Ticketing/Types/AccountDetailsAndActionsStatusEnum.cs +++ b/src/Merge.Client/Ticketing/Types/AccountDetailsAndActionsStatusEnum.cs @@ -1,7 +1,6 @@ using System.Runtime.Serialization; using System.Text.Json.Serialization; using Merge.Client.Core; -using Merge.Client.Ticketing; #nullable enable diff --git a/src/Merge.Client/Ticketing/Types/AccountIntegration.cs b/src/Merge.Client/Ticketing/Types/AccountIntegration.cs index dc925923..9df0d351 100644 --- a/src/Merge.Client/Ticketing/Types/AccountIntegration.cs +++ b/src/Merge.Client/Ticketing/Types/AccountIntegration.cs @@ -1,66 +1,65 @@ using System.Text.Json.Serialization; -using Merge.Client.Ticketing; #nullable enable namespace Merge.Client.Ticketing; -public class AccountIntegration +public record AccountIntegration { /// /// Company name. /// [JsonPropertyName("name")] - public string Name { get; init; } + public required string Name { get; set; } /// /// Optional. This shortened name appears in places with limited space, usually in conjunction with the platform's logo (e.g., Merge Link menu).

Example: Workforce Now (in lieu of ADP Workforce Now), SuccessFactors (in lieu of SAP SuccessFactors) ///
[JsonPropertyName("abbreviated_name")] - public string? AbbreviatedName { get; init; } + public string? AbbreviatedName { get; set; } /// /// Category or categories this integration belongs to. Multiple categories should be comma separated, i.e. [ats, hris]. /// [JsonPropertyName("categories")] - public IEnumerable? Categories { get; init; } + public IEnumerable? Categories { get; set; } /// /// Company logo in rectangular shape. Upload an image with a clear background. /// [JsonPropertyName("image")] - public string? Image { get; init; } + public string? Image { get; set; } /// /// Company logo in square shape. Upload an image with a white background. /// [JsonPropertyName("square_image")] - public string? SquareImage { get; init; } + public string? SquareImage { get; set; } /// /// The color of this integration used for buttons and text throughout the app and landing pages. Choose a darker, saturated color. /// [JsonPropertyName("color")] - public string? Color { get; init; } + public string? Color { get; set; } [JsonPropertyName("slug")] - public string? Slug { get; init; } + public string? Slug { get; set; } /// /// Mapping of API endpoints to documentation urls for support. Example: {'GET': [['/common-model-scopes', 'https://docs.merge.dev/accounting/common-model-scopes/#common_model_scopes_retrieve'],['/common-model-actions', 'https://docs.merge.dev/accounting/common-model-actions/#common_model_actions_retrieve']], 'POST': []} /// [JsonPropertyName("api_endpoints_to_documentation_urls")] - public Dictionary? ApiEndpointsToDocumentationUrls { get; init; } + public Dictionary? ApiEndpointsToDocumentationUrls { get; set; } /// /// Setup guide URL for third party webhook creation. Exposed in Merge Docs. /// [JsonPropertyName("webhook_setup_guide_url")] - public string? WebhookSetupGuideUrl { get; init; } + public string? WebhookSetupGuideUrl { get; set; } /// /// Category or categories this integration is in beta status for. /// [JsonPropertyName("category_beta_status")] - public Dictionary? CategoryBetaStatus { get; init; } + public Dictionary? CategoryBetaStatus { get; set; } } diff --git a/src/Merge.Client/Ticketing/Types/AccountToken.cs b/src/Merge.Client/Ticketing/Types/AccountToken.cs index b82b9e4e..abff3507 100644 --- a/src/Merge.Client/Ticketing/Types/AccountToken.cs +++ b/src/Merge.Client/Ticketing/Types/AccountToken.cs @@ -1,15 +1,14 @@ using System.Text.Json.Serialization; -using Merge.Client.Ticketing; #nullable enable namespace Merge.Client.Ticketing; -public class AccountToken +public record AccountToken { [JsonPropertyName("account_token")] - public string AccountToken_ { get; init; } + public required string AccountToken_ { get; set; } [JsonPropertyName("integration")] - public AccountIntegration Integration { get; init; } + public required AccountIntegration Integration { get; set; } } diff --git a/src/Merge.Client/Ticketing/Types/AdvancedMetadata.cs b/src/Merge.Client/Ticketing/Types/AdvancedMetadata.cs index 81dc6626..26141ab5 100644 --- a/src/Merge.Client/Ticketing/Types/AdvancedMetadata.cs +++ b/src/Merge.Client/Ticketing/Types/AdvancedMetadata.cs @@ -4,23 +4,23 @@ namespace Merge.Client.Ticketing; -public class AdvancedMetadata +public record AdvancedMetadata { [JsonPropertyName("id")] - public string Id { get; init; } + public required string Id { get; set; } [JsonPropertyName("display_name")] - public string? DisplayName { get; init; } + public string? DisplayName { get; set; } [JsonPropertyName("description")] - public string? Description { get; init; } + public string? Description { get; set; } [JsonPropertyName("is_required")] - public bool? IsRequired { get; init; } + public bool? IsRequired { get; set; } [JsonPropertyName("is_custom")] - public bool? IsCustom { get; init; } + public bool? IsCustom { get; set; } [JsonPropertyName("field_choices")] - public IEnumerable? FieldChoices { get; init; } + public IEnumerable? FieldChoices { get; set; } } diff --git a/src/Merge.Client/Ticketing/Types/AsyncPassthroughReciept.cs b/src/Merge.Client/Ticketing/Types/AsyncPassthroughReciept.cs index d177f468..48717831 100644 --- a/src/Merge.Client/Ticketing/Types/AsyncPassthroughReciept.cs +++ b/src/Merge.Client/Ticketing/Types/AsyncPassthroughReciept.cs @@ -4,8 +4,8 @@ namespace Merge.Client.Ticketing; -public class AsyncPassthroughReciept +public record AsyncPassthroughReciept { [JsonPropertyName("async_passthrough_receipt_id")] - public string AsyncPassthroughReceiptId { get; init; } + public required string AsyncPassthroughReceiptId { get; set; } } diff --git a/src/Merge.Client/Ticketing/Types/Attachment.cs b/src/Merge.Client/Ticketing/Types/Attachment.cs index 2e925b38..ab587168 100644 --- a/src/Merge.Client/Ticketing/Types/Attachment.cs +++ b/src/Merge.Client/Ticketing/Types/Attachment.cs @@ -1,78 +1,77 @@ using System.Text.Json.Serialization; using Merge.Client.Core; -using Merge.Client.Ticketing; using OneOf; #nullable enable namespace Merge.Client.Ticketing; -public class Attachment +public record Attachment { [JsonPropertyName("id")] - public string? Id { get; init; } + public string? Id { get; set; } /// /// The third-party API ID of the matching object. /// [JsonPropertyName("remote_id")] - public string? RemoteId { get; init; } + public string? RemoteId { get; set; } /// /// The datetime that this object was created by Merge. /// [JsonPropertyName("created_at")] - public DateTime? CreatedAt { get; init; } + public DateTime? CreatedAt { get; set; } /// /// The datetime that this object was modified by Merge. /// [JsonPropertyName("modified_at")] - public DateTime? ModifiedAt { get; init; } + public DateTime? ModifiedAt { get; set; } /// /// The attachment's name. It is required to include the file extension in the attachment's name. /// [JsonPropertyName("file_name")] - public string? FileName { get; init; } + public string? FileName { get; set; } /// /// The ticket associated with the attachment. /// [JsonPropertyName("ticket")] [JsonConverter(typeof(OneOfSerializer>))] - public OneOf? Ticket { get; init; } + public OneOf? Ticket { get; set; } /// /// The attachment's url. It is required to include the file extension in the file's URL. /// [JsonPropertyName("file_url")] - public string? FileUrl { get; init; } + public string? FileUrl { get; set; } /// /// The attachment's file format. /// [JsonPropertyName("content_type")] - public string? ContentType { get; init; } + public string? ContentType { get; set; } /// /// The user who uploaded the attachment. /// [JsonPropertyName("uploaded_by")] - public string? UploadedBy { get; init; } + public string? UploadedBy { get; set; } /// /// When the third party's attachment was created. /// [JsonPropertyName("remote_created_at")] - public DateTime? RemoteCreatedAt { get; init; } + public DateTime? RemoteCreatedAt { get; set; } [JsonPropertyName("remote_was_deleted")] - public bool? RemoteWasDeleted { get; init; } + public bool? RemoteWasDeleted { get; set; } [JsonPropertyName("field_mappings")] - public Dictionary? FieldMappings { get; init; } + public Dictionary? FieldMappings { get; set; } [JsonPropertyName("remote_data")] - public IEnumerable? RemoteData { get; init; } + public IEnumerable? RemoteData { get; set; } } diff --git a/src/Merge.Client/Ticketing/Types/AttachmentRequest.cs b/src/Merge.Client/Ticketing/Types/AttachmentRequest.cs index 2fcacf37..c50af590 100644 --- a/src/Merge.Client/Ticketing/Types/AttachmentRequest.cs +++ b/src/Merge.Client/Ticketing/Types/AttachmentRequest.cs @@ -1,48 +1,47 @@ using System.Text.Json.Serialization; using Merge.Client.Core; -using Merge.Client.Ticketing; using OneOf; #nullable enable namespace Merge.Client.Ticketing; -public class AttachmentRequest +public record AttachmentRequest { /// /// The attachment's name. It is required to include the file extension in the attachment's name. /// [JsonPropertyName("file_name")] - public string? FileName { get; init; } + public string? FileName { get; set; } /// /// The ticket associated with the attachment. /// [JsonPropertyName("ticket")] [JsonConverter(typeof(OneOfSerializer>))] - public OneOf? Ticket { get; init; } + public OneOf? Ticket { get; set; } /// /// The attachment's url. It is required to include the file extension in the file's URL. /// [JsonPropertyName("file_url")] - public string? FileUrl { get; init; } + public string? FileUrl { get; set; } /// /// The attachment's file format. /// [JsonPropertyName("content_type")] - public string? ContentType { get; init; } + public string? ContentType { get; set; } /// /// The user who uploaded the attachment. /// [JsonPropertyName("uploaded_by")] - public string? UploadedBy { get; init; } + public string? UploadedBy { get; set; } [JsonPropertyName("integration_params")] - public Dictionary? IntegrationParams { get; init; } + public Dictionary? IntegrationParams { get; set; } [JsonPropertyName("linked_account_params")] - public Dictionary? LinkedAccountParams { get; init; } + public Dictionary? LinkedAccountParams { get; set; } } diff --git a/src/Merge.Client/Ticketing/Types/AuditLogEvent.cs b/src/Merge.Client/Ticketing/Types/AuditLogEvent.cs index 0db65c84..d34c2502 100644 --- a/src/Merge.Client/Ticketing/Types/AuditLogEvent.cs +++ b/src/Merge.Client/Ticketing/Types/AuditLogEvent.cs @@ -1,26 +1,25 @@ using System.Text.Json.Serialization; -using Merge.Client.Ticketing; #nullable enable namespace Merge.Client.Ticketing; -public class AuditLogEvent +public record AuditLogEvent { [JsonPropertyName("id")] - public string? Id { get; init; } + public string? Id { get; set; } /// /// The User's full name at the time of this Event occurring. /// [JsonPropertyName("user_name")] - public string? UserName { get; init; } + public string? UserName { get; set; } /// /// The User's email at the time of this Event occurring. /// [JsonPropertyName("user_email")] - public string? UserEmail { get; init; } + public string? UserEmail { get; set; } /// /// Designates the role of the user (or SYSTEM/API if action not taken by a user) at the time of this Event occurring. @@ -33,10 +32,10 @@ public class AuditLogEvent /// - `MERGE_TEAM` - MERGE_TEAM /// [JsonPropertyName("role")] - public RoleEnum Role { get; init; } + public required RoleEnum Role { get; set; } [JsonPropertyName("ip_address")] - public string IpAddress { get; init; } + public required string IpAddress { get; set; } /// /// Designates the type of event that occurred. @@ -81,11 +80,11 @@ public class AuditLogEvent /// - `END_USER_CREDENTIALS_ACCESSED` - END_USER_CREDENTIALS_ACCESSED /// [JsonPropertyName("event_type")] - public EventTypeEnum EventType { get; init; } + public required EventTypeEnum EventType { get; set; } [JsonPropertyName("event_description")] - public string EventDescription { get; init; } + public required string EventDescription { get; set; } [JsonPropertyName("created_at")] - public DateTime? CreatedAt { get; init; } + public DateTime? CreatedAt { get; set; } } diff --git a/src/Merge.Client/Ticketing/Types/AvailableActions.cs b/src/Merge.Client/Ticketing/Types/AvailableActions.cs index d1870272..7e100a4e 100644 --- a/src/Merge.Client/Ticketing/Types/AvailableActions.cs +++ b/src/Merge.Client/Ticketing/Types/AvailableActions.cs @@ -1,18 +1,17 @@ using System.Text.Json.Serialization; -using Merge.Client.Ticketing; #nullable enable namespace Merge.Client.Ticketing; -public class AvailableActions +public record AvailableActions { [JsonPropertyName("integration")] - public AccountIntegration Integration { get; init; } + public required AccountIntegration Integration { get; set; } [JsonPropertyName("passthrough_available")] - public bool PassthroughAvailable { get; init; } + public required bool PassthroughAvailable { get; set; } [JsonPropertyName("available_model_operations")] - public IEnumerable? AvailableModelOperations { get; init; } + public IEnumerable? AvailableModelOperations { get; set; } } diff --git a/src/Merge.Client/Ticketing/Types/CategoriesEnum.cs b/src/Merge.Client/Ticketing/Types/CategoriesEnum.cs index a943641b..faa85b29 100644 --- a/src/Merge.Client/Ticketing/Types/CategoriesEnum.cs +++ b/src/Merge.Client/Ticketing/Types/CategoriesEnum.cs @@ -1,7 +1,6 @@ using System.Runtime.Serialization; using System.Text.Json.Serialization; using Merge.Client.Core; -using Merge.Client.Ticketing; #nullable enable diff --git a/src/Merge.Client/Ticketing/Types/CategoryEnum.cs b/src/Merge.Client/Ticketing/Types/CategoryEnum.cs index fab6a60e..f6c6b672 100644 --- a/src/Merge.Client/Ticketing/Types/CategoryEnum.cs +++ b/src/Merge.Client/Ticketing/Types/CategoryEnum.cs @@ -1,7 +1,6 @@ using System.Runtime.Serialization; using System.Text.Json.Serialization; using Merge.Client.Core; -using Merge.Client.Ticketing; #nullable enable diff --git a/src/Merge.Client/Ticketing/Types/Collection.cs b/src/Merge.Client/Ticketing/Types/Collection.cs index 39ab8e4b..ad163c33 100644 --- a/src/Merge.Client/Ticketing/Types/Collection.cs +++ b/src/Merge.Client/Ticketing/Types/Collection.cs @@ -1,46 +1,45 @@ using System.Text.Json.Serialization; using Merge.Client.Core; -using Merge.Client.Ticketing; using OneOf; #nullable enable namespace Merge.Client.Ticketing; -public class Collection +public record Collection { [JsonPropertyName("id")] - public string? Id { get; init; } + public string? Id { get; set; } /// /// The third-party API ID of the matching object. /// [JsonPropertyName("remote_id")] - public string? RemoteId { get; init; } + public string? RemoteId { get; set; } /// /// The datetime that this object was created by Merge. /// [JsonPropertyName("created_at")] - public DateTime? CreatedAt { get; init; } + public DateTime? CreatedAt { get; set; } /// /// The datetime that this object was modified by Merge. /// [JsonPropertyName("modified_at")] - public DateTime? ModifiedAt { get; init; } + public DateTime? ModifiedAt { get; set; } /// /// The collection's name. /// [JsonPropertyName("name")] - public string? Name { get; init; } + public string? Name { get; set; } /// /// The collection's description. /// [JsonPropertyName("description")] - public string? Description { get; init; } + public string? Description { get; set; } /// /// The collection's type. @@ -49,20 +48,20 @@ public class Collection /// - `PROJECT` - PROJECT /// [JsonPropertyName("collection_type")] - public CollectionTypeEnum? CollectionType { get; init; } + public CollectionTypeEnum? CollectionType { get; set; } /// /// The parent collection for this collection. /// [JsonPropertyName("parent_collection")] [JsonConverter(typeof(OneOfSerializer>))] - public OneOf? ParentCollection { get; init; } + public OneOf? ParentCollection { get; set; } /// /// Indicates whether or not this object has been deleted in the third party platform. /// [JsonPropertyName("remote_was_deleted")] - public bool? RemoteWasDeleted { get; init; } + public bool? RemoteWasDeleted { get; set; } /// /// The level of access a User has to the Collection and its sub-objects. @@ -72,11 +71,11 @@ public class Collection /// - `PUBLIC` - PUBLIC /// [JsonPropertyName("access_level")] - public AccessLevelEnum? AccessLevel { get; init; } + public AccessLevelEnum? AccessLevel { get; set; } [JsonPropertyName("field_mappings")] - public Dictionary? FieldMappings { get; init; } + public Dictionary? FieldMappings { get; set; } [JsonPropertyName("remote_data")] - public IEnumerable? RemoteData { get; init; } + public IEnumerable? RemoteData { get; set; } } diff --git a/src/Merge.Client/Ticketing/Types/CollectionTypeEnum.cs b/src/Merge.Client/Ticketing/Types/CollectionTypeEnum.cs index 75ed1572..25bc1a79 100644 --- a/src/Merge.Client/Ticketing/Types/CollectionTypeEnum.cs +++ b/src/Merge.Client/Ticketing/Types/CollectionTypeEnum.cs @@ -1,7 +1,6 @@ using System.Runtime.Serialization; using System.Text.Json.Serialization; using Merge.Client.Core; -using Merge.Client.Ticketing; #nullable enable diff --git a/src/Merge.Client/Ticketing/Types/Comment.cs b/src/Merge.Client/Ticketing/Types/Comment.cs index 8b306d49..88ad1701 100644 --- a/src/Merge.Client/Ticketing/Types/Comment.cs +++ b/src/Merge.Client/Ticketing/Types/Comment.cs @@ -1,86 +1,85 @@ using System.Text.Json.Serialization; using Merge.Client.Core; -using Merge.Client.Ticketing; using OneOf; #nullable enable namespace Merge.Client.Ticketing; -public class Comment +public record Comment { [JsonPropertyName("id")] - public string? Id { get; init; } + public string? Id { get; set; } /// /// The third-party API ID of the matching object. /// [JsonPropertyName("remote_id")] - public string? RemoteId { get; init; } + public string? RemoteId { get; set; } /// /// The datetime that this object was created by Merge. /// [JsonPropertyName("created_at")] - public DateTime? CreatedAt { get; init; } + public DateTime? CreatedAt { get; set; } /// /// The datetime that this object was modified by Merge. /// [JsonPropertyName("modified_at")] - public DateTime? ModifiedAt { get; init; } + public DateTime? ModifiedAt { get; set; } /// /// The author of the Comment, if the author is a User. /// [JsonPropertyName("user")] [JsonConverter(typeof(OneOfSerializer>))] - public OneOf? User { get; init; } + public OneOf? User { get; set; } /// /// The author of the Comment, if the author is a Contact. /// [JsonPropertyName("contact")] [JsonConverter(typeof(OneOfSerializer>))] - public OneOf? Contact { get; init; } + public OneOf? Contact { get; set; } /// /// The comment's text body. /// [JsonPropertyName("body")] - public string? Body { get; init; } + public string? Body { get; set; } /// /// The comment's text body formatted as html. /// [JsonPropertyName("html_body")] - public string? HtmlBody { get; init; } + public string? HtmlBody { get; set; } /// /// The ticket associated with the comment. /// [JsonPropertyName("ticket")] [JsonConverter(typeof(OneOfSerializer>))] - public OneOf? Ticket { get; init; } + public OneOf? Ticket { get; set; } /// /// Whether or not the comment is internal. /// [JsonPropertyName("is_private")] - public bool? IsPrivate { get; init; } + public bool? IsPrivate { get; set; } /// /// When the third party's comment was created. /// [JsonPropertyName("remote_created_at")] - public DateTime? RemoteCreatedAt { get; init; } + public DateTime? RemoteCreatedAt { get; set; } [JsonPropertyName("remote_was_deleted")] - public bool? RemoteWasDeleted { get; init; } + public bool? RemoteWasDeleted { get; set; } [JsonPropertyName("field_mappings")] - public Dictionary? FieldMappings { get; init; } + public Dictionary? FieldMappings { get; set; } [JsonPropertyName("remote_data")] - public IEnumerable? RemoteData { get; init; } + public IEnumerable? RemoteData { get; set; } } diff --git a/src/Merge.Client/Ticketing/Types/CommentRequest.cs b/src/Merge.Client/Ticketing/Types/CommentRequest.cs index 7ac6bd38..f733305a 100644 --- a/src/Merge.Client/Ticketing/Types/CommentRequest.cs +++ b/src/Merge.Client/Ticketing/Types/CommentRequest.cs @@ -1,56 +1,55 @@ using System.Text.Json.Serialization; using Merge.Client.Core; -using Merge.Client.Ticketing; using OneOf; #nullable enable namespace Merge.Client.Ticketing; -public class CommentRequest +public record CommentRequest { /// /// The author of the Comment, if the author is a User. /// [JsonPropertyName("user")] [JsonConverter(typeof(OneOfSerializer>))] - public OneOf? User { get; init; } + public OneOf? User { get; set; } /// /// The author of the Comment, if the author is a Contact. /// [JsonPropertyName("contact")] [JsonConverter(typeof(OneOfSerializer>))] - public OneOf? Contact { get; init; } + public OneOf? Contact { get; set; } /// /// The comment's text body. /// [JsonPropertyName("body")] - public string? Body { get; init; } + public string? Body { get; set; } /// /// The comment's text body formatted as html. /// [JsonPropertyName("html_body")] - public string? HtmlBody { get; init; } + public string? HtmlBody { get; set; } /// /// The ticket associated with the comment. /// [JsonPropertyName("ticket")] [JsonConverter(typeof(OneOfSerializer>))] - public OneOf? Ticket { get; init; } + public OneOf? Ticket { get; set; } /// /// Whether or not the comment is internal. /// [JsonPropertyName("is_private")] - public bool? IsPrivate { get; init; } + public bool? IsPrivate { get; set; } [JsonPropertyName("integration_params")] - public Dictionary? IntegrationParams { get; init; } + public Dictionary? IntegrationParams { get; set; } [JsonPropertyName("linked_account_params")] - public Dictionary? LinkedAccountParams { get; init; } + public Dictionary? LinkedAccountParams { get; set; } } diff --git a/src/Merge.Client/Ticketing/Types/CommentResponse.cs b/src/Merge.Client/Ticketing/Types/CommentResponse.cs index 8fb6ff9b..5d8562ac 100644 --- a/src/Merge.Client/Ticketing/Types/CommentResponse.cs +++ b/src/Merge.Client/Ticketing/Types/CommentResponse.cs @@ -1,21 +1,22 @@ using System.Text.Json.Serialization; -using Merge.Client.Ticketing; #nullable enable namespace Merge.Client.Ticketing; -public class CommentResponse +public record CommentResponse { [JsonPropertyName("model")] - public Comment Model { get; init; } + public required Comment Model { get; set; } [JsonPropertyName("warnings")] - public IEnumerable Warnings { get; init; } + public IEnumerable Warnings { get; set; } = + new List(); [JsonPropertyName("errors")] - public IEnumerable Errors { get; init; } + public IEnumerable Errors { get; set; } = + new List(); [JsonPropertyName("logs")] - public IEnumerable? Logs { get; init; } + public IEnumerable? Logs { get; set; } } diff --git a/src/Merge.Client/Ticketing/Types/CommonModelScopeApi.cs b/src/Merge.Client/Ticketing/Types/CommonModelScopeApi.cs index eb0eba2c..1ad78a19 100644 --- a/src/Merge.Client/Ticketing/Types/CommonModelScopeApi.cs +++ b/src/Merge.Client/Ticketing/Types/CommonModelScopeApi.cs @@ -1,15 +1,15 @@ using System.Text.Json.Serialization; -using Merge.Client.Ticketing; #nullable enable namespace Merge.Client.Ticketing; -public class CommonModelScopeApi +public record CommonModelScopeApi { /// /// The common models you want to update the scopes for /// [JsonPropertyName("common_models")] - public IEnumerable CommonModels { get; init; } + public IEnumerable CommonModels { get; set; } = + new List(); } diff --git a/src/Merge.Client/Ticketing/Types/CommonModelScopesBodyRequest.cs b/src/Merge.Client/Ticketing/Types/CommonModelScopesBodyRequest.cs index cd4db67d..80275ea1 100644 --- a/src/Merge.Client/Ticketing/Types/CommonModelScopesBodyRequest.cs +++ b/src/Merge.Client/Ticketing/Types/CommonModelScopesBodyRequest.cs @@ -1,18 +1,18 @@ using System.Text.Json.Serialization; -using Merge.Client.Ticketing; #nullable enable namespace Merge.Client.Ticketing; -public class CommonModelScopesBodyRequest +public record CommonModelScopesBodyRequest { [JsonPropertyName("model_id")] - public string ModelId { get; init; } + public required string ModelId { get; set; } [JsonPropertyName("enabled_actions")] - public IEnumerable EnabledActions { get; init; } + public IEnumerable EnabledActions { get; set; } = + new List(); [JsonPropertyName("disabled_fields")] - public IEnumerable DisabledFields { get; init; } + public IEnumerable DisabledFields { get; set; } = new List(); } diff --git a/src/Merge.Client/Ticketing/Types/Contact.cs b/src/Merge.Client/Ticketing/Types/Contact.cs index 1042f731..c08f783e 100644 --- a/src/Merge.Client/Ticketing/Types/Contact.cs +++ b/src/Merge.Client/Ticketing/Types/Contact.cs @@ -1,75 +1,74 @@ using System.Text.Json.Serialization; using Merge.Client.Core; -using Merge.Client.Ticketing; using OneOf; #nullable enable namespace Merge.Client.Ticketing; -public class Contact +public record Contact { [JsonPropertyName("id")] - public string? Id { get; init; } + public string? Id { get; set; } /// /// The third-party API ID of the matching object. /// [JsonPropertyName("remote_id")] - public string? RemoteId { get; init; } + public string? RemoteId { get; set; } /// /// The datetime that this object was created by Merge. /// [JsonPropertyName("created_at")] - public DateTime? CreatedAt { get; init; } + public DateTime? CreatedAt { get; set; } /// /// The datetime that this object was modified by Merge. /// [JsonPropertyName("modified_at")] - public DateTime? ModifiedAt { get; init; } + public DateTime? ModifiedAt { get; set; } /// /// The contact's name. /// [JsonPropertyName("name")] - public string? Name { get; init; } + public string? Name { get; set; } /// /// The contact's email address. /// [JsonPropertyName("email_address")] - public string? EmailAddress { get; init; } + public string? EmailAddress { get; set; } /// /// The contact's phone number. /// [JsonPropertyName("phone_number")] - public string? PhoneNumber { get; init; } + public string? PhoneNumber { get; set; } /// /// The contact's details. /// [JsonPropertyName("details")] - public string? Details { get; init; } + public string? Details { get; set; } /// /// The contact's account. /// [JsonPropertyName("account")] [JsonConverter(typeof(OneOfSerializer>))] - public OneOf? Account { get; init; } + public OneOf? Account { get; set; } /// /// Indicates whether or not this object has been deleted in the third party platform. /// [JsonPropertyName("remote_was_deleted")] - public bool? RemoteWasDeleted { get; init; } + public bool? RemoteWasDeleted { get; set; } [JsonPropertyName("field_mappings")] - public Dictionary? FieldMappings { get; init; } + public Dictionary? FieldMappings { get; set; } [JsonPropertyName("remote_data")] - public IEnumerable? RemoteData { get; init; } + public IEnumerable? RemoteData { get; set; } } diff --git a/src/Merge.Client/Ticketing/Types/ContactRequest.cs b/src/Merge.Client/Ticketing/Types/ContactRequest.cs index 7e3aa517..a5f7c175 100644 --- a/src/Merge.Client/Ticketing/Types/ContactRequest.cs +++ b/src/Merge.Client/Ticketing/Types/ContactRequest.cs @@ -1,48 +1,47 @@ using System.Text.Json.Serialization; using Merge.Client.Core; -using Merge.Client.Ticketing; using OneOf; #nullable enable namespace Merge.Client.Ticketing; -public class ContactRequest +public record ContactRequest { /// /// The contact's name. /// [JsonPropertyName("name")] - public string? Name { get; init; } + public string? Name { get; set; } /// /// The contact's email address. /// [JsonPropertyName("email_address")] - public string? EmailAddress { get; init; } + public string? EmailAddress { get; set; } /// /// The contact's phone number. /// [JsonPropertyName("phone_number")] - public string? PhoneNumber { get; init; } + public string? PhoneNumber { get; set; } /// /// The contact's details. /// [JsonPropertyName("details")] - public string? Details { get; init; } + public string? Details { get; set; } /// /// The contact's account. /// [JsonPropertyName("account")] [JsonConverter(typeof(OneOfSerializer>))] - public OneOf? Account { get; init; } + public OneOf? Account { get; set; } [JsonPropertyName("integration_params")] - public Dictionary? IntegrationParams { get; init; } + public Dictionary? IntegrationParams { get; set; } [JsonPropertyName("linked_account_params")] - public Dictionary? LinkedAccountParams { get; init; } + public Dictionary? LinkedAccountParams { get; set; } } diff --git a/src/Merge.Client/Ticketing/Types/DataPassthroughRequest.cs b/src/Merge.Client/Ticketing/Types/DataPassthroughRequest.cs index 5a6830ab..c1d76125 100644 --- a/src/Merge.Client/Ticketing/Types/DataPassthroughRequest.cs +++ b/src/Merge.Client/Ticketing/Types/DataPassthroughRequest.cs @@ -1,51 +1,50 @@ using System.Text.Json.Serialization; -using Merge.Client.Ticketing; #nullable enable namespace Merge.Client.Ticketing; -public class DataPassthroughRequest +public record DataPassthroughRequest { [JsonPropertyName("method")] - public MethodEnum Method { get; init; } + public required MethodEnum Method { get; set; } /// /// The path of the request in the third party's platform. /// [JsonPropertyName("path")] - public string Path { get; init; } + public required string Path { get; set; } /// /// An optional override of the third party's base url for the request. /// [JsonPropertyName("base_url_override")] - public string? BaseUrlOverride { get; init; } + public string? BaseUrlOverride { get; set; } /// /// The data with the request. You must include a `request_format` parameter matching the data's format /// [JsonPropertyName("data")] - public string? Data { get; init; } + public string? Data { get; set; } /// /// Pass an array of `MultipartFormField` objects in here instead of using the `data` param if `request_format` is set to `MULTIPART`. /// [JsonPropertyName("multipart_form_data")] - public IEnumerable? MultipartFormData { get; init; } + public IEnumerable? MultipartFormData { get; set; } /// /// The headers to use for the request (Merge will handle the account's authorization headers). `Content-Type` header is required for passthrough. Choose content type corresponding to expected format of receiving server. /// [JsonPropertyName("headers")] - public Dictionary? Headers { get; init; } + public Dictionary? Headers { get; set; } [JsonPropertyName("request_format")] - public RequestFormatEnum? RequestFormat { get; init; } + public RequestFormatEnum? RequestFormat { get; set; } /// /// Optional. If true, the response will always be an object of the form `{"type": T, "value": ...}` where `T` will be one of `string, boolean, number, null, array, object`. /// [JsonPropertyName("normalize_response")] - public bool? NormalizeResponse { get; init; } + public bool? NormalizeResponse { get; set; } } diff --git a/src/Merge.Client/Ticketing/Types/DebugModeLog.cs b/src/Merge.Client/Ticketing/Types/DebugModeLog.cs index e3cb90eb..b10132ff 100644 --- a/src/Merge.Client/Ticketing/Types/DebugModeLog.cs +++ b/src/Merge.Client/Ticketing/Types/DebugModeLog.cs @@ -1,18 +1,17 @@ using System.Text.Json.Serialization; -using Merge.Client.Ticketing; #nullable enable namespace Merge.Client.Ticketing; -public class DebugModeLog +public record DebugModeLog { [JsonPropertyName("log_id")] - public string LogId { get; init; } + public required string LogId { get; set; } [JsonPropertyName("dashboard_view")] - public string DashboardView { get; init; } + public required string DashboardView { get; set; } [JsonPropertyName("log_summary")] - public DebugModelLogSummary LogSummary { get; init; } + public required DebugModelLogSummary LogSummary { get; set; } } diff --git a/src/Merge.Client/Ticketing/Types/DebugModelLogSummary.cs b/src/Merge.Client/Ticketing/Types/DebugModelLogSummary.cs index 67bca8a1..51a9877a 100644 --- a/src/Merge.Client/Ticketing/Types/DebugModelLogSummary.cs +++ b/src/Merge.Client/Ticketing/Types/DebugModelLogSummary.cs @@ -4,14 +4,14 @@ namespace Merge.Client.Ticketing; -public class DebugModelLogSummary +public record DebugModelLogSummary { [JsonPropertyName("url")] - public string Url { get; init; } + public required string Url { get; set; } [JsonPropertyName("method")] - public string Method { get; init; } + public required string Method { get; set; } [JsonPropertyName("status_code")] - public int StatusCode { get; init; } + public required int StatusCode { get; set; } } diff --git a/src/Merge.Client/Ticketing/Types/EnabledActionsEnum.cs b/src/Merge.Client/Ticketing/Types/EnabledActionsEnum.cs index 120643f3..ddcde5e4 100644 --- a/src/Merge.Client/Ticketing/Types/EnabledActionsEnum.cs +++ b/src/Merge.Client/Ticketing/Types/EnabledActionsEnum.cs @@ -1,7 +1,6 @@ using System.Runtime.Serialization; using System.Text.Json.Serialization; using Merge.Client.Core; -using Merge.Client.Ticketing; #nullable enable diff --git a/src/Merge.Client/Ticketing/Types/EncodingEnum.cs b/src/Merge.Client/Ticketing/Types/EncodingEnum.cs index ab60c628..d81344c4 100644 --- a/src/Merge.Client/Ticketing/Types/EncodingEnum.cs +++ b/src/Merge.Client/Ticketing/Types/EncodingEnum.cs @@ -1,7 +1,6 @@ using System.Runtime.Serialization; using System.Text.Json.Serialization; using Merge.Client.Core; -using Merge.Client.Ticketing; #nullable enable diff --git a/src/Merge.Client/Ticketing/Types/ErrorValidationProblem.cs b/src/Merge.Client/Ticketing/Types/ErrorValidationProblem.cs index e9ba3a27..5bed9363 100644 --- a/src/Merge.Client/Ticketing/Types/ErrorValidationProblem.cs +++ b/src/Merge.Client/Ticketing/Types/ErrorValidationProblem.cs @@ -1,21 +1,20 @@ using System.Text.Json.Serialization; -using Merge.Client.Ticketing; #nullable enable namespace Merge.Client.Ticketing; -public class ErrorValidationProblem +public record ErrorValidationProblem { [JsonPropertyName("source")] - public ValidationProblemSource? Source { get; init; } + public ValidationProblemSource? Source { get; set; } [JsonPropertyName("title")] - public string Title { get; init; } + public required string Title { get; set; } [JsonPropertyName("detail")] - public string Detail { get; init; } + public required string Detail { get; set; } [JsonPropertyName("problem_type")] - public string ProblemType { get; init; } + public required string ProblemType { get; set; } } diff --git a/src/Merge.Client/Ticketing/Types/EventTypeEnum.cs b/src/Merge.Client/Ticketing/Types/EventTypeEnum.cs index 3a4322a0..e06adfd4 100644 --- a/src/Merge.Client/Ticketing/Types/EventTypeEnum.cs +++ b/src/Merge.Client/Ticketing/Types/EventTypeEnum.cs @@ -1,7 +1,6 @@ using System.Runtime.Serialization; using System.Text.Json.Serialization; using Merge.Client.Core; -using Merge.Client.Ticketing; #nullable enable diff --git a/src/Merge.Client/Ticketing/Types/ExternalTargetFieldApi.cs b/src/Merge.Client/Ticketing/Types/ExternalTargetFieldApi.cs index db2b5521..3f785c04 100644 --- a/src/Merge.Client/Ticketing/Types/ExternalTargetFieldApi.cs +++ b/src/Merge.Client/Ticketing/Types/ExternalTargetFieldApi.cs @@ -4,14 +4,14 @@ namespace Merge.Client.Ticketing; -public class ExternalTargetFieldApi +public record ExternalTargetFieldApi { [JsonPropertyName("name")] - public string? Name { get; init; } + public string? Name { get; set; } [JsonPropertyName("description")] - public string? Description { get; init; } + public string? Description { get; set; } [JsonPropertyName("is_mapped")] - public string? IsMapped { get; init; } + public string? IsMapped { get; set; } } diff --git a/src/Merge.Client/Ticketing/Types/ExternalTargetFieldApiResponse.cs b/src/Merge.Client/Ticketing/Types/ExternalTargetFieldApiResponse.cs index 177b8c70..4c254fbb 100644 --- a/src/Merge.Client/Ticketing/Types/ExternalTargetFieldApiResponse.cs +++ b/src/Merge.Client/Ticketing/Types/ExternalTargetFieldApiResponse.cs @@ -1,42 +1,41 @@ using System.Text.Json.Serialization; -using Merge.Client.Ticketing; #nullable enable namespace Merge.Client.Ticketing; -public class ExternalTargetFieldApiResponse +public record ExternalTargetFieldApiResponse { [JsonPropertyName("Ticket")] - public IEnumerable? Ticket { get; init; } + public IEnumerable? Ticket { get; set; } [JsonPropertyName("Comment")] - public IEnumerable? Comment { get; init; } + public IEnumerable? Comment { get; set; } [JsonPropertyName("Project")] - public IEnumerable? Project { get; init; } + public IEnumerable? Project { get; set; } [JsonPropertyName("Collection")] - public IEnumerable? Collection { get; init; } + public IEnumerable? Collection { get; set; } [JsonPropertyName("User")] - public IEnumerable? User { get; init; } + public IEnumerable? User { get; set; } [JsonPropertyName("Role")] - public IEnumerable? Role { get; init; } + public IEnumerable? Role { get; set; } [JsonPropertyName("Account")] - public IEnumerable? Account { get; init; } + public IEnumerable? Account { get; set; } [JsonPropertyName("Team")] - public IEnumerable? Team { get; init; } + public IEnumerable? Team { get; set; } [JsonPropertyName("Attachment")] - public IEnumerable? Attachment { get; init; } + public IEnumerable? Attachment { get; set; } [JsonPropertyName("Tag")] - public IEnumerable? Tag { get; init; } + public IEnumerable? Tag { get; set; } [JsonPropertyName("Contact")] - public IEnumerable? Contact { get; init; } + public IEnumerable? Contact { get; set; } } diff --git a/src/Merge.Client/Ticketing/Types/FieldFormatEnum.cs b/src/Merge.Client/Ticketing/Types/FieldFormatEnum.cs index ef0fd1dd..ec9cbd7d 100644 --- a/src/Merge.Client/Ticketing/Types/FieldFormatEnum.cs +++ b/src/Merge.Client/Ticketing/Types/FieldFormatEnum.cs @@ -1,7 +1,6 @@ using System.Runtime.Serialization; using System.Text.Json.Serialization; using Merge.Client.Core; -using Merge.Client.Ticketing; #nullable enable diff --git a/src/Merge.Client/Ticketing/Types/FieldMappingApiInstance.cs b/src/Merge.Client/Ticketing/Types/FieldMappingApiInstance.cs index b59a2e69..eed7839e 100644 --- a/src/Merge.Client/Ticketing/Types/FieldMappingApiInstance.cs +++ b/src/Merge.Client/Ticketing/Types/FieldMappingApiInstance.cs @@ -1,21 +1,20 @@ using System.Text.Json.Serialization; -using Merge.Client.Ticketing; #nullable enable namespace Merge.Client.Ticketing; -public class FieldMappingApiInstance +public record FieldMappingApiInstance { [JsonPropertyName("id")] - public string? Id { get; init; } + public string? Id { get; set; } [JsonPropertyName("is_integration_wide")] - public bool? IsIntegrationWide { get; init; } + public bool? IsIntegrationWide { get; set; } [JsonPropertyName("target_field")] - public FieldMappingApiInstanceTargetField? TargetField { get; init; } + public FieldMappingApiInstanceTargetField? TargetField { get; set; } [JsonPropertyName("remote_field")] - public FieldMappingApiInstanceRemoteField? RemoteField { get; init; } + public FieldMappingApiInstanceRemoteField? RemoteField { get; set; } } diff --git a/src/Merge.Client/Ticketing/Types/FieldMappingApiInstanceRemoteField.cs b/src/Merge.Client/Ticketing/Types/FieldMappingApiInstanceRemoteField.cs index a0eb677f..80fd0f98 100644 --- a/src/Merge.Client/Ticketing/Types/FieldMappingApiInstanceRemoteField.cs +++ b/src/Merge.Client/Ticketing/Types/FieldMappingApiInstanceRemoteField.cs @@ -1,18 +1,17 @@ using System.Text.Json.Serialization; -using Merge.Client.Ticketing; #nullable enable namespace Merge.Client.Ticketing; -public class FieldMappingApiInstanceRemoteField +public record FieldMappingApiInstanceRemoteField { [JsonPropertyName("remote_key_name")] - public string RemoteKeyName { get; init; } + public required string RemoteKeyName { get; set; } [JsonPropertyName("schema")] - public Dictionary Schema { get; init; } + public Dictionary Schema { get; set; } = new Dictionary(); [JsonPropertyName("remote_endpoint_info")] - public FieldMappingApiInstanceRemoteFieldRemoteEndpointInfo RemoteEndpointInfo { get; init; } + public required FieldMappingApiInstanceRemoteFieldRemoteEndpointInfo RemoteEndpointInfo { get; set; } } diff --git a/src/Merge.Client/Ticketing/Types/FieldMappingApiInstanceRemoteFieldRemoteEndpointInfo.cs b/src/Merge.Client/Ticketing/Types/FieldMappingApiInstanceRemoteFieldRemoteEndpointInfo.cs index db1ec755..74052074 100644 --- a/src/Merge.Client/Ticketing/Types/FieldMappingApiInstanceRemoteFieldRemoteEndpointInfo.cs +++ b/src/Merge.Client/Ticketing/Types/FieldMappingApiInstanceRemoteFieldRemoteEndpointInfo.cs @@ -4,14 +4,14 @@ namespace Merge.Client.Ticketing; -public class FieldMappingApiInstanceRemoteFieldRemoteEndpointInfo +public record FieldMappingApiInstanceRemoteFieldRemoteEndpointInfo { [JsonPropertyName("method")] - public string? Method { get; init; } + public string? Method { get; set; } [JsonPropertyName("url_path")] - public string? UrlPath { get; init; } + public string? UrlPath { get; set; } [JsonPropertyName("field_traversal_path")] - public IEnumerable? FieldTraversalPath { get; init; } + public IEnumerable? FieldTraversalPath { get; set; } } diff --git a/src/Merge.Client/Ticketing/Types/FieldMappingApiInstanceResponse.cs b/src/Merge.Client/Ticketing/Types/FieldMappingApiInstanceResponse.cs index 003fdcd6..02f3f690 100644 --- a/src/Merge.Client/Ticketing/Types/FieldMappingApiInstanceResponse.cs +++ b/src/Merge.Client/Ticketing/Types/FieldMappingApiInstanceResponse.cs @@ -1,42 +1,41 @@ using System.Text.Json.Serialization; -using Merge.Client.Ticketing; #nullable enable namespace Merge.Client.Ticketing; -public class FieldMappingApiInstanceResponse +public record FieldMappingApiInstanceResponse { [JsonPropertyName("Ticket")] - public IEnumerable? Ticket { get; init; } + public IEnumerable? Ticket { get; set; } [JsonPropertyName("Comment")] - public IEnumerable? Comment { get; init; } + public IEnumerable? Comment { get; set; } [JsonPropertyName("Project")] - public IEnumerable? Project { get; init; } + public IEnumerable? Project { get; set; } [JsonPropertyName("Collection")] - public IEnumerable? Collection { get; init; } + public IEnumerable? Collection { get; set; } [JsonPropertyName("User")] - public IEnumerable? User { get; init; } + public IEnumerable? User { get; set; } [JsonPropertyName("Role")] - public IEnumerable? Role { get; init; } + public IEnumerable? Role { get; set; } [JsonPropertyName("Account")] - public IEnumerable? Account { get; init; } + public IEnumerable? Account { get; set; } [JsonPropertyName("Team")] - public IEnumerable? Team { get; init; } + public IEnumerable? Team { get; set; } [JsonPropertyName("Attachment")] - public IEnumerable? Attachment { get; init; } + public IEnumerable? Attachment { get; set; } [JsonPropertyName("Tag")] - public IEnumerable? Tag { get; init; } + public IEnumerable? Tag { get; set; } [JsonPropertyName("Contact")] - public IEnumerable? Contact { get; init; } + public IEnumerable? Contact { get; set; } } diff --git a/src/Merge.Client/Ticketing/Types/FieldMappingApiInstanceTargetField.cs b/src/Merge.Client/Ticketing/Types/FieldMappingApiInstanceTargetField.cs index 3f5f1f28..46e88393 100644 --- a/src/Merge.Client/Ticketing/Types/FieldMappingApiInstanceTargetField.cs +++ b/src/Merge.Client/Ticketing/Types/FieldMappingApiInstanceTargetField.cs @@ -4,14 +4,14 @@ namespace Merge.Client.Ticketing; -public class FieldMappingApiInstanceTargetField +public record FieldMappingApiInstanceTargetField { [JsonPropertyName("name")] - public string Name { get; init; } + public required string Name { get; set; } [JsonPropertyName("description")] - public string Description { get; init; } + public required string Description { get; set; } [JsonPropertyName("is_organization_wide")] - public bool IsOrganizationWide { get; init; } + public required bool IsOrganizationWide { get; set; } } diff --git a/src/Merge.Client/Ticketing/Types/FieldMappingInstanceResponse.cs b/src/Merge.Client/Ticketing/Types/FieldMappingInstanceResponse.cs index 413176c8..894bbd2c 100644 --- a/src/Merge.Client/Ticketing/Types/FieldMappingInstanceResponse.cs +++ b/src/Merge.Client/Ticketing/Types/FieldMappingInstanceResponse.cs @@ -1,21 +1,22 @@ using System.Text.Json.Serialization; -using Merge.Client.Ticketing; #nullable enable namespace Merge.Client.Ticketing; -public class FieldMappingInstanceResponse +public record FieldMappingInstanceResponse { [JsonPropertyName("model")] - public FieldMappingApiInstance Model { get; init; } + public required FieldMappingApiInstance Model { get; set; } [JsonPropertyName("warnings")] - public IEnumerable Warnings { get; init; } + public IEnumerable Warnings { get; set; } = + new List(); [JsonPropertyName("errors")] - public IEnumerable Errors { get; init; } + public IEnumerable Errors { get; set; } = + new List(); [JsonPropertyName("logs")] - public IEnumerable? Logs { get; init; } + public IEnumerable? Logs { get; set; } } diff --git a/src/Merge.Client/Ticketing/Types/FieldPermissionDeserializer.cs b/src/Merge.Client/Ticketing/Types/FieldPermissionDeserializer.cs index 34c80472..d4b4a0b2 100644 --- a/src/Merge.Client/Ticketing/Types/FieldPermissionDeserializer.cs +++ b/src/Merge.Client/Ticketing/Types/FieldPermissionDeserializer.cs @@ -4,11 +4,11 @@ namespace Merge.Client.Ticketing; -public class FieldPermissionDeserializer +public record FieldPermissionDeserializer { [JsonPropertyName("enabled")] - public IEnumerable? Enabled { get; init; } + public IEnumerable? Enabled { get; set; } [JsonPropertyName("disabled")] - public IEnumerable? Disabled { get; init; } + public IEnumerable? Disabled { get; set; } } diff --git a/src/Merge.Client/Ticketing/Types/FieldPermissionDeserializerRequest.cs b/src/Merge.Client/Ticketing/Types/FieldPermissionDeserializerRequest.cs index 529be0c3..310b57c2 100644 --- a/src/Merge.Client/Ticketing/Types/FieldPermissionDeserializerRequest.cs +++ b/src/Merge.Client/Ticketing/Types/FieldPermissionDeserializerRequest.cs @@ -4,11 +4,11 @@ namespace Merge.Client.Ticketing; -public class FieldPermissionDeserializerRequest +public record FieldPermissionDeserializerRequest { [JsonPropertyName("enabled")] - public IEnumerable? Enabled { get; init; } + public IEnumerable? Enabled { get; set; } [JsonPropertyName("disabled")] - public IEnumerable? Disabled { get; init; } + public IEnumerable? Disabled { get; set; } } diff --git a/src/Merge.Client/Ticketing/Types/FieldTypeEnum.cs b/src/Merge.Client/Ticketing/Types/FieldTypeEnum.cs index cdde30af..4ca06179 100644 --- a/src/Merge.Client/Ticketing/Types/FieldTypeEnum.cs +++ b/src/Merge.Client/Ticketing/Types/FieldTypeEnum.cs @@ -1,7 +1,6 @@ using System.Runtime.Serialization; using System.Text.Json.Serialization; using Merge.Client.Core; -using Merge.Client.Ticketing; #nullable enable diff --git a/src/Merge.Client/Ticketing/Types/IndividualCommonModelScopeDeserializer.cs b/src/Merge.Client/Ticketing/Types/IndividualCommonModelScopeDeserializer.cs index 2ee89da1..1581b893 100644 --- a/src/Merge.Client/Ticketing/Types/IndividualCommonModelScopeDeserializer.cs +++ b/src/Merge.Client/Ticketing/Types/IndividualCommonModelScopeDeserializer.cs @@ -1,18 +1,17 @@ using System.Text.Json.Serialization; -using Merge.Client.Ticketing; #nullable enable namespace Merge.Client.Ticketing; -public class IndividualCommonModelScopeDeserializer +public record IndividualCommonModelScopeDeserializer { [JsonPropertyName("model_name")] - public string ModelName { get; init; } + public required string ModelName { get; set; } [JsonPropertyName("model_permissions")] - public Dictionary? ModelPermissions { get; init; } + public Dictionary? ModelPermissions { get; set; } [JsonPropertyName("field_permissions")] - public FieldPermissionDeserializer? FieldPermissions { get; init; } + public FieldPermissionDeserializer? FieldPermissions { get; set; } } diff --git a/src/Merge.Client/Ticketing/Types/IndividualCommonModelScopeDeserializerRequest.cs b/src/Merge.Client/Ticketing/Types/IndividualCommonModelScopeDeserializerRequest.cs index a6556b2c..499facf2 100644 --- a/src/Merge.Client/Ticketing/Types/IndividualCommonModelScopeDeserializerRequest.cs +++ b/src/Merge.Client/Ticketing/Types/IndividualCommonModelScopeDeserializerRequest.cs @@ -1,18 +1,17 @@ using System.Text.Json.Serialization; -using Merge.Client.Ticketing; #nullable enable namespace Merge.Client.Ticketing; -public class IndividualCommonModelScopeDeserializerRequest +public record IndividualCommonModelScopeDeserializerRequest { [JsonPropertyName("model_name")] - public string ModelName { get; init; } + public required string ModelName { get; set; } [JsonPropertyName("model_permissions")] - public Dictionary? ModelPermissions { get; init; } + public Dictionary? ModelPermissions { get; set; } [JsonPropertyName("field_permissions")] - public FieldPermissionDeserializerRequest? FieldPermissions { get; init; } + public FieldPermissionDeserializerRequest? FieldPermissions { get; set; } } diff --git a/src/Merge.Client/Ticketing/Types/Issue.cs b/src/Merge.Client/Ticketing/Types/Issue.cs index ab869ae3..c8c5e12d 100644 --- a/src/Merge.Client/Ticketing/Types/Issue.cs +++ b/src/Merge.Client/Ticketing/Types/Issue.cs @@ -1,14 +1,13 @@ using System.Text.Json.Serialization; -using Merge.Client.Ticketing; #nullable enable namespace Merge.Client.Ticketing; -public class Issue +public record Issue { [JsonPropertyName("id")] - public string? Id { get; init; } + public string? Id { get; set; } /// /// Status of the issue. Options: ('ONGOING', 'RESOLVED') @@ -17,23 +16,23 @@ public class Issue /// - `RESOLVED` - RESOLVED /// [JsonPropertyName("status")] - public IssueStatusEnum? Status { get; init; } + public IssueStatusEnum? Status { get; set; } [JsonPropertyName("error_description")] - public string ErrorDescription { get; init; } + public required string ErrorDescription { get; set; } [JsonPropertyName("end_user")] - public Dictionary? EndUser { get; init; } + public Dictionary? EndUser { get; set; } [JsonPropertyName("first_incident_time")] - public DateTime? FirstIncidentTime { get; init; } + public DateTime? FirstIncidentTime { get; set; } [JsonPropertyName("last_incident_time")] - public DateTime? LastIncidentTime { get; init; } + public DateTime? LastIncidentTime { get; set; } [JsonPropertyName("is_muted")] - public bool? IsMuted { get; init; } + public bool? IsMuted { get; set; } [JsonPropertyName("error_details")] - public IEnumerable? ErrorDetails { get; init; } + public IEnumerable? ErrorDetails { get; set; } } diff --git a/src/Merge.Client/Ticketing/Types/IssueStatusEnum.cs b/src/Merge.Client/Ticketing/Types/IssueStatusEnum.cs index e8bd8048..aebfdadb 100644 --- a/src/Merge.Client/Ticketing/Types/IssueStatusEnum.cs +++ b/src/Merge.Client/Ticketing/Types/IssueStatusEnum.cs @@ -1,7 +1,6 @@ using System.Runtime.Serialization; using System.Text.Json.Serialization; using Merge.Client.Core; -using Merge.Client.Ticketing; #nullable enable diff --git a/src/Merge.Client/Ticketing/Types/ItemFormatEnum.cs b/src/Merge.Client/Ticketing/Types/ItemFormatEnum.cs index b7f8fdb0..f126096a 100644 --- a/src/Merge.Client/Ticketing/Types/ItemFormatEnum.cs +++ b/src/Merge.Client/Ticketing/Types/ItemFormatEnum.cs @@ -1,7 +1,6 @@ using System.Runtime.Serialization; using System.Text.Json.Serialization; using Merge.Client.Core; -using Merge.Client.Ticketing; #nullable enable diff --git a/src/Merge.Client/Ticketing/Types/ItemSchema.cs b/src/Merge.Client/Ticketing/Types/ItemSchema.cs index 8cbdcba6..d1d2e22f 100644 --- a/src/Merge.Client/Ticketing/Types/ItemSchema.cs +++ b/src/Merge.Client/Ticketing/Types/ItemSchema.cs @@ -1,18 +1,17 @@ using System.Text.Json.Serialization; -using Merge.Client.Ticketing; #nullable enable namespace Merge.Client.Ticketing; -public class ItemSchema +public record ItemSchema { [JsonPropertyName("item_type")] - public ItemTypeEnum? ItemType { get; init; } + public ItemTypeEnum? ItemType { get; set; } [JsonPropertyName("item_format")] - public ItemFormatEnum? ItemFormat { get; init; } + public ItemFormatEnum? ItemFormat { get; set; } [JsonPropertyName("item_choices")] - public IEnumerable? ItemChoices { get; init; } + public IEnumerable? ItemChoices { get; set; } } diff --git a/src/Merge.Client/Ticketing/Types/ItemTypeEnum.cs b/src/Merge.Client/Ticketing/Types/ItemTypeEnum.cs index 48f0fa2f..ed628ef0 100644 --- a/src/Merge.Client/Ticketing/Types/ItemTypeEnum.cs +++ b/src/Merge.Client/Ticketing/Types/ItemTypeEnum.cs @@ -1,7 +1,6 @@ using System.Runtime.Serialization; using System.Text.Json.Serialization; using Merge.Client.Core; -using Merge.Client.Ticketing; #nullable enable diff --git a/src/Merge.Client/Ticketing/Types/LinkToken.cs b/src/Merge.Client/Ticketing/Types/LinkToken.cs index 6e7cf0cc..104d3509 100644 --- a/src/Merge.Client/Ticketing/Types/LinkToken.cs +++ b/src/Merge.Client/Ticketing/Types/LinkToken.cs @@ -4,14 +4,14 @@ namespace Merge.Client.Ticketing; -public class LinkToken +public record LinkToken { [JsonPropertyName("link_token")] - public string LinkToken_ { get; init; } + public required string LinkToken_ { get; set; } [JsonPropertyName("integration_name")] - public string? IntegrationName { get; init; } + public string? IntegrationName { get; set; } [JsonPropertyName("magic_link_url")] - public string? MagicLinkUrl { get; init; } + public string? MagicLinkUrl { get; set; } } diff --git a/src/Merge.Client/Ticketing/Types/LinkedAccountStatus.cs b/src/Merge.Client/Ticketing/Types/LinkedAccountStatus.cs index 05a3716a..6bb60f29 100644 --- a/src/Merge.Client/Ticketing/Types/LinkedAccountStatus.cs +++ b/src/Merge.Client/Ticketing/Types/LinkedAccountStatus.cs @@ -4,11 +4,11 @@ namespace Merge.Client.Ticketing; -public class LinkedAccountStatus +public record LinkedAccountStatus { [JsonPropertyName("linked_account_status")] - public string LinkedAccountStatus_ { get; init; } + public required string LinkedAccountStatus_ { get; set; } [JsonPropertyName("can_make_request")] - public bool CanMakeRequest { get; init; } + public required bool CanMakeRequest { get; set; } } diff --git a/src/Merge.Client/Ticketing/Types/MetaResponse.cs b/src/Merge.Client/Ticketing/Types/MetaResponse.cs index 92be8cbd..23cde483 100644 --- a/src/Merge.Client/Ticketing/Types/MetaResponse.cs +++ b/src/Merge.Client/Ticketing/Types/MetaResponse.cs @@ -1,24 +1,24 @@ using System.Text.Json.Serialization; -using Merge.Client.Ticketing; #nullable enable namespace Merge.Client.Ticketing; -public class MetaResponse +public record MetaResponse { [JsonPropertyName("request_schema")] - public Dictionary RequestSchema { get; init; } + public Dictionary RequestSchema { get; set; } = + new Dictionary(); [JsonPropertyName("remote_field_classes")] - public Dictionary? RemoteFieldClasses { get; init; } + public Dictionary? RemoteFieldClasses { get; set; } [JsonPropertyName("status")] - public LinkedAccountStatus? Status { get; init; } + public LinkedAccountStatus? Status { get; set; } [JsonPropertyName("has_conditional_params")] - public bool HasConditionalParams { get; init; } + public required bool HasConditionalParams { get; set; } [JsonPropertyName("has_required_linked_account_params")] - public bool HasRequiredLinkedAccountParams { get; init; } + public required bool HasRequiredLinkedAccountParams { get; set; } } diff --git a/src/Merge.Client/Ticketing/Types/MethodEnum.cs b/src/Merge.Client/Ticketing/Types/MethodEnum.cs index 19c57d52..a36db493 100644 --- a/src/Merge.Client/Ticketing/Types/MethodEnum.cs +++ b/src/Merge.Client/Ticketing/Types/MethodEnum.cs @@ -1,7 +1,6 @@ using System.Runtime.Serialization; using System.Text.Json.Serialization; using Merge.Client.Core; -using Merge.Client.Ticketing; #nullable enable diff --git a/src/Merge.Client/Ticketing/Types/ModelOperation.cs b/src/Merge.Client/Ticketing/Types/ModelOperation.cs index 04cd88e4..67cda139 100644 --- a/src/Merge.Client/Ticketing/Types/ModelOperation.cs +++ b/src/Merge.Client/Ticketing/Types/ModelOperation.cs @@ -4,17 +4,17 @@ namespace Merge.Client.Ticketing; -public class ModelOperation +public record ModelOperation { [JsonPropertyName("model_name")] - public string ModelName { get; init; } + public required string ModelName { get; set; } [JsonPropertyName("available_operations")] - public IEnumerable AvailableOperations { get; init; } + public IEnumerable AvailableOperations { get; set; } = new List(); [JsonPropertyName("required_post_parameters")] - public IEnumerable RequiredPostParameters { get; init; } + public IEnumerable RequiredPostParameters { get; set; } = new List(); [JsonPropertyName("supported_fields")] - public IEnumerable SupportedFields { get; init; } + public IEnumerable SupportedFields { get; set; } = new List(); } diff --git a/src/Merge.Client/Ticketing/Types/ModelPermissionDeserializer.cs b/src/Merge.Client/Ticketing/Types/ModelPermissionDeserializer.cs index 646f1ea3..32e2005b 100644 --- a/src/Merge.Client/Ticketing/Types/ModelPermissionDeserializer.cs +++ b/src/Merge.Client/Ticketing/Types/ModelPermissionDeserializer.cs @@ -4,8 +4,8 @@ namespace Merge.Client.Ticketing; -public class ModelPermissionDeserializer +public record ModelPermissionDeserializer { [JsonPropertyName("is_enabled")] - public bool? IsEnabled { get; init; } + public bool? IsEnabled { get; set; } } diff --git a/src/Merge.Client/Ticketing/Types/ModelPermissionDeserializerRequest.cs b/src/Merge.Client/Ticketing/Types/ModelPermissionDeserializerRequest.cs index 9dac96a8..24bdfdb8 100644 --- a/src/Merge.Client/Ticketing/Types/ModelPermissionDeserializerRequest.cs +++ b/src/Merge.Client/Ticketing/Types/ModelPermissionDeserializerRequest.cs @@ -4,8 +4,8 @@ namespace Merge.Client.Ticketing; -public class ModelPermissionDeserializerRequest +public record ModelPermissionDeserializerRequest { [JsonPropertyName("is_enabled")] - public bool? IsEnabled { get; init; } + public bool? IsEnabled { get; set; } } diff --git a/src/Merge.Client/Ticketing/Types/MultipartFormFieldRequest.cs b/src/Merge.Client/Ticketing/Types/MultipartFormFieldRequest.cs index 8799d17e..9ca4272d 100644 --- a/src/Merge.Client/Ticketing/Types/MultipartFormFieldRequest.cs +++ b/src/Merge.Client/Ticketing/Types/MultipartFormFieldRequest.cs @@ -1,23 +1,22 @@ using System.Text.Json.Serialization; -using Merge.Client.Ticketing; #nullable enable namespace Merge.Client.Ticketing; -public class MultipartFormFieldRequest +public record MultipartFormFieldRequest { /// /// The name of the form field /// [JsonPropertyName("name")] - public string Name { get; init; } + public required string Name { get; set; } /// /// The data for the form field. /// [JsonPropertyName("data")] - public string Data { get; init; } + public required string Data { get; set; } /// /// The encoding of the value of `data`. Defaults to `RAW` if not defined. @@ -27,17 +26,17 @@ public class MultipartFormFieldRequest /// - `GZIP_BASE64` - GZIP_BASE64 /// [JsonPropertyName("encoding")] - public EncodingEnum? Encoding { get; init; } + public EncodingEnum? Encoding { get; set; } /// /// The file name of the form field, if the field is for a file. /// [JsonPropertyName("file_name")] - public string? FileName { get; init; } + public string? FileName { get; set; } /// /// The MIME type of the file, if the field is for a file. /// [JsonPropertyName("content_type")] - public string? ContentType { get; init; } + public string? ContentType { get; set; } } diff --git a/src/Merge.Client/Ticketing/Types/PaginatedAccountDetailsAndActionsList.cs b/src/Merge.Client/Ticketing/Types/PaginatedAccountDetailsAndActionsList.cs index 5ead91b5..da0120fb 100644 --- a/src/Merge.Client/Ticketing/Types/PaginatedAccountDetailsAndActionsList.cs +++ b/src/Merge.Client/Ticketing/Types/PaginatedAccountDetailsAndActionsList.cs @@ -1,18 +1,17 @@ using System.Text.Json.Serialization; -using Merge.Client.Ticketing; #nullable enable namespace Merge.Client.Ticketing; -public class PaginatedAccountDetailsAndActionsList +public record PaginatedAccountDetailsAndActionsList { [JsonPropertyName("next")] - public string? Next { get; init; } + public string? Next { get; set; } [JsonPropertyName("previous")] - public string? Previous { get; init; } + public string? Previous { get; set; } [JsonPropertyName("results")] - public IEnumerable? Results { get; init; } + public IEnumerable? Results { get; set; } } diff --git a/src/Merge.Client/Ticketing/Types/PaginatedAccountList.cs b/src/Merge.Client/Ticketing/Types/PaginatedAccountList.cs index 94ca81f5..58795697 100644 --- a/src/Merge.Client/Ticketing/Types/PaginatedAccountList.cs +++ b/src/Merge.Client/Ticketing/Types/PaginatedAccountList.cs @@ -1,18 +1,17 @@ using System.Text.Json.Serialization; -using Merge.Client.Ticketing; #nullable enable namespace Merge.Client.Ticketing; -public class PaginatedAccountList +public record PaginatedAccountList { [JsonPropertyName("next")] - public string? Next { get; init; } + public string? Next { get; set; } [JsonPropertyName("previous")] - public string? Previous { get; init; } + public string? Previous { get; set; } [JsonPropertyName("results")] - public IEnumerable? Results { get; init; } + public IEnumerable? Results { get; set; } } diff --git a/src/Merge.Client/Ticketing/Types/PaginatedAttachmentList.cs b/src/Merge.Client/Ticketing/Types/PaginatedAttachmentList.cs index 0f119d68..a834cf04 100644 --- a/src/Merge.Client/Ticketing/Types/PaginatedAttachmentList.cs +++ b/src/Merge.Client/Ticketing/Types/PaginatedAttachmentList.cs @@ -1,18 +1,17 @@ using System.Text.Json.Serialization; -using Merge.Client.Ticketing; #nullable enable namespace Merge.Client.Ticketing; -public class PaginatedAttachmentList +public record PaginatedAttachmentList { [JsonPropertyName("next")] - public string? Next { get; init; } + public string? Next { get; set; } [JsonPropertyName("previous")] - public string? Previous { get; init; } + public string? Previous { get; set; } [JsonPropertyName("results")] - public IEnumerable? Results { get; init; } + public IEnumerable? Results { get; set; } } diff --git a/src/Merge.Client/Ticketing/Types/PaginatedAuditLogEventList.cs b/src/Merge.Client/Ticketing/Types/PaginatedAuditLogEventList.cs index 193dd4b3..f3b9acfb 100644 --- a/src/Merge.Client/Ticketing/Types/PaginatedAuditLogEventList.cs +++ b/src/Merge.Client/Ticketing/Types/PaginatedAuditLogEventList.cs @@ -1,18 +1,17 @@ using System.Text.Json.Serialization; -using Merge.Client.Ticketing; #nullable enable namespace Merge.Client.Ticketing; -public class PaginatedAuditLogEventList +public record PaginatedAuditLogEventList { [JsonPropertyName("next")] - public string? Next { get; init; } + public string? Next { get; set; } [JsonPropertyName("previous")] - public string? Previous { get; init; } + public string? Previous { get; set; } [JsonPropertyName("results")] - public IEnumerable? Results { get; init; } + public IEnumerable? Results { get; set; } } diff --git a/src/Merge.Client/Ticketing/Types/PaginatedCollectionList.cs b/src/Merge.Client/Ticketing/Types/PaginatedCollectionList.cs index 4cf53b54..efd5ea17 100644 --- a/src/Merge.Client/Ticketing/Types/PaginatedCollectionList.cs +++ b/src/Merge.Client/Ticketing/Types/PaginatedCollectionList.cs @@ -1,18 +1,17 @@ using System.Text.Json.Serialization; -using Merge.Client.Ticketing; #nullable enable namespace Merge.Client.Ticketing; -public class PaginatedCollectionList +public record PaginatedCollectionList { [JsonPropertyName("next")] - public string? Next { get; init; } + public string? Next { get; set; } [JsonPropertyName("previous")] - public string? Previous { get; init; } + public string? Previous { get; set; } [JsonPropertyName("results")] - public IEnumerable? Results { get; init; } + public IEnumerable? Results { get; set; } } diff --git a/src/Merge.Client/Ticketing/Types/PaginatedCommentList.cs b/src/Merge.Client/Ticketing/Types/PaginatedCommentList.cs index a2eed257..db85e04f 100644 --- a/src/Merge.Client/Ticketing/Types/PaginatedCommentList.cs +++ b/src/Merge.Client/Ticketing/Types/PaginatedCommentList.cs @@ -1,18 +1,17 @@ using System.Text.Json.Serialization; -using Merge.Client.Ticketing; #nullable enable namespace Merge.Client.Ticketing; -public class PaginatedCommentList +public record PaginatedCommentList { [JsonPropertyName("next")] - public string? Next { get; init; } + public string? Next { get; set; } [JsonPropertyName("previous")] - public string? Previous { get; init; } + public string? Previous { get; set; } [JsonPropertyName("results")] - public IEnumerable? Results { get; init; } + public IEnumerable? Results { get; set; } } diff --git a/src/Merge.Client/Ticketing/Types/PaginatedContactList.cs b/src/Merge.Client/Ticketing/Types/PaginatedContactList.cs index c4df5534..58e1f995 100644 --- a/src/Merge.Client/Ticketing/Types/PaginatedContactList.cs +++ b/src/Merge.Client/Ticketing/Types/PaginatedContactList.cs @@ -1,18 +1,17 @@ using System.Text.Json.Serialization; -using Merge.Client.Ticketing; #nullable enable namespace Merge.Client.Ticketing; -public class PaginatedContactList +public record PaginatedContactList { [JsonPropertyName("next")] - public string? Next { get; init; } + public string? Next { get; set; } [JsonPropertyName("previous")] - public string? Previous { get; init; } + public string? Previous { get; set; } [JsonPropertyName("results")] - public IEnumerable? Results { get; init; } + public IEnumerable? Results { get; set; } } diff --git a/src/Merge.Client/Ticketing/Types/PaginatedIssueList.cs b/src/Merge.Client/Ticketing/Types/PaginatedIssueList.cs index 64ee57d1..cb94812e 100644 --- a/src/Merge.Client/Ticketing/Types/PaginatedIssueList.cs +++ b/src/Merge.Client/Ticketing/Types/PaginatedIssueList.cs @@ -1,18 +1,17 @@ using System.Text.Json.Serialization; -using Merge.Client.Ticketing; #nullable enable namespace Merge.Client.Ticketing; -public class PaginatedIssueList +public record PaginatedIssueList { [JsonPropertyName("next")] - public string? Next { get; init; } + public string? Next { get; set; } [JsonPropertyName("previous")] - public string? Previous { get; init; } + public string? Previous { get; set; } [JsonPropertyName("results")] - public IEnumerable? Results { get; init; } + public IEnumerable? Results { get; set; } } diff --git a/src/Merge.Client/Ticketing/Types/PaginatedProjectList.cs b/src/Merge.Client/Ticketing/Types/PaginatedProjectList.cs index 7d1f40bd..745b6356 100644 --- a/src/Merge.Client/Ticketing/Types/PaginatedProjectList.cs +++ b/src/Merge.Client/Ticketing/Types/PaginatedProjectList.cs @@ -1,18 +1,17 @@ using System.Text.Json.Serialization; -using Merge.Client.Ticketing; #nullable enable namespace Merge.Client.Ticketing; -public class PaginatedProjectList +public record PaginatedProjectList { [JsonPropertyName("next")] - public string? Next { get; init; } + public string? Next { get; set; } [JsonPropertyName("previous")] - public string? Previous { get; init; } + public string? Previous { get; set; } [JsonPropertyName("results")] - public IEnumerable? Results { get; init; } + public IEnumerable? Results { get; set; } } diff --git a/src/Merge.Client/Ticketing/Types/PaginatedRemoteFieldClassList.cs b/src/Merge.Client/Ticketing/Types/PaginatedRemoteFieldClassList.cs index 1cfa3eac..21441283 100644 --- a/src/Merge.Client/Ticketing/Types/PaginatedRemoteFieldClassList.cs +++ b/src/Merge.Client/Ticketing/Types/PaginatedRemoteFieldClassList.cs @@ -1,18 +1,17 @@ using System.Text.Json.Serialization; -using Merge.Client.Ticketing; #nullable enable namespace Merge.Client.Ticketing; -public class PaginatedRemoteFieldClassList +public record PaginatedRemoteFieldClassList { [JsonPropertyName("next")] - public string? Next { get; init; } + public string? Next { get; set; } [JsonPropertyName("previous")] - public string? Previous { get; init; } + public string? Previous { get; set; } [JsonPropertyName("results")] - public IEnumerable? Results { get; init; } + public IEnumerable? Results { get; set; } } diff --git a/src/Merge.Client/Ticketing/Types/PaginatedRoleList.cs b/src/Merge.Client/Ticketing/Types/PaginatedRoleList.cs index bec82440..24f00ad9 100644 --- a/src/Merge.Client/Ticketing/Types/PaginatedRoleList.cs +++ b/src/Merge.Client/Ticketing/Types/PaginatedRoleList.cs @@ -1,18 +1,17 @@ using System.Text.Json.Serialization; -using Merge.Client.Ticketing; #nullable enable namespace Merge.Client.Ticketing; -public class PaginatedRoleList +public record PaginatedRoleList { [JsonPropertyName("next")] - public string? Next { get; init; } + public string? Next { get; set; } [JsonPropertyName("previous")] - public string? Previous { get; init; } + public string? Previous { get; set; } [JsonPropertyName("results")] - public IEnumerable? Results { get; init; } + public IEnumerable? Results { get; set; } } diff --git a/src/Merge.Client/Ticketing/Types/PaginatedSyncStatusList.cs b/src/Merge.Client/Ticketing/Types/PaginatedSyncStatusList.cs index 98f6acf2..ca53db5c 100644 --- a/src/Merge.Client/Ticketing/Types/PaginatedSyncStatusList.cs +++ b/src/Merge.Client/Ticketing/Types/PaginatedSyncStatusList.cs @@ -1,18 +1,17 @@ using System.Text.Json.Serialization; -using Merge.Client.Ticketing; #nullable enable namespace Merge.Client.Ticketing; -public class PaginatedSyncStatusList +public record PaginatedSyncStatusList { [JsonPropertyName("next")] - public string? Next { get; init; } + public string? Next { get; set; } [JsonPropertyName("previous")] - public string? Previous { get; init; } + public string? Previous { get; set; } [JsonPropertyName("results")] - public IEnumerable? Results { get; init; } + public IEnumerable? Results { get; set; } } diff --git a/src/Merge.Client/Ticketing/Types/PaginatedTagList.cs b/src/Merge.Client/Ticketing/Types/PaginatedTagList.cs index 1294fa26..9d8c8cdf 100644 --- a/src/Merge.Client/Ticketing/Types/PaginatedTagList.cs +++ b/src/Merge.Client/Ticketing/Types/PaginatedTagList.cs @@ -1,18 +1,17 @@ using System.Text.Json.Serialization; -using Merge.Client.Ticketing; #nullable enable namespace Merge.Client.Ticketing; -public class PaginatedTagList +public record PaginatedTagList { [JsonPropertyName("next")] - public string? Next { get; init; } + public string? Next { get; set; } [JsonPropertyName("previous")] - public string? Previous { get; init; } + public string? Previous { get; set; } [JsonPropertyName("results")] - public IEnumerable? Results { get; init; } + public IEnumerable? Results { get; set; } } diff --git a/src/Merge.Client/Ticketing/Types/PaginatedTeamList.cs b/src/Merge.Client/Ticketing/Types/PaginatedTeamList.cs index 4004759a..ff2d80c0 100644 --- a/src/Merge.Client/Ticketing/Types/PaginatedTeamList.cs +++ b/src/Merge.Client/Ticketing/Types/PaginatedTeamList.cs @@ -1,18 +1,17 @@ using System.Text.Json.Serialization; -using Merge.Client.Ticketing; #nullable enable namespace Merge.Client.Ticketing; -public class PaginatedTeamList +public record PaginatedTeamList { [JsonPropertyName("next")] - public string? Next { get; init; } + public string? Next { get; set; } [JsonPropertyName("previous")] - public string? Previous { get; init; } + public string? Previous { get; set; } [JsonPropertyName("results")] - public IEnumerable? Results { get; init; } + public IEnumerable? Results { get; set; } } diff --git a/src/Merge.Client/Ticketing/Types/PaginatedTicketList.cs b/src/Merge.Client/Ticketing/Types/PaginatedTicketList.cs index bd7ffc2e..f46268a6 100644 --- a/src/Merge.Client/Ticketing/Types/PaginatedTicketList.cs +++ b/src/Merge.Client/Ticketing/Types/PaginatedTicketList.cs @@ -1,18 +1,17 @@ using System.Text.Json.Serialization; -using Merge.Client.Ticketing; #nullable enable namespace Merge.Client.Ticketing; -public class PaginatedTicketList +public record PaginatedTicketList { [JsonPropertyName("next")] - public string? Next { get; init; } + public string? Next { get; set; } [JsonPropertyName("previous")] - public string? Previous { get; init; } + public string? Previous { get; set; } [JsonPropertyName("results")] - public IEnumerable? Results { get; init; } + public IEnumerable? Results { get; set; } } diff --git a/src/Merge.Client/Ticketing/Types/PaginatedUserList.cs b/src/Merge.Client/Ticketing/Types/PaginatedUserList.cs index 1fe1d364..cb4e9d4b 100644 --- a/src/Merge.Client/Ticketing/Types/PaginatedUserList.cs +++ b/src/Merge.Client/Ticketing/Types/PaginatedUserList.cs @@ -1,18 +1,17 @@ using System.Text.Json.Serialization; -using Merge.Client.Ticketing; #nullable enable namespace Merge.Client.Ticketing; -public class PaginatedUserList +public record PaginatedUserList { [JsonPropertyName("next")] - public string? Next { get; init; } + public string? Next { get; set; } [JsonPropertyName("previous")] - public string? Previous { get; init; } + public string? Previous { get; set; } [JsonPropertyName("results")] - public IEnumerable? Results { get; init; } + public IEnumerable? Results { get; set; } } diff --git a/src/Merge.Client/Ticketing/Types/PatchedTicketRequest.cs b/src/Merge.Client/Ticketing/Types/PatchedTicketRequest.cs index 22af1782..147b012e 100644 --- a/src/Merge.Client/Ticketing/Types/PatchedTicketRequest.cs +++ b/src/Merge.Client/Ticketing/Types/PatchedTicketRequest.cs @@ -1,32 +1,31 @@ using System.Text.Json.Serialization; -using Merge.Client.Ticketing; #nullable enable namespace Merge.Client.Ticketing; -public class PatchedTicketRequest +public record PatchedTicketRequest { /// /// The ticket's name. /// [JsonPropertyName("name")] - public string? Name { get; init; } + public string? Name { get; set; } [JsonPropertyName("assignees")] - public IEnumerable? Assignees { get; init; } + public IEnumerable? Assignees { get; set; } /// /// The user who created this ticket. /// [JsonPropertyName("creator")] - public string? Creator { get; init; } + public string? Creator { get; set; } /// /// The ticket's due date. /// [JsonPropertyName("due_date")] - public DateTime? DueDate { get; init; } + public DateTime? DueDate { get; set; } /// /// The current status of the ticket. @@ -37,55 +36,55 @@ public class PatchedTicketRequest /// - `ON_HOLD` - ON_HOLD /// [JsonPropertyName("status")] - public TicketStatusEnum? Status { get; init; } + public TicketStatusEnum? Status { get; set; } /// /// The ticket’s description. HTML version of description is mapped if supported by the third-party platform. /// [JsonPropertyName("description")] - public string? Description { get; init; } + public string? Description { get; set; } [JsonPropertyName("collections")] - public IEnumerable? Collections { get; init; } + public IEnumerable? Collections { get; set; } /// /// The sub category of the ticket within the 3rd party system. Examples include incident, task, subtask or to-do. /// [JsonPropertyName("ticket_type")] - public string? TicketType { get; init; } + public string? TicketType { get; set; } /// /// The account associated with the ticket. /// [JsonPropertyName("account")] - public string? Account { get; init; } + public string? Account { get; set; } /// /// The contact associated with the ticket. /// [JsonPropertyName("contact")] - public string? Contact { get; init; } + public string? Contact { get; set; } /// /// The ticket's parent ticket. /// [JsonPropertyName("parent_ticket")] - public string? ParentTicket { get; init; } + public string? ParentTicket { get; set; } [JsonPropertyName("tags")] - public IEnumerable? Tags { get; init; } + public IEnumerable? Tags { get; set; } /// /// When the ticket was completed. /// [JsonPropertyName("completed_at")] - public DateTime? CompletedAt { get; init; } + public DateTime? CompletedAt { get; set; } /// /// The 3rd party url of the Ticket. /// [JsonPropertyName("ticket_url")] - public string? TicketUrl { get; init; } + public string? TicketUrl { get; set; } /// /// The priority or urgency of the Ticket. @@ -96,14 +95,14 @@ public class PatchedTicketRequest /// - `LOW` - LOW /// [JsonPropertyName("priority")] - public PriorityEnum? Priority { get; init; } + public PriorityEnum? Priority { get; set; } [JsonPropertyName("integration_params")] - public Dictionary? IntegrationParams { get; init; } + public Dictionary? IntegrationParams { get; set; } [JsonPropertyName("linked_account_params")] - public Dictionary? LinkedAccountParams { get; init; } + public Dictionary? LinkedAccountParams { get; set; } [JsonPropertyName("remote_fields")] - public IEnumerable? RemoteFields { get; init; } + public IEnumerable? RemoteFields { get; set; } } diff --git a/src/Merge.Client/Ticketing/Types/PriorityEnum.cs b/src/Merge.Client/Ticketing/Types/PriorityEnum.cs index 82d667f1..2c8ecbd5 100644 --- a/src/Merge.Client/Ticketing/Types/PriorityEnum.cs +++ b/src/Merge.Client/Ticketing/Types/PriorityEnum.cs @@ -1,7 +1,6 @@ using System.Runtime.Serialization; using System.Text.Json.Serialization; using Merge.Client.Core; -using Merge.Client.Ticketing; #nullable enable diff --git a/src/Merge.Client/Ticketing/Types/Project.cs b/src/Merge.Client/Ticketing/Types/Project.cs index 4173194c..e318ad15 100644 --- a/src/Merge.Client/Ticketing/Types/Project.cs +++ b/src/Merge.Client/Ticketing/Types/Project.cs @@ -1,54 +1,53 @@ using System.Text.Json.Serialization; -using Merge.Client.Ticketing; #nullable enable namespace Merge.Client.Ticketing; -public class Project +public record Project { [JsonPropertyName("id")] - public string? Id { get; init; } + public string? Id { get; set; } /// /// The third-party API ID of the matching object. /// [JsonPropertyName("remote_id")] - public string? RemoteId { get; init; } + public string? RemoteId { get; set; } /// /// The datetime that this object was created by Merge. /// [JsonPropertyName("created_at")] - public DateTime? CreatedAt { get; init; } + public DateTime? CreatedAt { get; set; } /// /// The datetime that this object was modified by Merge. /// [JsonPropertyName("modified_at")] - public DateTime? ModifiedAt { get; init; } + public DateTime? ModifiedAt { get; set; } /// /// The project's name. /// [JsonPropertyName("name")] - public string? Name { get; init; } + public string? Name { get; set; } /// /// The project's description. /// [JsonPropertyName("description")] - public string? Description { get; init; } + public string? Description { get; set; } /// /// Indicates whether or not this object has been deleted in the third party platform. /// [JsonPropertyName("remote_was_deleted")] - public bool? RemoteWasDeleted { get; init; } + public bool? RemoteWasDeleted { get; set; } [JsonPropertyName("field_mappings")] - public Dictionary? FieldMappings { get; init; } + public Dictionary? FieldMappings { get; set; } [JsonPropertyName("remote_data")] - public IEnumerable? RemoteData { get; init; } + public IEnumerable? RemoteData { get; set; } } diff --git a/src/Merge.Client/Ticketing/Types/RemoteData.cs b/src/Merge.Client/Ticketing/Types/RemoteData.cs index 56b1cf47..64abc17b 100644 --- a/src/Merge.Client/Ticketing/Types/RemoteData.cs +++ b/src/Merge.Client/Ticketing/Types/RemoteData.cs @@ -4,11 +4,11 @@ namespace Merge.Client.Ticketing; -public class RemoteData +public record RemoteData { [JsonPropertyName("path")] - public string Path { get; init; } + public required string Path { get; set; } [JsonPropertyName("data")] - public object? Data { get; init; } + public object? Data { get; set; } } diff --git a/src/Merge.Client/Ticketing/Types/RemoteEndpointInfo.cs b/src/Merge.Client/Ticketing/Types/RemoteEndpointInfo.cs index 5010f8ef..a3593e2b 100644 --- a/src/Merge.Client/Ticketing/Types/RemoteEndpointInfo.cs +++ b/src/Merge.Client/Ticketing/Types/RemoteEndpointInfo.cs @@ -4,14 +4,14 @@ namespace Merge.Client.Ticketing; -public class RemoteEndpointInfo +public record RemoteEndpointInfo { [JsonPropertyName("method")] - public string Method { get; init; } + public required string Method { get; set; } [JsonPropertyName("url_path")] - public string UrlPath { get; init; } + public required string UrlPath { get; set; } [JsonPropertyName("field_traversal_path")] - public IEnumerable FieldTraversalPath { get; init; } + public IEnumerable FieldTraversalPath { get; set; } = new List(); } diff --git a/src/Merge.Client/Ticketing/Types/RemoteField.cs b/src/Merge.Client/Ticketing/Types/RemoteField.cs index 70f132bd..fc463e5d 100644 --- a/src/Merge.Client/Ticketing/Types/RemoteField.cs +++ b/src/Merge.Client/Ticketing/Types/RemoteField.cs @@ -1,18 +1,17 @@ using System.Text.Json.Serialization; using Merge.Client.Core; -using Merge.Client.Ticketing; using OneOf; #nullable enable namespace Merge.Client.Ticketing; -public class RemoteField +public record RemoteField { [JsonPropertyName("remote_field_class")] [JsonConverter(typeof(OneOfSerializer>))] - public OneOf RemoteFieldClass { get; init; } + public required OneOf RemoteFieldClass { get; set; } [JsonPropertyName("value")] - public object? Value { get; init; } + public object? Value { get; set; } } diff --git a/src/Merge.Client/Ticketing/Types/RemoteFieldApi.cs b/src/Merge.Client/Ticketing/Types/RemoteFieldApi.cs index 26361c13..577c48a1 100644 --- a/src/Merge.Client/Ticketing/Types/RemoteFieldApi.cs +++ b/src/Merge.Client/Ticketing/Types/RemoteFieldApi.cs @@ -1,30 +1,29 @@ using System.Text.Json.Serialization; using Merge.Client.Core; -using Merge.Client.Ticketing; using OneOf; #nullable enable namespace Merge.Client.Ticketing; -public class RemoteFieldApi +public record RemoteFieldApi { [JsonPropertyName("schema")] - public Dictionary Schema { get; init; } + public Dictionary Schema { get; set; } = new Dictionary(); [JsonPropertyName("remote_key_name")] - public string RemoteKeyName { get; init; } + public required string RemoteKeyName { get; set; } [JsonPropertyName("remote_endpoint_info")] - public RemoteEndpointInfo RemoteEndpointInfo { get; init; } + public required RemoteEndpointInfo RemoteEndpointInfo { get; set; } [JsonPropertyName("example_values")] - public IEnumerable? ExampleValues { get; init; } + public IEnumerable? ExampleValues { get; set; } [JsonPropertyName("advanced_metadata")] - public AdvancedMetadata? AdvancedMetadata { get; init; } + public AdvancedMetadata? AdvancedMetadata { get; set; } [JsonPropertyName("coverage")] [JsonConverter(typeof(OneOfSerializer>))] - public OneOf? Coverage { get; init; } + public OneOf? Coverage { get; set; } } diff --git a/src/Merge.Client/Ticketing/Types/RemoteFieldApiResponse.cs b/src/Merge.Client/Ticketing/Types/RemoteFieldApiResponse.cs index 795702f3..21842a8f 100644 --- a/src/Merge.Client/Ticketing/Types/RemoteFieldApiResponse.cs +++ b/src/Merge.Client/Ticketing/Types/RemoteFieldApiResponse.cs @@ -1,42 +1,41 @@ using System.Text.Json.Serialization; -using Merge.Client.Ticketing; #nullable enable namespace Merge.Client.Ticketing; -public class RemoteFieldApiResponse +public record RemoteFieldApiResponse { [JsonPropertyName("Ticket")] - public IEnumerable? Ticket { get; init; } + public IEnumerable? Ticket { get; set; } [JsonPropertyName("Comment")] - public IEnumerable? Comment { get; init; } + public IEnumerable? Comment { get; set; } [JsonPropertyName("Project")] - public IEnumerable? Project { get; init; } + public IEnumerable? Project { get; set; } [JsonPropertyName("Collection")] - public IEnumerable? Collection { get; init; } + public IEnumerable? Collection { get; set; } [JsonPropertyName("User")] - public IEnumerable? User { get; init; } + public IEnumerable? User { get; set; } [JsonPropertyName("Role")] - public IEnumerable? Role { get; init; } + public IEnumerable? Role { get; set; } [JsonPropertyName("Account")] - public IEnumerable? Account { get; init; } + public IEnumerable? Account { get; set; } [JsonPropertyName("Team")] - public IEnumerable? Team { get; init; } + public IEnumerable? Team { get; set; } [JsonPropertyName("Attachment")] - public IEnumerable? Attachment { get; init; } + public IEnumerable? Attachment { get; set; } [JsonPropertyName("Tag")] - public IEnumerable? Tag { get; init; } + public IEnumerable? Tag { get; set; } [JsonPropertyName("Contact")] - public IEnumerable? Contact { get; init; } + public IEnumerable? Contact { get; set; } } diff --git a/src/Merge.Client/Ticketing/Types/RemoteFieldClass.cs b/src/Merge.Client/Ticketing/Types/RemoteFieldClass.cs index 77719001..fbfb7843 100644 --- a/src/Merge.Client/Ticketing/Types/RemoteFieldClass.cs +++ b/src/Merge.Client/Ticketing/Types/RemoteFieldClass.cs @@ -1,39 +1,38 @@ using System.Text.Json.Serialization; -using Merge.Client.Ticketing; #nullable enable namespace Merge.Client.Ticketing; -public class RemoteFieldClass +public record RemoteFieldClass { [JsonPropertyName("id")] - public string? Id { get; init; } + public string? Id { get; set; } [JsonPropertyName("display_name")] - public string? DisplayName { get; init; } + public string? DisplayName { get; set; } [JsonPropertyName("remote_key_name")] - public string? RemoteKeyName { get; init; } + public string? RemoteKeyName { get; set; } [JsonPropertyName("description")] - public string? Description { get; init; } + public string? Description { get; set; } [JsonPropertyName("is_custom")] - public bool? IsCustom { get; init; } + public bool? IsCustom { get; set; } [JsonPropertyName("is_required")] - public bool? IsRequired { get; init; } + public bool? IsRequired { get; set; } [JsonPropertyName("field_type")] - public FieldTypeEnum? FieldType { get; init; } + public FieldTypeEnum? FieldType { get; set; } [JsonPropertyName("field_format")] - public FieldFormatEnum? FieldFormat { get; init; } + public FieldFormatEnum? FieldFormat { get; set; } [JsonPropertyName("field_choices")] - public IEnumerable? FieldChoices { get; init; } + public IEnumerable? FieldChoices { get; set; } [JsonPropertyName("item_schema")] - public ItemSchema? ItemSchema { get; init; } + public ItemSchema? ItemSchema { get; set; } } diff --git a/src/Merge.Client/Ticketing/Types/RemoteFieldClassFieldChoicesItem.cs b/src/Merge.Client/Ticketing/Types/RemoteFieldClassFieldChoicesItem.cs index 3a7b9893..a453e07a 100644 --- a/src/Merge.Client/Ticketing/Types/RemoteFieldClassFieldChoicesItem.cs +++ b/src/Merge.Client/Ticketing/Types/RemoteFieldClassFieldChoicesItem.cs @@ -4,11 +4,11 @@ namespace Merge.Client.Ticketing; -public class RemoteFieldClassFieldChoicesItem +public record RemoteFieldClassFieldChoicesItem { [JsonPropertyName("value")] - public object? Value { get; init; } + public object? Value { get; set; } [JsonPropertyName("display_name")] - public string? DisplayName { get; init; } + public string? DisplayName { get; set; } } diff --git a/src/Merge.Client/Ticketing/Types/RemoteFieldRequest.cs b/src/Merge.Client/Ticketing/Types/RemoteFieldRequest.cs index cc422338..d21c5bff 100644 --- a/src/Merge.Client/Ticketing/Types/RemoteFieldRequest.cs +++ b/src/Merge.Client/Ticketing/Types/RemoteFieldRequest.cs @@ -1,18 +1,17 @@ using System.Text.Json.Serialization; using Merge.Client.Core; -using Merge.Client.Ticketing; using OneOf; #nullable enable namespace Merge.Client.Ticketing; -public class RemoteFieldRequest +public record RemoteFieldRequest { [JsonPropertyName("remote_field_class")] [JsonConverter(typeof(OneOfSerializer>))] - public OneOf RemoteFieldClass { get; init; } + public required OneOf RemoteFieldClass { get; set; } [JsonPropertyName("value")] - public string? Value { get; init; } + public string? Value { get; set; } } diff --git a/src/Merge.Client/Ticketing/Types/RemoteKey.cs b/src/Merge.Client/Ticketing/Types/RemoteKey.cs index c807a5cd..33b5cc92 100644 --- a/src/Merge.Client/Ticketing/Types/RemoteKey.cs +++ b/src/Merge.Client/Ticketing/Types/RemoteKey.cs @@ -4,11 +4,11 @@ namespace Merge.Client.Ticketing; -public class RemoteKey +public record RemoteKey { [JsonPropertyName("name")] - public string Name { get; init; } + public required string Name { get; set; } [JsonPropertyName("key")] - public string Key { get; init; } + public required string Key { get; set; } } diff --git a/src/Merge.Client/Ticketing/Types/RemoteResponse.cs b/src/Merge.Client/Ticketing/Types/RemoteResponse.cs index e6ee49f0..18891c6f 100644 --- a/src/Merge.Client/Ticketing/Types/RemoteResponse.cs +++ b/src/Merge.Client/Ticketing/Types/RemoteResponse.cs @@ -1,30 +1,29 @@ using System.Text.Json.Serialization; -using Merge.Client.Ticketing; #nullable enable namespace Merge.Client.Ticketing; -public class RemoteResponse +public record RemoteResponse { [JsonPropertyName("method")] - public string Method { get; init; } + public required string Method { get; set; } [JsonPropertyName("path")] - public string Path { get; init; } + public required string Path { get; set; } [JsonPropertyName("status")] - public int Status { get; init; } + public required int Status { get; set; } [JsonPropertyName("response")] - public object Response { get; init; } + public required object Response { get; set; } [JsonPropertyName("response_headers")] - public Dictionary? ResponseHeaders { get; init; } + public Dictionary? ResponseHeaders { get; set; } [JsonPropertyName("response_type")] - public ResponseTypeEnum? ResponseType { get; init; } + public ResponseTypeEnum? ResponseType { get; set; } [JsonPropertyName("headers")] - public Dictionary? Headers { get; init; } + public Dictionary? Headers { get; set; } } diff --git a/src/Merge.Client/Ticketing/Types/RequestFormatEnum.cs b/src/Merge.Client/Ticketing/Types/RequestFormatEnum.cs index 5c89d763..72877ee5 100644 --- a/src/Merge.Client/Ticketing/Types/RequestFormatEnum.cs +++ b/src/Merge.Client/Ticketing/Types/RequestFormatEnum.cs @@ -1,7 +1,6 @@ using System.Runtime.Serialization; using System.Text.Json.Serialization; using Merge.Client.Core; -using Merge.Client.Ticketing; #nullable enable diff --git a/src/Merge.Client/Ticketing/Types/ResponseTypeEnum.cs b/src/Merge.Client/Ticketing/Types/ResponseTypeEnum.cs index 2a21e08f..dd21bd5b 100644 --- a/src/Merge.Client/Ticketing/Types/ResponseTypeEnum.cs +++ b/src/Merge.Client/Ticketing/Types/ResponseTypeEnum.cs @@ -1,7 +1,6 @@ using System.Runtime.Serialization; using System.Text.Json.Serialization; using Merge.Client.Core; -using Merge.Client.Ticketing; #nullable enable diff --git a/src/Merge.Client/Ticketing/Types/Role.cs b/src/Merge.Client/Ticketing/Types/Role.cs index 416ee631..90942f38 100644 --- a/src/Merge.Client/Ticketing/Types/Role.cs +++ b/src/Merge.Client/Ticketing/Types/Role.cs @@ -1,44 +1,43 @@ using System.Text.Json.Serialization; -using Merge.Client.Ticketing; #nullable enable namespace Merge.Client.Ticketing; -public class Role +public record Role { [JsonPropertyName("id")] - public string? Id { get; init; } + public string? Id { get; set; } /// /// The third-party API ID of the matching object. /// [JsonPropertyName("remote_id")] - public string? RemoteId { get; init; } + public string? RemoteId { get; set; } /// /// The datetime that this object was created by Merge. /// [JsonPropertyName("created_at")] - public DateTime? CreatedAt { get; init; } + public DateTime? CreatedAt { get; set; } /// /// The datetime that this object was modified by Merge. /// [JsonPropertyName("modified_at")] - public DateTime? ModifiedAt { get; init; } + public DateTime? ModifiedAt { get; set; } /// /// The name of the Role. /// [JsonPropertyName("name")] - public string? Name { get; init; } + public string? Name { get; set; } /// /// The set of actions that a User with this Role can perform. Possible enum values include: `VIEW`, `CREATE`, `EDIT`, `DELETE`, `CLOSE`, and `ASSIGN`. /// [JsonPropertyName("ticket_actions")] - public IEnumerable? TicketActions { get; init; } + public IEnumerable? TicketActions { get; set; } /// /// The level of Ticket access that a User with this Role can perform. @@ -48,17 +47,17 @@ public class Role /// - `TEAM_ONLY` - TEAM_ONLY /// [JsonPropertyName("ticket_access")] - public TicketAccessEnum? TicketAccess { get; init; } + public TicketAccessEnum? TicketAccess { get; set; } /// /// Indicates whether or not this object has been deleted in the third party platform. /// [JsonPropertyName("remote_was_deleted")] - public bool? RemoteWasDeleted { get; init; } + public bool? RemoteWasDeleted { get; set; } [JsonPropertyName("field_mappings")] - public Dictionary? FieldMappings { get; init; } + public Dictionary? FieldMappings { get; set; } [JsonPropertyName("remote_data")] - public IEnumerable? RemoteData { get; init; } + public IEnumerable? RemoteData { get; set; } } diff --git a/src/Merge.Client/Ticketing/Types/RoleEnum.cs b/src/Merge.Client/Ticketing/Types/RoleEnum.cs index e9bcb9ea..54600242 100644 --- a/src/Merge.Client/Ticketing/Types/RoleEnum.cs +++ b/src/Merge.Client/Ticketing/Types/RoleEnum.cs @@ -1,7 +1,6 @@ using System.Runtime.Serialization; using System.Text.Json.Serialization; using Merge.Client.Core; -using Merge.Client.Ticketing; #nullable enable diff --git a/src/Merge.Client/Ticketing/Types/SelectiveSyncConfigurationsUsageEnum.cs b/src/Merge.Client/Ticketing/Types/SelectiveSyncConfigurationsUsageEnum.cs index 06f0b04f..e94d7b7e 100644 --- a/src/Merge.Client/Ticketing/Types/SelectiveSyncConfigurationsUsageEnum.cs +++ b/src/Merge.Client/Ticketing/Types/SelectiveSyncConfigurationsUsageEnum.cs @@ -1,7 +1,6 @@ using System.Runtime.Serialization; using System.Text.Json.Serialization; using Merge.Client.Core; -using Merge.Client.Ticketing; #nullable enable diff --git a/src/Merge.Client/Ticketing/Types/SyncStatus.cs b/src/Merge.Client/Ticketing/Types/SyncStatus.cs index 0a3d61f9..b3abd8a9 100644 --- a/src/Merge.Client/Ticketing/Types/SyncStatus.cs +++ b/src/Merge.Client/Ticketing/Types/SyncStatus.cs @@ -1,30 +1,29 @@ using System.Text.Json.Serialization; -using Merge.Client.Ticketing; #nullable enable namespace Merge.Client.Ticketing; -public class SyncStatus +public record SyncStatus { [JsonPropertyName("model_name")] - public string ModelName { get; init; } + public required string ModelName { get; set; } [JsonPropertyName("model_id")] - public string ModelId { get; init; } + public required string ModelId { get; set; } [JsonPropertyName("last_sync_start")] - public DateTime? LastSyncStart { get; init; } + public DateTime? LastSyncStart { get; set; } [JsonPropertyName("next_sync_start")] - public DateTime? NextSyncStart { get; init; } + public DateTime? NextSyncStart { get; set; } [JsonPropertyName("status")] - public SyncStatusStatusEnum Status { get; init; } + public required SyncStatusStatusEnum Status { get; set; } [JsonPropertyName("is_initial_sync")] - public bool IsInitialSync { get; init; } + public required bool IsInitialSync { get; set; } [JsonPropertyName("selective_sync_configurations_usage")] - public SelectiveSyncConfigurationsUsageEnum? SelectiveSyncConfigurationsUsage { get; init; } + public SelectiveSyncConfigurationsUsageEnum? SelectiveSyncConfigurationsUsage { get; set; } } diff --git a/src/Merge.Client/Ticketing/Types/SyncStatusStatusEnum.cs b/src/Merge.Client/Ticketing/Types/SyncStatusStatusEnum.cs index 046b663b..312a0fbb 100644 --- a/src/Merge.Client/Ticketing/Types/SyncStatusStatusEnum.cs +++ b/src/Merge.Client/Ticketing/Types/SyncStatusStatusEnum.cs @@ -1,7 +1,6 @@ using System.Runtime.Serialization; using System.Text.Json.Serialization; using Merge.Client.Core; -using Merge.Client.Ticketing; #nullable enable diff --git a/src/Merge.Client/Ticketing/Types/Tag.cs b/src/Merge.Client/Ticketing/Types/Tag.cs index 310a0703..dbb02b3e 100644 --- a/src/Merge.Client/Ticketing/Types/Tag.cs +++ b/src/Merge.Client/Ticketing/Types/Tag.cs @@ -1,48 +1,47 @@ using System.Text.Json.Serialization; -using Merge.Client.Ticketing; #nullable enable namespace Merge.Client.Ticketing; -public class Tag +public record Tag { /// /// The third-party API ID of the matching object. /// [JsonPropertyName("remote_id")] - public string? RemoteId { get; init; } + public string? RemoteId { get; set; } /// /// The datetime that this object was created by Merge. /// [JsonPropertyName("created_at")] - public DateTime? CreatedAt { get; init; } + public DateTime? CreatedAt { get; set; } /// /// The datetime that this object was modified by Merge. /// [JsonPropertyName("modified_at")] - public DateTime? ModifiedAt { get; init; } + public DateTime? ModifiedAt { get; set; } [JsonPropertyName("id")] - public string? Id { get; init; } + public string? Id { get; set; } /// /// The tag's name. /// [JsonPropertyName("name")] - public string? Name { get; init; } + public string? Name { get; set; } /// /// Indicates whether or not this object has been deleted in the third party platform. /// [JsonPropertyName("remote_was_deleted")] - public bool? RemoteWasDeleted { get; init; } + public bool? RemoteWasDeleted { get; set; } [JsonPropertyName("field_mappings")] - public Dictionary? FieldMappings { get; init; } + public Dictionary? FieldMappings { get; set; } [JsonPropertyName("remote_data")] - public IEnumerable? RemoteData { get; init; } + public IEnumerable? RemoteData { get; set; } } diff --git a/src/Merge.Client/Ticketing/Types/Team.cs b/src/Merge.Client/Ticketing/Types/Team.cs index 3d279e4c..97e6898b 100644 --- a/src/Merge.Client/Ticketing/Types/Team.cs +++ b/src/Merge.Client/Ticketing/Types/Team.cs @@ -1,54 +1,53 @@ using System.Text.Json.Serialization; -using Merge.Client.Ticketing; #nullable enable namespace Merge.Client.Ticketing; -public class Team +public record Team { [JsonPropertyName("id")] - public string? Id { get; init; } + public string? Id { get; set; } /// /// The third-party API ID of the matching object. /// [JsonPropertyName("remote_id")] - public string? RemoteId { get; init; } + public string? RemoteId { get; set; } /// /// The datetime that this object was created by Merge. /// [JsonPropertyName("created_at")] - public DateTime? CreatedAt { get; init; } + public DateTime? CreatedAt { get; set; } /// /// The datetime that this object was modified by Merge. /// [JsonPropertyName("modified_at")] - public DateTime? ModifiedAt { get; init; } + public DateTime? ModifiedAt { get; set; } /// /// The team's name. /// [JsonPropertyName("name")] - public string? Name { get; init; } + public string? Name { get; set; } /// /// The team's description. /// [JsonPropertyName("description")] - public string? Description { get; init; } + public string? Description { get; set; } /// /// Indicates whether or not this object has been deleted in the third party platform. /// [JsonPropertyName("remote_was_deleted")] - public bool? RemoteWasDeleted { get; init; } + public bool? RemoteWasDeleted { get; set; } [JsonPropertyName("field_mappings")] - public Dictionary? FieldMappings { get; init; } + public Dictionary? FieldMappings { get; set; } [JsonPropertyName("remote_data")] - public IEnumerable? RemoteData { get; init; } + public IEnumerable? RemoteData { get; set; } } diff --git a/src/Merge.Client/Ticketing/Types/Ticket.cs b/src/Merge.Client/Ticketing/Types/Ticket.cs index c1c34147..ae2867a2 100644 --- a/src/Merge.Client/Ticketing/Types/Ticket.cs +++ b/src/Merge.Client/Ticketing/Types/Ticket.cs @@ -1,59 +1,58 @@ using System.Text.Json.Serialization; using Merge.Client.Core; -using Merge.Client.Ticketing; using OneOf; #nullable enable namespace Merge.Client.Ticketing; -public class Ticket +public record Ticket { [JsonPropertyName("id")] - public string? Id { get; init; } + public string? Id { get; set; } /// /// The third-party API ID of the matching object. /// [JsonPropertyName("remote_id")] - public string? RemoteId { get; init; } + public string? RemoteId { get; set; } /// /// The datetime that this object was created by Merge. /// [JsonPropertyName("created_at")] - public DateTime? CreatedAt { get; init; } + public DateTime? CreatedAt { get; set; } /// /// The datetime that this object was modified by Merge. /// [JsonPropertyName("modified_at")] - public DateTime? ModifiedAt { get; init; } + public DateTime? ModifiedAt { get; set; } /// /// The ticket's name. /// [JsonPropertyName("name")] - public string? Name { get; init; } + public string? Name { get; set; } [JsonPropertyName("assignees")] [JsonConverter( typeof(CollectionItemSerializer, OneOfSerializer>>) )] - public IEnumerable>? Assignees { get; init; } + public IEnumerable>? Assignees { get; set; } /// /// The user who created this ticket. /// [JsonPropertyName("creator")] [JsonConverter(typeof(OneOfSerializer>))] - public OneOf? Creator { get; init; } + public OneOf? Creator { get; set; } /// /// The ticket's due date. /// [JsonPropertyName("due_date")] - public DateTime? DueDate { get; init; } + public DateTime? DueDate { get; set; } /// /// The current status of the ticket. @@ -64,13 +63,13 @@ public class Ticket /// - `ON_HOLD` - ON_HOLD /// [JsonPropertyName("status")] - public TicketStatusEnum? Status { get; init; } + public TicketStatusEnum? Status { get; set; } /// /// The ticket’s description. HTML version of description is mapped if supported by the third-party platform. /// [JsonPropertyName("description")] - public string? Description { get; init; } + public string? Description { get; set; } [JsonPropertyName("collections")] [JsonConverter( @@ -79,34 +78,34 @@ public class Ticket OneOfSerializer> >) )] - public IEnumerable>? Collections { get; init; } + public IEnumerable>? Collections { get; set; } /// /// The sub category of the ticket within the 3rd party system. Examples include incident, task, subtask or to-do. /// [JsonPropertyName("ticket_type")] - public string? TicketType { get; init; } + public string? TicketType { get; set; } /// /// The account associated with the ticket. /// [JsonPropertyName("account")] [JsonConverter(typeof(OneOfSerializer>))] - public OneOf? Account { get; init; } + public OneOf? Account { get; set; } /// /// The contact associated with the ticket. /// [JsonPropertyName("contact")] [JsonConverter(typeof(OneOfSerializer>))] - public OneOf? Contact { get; init; } + public OneOf? Contact { get; set; } /// /// The ticket's parent ticket. /// [JsonPropertyName("parent_ticket")] [JsonConverter(typeof(OneOfSerializer>))] - public OneOf? ParentTicket { get; init; } + public OneOf? ParentTicket { get; set; } [JsonPropertyName("attachments")] [JsonConverter( @@ -115,37 +114,37 @@ public class Ticket OneOfSerializer> >) )] - public IEnumerable>? Attachments { get; init; } + public IEnumerable>? Attachments { get; set; } [JsonPropertyName("tags")] - public IEnumerable? Tags { get; init; } + public IEnumerable? Tags { get; set; } /// /// When the third party's ticket was created. /// [JsonPropertyName("remote_created_at")] - public DateTime? RemoteCreatedAt { get; init; } + public DateTime? RemoteCreatedAt { get; set; } /// /// When the third party's ticket was updated. /// [JsonPropertyName("remote_updated_at")] - public DateTime? RemoteUpdatedAt { get; init; } + public DateTime? RemoteUpdatedAt { get; set; } /// /// When the ticket was completed. /// [JsonPropertyName("completed_at")] - public DateTime? CompletedAt { get; init; } + public DateTime? CompletedAt { get; set; } [JsonPropertyName("remote_was_deleted")] - public bool? RemoteWasDeleted { get; init; } + public bool? RemoteWasDeleted { get; set; } /// /// The 3rd party url of the Ticket. /// [JsonPropertyName("ticket_url")] - public string? TicketUrl { get; init; } + public string? TicketUrl { get; set; } /// /// The priority or urgency of the Ticket. @@ -156,14 +155,14 @@ public class Ticket /// - `LOW` - LOW /// [JsonPropertyName("priority")] - public PriorityEnum? Priority { get; init; } + public PriorityEnum? Priority { get; set; } [JsonPropertyName("field_mappings")] - public Dictionary? FieldMappings { get; init; } + public Dictionary? FieldMappings { get; set; } [JsonPropertyName("remote_data")] - public IEnumerable? RemoteData { get; init; } + public IEnumerable? RemoteData { get; set; } [JsonPropertyName("remote_fields")] - public IEnumerable? RemoteFields { get; init; } + public IEnumerable? RemoteFields { get; set; } } diff --git a/src/Merge.Client/Ticketing/Types/TicketAccessEnum.cs b/src/Merge.Client/Ticketing/Types/TicketAccessEnum.cs index ec3d4eed..f9994d26 100644 --- a/src/Merge.Client/Ticketing/Types/TicketAccessEnum.cs +++ b/src/Merge.Client/Ticketing/Types/TicketAccessEnum.cs @@ -1,7 +1,6 @@ using System.Runtime.Serialization; using System.Text.Json.Serialization; using Merge.Client.Core; -using Merge.Client.Ticketing; #nullable enable diff --git a/src/Merge.Client/Ticketing/Types/TicketActionsEnum.cs b/src/Merge.Client/Ticketing/Types/TicketActionsEnum.cs index b0529a34..1feddedf 100644 --- a/src/Merge.Client/Ticketing/Types/TicketActionsEnum.cs +++ b/src/Merge.Client/Ticketing/Types/TicketActionsEnum.cs @@ -1,7 +1,6 @@ using System.Runtime.Serialization; using System.Text.Json.Serialization; using Merge.Client.Core; -using Merge.Client.Ticketing; #nullable enable diff --git a/src/Merge.Client/Ticketing/Types/TicketRequest.cs b/src/Merge.Client/Ticketing/Types/TicketRequest.cs index 94dedd7b..32354262 100644 --- a/src/Merge.Client/Ticketing/Types/TicketRequest.cs +++ b/src/Merge.Client/Ticketing/Types/TicketRequest.cs @@ -1,38 +1,37 @@ using System.Text.Json.Serialization; using Merge.Client.Core; -using Merge.Client.Ticketing; using OneOf; #nullable enable namespace Merge.Client.Ticketing; -public class TicketRequest +public record TicketRequest { /// /// The ticket's name. /// [JsonPropertyName("name")] - public string? Name { get; init; } + public string? Name { get; set; } [JsonPropertyName("assignees")] [JsonConverter( typeof(CollectionItemSerializer, OneOfSerializer>>) )] - public IEnumerable>? Assignees { get; init; } + public IEnumerable>? Assignees { get; set; } /// /// The user who created this ticket. /// [JsonPropertyName("creator")] [JsonConverter(typeof(OneOfSerializer>))] - public OneOf? Creator { get; init; } + public OneOf? Creator { get; set; } /// /// The ticket's due date. /// [JsonPropertyName("due_date")] - public DateTime? DueDate { get; init; } + public DateTime? DueDate { get; set; } /// /// The current status of the ticket. @@ -43,13 +42,13 @@ public class TicketRequest /// - `ON_HOLD` - ON_HOLD /// [JsonPropertyName("status")] - public TicketStatusEnum? Status { get; init; } + public TicketStatusEnum? Status { get; set; } /// /// The ticket’s description. HTML version of description is mapped if supported by the third-party platform. /// [JsonPropertyName("description")] - public string? Description { get; init; } + public string? Description { get; set; } [JsonPropertyName("collections")] [JsonConverter( @@ -58,34 +57,34 @@ public class TicketRequest OneOfSerializer> >) )] - public IEnumerable>? Collections { get; init; } + public IEnumerable>? Collections { get; set; } /// /// The sub category of the ticket within the 3rd party system. Examples include incident, task, subtask or to-do. /// [JsonPropertyName("ticket_type")] - public string? TicketType { get; init; } + public string? TicketType { get; set; } /// /// The account associated with the ticket. /// [JsonPropertyName("account")] [JsonConverter(typeof(OneOfSerializer>))] - public OneOf? Account { get; init; } + public OneOf? Account { get; set; } /// /// The contact associated with the ticket. /// [JsonPropertyName("contact")] [JsonConverter(typeof(OneOfSerializer>))] - public OneOf? Contact { get; init; } + public OneOf? Contact { get; set; } /// /// The ticket's parent ticket. /// [JsonPropertyName("parent_ticket")] [JsonConverter(typeof(OneOfSerializer>))] - public OneOf? ParentTicket { get; init; } + public OneOf? ParentTicket { get; set; } [JsonPropertyName("attachments")] [JsonConverter( @@ -94,22 +93,22 @@ public class TicketRequest OneOfSerializer> >) )] - public IEnumerable>? Attachments { get; init; } + public IEnumerable>? Attachments { get; set; } [JsonPropertyName("tags")] - public IEnumerable? Tags { get; init; } + public IEnumerable? Tags { get; set; } /// /// When the ticket was completed. /// [JsonPropertyName("completed_at")] - public DateTime? CompletedAt { get; init; } + public DateTime? CompletedAt { get; set; } /// /// The 3rd party url of the Ticket. /// [JsonPropertyName("ticket_url")] - public string? TicketUrl { get; init; } + public string? TicketUrl { get; set; } /// /// The priority or urgency of the Ticket. @@ -120,14 +119,14 @@ public class TicketRequest /// - `LOW` - LOW /// [JsonPropertyName("priority")] - public PriorityEnum? Priority { get; init; } + public PriorityEnum? Priority { get; set; } [JsonPropertyName("integration_params")] - public Dictionary? IntegrationParams { get; init; } + public Dictionary? IntegrationParams { get; set; } [JsonPropertyName("linked_account_params")] - public Dictionary? LinkedAccountParams { get; init; } + public Dictionary? LinkedAccountParams { get; set; } [JsonPropertyName("remote_fields")] - public IEnumerable? RemoteFields { get; init; } + public IEnumerable? RemoteFields { get; set; } } diff --git a/src/Merge.Client/Ticketing/Types/TicketResponse.cs b/src/Merge.Client/Ticketing/Types/TicketResponse.cs index fe15f8be..e675db90 100644 --- a/src/Merge.Client/Ticketing/Types/TicketResponse.cs +++ b/src/Merge.Client/Ticketing/Types/TicketResponse.cs @@ -1,21 +1,22 @@ using System.Text.Json.Serialization; -using Merge.Client.Ticketing; #nullable enable namespace Merge.Client.Ticketing; -public class TicketResponse +public record TicketResponse { [JsonPropertyName("model")] - public Ticket Model { get; init; } + public required Ticket Model { get; set; } [JsonPropertyName("warnings")] - public IEnumerable Warnings { get; init; } + public IEnumerable Warnings { get; set; } = + new List(); [JsonPropertyName("errors")] - public IEnumerable Errors { get; init; } + public IEnumerable Errors { get; set; } = + new List(); [JsonPropertyName("logs")] - public IEnumerable? Logs { get; init; } + public IEnumerable? Logs { get; set; } } diff --git a/src/Merge.Client/Ticketing/Types/TicketStatusEnum.cs b/src/Merge.Client/Ticketing/Types/TicketStatusEnum.cs index f503c104..50638b4c 100644 --- a/src/Merge.Client/Ticketing/Types/TicketStatusEnum.cs +++ b/src/Merge.Client/Ticketing/Types/TicketStatusEnum.cs @@ -1,7 +1,6 @@ using System.Runtime.Serialization; using System.Text.Json.Serialization; using Merge.Client.Core; -using Merge.Client.Ticketing; #nullable enable diff --git a/src/Merge.Client/Ticketing/Types/TicketingAttachmentResponse.cs b/src/Merge.Client/Ticketing/Types/TicketingAttachmentResponse.cs index 9c9b31b6..c3bf0e4e 100644 --- a/src/Merge.Client/Ticketing/Types/TicketingAttachmentResponse.cs +++ b/src/Merge.Client/Ticketing/Types/TicketingAttachmentResponse.cs @@ -1,21 +1,22 @@ using System.Text.Json.Serialization; -using Merge.Client.Ticketing; #nullable enable namespace Merge.Client.Ticketing; -public class TicketingAttachmentResponse +public record TicketingAttachmentResponse { [JsonPropertyName("model")] - public Attachment Model { get; init; } + public required Attachment Model { get; set; } [JsonPropertyName("warnings")] - public IEnumerable Warnings { get; init; } + public IEnumerable Warnings { get; set; } = + new List(); [JsonPropertyName("errors")] - public IEnumerable Errors { get; init; } + public IEnumerable Errors { get; set; } = + new List(); [JsonPropertyName("logs")] - public IEnumerable? Logs { get; init; } + public IEnumerable? Logs { get; set; } } diff --git a/src/Merge.Client/Ticketing/Types/TicketingContactResponse.cs b/src/Merge.Client/Ticketing/Types/TicketingContactResponse.cs index 73f2d704..876367a3 100644 --- a/src/Merge.Client/Ticketing/Types/TicketingContactResponse.cs +++ b/src/Merge.Client/Ticketing/Types/TicketingContactResponse.cs @@ -1,21 +1,22 @@ using System.Text.Json.Serialization; -using Merge.Client.Ticketing; #nullable enable namespace Merge.Client.Ticketing; -public class TicketingContactResponse +public record TicketingContactResponse { [JsonPropertyName("model")] - public Contact Model { get; init; } + public required Contact Model { get; set; } [JsonPropertyName("warnings")] - public IEnumerable Warnings { get; init; } + public IEnumerable Warnings { get; set; } = + new List(); [JsonPropertyName("errors")] - public IEnumerable Errors { get; init; } + public IEnumerable Errors { get; set; } = + new List(); [JsonPropertyName("logs")] - public IEnumerable? Logs { get; init; } + public IEnumerable? Logs { get; set; } } diff --git a/src/Merge.Client/Ticketing/Types/User.cs b/src/Merge.Client/Ticketing/Types/User.cs index eb6b7cba..5c78f1ae 100644 --- a/src/Merge.Client/Ticketing/Types/User.cs +++ b/src/Merge.Client/Ticketing/Types/User.cs @@ -1,80 +1,79 @@ using System.Text.Json.Serialization; using Merge.Client.Core; -using Merge.Client.Ticketing; using OneOf; #nullable enable namespace Merge.Client.Ticketing; -public class User +public record User { [JsonPropertyName("id")] - public string? Id { get; init; } + public string? Id { get; set; } /// /// The third-party API ID of the matching object. /// [JsonPropertyName("remote_id")] - public string? RemoteId { get; init; } + public string? RemoteId { get; set; } /// /// The datetime that this object was created by Merge. /// [JsonPropertyName("created_at")] - public DateTime? CreatedAt { get; init; } + public DateTime? CreatedAt { get; set; } /// /// The datetime that this object was modified by Merge. /// [JsonPropertyName("modified_at")] - public DateTime? ModifiedAt { get; init; } + public DateTime? ModifiedAt { get; set; } /// /// The user's name. /// [JsonPropertyName("name")] - public string? Name { get; init; } + public string? Name { get; set; } /// /// The user's email address. /// [JsonPropertyName("email_address")] - public string? EmailAddress { get; init; } + public string? EmailAddress { get; set; } /// /// Whether or not the user is active. /// [JsonPropertyName("is_active")] - public bool? IsActive { get; init; } + public bool? IsActive { get; set; } [JsonPropertyName("teams")] [JsonConverter( typeof(CollectionItemSerializer, OneOfSerializer>>) )] - public IEnumerable>? Teams { get; init; } + public IEnumerable>? Teams { get; set; } [JsonPropertyName("roles")] [JsonConverter( typeof(CollectionItemSerializer, OneOfSerializer>>) )] - public IEnumerable>? Roles { get; init; } + public IEnumerable>? Roles { get; set; } /// /// The user's avatar picture. /// [JsonPropertyName("avatar")] - public string? Avatar { get; init; } + public string? Avatar { get; set; } /// /// Indicates whether or not this object has been deleted in the third party platform. /// [JsonPropertyName("remote_was_deleted")] - public bool? RemoteWasDeleted { get; init; } + public bool? RemoteWasDeleted { get; set; } [JsonPropertyName("field_mappings")] - public Dictionary? FieldMappings { get; init; } + public Dictionary? FieldMappings { get; set; } [JsonPropertyName("remote_data")] - public IEnumerable? RemoteData { get; init; } + public IEnumerable? RemoteData { get; set; } } diff --git a/src/Merge.Client/Ticketing/Types/ValidationProblemSource.cs b/src/Merge.Client/Ticketing/Types/ValidationProblemSource.cs index ee47bda6..82273ccc 100644 --- a/src/Merge.Client/Ticketing/Types/ValidationProblemSource.cs +++ b/src/Merge.Client/Ticketing/Types/ValidationProblemSource.cs @@ -4,8 +4,8 @@ namespace Merge.Client.Ticketing; -public class ValidationProblemSource +public record ValidationProblemSource { [JsonPropertyName("pointer")] - public string Pointer { get; init; } + public required string Pointer { get; set; } } diff --git a/src/Merge.Client/Ticketing/Types/WarningValidationProblem.cs b/src/Merge.Client/Ticketing/Types/WarningValidationProblem.cs index 31e09dcb..adf79b5d 100644 --- a/src/Merge.Client/Ticketing/Types/WarningValidationProblem.cs +++ b/src/Merge.Client/Ticketing/Types/WarningValidationProblem.cs @@ -1,21 +1,20 @@ using System.Text.Json.Serialization; -using Merge.Client.Ticketing; #nullable enable namespace Merge.Client.Ticketing; -public class WarningValidationProblem +public record WarningValidationProblem { [JsonPropertyName("source")] - public ValidationProblemSource? Source { get; init; } + public ValidationProblemSource? Source { get; set; } [JsonPropertyName("title")] - public string Title { get; init; } + public required string Title { get; set; } [JsonPropertyName("detail")] - public string Detail { get; init; } + public required string Detail { get; set; } [JsonPropertyName("problem_type")] - public string ProblemType { get; init; } + public required string ProblemType { get; set; } } diff --git a/src/Merge.Client/Ticketing/Types/WebhookReceiver.cs b/src/Merge.Client/Ticketing/Types/WebhookReceiver.cs index 06b35d48..2e4364a3 100644 --- a/src/Merge.Client/Ticketing/Types/WebhookReceiver.cs +++ b/src/Merge.Client/Ticketing/Types/WebhookReceiver.cs @@ -4,14 +4,14 @@ namespace Merge.Client.Ticketing; -public class WebhookReceiver +public record WebhookReceiver { [JsonPropertyName("event")] - public string Event { get; init; } + public required string Event { get; set; } [JsonPropertyName("is_active")] - public bool IsActive { get; init; } + public required bool IsActive { get; set; } [JsonPropertyName("key")] - public string? Key { get; init; } + public string? Key { get; set; } } diff --git a/src/Merge.Client/Ticketing/Users/Requests/UsersListRequest.cs b/src/Merge.Client/Ticketing/Users/Requests/UsersListRequest.cs index 3d2e7a28..50b22560 100644 --- a/src/Merge.Client/Ticketing/Users/Requests/UsersListRequest.cs +++ b/src/Merge.Client/Ticketing/Users/Requests/UsersListRequest.cs @@ -1,63 +1,59 @@ -using Merge.Client.Ticketing; - -#nullable enable - namespace Merge.Client.Ticketing; -public class UsersListRequest +public record UsersListRequest { /// /// If provided, will only return objects created after this datetime. /// - public DateTime? CreatedAfter { get; init; } + public DateTime? CreatedAfter { get; set; } /// /// If provided, will only return objects created before this datetime. /// - public DateTime? CreatedBefore { get; init; } + public DateTime? CreatedBefore { get; set; } /// /// The pagination cursor value. /// - public string? Cursor { get; init; } + public string? Cursor { get; set; } /// /// If provided, will only return users with emails equal to this value (case insensitive). /// - public string? EmailAddress { get; init; } + public string? EmailAddress { get; set; } /// /// Which relations should be returned in expanded form. Multiple relation names should be comma separated without spaces. /// - public UsersListRequestExpand? Expand { get; init; } + public UsersListRequestExpand? Expand { get; set; } /// /// Whether to include data that was marked as deleted by third party webhooks. /// - public bool? IncludeDeletedData { get; init; } + public bool? IncludeDeletedData { get; set; } /// /// Whether to include the original data Merge fetched from the third-party to produce these models. /// - public bool? IncludeRemoteData { get; init; } + public bool? IncludeRemoteData { get; set; } /// /// If provided, only objects synced by Merge after this date time will be returned. /// - public DateTime? ModifiedAfter { get; init; } + public DateTime? ModifiedAfter { get; set; } /// /// If provided, only objects synced by Merge before this date time will be returned. /// - public DateTime? ModifiedBefore { get; init; } + public DateTime? ModifiedBefore { get; set; } /// /// Number of results to return per page. /// - public int? PageSize { get; init; } + public int? PageSize { get; set; } /// /// The API provider's ID for the given object. /// - public string? RemoteId { get; init; } + public string? RemoteId { get; set; } } diff --git a/src/Merge.Client/Ticketing/Users/Requests/UsersRetrieveRequest.cs b/src/Merge.Client/Ticketing/Users/Requests/UsersRetrieveRequest.cs index 18bd31f4..bdd5445f 100644 --- a/src/Merge.Client/Ticketing/Users/Requests/UsersRetrieveRequest.cs +++ b/src/Merge.Client/Ticketing/Users/Requests/UsersRetrieveRequest.cs @@ -1,18 +1,14 @@ -using Merge.Client.Ticketing; - -#nullable enable - namespace Merge.Client.Ticketing; -public class UsersRetrieveRequest +public record UsersRetrieveRequest { /// /// Which relations should be returned in expanded form. Multiple relation names should be comma separated without spaces. /// - public UsersRetrieveRequestExpand? Expand { get; init; } + public UsersRetrieveRequestExpand? Expand { get; set; } /// /// Whether to include the original data Merge fetched from the third-party to produce these models. /// - public bool? IncludeRemoteData { get; init; } + public bool? IncludeRemoteData { get; set; } } diff --git a/src/Merge.Client/Ticketing/Users/Types/UsersListRequestExpand.cs b/src/Merge.Client/Ticketing/Users/Types/UsersListRequestExpand.cs index 3ef633db..1a15b697 100644 --- a/src/Merge.Client/Ticketing/Users/Types/UsersListRequestExpand.cs +++ b/src/Merge.Client/Ticketing/Users/Types/UsersListRequestExpand.cs @@ -1,7 +1,6 @@ using System.Runtime.Serialization; using System.Text.Json.Serialization; using Merge.Client.Core; -using Merge.Client.Ticketing; #nullable enable diff --git a/src/Merge.Client/Ticketing/Users/Types/UsersRetrieveRequestExpand.cs b/src/Merge.Client/Ticketing/Users/Types/UsersRetrieveRequestExpand.cs index ddafcf4c..927e3905 100644 --- a/src/Merge.Client/Ticketing/Users/Types/UsersRetrieveRequestExpand.cs +++ b/src/Merge.Client/Ticketing/Users/Types/UsersRetrieveRequestExpand.cs @@ -1,7 +1,6 @@ using System.Runtime.Serialization; using System.Text.Json.Serialization; using Merge.Client.Core; -using Merge.Client.Ticketing; #nullable enable diff --git a/src/Merge.Client/Ticketing/Users/UsersClient.cs b/src/Merge.Client/Ticketing/Users/UsersClient.cs index 883f5721..383134fe 100644 --- a/src/Merge.Client/Ticketing/Users/UsersClient.cs +++ b/src/Merge.Client/Ticketing/Users/UsersClient.cs @@ -1,6 +1,6 @@ +using System.Net.Http; using System.Text.Json; -using Merge.Client; -using Merge.Client.Ticketing; +using Merge.Client.Core; #nullable enable @@ -18,16 +18,21 @@ public UsersClient(RawClient client) /// /// Returns a list of `User` objects. /// - public async Task ListAsync(UsersListRequest request) + public async Task ListAsync( + UsersListRequest request, + RequestOptions? options = null + ) { var _query = new Dictionary() { }; if (request.CreatedAfter != null) { - _query["created_after"] = request.CreatedAfter.Value.ToString("o0"); + _query["created_after"] = request.CreatedAfter.Value.ToString(Constants.DateTimeFormat); } if (request.CreatedBefore != null) { - _query["created_before"] = request.CreatedBefore.Value.ToString("o0"); + _query["created_before"] = request.CreatedBefore.Value.ToString( + Constants.DateTimeFormat + ); } if (request.Cursor != null) { @@ -51,11 +56,15 @@ public async Task ListAsync(UsersListRequest request) } if (request.ModifiedAfter != null) { - _query["modified_after"] = request.ModifiedAfter.Value.ToString("o0"); + _query["modified_after"] = request.ModifiedAfter.Value.ToString( + Constants.DateTimeFormat + ); } if (request.ModifiedBefore != null) { - _query["modified_before"] = request.ModifiedBefore.Value.ToString("o0"); + _query["modified_before"] = request.ModifiedBefore.Value.ToString( + Constants.DateTimeFormat + ); } if (request.PageSize != null) { @@ -68,23 +77,41 @@ public async Task ListAsync(UsersListRequest request) var response = await _client.MakeRequestAsync( new RawClient.JsonApiRequest { + BaseUrl = _client.Options.BaseUrl, Method = HttpMethod.Get, Path = "ticketing/v1/users", - Query = _query + Query = _query, + Options = options } ); - string responseBody = await response.Raw.Content.ReadAsStringAsync(); - if (response.StatusCode >= 200 && response.StatusCode < 400) + var responseBody = await response.Raw.Content.ReadAsStringAsync(); + if (response.StatusCode is >= 200 and < 400) { - return JsonSerializer.Deserialize(responseBody); + try + { + return JsonUtils.Deserialize(responseBody)!; + } + catch (JsonException e) + { + throw new MergeException("Failed to deserialize response", e); + } } - throw new Exception(responseBody); + + throw new MergeApiException( + $"Error with status code {response.StatusCode}", + response.StatusCode, + JsonUtils.Deserialize(responseBody) + ); } /// /// Returns a `User` object with the given `id`. /// - public async Task RetrieveAsync(string id, UsersRetrieveRequest request) + public async Task RetrieveAsync( + string id, + UsersRetrieveRequest request, + RequestOptions? options = null + ) { var _query = new Dictionary() { }; if (request.Expand != null) @@ -98,16 +125,30 @@ public async Task RetrieveAsync(string id, UsersRetrieveRequest request) var response = await _client.MakeRequestAsync( new RawClient.JsonApiRequest { + BaseUrl = _client.Options.BaseUrl, Method = HttpMethod.Get, Path = $"ticketing/v1/users/{id}", - Query = _query + Query = _query, + Options = options } ); - string responseBody = await response.Raw.Content.ReadAsStringAsync(); - if (response.StatusCode >= 200 && response.StatusCode < 400) + var responseBody = await response.Raw.Content.ReadAsStringAsync(); + if (response.StatusCode is >= 200 and < 400) { - return JsonSerializer.Deserialize(responseBody); + try + { + return JsonUtils.Deserialize(responseBody)!; + } + catch (JsonException e) + { + throw new MergeException("Failed to deserialize response", e); + } } - throw new Exception(responseBody); + + throw new MergeApiException( + $"Error with status code {response.StatusCode}", + response.StatusCode, + JsonUtils.Deserialize(responseBody) + ); } } diff --git a/src/Merge.Client/Ticketing/WebhookReceivers/Requests/WebhookReceiverRequest.cs b/src/Merge.Client/Ticketing/WebhookReceivers/Requests/WebhookReceiverRequest.cs index 4adb9fbc..5abd2315 100644 --- a/src/Merge.Client/Ticketing/WebhookReceivers/Requests/WebhookReceiverRequest.cs +++ b/src/Merge.Client/Ticketing/WebhookReceivers/Requests/WebhookReceiverRequest.cs @@ -4,14 +4,14 @@ namespace Merge.Client.Ticketing; -public class WebhookReceiverRequest +public record WebhookReceiverRequest { [JsonPropertyName("event")] - public string Event { get; init; } + public required string Event { get; set; } [JsonPropertyName("is_active")] - public bool IsActive { get; init; } + public required bool IsActive { get; set; } [JsonPropertyName("key")] - public string? Key { get; init; } + public string? Key { get; set; } } diff --git a/src/Merge.Client/Ticketing/WebhookReceivers/WebhookReceiversClient.cs b/src/Merge.Client/Ticketing/WebhookReceivers/WebhookReceiversClient.cs index ff6142ac..a166fee4 100644 --- a/src/Merge.Client/Ticketing/WebhookReceivers/WebhookReceiversClient.cs +++ b/src/Merge.Client/Ticketing/WebhookReceivers/WebhookReceiversClient.cs @@ -1,6 +1,6 @@ +using System.Net.Http; using System.Text.Json; -using Merge.Client; -using Merge.Client.Ticketing; +using Merge.Client.Core; #nullable enable @@ -18,41 +18,72 @@ public WebhookReceiversClient(RawClient client) /// /// Returns a list of `WebhookReceiver` objects. /// - public async Task> ListAsync() + public async Task> ListAsync(RequestOptions? options = null) { var response = await _client.MakeRequestAsync( new RawClient.JsonApiRequest { + BaseUrl = _client.Options.BaseUrl, Method = HttpMethod.Get, - Path = "ticketing/v1/webhook-receivers" + Path = "ticketing/v1/webhook-receivers", + Options = options } ); - string responseBody = await response.Raw.Content.ReadAsStringAsync(); - if (response.StatusCode >= 200 && response.StatusCode < 400) + var responseBody = await response.Raw.Content.ReadAsStringAsync(); + if (response.StatusCode is >= 200 and < 400) { - return JsonSerializer.Deserialize>(responseBody); + try + { + return JsonUtils.Deserialize>(responseBody)!; + } + catch (JsonException e) + { + throw new MergeException("Failed to deserialize response", e); + } } - throw new Exception(responseBody); + + throw new MergeApiException( + $"Error with status code {response.StatusCode}", + response.StatusCode, + JsonUtils.Deserialize(responseBody) + ); } /// /// Creates a `WebhookReceiver` object with the given values. /// - public async Task CreateAsync(WebhookReceiverRequest request) + public async Task CreateAsync( + WebhookReceiverRequest request, + RequestOptions? options = null + ) { var response = await _client.MakeRequestAsync( new RawClient.JsonApiRequest { + BaseUrl = _client.Options.BaseUrl, Method = HttpMethod.Post, Path = "ticketing/v1/webhook-receivers", - Body = request + Body = request, + Options = options } ); - string responseBody = await response.Raw.Content.ReadAsStringAsync(); - if (response.StatusCode >= 200 && response.StatusCode < 400) + var responseBody = await response.Raw.Content.ReadAsStringAsync(); + if (response.StatusCode is >= 200 and < 400) { - return JsonSerializer.Deserialize(responseBody); + try + { + return JsonUtils.Deserialize(responseBody)!; + } + catch (JsonException e) + { + throw new MergeException("Failed to deserialize response", e); + } } - throw new Exception(responseBody); + + throw new MergeApiException( + $"Error with status code {response.StatusCode}", + response.StatusCode, + JsonUtils.Deserialize(responseBody) + ); } }