Class: LHC::Request
- Inherits:
-
Object
- Object
- LHC::Request
- Defined in:
- lib/lhc/request.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.
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.
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
- #url ⇒ Object
Constructor Details
#initialize(options, self_executing = true) ⇒ Request
Returns a new instance of Request.
13 14 15 16 17 18 19 20 21 22 23 24 25 |
# File 'lib/lhc/request.rb', line 13 def initialize(, self_executing = true) self.errors_ignored = .fetch(:ignored_errors, []) self. = .deep_dup || {} self.error_handler = .delete :error_handler self.format = .delete('format') || LHC::Formats::JSON.new 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) run! if self_executing && !response end |
Instance Attribute Details
#error_handler ⇒ Object
Returns the value of attribute error_handler.
11 12 13 |
# File 'lib/lhc/request.rb', line 11 def error_handler @error_handler end |
#errors_ignored ⇒ Object
Returns the value of attribute errors_ignored.
11 12 13 |
# File 'lib/lhc/request.rb', line 11 def errors_ignored @errors_ignored end |
#format ⇒ Object
Returns the value of attribute format.
11 12 13 |
# File 'lib/lhc/request.rb', line 11 def format @format end |
#options ⇒ Object
Returns the value of attribute options.
11 12 13 |
# File 'lib/lhc/request.rb', line 11 def @options end |
#raw ⇒ Object
Returns the value of attribute raw.
11 12 13 |
# File 'lib/lhc/request.rb', line 11 def raw @raw end |
#response ⇒ Object
Returns the value of attribute response.
11 12 13 |
# File 'lib/lhc/request.rb', line 11 def response @response end |
Instance Method Details
#error_ignored? ⇒ Boolean
43 44 45 |
# File 'lib/lhc/request.rb', line 43 def error_ignored? ignore_error? end |
#headers ⇒ Object
35 36 37 |
# File 'lib/lhc/request.rb', line 35 def headers raw..fetch(:headers, nil) || raw.[:headers] = {} end |
#method ⇒ Object
31 32 33 |
# File 'lib/lhc/request.rb', line 31 def method (raw.[:method] || [:method] || :get).to_sym end |
#params ⇒ Object
39 40 41 |
# File 'lib/lhc/request.rb', line 39 def params raw..fetch(:params, nil) || raw.[:params] = {} end |
#run! ⇒ Object
47 48 49 |
# File 'lib/lhc/request.rb', line 47 def run! raw.run end |
#url ⇒ Object
27 28 29 |
# File 'lib/lhc/request.rb', line 27 def url raw.base_url || [:url] end |