Class: Koala::HTTPService::UploadableIO

Inherits:
Object
  • Object
show all
Defined in:
lib/koala/http_service/uploadable_io.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(io_or_path_or_mixed, content_type = nil, filename = nil) ⇒ UploadableIO

Returns a new instance of UploadableIO.

Raises:



9
10
11
12
13
14
15
16
17
18
19
20
# File 'lib/koala/http_service/uploadable_io.rb', line 9

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_typeObject (readonly)

Returns the value of attribute content_type.



7
8
9
# File 'lib/koala/http_service/uploadable_io.rb', line 7

def content_type
  @content_type
end

#filenameObject (readonly)

Returns the value of attribute filename.



7
8
9
# File 'lib/koala/http_service/uploadable_io.rb', line 7

def filename
  @filename
end

#io_or_pathObject (readonly)

Returns the value of attribute io_or_path.



7
8
9
# File 'lib/koala/http_service/uploadable_io.rb', line 7

def io_or_path
  @io_or_path
end

Class Method Details

.binary_content?(content) ⇒ Boolean

Returns:

  • (Boolean)


30
31
32
# File 'lib/koala/http_service/uploadable_io.rb', line 30

def self.binary_content?(content)
  content.is_a?(UploadableIO) || DETECTION_STRATEGIES.detect {|method| send(method, content)}
end

Instance Method Details

#to_fileObject



26
27
28
# File 'lib/koala/http_service/uploadable_io.rb', line 26

def to_file
  @io_or_path.is_a?(String) ? File.open(@io_or_path) : @io_or_path
end

#to_upload_ioObject



22
23
24
# File 'lib/koala/http_service/uploadable_io.rb', line 22

def to_upload_io
  UploadIO.new(@io_or_path, @content_type, @filename)
end