Code Monkey home page Code Monkey logo

nbpfetch's Introduction

NBPFetch Build Status

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:

composer require adamale/nbpfetch

b) without Composer:
include Composer File Loader in your project to autoload all the necessary classes.

Usage

Currency rate

<?php

use NBPFetch\NBPFetch;

require_once "vendor/autoload.php";

$NBPFetch = new NBPFetch();
$NBPFetchCurrencyRate = $NBPFetch->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

use NBPFetch\NBPFetch;

require_once "vendor/autoload.php";

$NBPFetch = new NBPFetch();
$NBPFetchExchangeRateTable = $NBPFetch->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

use NBPFetch\NBPFetch;

require_once "vendor/autoload.php";

$NBPFetch = new NBPFetch();
$NBPFetchGoldPrice = $NBPFetch->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 [email protected]

License

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

nbpfetch's People

Contributors

adamale avatar

Stargazers

 avatar  avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.