Class: LHC::Request
- Inherits:
-
Object
- Object
- LHC::Request
- Includes:
- UserAgentConcern
- Defined in:
- lib/lhc/request.rb,
lib/lhc/concerns/lhc/request/user_agent_concern.rb
Overview
The request is doing an http-request using typhoeus. It provides functionalities to access and alter request data and it communicates with interceptors.
Defined Under Namespace
Modules: UserAgentConcern
Instance Attribute Summary collapse
-
#error_handler ⇒ Object
Returns the value of attribute error_handler.
-
#errors_ignored ⇒ Object
Returns the value of attribute errors_ignored.
-
#format ⇒ Object
Returns the value of attribute format.
-
#options ⇒ Object
Returns the value of attribute options.
-
#raw ⇒ Object
Returns the value of attribute raw.
-
#response ⇒ Object
Returns the value of attribute response.
-
#source ⇒ Object
Returns the value of attribute source.
Instance Method Summary collapse
- #error_ignored? ⇒ Boolean
- #headers ⇒ Object
-
#initialize(options, self_executing = true) ⇒ Request
constructor
A new instance of Request.
- #method ⇒ Object
- #params ⇒ Object
- #run! ⇒ Object
- #scrubbed_headers ⇒ Object
- #scrubbed_options ⇒ Object
- #scrubbed_params ⇒ Object
- #url ⇒ Object
Constructor Details
#initialize(options, self_executing = true) ⇒ Request
Returns a new instance of Request.
23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 |
# File 'lib/lhc/request.rb', line 23 def initialize(, self_executing = true) self.errors_ignored = (.fetch(:ignore, []) || []).to_a.compact self.source = &.dig(:source) self. = format!(.deep_dup || {}) self.error_handler = .delete :rescue use_configured_endpoint! generate_url_from_template! self.interceptors = LHC::Interceptors.new(self) interceptors.intercept(:before_raw_request) self.raw = create_request interceptors.intercept(:before_request) if self_executing && !response run! elsif response on_complete(response) end end |
Instance Attribute Details
#error_handler ⇒ Object
Returns the value of attribute error_handler.
15 16 17 |
# File 'lib/lhc/request.rb', line 15 def error_handler @error_handler end |
#errors_ignored ⇒ Object
Returns the value of attribute errors_ignored.
15 16 17 |
# File 'lib/lhc/request.rb', line 15 def errors_ignored @errors_ignored end |
#format ⇒ Object
Returns the value of attribute format.
15 16 17 |
# File 'lib/lhc/request.rb', line 15 def format @format end |
#options ⇒ Object
Returns the value of attribute options.
15 16 17 |
# File 'lib/lhc/request.rb', line 15 def @options end |
#raw ⇒ Object
Returns the value of attribute raw.
15 16 17 |
# File 'lib/lhc/request.rb', line 15 def raw @raw end |
#response ⇒ Object
Returns the value of attribute response.
15 16 17 |
# File 'lib/lhc/request.rb', line 15 def response @response end |
#source ⇒ Object
Returns the value of attribute source.
15 16 17 |
# File 'lib/lhc/request.rb', line 15 def source @source end |
Instance Method Details
#error_ignored? ⇒ Boolean
57 58 59 |
# File 'lib/lhc/request.rb', line 57 def error_ignored? ignore_error? end |
#headers ⇒ Object
49 50 51 |
# File 'lib/lhc/request.rb', line 49 def headers raw..fetch(:headers, nil) || raw.[:headers] = {} end |
#method ⇒ Object
45 46 47 |
# File 'lib/lhc/request.rb', line 45 def method (raw.[:method] || [:method] || :get).to_sym end |
#params ⇒ Object
53 54 55 |
# File 'lib/lhc/request.rb', line 53 def params raw..fetch(:params, nil) || raw.[:params] = {} end |
#run! ⇒ Object
61 62 63 |
# File 'lib/lhc/request.rb', line 61 def run! raw.run end |
#scrubbed_headers ⇒ Object
69 70 71 |
# File 'lib/lhc/request.rb', line 69 def scrubbed_headers LHC::HeadersScrubber.new(headers.deep_dup, [:auth]).scrubbed end |
#scrubbed_options ⇒ Object
73 74 75 76 77 78 79 80 81 |
# File 'lib/lhc/request.rb', line 73 def = .deep_dup [:cache] = LHC::CacheScrubber.new([:cache]).scrubbed [:params] = LHC::ParamsScrubber.new([:params]).scrubbed [:headers] = LHC::HeadersScrubber.new([:headers], [:auth]).scrubbed [:auth] = LHC::AuthScrubber.new([:auth]).scrubbed [:body] = LHC::BodyScrubber.new([:body]).scrubbed end |
#scrubbed_params ⇒ Object
65 66 67 |
# File 'lib/lhc/request.rb', line 65 def scrubbed_params LHC::ParamsScrubber.new(params.deep_dup).scrubbed end |
#url ⇒ Object
41 42 43 |
# File 'lib/lhc/request.rb', line 41 def url raw.base_url || [:url] end |