pocketenv

Core types and HTTP helpers for the Pocketenv API client.

Start by creating a Client with new_client/2, then pass it to any of the sub-module functions (sandbox, env, secrets, files, etc.).

Types

Holds the base URL and bearer token used for every API request.

pub type Client {
  Client(base_url: String, token: String)
}

Constructors

  • Client(base_url: String, token: String)

Errors that can be returned by any API call.

pub type PocketenvError {
  HttpError(String)
  JsonDecodeError(json.DecodeError)
  ApiError(Int)
  RequestBuildError
}

Constructors

  • HttpError(String)

    An HTTP-level error (connection failure, timeout, etc.).

  • JsonDecodeError(json.DecodeError)

    The response body could not be decoded as expected JSON.

  • ApiError(Int)

    The server returned a non-2xx status code.

  • RequestBuildError

    The request URL could not be constructed (malformed base URL).

Information about the authenticated actor (user/bot).

pub type Profile {
  Profile(
    id: option.Option(String),
    did: String,
    handle: String,
    display_name: option.Option(String),
    avatar: option.Option(String),
    created_at: option.Option(String),
    updated_at: option.Option(String),
  )
}

Constructors

Values

pub const default_base_url: String

The default base URL for the Pocketenv API.

pub fn do_get(
  client: Client,
  path: String,
  query: List(#(String, String)),
) -> Result(String, PocketenvError)

Sends an authenticated GET request to path with optional query params. Returns the raw response body on success.

pub fn do_post(
  client: Client,
  path: String,
  query: List(#(String, String)),
  body: String,
) -> Result(String, PocketenvError)

Sends an authenticated POST request to path with an optional query and a JSON body. Returns the raw response body on success.

pub fn get_profile(
  client: Client,
) -> Result(Profile, PocketenvError)

Fetches the profile of the authenticated actor.

Example

let assert Ok(profile) = pocketenv.get_profile(client)
io.println(profile.handle)
pub fn new_client(token: String) -> Client

Creates a new API client using the default base URL (https://api.pocketenv.io).

Example

let client = pocketenv.new_client("your-token")
pub fn new_client_with_base_url(
  base_url: String,
  token: String,
) -> Client

Creates a new API client with a custom base URL.

Example

let client = pocketenv.new_client_with_base_url("https://self-hosted.example.com", "your-token")
pub fn profile_decoder() -> decode.Decoder(Profile)

JSON decoder for Profile. Useful when embedding profile data in custom decoders.

Search Document