Skip to content

Commit 45af847

Browse files
committed
implement the "statuses/update_with_media" API method
- this uses the recently added multipart support in the OAuth library
1 parent edd4e2b commit 45af847

2 files changed

Lines changed: 22 additions & 4 deletions

File tree

‎src/luatwit.lua‎

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ local assert, error, next, pairs, select, setmetatable, table_concat, tostring,
77
local oauth = require "OAuth"
88
local json = require "cjson"
99
local util = require "luatwit.util"
10+
local multipart = require("OAuth.helpers").multipart
1011

1112
local _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
112117
end
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

‎src/luatwit/resources.lua‎

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -155,7 +155,20 @@ _M.get_retweeter_ids = api{ GET, "statuses/retweeters/ids", {
155155
},
156156
"userid_cursor"
157157
}
158-
-- POST statuses/update_with_media --TODO: requires multipart/form-data request
158+
--- Updates the authenticating user's current status and attaches media for upload.
159+
_M.tweet_with_media = api{ POST, "statuses/update_with_media", {
160+
status = true,
161+
["media[]"] = { true, "table" },
162+
possibly_sensitive = false,
163+
in_reply_to_status_id = false,
164+
lat = false,
165+
long = false,
166+
place_id = false,
167+
display_coordinates = false,
168+
},
169+
"tweet",
170+
_multipart = true
171+
}
159172

160173
--( Search )--
161174

0 commit comments

Comments
 (0)