项目作者: XenonLab

项目描述 :
REST Client
高级语言: PHP
项目地址: git://github.com/XenonLab/xecd-rates-client-php.git
创建时间: 2017-09-14T19:41:59Z
项目社区:https://github.com/XenonLab/xecd-rates-client-php

开源协议:Mozilla Public License 2.0

下载






XE Currency Data Client - PHP

XE.com Inc. is the World’s Trusted Currency Authority. This project provides an SDK to interface with our XE Currency Data (XECD) product.

XE Currency Data is a REST API that gives you access to daily or live rates and historic mid-market conversion rates between all of our supported currencies.

You will need an api key and secret to use this sdk. Sign up for a free trial or register for a full account.

Installation

The preferred way to install this package is through composer.

  1. composer require xe/xecd-rates-client

This package follows semantic versioning.

Usage

  1. <?php
  2. require 'vendor/autoload.php';
  3. use Xe\Xecd\Client\Rates\XecdRatesClientAspectKernel;
  4. use Xe\Xecd\Client\Rates\Exception\XecdRatesException;
  5. use GuzzleHttp\Exception\RequestException;
  6. XecdRatesClientAspectKernel::getInstance()->init([
  7. 'cacheDir' => '/your/cache/directory',
  8. ]);
  9. $xecdRatesClient = XecdRatesClient::create(<YOUR_ACCOUNT_ID>, <YOUR_API_KEY>);
  10. try
  11. {
  12. $conversions = $xecdRatesClient->convertFrom(new Currency('CAD'), Currencies::wildcard(), 12345.67)->getBody();
  13. foreach ($conversions->getConversions() as $currency => $currencyConversions) {
  14. foreach ($currencyConversions as $timestamp => $conversion) {
  15. echo "{$conversion->getFromAmount()} {$conversion->getFromCurrency()} = {$conversion->getToAmount()} {$conversion->getToCurrency()}\n";
  16. }
  17. }
  18. } catch (XecdRatesException $e) {
  19. // API errors with error code.
  20. } catch (Exception $e) {
  21. // ALl other errors, such as connection timeout errors.
  22. }

Documentation

Technical Specifications

Contributing

xecd-rates-client-php is an open-source project. Submit a pull request to contribute!

Testing

  1. cd xecd-rates-client-php
  2. composer install
  3. # Unit tests.
  4. phpunit --testsuite Unit
  5. # Integration tests.
  6. export XECD_RATES_API_ACCOUNT_ID=<YOUR_API_ACCOUNT_ID>
  7. export XECD_RATES_API_KEY=<YOUR_API_KEY>
  8. phpunit --testsuite Integration

Security Issues

If you discover a security vulnerability within this package, please DO NOT publish it publicly. Instead, contact us at security [at] xe.com. We will follow up with you as soon as possible.

About Us

XE.com Inc. is The World’s Trusted Currency Authority. Development of this project is led by the XE.com Inc. Development Team and supported by the open-source community.