CRAM.Reference.Refget (cram v0.1.0)

Copy Markdown View Source

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.

Summary

Types

t()

A Refget base URL.

Functions

Fetch name from Refget when the network is allowed.

Build a Refget client.

Types

t()

@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

Functions

fetch(provider, name, expected_md5)

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(base_url, opts \\ [])

@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