Sha256: 3bac876283504561890badf2809fa9c301fa4b06ce6b37e2e501b6ea3b160947

Contents?: true

Size: 722 Bytes

Versions: 6

Compression:

Stored size: 722 Bytes

Contents

require_relative "base_client"

module PortalConnectors
  class MakerClient < BaseClient
    def fetch_stocks
      url = "#{host}/stocks"
      res = get_with_signature(url, {})
      json_stocks = JSON.parse(res.body_str)
      self.class.cached_stocks = json_stocks
      [json_stocks, res.response_code == 200]
    rescue => e
      [e.inspect, false]
    end

    def self.cached_stocks=(json_stocks)
      PortalConnectors.redis.set(cached_key_for(["stocks"]), json_stocks.to_json)
    end

    def self.cached_stocks
      cached_key = cached_key_for(["stocks"])
      return nil unless PortalConnectors.redis.exists(cached_key)
      JSON.parse(PortalConnectors.redis.get(cached_key)) rescue nil
    end
  end
end

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
portal-connectors-0.58.39xc lib/portal-connectors/maker_client.rb
portal-connectors-0.58.39xb lib/portal-connectors/maker_client.rb
portal-connectors-0.58.39xa lib/portal-connectors/maker_client.rb
portal-connectors-0.58.39fj lib/portal-connectors/maker_client.rb
portal-connectors-0.58.39fg lib/portal-connectors/maker_client.rb
portal-connectors-0.58.38xn lib/portal-connectors/maker_client.rb