simple_forex 0.1.0 → 0.1.1
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 +4 -4
- data/CHANGELOG.md +5 -1
- data/README.md +7 -7
- data/lib/simple_forex/tasks/simple_forex.rake +17 -2
- data/lib/simple_forex/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: f474511989432ae427e6107ca3470d42cc43b1d6876d72a66b8a0a18fd0e678f
|
4
|
+
data.tar.gz: fa0b99e28d57e2ee24b1a250164b3ff13550d9ef2524cc56b619acbbe941b9ac
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 556b50a43b7b13ae4a16a5dc92bf6c917aa61158729698bb3093917ab1163c497b3892571b394a9301cfecfd9ed7e6c391eb4d033c6ab9b42d8f5bd36be10098
|
7
|
+
data.tar.gz: e8038a1f63c9f0098aa47afbbf1d99b592b5c15bbbc134bc75a40fded711835104e0d6e45b9a8ef0303525e0ad960d4245fa4c25d8b2fe7a7fe04f67b303f71a
|
data/CHANGELOG.md
CHANGED
data/README.md
CHANGED
@@ -44,8 +44,9 @@ rake db:migrate
|
|
44
44
|
Get a [free API key](https://openexchangerates.org/signup/free), open credentials.yml (`EDITOR="vim" rails credentials:edit`) and add the API key to credentials.yml like so:
|
45
45
|
|
46
46
|
```
|
47
|
+
# config/credentials.yml.enc
|
47
48
|
simple_forex:
|
48
|
-
openexchangerates_key:
|
49
|
+
openexchangerates_key: 1234abcd
|
49
50
|
```
|
50
51
|
|
51
52
|
Then, run this to retrieve currencies in the currencies table:
|
@@ -54,10 +55,10 @@ Then, run this to retrieve currencies in the currencies table:
|
|
54
55
|
rake simple_forex:fetch_rates
|
55
56
|
```
|
56
57
|
|
57
|
-
|
58
|
+
View the exchange rate data in the rails console with `Currency.last`.
|
58
59
|
|
59
60
|
|
60
|
-
### Schedule
|
61
|
+
### Schedule task to update currencies
|
61
62
|
|
62
63
|
**Optional**
|
63
64
|
|
@@ -70,21 +71,20 @@ Tip: open exchange rates's free API gives 1000 calls monthly, and there are ~700
|
|
70
71
|
|
71
72
|
Convert currencies by calling
|
72
73
|
|
73
|
-
|
74
74
|
```ruby
|
75
75
|
require 'simple_forex'
|
76
76
|
convert(amount, from_currency, to_currency)
|
77
77
|
```
|
78
78
|
|
79
|
-
|
80
|
-
### Example
|
79
|
+
For example
|
81
80
|
|
82
81
|
```ruby
|
83
82
|
require 'simple_forex'
|
84
83
|
convert(100, 'USD', 'EUR')
|
85
|
-
# =>
|
84
|
+
# => 0.939717e2
|
86
85
|
```
|
87
86
|
|
87
|
+
Note the decimal value returned uses scientific notation, evidenced by the `e` in the decimal's representation.
|
88
88
|
|
89
89
|
|
90
90
|
## Development
|
@@ -40,10 +40,25 @@ namespace :simple_forex do
|
|
40
40
|
# from = "AUDz"
|
41
41
|
# error_message % {currency_code: from}
|
42
42
|
|
43
|
-
|
43
|
+
|
44
|
+
|
45
|
+
def get_key
|
46
|
+
# Get key
|
47
|
+
if Rails.version[0].to_i <= 6
|
48
|
+
# Works in rails 6
|
49
|
+
Rails.application.credentials.simple_forex[:openexchangerates_key]
|
50
|
+
elsif Rails.version[0].to_i >= 7
|
51
|
+
# Works for rails 7
|
52
|
+
Rails.application.credentials.simple_forex.openexchangerates_key
|
53
|
+
end
|
54
|
+
end
|
55
|
+
|
56
|
+
|
57
|
+
|
58
|
+
|
44
59
|
|
45
60
|
begin
|
46
|
-
|
61
|
+
get_key
|
47
62
|
rescue => exception
|
48
63
|
$stderr.puts "Error: #{exception} - \n\n" + error_message + "\n\n"
|
49
64
|
end
|
data/lib/simple_forex/version.rb
CHANGED