Sha256: 7175404bb7382a390c62f44ca15a3d5ac741328c11a51e487e13ba9067aab0ea

Contents?: true

Size: 1.04 KB

Versions: 65

Compression:

Stored size: 1.04 KB

Contents

#--
# Copyright (c) 2007-2013 Nick Sieger.
# See the file README.txt included with the distribution for
# software license details.
#++

require 'parts'
  module Multipartable
    DEFAULT_BOUNDARY = "-----------RubyMultipartPost"
    def initialize(path, params, headers={}, boundary = DEFAULT_BOUNDARY)
      headers = headers.clone # don't want to modify the original variable
      parts_headers = headers.delete(:parts) || {}
      super(path, headers)
      parts = params.map do |k,v|
        case v
        when Array
          v.map {|item| Parts::Part.new(boundary, k, item, parts_headers[k]) }
        else
          Parts::Part.new(boundary, k, v, parts_headers[k])
        end
      end.flatten
      parts << Parts::EpiloguePart.new(boundary)
      ios = parts.map {|p| p.to_io }
      self.set_content_type(headers["Content-Type"] || "multipart/form-data",
                            { "boundary" => boundary })
      self.content_length = parts.inject(0) {|sum,i| sum + i.length }
      self.body_stream = CompositeReadIO.new(*ios)
    end
  end

Version data entries

65 entries across 62 versions & 10 rubygems

Version Path
kinetic_sdk-5.0.9 gems/multipart-post-2.0.0/lib/multipartable.rb
kinetic_sdk-5.0.8 gems/multipart-post-2.0.0/lib/multipartable.rb
kinetic_sdk-5.0.7 gems/multipart-post-2.0.0/lib/multipartable.rb
kinetic_sdk-5.0.6 gems/multipart-post-2.0.0/lib/multipartable.rb
kinetic_sdk-5.0.5 gems/multipart-post-2.0.0/lib/multipartable.rb
kinetic_sdk-5.0.4 gems/multipart-post-2.0.0/lib/multipartable.rb
kinetic_sdk-5.0.3 gems/multipart-post-2.0.0/lib/multipartable.rb
kinetic_sdk-5.0.2 gems/multipart-post-2.0.0/lib/multipartable.rb
kinetic_sdk-5.0.2.beta.4 gems/multipart-post-2.0.0/lib/multipartable.rb
kinetic_sdk-5.0.2.beta.3 gems/multipart-post-2.0.0/lib/multipartable.rb
kinetic_sdk-5.0.2.beta.2 gems/multipart-post-2.0.0/lib/multipartable.rb
kinetic_sdk-5.0.2.beta.1 gems/multipart-post-2.0.0/lib/multipartable.rb
kinetic_sdk-5.0.1 gems/multipart-post-2.0.0/lib/multipartable.rb
kinetic_sdk-5.0.0 gems/multipart-post-2.0.0/lib/multipartable.rb
kinetic_sdk-1.0.2 gems/multipart-post-2.0.0/lib/multipartable.rb
kinetic_sdk-1.0.1 gems/multipart-post-2.0.0/lib/multipartable.rb
kinetic_sdk-1.0.0 gems/multipart-post-2.0.0/lib/multipartable.rb
kinetic_sdk-0.1.1 gems/multipart-post-2.0.0/lib/multipartable.rb
tdiary-5.0.13 vendor/bundle/gems/multipart-post-2.0.0/lib/multipartable.rb
tdiary-5.0.12.1 vendor/bundle/gems/multipart-post-2.0.0/lib/multipartable.rb