DSpace.API.Transform (dspace_ex v0.1.0-alpha2)

Copy Markdown View Source

Functions for transforming API responses.

Summary

Functions

Extracts the body as a map from an API response structure.

Extracts a value from the response body by key.

Extracts and transforms a collection of resources from a response.

Extracts resources and metadata from a paginated collection response.

Functions

from_response(arg1)

@spec from_response(DSpace.API.HTTP.Response.t() | term()) :: map()

Extracts the body as a map from an API response structure.

get(response, key, default \\ nil)

Extracts a value from the response body by key.

transform(map, options)

@spec transform(
  DSpace.API.HTTP.Response.t() | map(),
  keyword()
) :: [term()]

Extracts and transforms a collection of resources from a response.

Parameters

  • map - A map or DSpace.API.HTTP.Response.t/0 containing the resource(s)
  • options - A keyword list with the following keys:
    • :extract - A path to navigate to the resource(s) (defaults to nil)
    • :transform - A function to process each resource (defaults to identity)

transform_collection(map, options)

@spec transform_collection(
  struct() | map(),
  keyword()
) :: {[term()], map(), term()}

Extracts resources and metadata from a paginated collection response.

Returns a three-element tuple {data, meta, next}:

  • data - List of transformed resources
  • meta - Meta information from the API response
  • next - URL for next page or nil if no more pages

Parameters

  • map - A map or DSpace.API.HTTP.Response.t/0 containing the resource collection
  • options - A keyword list with the following keys:
    • :extract - A path to navigate to the resources (required)
    • :next - A path to navigate to the continuation token (defaults to ["_links", "next", "href"])
    • :transform - A function to process each resource (defaults to identity)