ksaveras / lb-fx-rates
LB Fx Rates client
v0.1.0
2024-09-14 13:36 UTC
Requires
- php: ^8.2
- ext-simplexml: *
- psr/http-client: ^1.0
- psr/http-factory: ^1.1
Requires (Dev)
- friendsofphp/php-cs-fixer: ^3.64
- nyholm/psr7: ^1.8
- phpstan/phpstan: ^1.12
- phpstan/phpstan-phpunit: ^1.4
- phpunit/phpunit: ^11.3
- rector/rector: ^1.2
- symfony/http-client: ^7.1
Suggests
- symfony/http-client: Allows using Symfony HttpClient for requests
This package is auto-updated.
Last update: 2024-12-21 07:00:02 UTC
README
More information: https://www.lb.lt/webservices/fxrates/
Installation
composer require ksaveras/lb-fx-rates
Use cases
Basic example
Fetch FX rates from LB API. Using Symfony HttpClient to fetch data.
use Ksaveras\LBFxRates\PsrClient; use Symfony\Component\HttpClient\Psr18Client; // Psr18Client implements all three required interfaces $psr18Client = new Psr18Client(); $fxRatesClient = new PsrClient( $psr18Client, $psr18Client, $psr18Client, ); $fxRates = $fxRatesClient->currentFxRates(); foreach ($fxRates as $fxRate) { echo sprintf( "%s: %.4f %s == %.4f %s\n", $fxRate->date()->format('Y-m-d'), $fxRate->currencyAmount()->amount(), $fxRate->currencyAmount()->currency()->value, $fxRate->targetCurrencyAmount()->amount(), $fxRate->targetCurrencyAmount()->currency()->value, ); }
This will output something like:
2024-08-31: 1.0000 EUR == 1.6542 AUD
2024-08-31: 1.0000 EUR == 1.9558 BGN
2024-08-31: 1.0000 EUR == 6.2147 BRL
2024-08-31: 1.0000 EUR == 1.5061 CAD
2024-08-31: 1.0000 EUR == 0.9387 CHF
2024-08-31: 1.0000 EUR == 7.8634 CNY
2024-08-31: 1.0000 EUR == 25.1470 CZK
Tests
composer test
Code Quality
composer static-analysis