Class: ChatWork::Multipart

Inherits:
Faraday::Multipart::Middleware
  • Object
show all
Defined in:
lib/chatwork/multipart.rb

Instance Method Summary collapse

Instance Method Details

#create_multipart(env, params) ⇒ Object



5
6
7
8
9
10
11
12
13
14
15
16
# File 'lib/chatwork/multipart.rb', line 5

def create_multipart(env, params)
  original_body = super(env, params)

  # replace from Faraday::Parts::EpiloguePart to ChatWork::Multipart::EpiloguePart
  parts = original_body.instance_variable_get(:@parts)
  parts.pop
  parts << EpiloguePart.new(env.request.boundary)

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