API

Public Domain Calculators

In addition to being run as a standalone program, the public domain calculators provide an API that can be easily integrated into a website.

 

Here is an example on how to do it by means of simple javascript code:

<!DOCTYPE html>

<html>

<head>

 

<meta charset=”utf-8″ />

<title>Public Domain Works example</title>

 

<script src=”//ajax.googleapis.com/ajax/libs/jquery/1.8.1/jquery.min.js”></script>

 

<script type=”text/javascript”>

jQuery(document).ready(function($) {

// Function that specifies how to display the results:

 

 var showresult = function(data) {

 

       $(‘#result’).remove();

 

       var result = ‘<div id=”result”>’;

 

      for ( var i in data ) {

 

/* data is an array that contains the following information:

   “output” : questions, answers and assumptions for every node in the decision tree

   “errors”  : all errors raised along the process

   “work”    : the JSON description of the work being processed */

 

result +=  i + ‘: ‘ + JSON.stringify( data[i] ).replace( /\\n/g, ‘<br>’ ).replace( /\\”/g, ” );

      }

 

       result += ‘</div>’;

 

       $(‘body’).append(result);

   }

// Function that specifies what to do once the query has been submitted:

 

   var pdw = function(event) {

event.preventDefault();

var url = ‘http://publicdomainworks.net/api/pd?jurisdiction=’ + $(‘#jurisdiction’).val()   // relevant jurisdiction

 

//  if the metadata has been passed as POST (in JSON format)

+ ‘&work=’ + JSON.stringify(work);

 

// if the metadata is provided through a filename (in JSON or RDF format)

+ ‘&work=’ + ‘http://bnb.bibsoup.net/bibsoup/bnb/GB9407119.json’;

+ ‘&work=’ + ‘https://raw.github.com/okfn/pdcalc/master/pd/’ + $(‘#work’).val() + ‘.rdf’;

 

     $.ajax({

           type: “get”,

           url: url,

           dataType: ‘jsonp’,

           success: showresult,

           error: showresult

       });

   }

 

   $(‘#submit’).bind(‘click’, pdw);

 

})

 

</script>

</head>

 

<body>

 

<p>

jurisdiction: <select name=”jurisdiction” id=”jurisdiction”>

<option>austria</option>

<option>spain</option>

<option>uk</option>

</select>

</p>

 

<p>

metadata file: <select name=”work” id=”work”>

<option>A</option>

<option>B</option>

<option>C</option>

</select>

</p>

 

<p><input type=”submit” name=”submit” value=”submit” id=”submit” /></p>

 

</body>

</html>

Leave a Reply

Your email address will not be published. Required fields are marked *