Class: XamarinTestCloud::HTTP::Payload::Base
- Inherits:
-
Object
- Object
- XamarinTestCloud::HTTP::Payload::Base
show all
- Defined in:
- lib/xamarin-test-cloud/http/payload.rb
Instance Method Summary
collapse
Constructor Details
#initialize(params) ⇒ Base
Returns a new instance of Base.
80
81
82
|
# File 'lib/xamarin-test-cloud/http/payload.rb', line 80
def initialize(params)
build_stream(params)
end
|
Instance Method Details
#build_stream(params) ⇒ Object
84
85
86
87
|
# File 'lib/xamarin-test-cloud/http/payload.rb', line 84
def build_stream(params)
@stream = StringIO.new(params)
@stream.seek(0)
end
|
#close ⇒ Object
136
137
138
|
# File 'lib/xamarin-test-cloud/http/payload.rb', line 136
def close
@stream.close unless @stream.closed?
end
|
#flatten_params(params, parent_key = nil) ⇒ Object
Flatten parameters by converting hashes of hashes to flat hashes => {keys2 => value} will be transformed into [keys1, value]
97
98
99
100
101
102
103
104
105
106
107
108
109
110
|
# File 'lib/xamarin-test-cloud/http/payload.rb', line 97
def flatten_params(params, parent_key = nil)
result = []
params.each do |key, value|
calculated_key = parent_key ? "#{parent_key}[#{handle_key(key)}]" : handle_key(key)
if value.is_a? Hash
result += flatten_params(value, calculated_key)
elsif value.is_a? Array
result += flatten_params_array(value, calculated_key)
else
result << [calculated_key, value]
end
end
result
end
|
#flatten_params_array(value, calculated_key) ⇒ Object
112
113
114
115
116
117
118
119
120
121
122
123
124
|
# File 'lib/xamarin-test-cloud/http/payload.rb', line 112
def flatten_params_array(value, calculated_key)
result = []
value.each do |elem|
if elem.is_a? Hash
result += flatten_params(elem, calculated_key)
elsif elem.is_a? Array
result += flatten_params_array(elem, calculated_key)
else
result << ["#{calculated_key}[]", elem]
end
end
result
end
|
126
127
128
|
# File 'lib/xamarin-test-cloud/http/payload.rb', line 126
def
{'Content-Length' => size.to_s}
end
|
#inspect ⇒ Object
140
141
142
143
144
|
# File 'lib/xamarin-test-cloud/http/payload.rb', line 140
def inspect
result = to_s.inspect
@stream.seek(0)
result
end
|
#read(bytes = nil) ⇒ Object
Also known as:
to_s
89
90
91
|
# File 'lib/xamarin-test-cloud/http/payload.rb', line 89
def read(bytes=nil)
@stream.read(bytes)
end
|
#short_inspect ⇒ Object
146
147
148
|
# File 'lib/xamarin-test-cloud/http/payload.rb', line 146
def short_inspect
(size > 500 ? "#{size} byte(s) length" : inspect)
end
|
#size ⇒ Object
Also known as:
length
130
131
132
|
# File 'lib/xamarin-test-cloud/http/payload.rb', line 130
def size
@stream.size
end
|