Class: ConvenientService::Examples::Standard::V1::RequestParams::Utils::HTTP::Request::ParseBody

Inherits:
Command
  • Object
show all
Defined in:
lib/convenient_service/examples/standard/v1/request_params/utils/http/request/parse_body.rb

Overview

TODO: Specs.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(http_string:) ⇒ ParseBody

Returns a new instance of ParseBody.



17
18
19
# File 'lib/convenient_service/examples/standard/v1/request_params/utils/http/request/parse_body.rb', line 17

def initialize(http_string:)
  @http_string = http_string
end

Instance Attribute Details

#http_stringObject (readonly)

Returns the value of attribute http_string.



15
16
17
# File 'lib/convenient_service/examples/standard/v1/request_params/utils/http/request/parse_body.rb', line 15

def http_string
  @http_string
end

Instance Method Details

#callObject



27
28
29
30
31
32
33
34
35
# File 'lib/convenient_service/examples/standard/v1/request_params/utils/http/request/parse_body.rb', line 27

def call
  webrick_request = ::WEBrick::HTTPRequest.new(::WEBrick::Config::HTTP)

  webrick_request.parse(::StringIO.new(http_string))

  webrick_request.body
rescue ::WEBrick::HTTPStatus::BadRequest
  nil
end