Class: VoiceBase::Request::FilePart

Inherits:
TextPart
  • Object
show all
Defined in:
lib/voicebase/request/file_part.rb

Instance Attribute Summary collapse

Attributes inherited from TextPart

#body, #name

Instance Method Summary collapse

Constructor Details

#initialize(name:, file:) ⇒ FilePart

Returns a new instance of FilePart.



9
10
11
12
13
# File 'lib/voicebase/request/file_part.rb', line 9

def initialize(name:, file:)
  @name = name
  @filepath = file.path
  @body = file.read
end

Instance Attribute Details

#filepathObject

Returns the value of attribute filepath.



7
8
9
# File 'lib/voicebase/request/file_part.rb', line 7

def filepath
  @filepath
end

Instance Method Details

#multipartObject



15
16
17
18
# File 'lib/voicebase/request/file_part.rb', line 15

def multipart
  "Content-Disposition: form-data; name=\"#{CGI::escape(name)}\"; filename=\"#{ File.basename(filepath) }\"\r\n" +
    "Content-Type: #{ mime_type.simplified }\r\n\r\n#{ body }\r\n\r\n"
end