Module: RestClient::Payload

Extended by:
Payload
Included in:
Payload
Defined in:
lib/restclient/payload.rb

Defined Under Namespace

Classes: Base, Multipart, Streamed, UrlEncoded

Instance Method Summary collapse

Instance Method Details

#generate(params) ⇒ Object



9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
# File 'lib/restclient/payload.rb', line 9

def generate(params)
  if params.is_a?(String)
    Base.new(params)
  elsif params.respond_to?(:read)
    Streamed.new(params)
  elsif params
    if params.delete(:multipart) == true || has_file?(params)
      Multipart.new(params)
    else
      UrlEncoded.new(params)
    end
  else
    nil
  end
end

#has_file?(params) ⇒ Boolean

Returns:

  • (Boolean)


25
26
27
28
29
30
31
32
33
34
# File 'lib/restclient/payload.rb', line 25

def has_file?(params)
  params.any? do |_, v|
    case v
      when Hash
        has_file?(v)
      else
        v.respond_to?(:path) && v.respond_to?(:read)
    end
  end
end