# frozen_string_literal: true require 'oj' require_relative '../cache/redis.rb' module EodFacade class Fundamentals < ::EodFacade::Base class << self def call(symbol) # raise Cache::Redis.inspect unless Cache::Redis.get(redis_key(symbol)) response = make_request(url_path(symbol)) unless response.success? raise ArgumentError, "Error fetching fundamentals 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) "/fundamentals/#{symbol}" end def redis_key(symbol) "#{symbol}_fundamentals" end end end end