OpenUrzednik.Nbp 1.0.35-preview.g216ea16a82

This is a prerelease version of OpenUrzednik.Nbp.
dotnet add package OpenUrzednik.Nbp --version 1.0.35-preview.g216ea16a82
                    
NuGet\Install-Package OpenUrzednik.Nbp -Version 1.0.35-preview.g216ea16a82
                    
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="OpenUrzednik.Nbp" Version="1.0.35-preview.g216ea16a82" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="OpenUrzednik.Nbp" Version="1.0.35-preview.g216ea16a82" />
                    
Directory.Packages.props
<PackageReference Include="OpenUrzednik.Nbp" />
                    
Project file
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add OpenUrzednik.Nbp --version 1.0.35-preview.g216ea16a82
                    
#r "nuget: OpenUrzednik.Nbp, 1.0.35-preview.g216ea16a82"
                    
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
#:package OpenUrzednik.Nbp@1.0.35-preview.g216ea16a82
                    
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=OpenUrzednik.Nbp&version=1.0.35-preview.g216ea16a82&prerelease
                    
Install as a Cake Addin
#tool nuget:?package=OpenUrzednik.Nbp&version=1.0.35-preview.g216ea16a82&prerelease
                    
Install as a Cake Tool

OpenUrzednik.Nbp

🇬🇧 English version

Klient NBP (Narodowy Bank Polski) dla OpenUrzednik.NET — kursy walut oraz ceny złota z API Narodowego Banku Polskiego.

Część zestawu OpenUrzednik.NET — zobacz główne README po pełny przegląd projektu.

Status

🧪 Wersja preview — dostępne są klienty kursów walut (NbpCurrencyExchangeRateClient), tabel kursów (NbpExchangeRateTableClient) i cen złota (NbpGoldPriceClient). Publiczne API może się jeszcze zmienić przed wydaniem stabilnym.

Instalacja

dotnet add package OpenUrzednik.Nbp

Wymaga OpenUrzednik.Core i OpenUrzednik.Http (instalowane automatycznie jako zależności).

Użycie

Najprostszy wariant: domyślny adres API NBP i limit czasu z HttpClient.

using var httpClient = new HttpClient();
var client = new NbpGoldPriceClient(httpClient);

var result = await client.GetLatestAsync();
if (result.IsSuccess)
    Console.WriteLine($"{result.Value.Date}: {result.Value.Price} zł");
else
    Console.WriteLine(result.Errors[0].Message);

Własny adres (np. proxy albo bramki API) i limit czasu przekazujesz w NbpOptions. Klient nie zmienia HttpClient, więc możesz go współdzielić z innym kodem:

var client = new NbpCurrencyExchangeRateClient(httpClient, new NbpOptions
{
    ApiUrl = "https://proxy.example.com/nbp/",
    Timeout = TimeSpan.FromSeconds(5),
});

Z kontenerem DI użyj pakietu OpenUrzednik.Nbp.DependencyInjection: builder.Services.AddOpenUrzednikNbp() rejestruje wszystkie trzy klienty, a .AddStandardResilienceHandler() dodaje ponowienia.

Klient bierze adres API z pierwszego ustawionego miejsca: NbpOptions.ApiUrl, HttpClient.BaseAddress, a na końcu domyślny https://api.nbp.pl/api/. Jeśli nie ustawisz NbpOptions.Timeout, obowiązuje limit czasu HttpClient (domyślnie 100 s). NbpOptions.Timeout może ten limit skrócić, ale nie wydłużyć, bo HttpClient.Timeout nadal obowiązuje do otrzymania nagłówków odpowiedzi. Adres API nie może zawierać zapytania (?…) ani fragmentu (#…).

Błędy, takie jak brak danych, przekroczony limit zapytań albo upływ limitu czasu, wracają w wyniku, a nie jako wyjątki. Jeśli wolisz wyjątki, wywołaj na wyniku EnsureSuccess().

.NET Framework

Pakiet działa też na .NET Framework (przez netstandard2.0). Tam daty są typu DateTime, a nie DateOnly: metody przyjmują DateTime i zwracają go w modelach (np. GoldPrice.Date). Liczy się tylko data: godzinę klient pomija, a zwracane daty mają godzinę 00:00 i DateTimeKind.Unspecified.

