Sha256: 4d4e7894f87ab4367ce582267fbb1c023ac9684d53c068dbd8a84b53b3a1d372

Contents?: true

Size: 753 Bytes

Versions: 7

Compression:

Stored size: 753 Bytes

Contents

module CurrencyRate
  class ForgeAdapter < Adapter
    SUPPORTED_CURRENCIES = %w(
      JPY CHF CAD SEK NOK MXN ZAR TRY CNH EUR GBP AUD NZD XAU XAG
    )

    ANCHOR_CURRENCY = "USD"
    FETCH_URL = "https://forex.1forge.com/1.0.2/quotes?pairs=" + SUPPORTED_CURRENCIES.map { |c| "#{ANCHOR_CURRENCY}#{c}" }.join(",")
    API_KEY_PARAM = "api_key"

    def normalize(data)
      return nil unless super
      rates = { "anchor" => self.class::ANCHOR_CURRENCY }
      data.each do |rate|
        if rate["error"]
          CurrencyRate.logger.error("Forge exchange returned error")
          return nil
        end
        rates[rate["symbol"].sub(self.class::ANCHOR_CURRENCY, "")] = BigDecimal(rate["price"].to_s)
      end
      rates
    end

  end
end

Version data entries

7 entries across 7 versions & 1 rubygems

Version Path
currency-rate-1.7.0 lib/adapters/fiat/forge_adapter.rb
currency-rate-1.6.1 lib/adapters/fiat/forge_adapter.rb
currency-rate-1.6.0 lib/adapters/fiat/forge_adapter.rb
currency-rate-1.5.4 lib/adapters/fiat/forge_adapter.rb
currency-rate-1.5.3 lib/adapters/fiat/forge_adapter.rb
currency-rate-1.5.2 lib/adapters/fiat/forge_adapter.rb
currency-rate-1.5.1 lib/adapters/fiat/forge_adapter.rb