Skip to content

Commit 6cbb830

Browse files
committedJun 7, 2019
Initial commit
0 parents  commit 6cbb830

21 files changed

+3245
-0
lines changed
 

‎.gitignore

+16
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
### VisualStudioCode template
2+
.vscode/*
3+
!.vscode/settings.json
4+
!.vscode/tasks.json
5+
!.vscode/launch.json
6+
!.vscode/extensions.json
7+
8+
### Composer template
9+
composer.phar
10+
/vendor/
11+
12+
### JetBrains template
13+
.idea/
14+
15+
### PHPUnit
16+
build

‎.travis.yml

+17
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
language: php
2+
3+
php:
4+
- 7.1
5+
- 7.2
6+
- 7.3
7+
8+
install:
9+
- curl -s http://getcomposer.org/installer | php
10+
- php composer.phar install --dev --no-interaction
11+
12+
script:
13+
- mkdir -p build/logs
14+
- vendor/bin/phpunit --coverage-clover build/logs/clover.xml
15+
16+
after_success:
17+
- travis_retry php vendor/bin/php-coveralls

‎LICENSE.md

+25
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
The MIT License (MIT)
2+
=====================
3+
4+
Copyright © `2019` [`@otherguy`](https://github.com/otherguy/)
5+
6+
Permission is hereby granted, free of charge, to any person
7+
obtaining a copy of this software and associated documentation
8+
files (the “Software”), to deal in the Software without
9+
restriction, including without limitation the rights to use,
10+
copy, modify, merge, publish, distribute, sublicense, and/or sell
11+
copies of the Software, and to permit persons to whom the
12+
Software is furnished to do so, subject to the following
13+
conditions:
14+
15+
The above copyright notice and this permission notice shall be
16+
included in all copies or substantial portions of the Software.
17+
18+
THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND,
19+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
20+
OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
21+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
22+
HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
23+
WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
24+
FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
25+
OTHER DEALINGS IN THE SOFTWARE.

‎README.md

+76
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
# PHP 7 API Wrapper for Popular Currency Rate APIs
2+
3+
[![Version](https://img.shields.io/packagist/v/otherguy/php-currency-api.svg?style=flat-square)](https://packagist.org/packages/otherguy/php-currency-api)
4+
[![GitHub issues](https://img.shields.io/github/issues/otherguy/php-currency-api.svg?style=flat-square)](https://github.com/otherguy/php-currency-api/issues)
5+
[![Travis CI](https://img.shields.io/travis/otherguy/php-currency-api.svg?style=flat-square)](https://travis-ci.com/otherguy/php-currency-api)
6+
[![Coverage](https://img.shields.io/coveralls/otherguy/php-currency-api.svg?style=flat-square)](https://coveralls.io/github/otherguy/php-currency-api?branch=master)
7+
[![GitHub](https://img.shields.io/github/license/otherguy/php-currency-api.svg?style=flat-square)](LICENSE.md)
8+
9+
Dont worry about your favorite currency conversion service suddenly shutting down or switching plans on you. Switch away easily.
10+
11+
## Inspiration
12+
13+
I needed a currency conversion API for [my travel website]() but couldn't find a good PHP package. The idea of the
14+
[`Rackbeat/php-currency-api`](https://github.com/Rackbeat/php-currency-api) package came closest but unfortunately it
15+
was just a stub and not implemented.
16+
17+
## Supported APIs
18+
19+
* [FixerIO](https://fixer.io) (`fixerio`)
20+
* [CurrencyLayer](https://currencylayer.com) (`currencylayer`)
21+
* [Open Exchange Rates](https://openexchangerates.org) (`openexchangerates`)
22+
23+
## Prerequisites
24+
25+
* PHP 7.1+
26+
* An account with one of the APIs above
27+
28+
## Installation
29+
30+
Just require the package using composer and you're good to go!
31+
32+
```bash
33+
$ composer require otherguy/php-currency-api
34+
```
35+
36+
## Usage
37+
38+
### Initialize instance
39+
40+
```php
41+
$api = Otherguy\Currency\API::make('fixerio'); // driver from supported drivers.
42+
```
43+
44+
### Set base currency (default = USD)
45+
46+
```php
47+
$api->setBase(Otherguy\Currency\Symbol::USD);
48+
```
49+
50+
### Set symbols to return (default = all/[])
51+
52+
```php
53+
$api->setSymbols([ Otherguy\Currency\Symbol::DKK, Otherguy\Currency\Symbol::EUR, Otherguy\Currency\Symbol::USD ]);
54+
```
55+
56+
*Please note, you are not required to use `Otherguy\Currency\Symbol` to specify symbols. It's simply a convenience helper.*
57+
58+
### Get latest rates
59+
60+
```php
61+
$api->get(); // Get latest rates for selected symbols, using set base currency
62+
$api->get('DKK'); // Get latest rates for selected symbols, using DKK as base currency
63+
```
64+
65+
### Convert amount from one currency to another
66+
67+
```php
68+
$api->convert($fromCurrency = 'DKK', $toCurrency = 'EUR', 10.00); // Convert 10 DKK to EUR
69+
```
70+
71+
### Get rate on specific date
72+
73+
```php
74+
$api->historical($date = '2018-01-01'); // Get currency rate for base on 1st of January 2018
75+
$api->historical($date = '2018-01-01', 'GBP'); // Get currency rate for GBP on 1st of January 2018
76+
```

‎composer.json

+44
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
{
2+
"name": "otherguy/php-currency-api",
3+
"description": "Wrapper for multiple currency rate APIs",
4+
"keywords": [
5+
"currency",
6+
"currency rates",
7+
"exchange rates",
8+
"currency conversion",
9+
"api"
10+
],
11+
"type": "library",
12+
"license": "MIT",
13+
"authors": [
14+
{
15+
"name": "Alexander Graf",
16+
"email": "alex@otherguy.io"
17+
}
18+
],
19+
"require": {
20+
"php": ">=7.1",
21+
"rmccue/requests": ">=1.7"
22+
},
23+
"require-dev": {
24+
"php-coveralls/php-coveralls": "^2.1",
25+
"phpunit/php-code-coverage": "^6.1",
26+
"phpunit/phpunit": "^7.0"
27+
},
28+
"suggest": {
29+
"ext-curl": "Faster HTTP requests"
30+
},
31+
"autoload": {
32+
"psr-4": {
33+
"Otherguy\\Currency\\": "src/"
34+
}
35+
},
36+
"autoload-dev": {
37+
"psr-4": {
38+
"Currency\\Tests\\": "tests/"
39+
}
40+
},
41+
"config": {
42+
"sort-packages": true
43+
}
44+
}

0 commit comments

Comments
 (0)
Failed to load comments.