Aura.Packages (Aura v0.9.1)

View Source

Service module for interacting with Hex Packages

📖 Resources

Summary

Functions

Adds a new owner to the list of package owners

Grabs a package given its name

Grabs a single package owner by their username

Grabs all owners of a given package

Removes an existing owner from the list of package owners

Grabs a stream of packages, given optional criteria

Functions

add_package_owner(package_name, owner_email, opts \\ [])

@spec add_package_owner(
  package_name :: Aura.Common.package_name(),
  owner_email :: Aura.Common.email(),
  opts :: list()
) :: :ok | {:error, any()}

Adds a new owner to the list of package owners

🏷️ Params

⤵️ Returns

✅ On Success

  :ok

❌ On Failure

  {:error, (some failure)}

get_package(name, opts \\ [])

@spec get_package(name :: Aura.Common.package_name(), opts :: list()) ::
  {:ok, Aura.Model.HexPackage.t()} | {:error, any()}

Grabs a package given its name

🏷️ Params

⤵️ Returns

✅ On Success

  {:ok, %HexPackage{}}

❌ On Failure

  {:error, (some failure)}

💻 Examples

iex> alias Aura.Packages
iex> {:ok, pkg} = Packages.get_package("decimal", repo_url: "http://localhost:4000/api")
iex> pkg.name
"decimal"

get_package_owner(package_name, username, opts \\ [])

@spec get_package_owner(
  package_name :: Aura.Common.package_name(),
  username :: Aura.Common.username(),
  opts :: list()
) :: {:ok, Aura.Model.HexPackageOwner.t()} | {:error, any()}

Grabs a single package owner by their username

🏷️ Params

⤵️ Returns

✅ On Success

  {:ok, %HexPackageOwner{}}

❌ On Failure

  {:error, (some failure)}

💻 Examples

iex> alias Aura.Packages
iex> {:ok, owner} = Packages.get_package_owner("decimal", "eric", repo_url: "http://localhost:4000/api")
iex> owner.email
"eric@example.com"

list_package_owners(name, opts \\ [])

@spec list_package_owners(name :: Aura.Common.package_name(), opts :: list()) ::
  {:ok, [Aura.Model.HexPackageOwner.t()]} | {:error, any()}

Grabs all owners of a given package

🏷️ Params

⤵️ Returns

✅ On Success

  {:ok, [%HexPackageOwner{}...]}

❌ On Failure

  {:error, (some failure)}

💻 Examples

iex> alias Aura.Packages
iex> {:ok, [owner | _]} =
...>   Packages.list_package_owners("decimal", repo_url: "http://localhost:4000/api")
iex> owner.email
"eric@example.com"

remove_package_owner(package_name, owner_email, opts \\ [])

@spec remove_package_owner(
  package_name :: Aura.Common.package_name(),
  owner_email :: Aura.Common.email(),
  opts :: list()
) :: :ok | {:error, any()}

Removes an existing owner from the list of package owners

🏷️ Params

⤵️ Returns

✅ On Success

  :ok

❌ On Failure

  {:error, (some failure)}

stream_audit_logs(package_name, opts \\ [])

@spec stream_audit_logs(package_name :: Aura.Common.package_name(), opts :: list()) ::
  Enumerable.t()

Streams Aura.Model.HexAuditLog, scoped to a package

🏷️ Params

⤵️ Returns

✅ On Success

  Stream.resource/3

💻 Examples

iex> alias Aura.Packages
iex> audit_logs = Packages.stream_audit_logs("decimal", repo_url: "http://localhost:4000/api")
iex> _actions = Enum.map(audit_logs, fn audit_log -> audit_log.action end)

stream_packages(opts \\ [])

@spec stream_packages(opts :: list()) :: Enumerable.t()

Grabs a stream of packages, given optional criteria

🏷️ Params

  • opts :: option parameters used to modify requests

⤵️ Returns

✅ On Success

  Stream.resource/3

💻 Examples

# request packages,
  # from the local test instance
  # scoped to the repo "hexpm"
  # starting with page 2
  # sorted by total downloads
iex> alias Aura.Packages
iex> packages = Packages.stream_packages(
...>  repo_url: "http://localhost:4000/api",
...>  repo: "hexpm",
...>  page: 2,
...>  sort: :total_downloads)
iex> Enum.empty?(packages)
false