module Http::Multipart

Constants

QUERY_STRING_NORMALIZER
TRANSFORMABLE_TYPES

Public Class Methods

file_to_upload_io(file) click to toggle source
# File lib/angus/remote/http/multipart.rb, line 15
def self.file_to_upload_io(file)
  if file.respond_to? :original_filename
    filename = file.original_filename
  else
    filename =  File.split(file.path).last
  end
  content_type = 'application/octet-stream'
  UploadIO.new(file, content_type, filename)
end
flatten_params(params={}, prefix='') click to toggle source
# File lib/angus/remote/http/multipart.rb, line 35
def self.flatten_params(params={}, prefix='')
  flattened = []
  params.each do |(k,v)|
    if params.is_a?(Array)
      v = k
      k = ''
    end

    flattened_key = prefix == '' ? "#{k}" : "#{prefix}[#{k}]"
    if v.is_a?(Hash) || v.is_a?(Array)
      flattened += flatten_params(v, flattened_key)
    else
      flattened << [flattened_key, v]
    end
  end
  flattened
end
hash_contains_files?(hash) click to toggle source
# File lib/angus/remote/http/multipart.rb, line 25
def self.hash_contains_files?(hash)
  hash.is_a?(Hash) && self.flatten_params(hash).select do |(k,v)|
    self.transformable_type?(v) || v.is_a?(UploadIO)
  end.size > 0
end
transformable_type?(object) click to toggle source
# File lib/angus/remote/http/multipart.rb, line 31
def self.transformable_type?(object)
  TRANSFORMABLE_TYPES.any? { |klass| object.is_a?(klass) }
end