Skip to content

Commit

Permalink
Update documentation
Browse files Browse the repository at this point in the history
  • Loading branch information
filipsedivy committed Jan 26, 2020
1 parent 3277da6 commit 07f66a0
Showing 1 changed file with 19 additions and 34 deletions.
53 changes: 19 additions & 34 deletions .docs/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,35 +5,16 @@ Usage

### Create instance of class

If you leave the first parameter blank, the cache will be disabled.

```php
$cnb = new CnbApi\CnbApi(string $tempDirectory = null);
```


If you want to turn on caching results, use the first parameter to set the folder to temp folder.

```php
$cnb = new CnbApi\CnbApi(__DIR__ . '/temp');
```

To use the cache, you must have the [nette/caching](https://packagist.org/packages/nette/caching) package installed, which is not part of the mandatory packages.

**The folder must exist, otherwise the application will end with an exception.**

If you do not want to cach the result, you do not need to specify the first parameter.

```php
$cnb = new CnbApi\CnbApi();
$client = new CnbApi\Client(?CnbApi\Caching\ICaching $caching = null, ?CnbApi\Source\ISource $source = null);
```

### Exchange rate list selection

To select the entire exchange rate list, there is a method that returns the complete data from the Czech National Bank.

```php
$cnb->getEntity();
$client->getEntity(?DateTime $date = null);
```

The **first parameter is the date of the exchange rate list** . If the date is not specified, the exchange rate list is selected at the current date.
Expand All @@ -45,41 +26,45 @@ The method returns an object `CnbApi\Entity\ExchangeRate`
Select by exchange rate code

```php
$cnb->findRateByCode('EUR');
$client->findRateByCode('EUR');
```

Select by country name

```php
$cnb->findRateByCountry('Mexiko');
$client->findRateByCountry('Mexiko');
```

These selections always return the object `CnbApi\Entity\Rate`

If you specify the DateTime object as the second parameter, the date will be listed with the date set. Time is ignored.

```php
$cnb->findRateByCode('EUR', new \DateTime('2019-01-01'));
$client->findRateByCode('EUR', new \DateTime('2019-01-01'));
```

### Currency conversion between Czech crown
### Helper classes

Ancillary methods are available that allow the transfer between the Czech crown and the country's target name or the country's destination code.
In class `CnbApi\Helpers\Currency` are maintained most widely used currency.

```php
$cnb->convertFromCzk('EUR', 5.0);
$client->findRateByCode(\CnbApi\Helpers\Currency::EURO);
```

```php
$cnb->convertToCzk('EUR', 5.0);
```
### Advanced conversion

Methods return object `CnbApi\Entity\Rate`
If you need to convert from one currency to another, it is possible to use the Client :: rate (...) method, which allows conversion between multiple currencies.

### Helper classes
The entire conversion process is shown in this diagram.

In class `CnbApi\Helpers\Currency` are maintained most widely used currency.
```
+----------------------------------+ +---------------------+ +---------------------+
| Client::rate(from: EUR, to: USD) +---> Convert EUR to CZK +---> Convert CZK to USD |
+----------------------------------+ +---------------------+ +---------------------+
```

Convert 5 EUR to USD:

```php
$cnb->findRateByCode(\CnbApi\Helpers\Currency::EURO)
$client->rate('EUR', 'USD', 5);
```

0 comments on commit 07f66a0

Please sign in to comment.