Class: GroqRuby::Multipart
- Inherits:
-
Object
- Object
- GroqRuby::Multipart
- Defined in:
- lib/groq_ruby/multipart.rb
Overview
Encodes a list of fields into a multipart/form-data body. Used by the file upload endpoints (audio transcription/translation, files.create). Single-purpose — builds the body and content-type header. Does no IO.
Defined Under Namespace
Classes: Part
Instance Attribute Summary collapse
-
#boundary ⇒ String
readonly
The random boundary string used to separate parts.
Instance Method Summary collapse
-
#body ⇒ String
The encoded multipart body, suitable for ‘Net::HTTP::Post#body=`.
-
#content_type ⇒ String
The value to use for the ‘Content-Type` header.
-
#initialize(parts, boundary: SecureRandom.hex(16)) ⇒ Multipart
constructor
A new instance of Multipart.
Constructor Details
#initialize(parts, boundary: SecureRandom.hex(16)) ⇒ Multipart
Returns a new instance of Multipart.
48 49 50 51 |
# File 'lib/groq_ruby/multipart.rb', line 48 def initialize(parts, boundary: SecureRandom.hex(16)) @parts = parts @boundary = boundary end |
Instance Attribute Details
#boundary ⇒ String (readonly)
Returns the random boundary string used to separate parts.
44 45 46 |
# File 'lib/groq_ruby/multipart.rb', line 44 def boundary @boundary end |
Instance Method Details
#body ⇒ String
Returns the encoded multipart body, suitable for ‘Net::HTTP::Post#body=`.
54 55 56 57 58 59 |
# File 'lib/groq_ruby/multipart.rb', line 54 def body buffer = +"" @parts.each { |p| buffer << encode_part(p) } buffer << "--#{@boundary}--\r\n" buffer end |
#content_type ⇒ String
Returns the value to use for the ‘Content-Type` header.
62 63 64 |
# File 'lib/groq_ruby/multipart.rb', line 62 def content_type "multipart/form-data; boundary=#{@boundary}" end |