Class: Koala::HTTPService::MultipartRequest

Inherits:
Faraday::Request::Multipart
  • Object
show all
Defined in:
lib/koala/http_service/multipart_request.rb

Instance Method Summary collapse

Instance Method Details

#process_params(params, prefix = nil, pieces = nil, &block) ⇒ Object


20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
# File 'lib/koala/http_service/multipart_request.rb', line 20

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

Returns:

  • (Boolean)

14
15
16
17
# File 'lib/koala/http_service/multipart_request.rb', line 14

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