Class: AngellistApi::Request::MultipartWithFile

Inherits:
Faraday::Middleware
  • Object
show all
Defined in:
lib/angellist_api/request/multipart_with_file.rb

Instance Method Summary collapse

Instance Method Details

#call(env) ⇒ Object



6
7
8
9
10
11
12
13
14
15
16
17
18
# File 'lib/angellist_api/request/multipart_with_file.rb', line 6

def call(env)
  if env[:body].is_a?(Hash)
    env[:body].each do |key, value|
      if value.is_a?(File)
        env[:body][key] = Faraday::UploadIO.new(value, mime_type(value.path), value.path)
      elsif value.is_a?(Hash) && (value['io'].is_a?(IO) || value['io'].is_a?(StringIO))
        env[:body][key] = Faraday::UploadIO.new(value['io'], mime_type('.'+value['type']), '')
      end
    end
  end

  @app.call(env)
end