Other example uses of the ORI APIs are example_get.html and example_list.html
This is a very simple client/demonstrator of the ORI.
(The api is devel.edina.ac.uk:1201/cgi/api5. Documentation is on the blog)
To play with it, add various parameters to the end of the url:
The data is known to contain errors, and there will be a concerted effort to "tidy up" shortly.
The client-side script that is being run to create content inside the box above is:
#!/usr/bin/perl
use strict;
use Data::Dumper;
use CGI;
use LWP::Simple qw(get);
use JSON qw(from_json);
use URI::Escape;
use HTML::Entities;
my $host = 'http://devel.edina.ac.uk:1201/';
##########################
#
# Render response
#
##########################
sub list_repos {
my $data = shift;
my %orgs = ();
my $network;
if ( $data->{'status'} == 'ok' ) {
# NETWORK
for my $net ( values %{ $data->{'message'}->{'net'} } ) {
if ( !$net->{'orgs'} ) {
print '<p><strong>No organisations were found.</strong></p>';
} else {
# ORGANISATION
for my $org ( sort { $a->{'org_name'} cmp $b->{'org_name'} }
@{ $net->{'orgs'} } )
{
print '<div class="org">';
print '<div class="org_map">';
print '<img src="http://maps.googleapis.com/maps/api/staticmap?center='
. $org->{'lat'} . ',' . $org->{'long'}
. '&size=500x500&sensor=false&zoom=14&maptype=hybrid&markers=color:blue%7Clabel:O%7C'
. $org->{'lat'} . ',' . $org->{'long'} . '" />';
print '</div>';
unless ( defined $org->{'repos'} ) {
printf
'<p class="org-summary"><strong>%s</strong> has no known repositories registered.</p>',
$org->{'org_name'};
} else {
# Organisation summary text
printf
'<p class="org-summary"><strong>%s</strong> has %d associated %s.</p>',
$org->{'org_name'},
scalar @{ $org->{'repos'} },
( scalar @{ $org->{'repos'} } == 1 )
? 'repository'
: 'repositories';
# REPOSITORIES
if ( scalar @{ $org->{'repos'} } ) {
print '<div class="repos">';
for my $repo ( sort { $a->{'repo_name'} cmp $b->{'repo_name'} }
@{ $org->{'repos'} } )
{
print '<div class="repo">';
print '<div class="repo_map">';
print '<img src="http://maps.googleapis.com/maps/api/staticmap?center=' . $repo->{'lat'}
. ',' . $repo->{'long'}
. '&size=300x300&sensor=false&zoom=16&maptype=hybrid&markers=color:blue%7Clabel:R%7C'
. $repo->{'lat'} . ',' . $repo->{'long'} . '" />';
print '</div>';
print '<dl class="oarj_repository">';
# Name
print '<dt class="oarj_name">Repository name :</dt>';
print '<dd>';
printf
'<a href="http://%s/cgi/RJ-Bounce?url=%s" rel="external">%s</a>',
$ENV{'HTTP_HOST'},
uri_escape( $repo->{'repo_url'} ),
$repo->{'repo_name'};
print " ($repo->{'repo_acronym'})"
if ( $repo->{'repo_acronym'} );
print ' <span style="font-size:smaller">(live:'
. $repo->{'repo_date_checked'} . ')</span>'
if $repo->{'repo_checked_good'};
print '</dd>';
# Description
if ( $repo->{'description'} ) {
print
'<dt class="oarj_description_title">Description :</dt>';
print '<dd class="oarj_description_text">';
print encode_entities( $repo->{'description'} );
print '</dd>';
} ## end if ( $repo->{'description'...})
# Comment(s)
if ( exists $repo->{'comment'} && scalar @{$repo->{'comment'}} ) {
print '<dt class="oarj_comment_title">Additional Comment :</dt>';
foreach my $c ( @{$repo->{'comment'}} ) {
print '<dd class="oarj_comment_text">';
print encode_entities( $c );
print '</dd>';
}
} ## end if ( $repo->{'comment'...})
# Repository Type(s)
if ( $repo->{'types'} ) {
print
'<dt class="oarj_types_title">Repository Type(s) : </dt>';
print '<dd class="oarj_types_text">';
print join ', ', @{ $repo->{'types'} };
print '</dd>';
} ## end if ( $repo->{'types'} )
# Content Type(s)
if ( $repo->{'content'} ) {
print
'<dt class="oarj_content_title">Content Type(s) : </dt>';
print '<dd class="oarj_content_text">';
print join ', ', @{ $repo->{'content'} };
print '</dd>';
} ## end if ( $repo->{'content'...})
# Languages
if ( $repo->{'language'} ) {
print '<dt class="oarj_lang_title">Language(s) : </dt>';
print '<dd class="oarj_language_text">';
print join ', ', @{ $repo->{'language'} };
print '</dd>';
} ## end if ( $repo->{'language'...})
print '</dl>';
print '</div>';
} ## end for my $repo ( sort { $a...})
print '</div>';
} ## end if ( scalar @{ $org->{...}})
} ## end else
print '</div>';
} ## end for my $org ( sort { $a...})
} ## end else [ if ( !$net->{'orgs'} )]
} ## end for my $net ( @{ $data->...})
} ## end if ( $data->{'status'}...)
} ## end sub list_repos
##########################
#
# Main
#
##########################
my $query = CGI->new;
print $query->header('text/plain');
#print $query->header();
# Setup query string for API call
my ( %params, @queryString, @ips, @orgs, @contents, @types, @geos );
@queryString = ();
@ips = $query->param('ip');
@orgs = $query->param('org');
@geos = $query->param('geo');
@contents = $query->param('content');
@types = $query->param('type');
unless ( scalar @ips || scalar @orgs || scalar @geos ) {
( $ips[0] ) = ( $ENV{'REMOTE_ADDR'} );
}
for my $ip (@ips) {
push( @queryString, "ip=$ip" );
}
for my $org (@orgs) {
push( @queryString, "org=$org" );
}
for my $geo (@geos) {
push( @queryString, "geo=$geo" );
}
for my $content (@contents) {
push( @queryString, "content=$content" );
}
for my $types (@types) {
push( @queryString, "type=$types" );
}
# Get JSON object
my $url
= "http://devel.edina.ac.uk:1201/cgi/api5?" . join( '&', @queryString );
my $foo = from_json( get($url), { utf8 => 1 } );
print list_repos($foo);