# 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::RedisCache.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::RedisCache.set( redis_key(symbol), response.parsed_response ) end raise Cache::RedisCache.get(redis_key(symbol)).inspect Oj.load(Cache::RedisCache.get(redis_key(symbol))) end private def url_path(symbol) "/eod/#{symbol}" end def redis_key(symbol) "#{symbol}_eod" end end end end