vici-exchange-rates 0.1.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 +7 -0
- data/.gitignore +83 -0
- data/.idea/.gitignore +2 -0
- data/.idea/.rakeTasks +7 -0
- data/.idea/inspectionProfiles/Project_Default.xml +10 -0
- data/.idea/misc.xml +7 -0
- data/.idea/modules.xml +8 -0
- data/.idea/vcs.xml +6 -0
- data/.idea/vici-exchange_rates.iml +28 -0
- data/.rspec +3 -0
- data/.travis.yml +7 -0
- data/CODE_OF_CONDUCT.md +74 -0
- data/Gemfile +4 -0
- data/Gemfile.lock +54 -0
- data/LICENSE.txt +21 -0
- data/README.md +108 -0
- data/Rakefile +6 -0
- data/bin/console +14 -0
- data/bin/setup +8 -0
- data/lib/vici/exchange_rates/version.rb +5 -0
- data/lib/vici/exchange_rates.rb +136 -0
- data/vici-exchange-rates.gemspec +30 -0
- metadata +140 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: de783d419042d4e43cb16154546f6b1f8ed41246fd38088805fa192867e83426
|
4
|
+
data.tar.gz: deca20ee8fadfd09d1b8695f8551c5e317d892f83844cb2dd8965f9c327d0ce3
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: cd0a347ca7a7a254709b29cd3aec4c4c7423dc7b6af131186ce361075b3bdf40f80b191e823124ffe93117bd32caf73e0197c0dc950bf30aa88974ea653b0203
|
7
|
+
data.tar.gz: 4e04812d2acbe44cd7379748bb722fcc5bb095f4b35d5d768f25d9617d60c206ecb25d50f6d95a72764abde7162ae03f0c357a59f53748d78d4db8b834b2eaac
|
data/.gitignore
ADDED
@@ -0,0 +1,83 @@
|
|
1
|
+
/.bundle/
|
2
|
+
/.yardoc
|
3
|
+
/_yardoc/
|
4
|
+
/coverage/
|
5
|
+
/doc/
|
6
|
+
/pkg/
|
7
|
+
/spec/reports/
|
8
|
+
/tmp/
|
9
|
+
|
10
|
+
.rspec_status
|
11
|
+
.DS_Store
|
12
|
+
|
13
|
+
# Covers JetBrains IDEs: IntelliJ, RubyMine, PhpStorm, AppCode, PyCharm, CLion, Android Studio and WebStorm
|
14
|
+
# Reference: https://intellij-support.jetbrains.com/hc/en-us/articles/206544839
|
15
|
+
|
16
|
+
# User-specific stuff
|
17
|
+
.idea/**/workspace.xml
|
18
|
+
.idea/**/tasks.xml
|
19
|
+
.idea/**/usage.statistics.xml
|
20
|
+
.idea/**/dictionaries
|
21
|
+
.idea/**/shelf
|
22
|
+
|
23
|
+
# Generated files
|
24
|
+
.idea/**/contentModel.xml
|
25
|
+
|
26
|
+
# Sensitive or high-churn files
|
27
|
+
.idea/**/dataSources/
|
28
|
+
.idea/**/dataSources.ids
|
29
|
+
.idea/**/dataSources.local.xml
|
30
|
+
.idea/**/sqlDataSources.xml
|
31
|
+
.idea/**/dynamic.xml
|
32
|
+
.idea/**/uiDesigner.xml
|
33
|
+
.idea/**/dbnavigator.xml
|
34
|
+
|
35
|
+
# Gradle
|
36
|
+
.idea/**/gradle.xml
|
37
|
+
.idea/**/libraries
|
38
|
+
|
39
|
+
# Gradle and Maven with auto-import
|
40
|
+
# When using Gradle or Maven with auto-import, you should exclude module files,
|
41
|
+
# since they will be recreated, and may cause churn. Uncomment if using
|
42
|
+
# auto-import.
|
43
|
+
# .idea/artifacts
|
44
|
+
# .idea/compiler.xml
|
45
|
+
# .idea/jarRepositories.xml
|
46
|
+
# .idea/modules.xml
|
47
|
+
# .idea/*.iml
|
48
|
+
# .idea/modules
|
49
|
+
# *.iml
|
50
|
+
# *.ipr
|
51
|
+
|
52
|
+
# CMake
|
53
|
+
cmake-build-*/
|
54
|
+
|
55
|
+
# Mongo Explorer plugin
|
56
|
+
.idea/**/mongoSettings.xml
|
57
|
+
|
58
|
+
# File-based project format
|
59
|
+
*.iws
|
60
|
+
|
61
|
+
# IntelliJ
|
62
|
+
out/
|
63
|
+
|
64
|
+
# mpeltonen/sbt-idea plugin
|
65
|
+
.idea_modules/
|
66
|
+
|
67
|
+
# JIRA plugin
|
68
|
+
atlassian-ide-plugin.xml
|
69
|
+
|
70
|
+
# Cursive Clojure plugin
|
71
|
+
.idea/replstate.xml
|
72
|
+
|
73
|
+
# Crashlytics plugin (for Android Studio and IntelliJ)
|
74
|
+
com_crashlytics_export_strings.xml
|
75
|
+
crashlytics.properties
|
76
|
+
crashlytics-build.properties
|
77
|
+
fabric.properties
|
78
|
+
|
79
|
+
# Editor-based Rest Client
|
80
|
+
.idea/httpRequests
|
81
|
+
|
82
|
+
# Android studio 3.1+ serialized cache file
|
83
|
+
.idea/caches/build_file_checksums.ser
|
data/.idea/.gitignore
ADDED
data/.idea/.rakeTasks
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
<?xml version="1.0" encoding="UTF-8"?>
|
2
|
+
<Settings><!--This file was automatically generated by Ruby plugin.
|
3
|
+
You are allowed to:
|
4
|
+
1. Remove rake task
|
5
|
+
2. Add existing rake tasks
|
6
|
+
To add existing rake tasks automatically delete this file and reload the project.
|
7
|
+
--><RakeGroup description="" fullCmd="" taksId="rake"><RakeTask description="Build vici-exchange_rates-0.1.0.gem into the pkg directory" fullCmd="build" taksId="build" /><RakeTask description="Remove any temporary products" fullCmd="clean" taksId="clean" /><RakeTask description="Remove any generated files" fullCmd="clobber" taksId="clobber" /><RakeTask description="Build and install vici-exchange_rates-0.1.0.gem into system gems" fullCmd="install" taksId="install" /><RakeGroup description="" fullCmd="" taksId="install"><RakeTask description="Build and install vici-exchange_rates-0.1.0.gem into system gems without network access" fullCmd="install:local" taksId="local" /></RakeGroup><RakeTask description="Create tag v0.1.0 and build and push vici-exchange_rates-0.1.0.gem to TODO: Set to 'http://mygemserver.com'" fullCmd="release[remote]" taksId="release[remote]" /><RakeTask description="Run RSpec code examples" fullCmd="spec" taksId="spec" /><RakeTask description="" fullCmd="default" taksId="default" /><RakeTask description="" fullCmd="release" taksId="release" /><RakeGroup description="" fullCmd="" taksId="release"><RakeTask description="" fullCmd="release:guard_clean" taksId="guard_clean" /><RakeTask description="" fullCmd="release:rubygem_push" taksId="rubygem_push" /><RakeTask description="" fullCmd="release:source_control_push" taksId="source_control_push" /></RakeGroup></RakeGroup></Settings>
|
@@ -0,0 +1,10 @@
|
|
1
|
+
<component name="InspectionProjectProfileManager">
|
2
|
+
<profile version="1.0">
|
3
|
+
<option name="myName" value="Project Default" />
|
4
|
+
<inspection_tool class="SpellCheckingInspection" enabled="false" level="TYPO" enabled_by_default="false">
|
5
|
+
<option name="processCode" value="true" />
|
6
|
+
<option name="processLiterals" value="true" />
|
7
|
+
<option name="processComments" value="true" />
|
8
|
+
</inspection_tool>
|
9
|
+
</profile>
|
10
|
+
</component>
|
data/.idea/misc.xml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
<?xml version="1.0" encoding="UTF-8"?>
|
2
|
+
<project version="4">
|
3
|
+
<component name="JavaScriptSettings">
|
4
|
+
<option name="languageLevel" value="ES6" />
|
5
|
+
</component>
|
6
|
+
<component name="ProjectRootManager" version="2" project-jdk-name="rbenv: 2.6.3" project-jdk-type="RUBY_SDK" />
|
7
|
+
</project>
|
data/.idea/modules.xml
ADDED
@@ -0,0 +1,8 @@
|
|
1
|
+
<?xml version="1.0" encoding="UTF-8"?>
|
2
|
+
<project version="4">
|
3
|
+
<component name="ProjectModuleManager">
|
4
|
+
<modules>
|
5
|
+
<module fileurl="file://$PROJECT_DIR$/.idea/vici-exchange_rates.iml" filepath="$PROJECT_DIR$/.idea/vici-exchange_rates.iml" />
|
6
|
+
</modules>
|
7
|
+
</component>
|
8
|
+
</project>
|
data/.idea/vcs.xml
ADDED
@@ -0,0 +1,28 @@
|
|
1
|
+
<?xml version="1.0" encoding="UTF-8"?>
|
2
|
+
<module type="RUBY_MODULE" version="4">
|
3
|
+
<component name="ModuleRunConfigurationManager">
|
4
|
+
<shared />
|
5
|
+
</component>
|
6
|
+
<component name="NewModuleRootManager">
|
7
|
+
<content url="file://$MODULE_DIR$" />
|
8
|
+
<orderEntry type="inheritedJdk" />
|
9
|
+
<orderEntry type="sourceFolder" forTests="false" />
|
10
|
+
<orderEntry type="library" scope="PROVIDED" name="activesupport (v6.0.2.1, rbenv: 2.6.3) [gem]" level="application" />
|
11
|
+
<orderEntry type="library" scope="PROVIDED" name="bundler (v2.0.2, rbenv: 2.6.3) [gem]" level="application" />
|
12
|
+
<orderEntry type="library" scope="PROVIDED" name="concurrent-ruby (v1.1.5, rbenv: 2.6.3) [gem]" level="application" />
|
13
|
+
<orderEntry type="library" scope="PROVIDED" name="diff-lcs (v1.3, rbenv: 2.6.3) [gem]" level="application" />
|
14
|
+
<orderEntry type="library" scope="PROVIDED" name="faraday (v1.0.0, rbenv: 2.6.3) [gem]" level="application" />
|
15
|
+
<orderEntry type="library" scope="PROVIDED" name="i18n (v1.8.2, rbenv: 2.6.3) [gem]" level="application" />
|
16
|
+
<orderEntry type="library" scope="PROVIDED" name="minitest (v5.14.0, rbenv: 2.6.3) [gem]" level="application" />
|
17
|
+
<orderEntry type="library" scope="PROVIDED" name="multipart-post (v2.1.1, rbenv: 2.6.3) [gem]" level="application" />
|
18
|
+
<orderEntry type="library" scope="PROVIDED" name="rake (v10.5.0, rbenv: 2.6.3) [gem]" level="application" />
|
19
|
+
<orderEntry type="library" scope="PROVIDED" name="rspec (v3.9.0, rbenv: 2.6.3) [gem]" level="application" />
|
20
|
+
<orderEntry type="library" scope="PROVIDED" name="rspec-core (v3.9.1, rbenv: 2.6.3) [gem]" level="application" />
|
21
|
+
<orderEntry type="library" scope="PROVIDED" name="rspec-expectations (v3.9.0, rbenv: 2.6.3) [gem]" level="application" />
|
22
|
+
<orderEntry type="library" scope="PROVIDED" name="rspec-mocks (v3.9.1, rbenv: 2.6.3) [gem]" level="application" />
|
23
|
+
<orderEntry type="library" scope="PROVIDED" name="rspec-support (v3.9.2, rbenv: 2.6.3) [gem]" level="application" />
|
24
|
+
<orderEntry type="library" scope="PROVIDED" name="thread_safe (v0.3.6, rbenv: 2.6.3) [gem]" level="application" />
|
25
|
+
<orderEntry type="library" scope="PROVIDED" name="tzinfo (v1.2.6, rbenv: 2.6.3) [gem]" level="application" />
|
26
|
+
<orderEntry type="library" scope="PROVIDED" name="zeitwerk (v2.2.2, rbenv: 2.6.3) [gem]" level="application" />
|
27
|
+
</component>
|
28
|
+
</module>
|
data/.rspec
ADDED
data/.travis.yml
ADDED
data/CODE_OF_CONDUCT.md
ADDED
@@ -0,0 +1,74 @@
|
|
1
|
+
# Contributor Covenant Code of Conduct
|
2
|
+
|
3
|
+
## Our Pledge
|
4
|
+
|
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
|
+
nationality, personal appearance, race, religion, or sexual identity and
|
10
|
+
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
|
22
|
+
|
23
|
+
Examples of unacceptable behavior by participants include:
|
24
|
+
|
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
|
28
|
+
* Public or private harassment
|
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.
|
39
|
+
|
40
|
+
Project maintainers have the right and responsibility to remove, edit, or
|
41
|
+
reject comments, commits, code, wiki edits, issues, and other contributions
|
42
|
+
that are not aligned to this Code of Conduct, or to ban temporarily or
|
43
|
+
permanently any contributor for other behaviors that they deem inappropriate,
|
44
|
+
threatening, offensive, or harmful.
|
45
|
+
|
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.
|
54
|
+
|
55
|
+
## Enforcement
|
56
|
+
|
57
|
+
Instances of abusive, harassing, or otherwise unacceptable behavior may be
|
58
|
+
reported by contacting the project team at mafulprayoga@gmail.com. All
|
59
|
+
complaints will be reviewed and investigated and will result in a response that
|
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
|
69
|
+
|
70
|
+
This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4,
|
71
|
+
available at [http://contributor-covenant.org/version/1/4][version]
|
72
|
+
|
73
|
+
[homepage]: http://contributor-covenant.org
|
74
|
+
[version]: http://contributor-covenant.org/version/1/4/
|
data/Gemfile
ADDED
data/Gemfile.lock
ADDED
@@ -0,0 +1,54 @@
|
|
1
|
+
PATH
|
2
|
+
remote: .
|
3
|
+
specs:
|
4
|
+
vici-exchange-rates (0.1.0)
|
5
|
+
activesupport (~> 6.0, >= 6.0.2.1)
|
6
|
+
faraday (~> 1.0)
|
7
|
+
|
8
|
+
GEM
|
9
|
+
remote: https://rubygems.org/
|
10
|
+
specs:
|
11
|
+
activesupport (6.0.2.1)
|
12
|
+
concurrent-ruby (~> 1.0, >= 1.0.2)
|
13
|
+
i18n (>= 0.7, < 2)
|
14
|
+
minitest (~> 5.1)
|
15
|
+
tzinfo (~> 1.1)
|
16
|
+
zeitwerk (~> 2.2)
|
17
|
+
concurrent-ruby (1.1.5)
|
18
|
+
diff-lcs (1.3)
|
19
|
+
faraday (1.0.0)
|
20
|
+
multipart-post (>= 1.2, < 3)
|
21
|
+
i18n (1.8.2)
|
22
|
+
concurrent-ruby (~> 1.0)
|
23
|
+
minitest (5.14.0)
|
24
|
+
multipart-post (2.1.1)
|
25
|
+
rake (10.5.0)
|
26
|
+
rspec (3.9.0)
|
27
|
+
rspec-core (~> 3.9.0)
|
28
|
+
rspec-expectations (~> 3.9.0)
|
29
|
+
rspec-mocks (~> 3.9.0)
|
30
|
+
rspec-core (3.9.1)
|
31
|
+
rspec-support (~> 3.9.1)
|
32
|
+
rspec-expectations (3.9.0)
|
33
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
34
|
+
rspec-support (~> 3.9.0)
|
35
|
+
rspec-mocks (3.9.1)
|
36
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
37
|
+
rspec-support (~> 3.9.0)
|
38
|
+
rspec-support (3.9.2)
|
39
|
+
thread_safe (0.3.6)
|
40
|
+
tzinfo (1.2.6)
|
41
|
+
thread_safe (~> 0.1)
|
42
|
+
zeitwerk (2.2.2)
|
43
|
+
|
44
|
+
PLATFORMS
|
45
|
+
ruby
|
46
|
+
|
47
|
+
DEPENDENCIES
|
48
|
+
bundler (~> 2.0)
|
49
|
+
rake (~> 10.0)
|
50
|
+
rspec (~> 3.0)
|
51
|
+
vici-exchange-rates!
|
52
|
+
|
53
|
+
BUNDLED WITH
|
54
|
+
2.0.2
|
data/LICENSE.txt
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2020 maful
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
7
|
+
in the Software without restriction, including without limitation the rights
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
10
|
+
furnished to do so, subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in
|
13
|
+
all copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
21
|
+
THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,108 @@
|
|
1
|
+
# Vici::ExchangeRates
|
2
|
+
|
3
|
+
> A Simple and Rich for Exchange Rates
|
4
|
+
|
5
|
+
**Vici::ExchangeRates** is an unofficial SDK for the [ExchangeRatesAPI](https://exchangeratesapi.io). Exchange rates API is a free service for current and historical foreign exchange rates [published by the European Central Bank](https://www.ecb.europa.eu/stats/policy_and_exchange_rates/euro_reference_exchange_rates/html/index.en.html).
|
6
|
+
|
7
|
+
### Note
|
8
|
+
- This app requires JSON. If you're using JRuby < 1.7.0
|
9
|
+
you'll need to add `gem "json"` to your Gemfile or similar.
|
10
|
+
|
11
|
+
## Installation
|
12
|
+
|
13
|
+
Add this line to your application's Gemfile:
|
14
|
+
|
15
|
+
```ruby
|
16
|
+
gem 'vici-exchange-rates'
|
17
|
+
```
|
18
|
+
|
19
|
+
And then execute:
|
20
|
+
|
21
|
+
$ bundle
|
22
|
+
|
23
|
+
Or install it yourself as:
|
24
|
+
|
25
|
+
$ gem install vici-exchange-rates
|
26
|
+
|
27
|
+
## Usage
|
28
|
+
|
29
|
+
Currency code must be one of the [supported currency codes](https://www.ecb.europa.eu/stats/policy_and_exchange_rates/euro_reference_exchange_rates/html/index.en.html).
|
30
|
+
|
31
|
+
**Basic usage**
|
32
|
+
|
33
|
+
```ruby
|
34
|
+
require 'vici/exchange_rates'
|
35
|
+
|
36
|
+
rates = Vici::ExchangeRates.new
|
37
|
+
# or you can retrieve JSON response
|
38
|
+
rates = Vici::ExchangeRates.new(true)
|
39
|
+
rates.fetch
|
40
|
+
```
|
41
|
+
|
42
|
+
**Historical rates for any day since 1999**
|
43
|
+
|
44
|
+
```ruby
|
45
|
+
rates.at_date('2018-02-02')
|
46
|
+
rates.fetch
|
47
|
+
# OR
|
48
|
+
rates.at_date('2018-02-02').fetch
|
49
|
+
```
|
50
|
+
|
51
|
+
**Latest exchange rates with different base currency (Euro by default)**
|
52
|
+
|
53
|
+
```ruby
|
54
|
+
rates.base_currency('IDR')
|
55
|
+
rates.fetch
|
56
|
+
```
|
57
|
+
|
58
|
+
**Specific exchange rates**
|
59
|
+
|
60
|
+
```ruby
|
61
|
+
rates.rates('IDR')
|
62
|
+
|
63
|
+
# multi exchange rates
|
64
|
+
rates.rates(['IDR', 'USD'])
|
65
|
+
rates.fetch
|
66
|
+
# => {"rates"=>{"USD"=>1.1052, "IDR"=>15091.51}, "base"=>"EUR", "date"=>"2020-01-31"}
|
67
|
+
```
|
68
|
+
|
69
|
+
**Historical rates for a time period**
|
70
|
+
|
71
|
+
```ruby
|
72
|
+
rates.period(date_from: '2018-01-03', date_to: '2018-02-05')
|
73
|
+
rates.fetch
|
74
|
+
```
|
75
|
+
|
76
|
+
**Limit to specific exchange rates**
|
77
|
+
|
78
|
+
```ruby
|
79
|
+
rates.rates(['IDR', 'JPY']).period(date_from: '2018-01-03', date_to: '2018-02-05')
|
80
|
+
rates.fetch
|
81
|
+
```
|
82
|
+
|
83
|
+
**Historical rates with different currency**
|
84
|
+
|
85
|
+
```ruby
|
86
|
+
rates.base_currency('JPY').period(date_from: '2018-01-03', date_to: '2018-02-05')
|
87
|
+
rates.fetch
|
88
|
+
```
|
89
|
+
|
90
|
+
## Supported Currencies
|
91
|
+
|
92
|
+
The library supports any currency currently available on the European Central Bank's web service, please refer to [here](https://www.ecb.europa.eu/stats/policy_and_exchange_rates/euro_reference_exchange_rates/html/index.en.html).
|
93
|
+
|
94
|
+
## Contributing
|
95
|
+
|
96
|
+
1. Fork [the repo](https://github.com/maful/vici-exchange-rates)
|
97
|
+
2. Grab dependencies: `bundle install`
|
98
|
+
3. Make sure everything is working: `bundle exec rake spec`
|
99
|
+
4. Make your changes
|
100
|
+
5. Test your changes
|
101
|
+
5. Create a Pull Request
|
102
|
+
6. Celebrate!!!!!
|
103
|
+
|
104
|
+
This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](http://contributor-covenant.org) code of conduct.
|
105
|
+
|
106
|
+
## Copyright
|
107
|
+
|
108
|
+
Copyright (c) 2020 Maful Prayoga A. See LICENSE for further details.
|
data/Rakefile
ADDED
data/bin/console
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require "bundler/setup"
|
4
|
+
require "vici/exchange_rates"
|
5
|
+
|
6
|
+
# You can add fixtures and/or initialization code here to make experimenting
|
7
|
+
# with your gem easier. You can also use a different console, if you like.
|
8
|
+
|
9
|
+
# (If you use this, don't forget to add pry to your Gemfile!)
|
10
|
+
# require "pry"
|
11
|
+
# Pry.start
|
12
|
+
|
13
|
+
require "irb"
|
14
|
+
IRB.start(__FILE__)
|
data/bin/setup
ADDED
@@ -0,0 +1,136 @@
|
|
1
|
+
require 'active_support/core_ext/object'
|
2
|
+
require 'faraday'
|
3
|
+
require 'json'
|
4
|
+
|
5
|
+
require 'vici/exchange_rates/version'
|
6
|
+
|
7
|
+
module Vici
|
8
|
+
class ExchangeRates
|
9
|
+
class Error < StandardError; end
|
10
|
+
|
11
|
+
BASE_URI = 'https://api.exchangeratesapi.io'.freeze
|
12
|
+
CURRENCIES = %w[USD GBP EUR JPY BGN CZK DKK HUF PLN RON SEK CHF ISK NOK HRK RUB TRY AUD BRL CAD CNY HKD IDR ILS INR KRW MXN MYR NZD BHP SGD THB ZAR].freeze
|
13
|
+
CURRENCY_REGEX = /^[A-Z]{3}$/.freeze
|
14
|
+
DATE_REGEX = /^[0-9]{4}-(0[1-9]|1[0-2])-(0[1-9]|[1-2][0-9]|3[0-1])$/.freeze
|
15
|
+
|
16
|
+
def initialize(json = false)
|
17
|
+
@client = Faraday.new BASE_URI
|
18
|
+
@options = {}
|
19
|
+
@endpoint = 'latest'
|
20
|
+
@rates = []
|
21
|
+
@date = nil
|
22
|
+
@date_from = nil
|
23
|
+
@date_to = nil
|
24
|
+
@base = nil
|
25
|
+
@return_json = json
|
26
|
+
end
|
27
|
+
|
28
|
+
def base_currency(code)
|
29
|
+
currency_code = sanitize_curreny_code(code)
|
30
|
+
verify_currency_code(currency_code)
|
31
|
+
@base = code
|
32
|
+
self
|
33
|
+
end
|
34
|
+
|
35
|
+
def at_date(date)
|
36
|
+
@date = validate_date(date)
|
37
|
+
self
|
38
|
+
end
|
39
|
+
|
40
|
+
def rates(currencies)
|
41
|
+
if currencies.is_a?(Array)
|
42
|
+
currencies.each do |currency|
|
43
|
+
currency_code = sanitize_curreny_code(currency)
|
44
|
+
|
45
|
+
verify_currency_code(currency_code)
|
46
|
+
|
47
|
+
@rates << currency_code
|
48
|
+
end
|
49
|
+
else
|
50
|
+
currency_code = sanitize_curreny_code(currencies)
|
51
|
+
|
52
|
+
verify_currency_code(currency_code)
|
53
|
+
|
54
|
+
@rates << currency_code
|
55
|
+
end
|
56
|
+
self
|
57
|
+
end
|
58
|
+
|
59
|
+
def period(date_from:, date_to:)
|
60
|
+
@date_from = validate_date(date_from)
|
61
|
+
@date_to = validate_date(date_to)
|
62
|
+
self
|
63
|
+
end
|
64
|
+
|
65
|
+
def fetch
|
66
|
+
if @date_from.present? && @date_to.present?
|
67
|
+
@endpoint = 'history'
|
68
|
+
@options.merge!(start_at: @date_from, end_at: @date_to)
|
69
|
+
elsif @date.present?
|
70
|
+
@endpoint = @date
|
71
|
+
else
|
72
|
+
@endpoint
|
73
|
+
end
|
74
|
+
|
75
|
+
@options['base'] = @base if @base.present?
|
76
|
+
|
77
|
+
@options['symbols'] = @rates.join(',') if @rates.length.positive?
|
78
|
+
|
79
|
+
request = @client.get(@endpoint, @options)
|
80
|
+
response = JSON.parse(request.body)
|
81
|
+
|
82
|
+
if @return_json
|
83
|
+
JSON.generate(response)
|
84
|
+
else
|
85
|
+
response
|
86
|
+
end
|
87
|
+
end
|
88
|
+
|
89
|
+
private
|
90
|
+
|
91
|
+
def verify_currency_code(code)
|
92
|
+
currency_code = sanitize_curreny_code(code)
|
93
|
+
|
94
|
+
unless currency_valid?(currency_code)
|
95
|
+
raise 'The specified currency code is invalid. Please use ISO 4217 notation (e.g. IDR).'
|
96
|
+
end
|
97
|
+
|
98
|
+
unless currency_supported?(currency_code)
|
99
|
+
raise 'The specified currency code is not currently supported.'
|
100
|
+
end
|
101
|
+
end
|
102
|
+
|
103
|
+
def currency_valid?(code)
|
104
|
+
if code.present?
|
105
|
+
return false if code.length != 3
|
106
|
+
|
107
|
+
return false unless CURRENCY_REGEX.match?(code)
|
108
|
+
|
109
|
+
return true
|
110
|
+
end
|
111
|
+
false
|
112
|
+
end
|
113
|
+
|
114
|
+
def currency_supported?(code)
|
115
|
+
CURRENCIES.include?(code)
|
116
|
+
end
|
117
|
+
|
118
|
+
def validate_date(date)
|
119
|
+
unless date_valid?(date)
|
120
|
+
raise ArgumentError, 'The specified date is invalid. Please use ISO 8601 notation (e.g. YYYY-MM-DD).'
|
121
|
+
end
|
122
|
+
|
123
|
+
date
|
124
|
+
end
|
125
|
+
|
126
|
+
def date_valid?(date)
|
127
|
+
return DATE_REGEX.match?(date) if date.present?
|
128
|
+
|
129
|
+
false
|
130
|
+
end
|
131
|
+
|
132
|
+
def sanitize_curreny_code(code)
|
133
|
+
code.strip.upcase
|
134
|
+
end
|
135
|
+
end
|
136
|
+
end
|
@@ -0,0 +1,30 @@
|
|
1
|
+
lib = File.expand_path('lib', __dir__)
|
2
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
3
|
+
require 'vici/exchange_rates/version'
|
4
|
+
|
5
|
+
Gem::Specification.new do |spec|
|
6
|
+
spec.name = 'vici-exchange-rates'
|
7
|
+
spec.version = Vici::ExchangeRates::VERSION
|
8
|
+
spec.authors = ['maful']
|
9
|
+
spec.email = ['mafulprayoga@gmail.com']
|
10
|
+
|
11
|
+
spec.summary = %q{A Simple and Rich for Exchange Rates}
|
12
|
+
spec.homepage = 'https://github.com/maful/exchange-rates-exchange-rates'
|
13
|
+
spec.license = 'MIT'
|
14
|
+
|
15
|
+
# Specify which files should be added to the gem when it is released.
|
16
|
+
# The `git ls-files -z` loads the files in the RubyGem that have been added into git.
|
17
|
+
spec.files = Dir.chdir(File.expand_path('..', __FILE__)) do
|
18
|
+
`git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
|
19
|
+
end
|
20
|
+
spec.bindir = 'exe'
|
21
|
+
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
22
|
+
spec.require_paths = ['lib']
|
23
|
+
|
24
|
+
spec.add_dependency 'activesupport', '~> 6.0', '>= 6.0.2.1'
|
25
|
+
spec.add_dependency 'faraday', '~> 1.0'
|
26
|
+
|
27
|
+
spec.add_development_dependency 'bundler', '~> 2.0'
|
28
|
+
spec.add_development_dependency 'rake', '~> 10.0'
|
29
|
+
spec.add_development_dependency 'rspec', '~> 3.0'
|
30
|
+
end
|
metadata
ADDED
@@ -0,0 +1,140 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: vici-exchange-rates
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- maful
|
8
|
+
autorequire:
|
9
|
+
bindir: exe
|
10
|
+
cert_chain: []
|
11
|
+
date: 2020-01-31 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: activesupport
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '6.0'
|
20
|
+
- - ">="
|
21
|
+
- !ruby/object:Gem::Version
|
22
|
+
version: 6.0.2.1
|
23
|
+
type: :runtime
|
24
|
+
prerelease: false
|
25
|
+
version_requirements: !ruby/object:Gem::Requirement
|
26
|
+
requirements:
|
27
|
+
- - "~>"
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
version: '6.0'
|
30
|
+
- - ">="
|
31
|
+
- !ruby/object:Gem::Version
|
32
|
+
version: 6.0.2.1
|
33
|
+
- !ruby/object:Gem::Dependency
|
34
|
+
name: faraday
|
35
|
+
requirement: !ruby/object:Gem::Requirement
|
36
|
+
requirements:
|
37
|
+
- - "~>"
|
38
|
+
- !ruby/object:Gem::Version
|
39
|
+
version: '1.0'
|
40
|
+
type: :runtime
|
41
|
+
prerelease: false
|
42
|
+
version_requirements: !ruby/object:Gem::Requirement
|
43
|
+
requirements:
|
44
|
+
- - "~>"
|
45
|
+
- !ruby/object:Gem::Version
|
46
|
+
version: '1.0'
|
47
|
+
- !ruby/object:Gem::Dependency
|
48
|
+
name: bundler
|
49
|
+
requirement: !ruby/object:Gem::Requirement
|
50
|
+
requirements:
|
51
|
+
- - "~>"
|
52
|
+
- !ruby/object:Gem::Version
|
53
|
+
version: '2.0'
|
54
|
+
type: :development
|
55
|
+
prerelease: false
|
56
|
+
version_requirements: !ruby/object:Gem::Requirement
|
57
|
+
requirements:
|
58
|
+
- - "~>"
|
59
|
+
- !ruby/object:Gem::Version
|
60
|
+
version: '2.0'
|
61
|
+
- !ruby/object:Gem::Dependency
|
62
|
+
name: rake
|
63
|
+
requirement: !ruby/object:Gem::Requirement
|
64
|
+
requirements:
|
65
|
+
- - "~>"
|
66
|
+
- !ruby/object:Gem::Version
|
67
|
+
version: '10.0'
|
68
|
+
type: :development
|
69
|
+
prerelease: false
|
70
|
+
version_requirements: !ruby/object:Gem::Requirement
|
71
|
+
requirements:
|
72
|
+
- - "~>"
|
73
|
+
- !ruby/object:Gem::Version
|
74
|
+
version: '10.0'
|
75
|
+
- !ruby/object:Gem::Dependency
|
76
|
+
name: rspec
|
77
|
+
requirement: !ruby/object:Gem::Requirement
|
78
|
+
requirements:
|
79
|
+
- - "~>"
|
80
|
+
- !ruby/object:Gem::Version
|
81
|
+
version: '3.0'
|
82
|
+
type: :development
|
83
|
+
prerelease: false
|
84
|
+
version_requirements: !ruby/object:Gem::Requirement
|
85
|
+
requirements:
|
86
|
+
- - "~>"
|
87
|
+
- !ruby/object:Gem::Version
|
88
|
+
version: '3.0'
|
89
|
+
description:
|
90
|
+
email:
|
91
|
+
- mafulprayoga@gmail.com
|
92
|
+
executables: []
|
93
|
+
extensions: []
|
94
|
+
extra_rdoc_files: []
|
95
|
+
files:
|
96
|
+
- ".gitignore"
|
97
|
+
- ".idea/.gitignore"
|
98
|
+
- ".idea/.rakeTasks"
|
99
|
+
- ".idea/inspectionProfiles/Project_Default.xml"
|
100
|
+
- ".idea/misc.xml"
|
101
|
+
- ".idea/modules.xml"
|
102
|
+
- ".idea/vcs.xml"
|
103
|
+
- ".idea/vici-exchange_rates.iml"
|
104
|
+
- ".rspec"
|
105
|
+
- ".travis.yml"
|
106
|
+
- CODE_OF_CONDUCT.md
|
107
|
+
- Gemfile
|
108
|
+
- Gemfile.lock
|
109
|
+
- LICENSE.txt
|
110
|
+
- README.md
|
111
|
+
- Rakefile
|
112
|
+
- bin/console
|
113
|
+
- bin/setup
|
114
|
+
- lib/vici/exchange_rates.rb
|
115
|
+
- lib/vici/exchange_rates/version.rb
|
116
|
+
- vici-exchange-rates.gemspec
|
117
|
+
homepage: https://github.com/maful/exchange-rates-exchange-rates
|
118
|
+
licenses:
|
119
|
+
- MIT
|
120
|
+
metadata: {}
|
121
|
+
post_install_message:
|
122
|
+
rdoc_options: []
|
123
|
+
require_paths:
|
124
|
+
- lib
|
125
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
126
|
+
requirements:
|
127
|
+
- - ">="
|
128
|
+
- !ruby/object:Gem::Version
|
129
|
+
version: '0'
|
130
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
131
|
+
requirements:
|
132
|
+
- - ">="
|
133
|
+
- !ruby/object:Gem::Version
|
134
|
+
version: '0'
|
135
|
+
requirements: []
|
136
|
+
rubygems_version: 3.0.3
|
137
|
+
signing_key:
|
138
|
+
specification_version: 4
|
139
|
+
summary: A Simple and Rich for Exchange Rates
|
140
|
+
test_files: []
|