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
25
26
27
28
29
30
31
32
33
34
35
36
|
# 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) ⇒ Boolean
38
39
40
41
42
43
44
45
46
47
48
49
|
# 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
|