Class: LHC::Request

Inherits:
Object
  • Object
show all
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

Instance Method Summary collapse

Constructor Details

#initialize(options, self_executing = true) ⇒ Request

Returns a new instance of Request.



15
16
17
18
19
20
21
22
23
24
25
26
27
# File 'lib/lhc/request.rb', line 15

def initialize(options, self_executing = true)
  self.errors_ignored = options.fetch(:ignored_errors, [])
  self.options = options.deep_dup || {}
  self.error_handler = options.delete :error_handler
  self.format = options.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_handlerObject

Returns the value of attribute error_handler.



13
14
15
# File 'lib/lhc/request.rb', line 13

def error_handler
  @error_handler
end

#errors_ignoredObject

Returns the value of attribute errors_ignored.



13
14
15
# File 'lib/lhc/request.rb', line 13

def errors_ignored
  @errors_ignored
end

#formatObject

Returns the value of attribute format.



13
14
15
# File 'lib/lhc/request.rb', line 13

def format
  @format
end

#optionsObject

Returns the value of attribute options.



13
14
15
# File 'lib/lhc/request.rb', line 13

def options
  @options
end

#rawObject

Returns the value of attribute raw.



13
14
15
# File 'lib/lhc/request.rb', line 13

def raw
  @raw
end

#responseObject

Returns the value of attribute response.



13
14
15
# File 'lib/lhc/request.rb', line 13

def response
  @response
end

Instance Method Details

#error_ignored?Boolean

Returns:

  • (Boolean)


45
46
47
# File 'lib/lhc/request.rb', line 45

def error_ignored?
  ignore_error?
end

#headersObject



37
38
39
# File 'lib/lhc/request.rb', line 37

def headers
  raw.options.fetch(:headers, nil) || raw.options[:headers] = {}
end

#methodObject



33
34
35
# File 'lib/lhc/request.rb', line 33

def method
  (raw.options[:method] || options[:method] || :get).to_sym
end

#paramsObject



41
42
43
# File 'lib/lhc/request.rb', line 41

def params
  raw.options.fetch(:params, nil) || raw.options[:params] = {}
end

#run!Object



49
50
51
# File 'lib/lhc/request.rb', line 49

def run!
  raw.run
end

#urlObject



29
30
31
# File 'lib/lhc/request.rb', line 29

def url
  raw.base_url || options[:url]
end