Class: LHC::Request

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

Constant Summary collapse

TYPHOEUS_OPTIONS =
[:params, :method, :body, :headers, :follow_location]

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(options, self_executing = true) ⇒ Request

Returns a new instance of Request.



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

def initialize(options, self_executing = true)
  self.options = options.deep_dup || {}
  use_configured_endpoint!
  generate_url_from_template!
  self.iprocessor = LHC::InterceptorProcessor.new(self)
  self.raw = create_request
  self.format = options.delete('format') || JsonFormat.new
  iprocessor.intercept(:before_request, self)
  raw.run if self_executing && !response
end

Instance Attribute Details

#formatObject

Returns the value of attribute format.



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

def format
  @format
end

#optionsObject

Returns the value of attribute options.



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

def options
  @options
end

#rawObject

Returns the value of attribute raw.



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

def raw
  @raw
end

#responseObject

Returns the value of attribute response.



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

def response
  @response
end

Instance Method Details

#headersObject



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

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

#methodObject



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

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

#paramsObject



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

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

#urlObject



25
26
27
# File 'lib/lhc/request.rb', line 25

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