# `CRAM.Reference.Refget`
[🔗](https://github.com/baoulo/cram-elixir/blob/v0.1.0/lib/cram/reference/refget.ex#L1)

Optional GA4GH Refget sequence fetch.

`allow_network` must be true. The default is false, and `CRAM.open/2` does
not build this provider. The response body is returned only after its MD5
matches the requested checksum. The body is not placed in the error.

# `t`

```elixir
@type t() :: %CRAM.Reference.Refget{allow_network: boolean(), base_url: String.t()}
```

A Refget base URL.

  * `:base_url` — sequence endpoint prefix, without a trailing slash
  * `:allow_network` — false until the caller opts in. The default is false

    iex> {:ok, client} = CRAM.Reference.Refget.new("http://127.0.0.1:9/")
    iex> client.allow_network
    false

# `fetch`

Fetch `name` from Refget when the network is allowed.

`expected_md5` must be 32 hex digits. With `allow_network: false`, returns
`reason: :network_disabled` and does not connect. With the network allowed,
the body is returned only after its MD5 matches. A mismatch is
`reason: :reference_checksum_mismatch`. The body is not placed on the error.

    iex> {:ok, client} = CRAM.Reference.Refget.new("http://127.0.0.1:9")
    iex> {:error, error} = CRAM.Reference.Refget.fetch(client, "sq0", "be19336b7e15968f7ac7dc82493d9cd8")
    iex> error.reason
    :network_disabled

# `new`

```elixir
@spec new(String.t(), keyword()) :: {:ok, t()} | {:error, CRAM.Error.t()}
```

Build a Refget client.

`base_url` is a string. A trailing slash is removed. `opts` may include
`:allow_network`, which must be a boolean and defaults to false. Returns
`{:ok, client}`. A non-boolean flag is `reason: :invalid_range`. Does not
connect.

    iex> {:ok, client} = CRAM.Reference.Refget.new("http://127.0.0.1:9/", allow_network: false)
    iex> client.base_url
    "http://127.0.0.1:9"
    iex> {:error, error} = CRAM.Reference.Refget.new("http://127.0.0.1:9", allow_network: "yes")
    iex> error.reason
    :invalid_range

---

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