Class: Fleakr::Api::FileParameter
- Inherits:
-
Object
- Object
- Fleakr::Api::FileParameter
- Defined in:
- lib/fleakr/api/file_parameter.rb
Overview
FileParameter
Parameter class to encapsulate file data sent to the Flickr upload API
Constant Summary collapse
- MIME_TYPES =
{ '.jpg' => 'image/jpeg', '.png' => 'image/png', '.gif' => 'image/gif' }
Instance Attribute Summary collapse
-
#name ⇒ Object
readonly
Returns the value of attribute name.
Instance Method Summary collapse
-
#initialize(name, filename) ⇒ FileParameter
constructor
Create a parameter with name and specified filename.
-
#mime_type ⇒ Object
Discover MIME type by file extension using MIME_TYPES constant.
-
#to_form ⇒ Object
Generate a form representation of this file for upload (as multipart/form-data).
-
#value ⇒ Object
File data (from @filename) to pass to the Flickr API.
Constructor Details
#initialize(name, filename) ⇒ FileParameter
Create a parameter with name and specified filename
20 21 22 23 |
# File 'lib/fleakr/api/file_parameter.rb', line 20 def initialize(name, filename) @name = name @filename = filename end |
Instance Attribute Details
#name ⇒ Object (readonly)
Returns the value of attribute name.
16 17 18 |
# File 'lib/fleakr/api/file_parameter.rb', line 16 def name @name end |
Instance Method Details
#mime_type ⇒ Object
Discover MIME type by file extension using MIME_TYPES constant
27 28 29 |
# File 'lib/fleakr/api/file_parameter.rb', line 27 def mime_type MIME_TYPES[File.extname(@filename)] end |
#to_form ⇒ Object
Generate a form representation of this file for upload (as multipart/form-data)
39 40 41 42 43 44 |
# File 'lib/fleakr/api/file_parameter.rb', line 39 def to_form "Content-Disposition: form-data; name=\"#{self.name}\"; filename=\"#{@filename}\"\r\n" + "Content-Type: #{self.mime_type}\r\n" + "\r\n" + "#{self.value}\r\n" end |
#value ⇒ Object
File data (from @filename) to pass to the Flickr API
33 34 35 |
# File 'lib/fleakr/api/file_parameter.rb', line 33 def value @value ||= File.read(@filename) end |