Class: RestBuilder::Payload
- Inherits:
-
Object
- Object
- RestBuilder::Payload
show all
- Defined in:
- lib/rest-builder/payload.rb
Defined Under Namespace
Classes: Multipart, Streamed, StreamedString, UrlEncoded
Instance Attribute Summary collapse
Class Method Summary
collapse
Instance Method Summary
collapse
Constructor Details
#initialize(payload) ⇒ Payload
Returns a new instance of Payload.
55
|
# File 'lib/rest-builder/payload.rb', line 55
def initialize payload; @io = payload ; end
|
Instance Attribute Details
#io ⇒ Object
Also known as:
to_io
52
53
54
|
# File 'lib/rest-builder/payload.rb', line 52
def io
@io
end
|
Class Method Details
.generate(payload) ⇒ Object
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
|
# File 'lib/rest-builder/payload.rb', line 27
def self.generate payload
if payload.respond_to?(:read)
Streamed.new(payload)
elsif payload.kind_of?(String)
StreamedString.new(payload)
elsif payload.kind_of?(Hash)
if payload.empty?
nil
elsif Middleware.contain_binary?(payload)
Multipart.new(payload)
else
UrlEncoded.new(payload)
end
else
raise Error.new("Payload should be either String, Hash, or" \
" responding to `read', but: #{payload.inspect}")
end
end
|
18
19
20
21
22
23
24
25
|
# File 'lib/rest-builder/payload.rb', line 18
def self. payload,
h = if p = generate(payload)
p..merge()
else
end
[p, h]
end
|
Instance Method Details
#close ⇒ Object
57
|
# File 'lib/rest-builder/payload.rb', line 57
def close ; io.close unless closed?; end
|
#closed? ⇒ Boolean
58
|
# File 'lib/rest-builder/payload.rb', line 58
def closed? ; io.closed? ; end
|
59
|
# File 'lib/rest-builder/payload.rb', line 59
def ; {} ; end
|
#read(bytes = nil) ⇒ Object
56
|
# File 'lib/rest-builder/payload.rb', line 56
def read bytes=nil; io.read(bytes) ; end
|
#size ⇒ Object
61
62
63
64
65
66
67
68
69
|
# File 'lib/rest-builder/payload.rb', line 61
def size
if io.respond_to?(:size)
io.size
elsif io.respond_to?(:stat)
io.stat.size
else
0
end
end
|