Sha256: 0490305f4156b4e8980f781c931b58ec4d8067fe670a7826ac1e6566a94f4377

Contents?: true

Size: 974 Bytes

Versions: 1

Compression:

Stored size: 974 Bytes

Contents

# frozen_string_literal: true

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

module EodFacade
  class Eod < ::EodFacade::Base
    class << self
      def call(symbol, params = {})
        unless Cache::RedisCache.get(redis_key(symbol, params[:from], params[:to]))
          raise "NISHANT"
          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, params[:from], params[:to]),
            response.parsed_response.to_json
          )
        end

        Oj.load(Cache::RedisCache.get(redis_key(symbol, params[:from], params[:to])))
      end

      private

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

      def redis_key(symbol, from, to)
        "#{symbol}_#{from || ''}_#{to || ''}_eod"
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
sensei_eod_utils-0.0.46 lib/eod_facade/eod.rb