« Module:ZoteroAPI » : différence entre les versions

De alcolois
Aller à la navigation Aller à la recherche
Page créée avec « local p = {} function p.getItemRawJson(frame) local itemKey = frame.args[1] if not itemKey or itemKey == '' then return '❌ Aucun itemKey fourni.' end local url = 'https://api.zotero.org/groups/4893620/items/' .. itemKey .. '?include=data&format=json' local data = mw.ext.externalData.getExternalData({ url = url, format = 'json' }) if not data or next(data) == nil then return '❌ Aucune donnée reç... »
 
Aucun résumé des modifications
Ligne 9 : Ligne 9 :
     local url = 'https://api.zotero.org/groups/4893620/items/' .. itemKey .. '?include=data&format=json'
     local url = 'https://api.zotero.org/groups/4893620/items/' .. itemKey .. '?include=data&format=json'


     local data = mw.ext.externalData.getExternalData({
     local jsonString = mw.ext.externalData.getExternalData({
         url = url,
         url = url,
         format = 'json'
         format = 'json'
     })
     })


     if not data or next(data) == nil then
     if not jsonString or jsonString == '' then
         return '❌ Aucune donnée reçue de Zotero.'
         return '❌ Aucune donnée reçue de Zotero.'
     end
     end


    -- Encode le tableau en JSON lisible si possible
     return '<pre>' .. jsonString .. '</pre>'
    local ok, json = pcall(mw.text.jsonEncode, data)
    if not ok then
        return '❌ Erreur d’encodage JSON.'
    end
 
     return '<pre>' .. json .. '</pre>'
end
end


return p
return p

Version du 11 juin 2025 à 15:55

La documentation pour ce module peut être créée à Module:ZoteroAPI/doc

local p = {}

function p.getItemRawJson(frame)
    local itemKey = frame.args[1]
    if not itemKey or itemKey == '' then
        return '❌ Aucun itemKey fourni.'
    end

    local url = 'https://api.zotero.org/groups/4893620/items/' .. itemKey .. '?include=data&format=json'

    local jsonString = mw.ext.externalData.getExternalData({
        url = url,
        format = 'json'
    })

    if not jsonString or jsonString == '' then
        return '❌ Aucune donnée reçue de Zotero.'
    end

    return '<pre>' .. jsonString .. '</pre>'
end

return p