Module: Castle::API::Filter

Defined in:
lib/castle/api/filter.rb

Overview

Module for filter endpoint

Class Method Summary collapse

Class Method Details

.call(options = {}) ⇒ Object

return [Hash]

Parameters:

  • options (Hash) (defaults to: {})


10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
# File 'lib/castle/api/filter.rb', line 10

def call(options = {})
  options = Castle::Utils::DeepSymbolizeKeys.call(options || {}) unless options[:no_symbolize]
  options.delete(:no_symbolize)
  http = options.delete(:http)
  config = options.delete(:config) || Castle.config

  response = Castle::API.call(Castle::Commands::Filter.build(options), {}, http, config)
  response.merge(failover: false, failover_reason: nil)
rescue Castle::RequestError, Castle::InternalServerError => e
  unless config.failover_strategy == :throw
    strategy = (config || Castle.config).failover_strategy
    # `user` is optional on /v1/filter (#279) — fall back to `matching_user_id` then nil.
    user_id = options.dig(:user, :id) || options[:matching_user_id]
    return Castle::Failover::PrepareResponse.new(user_id, reason: e.to_s, strategy: strategy).call
  end

  raise e
end