-
Notifications
You must be signed in to change notification settings - Fork 966
/
param_part.rb
53 lines (47 loc) · 1.33 KB
/
param_part.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
# frozen_string_literal: true
module Faraday
# Multipart value used to POST data with a content type.
class ParamPart
# @param value [String] Uploaded content as a String.
# @param content_type [String] String content type of the value.
# @param content_id [String] Optional String of this value's Content-ID.
#
# @return [Faraday::ParamPart]
def initialize(value, content_type, content_id = nil)
@value = value
@content_type = content_type
@content_id = content_id
end
# Converts this value to a form part.
#
# @param boundary [String] String multipart boundary that must not exist in
# the content exactly.
# @param key [String] String key name for this value.
#
# @return [Faraday::Parts::Part]
def to_part(boundary, key)
Faraday::Parts::Part.new(boundary, key, value, headers)
end
# Returns a Hash of String key/value pairs.
#
# @return [Hash]
def headers
{
'Content-Type' => content_type,
'Content-ID' => content_id
}
end
# The content to upload.
#
# @return [String]
attr_reader :value
# The value's content type.
#
# @return [String]
attr_reader :content_type
# The value's content ID, if given.
#
# @return [String, nil]
attr_reader :content_id
end
end