Class: OpenReceive::Rates::HttpSimplePriceProvider

Inherits:
Object
  • Object
show all
Defined in:
lib/openreceive/rates.rb

Overview

Fetches a Simple Price compatible HTTP endpoint and selects the requested fiat currencies. When timeout_ms is set, a slow endpoint fails within that window so the caller can fall through to another feed.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(url:, source:, http: nil, timeout_ms: nil) ⇒ HttpSimplePriceProvider

Returns a new instance of HttpSimplePriceProvider.



245
246
247
248
249
250
# File 'lib/openreceive/rates.rb', line 245

def initialize(url:, source:, http: nil, timeout_ms: nil)
  @url = url
  @source = source
  @http = http
  @timeout_ms = timeout_ms
end

Instance Attribute Details

#sourceObject (readonly)

Returns the value of attribute source.



243
244
245
# File 'lib/openreceive/rates.rb', line 243

def source
  @source
end

#timeout_msObject (readonly)

Returns the value of attribute timeout_ms.



243
244
245
# File 'lib/openreceive/rates.rb', line 243

def timeout_ms
  @timeout_ms
end

#urlObject (readonly)

Returns the value of attribute url.



243
244
245
# File 'lib/openreceive/rates.rb', line 243

def url
  @url
end

Instance Method Details

#all_btc_fiat_ratesObject

Returns every well-formed currency the endpoint carries, for caching the whole feed in one read.



258
259
260
# File 'lib/openreceive/rates.rb', line 258

def all_btc_fiat_rates
  Rates.parse_available_simple_price_response(fetch_json)
end

#btc_fiat_rates(currencies) ⇒ Object



252
253
254
# File 'lib/openreceive/rates.rb', line 252

def btc_fiat_rates(currencies)
  Rates.parse_simple_price_response(fetch_json, currencies)
end