ecb_exchange 0.1.2 → 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.travis.yml +5 -10
- data/CHANGELOG.md +10 -1
- data/CODE_OF_CONDUCT.md +54 -30
- data/CONTRIBUTING.md +0 -1
- data/PULL_REQUEST_TEMPLATE.md +16 -0
- data/README.md +26 -29
- data/ecb_exchange.gemspec +6 -13
- data/lib/ecb/exchange.rb +3 -1
- data/lib/ecb/exchange/cache.rb +2 -0
- data/lib/ecb/exchange/errors.rb +2 -0
- data/lib/ecb/exchange/memory_cache.rb +2 -0
- data/lib/ecb/exchange/xml_feed.rb +2 -0
- data/lib/ecb_exchange.rb +2 -0
- metadata +5 -5
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: '0569c1270113499c32743bce9b846a4928a52389f678757789421b3f656609ba'
|
4
|
+
data.tar.gz: 283f20e271bbc1bfa5c39560b30d0f1d39b052775b556e9f7373a850b3307a60
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 6921600dfcd10a823ca657979fa6462d4b33ef0cbbcfdac6211743554c0dc15ac06a21755f1a3e7c57cda86bac4fa90149ca72b32e4fbd9bcbefebc32392de34
|
7
|
+
data.tar.gz: 2d18faa58686485957e0a17e2a1bba8e6f124a518707f6f150258ec1f9e52208114bcc871ca090f0d8a8983ac476b0479ba9ef20e0d260b25fb5ef9510dd060d
|
data/.travis.yml
CHANGED
@@ -2,16 +2,11 @@ sudo: false
|
|
2
2
|
language: ruby
|
3
3
|
cache: bundler
|
4
4
|
rvm:
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
-
|
10
|
-
- ruby-head
|
11
|
-
|
12
|
-
before_install:
|
13
|
-
- gem update --system
|
14
|
-
- gem install bundler
|
5
|
+
- 2.3.8
|
6
|
+
- 2.4.6
|
7
|
+
- 2.5.5
|
8
|
+
- 2.6.3
|
9
|
+
- ruby-head
|
15
10
|
|
16
11
|
matrix:
|
17
12
|
allow_failures:
|
data/CHANGELOG.md
CHANGED
@@ -7,6 +7,14 @@ adheres to [Semantic Versioning](Semver).
|
|
7
7
|
|
8
8
|
## [Unreleased]
|
9
9
|
|
10
|
+
- Your contribution here!
|
11
|
+
|
12
|
+
## [0.2.0] - 2019-04-22
|
13
|
+
### Changed
|
14
|
+
- Require at least Ruby 2.3 - earlier versions no longer supported.
|
15
|
+
### Added
|
16
|
+
- `# frozen_string_literal: true` to all Ruby files.
|
17
|
+
|
10
18
|
## [0.1.2] - 2018-05-05
|
11
19
|
### Changed
|
12
20
|
- Updated gemspec meta data links.
|
@@ -19,7 +27,8 @@ adheres to [Semantic Versioning](Semver).
|
|
19
27
|
### Added
|
20
28
|
- Initial version released.
|
21
29
|
|
22
|
-
[Unreleased]: https://github.com/matthutchinson/ecb_exchange/compare/v0.
|
30
|
+
[Unreleased]: https://github.com/matthutchinson/ecb_exchange/compare/v0.2.0...HEAD
|
31
|
+
[0.2.0]: https://github.com/matthutchinson/ecb_exchange/compare/v0.1.2...v0.2.0
|
23
32
|
[0.1.2]: https://github.com/matthutchinson/ecb_exchange/compare/v0.1.1...v0.1.2
|
24
33
|
[0.1.1]: https://github.com/matthutchinson/ecb_exchange/compare/v0.1.0...v0.1.1
|
25
34
|
[0.1.0]: https://github.com/matthutchinson/ecb_exchange/compare/e7366b3...v0.1.0
|
data/CODE_OF_CONDUCT.md
CHANGED
@@ -1,24 +1,41 @@
|
|
1
|
-
# Contributor Code of Conduct
|
1
|
+
# Contributor Covenant Code of Conduct
|
2
2
|
|
3
|
-
|
4
|
-
fostering an open and welcoming community, we pledge to respect all people who
|
5
|
-
contribute through reporting issues, posting feature requests, updating
|
6
|
-
documentation, submitting pull requests or patches, and other activities.
|
3
|
+
## Our Pledge
|
7
4
|
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
5
|
+
In the interest of fostering an open and welcoming environment, we as
|
6
|
+
contributors and maintainers pledge to making participation in our project and
|
7
|
+
our community a harassment-free experience for everyone, regardless of age, body
|
8
|
+
size, disability, ethnicity, gender identity and expression, level of experience,
|
9
|
+
education, socio-economic status, nationality, personal appearance, race,
|
10
|
+
religion, or sexual identity and orientation.
|
11
|
+
|
12
|
+
## Our Standards
|
13
|
+
|
14
|
+
Examples of behavior that contributes to creating a positive environment
|
15
|
+
include:
|
16
|
+
|
17
|
+
* Using welcoming and inclusive language
|
18
|
+
* Being respectful of differing viewpoints and experiences
|
19
|
+
* Gracefully accepting constructive criticism
|
20
|
+
* Focusing on what is best for the community
|
21
|
+
* Showing empathy towards other community members
|
12
22
|
|
13
23
|
Examples of unacceptable behavior by participants include:
|
14
24
|
|
15
|
-
* The use of sexualized language or imagery
|
16
|
-
|
17
|
-
* Trolling
|
25
|
+
* The use of sexualized language or imagery and unwelcome sexual attention or
|
26
|
+
advances
|
27
|
+
* Trolling, insulting/derogatory comments, and personal or political attacks
|
18
28
|
* Public or private harassment
|
19
|
-
* Publishing
|
20
|
-
|
21
|
-
* Other
|
29
|
+
* Publishing others' private information, such as a physical or electronic
|
30
|
+
address, without explicit permission
|
31
|
+
* Other conduct which could reasonably be considered inappropriate in a
|
32
|
+
professional setting
|
33
|
+
|
34
|
+
## Our Responsibilities
|
35
|
+
|
36
|
+
Project maintainers are responsible for clarifying the standards of acceptable
|
37
|
+
behavior and are expected to take appropriate and fair corrective action in
|
38
|
+
response to any instances of unacceptable behavior.
|
22
39
|
|
23
40
|
Project maintainers have the right and responsibility to remove, edit, or
|
24
41
|
reject comments, commits, code, wiki edits, issues, and other contributions
|
@@ -26,24 +43,31 @@ that are not aligned to this Code of Conduct, or to ban temporarily or
|
|
26
43
|
permanently any contributor for other behaviors that they deem inappropriate,
|
27
44
|
threatening, offensive, or harmful.
|
28
45
|
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
46
|
+
## Scope
|
47
|
+
|
48
|
+
This Code of Conduct applies both within project spaces and in public spaces
|
49
|
+
when an individual is representing the project or its community. Examples of
|
50
|
+
representing a project or community include using an official project e-mail
|
51
|
+
address, posting via an official social media account, or acting as an appointed
|
52
|
+
representative at an online or offline event. Representation of a project may be
|
53
|
+
further defined and clarified by project maintainers.
|
33
54
|
|
34
|
-
|
35
|
-
when an individual is representing the project or its community.
|
55
|
+
## Enforcement
|
36
56
|
|
37
57
|
Instances of abusive, harassing, or otherwise unacceptable behavior may be
|
38
|
-
reported by contacting
|
58
|
+
reported by contacting the project team at matt@hiddenloop.com. All
|
39
59
|
complaints will be reviewed and investigated and will result in a response that
|
40
|
-
is deemed necessary and appropriate to the circumstances.
|
41
|
-
obligated to maintain confidentiality with regard to the reporter of an
|
42
|
-
|
60
|
+
is deemed necessary and appropriate to the circumstances. The project team is
|
61
|
+
obligated to maintain confidentiality with regard to the reporter of an incident.
|
62
|
+
Further details of specific enforcement policies may be posted separately.
|
63
|
+
|
64
|
+
Project maintainers who do not follow or enforce the Code of Conduct in good
|
65
|
+
faith may face temporary or permanent repercussions as determined by other
|
66
|
+
members of the project's leadership.
|
67
|
+
|
68
|
+
## Attribution
|
43
69
|
|
44
|
-
This Code of Conduct is adapted from the [Contributor Covenant][homepage],
|
45
|
-
version
|
46
|
-
[http://contributor-covenant.org/version/1/3/0/][version]
|
70
|
+
This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4,
|
71
|
+
available at https://www.contributor-covenant.org/version/1/4/code-of-conduct.html
|
47
72
|
|
48
|
-
[homepage]:
|
49
|
-
[version]: http://contributor-covenant.org/version/1/3/0/
|
73
|
+
[homepage]: https://www.contributor-covenant.org
|
data/CONTRIBUTING.md
CHANGED
@@ -0,0 +1,16 @@
|
|
1
|
+
|
2
|
+
Explain what you're changing and why here.
|
3
|
+
|
4
|
+
---
|
5
|
+
#### :memo: Checklist
|
6
|
+
|
7
|
+
Please check this list and leave it intact for the reviewer. Thanks! :heart:
|
8
|
+
|
9
|
+
- [ ] Commit messages provide context (why not just what, some tips [here](http://tbaggery.com/2008/04/19/a-note-about-git-commit-messages.html)).
|
10
|
+
- [ ] If relevant, mention GitHub issue number above and include in a commit message.
|
11
|
+
- [ ] Latest code from master merged.
|
12
|
+
- [ ] New behaviour has test coverage.
|
13
|
+
- [ ] Avoid duplicating code.
|
14
|
+
- [ ] No commented out code.
|
15
|
+
- [ ] Avoid comments for your code, write code that explains itself.
|
16
|
+
- [ ] Changes are simple, useful, clear and brief.
|
data/README.md
CHANGED
@@ -1,21 +1,21 @@
|
|
1
1
|
# ECB Exchange
|
2
2
|
|
3
|
-
[![Gem
|
4
|
-
[![Travis
|
3
|
+
[![Gem](https://img.shields.io/gem/v/ecb_exchange.svg?style=flat)](http://rubygems.org/gems/ecb_exchange)
|
4
|
+
[![Travis](https://img.shields.io/travis/matthutchinson/ecb_exchange/master.svg?style=flat)](https://travis-ci.org/matthutchinson/ecb_exchange)
|
5
|
+
[![Depfu](https://img.shields.io/depfu/matthutchinson/ecb_exchange.svg?style=flat)](https://depfu.com/github/matthutchinson/ecb_exchange)
|
5
6
|
[![Maintainability](https://api.codeclimate.com/v1/badges/c67969dd7b921477bdcc/maintainability)](https://codeclimate.com/github/matthutchinson/ecb_exchange/maintainability)
|
6
7
|
[![Test Coverage](https://api.codeclimate.com/v1/badges/c67969dd7b921477bdcc/test_coverage)](https://codeclimate.com/github/matthutchinson/ecb_exchange/test_coverage)
|
7
|
-
[![Gem Dependency Status](https://gemnasium.com/badges/github.com/matthutchinson/ecb_exchange.svg)](https://gemnasium.com/github.com/matthutchinson/ecb_exchange)
|
8
8
|
|
9
9
|
Currency conversion using the European Central Bank's foreign [exchange
|
10
10
|
rates](http://www.ecb.europa.eu/stats/eurofxref/eurofxref-hist-90d.xml). Rates
|
11
11
|
for the last 90 days are fetched and cached on demand. All calculations are
|
12
|
-
performed and returned as `BigDecimal
|
12
|
+
performed and returned as `BigDecimal` (usually a [good
|
13
13
|
idea](https://makandracards.com/makandra/1178-bigdecimal-arithmetic-in-ruby)
|
14
|
-
when dealing with money.
|
14
|
+
when dealing with money).
|
15
15
|
|
16
16
|
## Requirements
|
17
17
|
|
18
|
-
* Ruby >= 2.
|
18
|
+
* [Ruby](http://ruby-lang.org/) >= 2.3
|
19
19
|
|
20
20
|
## Installation
|
21
21
|
|
@@ -27,54 +27,53 @@ gem 'ecb_exchange'
|
|
27
27
|
|
28
28
|
## Usage
|
29
29
|
|
30
|
-
|
30
|
+
Convert an amount from one currency to another:
|
31
31
|
|
32
32
|
```ruby
|
33
33
|
ECB::Exchange.convert(100, from: 'EUR', to: 'GBP')
|
34
34
|
=> 0.88235e2
|
35
35
|
```
|
36
36
|
|
37
|
-
The converted amount (using today's current rate) will be returned
|
38
|
-
`BigDecimal
|
39
|
-
|
37
|
+
The converted amount (using today's current rate) will be returned as
|
38
|
+
`BigDecimal`. In doing this, the gem will fetch and cache ECB rates for the last
|
39
|
+
90 days.
|
40
40
|
|
41
|
-
|
41
|
+
Convert an amount on a specific date:
|
42
42
|
|
43
43
|
```ruby
|
44
44
|
ECB::Exchange.convert(100, from: 'EUR', to: 'GBP', date: Date.parse('2017-01-11'))
|
45
45
|
=> 0.87235e2
|
46
46
|
```
|
47
47
|
|
48
|
-
To
|
48
|
+
To fetch the exchange rate multiplier between two currencies:
|
49
49
|
|
50
50
|
```ruby
|
51
|
-
ECB::Exchange.rate(from: 'EUR', to: 'USD')
|
51
|
+
ECB::Exchange.rate(from: 'EUR', to: 'USD') # pass an optional `date` arg here too
|
52
52
|
=> 0.11969e1
|
53
|
-
# you can pass an optional `date` argument to this method too
|
54
53
|
```
|
55
54
|
|
56
|
-
You can ask for an array of supported
|
55
|
+
You can ask for an array of all supported currencies with:
|
57
56
|
|
58
57
|
```ruby
|
59
58
|
ECB::Exchange.currencies
|
60
59
|
=> ["USD", "JPY", "BGN", "CZK", "DKK", "GBP", "HUF" ... ]
|
61
60
|
```
|
62
61
|
|
63
|
-
Finally, you can adjust the rates endpoint by setting
|
62
|
+
Finally, you can adjust the rates endpoint by setting your own
|
64
63
|
`XMLFeed.endpoint` (e.g. in an initializer):
|
65
64
|
|
66
65
|
```ruby
|
67
66
|
ECB::Exchange::XMLFeed.endpoint = "http://my-awesome-service.com/feed.xml"
|
68
67
|
```
|
69
68
|
|
70
|
-
The XML feed must conform to the [ECB
|
69
|
+
The XML feed at this endpoint must conform to the [ECB
|
71
70
|
rates](http://www.ecb.europa.eu/stats/eurofxref/eurofxref-hist-90d.xml)
|
72
71
|
structure.
|
73
72
|
|
74
73
|
## Handling Errors
|
75
74
|
|
76
75
|
Not all dates, rates or currencies may be available, or the remote endpoint
|
77
|
-
could be unresponsive.
|
76
|
+
could be unresponsive. For these cases consider handling these errors:
|
78
77
|
|
79
78
|
* `ECB::Exchange::DateNotFoundError`
|
80
79
|
* `ECB::Exchange::CurrencyNotFoundError`
|
@@ -85,18 +84,18 @@ Or rescue `ECB::Exchange::Error` to catch any of them.
|
|
85
84
|
|
86
85
|
## Caching
|
87
86
|
|
88
|
-
By default rates will be cached to one of the following backend stores (
|
89
|
-
|
87
|
+
By default rates will be cached to one of the following backend stores (in this
|
88
|
+
order of preference).
|
90
89
|
|
91
90
|
* Your own backend cache store (see below)
|
92
|
-
*
|
91
|
+
* `Rails.cache`
|
93
92
|
* An `ECB::Exchange::MemoryCache` instance (a simple in memory cache store)
|
94
93
|
|
95
|
-
To configure your own backend store:
|
94
|
+
To configure your own backend store (e.g. in an initializer):
|
96
95
|
|
97
96
|
```ruby
|
98
97
|
ECB::Exchange::Cache.backend = MyAwesomeCache.new
|
99
|
-
#
|
98
|
+
# this cache must implement public `read(key)` and `write(key, value)` methods
|
100
99
|
```
|
101
100
|
|
102
101
|
All keys in the cache are name-spaced with a `ecb_exchange_rates_for_date-`
|
@@ -108,8 +107,8 @@ Check out this repo and run `bin/setup`, this will install gem dependencies and
|
|
108
107
|
generate docs. Use `bundle exec rake` to run tests and generate a coverage
|
109
108
|
report.
|
110
109
|
|
111
|
-
You can also run `bin/console` for an interactive prompt
|
112
|
-
|
110
|
+
You can also run `bin/console` for an interactive prompt to experiment with the
|
111
|
+
code.
|
113
112
|
|
114
113
|
## Tests
|
115
114
|
|
@@ -146,12 +145,10 @@ Covenant](http://contributor-covenant.org) code of conduct. See
|
|
146
145
|
[here](https://github.com/matthutchinson/ecb_exchange/blob/master/CODE_OF_CONDUCT.md)
|
147
146
|
for more details.
|
148
147
|
|
149
|
-
|
150
148
|
## Todo
|
151
149
|
|
152
150
|
* Better RDoc documentation.
|
153
|
-
* A
|
154
|
-
* Allow `Net::HTTP` to be swapped out for any another HTTP client.
|
151
|
+
* A Rails app to demo this gem (e.g. with a one-click Heroku install).
|
155
152
|
|
156
153
|
## License
|
157
154
|
|
@@ -160,11 +157,11 @@ The code is available as open source under the terms of
|
|
160
157
|
|
161
158
|
## Links
|
162
159
|
|
160
|
+
* [Gem](http://rubygems.org/gems/ecb_exchange)
|
163
161
|
* [Travis CI](https://travis-ci.org/matthutchinson/ecb_exchange)
|
164
162
|
* [Maintainability](https://codeclimate.com/github/matthutchinson/ecb_exchange/maintainability)
|
165
163
|
* [Test Coverage](https://codeclimate.com/github/matthutchinson/ecb_exchange/test_coverage)
|
166
164
|
* [RDoc](http://rdoc.info/projects/matthutchinson/ecb_exchange)
|
167
165
|
* [Issues](http://github.com/matthutchinson/ecb_exchange/issues)
|
168
166
|
* [Report a bug](http://github.com/matthutchinson/ecb_exchange/issues/new)
|
169
|
-
* [Gem](http://rubygems.org/gems/ecb_exchange)
|
170
167
|
* [GitHub](https://github.com/matthutchinson/ecb_exchange)
|
data/ecb_exchange.gemspec
CHANGED
@@ -21,20 +21,13 @@ Gem::Specification.new do |spec|
|
|
21
21
|
EOF
|
22
22
|
|
23
23
|
spec.metadata = {
|
24
|
-
"homepage_uri"
|
25
|
-
"changelog_uri"
|
26
|
-
"source_code_uri"
|
27
|
-
"bug_tracker_uri"
|
24
|
+
"homepage_uri" => "https://github.com/matthutchinson/ecb_exchange",
|
25
|
+
"changelog_uri" => "https://github.com/matthutchinson/ecb_exchange/blob/master/CHANGELOG.md",
|
26
|
+
"source_code_uri" => "https://github.com/matthutchinson/ecb_exchange",
|
27
|
+
"bug_tracker_uri" => "https://github.com/matthutchinson/ecb_exchange/issues",
|
28
|
+
"allowed_push_host" => "https://rubygems.org"
|
28
29
|
}
|
29
30
|
|
30
|
-
# Prevent pushing this gem to RubyGems.org. To allow pushes either set the "allowed_push_host"
|
31
|
-
# to allow pushing to a single host or delete this section to allow pushing to any host.
|
32
|
-
if spec.respond_to?(:metadata)
|
33
|
-
spec.metadata["allowed_push_host"] = "https://rubygems.org"
|
34
|
-
else
|
35
|
-
raise "RubyGems 2.0 or newer is required to protect against public gem pushes."
|
36
|
-
end
|
37
|
-
|
38
31
|
spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
|
39
32
|
spec.test_files = `git ls-files -- {test}/*`.split("\n")
|
40
33
|
spec.bindir = "bin"
|
@@ -46,7 +39,7 @@ Gem::Specification.new do |spec|
|
|
46
39
|
spec.rdoc_options << "--title" << "ECB Exchange" << "--main" << "README.md" << "-ri"
|
47
40
|
|
48
41
|
# non-gem dependecies
|
49
|
-
spec.required_ruby_version = ">= 2.
|
42
|
+
spec.required_ruby_version = ">= 2.3"
|
50
43
|
|
51
44
|
# dev gems
|
52
45
|
spec.add_development_dependency "bundler"
|
data/lib/ecb/exchange.rb
CHANGED
@@ -1,9 +1,11 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
require 'date'
|
2
4
|
require 'bigdecimal/util'
|
3
5
|
|
4
6
|
module ECB
|
5
7
|
module Exchange
|
6
|
-
VERSION = "0.
|
8
|
+
VERSION = "0.2.0".freeze
|
7
9
|
|
8
10
|
def self.convert(amount, from:, to:, date: Date.today)
|
9
11
|
amount.to_d * rate(from: from, to: to, date: date)
|
data/lib/ecb/exchange/cache.rb
CHANGED
data/lib/ecb/exchange/errors.rb
CHANGED
data/lib/ecb_exchange.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: ecb_exchange
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Matthew Hutchinson
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2019-04-22 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -128,6 +128,7 @@ files:
|
|
128
128
|
- CONTRIBUTING.md
|
129
129
|
- Gemfile
|
130
130
|
- LICENSE
|
131
|
+
- PULL_REQUEST_TEMPLATE.md
|
131
132
|
- README.md
|
132
133
|
- Rakefile
|
133
134
|
- bin/console
|
@@ -161,15 +162,14 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
161
162
|
requirements:
|
162
163
|
- - ">="
|
163
164
|
- !ruby/object:Gem::Version
|
164
|
-
version: 2.
|
165
|
+
version: '2.3'
|
165
166
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
166
167
|
requirements:
|
167
168
|
- - ">="
|
168
169
|
- !ruby/object:Gem::Version
|
169
170
|
version: '0'
|
170
171
|
requirements: []
|
171
|
-
|
172
|
-
rubygems_version: 2.7.6
|
172
|
+
rubygems_version: 3.0.3
|
173
173
|
signing_key:
|
174
174
|
specification_version: 4
|
175
175
|
summary: Currency conversion using the European Central Bank's foreign exchange rates.
|