10.7.7. Utilities for REST API Adapters

pytan3.adapters.magic_endpoint(obj, target=None, auto_target=True, needs_target=False)[source]

Build a REST API endpoint from an API object.

Parameters:
  • obj (pytan3.api_models.ApiModel) – API object to get route and target from in order to build endpoint.
  • target (str, optional) –

    Manually provided target.

    Defaults to: None.

  • auto_target (bool, optional) –

    Try to identify the target from obj by getting “id” or “name” attributes if their values are not None.

    Defaults to: True.

  • needs_target (bool, optional) –

    Throw an exception if a target is not automatically determined from obj.

    Defaults to: False.

Raises:

exceptions.ModuleError – If needs_target is True and resolved target is None.

Returns:

str

pytan3.adapters.build_endpoint(route, target=None)[source]

Build a REST endpoint string by joining route and target.

Parameters:
  • route (str) – Route part of endpoint.
  • target (str, optional) –

    Target part of endpoint.

    Defaults to None.

Returns:

str

pytan3.adapters.serialize_json(obj, **kwargs)[source]

Encode python object into a JSON string.

Parameters:
  • obj (object) – Python object to encode into a string.
  • **kwargs
    indent (int):
    Indent spacing for prettifying.

    Defaults to: 2.

    rest of kwargs:
    Passed to json.dumps().
Returns:

str