Skip to content

Commit

Permalink
discovery index for data API, closes #20
Browse files Browse the repository at this point in the history
  • Loading branch information
EfraimFeinstein committed May 22, 2012
1 parent f3812ff commit f6cab9e
Show file tree
Hide file tree
Showing 5 changed files with 145 additions and 70 deletions.
69 changes: 69 additions & 0 deletions code/api/data/dindex.xqm
@@ -0,0 +1,69 @@
xquery version "3.0";
(: API module for functions for index URIs
:
: Functions assume that the following has already been done:
: authentication,
: content negotiation
:
: Copyright 2012 Efraim Feinstein <efraim@opensiddur.org>
: Open Siddur Project
: Licensed Under the GNU Lesser General Public License, version 3 or later
:)
module namespace dindex = 'http://jewishliturgy.org/api/data/index';

declare namespace rest="http://exquery.org/ns/rest/annotation/";
declare namespace output="http://www.w3.org/2010/xslt-xquery-serialization";
declare namespace o="http://a9.com/-/spec/opensearch/1.1/";

(:~ list all available data APIs :)
declare
%rest:GET
%rest:path("/data")
%rest:produces("application/xhtml+xml", "text/html", "application/xml", "text/xml")
function dindex:list(
) as item()+ {
<rest:response>
<output:serialization-parameters>
<output:method value="html5"/>
</output:serialization-parameters>
</rest:response>,
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>Open Siddur API Index</title>
</head>
<body>
<ul class="results">
<li class="result">
{((: TODO: replace request:get-uri() with rest:get-absolute-uri()
:))}
<a class="discovery" href="{request:get-uri()}/transliteration">Transliteration</a>
</li>
</ul>
</body>
</html>
};

declare
%rest:GET
%rest:path("/data/OpenSearchDescription")
%rest:query-param("source", "{$source}", "")
%rest:produces("application/opensearchdescription+xml","application/xml","text/xml")
function dindex:open-search(
$source as xs:string
) as item()+ {
<rest:response>
<output:serialization-parameters>
<output method="xml"/>
</output:serialization-parameters>
</rest:response>,
<o:OpenSearchDescription
xmlns:jsearch="http://jewishliturgy.org/ns/search">
<o:ShortName>Open Siddur Search</o:ShortName>
<o:Description>Full text search of Open Siddur texts.</o:Description>
<o:Tags>siddur</o:Tags>
<o:Contact>efraim@opensiddur.org</o:Contact>
<o:Url type="application/xhtml+xml"
template="{$source}?q={{searchTerms}}&amp;start={{startIndex?}}&amp;max-results={{count?}}"
/>
</o:OpenSearchDescription>
};
1 change: 1 addition & 0 deletions code/queries/pre-release-testing.xql
Expand Up @@ -14,6 +14,7 @@ let $tests-to-run :=
<test module="/code/tests/api/access.t.xml" /> <test module="/code/tests/api/access.t.xml" />
<test module="/code/tests/api/login.t.xml"/> <test module="/code/tests/api/login.t.xml"/>
<test module="/code/tests/modules/mirror.t.xml" admin="1"/> <test module="/code/tests/modules/mirror.t.xml" admin="1"/>
<test module="/code/tests/api/data/dindex.t.xml"/>
<test module="/code/tests/api/data/transliteration.t.xml"/> <test module="/code/tests/api/data/transliteration.t.xml"/>
<test module="/code/tests/transforms/translit/translit.t.xml"/> <test module="/code/tests/transforms/translit/translit.t.xml"/>
</tests> </tests>
Expand Down
65 changes: 0 additions & 65 deletions code/tests/api/data/data.t.xml

This file was deleted.

44 changes: 44 additions & 0 deletions code/tests/api/data/dindex.t.xml
@@ -0,0 +1,44 @@
<?xml version="1.0" encoding="utf-8"?>
<TestSuite
xmlns:tei="http://www.tei-c.org/ns/1.0"
xmlns:j="http://jewishliturgy.org/ns/jlptei/1.0"
xmlns:jx="http://jewishliturgy.org/ns/jlp-processor"
xmlns:o="http://a9.com/-/spec/opensearch/1.1/"
xmlns:http="http://expath.org/ns/http-client">
<suiteName>Data API index test</suiteName>
<description>
<p>Test the data API index</p>
<author>Efraim Feinstein</author>
<copyright>Copyright 2012 Efraim Feinstein,
Licensed under the GNU Lesser General Public License, version 3 or later</copyright>
</description>
<setup/>
<namespace prefix="html">http://www.w3.org/1999/xhtml</namespace>
<namespace prefix="o">http://a9.com/-/spec/opensearch/1.1/</namespace>
<imports>
import module namespace dindex="http://jewishliturgy.org/api/data/index"
at "xmldb:exist:///code/api/data/dindex.xqm";
</imports>
<TestSet>
<testName>dindex:list()</testName>
<test>
<task>GET</task>
<code><![CDATA[
dindex:list()
]]></code>
<class href="../common.t.xml#SerializeHTML5"/>
<xpath desc="returns a results class">.//html:*[@class='results']</xpath>
<xpath desc="returns at least one result class">count(.//html:li[@class='result']) &gt;= 1</xpath>
</test>
</TestSet>
<TestSet>
<testName>dindex:open-search()</testName>
<test>
<task>GET, no source</task>
<code><![CDATA[
dindex:open-search("")
]]></code>
<xpath desc="An OpenSearch description is returned">self::o:OpenSearchDescription</xpath>
</test>
</TestSet>
</TestSuite>
36 changes: 31 additions & 5 deletions data/controller.xql
@@ -1,9 +1,35 @@
xquery version "1.0"; xquery version "3.0";
(: this controller simply redirects to /code/api :) (: This controller behaves like a fill-in for RESTXQ.
: It does not do content negotiation.
: Copyright 2012 Efraim Feinstein <efraim@opensiddur.org>
: Licensed under the GNU Lesser General Public License, version 3 or later
:)
import module namespace api="http://jewishliturgy.org/modules/api"
at "xmldb:exist:///code/api/modules/api.xqm";
import module namespace dindex="http://jewishliturgy.org/api/data/index"
at "xmldb:exist:///code/api/data/dindex.xqm";

declare namespace exist="http://exist.sourceforge.net/NS/exist"; declare namespace exist="http://exist.sourceforge.net/NS/exist";


declare variable $exist:path external; declare variable $exist:path external;
declare variable $exist:resource external;


<exist:dispatch> let $uri := request:get-uri()
<exist:redirect url="/code/api/data/{$exist:path}"/> let $authenticated :=
</exist:dispatch> (: log in if you can, otherwise, let the access be checked
: by the called function
:)
api:request-authentication()
return
api:rest-response(
switch (api:get-method())
case "GET"
return
if ($exist:resource="OpenSearchDescription")
then
dindex:open-search(request:get-parameter("source", ""))
else
dindex:list()
default
return api:rest-error(405, "Method not allowed")
)

0 comments on commit f6cab9e

Please sign in to comment.