Module: RestMan::Payload
- Extended by:
- Payload
- Included in:
- Payload
- Defined in:
- lib/restman/payload.rb,
lib/restman/payload/base.rb,
lib/restman/payload/streamed.rb,
lib/restman/payload/multipart.rb,
lib/restman/payload/url_encoded.rb,
lib/restman/payload/multipart/write_content_disposition.rb
Defined Under Namespace
Classes: Base, Multipart, Streamed, UrlEncoded
Instance Method Summary
collapse
Instance Method Details
#generate(params) ⇒ Object
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
|
# File 'lib/restman/payload.rb', line 7
def generate(params)
if params.is_a?(RestMan::Payload::Base)
params
elsif 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.is_a?(ParamsArray)
if 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?(obj) ⇒ Boolean
38
39
40
41
42
43
44
45
46
47
48
49
|
# File 'lib/restman/payload.rb', line 38
def has_file?(obj)
case obj
when Hash, ParamsArray
obj.any? {|_, v| has_file?(v) }
when Array
obj.any? {|v| has_file?(v) }
else
obj.respond_to?(:path) && obj.respond_to?(:read)
end
end
|