<div dir="ltr">Winona, <div>this sounds like an interesting direction -- I'm mostly in the dark on modules, so this is really neat. </div><div><br></div><div>Thanks!</div><div>Bridger</div></div><div class="gmail_extra"><br><div class="gmail_quote">On Mon, Jan 18, 2016 at 1:11 PM, Winona Salesky <span dir="ltr"><<a href="mailto:wsalesky@gmail.com" target="_blank">wsalesky@gmail.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr">Have you considered using  the EXPath http client rather then the doc() function, I find it to be a more flexible option for handling API interactions? <a href="http://expath.org/modules/http-client/samples" target="_blank">http://expath.org/modules/http-client/samples</a><div><br></div><div>You can then run your query, and base subsequent action on the http status code, do a if/else for http status code 200, if 200, then test for a resumption token. If there is a resumption token, resubmit same query with resumption token parameter added otherwise (if no resumption token) your query is done. </div><div><br></div><div>Does that help? Or are you looking for something a little more step by step?</div><div>-Winona</div><div><br></div></div><div class="gmail_extra"><br><div class="gmail_quote"><div><div class="h5">On Mon, Jan 18, 2016 at 11:58 AM, Bridger Dyson-Smith <span dir="ltr"><<a href="mailto:bdysonsmith@gmail.com" target="_blank">bdysonsmith@gmail.com</a>></span> wrote:<br></div></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div><div class="h5"><div dir="ltr">Hi Christian, <div><br></div><div>thank you for your help. I'm using BaseX 8.3.1 as my query processor. I'm guilty, I'm afraid, of presenting a poorly framed question to the list. I need to mull over the problem a little more. </div><div><br></div><div>Thanks again!</div><span><font color="#888888"><div>Bridger</div></font></span></div><div><div><div class="gmail_extra"><br><div class="gmail_quote">On Mon, Jan 18, 2016 at 11:32 AM, Christian Grün <span dir="ltr"><<a href="mailto:christian.gruen@gmail.com" target="_blank">christian.gruen@gmail.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">Hi Bridger,<br>
<br>
I know too little about the API you are working, and your query<br>
processor (parts of the semantics of fn:doc are<br>
implementation-defined), but I noticed that the URL construction might<br>
need to be revised:<br>
<br>
OLD:<br>
<span>  local:getPID(doc("$in" || "&amp;sessionToken=" || "$rQ"))<br>
<br>
</span>NEW:<br>
  local:getPID(doc($in || "&amp;sessionToken=" || encode-for-uri($rQ)))<br>
