Class: OauthChina::Multipart::MultipartPost

Inherits:
Object
  • Object
show all
Defined in:
lib/oauth_china/multipart.rb

Constant Summary collapse

BOUNDARY =
'tarsiers-rule0000'
ContentType =
"multipart/form-data; boundary=" + BOUNDARY

Instance Method Summary collapse

Instance Method Details

#prepare_query(params) ⇒ Object



46
47
48
49
50
51
52
53
54
55
56
57
58
# File 'lib/oauth_china/multipart.rb', line 46

def prepare_query(params)
  fp = []
  params.each {|k,v|
    if v.respond_to?(:read)
      fp.push(FileParam.new(k, v.path, v.read))
      v.close
    else
      fp.push(Param.new(k,v))
    end
  }
  body = fp.collect {|p| "--" + BOUNDARY + "\r\n" + p.to_multipart }.join("") + "--" + BOUNDARY + "--rn"
  return body, ContentType
end

#set_form_data(req, params) ⇒ Object



38
39
40
41
42
43
44
# File 'lib/oauth_china/multipart.rb', line 38

def set_form_data(req, params)
  body, content_type = prepare_query(params)
  req["Content-Type"] = content_type
  req.body = body
  req["Content-Length"] = body.bytesize
  req
end