Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- --[[
- [API] Pastebin
- @version 1.1, 2014-08-13, TOB
- @author TheOddByte, TOB
- --]]
- --[[
- @description "Uploads a file to pastebin"
- @param path, string
- @param name, string
- @return boolean, string, string
- --]]
- function put( path, name )
- if not fs.exists( path ) then
- error( "File doesn't exist: " .. path, 2 )
- end
- local f = fs.open( path, "r")
- local code = f.readAll()
- f.close()
- local key = "0ec2eb25b6166c0c27a394ae118ad829"
- local response = http.post(
- "http://pastebin.com/api/api_post.php",
- "api_option=paste&"..
- "api_dev_key="..key.."&"..
- "api_paste_format=lua&"..
- "api_paste_name="..textutils.urlEncode(name).."&"..
- "api_paste_code="..textutils.urlEncode(code)
- )
- if response then
- local hResponse = response.readAll()
- response.close()
- local sCode = string.match( hResponse, "[^/]+$" )
- return true, name, sCode
- else
- return false
- end
- end
- --[[
- @description "Downloads a file from pastebin"
- @param name, string
- @param code, string
- @return boolean
- --]]
- function get( name, code )
- local response = http.get( "http://pastebin.com/raw.php?i="..textutils.urlEncode(code) )
- if response then
- local sCode = response.readAll()
- if sCode ~= nil and sCode ~= "" then
- response.close()
- local file = fs.open( name, "w" )
- file.write(sCode)
- file.close()
- return true
- end
- end
- return false
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement