-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathFacturapiClient.cs
More file actions
57 lines (52 loc) · 2.44 KB
/
FacturapiClient.cs
File metadata and controls
57 lines (52 loc) · 2.44 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
using Facturapi.Wrappers;
using System;
using System.Net.Http;
using System.Net.Http.Headers;
using System.Text;
namespace Facturapi
{
public sealed class FacturapiClient : IFacturapiClient
{
public CustomerWrapper Customer { get; private set; }
public ProductWrapper Product { get; private set; }
public InvoiceWrapper Invoice { get; private set; }
public OrganizationWrapper Organization { get; private set; }
public ReceiptWrapper Receipt { get; private set; }
public RetentionWrapper Retention { get; private set; }
public CatalogWrapper Catalog { get; private set; }
public CartaporteCatalogWrapper CartaporteCatalog { get; private set; }
public ToolWrapper Tool { get; private set; }
public WebhookWrapper Webhook { get; private set; }
private readonly HttpClient httpClient;
private bool disposed;
public FacturapiClient(string apiKey, string apiVersion = "v2")
{
var apiKeyBase64 = Convert.ToBase64String(Encoding.UTF8.GetBytes(apiKey + ":"));
this.httpClient = new HttpClient
{
BaseAddress = new Uri($"https://www.facturapi.io/{apiVersion}/")
};
this.httpClient.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Basic", apiKeyBase64);
this.Customer = new CustomerWrapper(apiKey, apiVersion, this.httpClient);
this.Product = new ProductWrapper(apiKey, apiVersion, this.httpClient);
this.Invoice = new InvoiceWrapper(apiKey, apiVersion, this.httpClient);
this.Organization = new OrganizationWrapper(apiKey, apiVersion, this.httpClient);
this.Receipt = new ReceiptWrapper(apiKey, apiVersion, this.httpClient);
this.Retention = new RetentionWrapper(apiKey, apiVersion, this.httpClient);
this.Catalog = new CatalogWrapper(apiKey, apiVersion, this.httpClient);
this.CartaporteCatalog = new CartaporteCatalogWrapper(apiKey, apiVersion, this.httpClient);
this.Tool = new ToolWrapper(apiKey, apiVersion, this.httpClient);
this.Webhook = new WebhookWrapper(apiKey, apiVersion, this.httpClient);
}
public void Dispose()
{
if (this.disposed)
{
return;
}
this.httpClient?.Dispose();
this.disposed = true;
GC.SuppressFinalize(this);
}
}
}