Class: Google::Apis::Core::Multipart
- Inherits:
-
Object
- Object
- Google::Apis::Core::Multipart
- Defined in:
- lib/google/apis/core/multipart.rb
Overview
Helper for building multipart requests
Constant Summary collapse
- MULTIPART_RELATED =
'multipart/related'
- DEFAULT_BOUNDARY =
'RubyApiClientMultiPart'
Instance Attribute Summary collapse
-
#content_type ⇒ String
readonly
Content type header.
Instance Method Summary collapse
-
#add_json(body, content_id: nil) ⇒ self
Append JSON data part.
-
#add_upload(upload_io, content_id: nil) ⇒ self
Append arbitrary data as a part.
-
#assemble ⇒ IO
Assemble the multipart requests.
-
#initialize(content_type: MULTIPART_RELATED, boundary: nil) ⇒ Multipart
constructor
A new instance of Multipart.
Constructor Details
#initialize(content_type: MULTIPART_RELATED, boundary: nil) ⇒ Multipart
Returns a new instance of Multipart.
136 137 138 139 140 |
# File 'lib/google/apis/core/multipart.rb', line 136 def initialize(content_type: MULTIPART_RELATED, boundary: nil) @parts = [] @boundary = boundary || DEFAULT_BOUNDARY @content_type = "#{content_type}; boundary=#{boundary}" end |
Instance Attribute Details
#content_type ⇒ String (readonly)
Returns Content type header.
129 130 131 |
# File 'lib/google/apis/core/multipart.rb', line 129 def content_type @content_type end |
Instance Method Details
#add_json(body, content_id: nil) ⇒ self
Append JSON data part
149 150 151 152 153 |
# File 'lib/google/apis/core/multipart.rb', line 149 def add_json(body, content_id: nil) header = { :content_id => content_id } @parts << Google::Apis::Core::JsonPart.new(@boundary, body, header) self end |
#add_upload(upload_io, content_id: nil) ⇒ self
Append arbitrary data as a part
162 163 164 165 166 167 168 |
# File 'lib/google/apis/core/multipart.rb', line 162 def add_upload(upload_io, content_id: nil) header = { :content_id => content_id } @parts << Google::Apis::Core::FilePart.new(@boundary, upload_io, header) self end |
#assemble ⇒ IO
Assemble the multipart requests
174 175 176 177 178 179 180 181 182 183 |
# File 'lib/google/apis/core/multipart.rb', line 174 def assemble @parts << Hurley::Multipart::EpiloguePart.new(@boundary) ios = [] len = 0 @parts.each do |part| len += part.length ios << part.to_io end Hurley::CompositeReadIO.new(len, *ios) end |