public

  • Download Gist
StringBin Module Test Harness.krl.js
JavaScript
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56
ruleset a369x116 {
meta {
name "SringBin Module Test Harness"
description <<
SringBin Module Test Harness
>>
author "AKO"
logging on
 
use module a369x115 alias StringBin with pin = "X9ooUUsrR180MkpxZ2N1M"
}
 
rule write_to_stringbin {
select when pageview ".*"
pre {
stuff = StringBin:write("yellow", "mellow");
}
 
emit <|
window.countOfThings = 0;
|>;
 
always {
raise explicit event "read_from_stringbin" with k = "yellow";
}
}
 
rule read_from_stringbin {
select when explicit read_from_stringbin
pre {
goodness = StringBin:read(event:param("k"));
}
{
emit <|
console.log(window.countOfThings + "\n" + JSON.stringify(goodness, null, 2));
window.countOfThings++;
|>;
}
 
always {
app:counter += 1 from 1;
raise explicit event "destroy_key_in_stringbin" with k = "yellow";
}
}
 
rule destroy_key_in_stringbin {
select when explicit destroy_key_in_stringbin
pre {
mcHorsty = StringBin:destroy(event:param("k"));
}
 
always {
raise explicit event "read_from_stringbin" with k = "yellow" if app:counter < 2;
}
}
}
StringBin Module.krl.js
JavaScript
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31
ruleset a369x115 {
meta {
name "StringBin Module"
description <<
StringBin Module
>>
author "AKO"
logging off
 
provide read, write, destroy
configure using pin = "nopin"
}
 
global {
 
datasource write <- "http://api.stringbin.com/1/write?" cachable for 1 second
datasource read <- "http://api.stringbin.com/1/read?" cachable for 1 second
 
write = function(k,v) {
datasource:write({"pin":pin,"key":k,"value":v})
}
 
read = function(k) {
datasource:read({"pin":pin,"key":k})
}
 
destroy = function(k) {
datasource:write({"pin":pin,"key":k,"value":""})
}
}
}

Please sign in to comment on this gist.

Something went wrong with that request. Please try again.