Deputy (Deputy v0.2.1)

View Source

Deputy is an Elixir client for the Deputy API.

Configuration

You can configure the Deputy client with:

client = Deputy.new(
  base_url: "https://your-subdomain.deputy.com",
  api_key: "your-api-key"
)

Usage Example

# Create a client
client = Deputy.new(
  base_url: "https://your-subdomain.deputy.com",
  api_key: "your-api-key"
)

# Get locations
{:ok, locations} = Deputy.Locations.get_locations(client)

# Error handling
case Deputy.Locations.get_location(client, 12345) do
  {:ok, location} ->
    # Process location data
    IO.inspect(location)

  {:error, %Deputy.Error.API{status: 404}} ->
    # Handle not found error
    IO.puts("Location not found")

  {:error, %Deputy.Error.HTTP{reason: reason}} ->
    # Handle HTTP error
    IO.puts("HTTP error: " <> inspect(reason))

  {:error, %Deputy.Error.RateLimitError{retry_after: seconds}} ->
    # Handle rate limit
    IO.puts("Rate limited. Try again in " <> to_string(seconds) <> " seconds")
end

Summary

Functions

Creates a new Deputy client with the given configuration.

Makes a HTTP request to the Deputy API.

Makes a HTTP request to the Deputy API.

Types

t()

@type t() :: %Deputy{api_key: String.t(), base_url: String.t(), http_client: module()}

Functions

new(opts)

@spec new(Keyword.t()) :: t()

Creates a new Deputy client with the given configuration.

Options

  • :base_url - Required. The base URL for the Deputy API.
  • :api_key - Required. The API key for authentication.
  • :http_client - Optional. Module implementing the HTTPClient behavior. Defaults to Deputy.HTTPClient.Req.

Examples

iex> Deputy.new(base_url: "https://your-subdomain.deputy.com", api_key: "your-api-key")
%Deputy{base_url: "https://your-subdomain.deputy.com", api_key: "your-api-key", http_client: Deputy.HTTPClient.Req}

request(client, method, path, opts \\ [])

@spec request(t(), atom(), String.t(), keyword()) ::
  {:ok, map()} | {:error, Deputy.Error.t()}

Makes a HTTP request to the Deputy API.

This is used internally by the API module functions.

Returns

  • {:ok, response_body} - Successful API call with response body
  • {:error, error} - Error from an API call where error is one of:
    • %Deputy.Error.API{} - API error with details from Deputy
    • %Deputy.Error.HTTP{} - HTTP transport-level error
    • %Deputy.Error.RateLimitError{} - Rate limit exceeded
    • %Deputy.Error.ParseError{} - Failed to parse response
    • %Deputy.Error.ValidationError{} - Validation of request parameters failed

request!(client, method, path, opts \\ [])

@spec request!(t(), atom(), String.t(), keyword()) :: map()

Makes a HTTP request to the Deputy API.

Raises an exception if the API call returns an error.

Examples

# client = Deputy.new(base_url: "https://test.deputy.com", api_key: "test-key")
# locations = Deputy.request!(client, :get, "/api/v1/resource/Company")