Class: Datadog::Core::Vendor::Multipart::Post::Parts::ParamPart

Inherits:
Object
  • Object
show all
Includes:
Part
Defined in:
lib/datadog/core/vendor/multipart-post/multipart/post/parts.rb

Overview

Represents a parametric part to be filled with given value.

Instance Method Summary collapse

Methods included from Part

file?, new, #to_io

Constructor Details

#initialize(boundary, name, value, headers = {}) ⇒ ParamPart

Returns a new instance of ParamPart.

Parameters:

  • boundary (String)
  • name (#to_s)
  • value (String)
  • headers (Hash) (defaults to: {})

    Content-Type and Content-ID are used, if present.



44
45
46
47
# File 'lib/datadog/core/vendor/multipart-post/multipart/post/parts.rb', line 44

def initialize(boundary, name, value, headers = {})
  @part = build_part(boundary, name, value, headers)
  @io = StringIO.new(@part)
end

Instance Method Details

#build_part(boundary, name, value, headers = {}) ⇒ Object

Parameters:

  • boundary (String)
  • name (#to_s)
  • value (String)
  • headers (Hash) (defaults to: {})

    Content-Type is used, if present.



57
58
59
60
61
62
63
64
65
# File 'lib/datadog/core/vendor/multipart-post/multipart/post/parts.rb', line 57

def build_part(boundary, name, value, headers = {})
  part = ''
  part << "--#{boundary}\r\n"
  part << "Content-ID: #{headers["Content-ID"]}\r\n" if headers["Content-ID"]
  part << "Content-Disposition: form-data; name=\"#{name.to_s}\"\r\n"
  part << "Content-Type: #{headers["Content-Type"]}\r\n" if headers["Content-Type"]
  part << "\r\n"
  part << "#{value}\r\n"
end

#lengthObject



49
50
51
# File 'lib/datadog/core/vendor/multipart-post/multipart/post/parts.rb', line 49

def length
  @part.bytesize
end