class Halo::Client

Public Class Methods

new(options = {}) click to toggle source
# File lib/halo-api/client.rb, line 7
def initialize(options = {})
  options = Halo.options.merge(options)

  Halo::Configuration::OPTIONS.each do |key|
    send("#{key}=", options[key])
  end

  set_up_cache(options.delete(:redis), options.delete(:ttl))
end

Public Instance Methods

cache_store() click to toggle source

Returns an options hash with cache keys @return [Hash]

# File lib/halo-api/client.rb, line 27
def cache_store
  {
    redis: @redis,
    ttl: @ttl,
    cached: @cached
  }
end
cached?() click to toggle source

@return [Boolean] true if the request should be cached

# File lib/halo-api/client.rb, line 36
def cached?
  cache_store[:cached]
end
set_up_cache(redis_url, ttl) click to toggle source
# File lib/halo-api/client.rb, line 17
def set_up_cache(redis_url, ttl)
  return @cached = false unless redis_url

  @ttl = ttl || Halo::Configuration::DEFAULT_TTL
  @cached = true
  @redis = Redis.new url: redis_url
end

Private Instance Methods

merge_options_and_return_obj(options, obj) click to toggle source
# File lib/halo-api/client.rb, line 42
def merge_options_and_return_obj(options, obj)
  opts = options.merge(client: self)
  obj.new(opts)
end