fxpotato 1.1.1 → 2.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: fb8890704ee0761a1495035f28e01fc790923a3c
4
- data.tar.gz: 835441cd4b04471b01771d689974ee4c9e9099b0
3
+ metadata.gz: a2f6de8473ac29270e901906c6df69a443e6ea3f
4
+ data.tar.gz: 814ef8a5b3cf444cc9bcce0cb1e2c373cc489793
5
5
  SHA512:
6
- metadata.gz: 69b6b6810b59d4daa04449092adf9cc83321418b65c26be46fccf0be5451e9f4d0add043b05b1900f80cd8d6e0eaf45b9ab40405686a861f0d53ade133b6324e
7
- data.tar.gz: b17104b54ed1f792ba0ec3f5727c5cd2ece166b10fbc2d43fbca9770c04bc15e9458c5b69fe3592f784f4794c871cd7175e84da696d9a9942b598e8570898f79
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(date, base, target)
13
+ fxrate = FxPotato.at(base, target, date)
14
14
  puts CLIFormatter.result(fxrate)
15
15
  rescue RuntimeError => message
16
16
  puts message
@@ -1,3 +1,3 @@
1
1
  module FxPotato
2
- VERSION = '1.1.1'
2
+ VERSION = '2.0.0'
3
3
  end
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(date, base_key, target_key)
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
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: fxpotato
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.1.1
4
+ version: 2.0.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Liam Stupid Name Humphreys