Sha256: 93288d8d9de2285621aff66f0fdb114167bb5ecede2f89604fb78057652dc121

Contents?: true

Size: 957 Bytes

Versions: 4

Compression:

Stored size: 957 Bytes

Contents

# frozen_string_literal: true

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

module EodFacade
  class Dividends < ::EodFacade::Base
    class << self
      def call(symbol, params = {})
        unless Cache::RedisCache.get(redis_key(symbol, params[:from], params[:to]))
          response = make_request(url_path(symbol), params.merge(fmt: 'json'))
          
          unless response.success?
            raise ArgumentError, "Error fetching dividend 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)
        "/div/#{symbol}"
      end

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

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
sensei_eod_utils-0.0.53 lib/eod_facade/dividends.rb
sensei_eod_utils-0.0.52 lib/eod_facade/dividends.rb
sensei_eod_utils-0.0.51 lib/eod_facade/dividends.rb
sensei_eod_utils-0.0.50 lib/eod_facade/dividends.rb