Module: MultipartFormData
- Defined in:
- lib/lyrics/utils/formdata.rb
Constant Summary collapse
- @@boundary =
"----------nOtA5FcjrNZuZ3TMioysxHGGCO69vA5iYysdBTL2osuNwOjcCfU7uiN"
Class Method Summary collapse
- .file_param(name, file, mime_type, content) ⇒ Object
- .prepare_query(params) ⇒ Object
- .text_param(name, value) ⇒ Object
Class Method Details
.file_param(name, file, mime_type, content) ⇒ Object
41 42 43 44 45 46 47 |
# File 'lib/lyrics/utils/formdata.rb', line 41 def MultipartFormData.file_param( name, file, mime_type, content ) return "Content-Disposition: form-data; name=\"#{CGI.escape(name)}\"; filename=\"#{file}\"\r\n" \ "Content-Transfer-Encoding: binary\r\n" \ "Content-Type: #{mime_type}\r\n" \ "\r\n" \ "#{content}\r\n" end |
.prepare_query(params) ⇒ Object
49 50 51 52 53 |
# File 'lib/lyrics/utils/formdata.rb', line 49 def MultipartFormData.prepare_query( params ) query = params.collect { |param| "--#{@@boundary}\r\n#{param}" }.join( "" ) + "--#{@@boundary}--" header = { "Content-type" => "multipart/form-data; boundary=" + @@boundary } return query, header end |
.text_param(name, value) ⇒ Object
35 36 37 38 39 |
# File 'lib/lyrics/utils/formdata.rb', line 35 def MultipartFormData.text_param( name, value ) return "Content-Disposition: form-data; name=\"#{CGI.escape(name)}\"\r\n" \ "\r\n" \ "#{value}\r\n" end |