Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions 6 Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,9 @@ OVERRIDES = \
.PHONY: lib clean purge

# if you change all: make sure all: in standard.mk is consistent.
# api-doc target must be run last.

all: installdirs $(TOOL_HDR) lib
all: installdirs $(TOOL_HDR) lib api-doc

# Use the PACKAGES macro to transform lib, bin, etc., targets
# into package level dependencies, e.g., lib -> PkgA.lib, PkgB.lib
Expand All @@ -67,7 +68,8 @@ purge:
rm -rf $(TARGET) bin/*.r

api-doc:
perl src/WebApplication/scripts/api2html.pl -url http://api.metagenomics.anl.gov -outfile site/CGI/Html/api.html
perl src/WebApplication/scripts/api2html.pl -url http://api.metagenomics.anl.gov/beta -site_name "MG-RAST" -outfile site/CGI/Html/api.html
perl src/WebApplication/scripts/api2html.pl -url http://kbase.us/services/communities/beta -site_name "Microbial Communities" -outfile site/CGI/Html/api.kbase.html

##
# Targets to setup the expected directory structure for the
Expand Down
14 changes: 12 additions & 2 deletions 14 src/MGRAST/cgi/api2.cgi
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,13 @@ if ($abs !~ /\.cgi/) {
}
my $rest = $cgi->url(-path_info=>1);
$rest =~ s/^.*$abs\/?//;
$rest =~ s/^\///;
$rest =~ s/^\d+//;
$rest =~ s/^beta//;
$rest =~ s/^\///;
$rest =~ s/^api2\.cgi//;
$rest =~ s/^\///;

my @rest_parameters = split m#/#, $rest;
map {$rest[$_] =~ s#forwardslash#/#gi} (0 .. $#rest);

Expand Down Expand Up @@ -177,11 +184,14 @@ if ($resource) {
}
# we are called without a resource, return API information
else {
my @resource_objects = map { { 'name' => $_, 'url' => $cgi->url.'/'.$_ } } sort @$resources;
my $cgi_url = $cgi->url;
$cgi_url =~ s/^(.*)\/$/$1/;
$cgi_url =~ s/^(.*)\/api2.cgi$/$1/;
my @resource_objects = map { { 'name' => $_, 'url' => $cgi_url.'/'.$_ } } sort @$resources;
my $content = { version => 1,
service => 'MG-RAST',
url => $cgi->url,
documentation => $cgi->url.'/api.html',
documentation => $cgi_url.'/api.html',
description => "RESTful Metagenomics RAST object and resource API\nFor usage note that required parameters need to be passed as path parameters, optional parameters need to be query parameters. If an optional parameter has a list of option values, the first displayed will be used as default.",
contact => 'mg-rast@mcs.anl.gov',
resources => \@resource_objects };
Expand Down
23 changes: 15 additions & 8 deletions 23 src/WebApplication/scripts/api2html.pl
Original file line number Diff line number Diff line change
Expand Up @@ -12,17 +12,19 @@

sub usage {
print "api2html.pl >>> create an HTML API documentation file from a REST API\n";
print "api2html.pl -url <url to api> -outfile <file for html output>\n";
print "api2html.pl -url <url to api> -site_name <name of site> -outfile <file for html output>\n";
}

# read in parameters
my $url = '';
my $outfile = '';
my $url = '';
my $site_name = '';
my $outfile = '';

GetOptions ( 'url=s' => \$url,
'site_name=s' => \$site_name,
'outfile=s' => \$outfile );

unless ($url and $outfile) {
unless ($url and $site_name and $outfile) {
&usage();
exit 0;
}
Expand Down Expand Up @@ -58,7 +60,7 @@ sub usage {
$structure->{resources} = $resources;

# start the template
my $html = template_start();
my $html = template_start($site_name);

# build the navigation
$html .= '<li><a href="#overview">overview</a></li>';
Expand All @@ -70,7 +72,7 @@ sub usage {
<div class="span12" style="margin-left: 270px;">
~;

$html .= "<h1><a name='overview' style='padding-top: 50px;'>".$structure->{service}->{name}." Overview</a></h1><p>".$structure->{service}->{description}."</p><hr>";
$html .= "<h1><a name='overview' style='padding-top: 50px;'>".$site_name." Overview</a></h1><p>".$structure->{service}->{description}."</p><hr>";

my %param_types = ( body => "<p>This parameter must be passed in the message body.</p>",
options => "<p>This is an optional parameter and may be passed in the query string.</p>",
Expand Down Expand Up @@ -113,6 +115,10 @@ sub usage {
}
}
$html .= "</ul>";
if (exists $req->{example}) {
$html .= "<h3>Example</h3><ul>";
$html .= "<li>".$req->{example}[0]."<li>".$req->{example}[1]."</ul>";
}
$html .= "<h3>Return Attributes</h3><ul>";
# iterate over attributes
foreach my $param (sort keys(%{$req->{attributes}})) {
Expand Down Expand Up @@ -188,11 +194,12 @@ sub usage {
exit;

sub template_start {
my $site_name = shift;
return qq~
<!DOCTYPE html>
<html>
<head>
<title>MG-RAST API</title>
<title>$site_name API</title>
<meta http-equiv="content-type" content="text/html; charset=utf-8" />
<script type="text/javascript" src="bootstrap.min.js"></script>
<link rel="stylesheet" type="text/css" href="bootstrap.min.css" />
Expand All @@ -202,7 +209,7 @@ sub template_start {
<div class="navbar navbar-inverse navbar-fixed-top">
<div class="navbar-inner">
<div class="container">
<a class="brand" href="./index.html">MG-RAST API documentation</a>
<a class="brand" href="./index.html">$site_name API documentation</a>
</div>
</div>
</div>
Expand Down
Morty Proxy This is a proxified and sanitized view of the page, visit original site.