module RestClient::Payload

Public Instance Methods

generate(params) click to toggle source
# File lib/restclient/payload.rb, line 9
def generate(params)
  if params.is_a?(String)
    Base.new(params)
  elsif params.is_a?(Hash)
    if params.delete(:multipart) == true || has_file?(params)
      Multipart.new(params)
    else
      UrlEncoded.new(params)
    end
  elsif params.respond_to?(:read)
    Streamed.new(params)
  else
    nil
  end
end
has_file?(params) click to toggle source
# File lib/restclient/payload.rb, line 25
def has_file?(params)
  params.any? do |_, v|
    case v
    when Hash
      has_file?(v)
    when Array
      has_file_array?(v)
    else
      v.respond_to?(:path) && v.respond_to?(:read)
    end
  end
end
has_file_array?(params) click to toggle source
# File lib/restclient/payload.rb, line 38
def has_file_array?(params)
  params.any? do |v|
    case v
    when Hash
      has_file?(v)
    when Array
      has_file_array?(v)
    else
      v.respond_to?(:path) && v.respond_to?(:read)
    end
  end
end