close

  
<p> function random() {
  return Math.floor(Math.random()*1000000);
}

function triplify(data) {
  var payload = "";
  for each (var d in data) {
    payload += JSON.stringify(d) + "\n";
  }
  return payload;
}
  
var rnd = random();
var ext_key = "/user/freeq_test_bot/" + rnd + "_key";
var ext_prop = "/user/freeq_test_bot/" + rnd + "_prop";
var ns_key = "/user/freeq_test_bot/" + rnd + "_ns";
var key1x = ext_key + "/" + random();
var key1ns = ns_key + "/" + random();
var id = "/en/john_f_kennedy";

var data = [
    {"action":"CREATE_EXTERNAL",  "data":{"id":ext_key,  "acts_like":    "/type/namespace"} },
    {"action":"CREATE_EXTERNAL",  "data":{"id":ext_prop, "acts_like":    "/type/property"} },
    {"action":"CREATE_NAMESPACE", "data":{"id":ns_key,   "uri_template": "http://en.wikipedia.org/wiki/{key}"} },
    {"action":"LOAD_TRIPLE",      "data":{"triple":{"s":id, "p":"key",    "o":key1x}} },
    {"action":"LOAD_TRIPLE",      "data":{"triple":{"s":id, "p":ext_prop, "o":{"foo":"bar", "baz":"zap"} }} },
    {"action":"LOAD_TRIPLE",      "data":{"triple":{"s":id, "p":"key",    "o":key1ns}} }
];

var headers = {};
headers['accept'] = 'text/plain';
headers['content-type'] = 'application/x-www-form-urlencoded';

var params = {};
params['action_type'] = "GENERIC";
params['graphport'] = "otg-scratch";
params['payload'] = triplify(data);
params['user'] = '/user/freeq_test_bot';

var argus = acre.request.params.argus || "http://dw01.corp.metaweb.com:5000/";
var instance = acre.request.params.instance || "unittest";
var url = argus + instance + ((acre.request.params.job) ? "/" + acre.request.params.job : "");

var response = acre.urlfetch(url,"POST",headers,acre.form.encode(params));
                             
acre.write(JSON.stringify(response,null,2));

var body = JSON.parse(response.body);

acre.write("\n\n" + JSON.stringify(body,null,2));

 </p>

Comments

Hide