PHP Classes

PHP NBG Currency: Get currency values from National Bank of Georgia

Recommend this page to a friend!
  Info   Documentation   View files Files   Install with Composer Install with Composer   Download Download   Reputation   Support forum   Blog    
Ratings Unique User Downloads Download Rankings
Not yet rated by the usersTotal: 23 All time: 11,249 This week: 524Up
Version License PHP version Categories
nbg-currency 1.0Custom (specified...5PHP 5, Web services, Finances
Description 

Author

This package is specific mainly for applications used in Georgia Georgia .

This class can get currency values from National Bank of Georgia.

It can send HTTP requests to the National Bank of Georgia API server to obtain values about many different currencies.

Currently it can take a given reference currency and obtains values like:

- Exchange value relative to other currency.
- Description text
- Recent change value

Picture of Temuri Takalandze
  Performance   Level  
Name: Temuri Takalandze <contact>
Classes: 6 packages by
Country: Georgia Georgia
Age: 24
All time rank: 35785 in Georgia Georgia
Week rank: 192 Up1 in Georgia Georgia Up
Innovation award
Innovation award
Nominee: 4x

Winner: 1x

Documentation

nbg-currency

PHP Library for getting data from National Bank of Georgia (NBG)'s API.

GitHub license

GitHub release

Packagist Version

Build Status

See documentation generated by phpDocumentor in docs/ folder.

Installation

You can install this library with Composer:

  • `composer require abgeo/nbg-currency`

Usage

Include composer autoloader in your main file (Ex.: index.php)

  • `require_once __DIR__.'/../vendor/autoload.php';`

Import Classes:

  • `use ABGEO\NBG\Currency;`
  • `use ABGEO\NBG\Helper\CurrencyCodes;`

Now you can create new Currency Class object ex. for USD currency:

  • `$USD = new Currency(CurrencyCodes::USD);`

The Currency class constructor takes a single argument - the Currency Code. You can pass it manually (ISO 4217) or using ABGEO\NBG\Helper\CurrencyCodes class constants:

AED, AMD, AUD, AZN, BGN, BYR, CAD, CHF, CNY, CZK, DKK, EEK, EGP, EUR, 
GBP, HKD, HUF, ILS, INR, IRR, ISK, JPY, KGS, KWD, KZT, LTL, LVL, MDL, 
NOK, NZD, PLN, RON, RSD, RUB, SEK, SGD, TJS, TMT, TRY, UAH, USD, UZS.

After creating a class object, we can get currency data. The API gives us:

  • Currency Amount;
  • Currency Description;
  • Currency Change value;
  • Currency Change rate (-1 - decreased; 0 - unchanged; 1 - increased);
  • Currency Date;

Public methods

  • `getCurrency()` - Get Currency Amount;
  • `getDescription()` - Get Currency Description;
  • `getChange()` - Currency Change value;
  • `getRate()` - Get Currency Change rate;
  • `getDate()` - Get Currency Date;

Examples

Example for USD

...
echo "Currency: \t{$USD->getCurrency()}\n";
echo "Description: \t{$USD->getDescription()}\n";
echo "Change: \t{$USD->getChange()}\n";
echo "Change Rate: \t{$USD->getRate()}\n";
echo "Date: \t\t{$USD->getDate()->format('m/d/Y')}\n";
...

Full example with USD and EUR

<?php

// Include Composer Autoloader.
require_once __DIR__.'/../vendor/autoload.php';

// Import namespace.
use ABGEO\NBG\Currency;
use ABGEO\NBG\Helper\CurrencyCodes;

// Create new Currency class object for USD and EUR Currencies.
$USD = new Currency(CurrencyCodes::USD);
$EUR = new Currency(CurrencyCodes::EUR);

// Print results.

echo "USD: \n\n";
echo "Currency: \t{$USD->getCurrency()}\n";
echo "Description: \t{$USD->getDescription()}\n";
echo "Change: \t{$USD->getChange()}\n";
echo "Change Rate: \t{$USD->getRate()}\n";
echo "Date: \t\t{$USD->getDate()->format('m/d/Y')}\n";

echo "\n------------------------------------------\n\n";

echo "EUR: \n\n";
echo "Currency: \t{$EUR->getCurrency()}\n";
echo "Description: \t{$EUR->getDescription()}\n";
echo "Change: \t{$EUR->getChange()}\n";
echo "Change Rate: \t{$EUR->getRate()}\n";
echo "Date: \t\t{$EUR->getDate()->format('m/d/Y')}\n";

Export

You can use ABGEO\NBG\Exporter Class for exporting currency data to CSV file or PHP Stream output. ABGEO\NBG\Exporter class has export() method that takes 3 arguments:

  • currencies - Single Currency Code or array;
  • exportMode [Optional][Default: Exporter::EXPORT_2_FILE] - Exporter::EXPORT_2_FILE(1) - To file; - Exporter::Exporter::EXPORT_2_FILE(2) - To stream;
  • file [Optional][Default: currency-{current-date}.csv] - Filename to export.

Export examples

Export single currency

...
Exporter::export(CurrencyCodes::USD, Exporter::EXPORT_2_FILE, 'single.csv');
...

Export many currencies

...
Exporter::export(
    [
        CurrencyCodes::USD,
        CurrencyCodes::EUR,
        CurrencyCodes::BGN,
        CurrencyCodes::AMD,
    ],
    Exporter::EXPORT_2_STREAM
);
...

NOTE: Don't print anything before exporting to stream coz we use header() function.

Authors

  • Temuri Takalandze - Initial work - ABGEO

License

This project is licensed under the MIT License - see the LICENSE file for details


  Files folder image Files (85)  
File Role Description
Files folder image.github (1 file, 1 directory)
Files folder imagedocs (2 files, 9 directories)
Files folder imageexamples (1 file)
Files folder imagesrc (2 files, 3 directories)
Files folder imagetests (1 file)
Accessible without login Plain text file CHANGELOG.md Data Auxiliary data
Accessible without login Plain text file composer.json Data Auxiliary data
Accessible without login Plain text file composer.lock Data Auxiliary data
Accessible without login Plain text file LICENSE Lic. License text
Accessible without login Plain text file phpunit.xml.dist Data Auxiliary data
Accessible without login Plain text file README.md Doc. Read me

  Files folder image Files (85)  /  .github  
File Role Description
Files folder imageworkflows (1 file)
  Accessible without login Plain text file FUNDING.yml Data Auxiliary data

  Files folder image Files (85)  /  .github  /  workflows  
File Role Description
  Accessible without login Plain text file php.yml Data Auxiliary data

  Files folder image Files (85)  /  docs  
File Role Description
Files folder imageclasses (5 files)
Files folder imagecss (5 files, 1 directory)
Files folder imagefiles (9 files, 3 directories)
Files folder imagefont (1 file)
Files folder imagegraphs (2 files)
Files folder imageimages (12 files, 1 directory)
Files folder imagejs (10 files, 1 directory)
Files folder imagenamespaces (5 files)
Files folder imagereports (3 files)
  Accessible without login Plain text file .htaccess Data Auxiliary data
  Accessible without login HTML file index.html Doc. Documentation

  Files folder image Files (85)  /  docs  /  classes  
File Role Description
  Accessible without login HTML file ABGEO.NBG.Currency.html Doc. Documentation
  Accessible without login HTML file ABGEO.NBG.CurrencyDataTrait.html Doc. Documentation
  Accessible without login HTML file ABGEO.NBG.Exceptio...rencyException.html Doc. Documentation
  Accessible without login HTML file ABGEO.NBG.Exporter.html Doc. Documentation
  Accessible without login HTML file ABGEO.NBG.Model.Currency.html Doc. Documentation

  Files folder image Files (85)  /  docs  /  css  
File Role Description
Files folder imagephpdocumentor-clean-icons (2 files, 1 directory)
  Accessible without login Plain text file bootstrap-combined.no-icons.min.css Data Auxiliary data
  Accessible without login Plain text file font-awesome.min.css Data Auxiliary data
  Accessible without login Plain text file jquery.iviewer.css Data Auxiliary data
  Accessible without login Plain text file prism.css Data Auxiliary data
  Accessible without login Plain text file template.css Data Auxiliary data

  Files folder image Files (85)  /  docs  /  css  /  phpdocumentor-clean-icons  
File Role Description
Files folder imagefonts (2 files)
  Accessible without login Plain text file lte-ie7.js Data Auxiliary data
  Accessible without login Plain text file style.css Data Auxiliary data

  Files folder image Files (85)  /  docs  /  css  /  phpdocumentor-clean-icons  /  fonts  
File Role Description
  Accessible without login Plain text file phpdocumentor-clean-icons.dev.svg Data Auxiliary data
  Accessible without login Plain text file phpdocumentor-clean-icons.svg Data Auxiliary data

  Files folder image Files (85)  /  docs  /  files  
File Role Description
Files folder imageException (1 file)
Files folder imageHelper (1 file)
Files folder imageModel (1 file)
  Accessible without login HTML file Currency.html Doc. Documentation
  Accessible without login Plain text file Currency.php.txt Doc. Documentation
  Accessible without login HTML file CurrencyDataTrait.html Doc. Documentation
  Accessible without login Plain text file CurrencyDataTrait.php.txt Doc. Documentation
  Accessible without login HTML file Exception.InvalidCurrencyException.html Doc. Documentation
  Accessible without login HTML file Exporter.html Doc. Documentation
  Accessible without login Plain text file Exporter.php.txt Doc. Documentation
  Accessible without login HTML file Helper.CurrencyCodes.html Doc. Documentation
  Accessible without login HTML file Model.Currency.html Doc. Documentation

  Files folder image Files (85)  /  docs  /  files  /  Exception  
File Role Description
  Accessible without login Plain text file InvalidCurrencyException.php.txt Doc. Documentation

  Files folder image Files (85)  /  docs  /  files  /  Helper  
File Role Description
  Accessible without login Plain text file CurrencyCodes.php.txt Doc. Documentation

  Files folder image Files (85)  /  docs  /  files  /  Model  
File Role Description
  Accessible without login Plain text file Currency.php.txt Doc. Documentation

  Files folder image Files (85)  /  docs  /  font  
File Role Description
  Accessible without login Plain text file fontawesome-webfont.svg Data Auxiliary data

  Files folder image Files (85)  /  docs  /  graphs  
File Role Description
  Accessible without login HTML file class.html Doc. Documentation
  Accessible without login Plain text file classes.svg Data Auxiliary data

  Files folder image Files (85)  /  docs  /  images  
File Role Description
Files folder imageiviewer (8 files)
  Accessible without login Image file apple-touch-icon-114x114.png Icon Icon image
  Accessible without login Image file apple-touch-icon-72x72.png Icon Icon image
  Accessible without login Image file apple-touch-icon.png Icon Icon image
  Accessible without login Plain text file custom-icons.svg Data Auxiliary data
  Accessible without login Image file favicon.ico Data Auxiliary data
  Accessible without login Image file hierarchy-item.png Icon Icon image
  Accessible without login Image file icon-class-13x13.png Icon Icon image
  Accessible without login Plain text file icon-class.svg Data Auxiliary data
  Accessible without login Image file icon-interface-13x13.png Icon Icon image
  Accessible without login Plain text file icon-interface.svg Data Auxiliary data
  Accessible without login Image file icon-trait-13x13.png Icon Icon image
  Accessible without login Plain text file icon-trait.svg Data Auxiliary data

  Files folder image Files (85)  /  docs  /  images  /  iviewer  
File Role Description
  Accessible without login Image file grab.cur Data Auxiliary data
  Accessible without login Image file hand.cur Data Auxiliary data
  Accessible without login Image file iviewer.rotate_left.png Icon Icon image
  Accessible without login Image file iviewer.rotate_right.png Icon Icon image
  Accessible without login Image file iviewer.zoom_fit.png Icon Icon image
  Accessible without login Image file iviewer.zoom_in.png Icon Icon image
  Accessible without login Image file iviewer.zoom_out.png Icon Icon image
  Accessible without login Image file iviewer.zoom_zero.png Icon Icon image

  Files folder image Files (85)  /  docs  /  js  
File Role Description
Files folder imageui (1 directory)
  Accessible without login Plain text file bootstrap.min.js Data Auxiliary data
  Accessible without login Plain text file html5.js Data Auxiliary data
  Accessible without login Plain text file jquery-1.11.0.min.js Data Auxiliary data
  Accessible without login Plain text file jquery.dotdotdot-1.5.9.js Data Auxiliary data
  Accessible without login Plain text file jquery.dotdotdot-1.5.9.min.js Data Auxiliary data
  Accessible without login Plain text file jquery.iviewer.js Data Auxiliary data
  Accessible without login Plain text file jquery.iviewer.min.js Data Auxiliary data
  Accessible without login Plain text file jquery.mousewheel.js Data Auxiliary data
  Accessible without login Plain text file jquery.smooth-scroll.js Data Auxiliary data
  Accessible without login Plain text file prism.min.js Data Auxiliary data

  Files folder image Files (85)  /  docs  /  js  /  ui  
File Role Description
Files folder image1.10.4 (1 file)

  Files folder image Files (85)  /  docs  /  js  /  ui  /  1.10.4  
File Role Description
  Accessible without login Plain text file jquery-ui.min.js Data Auxiliary data

  Files folder image Files (85)  /  docs  /  namespaces  
File Role Description
  Accessible without login HTML file ABGEO.html Doc. Documentation
  Accessible without login HTML file ABGEO.NBG.Exception.html Doc. Documentation
  Accessible without login HTML file ABGEO.NBG.html Doc. Documentation
  Accessible without login HTML file ABGEO.NBG.Model.html Doc. Documentation
  Accessible without login HTML file default.html Doc. Documentation

  Files folder image Files (85)  /  docs  /  reports  
File Role Description
  Accessible without login HTML file deprecated.html Doc. Documentation
  Accessible without login HTML file errors.html Doc. Documentation
  Accessible without login HTML file markers.html Doc. Documentation

  Files folder image Files (85)  /  examples  
File Role Description
  Accessible without login Plain text file example.php Example Example script

  Files folder image Files (85)  /  src  
File Role Description
Files folder imageException (1 file)
Files folder imageHelper (1 file)
Files folder imageModel (1 file)
  Plain text file Currency.php Class Class source
  Plain text file Exporter.php Class Class source

  Files folder image Files (85)  /  src  /  Exception  
File Role Description
  Plain text file InvalidCurrencyException.php Class Class source

  Files folder image Files (85)  /  src  /  Helper  
File Role Description
  Plain text file CurrencyCodes.php Class Class source

  Files folder image Files (85)  /  src  /  Model  
File Role Description
  Plain text file Currency.php Class Class source

  Files folder image Files (85)  /  tests  
File Role Description
  Plain text file CurrencyTest.php Class Class source

The PHP Classes site has supported package installation using the Composer tool since 2013, as you may verify by reading this instructions page.
Install with Composer Install with Composer
 Version Control Unique User Downloads Download Rankings  
 100%
Total:23
This week:0
All time:11,249
This week:524Up