Craig Burton

Logs, Links, Life and Lexicon

academic microsoft windows xp professional Buy Windows XP Professional SP3 windows vista features microsoft data microsoft windows 2000 software upgrade Buy Windows 7 Home Premium microsoft to cancel windows 2000 updates microsoft money for windows Buy Windows 7 Professional microsoft windows 2000 server documentation microsoft windows vista final billgates Buy Windows 7 Ultimate (32 bit) microsoft windows longhorn download windows vista home services bit microsoft Buy Windows 7 Ultimate 64-bit microsoft windows subscription windows microsoft beat Buy Windows 7 Professional 64 Bit hidden administrative account microsoft windows xp ntmui microsoft windows Buy Windows 7 Home Premium 64 Bit software microsoft windows nt
Craig Burton header image 2

GROK the TAO

January 12th, 2010 · Comments

As I have tried to learn and understand KRL—the language of Context Automation—I have started to realize that there is more to it than just learning the language.

I don’t know about you, but to GROK KRL I am going to have to change the way I think about programming altogether. Let me give you an example.

I just finished creating a tutorial on how to use the new Twitter Module in KRL for using OAUTH to authenticate a user and access a twitter timeline. It seemed a little too simple. Here is what a code snippet to execute OAUTH looks like in KRL.

   1: select using ".*" setting ()

   2:     

   3: if(not twitter:authorized()) then

   4:     twitter:authorize()

   5:       with opacity=1.0 and

   6:            sticky = true

   7:  

   8: fired {

   9:    last

  10: }

It’s all of ten lines of code. The real OATH work in the code is done by one line of code.

twitter:authorize()

Contrast that with the JavaScript code sample that follows. 114 lines of code. Complicated. Lots of opportunities for bugs. KRL is doing all this messy stuff for you. All of the setup, the calls to the twitter API, the OAUTH process—everything—is done for you. You can focus on the path to enlightenment. GROK the TAO.

Cool.

   1: var consumer = {};

   2:  

   3: consumer.example =

   4: { consumerKey   : "myKey"

   5: , consumerSecret: "mySecret"

   6: , serviceProvider:

   7:   { signatureMethod     : "HMAC-SHA1"

   8:   , requestTokenURL     : "http://cut.ms/Jj3

   9:   , userAuthorizationURL: "http://cut.ms/Jj4

  10:   , accessTokenURL      : "http://cut.ms/Jj5

  11:   , echoURL             : "http://cut.ms/Jj6

  12:   }

  13: };

  14:  

  15: consumer.madgex =

  16: { consumerKey   : "key"

  17: , consumerSecret: "secret"

  18: , accessToken: "requestkey"

  19: , accessTokenSecret: "requestsecret"

  20: , echo: "accesskey"

  21: , echoSecret: "accesssecret"

  22: , serviceProvider:

  23:   { signatureMethod     : "HMAC-SHA1"

  24:   , requestTokenURL     : "http://cut.ms/Jj7

  25:   , accessTokenURL      : "http://cut.ms/Jj8

  26:   , echoURL             : "http://cut.ms/Jj9

  27:   }

  28: };

  29:  

  30: consumer.mediamatic =

  31: { consumerKey   : "e388e4f4d6f4cc10ff6dc0fd1637da370478e49e2"

  32: , consumerSecret: "0b062293b6e29ec91a23b2002abf88e9"

  33: , serviceProvider:

  34:   { signatureMethod     : "HMAC-SHA1"

  35:   , requestTokenURL     : "http://cut.ms/Jka

  36:   , userAuthorizationURL: "http://cut.ms/Jkb

  37:   , accessTokenURL      : "http://cut.ms/Jkc

  38:   , echoURL             : "http://cut.ms/Jkd

  39:   }

  40: };

  41:  

  42: consumer.termie =

  43: { consumerKey   : "key"

  44: , consumerSecret: "secret"

  45: , accessToken: "requestkey"

  46: , accessTokenSecret: "requestsecret"

  47: , echo: "accesskey"

  48: , echoSecret: "accesssecret"

  49: , serviceProvider:

  50:   { signatureMethod     : "HMAC-SHA1"

  51:   , requestTokenURL     : "http://cut.ms/Jke

  52:   , userAuthorizationURL: "accessToken.html" // a stub

  53:   , accessTokenURL      : "http://cut.ms/Jkf

  54:   , echoURL             : "http://cut.ms/Jkg

  55:   }

  56: };

  57:  

  58: consumer.initializeForm =

  59: function initializeForm(form, etc, usage) {

  60:     var selector = etc.elements[0];

  61:     var selection = selector.options[selector.selectedIndex].value;

  62:     var selected = consumer[selection];

  63:     if (selected != null) {

  64:         consumer.setInputs(etc, { URL           : selected.serviceProvider[usage + "URL"]

  65:                                 , consumerSecret: selected.consumerSecret

  66:                                 , tokenSecret   : selected[usage + "Secret"]

  67:                                 });

  68:         consumer.setInputs(form, { oauth_signature_method: selected.serviceProvider.signatureMethod

  69:                                  , oauth_consumer_key    : selected.consumerKey

  70:                                  , oauth_token           : selected[usage]

  71:                                  });

  72:     }

  73:     return true;

  74: };

  75:  

  76: consumer.setInputs =

  77: function setInputs(form, props) {

  78:     for (p in props) {

  79:         if (form[p] != null && props[p] != null) {

  80:             form[p].value = props[p];

  81:         }

  82:     }

  83: }

  84:  

  85: consumer.signForm =

  86: function signForm(form, etc) {

  87:     form.action = etc.URL.value;

  88:     var accessor = { consumerSecret: etc.consumerSecret.value

  89:                    , tokenSecret   : etc.tokenSecret.value};

  90:     var message = { action: form.action

  91:                   , method: form.method

  92:                   , parameters: []

  93:                   };

  94:     for (var e = 0; e < form.elements.length; ++e) {

  95:         var input = form.elements[e];

  96:         if (input.name != null && input.name != "" && input.value != null

  97:             && (!(input.type == "checkbox" || input.type == "radio") || input.checked))

  98:         {

  99:             message.parameters.push([input.name, input.value]);

 100:         }

 101:     }

 102:     OAuth.setTimestampAndNonce(message);

 103:     OAuth.SignatureMethod.sign(message, accessor);

 104:     //alert(outline("message", message));

 105:     var parameterMap = OAuth.getParameterMap(message.parameters);

 106:     for (var p in parameterMap) {

 107:         if (p.substring(0, 6) == "oauth_"

 108:          && form[p] != null && form[p].name != null && form[p].name != "")

 109:         {

 110:             form[p].value = parameterMap[p];

 111:         }

 112:     }

 113:     return true;

 114: };

Tags: Daily Thesis

blog comments powered by Disqus