Class: Faraday::ParamPart

Inherits:
Object
  • Object
show all
Defined in:
lib/faraday/param_part.rb

Overview

Multipart value used to POST data with a content type.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(value, content_type, content_id = nil) ⇒ Faraday::ParamPart

Parameters:

  • value (String)

    Uploaded content as a String.

  • content_type (String)

    String content type of the value.

  • content_id (String) (defaults to: nil)

    Optional String of this value's Content-ID.


11
12
13
14
15
# File 'lib/faraday/param_part.rb', line 11

def initialize(value, content_type, content_id = nil)
  @value = value
  @content_type = content_type
  @content_id = content_id
end

Instance Attribute Details

#content_idString? (readonly)

The value's content ID, if given.

Returns:

  • (String, nil)

51
52
53
# File 'lib/faraday/param_part.rb', line 51

def content_id
  @content_id
end

#content_typeString (readonly)

The value's content type.

Returns:

  • (String)

46
47
48
# File 'lib/faraday/param_part.rb', line 46

def content_type
  @content_type
end

#valueString (readonly)

The content to upload.

Returns:

  • (String)

41
42
43
# File 'lib/faraday/param_part.rb', line 41

def value
  @value
end

Instance Method Details

#headersHash

Returns a Hash of String key/value pairs.

Returns:

  • (Hash)

31
32
33
34
35
36
# File 'lib/faraday/param_part.rb', line 31

def headers
  {
    'Content-Type' => content_type,
    'Content-ID' => content_id
  }
end

#to_part(boundary, key) ⇒ Faraday::Parts::Part

Converts this value to a form part.

Parameters:

  • boundary (String)

    String multipart boundary that must not exist in the content exactly.

  • key (String)

    String key name for this value.

Returns:

  • (Faraday::Parts::Part)

24
25
26
# File 'lib/faraday/param_part.rb', line 24

def to_part(boundary, key)
  Faraday::Parts::Part.new(boundary, key, value, headers)
end