Class: Nsa::NetHttpTracker

Inherits:
Object
  • Object
show all
Defined in:
lib/nsa/net_http_tracker.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(protocol, address, port, path, method, headers, body) ⇒ NetHttpTracker

Returns a new instance of NetHttpTracker.



19
20
21
22
23
24
25
26
27
28
# File 'lib/nsa/net_http_tracker.rb', line 19

def initialize(protocol, address, port, path, method, headers, body)
  @protocol = protocol
  @address = address
  @port = port
  @path = path
  @method = method
  @request_headers = headers
  @request_body = body
  self.class.on_request.call(self)
end

Instance Attribute Details

#addressObject (readonly)

Returns the value of attribute address.



15
16
17
# File 'lib/nsa/net_http_tracker.rb', line 15

def address
  @address
end

#methodObject (readonly)

Returns the value of attribute method.



15
16
17
# File 'lib/nsa/net_http_tracker.rb', line 15

def method
  @method
end

#pathObject (readonly)

Returns the value of attribute path.



15
16
17
# File 'lib/nsa/net_http_tracker.rb', line 15

def path
  @path
end

#portObject (readonly)

Returns the value of attribute port.



15
16
17
# File 'lib/nsa/net_http_tracker.rb', line 15

def port
  @port
end

#protocolObject (readonly)

Returns the value of attribute protocol.



15
16
17
# File 'lib/nsa/net_http_tracker.rb', line 15

def protocol
  @protocol
end

#request_bodyObject (readonly)

Returns the value of attribute request_body.



15
16
17
# File 'lib/nsa/net_http_tracker.rb', line 15

def request_body
  @request_body
end

#request_headersObject (readonly)

Returns the value of attribute request_headers.



15
16
17
# File 'lib/nsa/net_http_tracker.rb', line 15

def request_headers
  @request_headers
end

#response_bodyObject

Returns the value of attribute response_body.



15
16
17
# File 'lib/nsa/net_http_tracker.rb', line 15

def response_body
  @response_body
end

#response_headersObject (readonly)

Returns the value of attribute response_headers.



15
16
17
# File 'lib/nsa/net_http_tracker.rb', line 15

def response_headers
  @response_headers
end

#status_codeObject (readonly)

Returns the value of attribute status_code.



15
16
17
# File 'lib/nsa/net_http_tracker.rb', line 15

def status_code
  @status_code
end

#status_messageObject (readonly)

Returns the value of attribute status_message.



15
16
17
# File 'lib/nsa/net_http_tracker.rb', line 15

def status_message
  @status_message
end

Class Method Details

.on_request(&block) ⇒ Object



6
7
8
9
10
11
12
# File 'lib/nsa/net_http_tracker.rb', line 6

def on_request(&block)
  if block_given?
    @on_request = block
  else
    @on_request
  end
end

Instance Method Details

#on_body(&block) ⇒ Object



42
43
44
45
46
47
48
# File 'lib/nsa/net_http_tracker.rb', line 42

def on_body(&block)
  if block_given?
    @on_body = block
  else
    @on_body
  end
end

#on_response(&block) ⇒ Object



34
35
36
37
38
39
40
# File 'lib/nsa/net_http_tracker.rb', line 34

def on_response(&block)
  if block_given?
    @on_response = block
  else
    @on_response
  end
end

#set_response_info(status_code, status_message, headers) ⇒ Object



50
51
52
53
54
55
# File 'lib/nsa/net_http_tracker.rb', line 50

def set_response_info(status_code, status_message, headers)
  @status_code = status_code
  @status_message = status_message
  @response_headers = headers
  on_response.call
end

#urlObject



30
31
32
# File 'lib/nsa/net_http_tracker.rb', line 30

def url
  "#{protocol}://#{address}#{path}"
end