centrex/laravel-open-exchange-rates

这是我创建的包:laravel-open-exchange-rates

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

This package is auto-updated.

Last update: 2024-09-19 13:02:05 UTC


README

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

此包提供了一个简单方便的接口,用于与 Open Exchange Rates 服务交互。目前支持免费端点。

内容

安装

您可以通过 composer 安装此包

composer require centrex/laravel-open-exchange-rates

您可以使用以下命令发布配置文件

php artisan vendor:publish --tag="laravel-open-exchange-rates-config"

这是已发布配置文件的内容

return [
    'app_id' => 'your_own_appid',
    'default_base_currency' => 'USD'
];

使用方法

config/loer.php

return [
    'app_id' => '*****************************', // your own api key
    'default_base_currency' => 'USD'
];

在控制器(或服务)方法中

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();
    }
}

测试

使用 Pint 保持现代代码库

composer lint

使用 Rector 运行重构

composer refacto

使用 PHPStan 运行静态分析

composer test:types

使用 PEST 运行单元测试

composer test:unit

运行整个测试套件

composer test

变更日志

有关最近更改的更多信息,请参阅 变更日志

贡献

有关详细信息,请参阅 贡献指南

鸣谢

许可

MIT 许可证(MIT)。有关更多信息,请参阅 许可文件