centrex / laravel-open-exchange-rates
This is my package laravel-open-exchange-rates
v1.1.0
2024-09-19 13:00 UTC
Requires
- php: ^8.1|^8.2
- illuminate/database: ^10.0|^11.0
- illuminate/support: ^10.0|^11.0
Requires (Dev)
- larastan/larastan: ^2.0
- laravel/pint: ^1.0
- nunomaduro/collision: ^7.8
- orchestra/testbench: ^8.8
- pestphp/pest: ^2.30
- pestphp/pest-plugin-arch: ^2.0
- pestphp/pest-plugin-laravel: ^2.0
- phpstan/extension-installer: ^1.1
- phpstan/phpstan-deprecation-rules: ^1.0
- phpstan/phpstan-phpunit: ^1.0
- rector/rector: ^1.1
- spatie/laravel-ray: ^1.26
README
This package provides a simple and convenient interface for working with the Open Exchange Rates service. Currently supports free endpoints.
Contents
Installation
You can install the package via composer:
composer require centrex/laravel-open-exchange-rates
You can publish the config file with:
php artisan vendor:publish --tag="laravel-open-exchange-rates-config"
This is the contents of the published config file:
return [ 'app_id' => 'your_own_appid', 'default_base_currency' => 'USD' ];
Usage
In config/loer.php
return [ 'app_id' => '*****************************', // your own api key 'default_base_currency' => 'USD' ];
In controller (or service) method:
use Centrex\LaravelOpenExchangeRates\Client; class SomeController extends Controller { private $client; public function __construct(Client $client) { $this->client = $client; } public function someAction() { $coefficient = $this->client->latest('USD,RUB,AWG'); $historical_coefficent $this->client->historical('2011-03-05', 'USD,RUB,AWG'); // e.t.c... // Change in base currencies (not allowed for free account) and requests for the coefficients of all currencies relative to. $coefficient = $this->client->currency('RUB')->latest(); } }
Testing
๐งน Keep a modern codebase with Pint:
composer lint
โ Run refactors using Rector
composer refacto
โ๏ธ Run static analysis using PHPStan:
composer test:types
โ Run unit tests using PEST
composer test:unit
๐ Run the entire test suite:
composer test
Changelog
Please see CHANGELOG for more information on what has changed recently.
Contributing
Please see CONTRIBUTING for details.
Credits
License
The MIT License (MIT). Please see License File for more information.