Skip to content

Commit b8e2b32

Browse files
committed
separate CartaporteCatalogWrapper from CatalogWrapper
1 parent 8761762 commit b8e2b32

File tree

5 files changed

+81
-54
lines changed

5 files changed

+81
-54
lines changed

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,13 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
1111

1212
- Wrappers can no longer be constructed directly; their constructors are internal and they are intended to be used only through `FacturapiClient`.
1313
- Renamed existing methods to match documented C# surface: `Organization.List/Create/Update/DeleteSeriesAsync` (were `*SeriesGroupAsync`), `Invoice.UpdateStatusAsync` (was `UpdateStatus`), and `Tools.ValidateTaxIdAsync` (was `ValidateTaxId`).
14+
- Carta Porte catalog methods moved to a dedicated `CartaporteCatalogWrapper`; `CartaporteCatalog` is now of that type, and `CatalogWrapper` retains only product/unit catalogs.
1415

1516
### Added
1617

1718
- Expose webhook methods through `FacturapiClient`/`IFacturapiClient`.
1819
- New organization endpoints: `MeAsync` (`/organizations/me`), `CheckDomainIsAvailableAsync`, `UpdateReceiptSettingsAsync`, and `UpdateDomainAsync`.
20+
- New `CartaporteCatalogWrapper` for Carta Porte catalog searches.
1921
- Added `DomainAvailability` model for domain check responses.
2022
- Added `Tool.HealthCheckAsync` for `/check`.
2123
- `FacturapiException.Status` now surfaces the HTTP status code when available.

FacturapiClient.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ public class FacturapiClient : IFacturapiClient
1515
public ReceiptWrapper Receipt { get; private set; }
1616
public RetentionWrapper Retention { get; private set; }
1717
public CatalogWrapper Catalog { get; private set; }
18-
public CatalogWrapper CartaporteCatalog { get; private set; }
18+
public CartaporteCatalogWrapper CartaporteCatalog { get; private set; }
1919
public ToolWrapper Tool { get; private set; }
2020
public WebhookWrapper Webhook { get; private set; }
2121
private readonly HttpClient httpClient;
@@ -36,7 +36,7 @@ public FacturapiClient(string apiKey, string apiVersion = "v2")
3636
this.Receipt = new ReceiptWrapper(apiKey, apiVersion, this.httpClient);
3737
this.Retention = new RetentionWrapper(apiKey, apiVersion, this.httpClient);
3838
this.Catalog = new CatalogWrapper(apiKey, apiVersion, this.httpClient);
39-
this.CartaporteCatalog = new CatalogWrapper(apiKey, apiVersion, this.httpClient);
39+
this.CartaporteCatalog = new CartaporteCatalogWrapper(apiKey, apiVersion, this.httpClient);
4040
this.Tool = new ToolWrapper(apiKey, apiVersion, this.httpClient);
4141
this.Webhook = new WebhookWrapper(apiKey, apiVersion, this.httpClient);
4242
}

IFacturapiClient.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ public interface IFacturapiClient : IDisposable
1212
ReceiptWrapper Receipt { get; }
1313
RetentionWrapper Retention { get; }
1414
CatalogWrapper Catalog { get; }
15-
CatalogWrapper CartaporteCatalog { get; }
15+
CartaporteCatalogWrapper CartaporteCatalog { get; }
1616
ToolWrapper Tool { get; }
1717
WebhookWrapper Webhook { get; }
1818
}
Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
using Newtonsoft.Json;
2+
using System.Collections.Generic;
3+
using System.Net.Http;
4+
using System.Threading.Tasks;
5+
using System.Threading;
6+
7+
namespace Facturapi.Wrappers
8+
{
9+
public class CartaporteCatalogWrapper : BaseWrapper
10+
{
11+
internal CartaporteCatalogWrapper(string apiKey, string apiVersion, HttpClient httpClient) : base(apiKey, apiVersion, httpClient)
12+
{
13+
}
14+
15+
public async Task<SearchResult<CatalogItem>> SearchAirTransportCodes(Dictionary<string, object> query = null, CancellationToken cancellationToken = default)
16+
{
17+
return await this.SearchCatalogAsync(Router.SearchCartaporteAirTransportCodes(query), cancellationToken);
18+
}
19+
20+
public async Task<SearchResult<CatalogItem>> SearchTransportConfigs(Dictionary<string, object> query = null, CancellationToken cancellationToken = default)
21+
{
22+
return await this.SearchCatalogAsync(Router.SearchCartaporteTransportConfigs(query), cancellationToken);
23+
}
24+
25+
public async Task<SearchResult<CatalogItem>> SearchRightsOfPassage(Dictionary<string, object> query = null, CancellationToken cancellationToken = default)
26+
{
27+
return await this.SearchCatalogAsync(Router.SearchCartaporteRightsOfPassage(query), cancellationToken);
28+
}
29+
30+
public async Task<SearchResult<CatalogItem>> SearchCustomsDocuments(Dictionary<string, object> query = null, CancellationToken cancellationToken = default)
31+
{
32+
return await this.SearchCatalogAsync(Router.SearchCartaporteCustomsDocuments(query), cancellationToken);
33+
}
34+
35+
public async Task<SearchResult<CatalogItem>> SearchPackagingTypes(Dictionary<string, object> query = null, CancellationToken cancellationToken = default)
36+
{
37+
return await this.SearchCatalogAsync(Router.SearchCartaportePackagingTypes(query), cancellationToken);
38+
}
39+
40+
public async Task<SearchResult<CatalogItem>> SearchTrailerTypes(Dictionary<string, object> query = null, CancellationToken cancellationToken = default)
41+
{
42+
return await this.SearchCatalogAsync(Router.SearchCartaporteTrailerTypes(query), cancellationToken);
43+
}
44+
45+
public async Task<SearchResult<CatalogItem>> SearchHazardousMaterials(Dictionary<string, object> query = null, CancellationToken cancellationToken = default)
46+
{
47+
return await this.SearchCatalogAsync(Router.SearchCartaporteHazardousMaterials(query), cancellationToken);
48+
}
49+
50+
public async Task<SearchResult<CatalogItem>> SearchNavalAuthorizations(Dictionary<string, object> query = null, CancellationToken cancellationToken = default)
51+
{
52+
return await this.SearchCatalogAsync(Router.SearchCartaporteNavalAuthorizations(query), cancellationToken);
53+
}
54+
55+
public async Task<SearchResult<CatalogItem>> SearchPortStations(Dictionary<string, object> query = null, CancellationToken cancellationToken = default)
56+
{
57+
return await this.SearchCatalogAsync(Router.SearchCartaportePortStations(query), cancellationToken);
58+
}
59+
60+
public async Task<SearchResult<CatalogItem>> SearchMarineContainers(Dictionary<string, object> query = null, CancellationToken cancellationToken = default)
61+
{
62+
return await this.SearchCatalogAsync(Router.SearchCartaporteMarineContainers(query), cancellationToken);
63+
}
64+
65+
private async Task<SearchResult<CatalogItem>> SearchCatalogAsync(string url, CancellationToken cancellationToken)
66+
{
67+
using (var response = await client.GetAsync(url, cancellationToken))
68+
{
69+
await this.ThrowIfErrorAsync(response, cancellationToken);
70+
var resultString = await response.Content.ReadAsStringAsync();
71+
var searchResult = JsonConvert.DeserializeObject<SearchResult<CatalogItem>>(resultString, this.jsonSettings);
72+
return searchResult;
73+
}
74+
}
75+
}
76+
}

