Class: LontaraUtilities::HTTPClient::BodyParser

Inherits:
Object
  • Object
show all
Defined in:
lib/lontara_utilities/http_client/body_parser.rb

Overview

Body Parser responsible for parsing body based on content type.

Instance Method Summary collapse

Constructor Details

#initialize(content_type:, body:) ⇒ BodyParser

Returns a new instance of BodyParser.



7
8
9
10
# File 'lib/lontara_utilities/http_client/body_parser.rb', line 7

def initialize(content_type:, body:)
  @content_type = content_type
  @body = body
end

Instance Method Details

#parseObject

Parse body based on content type.



13
14
15
16
17
18
19
20
21
22
# File 'lib/lontara_utilities/http_client/body_parser.rb', line 13

def parse
  case content_type
  when 'application/json'
    body.to_json
  when 'application/x-www-form-urlencoded'
    URI.encode_www_form(body)
  else
    body
  end
end