A read-only client for MLS feeds over the RESO Web API.
Start with new/1 to configure the feed's OData service root.
Summary
Types
A page of records or the terminal error from a collection read.
OData query options for property/2 and media/2.
A client configured for an OData service root.
Functions
Makes an authenticated GET and returns the successful Req.Response.
Streams pages from the feed's Media collection.
Fetches the feed's $metadata document using the client's authentication.
Builds a client without making an HTTP request.
Streams pages from the feed's Property collection.
Types
@type auth() :: {:bearer, String.t()} | {:client_credentials, token_url: String.t(), client_id: String.t(), client_secret: String.t(), scope: String.t(), client_auth: :basic | :post}
Authentication options accepted by new/1.
@type page_result() :: {:ok, [map()]} | {:error, ExMLS.Error.t()}
A page of records or the terminal error from a collection read.
@type query_options() :: [ select: String.t(), filter: String.t(), orderby: String.t(), top: non_neg_integer(), expand: String.t() ]
OData query options for property/2 and media/2.
@opaque t()
A client configured for an OData service root.
Functions
@spec get(t(), String.t()) :: {:ok, Req.Response.t()} | {:error, ExMLS.Error.t()}
Makes an authenticated GET and returns the successful Req.Response.
Relative URLs resolve against the service root as a directory. Absolute URLs must match its scheme, host, and port. Query strings are sent as supplied. Redirects are returned as HTTP errors.
Returns {:error, %ExMLS.Error{}} if authentication or the request fails.
A feed response with HTTP 401 invalidates the OAuth token used for that
request. The next call can acquire a new token.
@spec media(t(), query_options()) :: Enumerable.t()
Streams pages from the feed's Media collection.
See property/2 for query options, pagination, and error handling.
@spec metadata(t()) :: {:ok, binary()} | {:error, ExMLS.Error.t()}
Fetches the feed's $metadata document using the client's authentication.
Returns {:ok, xml} with the raw EDMX XML as a binary. Follow a resource's
EntitySet to its EntityType, then inspect the Name and Type
attributes on its Property elements to discover fields and their types.
Returns {:error, %ExMLS.Error{}} on request failure. An empty body or a
response without an XML content type returns :invalid_response with the
HTTP status. XML parsing and validation are left to the caller.
Builds a client without making an HTTP request.
Pass :service_root as an absolute HTTP or HTTPS URL. It may include a path,
such as /odata/, and must be free of user information, a query, and a
fragment. Raises ArgumentError if the service root is missing or invalid.
Omit :auth for an unauthenticated client, or set it to one of these values.
{:bearer, token}sends a caller-supplied bearer token to the feed.{:client_credentials, options}obtains bearer tokens on demand. Set:token_urlto the provider's absolute token endpoint URL and supply:client_idand:client_secret. Set:scopeif the provider requires it. The default:client_authmethod is:basic(HTTP Basic). Use:postfor providers that expect credentials in the form body.
OAuth tokens are shared across requests made with this client until their
reported expiry. A token response without expires_in is used for a single
request. Invalid authentication options raise ArgumentError.
Use HTTPS for live services. Both URLs accept HTTP for local development.
iex> client = ExMLS.new(service_root: "https://example.com/odata/")
iex> is_struct(client, ExMLS)
true
@spec property(t(), query_options()) :: Enumerable.t()
Streams pages from the feed's Property collection.
Pass :select, :filter, :orderby, and :expand as OData expression
strings, and :top as a non-negative integer. The feed determines which
expressions it supports. Invalid option names or types raise ArgumentError.
Requests run as the stream is enumerated. The stream emits page_result/0
values. Each successful page emits {:ok, records}, including {:ok, []}
for an empty page. Records are maps with string keys and retain
provider-specific fields and nested values.
The stream follows @odata.nextLink until it is absent. Relative links
resolve against the URL that returned them. Continuations must stay on the
service root's origin, and their query strings are sent as supplied.
A failed request or malformed page emits {:error, %ExMLS.Error{}} and
ends the stream. Earlier successful pages remain available to the caller.
Throttling surfaces as :http_error with status 429.