Class: VoiceBase::V2::Client::FileParam
- Inherits:
-
Object
- Object
- VoiceBase::V2::Client::FileParam
- Defined in:
- lib/voicebase/v2/client.rb
Overview
Formats the contents of a file or string for inclusion with a multipart form post
Instance Attribute Summary collapse
-
#content ⇒ Object
Returns the value of attribute content.
-
#filename ⇒ Object
Returns the value of attribute filename.
-
#k ⇒ Object
Returns the value of attribute k.
Instance Method Summary collapse
-
#initialize(k, filename, content) ⇒ FileParam
constructor
A new instance of FileParam.
- #to_multipart ⇒ Object
Constructor Details
#initialize(k, filename, content) ⇒ FileParam
Returns a new instance of FileParam.
219 220 221 |
# File 'lib/voicebase/v2/client.rb', line 219 def initialize(k, filename, content) @k, @filename, @content = k, filename, content end |
Instance Attribute Details
#content ⇒ Object
Returns the value of attribute content.
217 218 219 |
# File 'lib/voicebase/v2/client.rb', line 217 def content @content end |
#filename ⇒ Object
Returns the value of attribute filename.
217 218 219 |
# File 'lib/voicebase/v2/client.rb', line 217 def filename @filename end |
#k ⇒ Object
Returns the value of attribute k.
217 218 219 |
# File 'lib/voicebase/v2/client.rb', line 217 def k @k end |
Instance Method Details
#to_multipart ⇒ Object
223 224 225 226 227 228 229 |
# File 'lib/voicebase/v2/client.rb', line 223 def to_multipart # If we can tell the possible mime-type from the filename, use the # first in the list; otherwise, use "application/octet-stream" mime_type = MIME::Types.type_for(filename)[0] || MIME::Types["application/octet-stream"][0] return "Content-Disposition: form-data; name=\"#{CGI::escape(k.to_s)}\"; filename=\"#{ filename }\"\r\n" + "Content-Type: #{ mime_type.simplified }\r\n\r\n#{ content }\r\n" end |