Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/adamale/nbpfetch

PHP library that helps to fetch data from NBP API.
https://github.com/adamale/nbpfetch

api-client composer currency-exchange-rates currency-rates exchange-rates gold-price mit nbp nbp-api php php-7 php-library travis-ci

Last synced: about 1 month ago
JSON representation

PHP library that helps to fetch data from NBP API.

Awesome Lists containing this project

README

        

# NBPFetch [![Build Status](https://travis-ci.org/adamale/NBPFetch.svg?branch=master)](https://travis-ci.org/adamale/NBPFetch)
PHP library that helps to fetch data from NBP API - http://api.nbp.pl/en.html.
It allows you to fetch currency rates, exchange rate tables and gold prices.

## Requirements
PHP 7.2 or above.

## Installation
a) with Composer:
``` bash
composer require adamale/nbpfetch
```
b) without Composer:
include [Composer File Loader](https://github.com/Wilkins/composer-file-loader) in your project to autoload all the necessary classes.

## Usage

### Currency rate
```php
currencyRate();

/**
* Currency rate examples.
* Available methods are: current(string $currency), today(string $currency)
* byDate(string $currency, string $date), byDateRange(string $currency, string $from, string $to)
* and last(string $currency, int count).
*/
try {
$currentCurrencyRate = $NBPFetchCurrencyRate->current("EUR");
$todayCurrencyRate = $NBPFetchCurrencyRate->current("EUR");
$givenDateCurrencyRate = $NBPFetchCurrencyRate->byDate("EUR", "2019-08-28");
$givenDateRangeCurrencyRates = $NBPFetchCurrencyRate->byDateRange("EUR", "2019-08-01", "2019-08-31");
$last10CurrencyRates = $NBPFetchCurrencyRate->last("EUR", 10);
} catch (Exception $e) {
}
```

### Exchange rate table
```php
exchangeRateTable();

/**
* Exchange rate table examples.
* Available methods are: current(string $table), today(string $table),
* byDate(string $table, string $date), byDateRange(string $table, string $from, string $to)
* and last(string $table, int count)
*/
try {
$currentExchangeRateTable = $NBPFetchExchangeRateTable->current("A");
$todayExchangeRateTable = $NBPFetchExchangeRateTable->today("A");
$givenDateExchangeRateTable = $NBPFetchExchangeRateTable->byDate("A", "2019-08-28");
$givenDateRangeExchangeRateTables = $NBPFetchExchangeRateTable->byDateRange("A", "2019-08-01", "2019-08-31");
$last10ExchangeRateTables = $NBPFetchExchangeRateTable->last("A", 10);
} catch (Exception $e) {
}
```

### Gold price
```php
goldPrice();

/**
* Gold price examples.
* Available methods are: current(), today(), byDate(string $date),
* byDateRange(string $from, string $to) and last(int count)
*/
try {
$currentGoldPrice = $NBPFetchGoldPrice->current();
$todayGoldPrice = $NBPFetchGoldPrice->today();
$givenDateGoldPrice = $NBPFetchGoldPrice->byDate("2019-08-28");
$givenDateRangeGoldPrices = $NBPFetchGoldPrice->byDateRange("2019-08-01", "2019-08-31");
$last10GoldPrices = $NBPFetchGoldPrice->last(10);
} catch (Exception $e) {
}
```

## About

### Author
Adam Aleksak

### License
NBPFetch is licensed under the MIT License - see the `LICENSE` file for the details.