class Koala::HTTPService::UploadableIO

Constants

DETECTION_STRATEGIES
MIME_TYPE_STRATEGIES
PARSE_STRATEGIES

Attributes

content_type[R]
filename[R]
io_or_path[R]

Public Instance Methods

to_file() click to toggle source
# 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_io() click to toggle source
# File lib/koala/http_service/uploadable_io.rb, line 22
def to_upload_io
  UploadIO.new(@io_or_path, @content_type, @filename)
end

Public Class Methods

binary_content?(content) click to toggle source
# 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
new(io_or_path_or_mixed, content_type = nil, filename = nil) click to toggle source
# 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