Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local shorten;
- do
- local key = "AIzaSyCIsKSsr1iu2PIbfa03IcDXqUgJk6gwKyg";
- function shorten( url )
- -- loads the HTTP module and any libraries it requires
- local http = require("socket.http");
- local ltn12 = require("ltn12");
- local response = {}
- local body, code, headers, status = http.request {
- url = "https://www.googleapis.com/urlshortener/v1/url?key=" .. key,
- method = "POST",
- source = JSONEncode( {
- ["longUrl"] = url,
- } ),
- headers = {
- ["Content-Type"] = "application/json",
- },
- sink = ltn12.sink.table( response ),
- };
- print('body:' .. tostring(body))
- print('code:' .. tostring(code))
- print('headers:' .. util.tableToString(headers))
- print('status:' .. tostring(status))
- end
- end
- MOD.AddCom( "shorten", shorten );
- MOD.Shorten = shorten;
Advertisement
Add Comment
Please, Sign In to add comment