Newer
Older
web-services / biblio-tools / v1 / unpaywall / expand.ini
@Nicolas Thouvenin Nicolas Thouvenin on 6 Oct 2022 3 KB fix: use one less statement
# OpenAPI Documentation - JSON format (dot notation)
mimeType = application/json

post.operationId = post-v1-unpaywall-expand
post.description = Récupération des informations OA associées à DOI dans la base Unpaywall
post.summary = Récupération à partir d'un tableau d'objets avec à minima un champ value contenant le DOI
post.tags.0 = biblio-tools
post.requestBody.content.application/json.example.0.id = 1
post.requestBody.content.application/json.example.0.value = 10.4000/edc.9014
post.requestBody.content.application/json.schema.$ref = #/components/schemas/JSONStream
post.requestBody.required = true
post.responses.default.content.application/json.example.0.id = 1
post.responses.default.content.application/json.example.0.value = { ... }
post.responses.default.content.application/json.schema.$ref =  #/components/schemas/JSONStream
post.responses.default.description = une réponse sous forme d'un objet ou n/a pour chaque DOI
post.parameters.0.description = Indenter le JSON résultant
post.parameters.0.in = query
post.parameters.0.name = indent
post.parameters.0.schema.type = boolean

# Rétablissons la coloration syntaxique (une ou deux apostrophes selon les besoins): '
value = fix('').join('')

# Necessary plugins
[use]
plugin = basics

# Flow configuration
[JSONParse]
separator = *

# Quelques paramètres modifiables si besoin
[env]
path = size
value = 10

path = indent
value = true

path = token
value = env('UNPAYWALL_API_KEY')

# Passage des doi en minuscule pour être compatible unpaywall
[assign]
path = value
value = get('value').toLower()

# Début du traitement par lot
[group]
size = env('size')

# Création d'une requete graphql avec une liste de DOI
[replace]
path = output.0.query
value = self().map('value').map(x => JSON.stringify(x)).join(',').thru(allIdentifiers => `{GetByDOI(dois:[${allIdentifiers}]){doi, is_oa, oa_status, has_repository_copy, best_oa_location { host_type }}}`)

path = input
value = self()

[map]
path = output

# Envoi de la requete
[map/URLStream]
url = http://vpunpaywallmir.intra.inist.fr:59700/api/graphql
header = env('token').prepend('x-api-key:')
path = data.GetByDOI.*
timeout = 30000
retries = 3
noerror = false

# Suppression des réponses qui n'ont pas abouties
[map/remove]
test = has('is_oa')
reverse = true

# Création d'un objet réponse
[map/replace]
path = __id
value = get('doi').toLower()

path = value.is_oa
value = get('is_oa')

path = value.oa_status
value = get('oa_status')

path = value.host_type
value = get('best_oa_location.host_type', 'n/a')

path = value.has_repository_copy
value = get('has_repository_copy', 'n/a')

# Reformatage des DOIS (input)
[map]
path = input

# Création d'un objet similaire à l'objet reponse
[map/replace]
path = __id
value = get('value')

path = value
value = self()

# Croissements des resultats et des dois (avec le champ __id comme clé)
[exchange]
value = get('output').unionBy(self.input, '__id')

# Fin du traitement par lot
[ungroup]

# Suppression des champs ajoutés
[exchange]
value = self().omit('__id')

# On marque les réponses qui n'ont pas abouti
[swing]
test = has('value.is_oa')
reverse = true

[swing/assign]
path = value
value = fix('n/a')

[dump]
indent = env('indent')