PostHog.API.Client behaviour (posthog v2.0.0)
View SourceBehaviour and the default implementation of a PostHog API client. Uses Req
.
Users are unlikely to interact with this module directly, but here's an example just in case:
Example
> client = PostHog.API.Client.client("phc_abcdedfgh", "https://us.i.posthog.com")
%PostHog.API.Client{
client: %Req.Request{...},
module: PostHog.API.Client
}
> client.module.request(client.client, :post, "/flags", json: %{distinct_id: "user123"}, params: %{v: 2, config: true})
{:ok, %Req.Response{status: 200, body: %{...}}}
Summary
Callbacks
Creates a struct that encapsulates all information required for making requests to PostHog's public endpoints.
Sends an API request.
Types
@type client() :: any()
Arbitrary term that is passed as the first argument to the request/4
callback.
For the default client, this is a Req.Request.t/0
struct.
@type response() :: {:ok, %{status: non_neg_integer(), body: any()}} | {:error, Exception.t()}
Callbacks
Creates a struct that encapsulates all information required for making requests to PostHog's public endpoints.
@callback request( client :: client(), method :: atom(), url :: String.t(), opts :: keyword() ) :: response()
Sends an API request.
Things such as the API token are expected to be baked into the client
argument.