Skip to content

Commit 229fa96

Browse files
committed
README
1 parent fee1f5f commit 229fa96

File tree

2 files changed

+68
-8
lines changed

2 files changed

+68
-8
lines changed

README.md

Lines changed: 65 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,12 @@ I needed a currency conversion API for [my travel website]() but couldn't find a
1616
[`Rackbeat/php-currency-api`](https://github.com/Rackbeat/php-currency-api) package came closest but unfortunately it
1717
was just a stub and not implemented.
1818

19+
## Features 🌈
20+
21+
* Support for [multiple different APIs](#supported-apis-) through the use of drivers
22+
* Consistent return interface, independent of the driver being used
23+
* [Calculations](#conversion-result) can be made based on the returned data
24+
1925
## Supported APIs 🌐
2026

2127
| Service | Identifier |
@@ -31,35 +37,84 @@ _If you want to see more services added, feel free to [open an issue](https://gi
3137
## Prerequisites 📚
3238

3339
* `PHP 7.1` or higher (Tested on: PHP `7.1` ✅, `7.2` ✅ and `7.3` ✅)
34-
* [`composer`](https://getcomposer.org)
35-
* An account with one or more of the API providers above
40+
* The [`composer`](https://getcomposer.org) dependency manager for PHP
41+
* An account with one or more of the [API providers](#supported-apis-) listed above
3642

3743
## Installation 🚀
3844

39-
Just require the package using `composer` and you're good to go!
45+
Simply require the package using `composer` and you're good to go!
4046

4147
```bash
4248
$ composer require otherguy/php-currency-api
4349
```
4450

4551
## Usage 🛠
4652

53+
### Currency Symbol Helper
54+
55+
The [`Otherguy\Currency\Symbol`](src/Symbol.php) class provides constants for each supported currency. This is merely
56+
a helper and does not need to be used. You can simply pass strings like `'USD', 'EUR', ...` to most methods.
57+
58+
```php
59+
// 'USD'
60+
$symbol = Otherguy\Currency\Symbol::USD;
61+
```
62+
63+
Use the `all()` method to retrieve an array of all currency symbols:
64+
65+
```php
66+
// [ 'AED', 'AFN', ... 'ZWL' ]
67+
$symbols = Otherguy\Currency\Symbol::all();
68+
```
69+
70+
The `names()` method returns an associative array with currency names instead:
71+
72+
```php
73+
// [ 'AED' => 'United Arab Emirates Dirham', 'AFN' => 'Afghan Afghani', ... ]
74+
$symbols = Otherguy\Currency\Symbol::names();
75+
```
76+
77+
To get the name of a single currency, use the `name()` method:
78+
79+
```php
80+
// 'United States Dollar'
81+
$symbols = Otherguy\Currency\Symbol::name( Otherguy\Currency\Symbol::USD );
82+
```
83+
4784
### Initialize API Instance
4885

4986
```php
50-
$api = Otherguy\Currency\API::make('fixerio'); // driver identifier from supported drivers.
87+
$currency = Otherguy\Currency\DriverFactory::make('fixerio'); // driver identifier from supported drivers.
88+
```
89+
90+
To get a list of supported drivers, use the `getDrivers()` method:
91+
92+
```php
93+
// [ 'mock', 'fixerio', 'currencylayer', ... ]
94+
$drivers = Otherguy\Currency\DriverFactory::getDrivers()
5195
```
5296

53-
### Set base currency (default = USD)
97+
### Set Base Currency
98+
99+
You can use either `from()` or `source()` to set the base currency. The methods are identical.
100+
101+
>**Note:** Each driver sets its own default base currency. [FixerIO](https://fixer.io) uses `EUR` as base currency
102+
> while [CurrencyLayer](https://currencylayer.com) uses `USD`.
103+
104+
Most services only allow you to change the base currency in their paid plans. The driver will throw a
105+
`Otherguy\Currency\Exceptions\ApiException` if your current plan does not allow changing the base currency.
54106

55107
```php
56-
$api->setBase(Otherguy\Currency\Symbol::USD);
108+
$currency->source(Otherguy\Currency\Symbol::USD);
109+
$currency->from(Otherguy\Currency\Symbol::USD);
57110
```
58111

59-
### Set symbols to return (default = all/[])
112+
### Set Return Currencies
113+
114+
You can use either `to()` or `symbols()` to set the return currencies. The methods are identical.
60115

61116
```php
62-
$api->setSymbols([ Otherguy\Currency\Symbol::DKK, Otherguy\Currency\Symbol::EUR, Otherguy\Currency\Symbol::USD ]);
117+
$api->to([ Otherguy\Currency\Symbol::BTC, Otherguy\Currency\Symbol::EUR, Otherguy\Currency\Symbol::USD ]);
63118
```
64119

65120
*Please note, you are not required to use `Otherguy\Currency\Symbol` to specify symbols. It's simply a convenience helper.*
@@ -84,6 +139,8 @@ $api->historical($date = '2018-01-01'); // Get currency rate for base on 1st of
84139
$api->historical($date = '2018-01-01', 'GBP'); // Get currency rate for GBP on 1st of January 2018
85140
```
86141

142+
### Conversion Result
143+
87144
## Contributing 🚧
88145

89146
[Pull Requests](https://github.com/otherguy/php-currency-api/pulls) are more than welcome! I'm striving for 100% test

tests/Helpers/DateHelperTest.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,9 @@
33
use Otherguy\Currency\Helpers\DateHelper;
44
use PHPUnit\Framework\TestCase;
55

6+
/**
7+
* DateHelperTest
8+
*/
69
class DateHelperTest extends TestCase
710
{
811

0 commit comments

Comments
 (0)