Class: Sarif::WebRequest
- Inherits:
-
Object
- Object
- Sarif::WebRequest
- Defined in:
- lib/sarif/web_request.rb
Overview
Describes an HTTP request.
Instance Attribute Summary collapse
-
#body ⇒ Object
Returns the value of attribute body.
-
#headers ⇒ Object
Returns the value of attribute headers.
-
#index ⇒ Object
Returns the value of attribute index.
-
#method ⇒ Object
Returns the value of attribute method.
-
#parameters ⇒ Object
Returns the value of attribute parameters.
-
#properties ⇒ Object
Returns the value of attribute properties.
-
#protocol ⇒ Object
Returns the value of attribute protocol.
-
#target ⇒ Object
Returns the value of attribute target.
-
#version ⇒ Object
Returns the value of attribute version.
Class Method Summary collapse
Instance Method Summary collapse
- #==(other) ⇒ Object (also: #eql?)
- #hash ⇒ Object
-
#initialize(index: -1,, protocol: nil, version: nil, target: nil, method: nil, headers: nil, parameters: nil, body: nil, properties: nil) ⇒ WebRequest
constructor
A new instance of WebRequest.
- #to_h ⇒ Object
- #to_json(pretty: false) ⇒ Object
Constructor Details
#initialize(index: -1,, protocol: nil, version: nil, target: nil, method: nil, headers: nil, parameters: nil, body: nil, properties: nil) ⇒ WebRequest
Returns a new instance of WebRequest.
8 9 10 11 12 13 14 15 16 17 18 |
# File 'lib/sarif/web_request.rb', line 8 def initialize(index: -1, protocol: nil, version: nil, target: nil, method: nil, headers: nil, parameters: nil, body: nil, properties: nil) @index = index @protocol = protocol @version = version @target = target @method = method @headers = headers @parameters = parameters @body = body @properties = properties end |
Instance Attribute Details
#body ⇒ Object
Returns the value of attribute body.
6 7 8 |
# File 'lib/sarif/web_request.rb', line 6 def body @body end |
#headers ⇒ Object
Returns the value of attribute headers.
6 7 8 |
# File 'lib/sarif/web_request.rb', line 6 def headers @headers end |
#index ⇒ Object
Returns the value of attribute index.
6 7 8 |
# File 'lib/sarif/web_request.rb', line 6 def index @index end |
#method ⇒ Object
Returns the value of attribute method.
6 7 8 |
# File 'lib/sarif/web_request.rb', line 6 def method @method end |
#parameters ⇒ Object
Returns the value of attribute parameters.
6 7 8 |
# File 'lib/sarif/web_request.rb', line 6 def parameters @parameters end |
#properties ⇒ Object
Returns the value of attribute properties.
6 7 8 |
# File 'lib/sarif/web_request.rb', line 6 def properties @properties end |
#protocol ⇒ Object
Returns the value of attribute protocol.
6 7 8 |
# File 'lib/sarif/web_request.rb', line 6 def protocol @protocol end |
#target ⇒ Object
Returns the value of attribute target.
6 7 8 |
# File 'lib/sarif/web_request.rb', line 6 def target @target end |
#version ⇒ Object
Returns the value of attribute version.
6 7 8 |
# File 'lib/sarif/web_request.rb', line 6 def version @version end |
Class Method Details
.from_hash(h) ⇒ Object
38 39 40 41 42 43 44 45 46 47 48 49 50 51 |
# File 'lib/sarif/web_request.rb', line 38 def self.from_hash(h) return nil if h.nil? new( index: h["index"] || -1, protocol: h["protocol"], version: h["version"], target: h["target"], method: h["method"], headers: h["headers"], parameters: h["parameters"], body: ArtifactContent.from_hash(h["body"]), properties: h["properties"] ) end |
Instance Method Details
#==(other) ⇒ Object Also known as: eql?
53 54 55 56 |
# File 'lib/sarif/web_request.rb', line 53 def ==(other) return false unless other.is_a?(WebRequest) @index == other.index && @protocol == other.protocol && @version == other.version && @target == other.target && @method == other.method && @headers == other.headers && @parameters == other.parameters && @body == other.body && @properties == other.properties end |
#hash ⇒ Object
60 61 62 |
# File 'lib/sarif/web_request.rb', line 60 def hash [@index, @protocol, @version, @target, @method, @headers, @parameters, @body, @properties].hash end |
#to_h ⇒ Object
20 21 22 23 24 25 26 27 28 29 30 31 32 |
# File 'lib/sarif/web_request.rb', line 20 def to_h h = {} h["index"] = @index if @index && @index != -1 h["protocol"] = @protocol unless @protocol.nil? h["version"] = @version unless @version.nil? h["target"] = @target unless @target.nil? h["method"] = @method unless @method.nil? h["headers"] = @headers unless @headers.nil? h["parameters"] = @parameters unless @parameters.nil? h["body"] = @body&.to_h unless @body.nil? h["properties"] = @properties unless @properties.nil? h end |
#to_json(pretty: false) ⇒ Object
34 35 36 |
# File 'lib/sarif/web_request.rb', line 34 def to_json(pretty: false) pretty ? JSON.pretty_generate(to_h) : JSON.generate(to_h) end |