Class: Flexirest::Multipart::FileParam

Inherits:
Object
  • Object
show all
Defined in:
lib/flexirest/multipart.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(k, filename, content) ⇒ FileParam

Returns a new instance of FileParam.



67
68
69
70
71
# File 'lib/flexirest/multipart.rb', line 67

def initialize(k, filename, content)
  @k = k
  @filename = filename
  @content = content
end

Instance Attribute Details

#contentObject

Returns the value of attribute content.



65
66
67
# File 'lib/flexirest/multipart.rb', line 65

def content
  @content
end

#filenameObject

Returns the value of attribute filename.



65
66
67
# File 'lib/flexirest/multipart.rb', line 65

def filename
  @filename
end

#kObject

Returns the value of attribute k.



65
66
67
# File 'lib/flexirest/multipart.rb', line 65

def k
  @k
end

Instance Method Details

#to_multipartObject



73
74
75
76
77
# File 'lib/flexirest/multipart.rb', line 73

def to_multipart
  mime_type = MIME::Types.type_for(filename)[0] || MIME::Types["application/octet-stream"][0]
  return "Content-Disposition: form-data; name=\"#{k}\"; filename=\"#{filename}\"\r\n" +
         "Content-Type: #{ mime_type.simplified }\r\n\r\n#{ content }\r\n"
end