aggixx

Untitled

Apr 13th, 2015
638
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.80 KB | None | 0 0
  1. local shorten;
  2.  
  3. do
  4. local key = "AIzaSyCIsKSsr1iu2PIbfa03IcDXqUgJk6gwKyg";
  5.  
  6. function shorten( url )
  7. -- loads the HTTP module and any libraries it requires
  8. local http = require("socket.http");
  9. local ltn12 = require("ltn12");
  10.  
  11. local response = {}
  12. local body, code, headers, status = http.request {
  13. url = "https://www.googleapis.com/urlshortener/v1/url?key=" .. key,
  14. method = "POST",
  15. source = JSONEncode( {
  16. ["longUrl"] = url,
  17. } ),
  18. headers = {
  19. ["Content-Type"] = "application/json",
  20. },
  21. sink = ltn12.sink.table( response ),
  22. };
  23.  
  24. print('body:' .. tostring(body))
  25. print('code:' .. tostring(code))
  26. print('headers:' .. util.tableToString(headers))
  27. print('status:' .. tostring(status))
  28. end
  29. end
  30.  
  31. MOD.AddCom( "shorten", shorten );
  32. MOD.Shorten = shorten;
Advertisement
Add Comment
Please, Sign In to add comment