Sha256: fc0f8d87d35a10d8c10814e64fbe607872ab8c5d1fbc769a0b7d5668b3779674

Contents?: true

Size: 822 Bytes

Versions: 3

Compression:

Stored size: 822 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 = {})
        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.to_json
          )
        end

        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

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
sensei_eod_utils-0.0.43 lib/eod_facade/eod.rb
sensei_eod_utils-0.0.42 lib/eod_facade/eod.rb
sensei_eod_utils-0.0.41 lib/eod_facade/eod.rb