14 posts
Posted 24 September 2016 - 04:40 PM
Hello! I made a computercraft API that allows you to easily make pastebin API requests!
It doesn't have very good error handling right now, but I will update it so that it does.
You can download it here:
http://pastebin.com/MpZXv6HzYou can get a devkey to use it here:
http://pastebin.com/apiHere are some examples:
--Logging in and doing stuff.
os.loadAPI("pbapi")
--Pastebin with or without using its API sends passwords in plaintext which you can see if you use wireshark. Sign up with a password you don't use normally!'
local h = pbapi.getUserHandle("your api devkey here","any username here","password for that user")
--Creating a paste:
local url = h.newPaste("paste content here")
--Creating a paste with optional parameters
--0: Public, 1: Unlisted, 2: Private
--Languages are at http://pastebin.com/api#5
--Only certain expire strings are allowed, http://pastebin.com/api#6
local otherurl = h.newPaste("NSString* gato = [[Person getCat] description]","migato (paste title)",2,"objc","10M")
--Listing pastes:
print(textutils.serialise(pbapi.listPastes()))
--Listing trending pastes:
print(textutils.serialise(pbapi.listTrending()))
--Listing user details:
print(textutils.serialise(pbapi.userDetails()))
--Deleting a paste:
h.deletePaste("paste key that belongs to user")
--Finally, reading a paste.
local data = h.rawPaste("public or unlisted paste key, or private paste key belonging to the user.")
There is also pbapi.getGuestHandle which behaves the same, but functions like listPastes that require to be logged in will not work.
Edited on 24 September 2016 - 02:41 PM
1715 posts
Location
ACDC Town
Posted 02 November 2016 - 07:29 PM
I've used something like this for PasteCCan, which is a CC pastebin client. Only problem being that it cannot edit, because the Pastebin API doesn't have a function for editing pastes. If you could hack together a way to edit pastes,I'll look into using this API rather than the one I'm using now.
7083 posts
Location
Tasmania (AU)
Posted 03 November 2016 - 04:24 AM
In regards to editing pastes, I've put a bit of research into that myself - but came up dry.
1715 posts
Location
ACDC Town
Posted 03 November 2016 - 11:36 AM
In regards to editing pastes, I've put a bit of research into that myself - but came up dry.
Arrrr, one would think it'd be in the Pastebin API, but
nooooo…
1426 posts
Location
Does anyone put something serious here?
Posted 03 November 2016 - 12:28 PM
I sent them an email a couple of weeks ago about this. It is "on their roadmap" but they don't have an ETA. So
6 to 8 weeks I guess.
7083 posts
Location
Tasmania (AU)
Posted 03 November 2016 - 12:59 PM
Huh. And here I thought they had some intentional reason to withhold the feature.
Actually I'm still not convinced that they don't, and that they simply don't want to explain themselves.
3 posts
Posted 06 November 2016 - 04:40 PM
How would I detect if a file request failed? For example:
function updateFile(pasteList, Name)
for i=1,#pasteList do
if (pasteList[i].title:lower() == Name:lower()) then
local pasteData = pasteHandle.rawPaste(pasteList[i].key)
local file = fs.open(Name, "w")
file.writeLine(pasteData)
file.close()
return true
end
end
return false
end
Would just overwrite any file with nothing if it failed to grab the raw data, correct?
7083 posts
Location
Tasmania (AU)
Posted 07 November 2016 - 10:18 AM
If you want to collect raw paste data, you may be better off doing it directly via the
http API. PBAPI would likely not empty your files, as it'd error before that - but unless you
pcall rawPaste(), you won't be able to handle the problem yourself.
Something along these lines maybe:
function updateFile(pasteList, Name)
for i = 1, #pasteList do
if pasteList[i].title:lower() == Name:lower() then
local webHandle = http.get("http://pastebin.com/raw/" .. pasteList[i].key)
if webHandle then
local file = fs.open(Name, "w")
file.writeLine(webHandle.readAll())
file.close()
webHandle.close()
return true
else
-- Connection failed; call "error" with a descriptive message or return false or something.
end
end
end
return false
end