fxpotato 1.1.1 → 2.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +39 -1
- data/lib/fxpotato/cli.rb +1 -1
- data/lib/fxpotato/version.rb +1 -1
- data/lib/fxpotato.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: a2f6de8473ac29270e901906c6df69a443e6ea3f
|
4
|
+
data.tar.gz: 814ef8a5b3cf444cc9bcce0cb1e2c373cc489793
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 476cab120e1797f427cf038ec896f7cec219d75b3d0928067d42b702646185b95f16bf283aec0b79e18ce57c4331fa6e8a7ecb5d6dab486e59553966240d5dd8
|
7
|
+
data.tar.gz: 5977afe0f51dfd77fd9803abe0e9515b0488f9cbb538b5dff478209e2f45c623a18ca60ff1e055970bbab8bf426bc9eaf2481e612f3b409a015de349cdf30bd8
|
data/README.md
CHANGED
@@ -21,7 +21,8 @@ Or install it yourself as:
|
|
21
21
|
$ gem install fxpotato
|
22
22
|
|
23
23
|
### Configuration
|
24
|
-
FxPotato takes rates from the [ECB website](http://www.ecb.europa.eu/stats/eurofxref/eurofxref-hist-90d.xml).
|
24
|
+
FxPotato takes rates from the [ECB website](http://www.ecb.europa.eu/stats/eurofxref/eurofxref-hist-90d.xml). It then saves this data into a `rates.xml` file under the `data` directory in the root of your project. To configure either of those destinations, set the corresponding environment variables:
|
25
|
+
`FXPOTATO_DATA_DIR` and `DATA_FILE`.
|
25
26
|
|
26
27
|
To change the feed, set the `FXPOTATO_DATA_SOURCE_URL` environment variable to the new URL, and if the structure of the xml is different (or indeed not XML at all, which is also totes cool), set `FxPotato.repo` to equal an instance of a custom class of your own writing for locating rates in the new structure. Make sure to set `FxPotato.repo = YourClass.new` before you use the other functionality in `FxPotato`.
|
27
28
|
|
@@ -36,6 +37,43 @@ end
|
|
36
37
|
If using the crontab functionality, configure your own schedule by editing the `config/schedule.rb` file, as per the [whenever documentation](https://github.com/javan/whenever#example-schedulerb-file).
|
37
38
|
|
38
39
|
## Usage
|
40
|
+
### Crontab
|
41
|
+
FxPotato comes with optional crontab functionality to keep itself up to date. To enable the cron job, run the rake task `rake fxpotato:update_crontab`. Then verify the job is in your crontab by running `crontab -l`.
|
42
|
+
|
43
|
+
If you decide this was a big mistake and wish to purify your crontab of fxpotato, then run the rake task `rake fxpotato:clear_crontab`, and verify again.
|
44
|
+
|
45
|
+
The details of the cron job is configurable, as mentioned before, by editing the `config/schedule.rb` file as per the [whenever documentation](https://github.com/javan/whenever#example-schedulerb-file).
|
46
|
+
|
47
|
+
### In your ruby app
|
48
|
+
Assuming you successfully followed the install instructions, and are still reading this exciting documentation with much reckless abandon, steady yourself!
|
49
|
+
|
50
|
+
Now. Using the FxPotato gem in your app is as simple as:
|
51
|
+
|
52
|
+
```
|
53
|
+
FxPotato.at('GBP', 'USD', date)
|
54
|
+
```
|
55
|
+
|
56
|
+
The date parameter is a `Date` object, which will default to today if nil, and the currency keys are simply strings. The gem is case insensitive, so don't worry about that.
|
57
|
+
|
58
|
+
This will return a hash that looks like this:
|
59
|
+
|
60
|
+
```
|
61
|
+
{
|
62
|
+
"date" => #<Date: 2017-06-06 ((2457911j,0s,0n),+0s,2299161j)>, // <-- a Date object
|
63
|
+
"base" => {
|
64
|
+
"key" => "GBP",
|
65
|
+
"rate" => 0.87268
|
66
|
+
},
|
67
|
+
"target" => {
|
68
|
+
"key" => "USD",
|
69
|
+
"rate" => 1.1217
|
70
|
+
},
|
71
|
+
"rate" => 1.2853508731722967
|
72
|
+
}
|
73
|
+
```
|
74
|
+
|
75
|
+
If for any reason the call was unsuccessful, the root `rate` will be nil, and the unlocatable rate(s) will also be nil.
|
76
|
+
|
39
77
|
### CLI
|
40
78
|
Get foreign exchange rates on the command line with the following command:
|
41
79
|
|
data/lib/fxpotato/cli.rb
CHANGED
@@ -10,7 +10,7 @@ module FxPotato
|
|
10
10
|
def getrate(base, target)
|
11
11
|
date = options[:date] || Date.today
|
12
12
|
begin
|
13
|
-
fxrate = FxPotato.at(
|
13
|
+
fxrate = FxPotato.at(base, target, date)
|
14
14
|
puts CLIFormatter.result(fxrate)
|
15
15
|
rescue RuntimeError => message
|
16
16
|
puts message
|
data/lib/fxpotato/version.rb
CHANGED
data/lib/fxpotato.rb
CHANGED
@@ -9,7 +9,7 @@ require "fxpotato/railtie" if defined?(Rails)
|
|
9
9
|
require 'date'
|
10
10
|
|
11
11
|
module FxPotato
|
12
|
-
def self.at(
|
12
|
+
def self.at(base_key, target_key, date = nil)
|
13
13
|
base_key = upcase_if_not_nil(base_key)
|
14
14
|
target_key = upcase_if_not_nil(target_key)
|
15
15
|
date ||= Date.today
|