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:



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

#filenameObject (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_pathObject (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

Returns:

  • (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_fileObject



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_ioObject



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