centrex/laravel-open-exchange-rates

This is my package laravel-open-exchange-rates

v1.1.0 2024-09-19 13:00 UTC

This package is auto-updated.

Last update: 2024-12-20 14:06:18 UTC


README

Latest Version on Packagist GitHub Tests Action Status GitHub Code Style Action Status Total Downloads

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.