Class: TShield::Request

Inherits:
Object
  • Object
show all
Defined in:
lib/tshield/request.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(path, options = {}) ⇒ Request

Returns a new instance of Request.



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

def initialize(path, options = {})
  @path = path
  @options = options 
  @configuration = TShield::Configuration.singleton
  @options[:timeout] =  @configuration.request['timeout']
  @options[:verify] =  @configuration.request['verify_ssl']
  request
end

Instance Attribute Details

#responseObject (readonly)

Returns the value of attribute response.



16
17
18
# File 'lib/tshield/request.rb', line 16

def response
  @response
end

Instance Method Details

#requestObject



27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
# File 'lib/tshield/request.rb', line 27

def request
  if not (@options[:raw_query].nil? or @options[:raw_query].empty?)
    @path = "#{@path}?#{@options[:raw_query]}"
  end

  @url = "#{domain}#{@path}"

  if exists
    @response = get_current_response  
    @response.original = false
  else
    @method = method
    @configuration.get_before_filters(domain).each do |filter|
      @method, @url, @options = filter.new.filter(@method, @url, @options)
    end

    raw = HTTParty.send("#{@method}", @url, @options)

    @configuration.get_after_filters(domain).each do |filter|
      raw = filter.new.filter(raw)
    end

    @response = save(raw)

    @response.original = true
  end
  current_session[:counter].add(@path, method) if current_session
  debugger if TShield::Options.instance.break?(path: @path, moment: :after)
  @response
end