定制 ranium/fixerio-php-client 二次开发

按需修改功能、优化性能、对接业务系统,提供一站式技术支持

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

ranium/fixerio-php-client

最新稳定版本:v1.2.0

Composer 安装命令:

composer require ranium/fixerio-php-client

包简介

A PHP client for fixer.io foreign exchange rates and currency conversion API.

README 文档

README

Build Status Total Downloads Latest Stable Version License

Fixer.io PHP Client

Provides an easy to use client for fixer.io exchange rates and currency conversion JSON API.

Looking for a Laravel package? Please use ranium/laravel-fixerio instead of this library.

Installation

This project can be installed using Composer:

composer require ranium/fixerio-php-client

Usage

This package uses's Guzzle's Service Description to make HTTP Requests to the fixer.io API.

To use this package in your application, simply use the package and instantiate the client as follows

use Ranium\Fixerio\Client;

$accessKey = '12345678901234567890';
$secure = true; // Optional, default is true (only paid plans of fixer.io supports SSL)
$config = []; // Optional, guzzle command client config that you might want to pass

$fixerio = Client::create($accessKey, $secure, $config);

Here's how you can access the fixer.io's endpoints:

Note: access_key parameter is sent by default in all requests so no need to pass it in the argument while calling methods. However, you can include it should you want to override the access key used while instantiating the fixerio client.

Latest rates endpoint

$latestRates = $fixerio->latest(
    [
        'base' => 'USD', // optional
        'symbols' => 'INR', // optional
    ]
);

// Display the INR rates
echo $latestRates['rates']['INR'];

Historical rates endpoint

$historicalRates = $fixerio->historical(
    [
        'date' => '2019-01-01',
        'base' => 'USD', // optional
        'symbols' => 'INR', //optional
    ]
);

// Display the INR rates
echo $latestRates['rates']['INR'];

Convert endpoint

$convertedRates = $fixerio->convert(
    [
        'from' => 'USD',
        'to' => 'INR',
        'amount' => 50.75,
        'date' => '2019-01-01', //optional
    ]
);

// Display the converted amount
echo $convertedRates['result'];

Time-Series data endpoint

$timeseriesData = $fixerio->timeseries(
    [
        'start_date' => '2019-01-01',
        'end_date' => '2019-01-05',
        'base' => 'USD', // optional
        'symbols' => 'INR', //optional
    ]
);

// Display the INR rate for 2019-01-02
echo $timeseriesData['rates']['2019-01-02']['INR'];

Fluctuation data endpoint

$fluctuationData = $fixerio->fluctuation(
    [
        'start_date' => '2019-01-01',
        'end_date' => '2019-01-05',
        'base' => 'USD', // optional
        'symbols' => 'INR', //optional
    ]
);

// Display the change/fluctuation amount of INR between the given date range
echo $fluctuationData['rates']['INR']['change'];

The response for all the above calls will be a JSON object. Please refer fixer.io's documentation for further details about various endpoints, request parameters and response objects.

License

This package is open-sourced software licensed under the MIT license.

统计信息

  • 总下载量: 42.65k
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 3
  • 点击次数: 1
  • 依赖项目数: 1
  • 推荐数: 0

GitHub 信息

  • Stars: 3
  • Watchers: 0
  • Forks: 3
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2019-02-05