Class: Faraday::Request::Multipart

### Home Classes Methods

### In Files

- lib/faraday/request/multipart.rb

### Parent

Faraday::Request::UrlEncoded

### Methods

- #call
- #create_multipart
- #has_multipart?
- #process_params
- #process_request?

### Class/Module Index

Quicksearch

- Faraday
- Faraday::Adapter
- Faraday::Adapter::EMHttp
- Faraday::Adapter::EMHttp::Manager
- Faraday::Adapter::EMHttp::Options
- Faraday::Adapter::EMSynchrony
- Faraday::Adapter::EMSynchrony::ParallelManager
- Faraday::Adapter::Excon
- Faraday::Adapter::HTTPClient
- Faraday::Adapter::NetHttp
- Faraday::Adapter::NetHttpPersistent
- Faraday::Adapter::Parallelism
- Faraday::Adapter::Patron
- Faraday::Adapter::Rack
- Faraday::Adapter::Test
- Faraday::Adapter::Test::Stub
- Faraday::Adapter::Test::Stubs
- Faraday::Adapter::Test::Stubs::NotFound
- Faraday::Adapter::Typhoeus
- Faraday::AutoloadHelper
- Faraday::ClientError
- Faraday::CompositeReadIO
- Faraday::Connection
- Faraday::ConnectionFailed
- Faraday::ConnectionOptions
- Faraday::Env
- Faraday::Error
- Faraday::FlatParamsEncoder
- Faraday::Middleware
- Faraday::MiddlewareRegistry
- Faraday::MissingDependency
- Faraday::NestedParamsEncoder
- Faraday::Options
- Faraday::ParsingError
- Faraday::ProxyOptions
- Faraday::RackBuilder
- Faraday::RackBuilder::Handler
- Faraday::RackBuilder::StackLocked
- Faraday::Request
- Faraday::Request::Authorization
- Faraday::Request::BasicAuthentication
- Faraday::Request::Instrumentation
- Faraday::Request::Instrumentation::Options
- Faraday::Request::Multipart
- Faraday::Request::Retry
- Faraday::Request::Retry::Options
- Faraday::Request::TokenAuthentication
- Faraday::Request::UrlEncoded
- Faraday::RequestOptions
- Faraday::ResourceNotFound
- Faraday::Response
- Faraday::Response::Logger
- Faraday::Response::Middleware
- Faraday::Response::RaiseError
- Faraday::SSLError
- Faraday::SSLOptions
- Faraday::TimeoutError
- Faraday::Utils
- Faraday::Utils::Headers
- Faraday::Utils::ParamsHash
- EmHttpSslPatch
- Object

No matching classes.

# Faraday::Request::Multipart

### Constants

DEFAULT_BOUNDARY

### Public Instance Methods

call(env) click to toggle source

    # File lib/faraday/request/multipart.rb, line 8
    def call(env)
      match_content_type(env) do |params|
        env.request.boundary ||= DEFAULT_BOUNDARY
        env.request_headers[CONTENT_TYPE] += "; boundary=#{env.request.boundary}"
        env.body = create_multipart(env, params)
      end
      @app.call env
    end

create_multipart(env, params) click to toggle source

    # File lib/faraday/request/multipart.rb, line 35
    def create_multipart(env, params)
      boundary = env.request.boundary
      parts = process_params(params) do |key, value|
        Faraday::Parts::Part.new(boundary, key, value)
      end
      parts << Faraday::Parts::EpiloguePart.new(boundary)

      body = Faraday::CompositeReadIO.new(parts)
      env.request_headers[Faraday::Env::ContentLength] = body.length.to_s
      return body
    end

has_multipart?(obj) click to toggle source

    # File lib/faraday/request/multipart.rb, line 25
    def has_multipart?(obj)
      # string is an enum in 1.8, returning list of itself
      if obj.respond_to?(:each) && !obj.is_a?(String)
        (obj.respond_to?(:values) ? obj.values : obj).each do |val|
          return true if (val.respond_to?(:content_type) || has_multipart?(val))
        end
      end
      false
    end

process_params(params, prefix = nil, pieces = nil, &block) click to toggle source

    # File lib/faraday/request/multipart.rb, line 47
    def process_params(params, prefix = nil, pieces = nil, &block)
      params.inject(pieces || []) do |all, (key, value)|
        key = "#{prefix}[#{key}]" 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) click to toggle source

    # File lib/faraday/request/multipart.rb, line 17
    def process_request?(env)
      type = request_type(env)
      env.body.respond_to?(:each_key) and !env.body.empty? and (
        (type.empty? and has_multipart?(env.body)) or
        type == self.class.mime_type
      )
    end

[Validate]

Generated with the Darkfish Rdoc Generator 2.