module OnebusawaySDK::Internal::Util

def encode_content(headers, body)

Returns:
  • (Object) -

Parameters:
  • body (Object) --
  • headers (Hash{String=>String}) --

Other tags:
    Api: - private
def encode_content(headers, body)
  content_type = headers["content-type"]
  case [content_type, body]
  in [OnebusawaySDK::Internal::Util::JSON_CONTENT, Hash | Array | -> { primitive?(_1) }]
    [headers, JSON.generate(body)]
  in [OnebusawaySDK::Internal::Util::JSONL_CONTENT, Enumerable] unless body.is_a?(OnebusawaySDK::Internal::Type::FileInput)
    [headers, body.lazy.map { JSON.generate(_1) }]
  in [%r{^multipart/form-data}, Hash | OnebusawaySDK::Internal::Type::FileInput]
    boundary, strio = encode_multipart_streaming(body)
    headers = {**headers, "content-type" => "#{content_type}; boundary=#{boundary}"}
    [headers, strio]
  in [_, Symbol | Numeric]
    [headers, body.to_s]
  in [_, StringIO]
    [headers, body.string]
  in [_, OnebusawaySDK::FilePart]
    [headers, body.content]
  else
    [headers, body]
  end
end