Sha256: 8d647b7f959f69909bc161211af1e84db4d5cb661db0ac1d210b28c2447a9a05

Contents?: true

Size: 834 Bytes

Versions: 4

Compression:

Stored size: 834 Bytes

Contents

# frozen_string_literal: true

require 'oj'
require_relative '../cache/redis.rb'

module EodFacade
  class Eod < ::EodFacade::Base
    class << self
      def call(symbol, params = {})
        raise Cache::Redis.inspect
        unless Cache::Redis.get(redis_key(symbol))
          response = make_request(url_path(symbol), params.merge(fmt: 'json'))
          
          unless response.success?
            raise ArgumentError, "Error fetching end of day data for #{symbol}"
          end

          Cache::Redis.set(
            redis_key(symbol),
            response.parsed_response
          )
        end

        Oj.load(Cache::Redis.get(redis_key(symbol)))
      end

      private

      def url_path(symbol)
        "/eod/#{symbol}"
      end

      def redis_key(symbol)
        "#{symbol}_eod"
      end
    end
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
sensei_eod_utils-0.0.37 lib/eod_facade/eod.rb
sensei_eod_utils-0.0.36 lib/eod_facade/eod.rb
sensei_eod_utils-0.0.35 lib/eod_facade/eod.rb
sensei_eod_utils-0.0.34 lib/eod_facade/eod.rb