exchangerate-api 0.1.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +9 -0
- data/.rubocop.yml +8 -0
- data/.travis.yml +7 -0
- data/CODE_OF_CONDUCT.md +74 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +21 -0
- data/README.md +58 -0
- data/Rakefile +29 -0
- data/bin/console +14 -0
- data/bin/setup +8 -0
- data/exchangerate-api.gemspec +40 -0
- data/lib/exchangerate_api.rb +37 -0
- data/lib/exchangerate_api/client.rb +71 -0
- data/lib/exchangerate_api/currency_codes.rb +81 -0
- data/lib/exchangerate_api/result.rb +49 -0
- data/lib/exchangerate_api/version.rb +5 -0
- metadata +227 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 82de488cea1f00940f8cca9ac604897f5c2f3ade764239aad2549cbfbd0b2777
|
4
|
+
data.tar.gz: 9117c2a2140450a8ecf29b95acde9c34697230e856d4e061957bf917c5614c55
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 2cc23e4066abc5cabc92e10e9336c08442cc2a64d03ca40ee5616e488b4f5120e2c0adf24701da1d0fd3593996de9a9f217574731ffc37c76708460ca49f3bac
|
7
|
+
data.tar.gz: 220d571ca819c709c99f975a1a5f517865dd78bab19fff72aaa17fc1e2e0203ccbfd346fe9fa4cf5c9463511caa8db7ad34537713f5e322074441d56500ac8ee
|
data/.gitignore
ADDED
data/.rubocop.yml
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 jirenpatel@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/LICENSE.txt
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2019 Jiren Patel
|
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,58 @@
|
|
1
|
+
# Exchangerate::Api
|
2
|
+
|
3
|
+
API client for [Exchangerate](https://www.exchangerate-api.com)
|
4
|
+
|
5
|
+
## Installation
|
6
|
+
|
7
|
+
Add this line to your application's Gemfile:
|
8
|
+
|
9
|
+
```ruby
|
10
|
+
gem 'exchangerate-api'
|
11
|
+
```
|
12
|
+
|
13
|
+
And then execute:
|
14
|
+
|
15
|
+
$ bundle
|
16
|
+
|
17
|
+
Or install it yourself as:
|
18
|
+
|
19
|
+
$ gem install exchangerate-api
|
20
|
+
|
21
|
+
## Usage
|
22
|
+
|
23
|
+
```ruby
|
24
|
+
require "exchagerate_api"
|
25
|
+
|
26
|
+
client = ExchangerateApi.new
|
27
|
+
|
28
|
+
result = client.rates_for('USD')
|
29
|
+
result.currency_code # "USD"
|
30
|
+
result.date # 2018-12-31 18:30:00 UTC
|
31
|
+
result.updated_at # 2019-10-15 02:01:16 UTC
|
32
|
+
result['EUR'] # 1.1
|
33
|
+
|
34
|
+
result = client.rates_for('EUR')
|
35
|
+
result.each do |currency_code, exchange_rate|
|
36
|
+
p "#{currency_code} - #{exchange_rate}"
|
37
|
+
end
|
38
|
+
|
39
|
+
client.currency_codes # ['USD', 'EUR', ....]
|
40
|
+
```
|
41
|
+
|
42
|
+
## Development
|
43
|
+
|
44
|
+
After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake test` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
|
45
|
+
|
46
|
+
To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
|
47
|
+
|
48
|
+
## Contributing
|
49
|
+
|
50
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/exchangerate-api. 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.
|
51
|
+
|
52
|
+
## License
|
53
|
+
|
54
|
+
The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
|
55
|
+
|
56
|
+
## Code of Conduct
|
57
|
+
|
58
|
+
Everyone interacting in the Exchangerate::Api project’s codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/[USERNAME]/exchangerate-api/blob/master/CODE_OF_CONDUCT.md).
|
data/Rakefile
ADDED
@@ -0,0 +1,29 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'bundler/setup'
|
4
|
+
require 'bundler/gem_tasks'
|
5
|
+
require 'rake/testtask'
|
6
|
+
require 'rubocop/rake_task'
|
7
|
+
RuboCop::RakeTask.new
|
8
|
+
|
9
|
+
Rake::TestTask.new(:test) do |t|
|
10
|
+
t.libs << 'test'
|
11
|
+
t.libs << 'lib'
|
12
|
+
t.test_files = FileList['test/**/*_test.rb']
|
13
|
+
end
|
14
|
+
|
15
|
+
desc 'Start an interactive shell.'
|
16
|
+
task :console do
|
17
|
+
require 'irb'
|
18
|
+
require 'irb/completion'
|
19
|
+
require 'pp'
|
20
|
+
|
21
|
+
$LOAD_PATH.unshift 'lib'
|
22
|
+
|
23
|
+
require 'exchangerate_api'
|
24
|
+
|
25
|
+
ARGV.clear
|
26
|
+
IRB.start
|
27
|
+
end
|
28
|
+
|
29
|
+
task default: :test
|
data/bin/console
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require "bundler/setup"
|
4
|
+
require "exchangerate/api"
|
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,40 @@
|
|
1
|
+
|
2
|
+
lib = File.expand_path("../lib", __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require "exchangerate_api/version"
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "exchangerate-api"
|
8
|
+
spec.version = ExchangerateApi::VERSION
|
9
|
+
spec.authors = ["Jiren Patel"]
|
10
|
+
spec.email = ["jiren@eloquent.studio"]
|
11
|
+
|
12
|
+
spec.summary = "Currency Exchange Rates API Client"
|
13
|
+
spec.description = "Currencies Exchange rates api client"
|
14
|
+
spec.homepage = "https://github.com/EloquentStudio/exchangerate-api-ruby"
|
15
|
+
spec.license = "MIT"
|
16
|
+
|
17
|
+
# Specify which files should be added to the gem when it is released.
|
18
|
+
# The `git ls-files -z` loads the files in the RubyGem that have been added into git.
|
19
|
+
spec.files = Dir.chdir(File.expand_path('..', __FILE__)) do
|
20
|
+
`git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
|
21
|
+
end
|
22
|
+
spec.bindir = "exe"
|
23
|
+
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
24
|
+
spec.require_paths = ["lib"]
|
25
|
+
|
26
|
+
|
27
|
+
spec.add_dependency "json", "~> 2.2"
|
28
|
+
spec.add_dependency "faraday", "~> 0.17.0"
|
29
|
+
spec.add_dependency "faraday_middleware", "~> 0.13.1"
|
30
|
+
|
31
|
+
spec.add_development_dependency "bundler", "~> 2.0"
|
32
|
+
spec.add_development_dependency "rake", "~> 10.0"
|
33
|
+
spec.add_development_dependency "minitest", "~> 5.12.2"
|
34
|
+
spec.add_development_dependency "minitest-focus", "~> 1.1.2"
|
35
|
+
spec.add_development_dependency "minitest-rg", "~> 5.2"
|
36
|
+
spec.add_development_dependency "rubocop", "~> 0.75.0"
|
37
|
+
spec.add_development_dependency "simplecov", "~> 0.17.1"
|
38
|
+
spec.add_development_dependency "simplecov-console", "~> 0.4.1"
|
39
|
+
spec.add_development_dependency "yard", "~> 0.9.20"
|
40
|
+
end
|
@@ -0,0 +1,37 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'exchangerate_api/version'
|
4
|
+
require 'exchangerate_api/client'
|
5
|
+
|
6
|
+
# # Exchangerate
|
7
|
+
#
|
8
|
+
module ExchangerateApi
|
9
|
+
# Exchangerate api standered error.
|
10
|
+
class Error < StandardError; end
|
11
|
+
|
12
|
+
# Create instance of API client.
|
13
|
+
#
|
14
|
+
# @return [Exchangerate::API]
|
15
|
+
#
|
16
|
+
# @example
|
17
|
+
# require "exchagerate_api"
|
18
|
+
#
|
19
|
+
# client = ExchangerateApi.new
|
20
|
+
#
|
21
|
+
# result = client.rates_for('USD')
|
22
|
+
# result.currency_code # "USD"
|
23
|
+
# result.date # 2018-12-31 18:30:00 UTC
|
24
|
+
# result.updated_at # 2019-10-15 02:01:16 UTC
|
25
|
+
# result['EUR'] # 1.1
|
26
|
+
#
|
27
|
+
# result = client.rates_for('EUR')
|
28
|
+
# result.each do |currency_code, exchange_rate|
|
29
|
+
# p "#{currency_code} - #{exchange_rate}"
|
30
|
+
# end
|
31
|
+
#
|
32
|
+
# client.currency_codes # ['USD', 'EUR', ....]
|
33
|
+
#
|
34
|
+
def self.new
|
35
|
+
Client.new
|
36
|
+
end
|
37
|
+
end
|
@@ -0,0 +1,71 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'faraday'
|
4
|
+
require 'faraday_middleware'
|
5
|
+
require 'exchangerate_api/result'
|
6
|
+
require 'exchangerate_api/currency_codes'
|
7
|
+
|
8
|
+
module ExchangerateApi
|
9
|
+
##
|
10
|
+
# # Client
|
11
|
+
#
|
12
|
+
# Client to fetch currency exchange rate data.
|
13
|
+
#
|
14
|
+
# @example
|
15
|
+
# require "exchagerate_api"
|
16
|
+
#
|
17
|
+
# client = ExchangerateApi::Client.new
|
18
|
+
#
|
19
|
+
# client.rates_for('USD')
|
20
|
+
#
|
21
|
+
# client.rates_for('EUR')
|
22
|
+
#
|
23
|
+
class Client
|
24
|
+
# Address of the exchagerate api service.
|
25
|
+
SERVICE_ADDRESS = 'https://api.exchangerate-api.com'
|
26
|
+
|
27
|
+
# @return [String] Exchangerate api version.
|
28
|
+
attr_reader :version
|
29
|
+
|
30
|
+
# Creates a new Client instance.
|
31
|
+
#
|
32
|
+
# @param version [String] Version of the api. Default value is `v4`
|
33
|
+
def initialize(version: 'v4')
|
34
|
+
@version = version
|
35
|
+
@connection = Faraday.new(url: SERVICE_ADDRESS) do |conn|
|
36
|
+
conn.response :json
|
37
|
+
conn.adapter Faraday.default_adapter
|
38
|
+
end
|
39
|
+
end
|
40
|
+
|
41
|
+
# Fetch exchage rate data by currency code
|
42
|
+
#
|
43
|
+
# @param currency_code [String] ISO format currency code.
|
44
|
+
# Supported currency codes are.
|
45
|
+
# @raise [ExchangerateApi::Error] if invalid currency code or
|
46
|
+
# other api errors.
|
47
|
+
# @return [ExchangerateApi::Result] Exchange rate data.
|
48
|
+
#
|
49
|
+
def rates_for(currency_code)
|
50
|
+
resp = @connection.get("/#{version}/latest/#{currency_code}")
|
51
|
+
|
52
|
+
return Result.new(resp.body) if resp.status == 200
|
53
|
+
|
54
|
+
raise ExchangerateApi::Error.new(status: resp.status, message: resp.body)
|
55
|
+
end
|
56
|
+
|
57
|
+
# List all supported currency codes with countries
|
58
|
+
#
|
59
|
+
# @return [Hash] List of currency codes {CurrencyCodes::CODES}
|
60
|
+
def currency_codes
|
61
|
+
CurrencyCodes::CODES
|
62
|
+
end
|
63
|
+
|
64
|
+
# Get exchage rate for usd
|
65
|
+
#
|
66
|
+
# @return [ExchangerateApi::Result] Exchange rate data.
|
67
|
+
def rates_for_usd
|
68
|
+
rates_for 'USD'
|
69
|
+
end
|
70
|
+
end
|
71
|
+
end
|
@@ -0,0 +1,81 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module ExchangerateApi
|
4
|
+
module CurrencyCodes
|
5
|
+
# Currency codes with full name and supported countries
|
6
|
+
CODES = {
|
7
|
+
'AED' => { name: 'UAE Dirham', countries: ['United Arab Emirates'] },
|
8
|
+
'ARS' => { name: 'Argentine Peso', countries: ['Argentina'] },
|
9
|
+
'AUD' => { name: 'Australian Dollar', countries: ['Australia'] },
|
10
|
+
'BGN' => { name: 'Bulgarian Lev', countries: ['Bulgaria'] },
|
11
|
+
'BRL' => { name: 'Brazilian Real', countries: ['Brazil'] },
|
12
|
+
'BSD' => { name: 'Bahamian Dollar', countries: ['Bahamas'] },
|
13
|
+
'CAD' => { name: 'Canadian Dollar', countries: ['Canada'] },
|
14
|
+
'CHF' => { name: 'Swiss Franc', countries: ['Switzerland'] },
|
15
|
+
'CLP' => { name: 'Chilean Peso', countries: ['Chile'] },
|
16
|
+
'CNY' => { name: 'Chinese Renminbi', countries: ['China'] },
|
17
|
+
'COP' => { name: 'Colombian Peso', countries: ['Colombia'] },
|
18
|
+
'CZK' => { name: 'Czech Koruna', countries: ['Czech Republic'] },
|
19
|
+
'DKK' => { name: 'Danish Krone', countries: ['Denmark'] },
|
20
|
+
'DOP' => { name: 'Dominican Peso', countries: ['Dominican Republic'] },
|
21
|
+
'EGP' => { name: 'Egyptian Pound', countries: ['Egypt'] },
|
22
|
+
'EUR' =>
|
23
|
+
{ name: 'Euro',
|
24
|
+
countries: %w[Germany
|
25
|
+
Austria
|
26
|
+
Belgium
|
27
|
+
Cyprus
|
28
|
+
Estonia
|
29
|
+
Finland
|
30
|
+
France
|
31
|
+
Greece
|
32
|
+
Ireland
|
33
|
+
Italy
|
34
|
+
Latvia
|
35
|
+
Lithuania
|
36
|
+
Luxembourg
|
37
|
+
Malta
|
38
|
+
Netherlands
|
39
|
+
Portugal
|
40
|
+
Slovakia
|
41
|
+
Slovenia
|
42
|
+
Spain] },
|
43
|
+
'FJD' => { name: 'Fiji Dollar', countries: ['Fiji'] },
|
44
|
+
'GBP' => { name: 'Pound Sterling', countries: ['United Kingdom'] },
|
45
|
+
'GTQ' => { name: 'Guatemalan Quetzal', countries: ['Guatemala'] },
|
46
|
+
'HKD' => { name: 'Hong Kong Dollar', countries: ['Hong Kong'] },
|
47
|
+
'HRK' => { name: 'Croatian Kuna', countries: ['Croatian'] },
|
48
|
+
'HUF' => { name: 'Hungarian Forint', countries: ['Hungary'] },
|
49
|
+
'IDR' => { name: 'Indonesian Rupiah', countries: ['Indonesia'] },
|
50
|
+
'ILS' => { name: 'Israeli Shekel', countries: ['Israel'] },
|
51
|
+
'INR' => { name: 'Indian Rupee', countries: ['India'] },
|
52
|
+
'ISK' => { name: 'Icelandic Krona', countries: ['Iceland'] },
|
53
|
+
'JPY' => { name: 'Japanese Yen', countries: ['Japan'] },
|
54
|
+
'KRW' => { name: 'South Korean Won', countries: ['Korea'] },
|
55
|
+
'KZT' => { name: 'Kazakhstani Tenge', countries: ['Kazakhstan'] },
|
56
|
+
'MXN' => { name: 'Mexican Peso', countries: ['Mexico'] },
|
57
|
+
'MYR' => { name: 'Malaysian Ringgit', countries: ['Malaysia'] },
|
58
|
+
'NOK' => { name: 'Norwegian Krone', countries: ['Norway'] },
|
59
|
+
'NZD' => { name: 'New Zealand Dollar', countries: ['New Zealand'] },
|
60
|
+
'PAB' => { name: 'Panamanian Balboa', countries: ['Panama'] },
|
61
|
+
'PEN' => { name: 'Peruvian Nuevo Sol', countries: ['Peru'] },
|
62
|
+
'PHP' => { name: 'Philippine Peso', countries: ['Philippines'] },
|
63
|
+
'PKR' => { name: 'Pakistani Rupee', countries: ['Pakistan'] },
|
64
|
+
'PLN' => { name: 'Polish Zloty', countries: ['Poland'] },
|
65
|
+
'PYG' => { name: 'Paraguayan Guarani', countries: ['Paraguay'] },
|
66
|
+
'RON' => { name: 'Romanian Leu', countries: ['Romania'] },
|
67
|
+
'RUB' => { name: 'Russian Ruble', countries: ['Russian Federation'] },
|
68
|
+
'SAR' => { name: 'Saudi Riyal', countries: ['Saudi Arabia'] },
|
69
|
+
'SEK' => { name: 'Swedish Krona', countries: ['Sweden'] },
|
70
|
+
'SGD' => { name: 'Singapore Dollar', countries: ['Singapore'] },
|
71
|
+
'THB' => { name: 'Thai Baht', countries: ['Thailand'] },
|
72
|
+
'TRY' => { name: 'Turkish Lira', countries: ['Turkey'] },
|
73
|
+
'TWD' => { name: 'New Taiwan Dollar', countries: ['Taiwan'] },
|
74
|
+
'UAH' => { name: 'Ukrainian Hryvnia', countries: ['Ukraine'] },
|
75
|
+
'USD' => { name: 'US Dollar', countries: ['United States'] },
|
76
|
+
'UYU' => { name: 'Uruguayan Peso', countries: ['Uruguay'] },
|
77
|
+
'VND' => { name: 'Vietnamese Dong', countries: ['Vietnam'] },
|
78
|
+
'ZAR' => { name: 'South African Rand', countries: ['South Africa'] }
|
79
|
+
}.freeze
|
80
|
+
end
|
81
|
+
end
|
@@ -0,0 +1,49 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'forwardable'
|
4
|
+
|
5
|
+
module ExchangerateApi
|
6
|
+
# # Result
|
7
|
+
#
|
8
|
+
# Exchange rate response data wrapper.
|
9
|
+
#
|
10
|
+
class Result
|
11
|
+
extend Forwardable
|
12
|
+
|
13
|
+
def_delegators :@rates, :each, :map, :length
|
14
|
+
|
15
|
+
# @return [String] ISO format currency code.
|
16
|
+
attr_reader :currency_code
|
17
|
+
|
18
|
+
# @return [Time] Exchange rate updated date.
|
19
|
+
attr_reader :date
|
20
|
+
|
21
|
+
# @return [Time] Exchange rate updated timestamp.
|
22
|
+
attr_reader :updated_at
|
23
|
+
|
24
|
+
# @return [Hash<String,Float>] Exchange rate data by currency.
|
25
|
+
attr_reader :rates
|
26
|
+
|
27
|
+
# @private
|
28
|
+
def initialize(data)
|
29
|
+
@currency_code = data['base']
|
30
|
+
@date = Time.new(data['date']).utc
|
31
|
+
@updated_at = Time.at(data['time_last_updated']).utc
|
32
|
+
@rates = data['rates']
|
33
|
+
end
|
34
|
+
|
35
|
+
# Get exchage rate by currency code.
|
36
|
+
#
|
37
|
+
# @return [Float,nil] Exchange value
|
38
|
+
def [](currency_code)
|
39
|
+
@rates[currency_code]
|
40
|
+
end
|
41
|
+
|
42
|
+
# List of currency codes
|
43
|
+
#
|
44
|
+
# @return [Array<String>]
|
45
|
+
def currency_codes
|
46
|
+
@rates.keys
|
47
|
+
end
|
48
|
+
end
|
49
|
+
end
|
metadata
ADDED
@@ -0,0 +1,227 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: exchangerate-api
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.2
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Jiren Patel
|
8
|
+
autorequire:
|
9
|
+
bindir: exe
|
10
|
+
cert_chain: []
|
11
|
+
date: 2019-10-15 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: json
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '2.2'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '2.2'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: faraday
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: 0.17.0
|
34
|
+
type: :runtime
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: 0.17.0
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: faraday_middleware
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: 0.13.1
|
48
|
+
type: :runtime
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: 0.13.1
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: bundler
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - "~>"
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '2.0'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - "~>"
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '2.0'
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: rake
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - "~>"
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '10.0'
|
76
|
+
type: :development
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - "~>"
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '10.0'
|
83
|
+
- !ruby/object:Gem::Dependency
|
84
|
+
name: minitest
|
85
|
+
requirement: !ruby/object:Gem::Requirement
|
86
|
+
requirements:
|
87
|
+
- - "~>"
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: 5.12.2
|
90
|
+
type: :development
|
91
|
+
prerelease: false
|
92
|
+
version_requirements: !ruby/object:Gem::Requirement
|
93
|
+
requirements:
|
94
|
+
- - "~>"
|
95
|
+
- !ruby/object:Gem::Version
|
96
|
+
version: 5.12.2
|
97
|
+
- !ruby/object:Gem::Dependency
|
98
|
+
name: minitest-focus
|
99
|
+
requirement: !ruby/object:Gem::Requirement
|
100
|
+
requirements:
|
101
|
+
- - "~>"
|
102
|
+
- !ruby/object:Gem::Version
|
103
|
+
version: 1.1.2
|
104
|
+
type: :development
|
105
|
+
prerelease: false
|
106
|
+
version_requirements: !ruby/object:Gem::Requirement
|
107
|
+
requirements:
|
108
|
+
- - "~>"
|
109
|
+
- !ruby/object:Gem::Version
|
110
|
+
version: 1.1.2
|
111
|
+
- !ruby/object:Gem::Dependency
|
112
|
+
name: minitest-rg
|
113
|
+
requirement: !ruby/object:Gem::Requirement
|
114
|
+
requirements:
|
115
|
+
- - "~>"
|
116
|
+
- !ruby/object:Gem::Version
|
117
|
+
version: '5.2'
|
118
|
+
type: :development
|
119
|
+
prerelease: false
|
120
|
+
version_requirements: !ruby/object:Gem::Requirement
|
121
|
+
requirements:
|
122
|
+
- - "~>"
|
123
|
+
- !ruby/object:Gem::Version
|
124
|
+
version: '5.2'
|
125
|
+
- !ruby/object:Gem::Dependency
|
126
|
+
name: rubocop
|
127
|
+
requirement: !ruby/object:Gem::Requirement
|
128
|
+
requirements:
|
129
|
+
- - "~>"
|
130
|
+
- !ruby/object:Gem::Version
|
131
|
+
version: 0.75.0
|
132
|
+
type: :development
|
133
|
+
prerelease: false
|
134
|
+
version_requirements: !ruby/object:Gem::Requirement
|
135
|
+
requirements:
|
136
|
+
- - "~>"
|
137
|
+
- !ruby/object:Gem::Version
|
138
|
+
version: 0.75.0
|
139
|
+
- !ruby/object:Gem::Dependency
|
140
|
+
name: simplecov
|
141
|
+
requirement: !ruby/object:Gem::Requirement
|
142
|
+
requirements:
|
143
|
+
- - "~>"
|
144
|
+
- !ruby/object:Gem::Version
|
145
|
+
version: 0.17.1
|
146
|
+
type: :development
|
147
|
+
prerelease: false
|
148
|
+
version_requirements: !ruby/object:Gem::Requirement
|
149
|
+
requirements:
|
150
|
+
- - "~>"
|
151
|
+
- !ruby/object:Gem::Version
|
152
|
+
version: 0.17.1
|
153
|
+
- !ruby/object:Gem::Dependency
|
154
|
+
name: simplecov-console
|
155
|
+
requirement: !ruby/object:Gem::Requirement
|
156
|
+
requirements:
|
157
|
+
- - "~>"
|
158
|
+
- !ruby/object:Gem::Version
|
159
|
+
version: 0.4.1
|
160
|
+
type: :development
|
161
|
+
prerelease: false
|
162
|
+
version_requirements: !ruby/object:Gem::Requirement
|
163
|
+
requirements:
|
164
|
+
- - "~>"
|
165
|
+
- !ruby/object:Gem::Version
|
166
|
+
version: 0.4.1
|
167
|
+
- !ruby/object:Gem::Dependency
|
168
|
+
name: yard
|
169
|
+
requirement: !ruby/object:Gem::Requirement
|
170
|
+
requirements:
|
171
|
+
- - "~>"
|
172
|
+
- !ruby/object:Gem::Version
|
173
|
+
version: 0.9.20
|
174
|
+
type: :development
|
175
|
+
prerelease: false
|
176
|
+
version_requirements: !ruby/object:Gem::Requirement
|
177
|
+
requirements:
|
178
|
+
- - "~>"
|
179
|
+
- !ruby/object:Gem::Version
|
180
|
+
version: 0.9.20
|
181
|
+
description: Currencies Exchange rates api client
|
182
|
+
email:
|
183
|
+
- jiren@eloquent.studio
|
184
|
+
executables: []
|
185
|
+
extensions: []
|
186
|
+
extra_rdoc_files: []
|
187
|
+
files:
|
188
|
+
- ".gitignore"
|
189
|
+
- ".rubocop.yml"
|
190
|
+
- ".travis.yml"
|
191
|
+
- CODE_OF_CONDUCT.md
|
192
|
+
- Gemfile
|
193
|
+
- LICENSE.txt
|
194
|
+
- README.md
|
195
|
+
- Rakefile
|
196
|
+
- bin/console
|
197
|
+
- bin/setup
|
198
|
+
- exchangerate-api.gemspec
|
199
|
+
- lib/exchangerate_api.rb
|
200
|
+
- lib/exchangerate_api/client.rb
|
201
|
+
- lib/exchangerate_api/currency_codes.rb
|
202
|
+
- lib/exchangerate_api/result.rb
|
203
|
+
- lib/exchangerate_api/version.rb
|
204
|
+
homepage: https://github.com/EloquentStudio/exchangerate-api-ruby
|
205
|
+
licenses:
|
206
|
+
- MIT
|
207
|
+
metadata: {}
|
208
|
+
post_install_message:
|
209
|
+
rdoc_options: []
|
210
|
+
require_paths:
|
211
|
+
- lib
|
212
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
213
|
+
requirements:
|
214
|
+
- - ">="
|
215
|
+
- !ruby/object:Gem::Version
|
216
|
+
version: '0'
|
217
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
218
|
+
requirements:
|
219
|
+
- - ">="
|
220
|
+
- !ruby/object:Gem::Version
|
221
|
+
version: '0'
|
222
|
+
requirements: []
|
223
|
+
rubygems_version: 3.0.3
|
224
|
+
signing_key:
|
225
|
+
specification_version: 4
|
226
|
+
summary: Currency Exchange Rates API Client
|
227
|
+
test_files: []
|