Wrappers/CatalogWrapper.cs

Lines changed: 0 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -22,57 +22,6 @@ public async Task<SearchResult<CatalogItem>> SearchUnits(Dictionary<string, obje
2222
return await this.SearchCatalogAsync(Router.SearchUnitKeys(query), cancellationToken);
2323
}
2424

25-
// Carta Porte catalogs
26-
public async Task<SearchResult<CatalogItem>> SearchAirTransportCodes(Dictionary<string, object> query = null, CancellationToken cancellationToken = default)
27-
{
28-
return await this.SearchCatalogAsync(Router.SearchCartaporteAirTransportCodes(query), cancellationToken);
29-
}
30-
31-
public async Task<SearchResult<CatalogItem>> SearchTransportConfigs(Dictionary<string, object> query = null, CancellationToken cancellationToken = default)
32-
{
33-
return await this.SearchCatalogAsync(Router.SearchCartaporteTransportConfigs(query), cancellationToken);
34-
}
35-
36-
public async Task<SearchResult<CatalogItem>> SearchRightsOfPassage(Dictionary<string, object> query = null, CancellationToken cancellationToken = default)
37-
{
38-
return await this.SearchCatalogAsync(Router.SearchCartaporteRightsOfPassage(query), cancellationToken);
39-
}
40-
41-
public async Task<SearchResult<CatalogItem>> SearchCustomsDocuments(Dictionary<string, object> query = null, CancellationToken cancellationToken = default)
42-
{
43-
return await this.SearchCatalogAsync(Router.SearchCartaporteCustomsDocuments(query), cancellationToken);
44-
}
45-
46-
public async Task<SearchResult<CatalogItem>> SearchPackagingTypes(Dictionary<string, object> query = null, CancellationToken cancellationToken = default)
47-
{
48-
return await this.SearchCatalogAsync(Router.SearchCartaportePackagingTypes(query), cancellationToken);
49-
}
50-
51-
public async Task<SearchResult<CatalogItem>> SearchTrailerTypes(Dictionary<string, object> query = null, CancellationToken cancellationToken = default)
52-
{
53-
return await this.SearchCatalogAsync(Router.SearchCartaporteTrailerTypes(query), cancellationToken);
54-
}
55-
56-
public async Task<SearchResult<CatalogItem>> SearchHazardousMaterials(Dictionary<string, object> query = null, CancellationToken cancellationToken = default)
57-
{
58-
return await this.SearchCatalogAsync(Router.SearchCartaporteHazardousMaterials(query), cancellationToken);
59-
}
60-
61-
public async Task<SearchResult<CatalogItem>> SearchNavalAuthorizations(Dictionary<string, object> query = null, CancellationToken cancellationToken = default)
62-
{
63-
return await this.SearchCatalogAsync(Router.SearchCartaporteNavalAuthorizations(query), cancellationToken);
64-
}
65-
66-
public async Task<SearchResult<CatalogItem>> SearchPortStations(Dictionary<string, object> query = null, CancellationToken cancellationToken = default)
67-
{
68-
return await this.SearchCatalogAsync(Router.SearchCartaportePortStations(query), cancellationToken);
69-
}
70-
71-
public async Task<SearchResult<CatalogItem>> SearchMarineContainers(Dictionary<string, object> query = null, CancellationToken cancellationToken = default)
72-
{
73-
return await this.SearchCatalogAsync(Router.SearchCartaporteMarineContainers(query), cancellationToken);
74-
}
75-
7625
private async Task<SearchResult<CatalogItem>> SearchCatalogAsync(string url, CancellationToken cancellationToken)
7726
{
7827
using (var response = await client.GetAsync(url, cancellationToken))

0 commit comments

Comments
 (0)