Skip to content

Commit 8c4f256

Browse files
Access ROR client ID environment variable (#30)
* Access ROR client ID environment variable * Add temporary endpoint to test if accessing the environment variable is successful elifesciences/issues#9358
1 parent 379272e commit 8c4f256

File tree

1 file changed

+13
-0
lines changed

1 file changed

+13
-0
lines changed

src/webapp/validator.xqm

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,16 @@ module namespace e = 'http://elifesciences.org/modules/validate';
22
import module namespace session = "http://basex.org/modules/session";
33
import module namespace rest = "http://exquery.org/ns/restxq";
44
declare namespace svrl = "http://purl.oclc.org/dsdl/svrl";
5+
declare variable $e:ror-client-id := fn:environment-variable('ROR_CLIENT_ID');
6+
7+
declare
8+
%rest:GET
9+
%rest:path('/ror-test')
10+
function e:get-ror-client-id() {
11+
if ($e:ror-client-id)
12+
then <result>{$e:ror-client-id}</result>
13+
else <result>Variable was not found.</result>
14+
};
515

616
(: Schematron :)
717

@@ -404,6 +414,7 @@ declare function e:introduce-rors($xml as item()) {
404414
let $json := try {
405415
http:send-request(
406416
<http:request method='get' href="{('https://api.ror.org/v2/organizations?affiliation='||web:encode-url($display))}" timeout='2'>
417+
<http:header name="Client-Id" value="{$e:ror-client-id}"/>
407418
</http:request>)//*:json}
408419
catch * {<json><number__of__results>0</number__of__results></json>}
409420
return if ((number($json//*:number__of__results) = 0) or not($json//*:items/_[number(*:score[1]) ge 0.8]))
@@ -428,6 +439,7 @@ declare function e:introduce-rors($xml as item()) {
428439
let $json := try {
429440
http:send-request(
430441
<http:request method='get' href="{('https://api.ror.org/v2/organizations?affiliation='||web:encode-url($inst))}" timeout='2'>
442+
<http:header name="Client-Id" value="{$e:ror-client-id}"/>
431443
</http:request>)//*:json}
432444
catch * {<json><number__of__results>0</number__of__results></json>}
433445
return if ((number($json//*:number__of__results) = 0) or not($json//*:items/_[number(*:score[1]) ge 0.8]))
@@ -787,6 +799,7 @@ declare function e:get-ror-rows($xml) as element(tr)* {
787799
let $json := try {
788800
http:send-request(
789801
<http:request method='get' href="{('https://api.ror.org/v2/organizations?affiliation='||web:encode-url($display))}" timeout='2'>
802+
<http:header name="Client-Id" value="{$e:ror-client-id}"/>
790803
</http:request>)//*:json}
791804
catch * {<json><number__of__results>0</number__of__results></json>}
792805
where (number($json//*:number__of__results) gt 0) and $json//*:items/_[number(*:score[1]) ge 0.8]

0 commit comments

Comments
 (0)