Skip to content
Permalink
Browse files
implement the "statuses/update_with_media" API method
- this uses the recently added multipart support in the OAuth library
  • Loading branch information
wolfiestyle committed Sep 25, 2013
1 parent edd4e2b commit 45af847
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 4 deletions.
@@ -7,6 +7,7 @@ local assert, error, next, pairs, select, setmetatable, table_concat, tostring,
local oauth = require "OAuth"
local json = require "cjson"
local util = require "luatwit.util"
local multipart = require("OAuth.helpers").multipart

local _M = {}

@@ -108,6 +109,10 @@ local function build_request(decl, args, name, defaults)
return val
end)
url = _M.resources._base_url .. url .. ".json"
if decl._multipart then
local mp = multipart.Request(request)
return method, url, mp.body, mp.headers
end
return method, url, request
end

@@ -152,16 +157,16 @@ function _M.api:raw_call(decl, args, name, defaults)
assert(#decl >= 2, "invalid resource declaration")
args = args or {}
name = name or "raw_call"
local method, url, request = build_request(decl, args, name, defaults)
local res_code, headers, status_line, body = self.oauth_client:PerformRequest(method, url, request)
local method, url, request, req_headers = build_request(decl, args, name, defaults)
local res_code, headers, status_line, body = self.oauth_client:PerformRequest(method, url, request, req_headers)
util.bless(headers, _M.objects.headers)
local tname = decl[4]
if args._raw then
if type(body) ~= "string" then body = nil end
return body, status_line, res_code, headers, tname
end
local json_data = type(body) == "string" and self:parse_json(body, tname) or nil
if method == "GET" and type(json_data) == "table" then
if method == "GET" and type(json_data) == "table" and type(request) == "table" then
json_data._source_method = function(_args)
return self:raw_call(decl, _args, name, request)
end
@@ -155,7 +155,20 @@ _M.get_retweeter_ids = api{ GET, "statuses/retweeters/ids", {
},
"userid_cursor"
}
-- POST statuses/update_with_media --TODO: requires multipart/form-data request
--- Updates the authenticating user's current status and attaches media for upload.
_M.tweet_with_media = api{ POST, "statuses/update_with_media", {
status = true,
["media[]"] = { true, "table" },
possibly_sensitive = false,
in_reply_to_status_id = false,
lat = false,
long = false,
place_id = false,
display_coordinates = false,
},
"tweet",
_multipart = true
}

--( Search )--

0 comments on commit 45af847

Please sign in to comment.