Skip to content

Commit 80eaecd

Browse files
committed
initial commit
0 parents  commit 80eaecd

File tree

19 files changed

+524
-0
lines changed

19 files changed

+524
-0
lines changed

.gitignore

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
.env
2+
pkg
3+
Gemfile.lock
4+
.DS_Store
5+
.bundle
6+
.idea
7+
*.gem

Gemfile

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
# frozen_string_literal: true
2+
3+
source 'http://rubygems.org'
4+
5+
gemspec

LICENSE.md

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
MIT License
2+
3+
Copyright (c) 2023 ForexRateAPI
4+
5+
Permission is hereby granted, free of charge, to any person obtaining
6+
a copy of this software and associated documentation files (the
7+
"Software"), to deal in the Software without restriction, including
8+
without limitation the rights to use, copy, modify, merge, publish,
9+
distribute, sublicense, and/or sell copies of the Software, and to
10+
permit persons to whom the Software is furnished to do so, subject to
11+
the following conditions:
12+
13+
The above copyright notice and this permission notice shall be
14+
included in all copies or substantial portions of the Software.
15+
16+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

README.md

Lines changed: 119 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,119 @@
1+
# ForexRateAPI
2+
3+
forexrateapi is the official Node.js wrapper for ForexRateAPI.com. This allows you to quickly integrate our foreign exchange rate API and currency conversion API into your application. Check https://forexrateapi.com documentation for more information.
4+
5+
## Installation
6+
Add to Gemfile.
7+
8+
```
9+
gem 'forexrateapi'
10+
```
11+
12+
## Usage
13+
14+
```ruby
15+
16+
api_key = 'SET_YOUR_API_KEY_HERE'
17+
client = ForexRateAPI::Client.new(api_key: api_key)
18+
```
19+
---
20+
## Documentation
21+
22+
#### fetchSymbols()
23+
```ruby
24+
client.fetchSymbols()
25+
```
26+
27+
[Link](https://forexrateapi.com/documentation#api_symbol)
28+
29+
---
30+
#### fetchLive(base, currencies)
31+
32+
- `base` <[string]> Optional. Pass in a base currency, defaults to USD.
33+
- `currencies` <[Array]<[string]>> Optional. Pass in an array of currencies to return values for.
34+
35+
```ruby
36+
client.fetchLive(base='USD', currencies=['AUD', 'CAD', 'GBP', 'JPY'])
37+
```
38+
39+
[Link](https://forexrateapi.com/documentation#api_realtime)
40+
41+
---
42+
#### fetchHistorical(date, base, currencies)
43+
44+
- `date` <[string]> Required. Pass in a string with format `YYYY-MM-DD`
45+
- `base` <[string]> Optional. Pass in a base currency, defaults to USD.
46+
- `currencies` <[Array]<[string]>> Optional. Pass in an array of currencies to return values for.
47+
48+
```ruby
49+
client.fetchHistorical(date='2021-04-05', base='USD', currencies=['AUD', 'CAD', 'GBP', 'JPY'])
50+
```
51+
52+
[Link](https://forexrateapi.com/documentation#api_historical)
53+
54+
---
55+
#### convert(from_currency, to_currency, amount, date)
56+
57+
- `from_currency` <[string]> Optional. Pass in a base currency, defaults to USD.
58+
- `to_currency` <[string]> Required. Specify currency you would like to convert to.
59+
- `amount` <[number]> Required. The amount to convert.
60+
- `date` <[string]> Optional. Specify date to use historical midpoint value for conversion with format `YYYY-MM-DD`. Otherwise, it will use live exchange rate date if value not passed in.
61+
62+
```ruby
63+
client.convert(from_currency='USD', to_currency='EUR', amount=100, date='2021-04-05')
64+
```
65+
66+
[Link](https://forexrateapi.com/documentation#api_convert)
67+
68+
---
69+
#### timeframe(start_date, end_date, base, currencies)
70+
71+
- `start_date` <[string]> Required. Specify the start date of your timeframe using the format `YYYY-MM-DD`.
72+
- `end_date` <[string]> Required. Specify the end date of your timeframe using the format `YYYY-MM-DD`.
73+
- `base` <[string]> Optional. Pass in a base currency, defaults to USD.
74+
- `currencies` <[Array]<[string]>> Optional. Pass in an array of currencies to return values for.
75+
76+
```ruby
77+
client.timeframe(start_date='2021-04-05', end_date='2021-04-06', base='USD', currencies=['AUD', 'CAD', 'GBP', 'JPY'])
78+
```
79+
80+
[Link](https://forexrateapi.com/documentation#api_timeframe)
81+
82+
---
83+
#### change(start_date, end_date, base, currencies)
84+
85+
- `start_date` <[string]> Required. Specify the start date of your timeframe using the format `YYYY-MM-DD`.
86+
- `end_date` <[string]> Required. Specify the end date of your timeframe using the format `YYYY-MM-DD`.
87+
- `base` <[string]> Optional. Pass in a base currency, defaults to USD.
88+
- `currencies` <[Array]<[string]>> Optional. Pass in an array of currencies to return values for.
89+
90+
```ruby
91+
client.change(start_date='2021-04-05', end_date='2021-04-06', base='USD', currencies=['AUD', 'CAD', 'GBP', 'JPY'])
92+
```
93+
94+
[Link](https://forexrateapi.com/documentation#api_change)
95+
96+
---
97+
**[Official documentation](https://forexrateapi.com/documentation)**
98+
99+
100+
---
101+
## FAQ
102+
103+
- How do I get an API Key?
104+
105+
Free API Keys are available [here](https://forexrateapi.com).
106+
107+
- I want more information
108+
109+
Checkout our FAQs [here](https://forexrateapi.com/faq).
110+
111+
112+
## Support
113+
114+
For support, get in touch using [this form](https://forexrateapi.com/contact).
115+
116+
117+
[Array]: https://www.geeksforgeeks.org/ruby-data-types/ 'Array'
118+
[number]: https://www.geeksforgeeks.org/ruby-data-types/ 'Number'
119+
[string]: https://apidock.com/ruby/String 'String'

Rakefile

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
# frozen_string_literal: true
2+
3+
require 'rubygems'
4+
require 'bundler'
5+
require 'bundler/gem_tasks'
6+
7+
Bundler.setup :default, :development

example/index.rb

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
require_relative '../lib/forexrateapi'
2+
3+
API_KEY = 'REPLACE_ME'
4+
5+
ForexRateAPI::VERSION
6+
7+
client = ForexRateAPI::Client.new(
8+
api_key: API_KEY
9+
)
10+
11+
data = client.fetchSymbols()
12+
puts data
13+
14+
data = client.fetchLive()
15+
puts data
16+
17+
data = client.fetchHistorical('2021-04-05', 'USD', ['AUD', 'CAD', 'GBP', 'JPY'])
18+
puts data
19+
20+
data = client.convert('USD', 'EUR', 100, '2021-04-05')
21+
puts data
22+
23+
data = client.timeframe('2021-04-05', '2021-04-06', 'USD', ['AUD', 'CAD', 'GBP', 'JPY'])
24+
puts data
25+
26+
data = client.change('2021-04-05', '2021-04-06', 'USD', ['AUD', 'CAD', 'GBP', 'JPY'])
27+
puts data

forexrateapi.gemspec

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
# frozen_string_literal: true
2+
3+
require 'forexrateapi/version'
4+
5+
Gem::Specification.new do |s|
6+
s.name = 'forexrateapi'
7+
s.version = ForexRateAPI::VERSION
8+
s.authors = ['ForexRateAPI']
9+
s.email = 'contact@forexrateapi.com'
10+
s.files = Dir['{bin,lib}/**/*'] + ['README.md', 'LICENSE.md']
11+
s.require_paths = ['lib']
12+
s.homepage = 'http://github.com/forexrateapi/forexrateapi-ruby'
13+
s.licenses = ['MIT']
14+
s.summary = 'Official ForexRateAPI Ruby client.'
15+
s.add_dependency 'faraday', '>= 1.0.0'
16+
s.add_dependency 'faraday_middleware'
17+
end

lib/forexrateapi.rb

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
# frozen_string_literal: true
2+
3+
require 'faraday'
4+
require 'faraday_middleware'
5+
require 'json'
6+
require 'logger'
7+
8+
require_relative 'forexrateapi/version'
9+
require_relative 'forexrateapi/logger'
10+
11+
require_relative 'forexrateapi/errors/fault'
12+
13+
require_relative 'forexrateapi/raise_error'
14+
require_relative 'forexrateapi/connection'
15+
require_relative 'forexrateapi/request'
16+
require_relative 'forexrateapi/config'
17+
require_relative 'forexrateapi/errors'
18+
require_relative 'forexrateapi/endpoints'
19+
require_relative 'forexrateapi/client'

lib/forexrateapi/client.rb

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
# frozen_string_literal: true
2+
3+
module ForexRateAPI
4+
class Client
5+
include Connection
6+
include Request
7+
include Endpoints
8+
9+
attr_accessor(*Config::ATTRIBUTES)
10+
11+
def initialize(options = {})
12+
ForexRateAPI::Config::ATTRIBUTES.each do |key|
13+
send("#{key}=", options[key] || ForexRateAPI.config.send(key))
14+
end
15+
@logger ||= ForexRateAPI::Logger.logger
16+
end
17+
18+
class << self
19+
def configure
20+
block_given? ? yield(Config) : Config
21+
end
22+
23+
def config
24+
Config
25+
end
26+
end
27+
end
28+
end

lib/forexrateapi/config.rb

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
# frozen_string_literal: true
2+
3+
module ForexRateAPI
4+
module Config
5+
extend self
6+
7+
ATTRIBUTES = %i[
8+
endpoint
9+
api_key
10+
proxy
11+
user_agent
12+
ca_path
13+
ca_file
14+
logger
15+
timeout
16+
open_timeout
17+
].freeze
18+
19+
attr_accessor(*Config::ATTRIBUTES)
20+
21+
def reset
22+
self.endpoint = 'https://api.forexrateapi.com/v1'
23+
self.api_key = nil
24+
self.user_agent = "ForexRateAPI Ruby Client/#{ForexRateAPI::VERSION}"
25+
self.ca_path = defined?(OpenSSL) ? OpenSSL::X509::DEFAULT_CERT_DIR : nil
26+
self.ca_file = defined?(OpenSSL) ? OpenSSL::X509::DEFAULT_CERT_FILE : nil
27+
self.proxy = nil
28+
self.logger = nil
29+
self.timeout = nil
30+
self.open_timeout = nil
31+
end
32+
end
33+
34+
class << self
35+
def configure
36+
block_given? ? yield(Config) : Config
37+
end
38+
39+
def config
40+
Config
41+
end
42+
end
43+
end
44+
45+
ForexRateAPI::Config.reset

0 commit comments

Comments
 (0)