Class: Koala::HTTPService::UploadableIO
- Inherits:
-
Object
- Object
- Koala::HTTPService::UploadableIO
- Defined in:
- lib/koala/http_service/uploadable_io.rb
Instance Attribute Summary collapse
-
#content_type ⇒ Object
readonly
Returns the value of attribute content_type.
-
#filename ⇒ Object
readonly
Returns the value of attribute filename.
-
#io_or_path ⇒ Object
readonly
Returns the value of attribute io_or_path.
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(io_or_path_or_mixed, content_type = nil, filename = nil) ⇒ UploadableIO
constructor
A new instance of UploadableIO.
- #to_file ⇒ Object
- #to_upload_io ⇒ Object
Constructor Details
#initialize(io_or_path_or_mixed, content_type = nil, filename = nil) ⇒ UploadableIO
Returns a new instance of UploadableIO.
8 9 10 11 12 13 14 15 16 17 18 19 |
# File 'lib/koala/http_service/uploadable_io.rb', line 8 def initialize(io_or_path_or_mixed, content_type = nil, filename = nil) # see if we got the right inputs parse_init_mixed_param io_or_path_or_mixed, content_type # filename is used in the Ads API # if it's provided, take precedence over the detected filename # otherwise, fall back to a dummy name @filename = filename || @filename || "koala-io-file.dum" raise KoalaError.new("Invalid arguments to initialize an UploadableIO") unless @io_or_path raise KoalaError.new("Unable to determine MIME type for UploadableIO") if !@content_type end |
Instance Attribute Details
#content_type ⇒ Object (readonly)
Returns the value of attribute content_type.
6 7 8 |
# File 'lib/koala/http_service/uploadable_io.rb', line 6 def content_type @content_type end |
#filename ⇒ Object (readonly)
Returns the value of attribute filename.
6 7 8 |
# File 'lib/koala/http_service/uploadable_io.rb', line 6 def filename @filename end |
#io_or_path ⇒ Object (readonly)
Returns the value of attribute io_or_path.
6 7 8 |
# File 'lib/koala/http_service/uploadable_io.rb', line 6 def io_or_path @io_or_path end |
Class Method Details
.binary_content?(content) ⇒ Boolean
29 30 31 |
# File 'lib/koala/http_service/uploadable_io.rb', line 29 def self.binary_content?(content) content.is_a?(UploadableIO) || DETECTION_STRATEGIES.detect {|method| send(method, content)} end |
Instance Method Details
#to_file ⇒ Object
25 26 27 |
# File 'lib/koala/http_service/uploadable_io.rb', line 25 def to_file @io_or_path.is_a?(String) ? File.open(@io_or_path) : @io_or_path end |
#to_upload_io ⇒ Object
21 22 23 |
# File 'lib/koala/http_service/uploadable_io.rb', line 21 def to_upload_io UploadIO.new(@io_or_path, @content_type, @filename) end |