Packages

The official Elixir SDK for the Spidra API.

Current section

Files

Jump to
spidra lib spidra config.ex
Raw

lib/spidra/config.ex

defmodule Spidra.Config do
@moduledoc """
Configuration struct for the Spidra client.
"""
defstruct [:api_key, base_url: "https://api.spidra.io/api"]
@type t :: %__MODULE__{
api_key: String.t(),
base_url: String.t()
}
@doc """
Creates a new Spidra configuration.
## Options
* `:api_key` - (Required) Your Spidra API key.
* `:base_url` - (Optional) Custom base URL, defaults to `https://api.spidra.io/api`.
## Examples
iex> Spidra.Config.new(api_key: "spd_...")
%Spidra.Config{...}
"""
@spec new(Keyword.t()) :: t()
def new(opts \\ []) do
api_key = Keyword.get(opts, :api_key) || System.get_env("SPIDRA_API_KEY")
unless api_key do
raise ArgumentError,
"Missing required option :api_key or SPIDRA_API_KEY environment variable"
end
struct!(__MODULE__, Keyword.put(opts, :api_key, api_key))
end
end