Sha256: 34f6abaf8a118b978f05c25f4227a213bbc671d724151111b30629d3ecf5a64b

Contents?: true

Size: 678 Bytes

Versions: 1

Compression:

Stored size: 678 Bytes

Contents

require 'money-distributed'
require 'json'

class Money
  module Distributed
    module Fetcher
      # Currencylayer rates fetcher
      class Currencylayer
        include Base

        API_ENDPOINT = 'http://apilayer.net/api/live'.freeze

        def initialize(api_key, bank = nil)
          super(bank)
          @api_key = api_key
        end

        private

        def exchange_rates
          url = "#{API_ENDPOINT}?access_key=#{@api_key}"
          data = JSON.parse(open(url).read)
          data['quotes'].each_with_object('USD' => 1) do |(code, rate), h|
            h[code[3, 3]] = BigDecimal.new(rate.to_s)
          end
        end
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
money-distributed-currencylayer-0.0.2.1 lib/money/distributed/fetcher/currencylayer.rb