@@ -7,6 +7,7 @@ local assert, error, next, pairs, select, setmetatable, table_concat, tostring,
77local oauth = require " OAuth"
88local json = require " cjson"
99local util = require " luatwit.util"
10+ local multipart = require (" OAuth.helpers" ).multipart
1011
1112local _M = {}
1213
@@ -108,6 +109,10 @@ local function build_request(decl, args, name, defaults)
108109 return val
109110 end )
110111 url = _M .resources ._base_url .. url .. " .json"
112+ if decl ._multipart then
113+ local mp = multipart .Request (request )
114+ return method , url , mp .body , mp .headers
115+ end
111116 return method , url , request
112117end
113118
@@ -152,16 +157,16 @@ function _M.api:raw_call(decl, args, name, defaults)
152157 assert (# decl >= 2 , " invalid resource declaration" )
153158 args = args or {}
154159 name = name or " raw_call"
155- local method , url , request = build_request (decl , args , name , defaults )
156- local res_code , headers , status_line , body = self .oauth_client :PerformRequest (method , url , request )
160+ local method , url , request , req_headers = build_request (decl , args , name , defaults )
161+ local res_code , headers , status_line , body = self .oauth_client :PerformRequest (method , url , request , req_headers )
157162 util .bless (headers , _M .objects .headers )
158163 local tname = decl [4 ]
159164 if args ._raw then
160165 if type (body ) ~= " string" then body = nil end
161166 return body , status_line , res_code , headers , tname
162167 end
163168 local json_data = type (body ) == " string" and self :parse_json (body , tname ) or nil
164- if method == " GET" and type (json_data ) == " table" then
169+ if method == " GET" and type (json_data ) == " table" and type ( request ) == " table " then
165170 json_data ._source_method = function (_args )
166171 return self :raw_call (decl , _args , name , request )
167172 end
0 commit comments