metalpriceapi 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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: b752dcae214e6d63cf250ae83b7749f19986f644b89c5a57a71946a35c4d85f0
4
- data.tar.gz: 716d1d203372742a7e66f48c1901bb54f5e35338c841c3484aed457b5e310fc0
3
+ metadata.gz: b62712677891b353f2d7a9cdba4828642f028b2b7ca7ea8a1d9da26d9cf387be
4
+ data.tar.gz: 3c2200eaf7ca8a0ce5f7a2b23ead0b5e5a4518a1387ab6c1263b26286a75a6d1
5
5
  SHA512:
6
- metadata.gz: c7d6d999df3dd81f25ca2e91fa43244a5ed6e74dc6e1b5ede72c770e0d5c112719c1f80ef4820d4710dbb7864475fdd7c1460205b86bd63882fc0ad555c7292d
7
- data.tar.gz: b12c1ea4110ca309d98714b573b5e67bbdb4dd8e670469ad50bdb8e0e5c8837db3a7f34b0606c34e91f6655aecaee455d443a18d1bd2e57dd6fcdf6619af1144
6
+ metadata.gz: 11715fca73cf0cc67c6834200f3f79fb6d9c84d6e31cb73abd020614712474b0125b49313f24ac0aeede4e454499902d743420e9d66d6f1539411c3b70c952d7
7
+ data.tar.gz: 662abe1157a08cd35d965e97851a244f2ccb3224677ae3228705ddc723032316832173372e115018906875fbb1c6023df43aeeebede20eb85a0d8b0d9e5e3cb0
data/README.md CHANGED
@@ -15,7 +15,28 @@ gem 'metalpriceapi'
15
15
 
16
16
  api_key = 'SET_YOUR_API_KEY_HERE'
17
17
  client = MetalpriceAPI::Client.new(api_key: api_key)
18
+
19
+ # Or use EU server:
20
+ # client = MetalpriceAPI::Client.new(api_key: api_key, server: 'eu')
18
21
  ```
22
+ ---
23
+ ## Server Regions
24
+
25
+ MetalpriceAPI 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.metalpriceapi.com/v1` |
30
+ | Europe | `https://api-eu.metalpriceapi.com/v1` |
31
+
32
+ ```ruby
33
+ # Default (US)
34
+ client = MetalpriceAPI::Client.new(api_key: 'SET_YOUR_API_KEY_HERE')
35
+
36
+ # Europe
37
+ client = MetalpriceAPI::Client.new(api_key: 'SET_YOUR_API_KEY_HERE', server: 'eu')
38
+ ```
39
+
19
40
  ---
20
41
  ## Documentation
21
42
 