Jeśli piszesz bibliotekę, która korzysta z tego pakietu, kompiluj ją na te same platformy (np. netstandard2.0;net8.0). Biblioteka tylko dla netstandard2.0 wywołuje metody z DateTime, a w aplikacji .NET 8+ NuGet wybierze wersję z DateOnly, więc dostaniesz MissingMethodException.

Logowanie i śledzenie

Klienty przyjmują opcjonalne parametry logger i traceSource. Bez nich nic nie logują i nie tworzą spanów. Żeby korzystać z ILogger i OpenTelemetry, zainstaluj adaptery OpenUrzednik.Extensions.Logging i OpenUrzednik.Diagnostics:

using OpenUrzednik.Diagnostics;
using OpenUrzednik.Extensions.Logging;
using OpenUrzednik.Nbp;
using OpenUrzednik.Nbp.Gold;

var client = new NbpGoldPriceClient(httpClient,
    logger: loggerFactory.CreateOpenUrzednikLogger<NbpGoldPriceClient>(),
    traceSource: ActivityTraceSource.GetShared(NbpTelemetry.SourceName));

Spany trafiają do źródła OpenUrzednik.Nbp, a logi do kategorii z pełną nazwą klienta (np. OpenUrzednik.Nbp.Gold.NbpGoldPriceClient).

Klienty używają własnych interfejsów (IOpenUrzednikLogger, IOpenUrzednikTraceSource z OpenUrzednik.Core), a nie ILogger i ActivitySource. Dzięki temu ten pakiet nie potrzebuje Microsoft.Extensions.Logging.Abstractions ani innych pakietów do logowania i śledzenia. Z ILogger i ActivitySource łączą go dopiero adaptery.

Product Compatible and additional computed target framework versions.
.NET net5.0 was computed.  net5.0-windows was computed.  net6.0 was computed.  net6.0-android was computed.  net6.0-ios was computed.  net6.0-maccatalyst was computed.  net6.0-macos was computed.  net6.0-tvos was computed.  net6.0-windows was computed.  net7.0 was computed.  net7.0-android was computed.  net7.0-ios was computed.  net7.0-maccatalyst was computed.  net7.0-macos was computed.  net7.0-tvos was computed.  net7.0-windows was computed.  net8.0 is compatible.  net8.0-android was computed.  net8.0-browser was computed.  net8.0-ios was computed.  net8.0-maccatalyst was computed.  net8.0-macos was computed.  net8.0-tvos was computed.  net8.0-windows was computed.  net9.0 is compatible.  net9.0-android was computed.  net9.0-browser was computed.  net9.0-ios was computed.  net9.0-maccatalyst was computed.  net9.0-macos was computed.  net9.0-tvos was computed.  net9.0-windows was computed.  net10.0 is compatible.  net10.0-android was computed.  net10.0-browser was computed.  net10.0-ios was computed.  net10.0-maccatalyst was computed.  net10.0-macos was computed.  net10.0-tvos was computed.  net10.0-windows was computed. 
.NET Core netcoreapp2.0 was computed.  netcoreapp2.1 was computed.  netcoreapp2.2 was computed.  netcoreapp3.0 was computed.  netcoreapp3.1 was computed. 
.NET Standard netstandard2.0 is compatible.  netstandard2.1 was computed. 
.NET Framework net461 was computed.  net462 was computed.  net463 was computed.  net47 was computed.  net471 was computed.  net472 was computed.  net48 was computed.  net481 was computed. 
MonoAndroid monoandroid was computed. 
MonoMac monomac was computed. 
MonoTouch monotouch was computed. 
Tizen tizen40 was computed.  tizen60 was computed. 
Xamarin.iOS xamarinios was computed. 
Xamarin.Mac xamarinmac was computed. 
Xamarin.TVOS xamarintvos was computed. 
Xamarin.WatchOS xamarinwatchos was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages (1)

Showing the top 1 NuGet packages that depend on OpenUrzednik.Nbp:

Package Downloads
OpenUrzednik.Nbp.DependencyInjection

Microsoft.Extensions.DependencyInjection registration for the OpenUrzednik.NET NBP clients: typed HttpClients, validated options, logging and tracing, ready for AddStandardResilienceHandler().

GitHub repositories

This package is not used by any popular GitHub repositories.