Class: EDH::HTTPService::MultipartRequest
- Inherits:
-
Faraday::Request::Multipart
- Object
- Faraday::Request::Multipart
- EDH::HTTPService::MultipartRequest
- Defined in:
- lib/edh/http_service/multipart_request.rb
Instance Method Summary collapse
- #process_params(params, prefix = nil, pieces = nil, &block) ⇒ Object
- #process_request?(env) ⇒ Boolean
Instance Method Details
#process_params(params, prefix = nil, pieces = nil, &block) ⇒ Object
19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 |
# File 'lib/edh/http_service/multipart_request.rb', line 19 def process_params(params, prefix = nil, pieces = nil, &block) params.inject(pieces || []) do |all, (key, value)| key = "#{prefix}%5B#{key}%5D" if prefix case value when Array values = value.inject([]) { |a,v| a << [nil, v] } process_params(values, key, all, &block) when Hash process_params(value, key, all, &block) else all << block.call(key, value) end end end |
#process_request?(env) ⇒ Boolean
13 14 15 16 |
# File 'lib/edh/http_service/multipart_request.rb', line 13 def process_request?(env) # if the request values contain any hashes or arrays, multipart it super || !!(env[:body].respond_to?(:values) && env[:body].values.find {|v| v.is_a?(Hash) || v.is_a?(Array)}) end |