Aura.Common (Aura v1.0.1)

View Source

Common capabilities across all Aura services

Resources

Summary

Types

A human-readable name for this API key

The path parameter of the request

Options to modify an audit request

An email address associated with this record

Name of the Hex organization

Name of the package

The version of a release

The name of the repository

A Hex compliant API endpoint

When streaming, start at this page number. Default: 1

A unique, human-readable ID for a user

Functions

Determines a api_path/0 by investigating opts for a :repo or :org key, representing a Aura.Model.HexRepo or a Aura.Model.HexOrganization.

Implements Hex API's pagination mechanism by returning a Stream.resource/3

Types

api_key_name()

@type api_key_name() :: String.t()

A human-readable name for this API key

Examples

 "my_computer"

api_path()

@type api_path() :: String.t()

The path parameter of the request

audit_opts()

@type audit_opts() :: [repo_url: repo_url(), page: start_page()]

Options to modify an audit request

Keys

email()

@type email() :: String.t()

An email address associated with this record

Examples

"hello@example.com"

org_name()

@type org_name() :: String.t()

Name of the Hex organization

Examples

"my_org"

See Also

package_name()

@type package_name() :: String.t()

Name of the package

Examples

"plug"

release_version()

@type release_version() :: String.t()

The version of a release

Examples

"1.2.3"

repo_name()

@type repo_name() :: String.t()

The name of the repository

Examples

"hexpm"

repo_url()

@type repo_url() :: URI.t()

A Hex compliant API endpoint

Examples

"https://hex.pm/api"
"http://localhost:4000/api"

start_page()

@type start_page() :: non_neg_integer()

When streaming, start at this page number. Default: 1

username()

@type username() :: String.t()

A unique, human-readable ID for a user

Examples

  "camatcode"

Functions

determine_path(opts, path)

@spec determine_path(opts :: [any()], path :: api_path()) :: {api_path(), [any()]}

Determines a api_path/0 by investigating opts for a :repo or :org key, representing a Aura.Model.HexRepo or a Aura.Model.HexOrganization.

If present, path will be modified to scope solely to that repo or org, otherwise the path is unmodified.

Parameters

ParameterDescription
pathapi_path/0
optsoption parameters used to modify requests

Examples

iex> alias Aura.Common
iex> alias Aura.Model.HexPackage
iex> opts = [repo_url: "http://localhost:4000/api", repo: "hexpm", page: 2, sort: :total_downloads]
iex> {_path, _opts} = Common.determine_path(opts, "/packages")
{"/repos/hexpm/packages", [repo_url: "http://localhost:4000/api", page: 2, sort: :total_downloads]}
iex> opts = [repo_url: "http://localhost:4000/api", org: "my_org", page: 2]
iex> {_path, _opts} = Common.determine_path(opts, "/keys")
{"/orgs/my_org/keys", [repo_url: "http://localhost:4000/api", page: 2]}

stream_paginate(path, build_func, opts)

@spec stream_paginate(
  path :: api_path(),
  build_func :: (map() -> map()),
  opts :: list()
) ::
  Enumerable.t()

Implements Hex API's pagination mechanism by returning a Stream.resource/3

Parameters

ParameterDescription
pathapi_path/0
optsoption parameters used to modify requests
build_funca function that takes in a map and returns a struct representing what's being paginated

Examples

iex> alias Aura.Common
iex> alias Aura.Model.HexPackage
iex> opts = [repo_url: "http://localhost:4000/api", repo: "hexpm", page: 2, sort: :total_downloads]
iex> {path, opts} = Common.determine_path(opts, "/packages")
iex> packages = Common.stream_paginate(path, &HexPackage.build/1, opts)
iex> Enum.empty?(packages)
false