currency-conversion-api 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: a416646772ec40e84164b770ccad763eff33af9b132ee39f296a8250067c231f
4
+ data.tar.gz: ad67eb5929113e3e0fc8ef1efe7856f50712dc65521dfabf5aa399cbaeb11da3
5
+ SHA512:
6
+ metadata.gz: 364d472489edae1e00a4ba1454954ac74801dd7d86f57dd5e0a76a208c23d33db851be294b9ffb464305291416f3d2ce2cf31cb822e4c9582929e1dba9e88382
7
+ data.tar.gz: 941b99026d54cf00b433862f3cec958a91037714475f14668464796f4a24202ace3d1624bd1d4536d6555d478f2b23bfdcc12400745bf24d17748e1c99db9171
data/.rubocop.yml ADDED
@@ -0,0 +1,17 @@
1
+ require:
2
+ - rubocop-rspec
3
+
4
+ AllCops:
5
+ NewCops: enable
6
+
7
+ Layout/LineLength:
8
+ Max: 120
9
+
10
+ Style/FetchEnvVar:
11
+ Enabled: false
12
+
13
+ RSpec/FilePath:
14
+ Enabled: false
15
+
16
+ Naming/FileName:
17
+ Enabled: false
data/CHANGELOG.md ADDED
@@ -0,0 +1,5 @@
1
+ ## [Unreleased]
2
+
3
+ ## [0.1.0] - 2022-10-09
4
+
5
+ - Initial release
@@ -0,0 +1,84 @@
1
+ # Contributor Covenant Code of Conduct
2
+
3
+ ## Our Pledge
4
+
5
+ We as members, contributors, and leaders pledge to make participation in our community a harassment-free experience for everyone, regardless of age, body size, visible or invisible disability, ethnicity, sex characteristics, gender identity and expression, level of experience, education, socio-economic status, nationality, personal appearance, race, religion, or sexual identity and orientation.
6
+
7
+ We pledge to act and interact in ways that contribute to an open, welcoming, diverse, inclusive, and healthy community.
8
+
9
+ ## Our Standards
10
+
11
+ Examples of behavior that contributes to a positive environment for our community include:
12
+
13
+ * Demonstrating empathy and kindness toward other people
14
+ * Being respectful of differing opinions, viewpoints, and experiences
15
+ * Giving and gracefully accepting constructive feedback
16
+ * Accepting responsibility and apologizing to those affected by our mistakes, and learning from the experience
17
+ * Focusing on what is best not just for us as individuals, but for the overall community
18
+
19
+ Examples of unacceptable behavior include:
20
+
21
+ * The use of sexualized language or imagery, and sexual attention or
22
+ advances of any kind
23
+ * Trolling, insulting or derogatory comments, and personal or political attacks
24
+ * Public or private harassment
25
+ * Publishing others' private information, such as a physical or email
26
+ address, without their explicit permission
27
+ * Other conduct which could reasonably be considered inappropriate in a
28
+ professional setting
29
+
30
+ ## Enforcement Responsibilities
31
+
32
+ Community leaders are responsible for clarifying and enforcing our standards of acceptable behavior and will take appropriate and fair corrective action in response to any behavior that they deem inappropriate, threatening, offensive, or harmful.
33
+
34
+ Community leaders have the right and responsibility to remove, edit, or reject comments, commits, code, wiki edits, issues, and other contributions that are not aligned to this Code of Conduct, and will communicate reasons for moderation decisions when appropriate.
35
+
36
+ ## Scope
37
+
38
+ This Code of Conduct applies within all community spaces, and also applies when an individual is officially representing the community in public spaces. Examples of representing our community include using an official e-mail address, posting via an official social media account, or acting as an appointed representative at an online or offline event.
39
+
40
+ ## Enforcement
41
+
42
+ Instances of abusive, harassing, or otherwise unacceptable behavior may be reported to the community leaders responsible for enforcement at mafulprayoga@gmail.com. All complaints will be reviewed and investigated promptly and fairly.
43
+
44
+ All community leaders are obligated to respect the privacy and security of the reporter of any incident.
45
+
46
+ ## Enforcement Guidelines
47
+
48
+ Community leaders will follow these Community Impact Guidelines in determining the consequences for any action they deem in violation of this Code of Conduct:
49
+
50
+ ### 1. Correction
51
+
52
+ **Community Impact**: Use of inappropriate language or other behavior deemed unprofessional or unwelcome in the community.
53
+
54
+ **Consequence**: A private, written warning from community leaders, providing clarity around the nature of the violation and an explanation of why the behavior was inappropriate. A public apology may be requested.
55
+
56
+ ### 2. Warning
57
+
58
+ **Community Impact**: A violation through a single incident or series of actions.
59
+
60
+ **Consequence**: A warning with consequences for continued behavior. No interaction with the people involved, including unsolicited interaction with those enforcing the Code of Conduct, for a specified period of time. This includes avoiding interactions in community spaces as well as external channels like social media. Violating these terms may lead to a temporary or permanent ban.
61
+
62
+ ### 3. Temporary Ban
63
+
64
+ **Community Impact**: A serious violation of community standards, including sustained inappropriate behavior.
65
+
66
+ **Consequence**: A temporary ban from any sort of interaction or public communication with the community for a specified period of time. No public or private interaction with the people involved, including unsolicited interaction with those enforcing the Code of Conduct, is allowed during this period. Violating these terms may lead to a permanent ban.
67
+
68
+ ### 4. Permanent Ban
69
+
70
+ **Community Impact**: Demonstrating a pattern of violation of community standards, including sustained inappropriate behavior, harassment of an individual, or aggression toward or disparagement of classes of individuals.
71
+
72
+ **Consequence**: A permanent ban from any sort of public interaction within the community.
73
+
74
+ ## Attribution
75
+
76
+ This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 2.0,
77
+ available at https://www.contributor-covenant.org/version/2/0/code_of_conduct.html.
78
+
79
+ Community Impact Guidelines were inspired by [Mozilla's code of conduct enforcement ladder](https://github.com/mozilla/diversity).
80
+
81
+ [homepage]: https://www.contributor-covenant.org
82
+
83
+ For answers to common questions about this code of conduct, see the FAQ at
84
+ https://www.contributor-covenant.org/faq. Translations are available at https://www.contributor-covenant.org/translations.
data/Gemfile ADDED
@@ -0,0 +1,13 @@
1
+ # frozen_string_literal: true
2
+
3
+ source 'https://rubygems.org'
4
+
5
+ # Specify your gem's dependencies in currency-conversion.gemspec
6
+ gemspec
7
+
8
+ gem 'rake', '~> 13.0'
9
+ gem 'rspec', '~> 3.11'
10
+ gem 'rubocop', '~> 1.36', require: false
11
+ gem 'rubocop-rspec', '~> 2.13', require: false
12
+ gem 'vcr', '~> 6.1'
13
+ gem 'byebug', '~> 11.1'
data/Gemfile.lock ADDED
@@ -0,0 +1,85 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ currency-conversion-api (0.1.0)
5
+ activesupport (~> 6.1)
6
+ faraday (~> 2.6)
7
+
8
+ GEM
9
+ remote: https://rubygems.org/
10
+ specs:
11
+ activesupport (6.1.7)
12
+ concurrent-ruby (~> 1.0, >= 1.0.2)
13
+ i18n (>= 1.6, < 2)
14
+ minitest (>= 5.1)
15
+ tzinfo (~> 2.0)
16
+ zeitwerk (~> 2.3)
17
+ ast (2.4.2)
18
+ byebug (11.1.3)
19
+ concurrent-ruby (1.1.10)
20
+ diff-lcs (1.5.0)
21
+ faraday (2.6.0)
22
+ faraday-net_http (>= 2.0, < 3.1)
23
+ ruby2_keywords (>= 0.0.4)
24
+ faraday-net_http (3.0.1)
25
+ i18n (1.12.0)
26
+ concurrent-ruby (~> 1.0)
27
+ json (2.6.2)
28
+ minitest (5.16.3)
29
+ parallel (1.22.1)
30
+ parser (3.1.2.1)
31
+ ast (~> 2.4.1)
32
+ rainbow (3.1.1)
33
+ rake (13.0.6)
34
+ regexp_parser (2.6.0)
35
+ rexml (3.2.5)
36
+ rspec (3.11.0)
37
+ rspec-core (~> 3.11.0)
38
+ rspec-expectations (~> 3.11.0)
39
+ rspec-mocks (~> 3.11.0)
40
+ rspec-core (3.11.0)
41
+ rspec-support (~> 3.11.0)
42
+ rspec-expectations (3.11.1)
43
+ diff-lcs (>= 1.2.0, < 2.0)
44
+ rspec-support (~> 3.11.0)
45
+ rspec-mocks (3.11.1)
46
+ diff-lcs (>= 1.2.0, < 2.0)
47
+ rspec-support (~> 3.11.0)
48
+ rspec-support (3.11.1)
49
+ rubocop (1.36.0)
50
+ json (~> 2.3)
51
+ parallel (~> 1.10)
52
+ parser (>= 3.1.2.1)
53
+ rainbow (>= 2.2.2, < 4.0)
54
+ regexp_parser (>= 1.8, < 3.0)
55
+ rexml (>= 3.2.5, < 4.0)
56
+ rubocop-ast (>= 1.20.1, < 2.0)
57
+ ruby-progressbar (~> 1.7)
58
+ unicode-display_width (>= 1.4.0, < 3.0)
59
+ rubocop-ast (1.21.0)
60
+ parser (>= 3.1.1.0)
61
+ rubocop-rspec (2.13.2)
62
+ rubocop (~> 1.33)
63
+ ruby-progressbar (1.11.0)
64
+ ruby2_keywords (0.0.5)
65
+ tzinfo (2.0.5)
66
+ concurrent-ruby (~> 1.0)
67
+ unicode-display_width (2.3.0)
68
+ vcr (6.1.0)
69
+ zeitwerk (2.6.1)
70
+
71
+ PLATFORMS
72
+ arm64-darwin-21
73
+ x86_64-linux
74
+
75
+ DEPENDENCIES
76
+ byebug (~> 11.1)
77
+ currency-conversion-api!
78
+ rake (~> 13.0)
79
+ rspec (~> 3.11)
80
+ rubocop (~> 1.36)
81
+ rubocop-rspec (~> 2.13)
82
+ vcr (~> 6.1)
83
+
84
+ BUNDLED WITH
85
+ 2.3.7
data/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2022 Maful Prayoga
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 all
13
+ 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 THE
21
+ SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,105 @@
1
+ # CurrencyAPI
2
+
3
+ [![Test](https://github.com/maful/currency-conversion-ruby/actions/workflows/test.yml/badge.svg?branch=main)](https://github.com/maful/currency-conversion-ruby/actions/workflows/test.yml)
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ ```ruby
10
+ gem 'currency-conversion'
11
+ ```
12
+
13
+ And then execute:
14
+
15
+ $ bundle install
16
+
17
+ Or install it yourself as:
18
+
19
+ $ gem install currency-conversion
20
+
21
+ ## Usage
22
+
23
+ Create a new client, grab the API key on [Currency Conversion API](https://currencyapi.com/) website.
24
+
25
+ ```ruby
26
+ client = CurrencyConversion::Client.new(api_key: ENV['API_KEY'])
27
+ ```
28
+
29
+ ## Endpoints
30
+
31
+ ### Status
32
+
33
+ ```ruby
34
+ response = client.status.retrieve
35
+ # => #<CurrencyConversion::Status quotas=#<OpenStruct month=#<OpenStruct total=300, used=1, remaining=299>, grace=#<OpenStruct ...
36
+ quotas = response.quotas
37
+ # => #<OpenStruct month=#<OpenStruct total=300, used=1, remaining=299>, grace=#<OpenStruct total=0, used=0, remaining=0>>
38
+ quotas.month.total
39
+ # => 300
40
+ ```
41
+
42
+ ### List available currencies
43
+
44
+ ```ruby
45
+ response = client.currencies.retrieve
46
+ response.data
47
+ # =>
48
+ # {"AED"=>
49
+ # {"symbol"=>"AED",
50
+ # "name"=>"United Arab Emirates Dirham",
51
+ # "symbol_native"=>"د.إ",
52
+ # "decimal_digits"=>2,
53
+ # "rounding"=>0,
54
+ # "code"=>"AED",
55
+ # "name_plural"=>"UAE dirhams"},
56
+ # {...}
57
+ # }
58
+
59
+ # retrieve specific currencies
60
+ response = client.currencies.retrieve(currencies: ['IDR', 'SGD'])
61
+ response.data
62
+ # =>
63
+ # {"IDR"=>
64
+ # {"symbol"=>"Rp",
65
+ # "name"=>"Indonesian Rupiah",
66
+ # "symbol_native"=>"Rp",
67
+ # "decimal_digits"=>0,
68
+ # "rounding"=>0,
69
+ # "code"=>"IDR",
70
+ # "name_plural"=>"Indonesian rupiahs"},
71
+ # "SGD"=>
72
+ # {"symbol"=>"S$",
73
+ # "name"=>"Singapore Dollar",
74
+ # "symbol_native"=>"$",
75
+ # "decimal_digits"=>2,
76
+ # "rounding"=>0,
77
+ # "code"=>"SGD",
78
+ # "name_plural"=>"Singapore dollars"}}
79
+ ```
80
+
81
+ ### Latest Exchange Rates
82
+
83
+ ```ruby
84
+ response = client.exchange_rates.latest(base_currency: 'USD', currencies: ['IDR', 'EUR'])
85
+ response.body
86
+ # => {"meta"=>{"last_updated_at"=>"2022-10-10T23:59:59Z"}, "data"=>{"EUR"=>{"code"=>"EUR", "value"=>1.029906}, "IDR"=>{"code"=>"IDR", "value"=>15350.189946}}}
87
+ response.meta
88
+ # => {"last_updated_at"=>"2022-10-10T23:59:59Z"}
89
+ response.last_updated_at
90
+ # => "2022-10-10T23:59:59Z"
91
+ ```
92
+
93
+ ## Development
94
+
95
+ After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
96
+
97
+ 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 the created tag, and push the `.gem` file to [rubygems.org](https://rubygems.org).
98
+
99
+ ## Contributing
100
+
101
+ Bug reports and pull requests are welcome on GitHub at https://github.com/maful/currency-conversion-ruby. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [code of conduct](https://github.com/maful/currency-conversion-ruby/blob/main/CODE_OF_CONDUCT.md).
102
+
103
+ ## Code of Conduct
104
+
105
+ Everyone interacting in the Currency::Conversion project's codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/maful/currency-conversion-ruby/blob/main/CODE_OF_CONDUCT.md).
data/Rakefile ADDED
@@ -0,0 +1,12 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "bundler/gem_tasks"
4
+ require "rspec/core/rake_task"
5
+
6
+ RSpec::Core::RakeTask.new(:spec)
7
+
8
+ require "rubocop/rake_task"
9
+
10
+ RuboCop::RakeTask.new
11
+
12
+ task default: %i[spec rubocop]
@@ -0,0 +1,39 @@
1
+ # frozen_string_literal: true
2
+
3
+ lib = File.expand_path('../lib', __FILE__)
4
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
5
+ require "currency-conversion/version"
6
+
7
+ Gem::Specification.new do |spec|
8
+ spec.name = "currency-conversion-api"
9
+ spec.version = CurrencyConversion::VERSION
10
+ spec.authors = ["maful"]
11
+ spec.email = ["mafulprayoga@gmail.com"]
12
+
13
+ spec.summary = "Ruby bindings for the currencyapi"
14
+ spec.homepage = "https://github.com/maful/currency-conversion-ruby"
15
+ spec.license = "MIT"
16
+ spec.required_ruby_version = ">= 2.6.0"
17
+
18
+ spec.metadata = {
19
+ "homepage_uri" => spec.homepage,
20
+ "bug_tracker_uri" => "https://github.com/maful/currency-conversion-ruby/issues",
21
+ "source_code_uri" => "https://github.com/maful/currency-conversion-ruby",
22
+ "github_repo" => "https://github.com/maful/currency-conversion-ruby",
23
+ "rubygems_mfa_required" => "true"
24
+ }
25
+
26
+ # Specify which files should be added to the gem when it is released.
27
+ # The `git ls-files -z` loads the files in the RubyGem that have been added into git.
28
+ spec.files = Dir.chdir(File.expand_path(__dir__)) do
29
+ `git ls-files -z`.split("\x0").reject do |f|
30
+ (f == __FILE__) || f.match(%r{\A(?:(?:bin|test|spec|features)/|\.(?:git|travis|circleci)|appveyor)})
31
+ end
32
+ end
33
+ spec.bindir = "exe"
34
+ spec.executables = spec.files.grep(%r{\Aexe/}) { |f| File.basename(f) }
35
+ spec.require_paths = ["lib"]
36
+
37
+ spec.add_dependency "faraday", "~> 2.6"
38
+ spec.add_dependency "activesupport", "~> 6.1"
39
+ end
@@ -0,0 +1,75 @@
1
+ # frozen_string_literal: true
2
+
3
+ module CurrencyConversion
4
+ # Client
5
+ class Client
6
+ # @return [String] Default API endpoint
7
+ BASE_URL = 'https://api.currencyapi.com'
8
+
9
+ # @return [String] API Version
10
+ API_VERSION = 'v3'
11
+
12
+ # @return [String] API Key
13
+ attr_reader :api_key
14
+
15
+ # @return [Symbol] Gets the Symbol key identifying a default Adapter to use
16
+ attr_reader :adapter
17
+
18
+ # Initialize a new client
19
+ #
20
+ # @param api_key [String] API Key
21
+ # @param adapter [Symbol] Faraday Adapter
22
+ #
23
+ # @return [Currency::Conversion::Client]
24
+ def initialize(api_key:, adapter: Faraday.default_adapter)
25
+ @api_key = api_key
26
+ @adapter = adapter
27
+ end
28
+
29
+ # Status Endpoint instance
30
+ #
31
+ # @return [StatusEndpoint]
32
+ def status
33
+ StatusEndpoint.new(self)
34
+ end
35
+
36
+ # Currencies Endpoint instance
37
+ #
38
+ # @return [CurrenciesEndpoint]
39
+ def currencies
40
+ CurrenciesEndpoint.new(self)
41
+ end
42
+
43
+ # Exchange Rates Endpoint instance
44
+ #
45
+ # @return [ExchangeRatesEndpoint]
46
+ def exchange_rates
47
+ ExchangeRatesEndpoint.new(self)
48
+ end
49
+
50
+ # Initializes a new Faraday connection
51
+ #
52
+ # @return [Faraday::Connection]
53
+ def connection
54
+ @connection ||= Faraday.new(headers: default_headers) do |conn|
55
+ conn.url_prefix = connection_url
56
+ conn.response :json, content_type: 'application/json'
57
+ conn.adapter adapter
58
+ end
59
+ end
60
+
61
+ private
62
+
63
+ def connection_url
64
+ URI.join(BASE_URL, API_VERSION).to_s
65
+ end
66
+
67
+ def default_headers
68
+ { 'apikey' => api_key, 'User-Agent' => user_agent }
69
+ end
70
+
71
+ def user_agent
72
+ @user_agent ||= "currency-conversion/#{CurrencyConversion::VERSION}"
73
+ end
74
+ end
75
+ end
@@ -0,0 +1,20 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'active_support/core_ext/object/blank'
4
+
5
+ module CurrencyConversion
6
+ # Currencies Endpoint
7
+ class CurrenciesEndpoint < Resource
8
+ # Returns all supported currencies
9
+ #
10
+ # @param currencies [Array<String>] The currency codes which you want to get.
11
+ # By default all available currencies will be shown.
12
+ #
13
+ # @return [Currencies]
14
+ def retrieve(currencies: nil)
15
+ params = {}
16
+ params[:currencies] = currencies.join(',') if currencies.present?
17
+ Currencies.new get_request('currencies', params: params)
18
+ end
19
+ end
20
+ end
@@ -0,0 +1,21 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'active_support/core_ext/object/blank'
4
+
5
+ module CurrencyConversion
6
+ # Latest Exchange Rates Endpoint
7
+ class ExchangeRatesEndpoint < Resource
8
+ # Returns the latest exchange rates
9
+ #
10
+ # @param base_currency [String] The base currency to which all results are behaving relative to
11
+ # @param currencies [Array<String>] An aray of string of currency codes which you want to get.
12
+ # Default all currencies will be shown.
13
+ #
14
+ # @return [ExchangeRates]
15
+ def latest(base_currency: 'USD', currencies: nil)
16
+ params = { base_currency: base_currency }
17
+ params[:currencies] = currencies.join(',') if currencies.present?
18
+ ExchangeRates.new get_request('latest', params: params)
19
+ end
20
+ end
21
+ end
@@ -0,0 +1,13 @@
1
+ # frozen_string_literal: true
2
+
3
+ module CurrencyConversion
4
+ # Status Endpoint
5
+ class StatusEndpoint < Resource
6
+ # Returns your current quota
7
+ #
8
+ # @return [Status]
9
+ def retrieve
10
+ Status.new get_request('status').body
11
+ end
12
+ end
13
+ end
@@ -0,0 +1,20 @@
1
+ require "ostruct"
2
+
3
+ module CurrencyConversion
4
+ # Object
5
+ class Object < OpenStruct
6
+ def initialize(attributes)
7
+ super to_ostruct(attributes)
8
+ end
9
+
10
+ def to_ostruct(obj)
11
+ if obj.is_a?(Hash)
12
+ OpenStruct.new(obj.map { |key, val| [key, to_ostruct(val)] }.to_h)
13
+ elsif obj.is_a?(Array)
14
+ obj.map { |o| to_ostruct(o) }
15
+ else
16
+ obj
17
+ end
18
+ end
19
+ end
20
+ end
@@ -0,0 +1,21 @@
1
+ # frozen_string_literal: true
2
+
3
+ module CurrencyConversion
4
+ # Currencies
5
+ class Currencies
6
+ # @return [Hash] The response body
7
+ attr_reader :body
8
+
9
+ # @return [Faraday::Response] The Faraday Response
10
+ attr_reader :response
11
+
12
+ def initialize(response)
13
+ @response = response
14
+ @body = response.body
15
+ end
16
+
17
+ def data
18
+ body['data']
19
+ end
20
+ end
21
+ end
@@ -0,0 +1,29 @@
1
+ # frozen_string_literal: true
2
+
3
+ module CurrencyConversion
4
+ # ExchangeRates
5
+ class ExchangeRates
6
+ # @return [Hash] The response body
7
+ attr_reader :body
8
+
9
+ # @return [Faraday::Response] The Faraday Response
10
+ attr_reader :response
11
+
12
+ def initialize(response)
13
+ @response = response
14
+ @body = response.body
15
+ end
16
+
17
+ def data
18
+ body['data']
19
+ end
20
+
21
+ def meta
22
+ body['meta']
23
+ end
24
+
25
+ def last_updated_at
26
+ meta['last_updated_at']
27
+ end
28
+ end
29
+ end
@@ -0,0 +1,6 @@
1
+ # frozen_string_literal: true
2
+
3
+ module CurrencyConversion
4
+ class Status < Object
5
+ end
6
+ end
@@ -0,0 +1,29 @@
1
+ # frozen_string_literal: true
2
+
3
+ module CurrencyConversion
4
+ # Resource
5
+ class Resource
6
+ # @return [Currency::Conversion::Client] Gets the Client instance
7
+ attr_reader :client
8
+
9
+ # Initialize a new resource
10
+ #
11
+ # @param client [Currency::Conversion::Client] The Client instance
12
+ #
13
+ # @return [Currency::Conversion::Resource]
14
+ def initialize(client)
15
+ @client = client
16
+ end
17
+
18
+ private
19
+
20
+ def get_request(path, params: {})
21
+ handle_response client.connection.get(path, params)
22
+ end
23
+
24
+ def handle_response(response)
25
+ # TODO: Handle response based on status code
26
+ response
27
+ end
28
+ end
29
+ end
@@ -0,0 +1,5 @@
1
+ # frozen_string_literal: true
2
+
3
+ module CurrencyConversion
4
+ VERSION = '0.1.0'
5
+ end
@@ -0,0 +1,18 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'faraday'
4
+ require 'currency-conversion/version'
5
+
6
+ module CurrencyConversion
7
+ autoload :Client, 'currency-conversion/client'
8
+ autoload :Resource, 'currency-conversion/resource'
9
+ autoload :Object, 'currency-conversion/object'
10
+
11
+ autoload :StatusEndpoint, 'currency-conversion/endpoints/status'
12
+ autoload :ExchangeRatesEndpoint, 'currency-conversion/endpoints/exchange_rates'
13
+ autoload :CurrenciesEndpoint, 'currency-conversion/endpoints/currencies'
14
+
15
+ autoload :Status, 'currency-conversion/objects/status'
16
+ autoload :ExchangeRates, 'currency-conversion/objects/exchange_rates'
17
+ autoload :Currencies, 'currency-conversion/objects/currencies'
18
+ end
@@ -0,0 +1,6 @@
1
+ module Currency
2
+ module Conversion
3
+ VERSION: String
4
+ # See the writing guide of rbs: https://github.com/ruby/rbs#guides
5
+ end
6
+ end
metadata ADDED
@@ -0,0 +1,97 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: currency-conversion-api
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: 2022-10-12 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: faraday
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '2.6'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '2.6'
27
+ - !ruby/object:Gem::Dependency
28
+ name: activesupport
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '6.1'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '6.1'
41
+ description:
42
+ email:
43
+ - mafulprayoga@gmail.com
44
+ executables: []
45
+ extensions: []
46
+ extra_rdoc_files: []
47
+ files:
48
+ - ".rubocop.yml"
49
+ - CHANGELOG.md
50
+ - CODE_OF_CONDUCT.md
51
+ - Gemfile
52
+ - Gemfile.lock
53
+ - LICENSE
54
+ - README.md
55
+ - Rakefile
56
+ - currency-conversion.gemspec
57
+ - lib/currency-conversion.rb
58
+ - lib/currency-conversion/client.rb
59
+ - lib/currency-conversion/endpoints/currencies.rb
60
+ - lib/currency-conversion/endpoints/exchange_rates.rb
61
+ - lib/currency-conversion/endpoints/status.rb
62
+ - lib/currency-conversion/object.rb
63
+ - lib/currency-conversion/objects/currencies.rb
64
+ - lib/currency-conversion/objects/exchange_rates.rb
65
+ - lib/currency-conversion/objects/status.rb
66
+ - lib/currency-conversion/resource.rb
67
+ - lib/currency-conversion/version.rb
68
+ - sig/currency/conversion.rbs
69
+ homepage: https://github.com/maful/currency-conversion-ruby
70
+ licenses:
71
+ - MIT
72
+ metadata:
73
+ homepage_uri: https://github.com/maful/currency-conversion-ruby
74
+ bug_tracker_uri: https://github.com/maful/currency-conversion-ruby/issues
75
+ source_code_uri: https://github.com/maful/currency-conversion-ruby
76
+ github_repo: https://github.com/maful/currency-conversion-ruby
77
+ rubygems_mfa_required: 'true'
78
+ post_install_message:
79
+ rdoc_options: []
80
+ require_paths:
81
+ - lib
82
+ required_ruby_version: !ruby/object:Gem::Requirement
83
+ requirements:
84
+ - - ">="
85
+ - !ruby/object:Gem::Version
86
+ version: 2.6.0
87
+ required_rubygems_version: !ruby/object:Gem::Requirement
88
+ requirements:
89
+ - - ">="
90
+ - !ruby/object:Gem::Version
91
+ version: '0'
92
+ requirements: []
93
+ rubygems_version: 3.3.7
94
+ signing_key:
95
+ specification_version: 4
96
+ summary: Ruby bindings for the currencyapi
97
+ test_files: []