# `Wiki.SiteMatrix`
[🔗](https://gitlab.com/wmde/technical-wishes/mediawiki_client_ex/blob/main/lib/site_matrix.ex#L1)

Retrieves sites from a wiki farm with the SiteMatrix extension installed.

Most applications will connect to a single wiki, or iterate over sites from a
single site matrix, so a singleton default can be set up as a child of
your Application.
```
children = [
  Wiki.SiteMatrix.Default
]
```

To override defaults, supply additional options:
```
children = [
  {Wiki.SiteMatrix.Default, api: "https://meta.wikimedia.beta.wmflabs.org/w/api.php"}
]
```

The `get` and `get_all` methods include a variation where the initial
SiteMatrix parameter is omitted, and the application default will be used
instead.
```
Wiki.SiteMatrix.get(:dewiki)
```

# `client_options`
[🔗](https://gitlab.com/wmde/technical-wishes/mediawiki_client_ex/blob/main/lib/site_matrix.ex#L45)

```elixir
@type client_options() :: [
  Wiki.Action.client_option()
  | {:api, binary()}
  | {:key_fun, (Wiki.SiteMatrix.Spec.t() -&gt; any())}
]
```

# `site_handle`
[🔗](https://gitlab.com/wmde/technical-wishes/mediawiki_client_ex/blob/main/lib/site_matrix.ex#L43)

```elixir
@type site_handle() :: Wiki.SiteMatrix.Spec.t() | site_name()
```

Site spec or dbname

# `site_name`
[🔗](https://gitlab.com/wmde/technical-wishes/mediawiki_client_ex/blob/main/lib/site_matrix.ex#L38)

```elixir
@type site_name() :: atom() | String.t()
```

dbname as an atom or a string

# `sitematrix_state`
[🔗](https://gitlab.com/wmde/technical-wishes/mediawiki_client_ex/blob/main/lib/site_matrix.ex#L82)

```elixir
@opaque sitematrix_state()
```

# `action_api`
[🔗](https://gitlab.com/wmde/technical-wishes/mediawiki_client_ex/blob/main/lib/site_matrix.ex#L282)

```elixir
@spec action_api(site_handle()) :: String.t()
```

Get the Action API for a known site

```
Wiki.SiteMatrix.action_api(:enwiki)

# "https://en.wikipedia.org/w/api.php"
```

As a convenience, the site can be referenced as a bare string, in which case
it will be looked up in the default Wikimedia farm.  Note that this will be
uncached and so inappropriate for most production use.

```
Wiki.SiteMatrix.action_api(:dewiki)
```

## Arguments

* `site` - Populated site structure.

## Return value

Calculated Action API.

# `default_sitematrix`
[🔗](https://gitlab.com/wmde/technical-wishes/mediawiki_client_ex/blob/main/lib/site_matrix.ex#L297)

```elixir
@spec default_sitematrix() :: sitematrix_state()
```

Utility method to get the shared SiteMatrix.

# `get`
[🔗](https://gitlab.com/wmde/technical-wishes/mediawiki_client_ex/blob/main/lib/site_matrix.ex#L244)

```elixir
@spec get(site_name()) :: {:ok, Wiki.SiteMatrix.Spec.t()} | {:error, any()}
```

Look up in the default site matrix

@see get/2

# `get`
[🔗](https://gitlab.com/wmde/technical-wishes/mediawiki_client_ex/blob/main/lib/site_matrix.ex#L210)

```elixir
@spec get(sitematrix_state(), site_name()) ::
  {:ok, Wiki.SiteMatrix.Spec.t()} | {:error, any()}
```

Look up a single site by key

## Arguments

* `sitematrix` - Result of Sitematrix.new()
* `key` - The dbname (eg. :enwiki) or value of another key if the sitematrix
has installed a custom `key_fun`.

## Return value

Site spec or error

# `get!`
[🔗](https://gitlab.com/wmde/technical-wishes/mediawiki_client_ex/blob/main/lib/site_matrix.ex#L253)

```elixir
@spec get!(site_name()) :: Wiki.SiteMatrix.Spec.t()
```

Look up in the default site matrix

@see get!/2

# `get!`
[🔗](https://gitlab.com/wmde/technical-wishes/mediawiki_client_ex/blob/main/lib/site_matrix.ex#L231)

```elixir
@spec get!(sitematrix_state(), site_name()) :: Wiki.SiteMatrix.Spec.t()
```

Assertive variant of `get`.

# `get_all`
[🔗](https://gitlab.com/wmde/technical-wishes/mediawiki_client_ex/blob/main/lib/site_matrix.ex#L133)

```elixir
@spec get_all() :: {:ok, [Wiki.SiteMatrix.Spec.t()]} | {:error, any()}
```

Get all sites from the default site matrix

@see get_all/1

# `get_all`
[🔗](https://gitlab.com/wmde/technical-wishes/mediawiki_client_ex/blob/main/lib/site_matrix.ex#L123)

```elixir
@spec get_all(sitematrix_state()) ::
  {:ok, [Wiki.SiteMatrix.Spec.t()]} | {:error, any()}
```

Get all sites for a wiki farm.

## Arguments

* `sitematrix` - Result of Sitematrix.new()

## Return value

List of site specifications.

# `new`
[🔗](https://gitlab.com/wmde/technical-wishes/mediawiki_client_ex/blob/main/lib/site_matrix.ex#L98)

```elixir
@spec new(client_options()) :: sitematrix_state()
```

## Options

- `api` - Action API URL for a site participating in the farm.
  Defaults to https://meta.wikimedia.org/w/api.php.

- `key_fun` - Function on a site spec, returning the key to build a lookup with,
  later passed as the `key` argument to `get`.
  Defaults to returning the site's `dbname` (eg. "enwiki").

---

*Consult [api-reference.md](api-reference.md) for complete listing*
