Skip to content

Commit

Permalink
Release v0.3.36
Browse files Browse the repository at this point in the history
  • Loading branch information
fern-api[bot] committed May 28, 2024
1 parent cf0d231 commit b00e4a7
Show file tree
Hide file tree
Showing 16 changed files with 137 additions and 110 deletions.
20 changes: 10 additions & 10 deletions src/Mercoa.Client.sln
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@ Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio Version 17
VisualStudioVersion = 17.0.31903.59
MinimumVisualStudioVersion = 10.0.40219.1
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Mercoa.Client", "Mercoa.Client\Mercoa.Client.csproj", "{4530AE6C-F016-4DB4-8B2C-2FC3CAAD1878}"
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Mercoa.Client", "Mercoa.Client\Mercoa.Client.csproj", "{C7248B78-60ED-4C1D-A405-DFB54E67ACEB}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Mercoa.Client.Test", "Mercoa.Client.Test\Mercoa.Client.Test.csproj", "{C2AC1CE2-705D-42D9-98E7-6360747263F5}"
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Mercoa.Client.Test", "Mercoa.Client.Test\Mercoa.Client.Test.csproj", "{2AC14705-C577-4654-83EF-1B12452A5AED}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Expand All @@ -16,13 +16,13 @@ Global
HideSolutionNode = FALSE
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{4530AE6C-F016-4DB4-8B2C-2FC3CAAD1878}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{4530AE6C-F016-4DB4-8B2C-2FC3CAAD1878}.Debug|Any CPU.Build.0 = Debug|Any CPU
{4530AE6C-F016-4DB4-8B2C-2FC3CAAD1878}.Release|Any CPU.ActiveCfg = Release|Any CPU
{4530AE6C-F016-4DB4-8B2C-2FC3CAAD1878}.Release|Any CPU.Build.0 = Release|Any CPU
{C2AC1CE2-705D-42D9-98E7-6360747263F5}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{C2AC1CE2-705D-42D9-98E7-6360747263F5}.Debug|Any CPU.Build.0 = Debug|Any CPU
{C2AC1CE2-705D-42D9-98E7-6360747263F5}.Release|Any CPU.ActiveCfg = Release|Any CPU
{C2AC1CE2-705D-42D9-98E7-6360747263F5}.Release|Any CPU.Build.0 = Release|Any CPU
{C7248B78-60ED-4C1D-A405-DFB54E67ACEB}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{C7248B78-60ED-4C1D-A405-DFB54E67ACEB}.Debug|Any CPU.Build.0 = Debug|Any CPU
{C7248B78-60ED-4C1D-A405-DFB54E67ACEB}.Release|Any CPU.ActiveCfg = Release|Any CPU
{C7248B78-60ED-4C1D-A405-DFB54E67ACEB}.Release|Any CPU.Build.0 = Release|Any CPU
{2AC14705-C577-4654-83EF-1B12452A5AED}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{2AC14705-C577-4654-83EF-1B12452A5AED}.Debug|Any CPU.Build.0 = Debug|Any CPU
{2AC14705-C577-4654-83EF-1B12452A5AED}.Release|Any CPU.ActiveCfg = Release|Any CPU
{2AC14705-C577-4654-83EF-1B12452A5AED}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
EndGlobal
4 changes: 3 additions & 1 deletion src/Mercoa.Client/Core/ClientOptions.cs
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
using Mercoa.Client.Core;

namespace Mercoa.Client;

