Skip to content

Raptek/nbp-php

 
 

Repository files navigation

nbp-php

API for accessing NBP (Narodowy Bank Polski) currecy rates in PHP

Latest Version on Packagist Build Status No dependencies MIT License

Usage

Note: currently only average rate is retrieved.

Example: getting the average rate from specific day

$nbp = new NbpRepository();
$currencyData = $nbp->getRate('2015-01-02', 'USD');

var_dump($currencyData->avg);
var_dump($currencyData->date);

Outputs:

double(3.5725)
string(10) "2015-01-02"

Example: getting the average rate from first date before specified date

This is usefull when you need to retrieve last available currency rate from working day before specified date.

$nbp = new NbpRepository();
$currencyData = $nbp->getRateBefore('2015-01-02', 'USD');

var_dump($currencyData->avg);
var_dump($currencyData->date);

Outputs:

double(3.5072)
string(10) "2014-12-31"

Example: using cache

When using cache the amount of HTTP requests to NBP server is minimized.

<?php
use Doctrine\Common\Cache\FilesystemCache;
use MaciejSz\NbpPhp\Service\NbpCache;
use MaciejSz\NbpPhp\NbpRepository;

$cacheBackend = new FilesystemCache(sys_get_temp_dir() . "/nbp-php");
$nbpCache = new NbpCache($cacheBackend);

$nbp = new NbpRepository($nbpCache);
// ...

About

API for accessing NBP (Narodowy Bank Polski) currecy rates in PHP

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages

  • PHP 96.5%
  • Gherkin 3.5%