forexrateapi 1.1.2 → 1.3.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 +4 -4
- data/README.md +58 -10
- data/lib/forexrateapi/client.rb +8 -0
- data/lib/forexrateapi/config.rb +6 -1
- data/lib/forexrateapi/endpoints/index.rb +19 -5
- data/lib/forexrateapi/version.rb +1 -1
- metadata +14 -8
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 1b95736b9d870b217de0a86b67ba39d66e188e3f98c2fcbc14b26510751c99a0
|
|
4
|
+
data.tar.gz: e592a8251ac179ed60bb3341b074e1c3ecd8ef336804e3aea3b7f5a8143023d6
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: f168941bd8dc7f4c8dd9009968c34b4e5fd47c9c7a21336cc40c5630c605df7ef80a3e71864adc4b7a7f2993c4788be39b421418f2d577bc259ed99114e749a7
|
|
7
|
+
data.tar.gz: e3aa765aa0cb5ee99d4233768168198c267dee0d46dbbfa718e98fc4aa423193da665537b36ae72977296416d4c8f48d5056bfb141139e36bfc27e65c5456ead
|
data/README.md
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
# ForexRateAPI
|
|
2
2
|
|
|
3
|
-
forexrateapi is the official
|
|
3
|
+
forexrateapi is the official Ruby 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
4
|
|
|
5
5
|
## Installation
|
|
6
6
|
Add to Gemfile.
|
|
@@ -15,7 +15,28 @@ gem 'forexrateapi'
|
|
|
15
15
|
|
|
16
16
|
api_key = 'SET_YOUR_API_KEY_HERE'
|
|
17
17
|
client = ForexRateAPI::Client.new(api_key: api_key)
|
|
18
|
+
|
|
19
|
+
# Or use EU server:
|
|
20
|
+
# client = ForexRateAPI::Client.new(api_key: api_key, server: 'eu')
|
|
21
|
+
```
|
|
22
|
+
---
|
|
23
|
+
## Server Regions
|
|
24
|
+
|
|
25
|
+
ForexRateAPI provides two regional endpoints. Choose the one closest to your servers for optimal performance.
|
|
26
|
+
|
|
27
|
+
| Region | Base URL |
|
|
28
|
+
|--------|----------|
|
|
29
|
+
| United States (default) | `https://api.forexrateapi.com/v1` |
|
|
30
|
+
| Europe | `https://api-eu.forexrateapi.com/v1` |
|
|
31
|
+
|
|
32
|
+
```ruby
|
|
33
|
+
# Default (US)
|
|
34
|
+
client = ForexRateAPI::Client.new(api_key: 'SET_YOUR_API_KEY_HERE')
|
|
35
|
+
|
|
36
|
+
# Europe
|
|
37
|
+
client = ForexRateAPI::Client.new(api_key: 'SET_YOUR_API_KEY_HERE', server: 'eu')
|
|
18
38
|
```
|
|
39
|
+
|
|
19
40
|
---
|
|
20
41
|
## Documentation
|
|
21
42
|
|
|
@@ -27,13 +48,23 @@ client.fetchSymbols()
|
|
|
27
48
|
[Link](https://forexrateapi.com/documentation#api_symbol)
|
|
28
49
|
|
|
29
50
|
---
|
|
30
|
-
####
|
|
51
|
+
#### setServer(server)
|
|
52
|
+
|
|
53
|
+
- `server` <[string]> Pass `'eu'` to use the EU server (`api-eu.forexrateapi.com`), or `'us'` for the US server. Defaults to US if not specified.
|
|
54
|
+
|
|
55
|
+
```ruby
|
|
56
|
+
client.setServer('eu')
|
|
57
|
+
```
|
|
58
|
+
|
|
59
|
+
---
|
|
60
|
+
#### fetchLive(base, currencies, math)
|
|
31
61
|
|
|
32
62
|
- `base` <[string]> Optional. Pass in a base currency, defaults to USD.
|
|
33
63
|
- `currencies` <[Array]<[string]>> Optional. Pass in an array of currencies to return values for.
|
|
64
|
+
- `math` <[string]> Optional. Pass in a math expression to apply to the rates.
|
|
34
65
|
|
|
35
66
|
```ruby
|
|
36
|
-
client.fetchLive(
|
|
67
|
+
client.fetchLive('USD', ['AUD', 'CAD', 'GBP', 'JPY'])
|
|
37
68
|
```
|
|
38
69
|
|
|
39
70
|
[Link](https://forexrateapi.com/documentation#api_realtime)
|
|
@@ -46,11 +77,27 @@ client.fetchLive(base='USD', currencies=['AUD', 'CAD', 'GBP', 'JPY'])
|
|
|
46
77
|
- `currencies` <[Array]<[string]>> Optional. Pass in an array of currencies to return values for.
|
|
47
78
|
|
|
48
79
|
```ruby
|
|
49
|
-
client.fetchHistorical(
|
|
80
|
+
client.fetchHistorical('2024-02-05', 'USD', ['AUD', 'CAD', 'GBP', 'JPY'])
|
|
50
81
|
```
|
|
51
82
|
|
|
52
83
|
[Link](https://forexrateapi.com/documentation#api_historical)
|
|
53
84
|
|
|
85
|
+
---
|
|
86
|
+
#### hourly(base, currency, start_date, end_date, math, date_type)
|
|
87
|
+
|
|
88
|
+
- `base` <[string]> Optional. Pass in a base currency, defaults to USD.
|
|
89
|
+
- `currency` <[string]> Required. Specify currency you would like to get hourly rates for.
|
|
90
|
+
- `start_date` <[string]> Required. Specify the start date using the format `YYYY-MM-DD`.
|
|
91
|
+
- `end_date` <[string]> Required. Specify the end date using the format `YYYY-MM-DD`.
|
|
92
|
+
- `math` <[string]> Optional. Pass in a math expression to apply to the rates.
|
|
93
|
+
- `date_type` <[string]> Optional. Pass in a date type, overrides date parameters if passed in.
|
|
94
|
+
|
|
95
|
+
```ruby
|
|
96
|
+
client.hourly('USD', 'EUR', '2024-02-05', '2024-02-05')
|
|
97
|
+
```
|
|
98
|
+
|
|
99
|
+
[Link](https://forexrateapi.com/documentation#api_hourly)
|
|
100
|
+
|
|
54
101
|
---
|
|
55
102
|
#### ohlc(base, currency, date, date_type)
|
|
56
103
|
|
|
@@ -60,7 +107,7 @@ client.fetchHistorical(date='2021-04-05', base='USD', currencies=['AUD', 'CAD',
|
|
|
60
107
|
- `date_type` <[string]> Optional. Pass in a date type, overrides date parameter if passed in.
|
|
61
108
|
|
|
62
109
|
```ruby
|
|
63
|
-
client.ohlc(
|
|
110
|
+
client.ohlc('USD', 'EUR', '2024-02-05', nil)
|
|
64
111
|
```
|
|
65
112
|
|
|
66
113
|
[Link](https://forexrateapi.com/documentation#api_ohlc)
|
|
@@ -74,7 +121,7 @@ client.ohlc(base='USD', currency='EUR', date='2021-04-05', date_type=nil)
|
|
|
74
121
|
- `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.
|
|
75
122
|
|
|
76
123
|
```ruby
|
|
77
|
-
client.convert(
|
|
124
|
+
client.convert('USD', 'EUR', 100, '2024-02-05')
|
|
78
125
|
```
|
|
79
126
|
|
|
80
127
|
[Link](https://forexrateapi.com/documentation#api_convert)
|
|
@@ -88,21 +135,22 @@ client.convert(from_currency='USD', to_currency='EUR', amount=100, date='2021-04
|
|
|
88
135
|
- `currencies` <[Array]<[string]>> Optional. Pass in an array of currencies to return values for.
|
|
89
136
|
|
|
90
137
|
```ruby
|
|
91
|
-
client.timeframe(
|
|
138
|
+
client.timeframe('2024-02-05', '2024-02-06', 'USD', ['AUD', 'CAD', 'GBP', 'JPY'])
|
|
92
139
|
```
|
|
93
140
|
|
|
94
141
|
[Link](https://forexrateapi.com/documentation#api_timeframe)
|
|
95
142
|
|
|
96
143
|
---
|
|
97
|
-
#### change(start_date, end_date, base, currencies)
|
|
144
|
+
#### change(start_date, end_date, base, currencies, date_type)
|
|
98
145
|
|
|
99
146
|
- `start_date` <[string]> Required. Specify the start date of your timeframe using the format `YYYY-MM-DD`.
|
|
100
147
|
- `end_date` <[string]> Required. Specify the end date of your timeframe using the format `YYYY-MM-DD`.
|
|
101
148
|
- `base` <[string]> Optional. Pass in a base currency, defaults to USD.
|
|
102
149
|
- `currencies` <[Array]<[string]>> Optional. Pass in an array of currencies to return values for.
|
|
150
|
+
- `date_type` <[string]> Optional. Pass in a date type, overrides date parameters if passed in.
|
|
103
151
|
|
|
104
152
|
```ruby
|
|
105
|
-
client.change(
|
|
153
|
+
client.change('2024-02-05', '2024-02-06', 'USD', ['AUD', 'CAD', 'GBP', 'JPY'])
|
|
106
154
|
```
|
|
107
155
|
|
|
108
156
|
[Link](https://forexrateapi.com/documentation#api_change)
|
|
@@ -137,4 +185,4 @@ For support, get in touch using [this form](https://forexrateapi.com/contact).
|
|
|
137
185
|
|
|
138
186
|
[Array]: https://www.geeksforgeeks.org/ruby-data-types/ 'Array'
|
|
139
187
|
[number]: https://www.geeksforgeeks.org/ruby-data-types/ 'Number'
|
|
140
|
-
[string]: https://apidock.com/ruby/String 'String'
|
|
188
|
+
[string]: https://apidock.com/ruby/String 'String'
|
data/lib/forexrateapi/client.rb
CHANGED
|
@@ -12,9 +12,17 @@ module ForexRateAPI
|
|
|
12
12
|
ForexRateAPI::Config::ATTRIBUTES.each do |key|
|
|
13
13
|
send("#{key}=", options[key] || ForexRateAPI.config.send(key))
|
|
14
14
|
end
|
|
15
|
+
if options[:server]
|
|
16
|
+
self.endpoint = Config::SERVERS[options[:server]] || Config::SERVERS['us']
|
|
17
|
+
end
|
|
15
18
|
@logger ||= ForexRateAPI::Logger.logger
|
|
16
19
|
end
|
|
17
20
|
|
|
21
|
+
def setServer(server)
|
|
22
|
+
self.endpoint = Config::SERVERS[server] || Config::SERVERS['us']
|
|
23
|
+
@connection = nil
|
|
24
|
+
end
|
|
25
|
+
|
|
18
26
|
class << self
|
|
19
27
|
def configure
|
|
20
28
|
block_given? ? yield(Config) : Config
|
data/lib/forexrateapi/config.rb
CHANGED
|
@@ -4,6 +4,11 @@ module ForexRateAPI
|
|
|
4
4
|
module Config
|
|
5
5
|
extend self
|
|
6
6
|
|
|
7
|
+
SERVERS = {
|
|
8
|
+
'us' => 'https://api.forexrateapi.com/v1',
|
|
9
|
+
'eu' => 'https://api-eu.forexrateapi.com/v1'
|
|
10
|
+
}.freeze
|
|
11
|
+
|
|
7
12
|
ATTRIBUTES = %i[
|
|
8
13
|
endpoint
|
|
9
14
|
api_key
|
|
@@ -19,7 +24,7 @@ module ForexRateAPI
|
|
|
19
24
|
attr_accessor(*Config::ATTRIBUTES)
|
|
20
25
|
|
|
21
26
|
def reset
|
|
22
|
-
self.endpoint = '
|
|
27
|
+
self.endpoint = SERVERS['us']
|
|
23
28
|
self.api_key = nil
|
|
24
29
|
self.user_agent = "ForexRateAPI Ruby Client/#{ForexRateAPI::VERSION}"
|
|
25
30
|
self.ca_path = defined?(OpenSSL) ? OpenSSL::X509::DEFAULT_CERT_DIR : nil
|
|
@@ -6,10 +6,11 @@ module ForexRateAPI
|
|
|
6
6
|
get('symbols')
|
|
7
7
|
end
|
|
8
8
|
|
|
9
|
-
def fetchLive(base = nil, currencies = nil)
|
|
9
|
+
def fetchLive(base = nil, currencies = nil, math = nil)
|
|
10
10
|
options = removeEmpty({
|
|
11
11
|
base: base,
|
|
12
|
-
currencies: (currencies || []).join(',')
|
|
12
|
+
currencies: (currencies || []).join(','),
|
|
13
|
+
math: math
|
|
13
14
|
})
|
|
14
15
|
get('latest', options)
|
|
15
16
|
end
|
|
@@ -22,6 +23,18 @@ module ForexRateAPI
|
|
|
22
23
|
get(date, options)
|
|
23
24
|
end
|
|
24
25
|
|
|
26
|
+
def hourly(base = nil, currency = nil, start_date = nil, end_date = nil, math = nil, date_type = nil)
|
|
27
|
+
options = removeEmpty({
|
|
28
|
+
base: base,
|
|
29
|
+
currency: currency,
|
|
30
|
+
start_date: start_date,
|
|
31
|
+
end_date: end_date,
|
|
32
|
+
math: math,
|
|
33
|
+
date_type: date_type
|
|
34
|
+
})
|
|
35
|
+
get('hourly', options)
|
|
36
|
+
end
|
|
37
|
+
|
|
25
38
|
def ohlc(base = nil, currency = nil, date = nil, date_type = nil)
|
|
26
39
|
options = removeEmpty({
|
|
27
40
|
base: base,
|
|
@@ -52,12 +65,13 @@ module ForexRateAPI
|
|
|
52
65
|
get('timeframe', options)
|
|
53
66
|
end
|
|
54
67
|
|
|
55
|
-
def change(start_date, end_date, base =
|
|
68
|
+
def change(start_date, end_date, base = nil, currencies = nil, date_type = nil)
|
|
56
69
|
options = removeEmpty({
|
|
57
70
|
'start_date': start_date,
|
|
58
71
|
'end_date': end_date,
|
|
59
72
|
'base': base,
|
|
60
|
-
'currencies': (currencies || []).join(',')
|
|
73
|
+
'currencies': (currencies || []).join(','),
|
|
74
|
+
'date_type': date_type
|
|
61
75
|
})
|
|
62
76
|
get('change', options)
|
|
63
77
|
end
|
|
@@ -70,7 +84,7 @@ module ForexRateAPI
|
|
|
70
84
|
|
|
71
85
|
def removeEmpty(options)
|
|
72
86
|
options.each do |key, value|
|
|
73
|
-
if (
|
|
87
|
+
if (value.nil? || value == '')
|
|
74
88
|
options.delete(key)
|
|
75
89
|
end
|
|
76
90
|
end
|
data/lib/forexrateapi/version.rb
CHANGED
metadata
CHANGED
|
@@ -1,19 +1,22 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: forexrateapi
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 1.
|
|
4
|
+
version: 1.3.0
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- ForexRateAPI
|
|
8
8
|
autorequire:
|
|
9
9
|
bindir: bin
|
|
10
10
|
cert_chain: []
|
|
11
|
-
date:
|
|
11
|
+
date: 2026-02-25 00:00:00.000000000 Z
|
|
12
12
|
dependencies:
|
|
13
13
|
- !ruby/object:Gem::Dependency
|
|
14
14
|
name: faraday
|
|
15
15
|
requirement: !ruby/object:Gem::Requirement
|
|
16
16
|
requirements:
|
|
17
|
+
- - "~>"
|
|
18
|
+
- !ruby/object:Gem::Version
|
|
19
|
+
version: '1.0'
|
|
17
20
|
- - ">="
|
|
18
21
|
- !ruby/object:Gem::Version
|
|
19
22
|
version: 1.0.0
|
|
@@ -21,6 +24,9 @@ dependencies:
|
|
|
21
24
|
prerelease: false
|
|
22
25
|
version_requirements: !ruby/object:Gem::Requirement
|
|
23
26
|
requirements:
|
|
27
|
+
- - "~>"
|
|
28
|
+
- !ruby/object:Gem::Version
|
|
29
|
+
version: '1.0'
|
|
24
30
|
- - ">="
|
|
25
31
|
- !ruby/object:Gem::Version
|
|
26
32
|
version: 1.0.0
|
|
@@ -28,16 +34,16 @@ dependencies:
|
|
|
28
34
|
name: faraday_middleware
|
|
29
35
|
requirement: !ruby/object:Gem::Requirement
|
|
30
36
|
requirements:
|
|
31
|
-
- - "
|
|
37
|
+
- - "~>"
|
|
32
38
|
- !ruby/object:Gem::Version
|
|
33
|
-
version: '0'
|
|
39
|
+
version: '1.0'
|
|
34
40
|
type: :runtime
|
|
35
41
|
prerelease: false
|
|
36
42
|
version_requirements: !ruby/object:Gem::Requirement
|
|
37
43
|
requirements:
|
|
38
|
-
- - "
|
|
44
|
+
- - "~>"
|
|
39
45
|
- !ruby/object:Gem::Version
|
|
40
|
-
version: '0'
|
|
46
|
+
version: '1.0'
|
|
41
47
|
description:
|
|
42
48
|
email: contact@forexrateapi.com
|
|
43
49
|
executables: []
|
|
@@ -70,14 +76,14 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
|
70
76
|
requirements:
|
|
71
77
|
- - ">="
|
|
72
78
|
- !ruby/object:Gem::Version
|
|
73
|
-
version: '
|
|
79
|
+
version: '2.7'
|
|
74
80
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
|
75
81
|
requirements:
|
|
76
82
|
- - ">="
|
|
77
83
|
- !ruby/object:Gem::Version
|
|
78
84
|
version: '0'
|
|
79
85
|
requirements: []
|
|
80
|
-
rubygems_version: 3.
|
|
86
|
+
rubygems_version: 3.5.22
|
|
81
87
|
signing_key:
|
|
82
88
|
specification_version: 4
|
|
83
89
|
summary: Official ForexRateAPI Ruby client.
|