Platform profiles.
A platform identifies itself with UCP-Agent: profile="<url>". That URL
serves the platform's profile document, whose order capability carries the
webhook_url order events go to. Bazaar.Plugs.UCPHeaders puts the URL in
conn.assigns.ucp_agent_profile.
HTTP client
No HTTP client is bundled. Pass a function that GETs a URL and returns
{:ok, %{status: integer, body: binary | map}} or {:error, reason}:
http_client = fn url ->
case Req.get(url) do
{:ok, %{status: status, body: body}} -> {:ok, %{status: status, body: body}}
{:error, reason} -> {:error, reason}
end
end
{:ok, webhook_url} = Bazaar.Platform.webhook_url(profile_url, http_client: http_client)Caching
discover_cached/3 takes a cache map with get (returns {:ok, value} or
:miss) and put functions, so a profile is fetched once per platform.
Summary
Functions
Fetches and parses a platform profile.
Like discover/2, reading and filling a cache keyed by the profile URL.
The URL a platform wants order events delivered to, read from the order capability of its profile.
Functions
Fetches and parses a platform profile.
Returns {:ok, profile}, {:error, {:http_error, status}},
{:error, {:json_error, reason}} or the HTTP client's error.
Like discover/2, reading and filling a cache keyed by the profile URL.
The URL a platform wants order events delivered to, read from the order capability of its profile.
Returns {:ok, url}, {:error, :webhook_url_not_advertised} or a
discover/2 error.