« Module:ZoteroAPI » : différence entre les versions
Aucun résumé des modifications |
Aucun résumé des modifications |
||
| Ligne 17 : | Ligne 17 : | ||
end | end | ||
-- Construire l'URL avec l'itemKey | -- Construire l'URL avec l'itemKey directement dans le chemin | ||
local url = 'https://api.zotero.org/groups/4893620/items | local url = 'https://api.zotero.org/groups/4893620/items/' .. itemKey | ||
-- Récupérer les données avec getExternalData en utilisant JSONPath | -- Récupérer les données avec getExternalData en utilisant JSONPath | ||
| Ligne 27 : | Ligne 27 : | ||
use_jsonpath = true, | use_jsonpath = true, | ||
data = { | data = { | ||
key = '$ | key = '$.key', | ||
caseName = '$ | caseName = '$.data.caseName', | ||
dateDecided = '$ | dateDecided = '$.data.dateDecided', | ||
court = '$ | court = '$.data.court', | ||
url = '$ | url = '$.data.url', | ||
history = '$ | history = '$.data.history', | ||
docketNumber = '$ | docketNumber = '$.data.docketNumber', | ||
firstName = '$.data.creators[0].firstName', | |||
firstName = '$ | lastName = '$.data.creators[0].lastName' | ||
lastName = '$ | |||
} | } | ||
}) | }) | ||
| Ligne 68 : | Ligne 67 : | ||
end | end | ||
local url = 'https://api.zotero.org/groups/4893620/items | local url = 'https://api.zotero.org/groups/4893620/items/' .. itemKey | ||
-- Essayons une | -- Essayons une approche simplifiée | ||
local success, | local output = {"Test de récupération des données:"} | ||
-- Test 1: Récupérer juste le titre sans JSONPath | |||
local success, result1 = pcall(function() | |||
return mw.ext.externalData.getExternalData({ | |||
url = url, | |||
format = 'json' | |||
}) | |||
end) | |||
table.insert(output, "\n1. Test sans JSONPath:") | |||
if not success then | |||
table.insert(output, " Erreur: " .. tostring(result1)) | |||
elseif not result1 then | |||
table.insert(output, " Aucun résultat") | |||
else | |||
table.insert(output, " Type de résultat: " .. type(result1)) | |||
-- Afficher quelques détails si c'est une table | |||
if type(result1) == "table" then | |||
for k, v in pairs(result1) do | |||
if type(v) ~= "table" then | |||
table.insert(output, " " .. k .. ": " .. tostring(v)) | |||
else | |||
table.insert(output, " " .. k .. ": [table]") | |||
end | |||
end | |||
else | |||
table.insert(output, " Valeur: " .. tostring(result1)) | |||
end | |||
end | |||
-- Test 2: Récupérer juste le titre avec JSONPath simple | |||
local success, result2 = pcall(function() | |||
return mw.ext.externalData.getExternalData({ | return mw.ext.externalData.getExternalData({ | ||
url = url, | url = url, | ||
| Ligne 77 : | Ligne 108 : | ||
use_jsonpath = true, | use_jsonpath = true, | ||
data = { | data = { | ||
title = '$ | title = '$.data.caseName' | ||
} | } | ||
}) | }) | ||
end) | end) | ||
table.insert(output, "\n2. Test avec JSONPath simple:") | |||
if not success then | if not success then | ||
table.insert(output, " Erreur: " .. tostring(result2)) | |||
elseif not result2 then | |||
table.insert(output, " Aucun résultat") | |||
else | |||
table.insert(output, " Type de résultat: " .. type(result2)) | |||
-- Afficher quelques détails si c'est une table | |||
if type(result2) == "table" then | |||
for k, v in pairs(result2) do | |||
if type(v) ~= "table" then | |||
table.insert(output, " " .. k .. ": " .. tostring(v)) | |||
else | |||
table.insert(output, " " .. k .. ": [table]") | |||
if k == "title" and type(v) == "table" then | |||
for i, val in ipairs(v) do | |||
table.insert(output, " " .. i .. ": " .. tostring(val)) | |||
end | |||
end | |||
end | |||
end | end | ||
else | else | ||
table.insert(output, " " .. tostring( | table.insert(output, " Valeur: " .. tostring(result2)) | ||
end | end | ||
end | end | ||
-- Test 3: Essayer avec #get_web_data via preprocess | |||
local webDataCall = '{{#get_web_data:url=' .. url .. '|format=json|use jsonpath=true|data=title=$.data.caseName}}' | |||
local result3 = frame:preprocess(webDataCall) | |||
table.insert(output, "\n3. Test avec #get_web_data:") | |||
table.insert(output, " Résultat: " .. result3) | |||
return table.concat(output, "\n") | return table.concat(output, "\n") | ||
| Ligne 164 : | Ligne 207 : | ||
function p.debugUrl(frame) | function p.debugUrl(frame) | ||
local itemKey = frame and frame.args[1] or "" | local itemKey = frame and frame.args[1] or "" | ||
return 'https://api.zotero.org/groups/4893620/items | return 'https://api.zotero.org/groups/4893620/items/' .. itemKey | ||
end | end | ||
return p | return p | ||