Class: Parts::ParamPart

Inherits:
Object
  • Object
show all
Includes:
Part
Defined in:
lib/tent-client/multipart-post/parts.rb

Instance Method Summary collapse

Methods included from Part

new, #to_io

Constructor Details

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

Returns a new instance of ParamPart.



26
27
28
29
# File 'lib/tent-client/multipart-post/parts.rb', line 26

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

Instance Method Details

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



35
36
37
38
39
40
41
42
43
44
45
46
# File 'lib/tent-client/multipart-post/parts.rb', line 35

def build_part(boundary, name, value, options = {})
  part = []
  part << "--#{boundary}"
  part << %(Content-Disposition: form-data; name="#{name.to_s}")

  (options[:headers] || {}).each do |name, value|
    part << "#{name}: #{value}"
  end

  part.join("\r\n") << "\r\n\r\n"
  part << "#{value}\r\n"
end

#lengthObject



31
32
33
# File 'lib/tent-client/multipart-post/parts.rb', line 31

def length
 @part.bytesize
end