Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local logins = {}
- --be sure to get a Personal Access token from https://github.com/settings/tokens and save it somewhere in order to use this API (requires gist permission node)
- local function installAPI(code, name)
- local webHandle = http.get("http://pastebin.com/raw.php?i="..code)
- if webHandle then
- local apiData = webHandle.readAll()
- webHandle.close()
- local tEnv = {}
- setmetatable( tEnv, { __index = _ENV } )
- local fnAPI, err = load( apiData, name, "t", tEnv )
- if fnAPI then
- fnAPI()
- end
- local tAPI = {}
- for k,v in pairs( tEnv ) do
- if k ~= "_ENV" then
- tAPI[k] = v
- end
- end
- _G[name] = tAPI
- else
- print("Could not retrieve API: "..name.."!")
- print("Ensure that the HTTP API is enabled.")
- return false
- end
- end
- if not json then
- installAPI("4nRg9CHU", "json")
- end
- local function genToken(token)
- local userp = user..":"..pass
- return "Token "..enc(userp)
- end
- local function createFS(fileTbl)
- local ret = {}
- for k,v in pairs(fileTbl) do
- ret[k] = {content=v}
- end
- return ret
- end
- function login(token, nick)
- logins[nick] = genToken(token)
- end
- function getNicks()
- local ret = {}
- for k,v in pairs(logins) do
- ret[#ret+1] = k
- end
- return ret
- end
- function createGist(nick, fileTbl, desc, pub)
- local send = json.encode({files = createFS(fileTbl), description = desc, public = pub})
- local s = http.post("https://api.github.com/gists", send, {Authorization = logins[nick]})
- local inf = s.readAll()
- return json.decode(inf).id
- end
- function updateGist(nick, ID, files)
- local send = json.encode({files = createFS(files)})
- local s = http.post("https://api.github.com/gists/"..ID, send, {Authorization = logins[nick]})
- return json.decode(s.readAll()).id
- end
- function getGistFiles(ID)
- local s = http.get("https://api.github.com/gists/"..ID)
- return json.decode(s.readAll()).files
- end
- function getUsersGists(nick)
- local s = http.get("https://api.github.com/gists", {Authorization=logins[nick]})
- return json.decode(s.readAll())
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement