diff --git a/code/api/data/dindex.xqm b/code/api/data/dindex.xqm new file mode 100644 index 00000000..716eaa4b --- /dev/null +++ b/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 + : 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()+ { + + + + + , + + + Open Siddur API Index + + + + + +}; + +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()+ { + + + + + , + + Open Siddur Search + Full text search of Open Siddur texts. + siddur + efraim@opensiddur.org + + +}; diff --git a/code/queries/pre-release-testing.xql b/code/queries/pre-release-testing.xql index 4bed0cdd..d971b22f 100644 --- a/code/queries/pre-release-testing.xql +++ b/code/queries/pre-release-testing.xql @@ -14,6 +14,7 @@ let $tests-to-run := + diff --git a/code/tests/api/data/data.t.xml b/code/tests/api/data/data.t.xml deleted file mode 100644 index 1d125621..00000000 --- a/code/tests/api/data/data.t.xml +++ /dev/null @@ -1,65 +0,0 @@ - - - Data API index test - -

Test the data API index

- Efraim Feinstein - Copyright 2012 Efraim Feinstein, - Licensed under the GNU Lesser General Public License, version 3 or later -
- - http://www.w3.org/1999/xhtml - - import module namespace apitest="http://jewishliturgy.org/modules/apitest" - at "xmldb:exist:///code/tests/api/apitest.xqm"; - - - HTTP REST calls - - - - - - - - GET accepting HTML - ) - ]]> - - - - - GET accepting text/plain - ) - ]]> - - - - PUT - ) - ]]> - - - - POST - ) - ]]> - - - - DELETE - - - - -
\ No newline at end of file diff --git a/code/tests/api/data/dindex.t.xml b/code/tests/api/data/dindex.t.xml new file mode 100644 index 00000000..99cfe353 --- /dev/null +++ b/code/tests/api/data/dindex.t.xml @@ -0,0 +1,44 @@ + + + Data API index test + +

Test the data API index

+ Efraim Feinstein + Copyright 2012 Efraim Feinstein, + Licensed under the GNU Lesser General Public License, version 3 or later +
+ + http://www.w3.org/1999/xhtml + http://a9.com/-/spec/opensearch/1.1/ + + import module namespace dindex="http://jewishliturgy.org/api/data/index" + at "xmldb:exist:///code/api/data/dindex.xqm"; + + + dindex:list() + + GET + + + .//html:*[@class='results'] + count(.//html:li[@class='result']) >= 1 + + + + dindex:open-search() + + GET, no source + + self::o:OpenSearchDescription + + +
\ No newline at end of file diff --git a/data/controller.xql b/data/controller.xql index 3d3c89b9..b4f586fe 100644 --- a/data/controller.xql +++ b/data/controller.xql @@ -1,9 +1,35 @@ -xquery version "1.0"; -(: this controller simply redirects to /code/api :) +xquery version "3.0"; +(: This controller behaves like a fill-in for RESTXQ. + : It does not do content negotiation. + : Copyright 2012 Efraim Feinstein + : 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 variable $exist:path external; +declare variable $exist:resource external; - - - +let $uri := request:get-uri() +let $authenticated := + (: 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") + ) \ No newline at end of file