@@ -27,32 +48,62 @@ client.fetchSymbols()
27
48
  [Link](https://metalpriceapi.com/documentation#api_symbol)
28
49
 
29
50
  ---
30
- #### fetchLive(base, currencies)
51
+ #### setServer(server)
52
+
53
+ - `server` <[string]> Pass `'eu'` to use the EU server (`api-eu.metalpriceapi.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, unit, purity, 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
+ - `unit` <[string]> Optional. Pass in a unit for metal prices (e.g. `troy_oz`, `gram`, `kilogram`).
65
+ - `purity` <[string]> Optional. Pass in a purity level for metal prices.
66
+ - `math` <[string]> Optional. Pass in a math expression to apply to the rates.
34
67
 
35
68
  ```ruby
36
- client.fetchLive(base='USD', currencies=['XAU', 'XAG', 'XPD', 'XPT'])
69
+ client.fetchLive('USD', ['XAU', 'XAG', 'XPD', 'XPT'], 'troy_oz')
37
70
  ```
38
71
 
39
72
  [Link](https://metalpriceapi.com/documentation#api_realtime)
40
73
 
41
74
  ---
42
- #### fetchHistorical(date, base, currencies)
75
+ #### fetchHistorical(date, base, currencies, unit)
43
76
 
44
77
  - `date` <[string]> Required. Pass in a string with format `YYYY-MM-DD`
45
78
  - `base` <[string]> Optional. Pass in a base currency, defaults to USD.
46
79
  - `currencies` <[Array]<[string]>> Optional. Pass in an array of currencies to return values for.
80
+ - `unit` <[string]> Optional. Pass in a unit for metal prices (e.g. `troy_oz`, `gram`, `kilogram`).
47
81
 
48
82
  ```ruby
49
- client.fetchHistorical(date='2021-04-05', base='USD', currencies=['XAU', 'XAG', 'XPD', 'XPT'])
83
+ client.fetchHistorical('2024-02-05', 'USD', ['XAU', 'XAG', 'XPD', 'XPT'], 'troy_oz')
50
84
  ```
51
85
 
52
86
  [Link](https://metalpriceapi.com/documentation#api_historical)
53
87
 
54
88
  ---
55
- #### fetchOHLC(base, currency, date, unit, dateType)
89
+ #### hourly(base, currency, unit, start_date, end_date, math, date_type)
90
+
91
+ - `base` <[string]> Optional. Pass in a base currency, defaults to USD.
92
+ - `currency` <[string]> Required. Specify currency you would like to get hourly rates for.
93
+ - `unit` <[string]> Optional. Pass in a unit for metal prices (e.g. `troy_oz`, `gram`, `kilogram`).
94
+ - `start_date` <[string]> Required. Specify the start date using the format `YYYY-MM-DD`.
95
+ - `end_date` <[string]> Required. Specify the end date using the format `YYYY-MM-DD`.
96
+ - `math` <[string]> Optional. Pass in a math expression to apply to the rates.
97
+ - `date_type` <[string]> Optional. Pass in a date type, overrides date parameters if passed in.
98
+
99
+ ```ruby
100
+ client.hourly('USD', 'XAU', 'troy_oz', '2025-11-03', '2025-11-03')
101
+ ```
102
+
103
+ [Link](https://metalpriceapi.com/documentation#api_hourly)
104
+
105
+ ---
106
+ #### fetchOHLC(base, currency, date, unit, date_type)
56
107
 
57
108
  - `base` <[string]> Optional. Pass in a base currency, defaults to USD.
58
109
  - `currency` <[string]> Required. Specify currency you would like to get OHLC for.
@@ -61,60 +112,65 @@ client.fetchHistorical(date='2021-04-05', base='USD', currencies=['XAU', 'XAG',
61
112
  - `date_type` <[string]> Optional. Pass in a date type, overrides date parameter if passed in.
62
113
 
63
114
  ```ruby
64
- client.fetchOHLC(base='USD', currency='XAU', date='2024-02-05', unit='troy_oz', date_type=nil)
115
+ client.fetchOHLC('USD', 'XAU', '2024-02-06', 'troy_oz')
65
116
  ```
66
117
 
67
118
  [Link](https://metalpriceapi.com/documentation#api_ohlc)
68
119
 
69
120
  ---
70
- #### convert(from_currency, to_currency, amount, date)
121
+ #### convert(from_currency, to_currency, amount, date, unit)
71
122
 
72
123
  - `from_currency` <[string]> Optional. Pass in a base currency, defaults to USD.
73
124
  - `to_currency` <[string]> Required. Specify currency you would like to convert to.
74
125
  - `amount` <[number]> Required. The amount to convert.
75
126
  - `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.
127
+ - `unit` <[string]> Optional. Pass in a unit for metal prices (e.g. `troy_oz`, `gram`, `kilogram`).
76
128
 
77
129
  ```ruby
78
- client.convert(from_currency='USD', to_currency='EUR', amount=100, date='2021-04-05')
130
+ client.convert('USD', 'EUR', 100, '2024-02-05')
79
131
  ```
80
132
 
81
133
  [Link](https://metalpriceapi.com/documentation#api_convert)
82
134
 
83
135
  ---
84
- #### timeframe(start_date, end_date, base, currencies)
136
+ #### timeframe(start_date, end_date, base, currencies, unit)
85
137
 
86
138
  - `start_date` <[string]> Required. Specify the start date of your timeframe using the format `YYYY-MM-DD`.
87
139
  - `end_date` <[string]> Required. Specify the end date of your timeframe using the format `YYYY-MM-DD`.
88
140
  - `base` <[string]> Optional. Pass in a base currency, defaults to USD.
89
141
  - `currencies` <[Array]<[string]>> Optional. Pass in an array of currencies to return values for.
142
+ - `unit` <[string]> Optional. Pass in a unit for metal prices (e.g. `troy_oz`, `gram`, `kilogram`).
90
143
 
91
144
  ```ruby
92
- client.timeframe(start_date='2021-04-05', end_date='2021-04-06', base='USD', currencies=['XAU', 'XAG', 'XPD', 'XPT'])
145
+ client.timeframe('2024-02-05', '2024-02-06', 'USD', ['XAU', 'XAG', 'XPD', 'XPT'], 'troy_oz')
93
146
  ```
94
147
 
95
148
  [Link](https://metalpriceapi.com/documentation#api_timeframe)
96
149
 
97
150
  ---
98
- #### change(start_date, end_date, base, currencies)
151
+ #### change(start_date, end_date, base, currencies, date_type)
99
152
 
100
153
  - `start_date` <[string]> Required. Specify the start date of your timeframe using the format `YYYY-MM-DD`.
101
154
  - `end_date` <[string]> Required. Specify the end date of your timeframe using the format `YYYY-MM-DD`.
102
155
  - `base` <[string]> Optional. Pass in a base currency, defaults to USD.
103
156
  - `currencies` <[Array]<[string]>> Optional. Pass in an array of currencies to return values for.
157
+ - `date_type` <[string]> Optional. Pass in a date type, overrides date parameters if passed in.
104
158
 
105
159
  ```ruby
106
- client.change(start_date='2021-04-05', end_date='2021-04-06', base='USD', currencies=['XAU', 'XAG', 'XPD', 'XPT'])
160
+ client.change('2024-02-05', '2024-02-06', 'USD', ['XAU', 'XAG', 'XPD', 'XPT'])
107
161
  ```
108
162
 
109
163
  [Link](https://metalpriceapi.com/documentation#api_change)
164
+
110
165
  ---
111
- #### carat(start_date, end_date, base, currencies)
166
+ #### carat(base, currency, date)
112
167
 
113
168
  - `base` <[string]> Optional. Pass in a base currency, defaults to USD.
169
+ - `currency` <[string]> Optional. Pass in a metal code to get carat prices for (defaults to XAU).
114
170
  - `date` <[string]> Optional. Specify date to get Carat for specific date using format `YYYY-MM-DD`. If not specified, uses live rates.
115
171
 
116
172
  ```ruby
117
- client.carat(base='USD', date='2021-04-06')
173
+ client.carat('USD', 'XAU', '2024-02-06')
118
174
  ```
119
175
 
120
176
  [Link](https://metalpriceapi.com/documentation#api_carat)
@@ -128,6 +184,9 @@ client.usage()
128
184
 
129
185
  [Link](https://metalpriceapi.com/documentation#api_usage)
130
186
 
187
+ ---
188
+ **[Official documentation](https://metalpriceapi.com/documentation)**
189
+
131
190
  ---
132
191
  ## FAQ
133
192
 
@@ -13,6 +13,15 @@ module MetalpriceAPI
13
13
  send("#{key}=", options[key] || MetalpriceAPI.config.send(key))
14
14
  end
15
15
  @logger ||= MetalpriceAPI::Logger.logger
16
+ # If server was explicitly passed, update endpoint accordingly
17
+ if options.key?(:server)
18
+ self.endpoint = MetalpriceAPI::SERVERS.fetch(options[:server], MetalpriceAPI::SERVERS['us'])
19
+ end
20
+ end
21
+
22
+ def setServer(server)
23
+ self.endpoint = MetalpriceAPI::SERVERS.fetch(server, MetalpriceAPI::SERVERS['us'])
24
+ @connection = nil # reset memoized connection
16
25
  end
17
26
 
18
27
  class << self
@@ -1,12 +1,18 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module MetalpriceAPI
4
+ SERVERS = {
5
+ 'us' => 'https://api.metalpriceapi.com/v1',
6
+ 'eu' => 'https://api-eu.metalpriceapi.com/v1',
7
+ }.freeze
8
+
4
9
  module Config
5
10
  extend self
6
11
 
7
12
  ATTRIBUTES = %i[
8
13
  endpoint
9
14
  api_key
15
+ server
10
16
  proxy
11
17
  user_agent
12
18
  ca_path
@@ -19,7 +25,8 @@ module MetalpriceAPI
19
25
  attr_accessor(*Config::ATTRIBUTES)
20
26
 
21
27
  def reset
22
- self.endpoint = 'https://api.metalpriceapi.com/v1'
28
+ self.server = 'us'
29
+ self.endpoint = MetalpriceAPI::SERVERS['us']
23
30
  self.api_key = nil
24
31
  self.user_agent = "MetalpriceAPI Ruby Client/#{MetalpriceAPI::VERSION}"
25
32
  self.ca_path = defined?(OpenSSL) ? OpenSSL::X509::DEFAULT_CERT_DIR : nil
@@ -29,6 +36,11 @@ module MetalpriceAPI
29
36
  self.timeout = nil
30
37
  self.open_timeout = nil
31
38
  end
39
+
40
+ def server=(value)
41
+ @server = value
42
+ self.endpoint = MetalpriceAPI::SERVERS.fetch(value, MetalpriceAPI::SERVERS['us'])
43
+ end
32
44
  end
33
45
 
34
46
  class << self
@@ -6,67 +6,88 @@ module MetalpriceAPI
6
6
  get('symbols')
7
7
  end
8
8
 
9
- def fetchLive(base = nil, currencies = nil)
9
+ def fetchLive(base = nil, currencies = nil, unit = nil, purity = nil, math = nil)
10
10
  options = removeEmpty({
11
11
  base: base,
12
- currencies: (currencies || []).join(',')
12
+ currencies: (currencies || []).join(','),
13
+ unit: unit,
14
+ purity: purity,
15
+ math: math,
13
16
  })
14
17
  get('latest', options)
15
18
  end
16
19
 
17
- def fetchHistorical(date, base = nil, currencies = nil)
20
+ def fetchHistorical(date, base = nil, currencies = nil, unit = nil)
18
21
  options = removeEmpty({
19
22
  base: base,
20
- currencies: (currencies || []).join(',')
23
+ currencies: (currencies || []).join(','),
24
+ unit: unit,
21
25
  })
22
26
  get(date, options)
23
27
  end
24
28
 
29
+ def hourly(base = nil, currency = nil, unit = nil, start_date = nil, end_date = nil, math = nil, date_type = nil)
30
+ options = removeEmpty({
31
+ base: base,
32
+ currency: currency,
33
+ unit: unit,
34
+ start_date: start_date,
35
+ end_date: end_date,
36
+ math: math,
37
+ date_type: date_type,
38
+ })
39
+ get('hourly', options)
40
+ end
41
+
25
42
  def fetchOHLC(base = nil, currency = nil, date = nil, unit = nil, date_type = nil)
26
43
  options = removeEmpty({
27
44
  base: base,
28
45
  currency: currency,
29
46
  date: date,
30
47
  unit: unit,
31
- date_type: dateType
48
+ date_type: date_type,
32
49
  })
33
50
  get('ohlc', options)
34
51
  end
35
52
 
36
- def convert(from_currency = nil, to_currency = nil, amount = nil, date = nil)
53
+ def convert(from_currency = nil, to_currency = nil, amount = nil, date = nil, unit = nil)
37
54
  options = removeEmpty({
38
55
  'from': from_currency,
39
56
  'to': to_currency,
40
57
  'amount': amount,
41
- 'date': date
58
+ 'date': date,
59
+ 'unit': unit,
42
60
  })
43
61
  get('convert', options)
44
62
  end
45
63
 
46
- def timeframe(start_date, end_date, base = nil, currencies = nil)
64
+ def timeframe(start_date, end_date, base = nil, currencies = nil, unit = nil)
47
65
  options = removeEmpty({
48
66
  'start_date': start_date,
49
67
  'end_date': end_date,
50
68
  'base': base,
51
- 'currencies': (currencies || []).join(',')
69
+ 'currencies': (currencies || []).join(','),
70
+ 'unit': unit,
52
71
  })
53
72
  get('timeframe', options)
54
73
  end
55
74
 
56
- def change(start_date, end_date, base = '', currencies = nil)
75
+ def change(start_date, end_date, base = nil, currencies = nil, date_type = nil)
57
76
  options = removeEmpty({
58
77
  'start_date': start_date,
59
78
  'end_date': end_date,
60
79
  'base': base,
61
- 'currencies': (currencies || []).join(',')
80
+ 'currencies': (currencies || []).join(','),
81
+ 'date_type': date_type,
62
82
  })
63
83
  get('change', options)
64
84
  end
65
85
 
66
- def carat(base = '', date = nil)
86
+ def carat(base = nil, currency = nil, date = nil)
67
87
  options = removeEmpty({
68
88
  'base': base,
69
- 'date': date
89
+ 'currency': currency,
90
+ 'date': date,
70
91
  })
71
92
  get('carat', options)
72
93
  end
@@ -79,7 +100,7 @@ module MetalpriceAPI
79
100
 
80
101
  def removeEmpty(options)
81
102
  options.each do |key, value|
82
- if (!value || value == '')
103
+ if (value.nil? || value == '')
83
104
  options.delete(key)
84
105
  end
85
106
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module MetalpriceAPI
4
- VERSION = '1.1.2'
4
+ VERSION = '1.3.0'
5
5
  end
metadata CHANGED
@@ -1,19 +1,22 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: metalpriceapi
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.1.2
4
+ version: 1.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - MetalpriceAPI
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2025-02-03 00:00:00.000000000 Z
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@metalpriceapi.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: '0'
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.1.6
86
+ rubygems_version: 3.5.22
81
87
  signing_key:
82
88
  specification_version: 4
83
89
  summary: Official MetalpriceAPI Ruby client.