Posted By

jasonseney on 10/09/09


Tagged

wsh jscript technorati xmlhttp


Versions (?)

Technorati Ping - JScript WSH (javascript with XMLHTTP)


 / Published in: JavaScript
 

URL: http://technorati.com/developers/ping/

Run in cmd with:

> CScript pingTechnorati.js BLOG_NAME BLOG_URL
  1. // Technorati Ping
  2. // Sends out XML-RPC ping for blog updates to technorati
  3.  
  4. (function technoratiPing() {
  5.  
  6. WScript.Echo("Technorati Ping
  7. ");
  8.  
  9. if(WScript.Arguments.length < 2) {
  10. WScript.Echo("Usage: BLOG_NAME BLOG_URL");
  11. WScript.Quit();
  12. }
  13.  
  14. var blogName = WScript.Arguments.Item(0);
  15. var blogURL = WScript.Arguments.Item(1);
  16.  
  17. var xmlBody =
  18. "<?xml version=\"1.0\"?>" +
  19. "<methodCall>" +
  20. " <methodName>weblogUpdates.ping</methodName>" +
  21. " <params>" +
  22. " <param>" +
  23. " <value>" + blogName + "</value>" +
  24. " </param>" +
  25. " <param>" +
  26. " <value>" + blogURL + "</value>" +
  27. " </param>" +
  28. " </params>" +
  29. "</methodCall>";
  30.  
  31. var xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
  32.  
  33. xmlhttp.open("POST", "http://rpc.technorati.com/rpc/ping",false);
  34. xmlhttp.setRequestHeader("Content-Type","text/xml");
  35. xmlhttp.setRequestHeader("Content-Length","250");
  36. xmlhttp.send(xmlBody);
  37.  
  38. WScript.Echo(getResult(xmlhttp));
  39.  
  40. //Function to inspect the xml response and print out message.
  41. //@Warning make some assumtions about the xml format
  42. function getResult(request) {
  43. if (request.readyState == 4) {
  44. if (request.status == 200) {
  45.  
  46. var outputBuffer = "";
  47.  
  48. var members = request.responseXML.getElementsByTagName("member");
  49.  
  50. for (var x=0; x < members.length; x++) {
  51.  
  52. var name = members[x].childNodes[0].childNodes[0].nodeValue;
  53. var value = members[x].childNodes[1].childNodes[0].childNodes[0].nodeValue;
  54.  
  55. outputBuffer += name + ":" + value + "
  56. ";
  57. }
  58.  
  59. return outputBuffer;
  60. }
  61. }
  62. }
  63. })();

Report this snippet  

You need to login to post a comment.