Skip to content

url_builder

Class to compose URIs for calling the Heurist API.

Classes:

  • URLBuilder

    Class to construct endpoints for the Heurist API (on Huma-Num's server).

URLBuilder

URLBuilder(
    database_name: str, server: str = HUMA_NUM_SERVER
)

Class to construct endpoints for the Heurist API (on Huma-Num's server).

Methods:

get_db_structure

get_db_structure() -> str

URL to retrieve the database structure.

Examples:

>>> db = "mock_db"
>>> builder = URLBuilder(db)
>>> builder.get_db_structure()
'https://heurist.huma-num.fr/heurist/hserv/structure/export/getDBStructureAsXML.php?db=mock_db'

Returns:

  • str ( str ) –

    URL to retrieve the database structure.

get_records

get_records(
    record_type_id: int,
    form: Literal["xml", "json"] = "xml",
    users: tuple = (),
) -> str

Build a URL to retrieve records of a certain type.

Examples:

>>> db = "mock_db"
>>> builder = URLBuilder(db)
>>> builder.get_records(101)
'https://heurist.huma-num.fr/heurist/export/xml/flathml.php?q=[{"t"%3A"101"}%2C{"sortby"%3A"t"}]&a=1&db=mock_db&depth=all&linkmode=direct_links'
>>> db = "mock_db"
>>> builder = URLBuilder(db)
>>> builder.get_records(102, form="json")
'https://heurist.huma-num.fr/heurist/hserv/controller/record_output.php?q=[{"t"%3A"102"}%2C{"sortby"%3A"t"}]&a=1&db=mock_db&depth=all&linkmode=direct_links&format=json&defs=0&extended=2'
>>> db = "mock_db"
>>> builder = URLBuilder(db)
>>> builder.get_records(102, users=(2,16,))
'https://heurist.huma-num.fr/heurist/export/xml/flathml.php?q=[{"t"%3A"102"}%2C{"sortby"%3A"t"}%2C{"addedby"%3A"2%2C16"}]&a=1&db=mock_db&depth=all&linkmode=direct_links'

Parameters:

  • record_type_id

    (int) –

    Heurist ID of the record type.

  • form

    (Literal['xml', 'json'], default: 'xml' ) –

    The format of the exported data.

Returns:

  • str ( str ) –

    URL to retrieve records of a certain type.