public partial class ClientOptions
{
/// <summary>
/// The Base URL for the API.
/// </summary>
public string? BaseUrl { get; init; }
public string BaseUrl { get; init; } = Environments.PRODUCTION;

/// <summary>
/// The http client used to make requests.
Expand Down
6 changes: 6 additions & 0 deletions src/Mercoa.Client/Core/Environments.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
namespace Mercoa.Client.Core;

public class Environments
{
public static string PRODUCTION = "https://api.mercoa.com";
}
75 changes: 75 additions & 0 deletions src/Mercoa.Client/Core/JsonEnumMemberStringEnumConverter.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
using System.Reflection;
using System.Runtime.Serialization;
using System.Text.Json;
using System.Text.Json.Serialization;

namespace Mercoa.Client;

#nullable enable

/// <summary>
/// Handles serializing C# enums into the appropriate string values.
/// </summary>
public class JsonEnumMemberStringEnumConverter : JsonConverterFactory
{
private readonly JsonNamingPolicy? _namingPolicy;
private readonly bool _allowIntegerValues;
private readonly JsonStringEnumConverter _baseConverter;

public JsonEnumMemberStringEnumConverter(
JsonNamingPolicy? namingPolicy = null,
bool allowIntegerValues = true
)
{
_namingPolicy = namingPolicy;
_allowIntegerValues = allowIntegerValues;
_baseConverter = new JsonStringEnumConverter(namingPolicy, allowIntegerValues);
}

public override bool CanConvert(Type typeToConvert) => _baseConverter.CanConvert(typeToConvert);

public override JsonConverter CreateConverter(Type typeToConvert, JsonSerializerOptions options)
{
var query =
from field in typeToConvert.GetFields(BindingFlags.Public | BindingFlags.Static)
let attr = field.GetCustomAttribute<EnumMemberAttribute>()
where attr != null && attr.Value != null
select (field.Name, attr.Value);
var dictionary = query.ToDictionary(p => p.Item1, p => p.Item2);
if (dictionary.Count > 0)
return new JsonStringEnumConverter(
new DictionaryLookupNamingPolicy(dictionary, _namingPolicy),
_allowIntegerValues
).CreateConverter(typeToConvert, options);
else
return _baseConverter.CreateConverter(typeToConvert, options);
}
}

public class JsonNamingPolicyDecorator : JsonNamingPolicy
{
readonly JsonNamingPolicy? _underlyingNamingPolicy;

protected JsonNamingPolicyDecorator(JsonNamingPolicy? underlyingNamingPolicy)
{
_underlyingNamingPolicy = underlyingNamingPolicy;
}

public override string ConvertName(string name) =>
_underlyingNamingPolicy?.ConvertName(name) ?? name;
}

internal class DictionaryLookupNamingPolicy : JsonNamingPolicyDecorator
{
readonly Dictionary<string, string> dictionary;

public DictionaryLookupNamingPolicy(
Dictionary<string, string> dictionary,
JsonNamingPolicy? underlyingNamingPolicy
)
: base(underlyingNamingPolicy) =>
this.dictionary = dictionary ?? throw new ArgumentNullException();

public override string ConvertName(string name) =>
dictionary.TryGetValue(name, out var value) ? value : base.ConvertName(name);
}
10 changes: 8 additions & 2 deletions src/Mercoa.Client/Core/RawClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,14 @@ public async Task<ApiResponse> MakeRequestAsync(ApiRequest request)
// Add the request body to the request
if (request.Body != null)
{
var serializerOptions = new JsonSerializerOptions
{
Converters = { new JsonEnumMemberStringEnumConverter() },
// Set other options as required:
WriteIndented = true,
};
httpRequest.Content = new StringContent(
JsonSerializer.Serialize(request.Body),
JsonSerializer.Serialize(request.Body, serializerOptions),
Encoding.UTF8,
"application/json"
);
Expand Down Expand Up @@ -106,7 +112,7 @@ private Dictionary<string, string> GetHeaders(ApiRequest request)

private string BuildUrl(string path, Dictionary<string, object> query)
{
var url = $"{_clientOptions.BaseUrl}/{path}";
var url = $"{_clientOptions.BaseUrl}{path}";
if (query.Count > 0)
{
url += "?";
Expand Down
4 changes: 2 additions & 2 deletions src/Mercoa.Client/Entity/EmailLog/EmailLogClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ public EmailLogClient(RawClient client)
}

/// <summary>
/// Get entity users
/// Get all incoming invoice emails for an entity.
/// </summary>
public async Task<EmailLogResponse> FindAsync(string entityId, EntityEmailLogRequest request)
{
Expand Down Expand Up @@ -56,7 +56,7 @@ public async Task<EmailLogResponse> FindAsync(string entityId, EntityEmailLogReq
}

/// <summary>
/// Get email log
/// Get an email log by ID
/// </summary>
public async Task<EmailLog> GetAsync(string entityId, string logId)
{
Expand Down
2 changes: 2 additions & 0 deletions src/Mercoa.Client/Entity/EntityClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -191,6 +191,8 @@ public async void InitiateKybAsync(string entityId)

/// <summary>
/// Generate a JWT token for an entity with the given options. This token can be used to authenticate the entity in the Mercoa API and iFrame.
///
/// <Warning>We recommend using [this endpoint](/api-reference/entity/user/get-token). This will enable features such as approvals and comments.</Warning>
/// </summary>
public async Task<string> GetTokenAsync(string entityId, TokenGenerationOptions request)
{
Expand Down
23 changes: 0 additions & 23 deletions src/Mercoa.Client/Entity/Invoice/InvoiceClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -103,29 +103,6 @@ public async Task<FindInvoiceResponse> FindAsync(EntityGetInvoicesRequest reques
throw new Exception();
}

public async Task<InvoiceResponse> GetAsync(string invoiceId, GetInvoice request)
{
var _query = new Dictionary<string, object>() { };
if (request.IncludeFees != null)
{
_query["includeFees"] = request.IncludeFees;
}
var response = await _client.MakeRequestAsync(
new RawClient.ApiRequest
{
Method = HttpMethod.Get,
Path = $"/invoice/{invoiceId}",
Query = _query
}
);
string responseBody = await response.Raw.Content.ReadAsStringAsync();
if (response.StatusCode >= 200 && response.StatusCode < 400)
{
return JsonSerializer.Deserialize<InvoiceResponse>(responseBody);
}
throw new Exception();
}

/// <summary>
/// Get invoice metrics for an entity with the given filters. Invoices will be grouped by currency. If none of excludePayables, excludeReceivables, payerId, vendorId, or invoiceId status filters are provided, excludeReceivables will be set to true.
/// </summary>
Expand Down
9 changes: 0 additions & 9 deletions src/Mercoa.Client/Entity/Invoice/requests/GetInvoice.cs

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
using System.Text.Json.Serialization;

namespace Mercoa.Client.Entity;

public class CompleteMicroDepositsRequest
{
/// <summary>
/// The amounts of the micro deposits in cents
/// </summary>
[JsonPropertyName("amounts")]
public List<int> Amounts { get; init; }
}
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
using System.Text.Json.Serialization;

namespace Mercoa.Client.Invoice;

public class UploadDocumentRequest
{
/// <summary>
/// Base64 encoded image or PDF of invoice document. PNG, JPG, and PDF are supported. 10MB max.
/// </summary>
[JsonPropertyName("document")]
public string? Document { get; init; }
}
9 changes: 5 additions & 4 deletions src/Mercoa.Client/Mercoa.Client.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -5,18 +5,19 @@
<TargetFramework>net7.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<NuGetAudit>false</NuGetAudit>
<Version>0.3.35</Version>
<Version>v0.3.36</Version>
<PackageReadmeFile>README.md</PackageReadmeFile>
<PackageProjectUrl>https://github.com/mercoa-finance/csharp</PackageProjectUrl>
</PropertyGroup>

<ItemGroup>
<None Include="..\..\README.md" Pack="true" PackagePath=""/>
<PackageReference Include="OneOf" Version="3.0.263" />
<PackageReference Include="System.Text.Json" Version="8.0.3" />
</ItemGroup>

<ItemGroup>
<PackageReference Include="OneOf" Version="3.0.263" />
<PackageReference Include="System.Text.Json" Version="8.0.3" />
<None Include="..\..\README.md" Pack="true" PackagePath=""/>
</ItemGroup>


</Project>
4 changes: 2 additions & 2 deletions src/Mercoa.Client/Mercoa.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@ public Mercoa(string token = null, ClientOptions clientOptions = null)
{
{ "Authorization", $"Bearer {token}" },
{ "X-Fern-Language", "C#" },
{ "X-Fern-SDK-Name", "mercoa_fern_api_sdk" },
{ "X-Fern-SDK-Version", "0.3.35" },
{ "X-Fern-SDK-Name", "Mercoa.Client" },
{ "X-Fern-SDK-Version", "v0.3.36" },
},
clientOptions ?? new ClientOptions()
);
Expand Down
26 changes: 4 additions & 22 deletions src/Mercoa.Client/Ocr/OcrClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,23 +15,14 @@ public OcrClient(RawClient client)
/// <summary>
/// Run OCR on an Base64 encoded image or PDF. This endpoint will block until the OCR is complete.
/// </summary>
public async Task<OcrResponse> OcrAsync(RunOcrSync request)
public async Task<OcrResponse> OcrAsync(OcrRequest request)
{
var _query = new Dictionary<string, object>() { };
if (request.VendorNetwork != null)
{
_query["vendorNetwork"] = request.VendorNetwork;
}
if (request.EntityId != null)
{
_query["entityId"] = request.EntityId;
}
var response = await _client.MakeRequestAsync(
new RawClient.ApiRequest
{
Method = HttpMethod.Post,
Path = "/ocr",
Query = _query
Body = request
}
);
string responseBody = await response.Raw.Content.ReadAsStringAsync();
Expand All @@ -45,23 +36,14 @@ public async Task<OcrResponse> OcrAsync(RunOcrSync request)
/// <summary>
/// Run OCR on an Base64 encoded image or PDF. This endpoint will return immediately and the OCR will be processed asynchronously.
/// </summary>
public async Task<OcrAsyncResponse> RunAsyncOcrAsync(RunOcrAsync request)
public async Task<OcrAsyncResponse> RunAsyncOcrAsync(OcrRequest request)
{
var _query = new Dictionary<string, object>() { };
if (request.VendorNetwork != null)
{
_query["vendorNetwork"] = request.VendorNetwork;
}
if (request.EntityId != null)
{
_query["entityId"] = request.EntityId;
}
var response = await _client.MakeRequestAsync(
new RawClient.ApiRequest
{
Method = HttpMethod.Post,
Path = "/ocr-async",
Query = _query
Body = request
}
);
string responseBody = await response.Raw.Content.ReadAsStringAsync();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,26 +1,31 @@
using System.Text.Json.Serialization;
using Mercoa.Client;

namespace Mercoa.Client;

public class RunOcrAsync
public class OcrRequest
{
/// <summary>
/// Limit OCR vendor search to a specific network
/// MIME type of the image. Supported types are image/png, image/jpeg, and application/pdf.
/// </summary>
public VendorNetwork? VendorNetwork { get; init; }
[JsonPropertyName("mimeType")]
public string MimeType { get; init; }

/// <summary>
/// When using the Entity vendor network, specify the entity to use if. EntityId on an auth token will take precedence over this parameter.
/// Base64 encoded image or PDF. PNG, JPG, and PDF are supported. 10MB max.
/// </summary>
public string? EntityId { get; init; }
[JsonPropertyName("image")]
public string Image { get; init; }

/// <summary>
/// MIME type of the image. Supported types are image/png, image/jpeg, and application/pdf.
/// Limit OCR vendor search to a specific network
/// </summary>
public string MimeType { get; init; }
[JsonPropertyName("vendorNetwork")]
public VendorNetwork? VendorNetwork { get; init; }

/// <summary>
/// Base64 encoded image or PDF. PNG, JPG, and PDF are supported. 10MB max.
/// When using the Entity vendor network, specify the entity to use if. EntityId on an auth token will take precedence over this parameter.
/// </summary>
public string Image { get; init; }
[JsonPropertyName("entityId")]
public string? EntityId { get; init; }
}
Loading

0 comments on commit b00e4a7

Please sign in to comment.