Class: Simple::HTTP::Request
- Inherits:
-
Object
- Object
- Simple::HTTP::Request
- Defined in:
- lib/simple/http/request.rb
Instance Attribute Summary collapse
-
#body ⇒ Object
readonly
Returns the value of attribute body.
-
#headers ⇒ Object
readonly
Returns the value of attribute headers.
-
#url ⇒ Object
readonly
Returns the value of attribute url.
-
#verb ⇒ Object
readonly
Returns the value of attribute verb.
Class Method Summary collapse
Instance Method Summary collapse
Instance Attribute Details
#body ⇒ Object (readonly)
Returns the value of attribute body.
2 3 4 |
# File 'lib/simple/http/request.rb', line 2 def body @body end |
#headers ⇒ Object (readonly)
Returns the value of attribute headers.
2 3 4 |
# File 'lib/simple/http/request.rb', line 2 def headers @headers end |
#url ⇒ Object (readonly)
Returns the value of attribute url.
2 3 4 |
# File 'lib/simple/http/request.rb', line 2 def url @url end |
#verb ⇒ Object (readonly)
Returns the value of attribute verb.
2 3 4 |
# File 'lib/simple/http/request.rb', line 2 def verb @verb end |
Class Method Details
.build(verb:, url:, body: nil, headers:) ⇒ Object
5 6 7 8 9 10 11 12 13 14 |
# File 'lib/simple/http/request.rb', line 5 def build(verb:, url:, body: nil, headers:) if body_permitted?(verb) && !headers.key?("Content-Type") if body.is_a?(Hash) || body.is_a?(Array) headers["Content-Type"] = "application/json" body = JSON.generate(body) end end new verb, url, body, headers end |
Instance Method Details
#to_s ⇒ Object
36 37 38 39 |
# File 'lib/simple/http/request.rb', line 36 def to_s scrubbed_url = url.gsub(/\/\/(.*):(.*)@/) { |_| "//#{$1}:xxxxxx@" } "#{verb} #{scrubbed_url}" end |