View Source ExPersona.Client.Parser (ex_persona v1.0.0)
This module contains functions used in parsing the results of API calls.
In this context, "parsing" occurs after JSON responses have been decoded into a Map
.
Link to this section Summary
Types
A result from a parsed API call that is streamable (i.e., a pagninated list).
Either a single or list result.
A single result from a parsed API call.
Functions
Provide a default parser in case an ExPersona.Client.Operation
doesn't specify one.
Turn a parser designed for a single record into one that can handle lists.
Link to this section Types
A result from a parsed API call that is streamable (i.e., a pagninated list).
@type parsed_result() :: parsed_single_result() | parsed_list_result()
Either a single or list result.
A single result from a parsed API call.
@type parser_func() :: (ExPersona.Client.Result.t() -> parsed_result())
Link to this section Functions
@spec default_parse(ExPersona.Client.Result.t()) :: parsed_result()
Provide a default parser in case an ExPersona.Client.Operation
doesn't specify one.
This just returns the body of the response. This is useful for downloading files, for instance, where there's no transformation that should be done on the result.
@spec list_parser(parser_func()) :: (ExPersona.Client.Result.t() -> parsed_list_result())
Turn a parser designed for a single record into one that can handle lists.
This is used in cases where the expected result of an ExPersona.Client.Operation
is one
that can handle pagination, and we'd like to just specify a single parser. For instance,
the ExPersona.Inquiry.list/0
function just creates this struct:
%Operation{path: "inquiries", parser: Parser.list_parser(&Inquiry.parse/1)}
where Inquiry.parse/1
describes how to handle creating one ExPersona.Inquiry
from a
ExPersona.Client.Result
.