<br>
Possibly, $in (or a part of it) needs to be encoded as well.<br>
<br>
Hope this helps,<br>
Christian<br>
<div><div><br>
<br>
<br>
On Mon, Jan 18, 2016 at 5:09 PM, Bridger Dyson-Smith<br>
<<a href="mailto:bdysonsmith@gmail.com" target="_blank">bdysonsmith@gmail.com</a>> wrote:<br>
> Hi all,<br>
><br>
> I'm struggling with getting a working example of the following problem: I'm<br>
> sending a query to an API that returns some data and, if the data set is<br>
> large enough, a resumption token to requery the API.<br>
><br>
> I'm stuck at the point of how to generate the new query URL, while still<br>
> processing the new data. Is the best idea to create a function that will<br>
> update a new request to the API, or is there a different approach that can<br>
> be used?<br>
><br>
> I've made several attempts with functions -- the latest non-working examples<br>
> are below -- and I'm missing... something, but I don't know what.<br>
><br>
> Thanks for any guidance you can provide.<br>
> Cheers,<br>
> Bridger<br>
><br>
> (: sample query :)<br>
> (:<br>
> <a href="http://server:8080/fedora/objects?query=pid~%7B$collection%7D*&resultFormat=xml&pid=true" rel="noreferrer" target="_blank">http://server:8080/fedora/objects?query=pid~{$collection}*&resultFormat=xml&pid=true</a><br>
> :)<br>
><br>
> declare variable $query external :=<br>
> '<a href="http://our.server:8080/fedora/objects?query=pid~gamble*&amp;resultFormat=xml&amp;pid=true" rel="noreferrer" target="_blank">http://our.server:8080/fedora/objects?query=pid~gamble*&amp;resultFormat=xml&amp;pid=true</a>';<br>
> declare variable $sessionToken := '&amp;sessionToken=';<br>
> declare variable $resToken := '';<br>
><br>
> (:functions:)<br>
> (:doesn't work:)<br>
> declare function local:getPID($in as document-node()) as xs:anyAtomicType*<br>
> {<br>
>   data($in/*:resultList/*:objectFields/*:pid)<br>
> };<br>
><br>
> (:doesn't work:)<br>
> declare function local:reQuery(<br>
>   $in as document-node(),<br>
>   $rQ as xs:untypedAtomic*) as document-node()<br>
> {<br>
>   let $rQ := $in/*:listSession/*:token/text()<br>
>   return (<br>
>     if ($rQ) then<br>
>       local:getPID(doc("$in" || "&amp;sessionToken=" || "$rQ"))<br>
>     else ()<br>
>   )<br>
> };<br>
><br>
> (: this works processing the descendant elements but doesn't recurse :)<br>
> for $result in fn:doc($query)/*:result<br>
> let $resToken := $result/*:listSession/*:token/text()<br>
> let $pid := $result/*:resultList/*:objectFields/*:pid/text()<br>
> return (<br>
>   $result,<br>
>   $resToken,<br>
>   $pid<br>
> )<br>
><br>
> (: sample returned from query; e.g. $result :)<br>
> <result xmlns="<a href="http://www.fedora.info/definitions/1/0/types/" rel="noreferrer" target="_blank">http://www.fedora.info/definitions/1/0/types/</a>"<br>
> xmlns:types="<a href="http://www.fedora.info/definitions/1/0/types/" rel="noreferrer" target="_blank">http://www.fedora.info/definitions/1/0/types/</a>"<br>
> xmlns:xsi="<a href="http://www.w3.org/2001/XMLSchema-instance" rel="noreferrer" target="_blank">http://www.w3.org/2001/XMLSchema-instance</a>"<br>
> xsi:schemaLocation="<a href="http://www.fedora.info/definitions/1/0/types/" rel="noreferrer" target="_blank">http://www.fedora.info/definitions/1/0/types/</a><br>
> <a href="http://localhost:8080/fedora/schema/findObjects.xsd" rel="noreferrer" target="_blank">http://localhost:8080/fedora/schema/findObjects.xsd</a>"><br>
>   <listSession><br>
>     <token>63c0762b5eb3d4b46c58add843b7b3e6</token><br>
>     <cursor>0</cursor><br>
>     <expirationDate>2016-01-18T01:40:05.381Z</expirationDate><br>
>   </listSession><br>
>   <resultList><br>
>     <objectFields><br>
>       <pid>gamble:1</pid><br>
>     </objectFields><br>
>     <objectFields><br>
>       <pid>gamble:10</pid><br>
>     </objectFields><br>
>   </resultList><br>
> </result><br>
><br>
><br>
><br>
><br>
><br>
><br>
</div></div>> _______________________________________________<br>
> <a href="mailto:talk@x-query.com" target="_blank">talk@x-query.com</a><br>
> <a href="http://x-query.com/mailman/listinfo/talk" rel="noreferrer" target="_blank">http://x-query.com/mailman/listinfo/talk</a><br>
</blockquote></div><br></div>
</div></div><br></div></div>_______________________________________________<br>
<a href="mailto:talk@x-query.com" target="_blank">talk@x-query.com</a><br>
<a href="http://x-query.com/mailman/listinfo/talk" rel="noreferrer" target="_blank">http://x-query.com/mailman/listinfo/talk</a><br></blockquote></div><br></div>
</blockquote></div><br></div>