Class: Freno::Client::Request

Inherits:
Object
  • Object
show all
Includes:
Preconditions
Defined in:
lib/freno/client/request.rb

Constant Summary

Constants included from Preconditions

Preconditions::PreconditionNotMet

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Preconditions

check

Constructor Details

#initialize(**kwargs) ⇒ Request

Returns a new instance of Request.



18
19
20
21
22
23
24
25
# File 'lib/freno/client/request.rb', line 18

def initialize(**kwargs)
  @args    = kwargs
  @faraday = kwargs.delete(:faraday) || nil
  @options = kwargs.delete(:options) || {}

  @raise_on_timeout = options.fetch(:raise_on_timeout, true)
  @verb = options.fetch(:verb, :head)
end

Instance Attribute Details

#argsObject (readonly)

Returns the value of attribute args.



12
13
14
# File 'lib/freno/client/request.rb', line 12

def args
  @args
end

#faradayObject (readonly)

Returns the value of attribute faraday.



12
13
14
# File 'lib/freno/client/request.rb', line 12

def faraday
  @faraday
end

#optionsObject (readonly)

Returns the value of attribute options.



12
13
14
# File 'lib/freno/client/request.rb', line 12

def options
  @options
end

#raise_on_timeoutObject (readonly)

Returns the value of attribute raise_on_timeout.



12
13
14
# File 'lib/freno/client/request.rb', line 12

def raise_on_timeout
  @raise_on_timeout
end

Class Method Details

.perform(**kwargs) ⇒ Object



14
15
16
# File 'lib/freno/client/request.rb', line 14

def self.perform(**kwargs)
  new(**kwargs).perform
end

Instance Method Details

#performObject



27
28
29
30
31
32
33
34
35
36
# File 'lib/freno/client/request.rb', line 27

def perform
  response = request(verb, path, params)
  process_response(response)
rescue Faraday::TimeoutError => error
  raise Freno::Error, error if raise_on_timeout

  Result.from_meaning(:request_timeout)
rescue StandardError => error
  raise Freno::Error, error
end