Posted by: Ian | May 3, 2010

Repository Junction AJAX-able APIs

Three beta APIs for people…. feedback more than welcome:

These three are built to be AJAX responders within an EPrints framework, but are perfectly suitable for any environment.

cgi/get_repos

Searches for repositories based on name or URL:

    cgi/get_orgs?q=ed.ac
    cgi/get_orgs?q=ed.ac&field=url
    cgi/get_nets?q=edinb
    cgi/get_nets?q=edinb&field=name

“q” is mandatory, and is the value the query the database with, “field” is an optional parameter and forces the script to search in justthe name for the organisation (“field=name”) or  just the url (“field=url”).

If “field” is not specificd, then the script searches both.

cgi/get_orgs

Searches for organisations based on name or URL:

    cgi/get_orgs?q=ed.ac
    cgi/get_orgs?q=ed.ac&field=url
    cgi/get_nets?q=edinb
    cgi/get_nets?q=edinb&field=name

“q” is mandatory, and is the value the query the database with, “field” is an optional parameter and forces the script to search in just the name for the organisation (“field=name”) or  just the url (“field=url”).

If “field” is not specificd, then the script searches both.

Note that the script searches both the name (or URL) and the “alternate” value (or, indeed, all for fields if name is not specified)

cgi/get_nets

Searches for networks based on an IP number, or the name for that network:

    cgi/get_nets?q=129.215
    cgi/get_nets?q=129.215&field=ip
    cgi/get_nets?q=edinb
    cgi/get_nets?q=edinb&field=name

“q” is mandatory, and is the value the query the database with, “field” is an optional parameter and forces the script to search in just the IP range (“field=ip”) or the name for the network (“field=name”).

If “field” is not specificd, then the script deduces the index to use based on the value: if there is anything other than a digit, a full stop, or an underscore then the field is assumed to be “name” else it will be “ip”

The returned format

In all three cases, the data is returned in essentially the same format.

That format can be altered depending in the AJAX engine being used: prototype, json, or [plain] text (see the “format” section of the API documentation)

For the Prototype format, the scripts return an unordered list, with the values for each selection in a sub-list. Also note that the data returned is not well-formed XML as its not got the XML declaration at the top.

<ul class='orgs'>

<li class='org'>Edinburgh College of Art
                   <br /> http://www.eca.ac.uk/
<ul class='values'>
<li id='for:value:component:_oid'>17533</li>
<li id='for:value:component:_ocname'>Edinburgh College of Art</li>
<li id='for:value:component:_oname'>Edinburgh College of Art</li>
<li id='for:value:component:_ourl'>http://www.eca.ac.uk/</li>
<li id='for:value:component:_oacronym'></li>
<li id='for:value:component:_onamepreferred'></li>
<li id='for:value:component:_oaltname'></li>
<li id='for:value:component:_oalturl'>
</li>
</ul>
</li>

<li class='org'>Edinburgh Napier University
                   <br /> http://www.napier.ac.uk/
<ul class='values'>
<li id='for:value:component:_oid'>17542</li>
<li id='for:value:component:_ocname'>Edinburgh Napier University</li>
<li id='for:value:component:_oname'>Edinburgh Napier University</li>
<li id='for:value:component:_ourl'>http://www.napier.ac.uk/</li>
<li id='for:value:component:_oacronym'></li>
<li id='for:value:component:_onamepreferred'></li>
<li id='for:value:component:_oaltname'></li>
<li id='for:value:component:_oalturl'></li>
</ul>
</li>

<li class='org'>Edinburgh's Telford College
                   <br /> http://www.ed-coll.ac.uk/
<ul class='values'>
<li id='for:value:component:_oid'>17583</li>
<li id='for:value:component:_ocname'>Edinburgh's Telford College</li>
<li id='for:value:component:_oname'>Edinburgh's Telford College</li>
<li id='for:value:component:_ourl'>http://www.ed-coll.ac.uk/</li>
<li id='for:value:component:_oacronym'></li>
<li id='for:value:component:_onamepreferred'></li>
<li id='for:value:component:_oaltname'></li>
<li id='for:value:component:_oalturl'></li>
</ul>
</li>

<li class='org'>Queen Margaret University, Edinburgh
                   <br /> http://www.qmu.ac.uk/
<ul class='values'>
<li id='for:value:component:_oid'>16960</li>
<li id='for:value:component:_ocname'>Queen Margaret University, Edinburgh</li>
<li id='for:value:component:_oname'>Queen Margaret University, Edinburgh</li>
<li id='for:value:component:_ourl'>http://www.qmu.ac.uk/</li>
<li id='for:value:component:_oacronym'></li>
<li id='for:value:component:_onamepreferred'></li>
<li id='for:value:component:_oaltname'></li>
<li id='for:value:component:_oalturl'></li>
</ul>
</li>

<li class='org'>The University of Edinburgh
                   <br /> http://edina.ac.uk/
<ul class='values'>
<li id='for:value:component:_oid'>17490</li>
<li id='for:value:component:_ocname'>The University of Edinburgh</li>
<li id='for:value:component:_oname'>The University of Edinburgh</li>
<li id='for:value:component:_ourl'>http://edina.ac.uk/</li>
<li id='for:value:component:_oacronym'></li>
<li id='for:value:component:_onamepreferred'></li>
<li id='for:value:component:_oaltname'></li>
<li id='for:value:component:_oalturl'></li>
</ul>
</li>

<li class='org'>University of Edinburgh
                   <br />[University of Edinburgh] http://www.ed.ac.uk
<ul class='values'>
<li id='for:value:component:_oid'>16480</li>
<li id='for:value:component:_ocname'>University of Edinburgh</li>
<li id='for:value:component:_oname'>University of Edinburgh</li>
<li id='for:value:component:_ourl'>http://www.ed.ac.uk</li>
<li id='for:value:component:_oacronym'></li>
<li id='for:value:component:_onamepreferred'></li>
<li id='for:value:component:_oaltname'>University of Edinburgh</li>
<li id='for:value:component:_oalturl'></li>
</ul>
</li>

</ul>

JSON formatted data is as you would expect:

{
 status:ok,
 to:http://devel.edina.ac.uk:1201/cgi/get_nets,
 message:{
  [
{nid:7156;nname: Latin American and Caribbean Center for Health Science;inetnum:200.10.178.0-200.10.179.255;dec_l:200.10.178.0;dec_u:200.10.179.255}
{nid:6761;nname:"Centre for Advanced Computing ";inetnum:146.64.0.0 - 146.64.255.255;dec_l:146.64.0.0;dec_u:146.64.255.255}
{nid:6787;nname:1&1 Internet;inetnum:212.227.134.0 - 212.227.143.255;dec_l:212.227.134.0;dec_u:212.227.143.255}
]
 }
}
Advertisements

Responses

  1. […] Junction List APIs Following on from the Repository Junction APIs post, here are another set of (beta) APIs for people to play with – one that lists data by […]


Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

Categories

%d bloggers like this: