Aura.Packages (Aura v1.0.1)
View SourceService module for interacting with Hex Packages
Resources
- Hex
- Contact the maintainer (he's happy to help!)
Summary
Types
The number of results per internal page. Aura sets this to 1000.
Options to modify a Packages request
Options to modify a Package stream request
Search term that filters package results
Sorting criteria for response
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
Streams audit logs, scoped to a package
Grabs a stream of packages, given optional criteria
Types
@type per_page() :: non_neg_integer()
The number of results per internal page. Aura sets this to 1000.
@type pkg_opts() :: [{:repo_url, Aura.Common.repo_url()}]
Options to modify a Packages request
Keys
- repo_url ::
Aura.Common.repo_url/0
@type pkg_stream_opts() :: [ repo: Aura.Common.repo_name(), page: Aura.Common.start_page(), per_page: per_page(), sort: sort_order(), search: search_term() ]
Options to modify a Package stream request
Keys
- sort ::
Aura.Packages.sort_order/0
- search ::
Aura.Packages.search_term/0
- repo_url ::
Aura.Common.repo_url/0
- repo ::
Aura.Common.repo_name/0
- page ::
Aura.Common.start_page/0
- per_page ::
Aura.Packages.per_page/0
@type search_term() :: String.t()
Search term that filters package results
By default search will do a wildcard match on the package name and full text search on the package
description. If the search string is nerves
, package names matching *nerves*
will be found and
packages having nerves
or a stemmed version of the string in the description.
Search can also be performed on specific fields, for example: name:nerves* extra:package,name,postgresql
.
The search fields are:
name
- Package name, can include the wildcard operator*
at the end or start of the string.description
- Full text search package description.extra
- Comma-separated search onextra
map in metadata.extra:type,nerves
will match{"type": "nerves"}
.
@type sort_order() ::
:name | :recent_downloads | :total_downloads | :inserted_at | :updated_at
Sorting criteria for response
Functions
@spec add_package_owner( package_name :: Aura.Common.package_name(), owner_email :: Aura.Common.email(), opts :: pkg_opts() ) :: :ok | {:error, any()}
Adds a new owner to the list of package owners
Parameters
Parameter | Description |
---|---|
package_name | Aura.Common.package_name/0 |
owner_email | Aura.Common.email/0 |
opts[:repo_url] | Aura.Common.repo_url/0 |
API Details
Method | Path | Controller | Action |
---|---|---|---|
PUT | /packages/:package_name /owners/:owner_email | OwnerController | :create |
PUT | /repos/opts[:repo] /packages/:package_name /owners/:owner_email | OwnerController | :create |
@spec get_package(name :: Aura.Common.package_name(), opts :: pkg_opts()) :: {:ok, Aura.Model.HexPackage.t()} | {:error, any()}
Grabs a package given its name
Parameters
Parameter | Description |
---|---|
name | Aura.Common.package_name/0 |
opts[:repo_url] | Aura.Common.repo_url/0 |
API Details
Method | Path | Controller | Action |
---|---|---|---|
GET | /packages/:name | PackageController | :show |
GET | /repos/opts[:repo] /packages/:name | PackageController | :show |
Examples
iex> alias Aura.Packages
iex> {:ok, pkg} = Packages.get_package("decimal", repo_url: "http://localhost:4000/api")
iex> pkg.name
"decimal"
@spec get_package_owner( package_name :: Aura.Common.package_name(), username :: Aura.Common.username(), opts :: pkg_opts() ) :: {:ok, Aura.Model.HexPackageOwner.t()} | {:error, any()}
Grabs a single package owner by their username
Parameters
Parameter | Description |
---|---|
name | Aura.Common.package_name/0 |
username | Aura.Common.username/0 |
opts[:repo_url] | Aura.Common.repo_url/0 |
API Details
Method | Path | Controller | Action |
---|---|---|---|
GET | /packages/:package_name /owners/:username | OwnerController | :show |
GET | /repos/opts[:repo] /packages/:package_name /owners/:username | OwnerController | :show |
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"
@spec list_package_owners(name :: Aura.Common.package_name(), opts :: pkg_opts()) :: {:ok, [Aura.Model.HexPackageOwner.t()]} | {:error, any()}
Grabs all owners of a given package
Parameters
Parameter | Description |
---|---|
name | Aura.Common.package_name/0 |
opts[:repo_url] | Aura.Common.repo_url/0 |
API Details
Method | Path | Controller | Action |
---|---|---|---|
GET | /packages/:name /owners | OwnerController | :index |
GET | /repos/opts[:repo] /packages/:name /owners | OwnerController | :index |
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"
@spec remove_package_owner( package_name :: Aura.Common.package_name(), owner_email :: Aura.Common.email(), opts :: pkg_opts() ) :: :ok | {:error, any()}
Removes an existing owner from the list of package owners
Parameters
Parameter | Description |
---|---|
package_name | Aura.Common.package_name/0 |
owner_email | Aura.Common.email/0 |
opts[:repo_url] | Aura.Common.repo_url/0 |
API Details
Method | Path | Controller | Action |
---|---|---|---|
DELETE | /packages/:package_name /owners/:owner_email | OwnerController | :delete |
DELETE | /repos/opts[:repo] /packages/:package_name /owners/:owner_email | OwnerController | :delete |
@spec stream_audit_logs( package_name :: Aura.Common.package_name(), opts :: Aura.Common.audit_opts() ) :: Enumerable.t()
Streams audit logs, scoped to a package
Note that the page size is fixed by the API to be 100 per page.
Parameters
Parameter | Description |
---|---|
package_name | Aura.Common.package_name/0 |
opts[:repo_url] | Aura.Common.repo_url/0 |
opts[:page] | Aura.Common.start_page/0 |
API Details
Method | Path | Controller | Action |
---|---|---|---|
GET | /packages/:package_name /audit-logs | PackageController | :audit_logs |
GET | /repos/opts[:repo] /packages/:package_name /audit-logs | PackageController | :audit_logs |
Examples
iex> alias Aura.Packages
iex> opts = [repo_url: "http://localhost:4000/api"]
iex> audit_logs = Packages.stream_audit_logs("decimal", opts) |> Enum.take(20)
iex> _actions = Enum.map(audit_logs, fn audit_log -> audit_log.action end)
@spec stream_packages(opts :: pkg_stream_opts()) :: Enumerable.t()
Grabs a stream of packages, given optional criteria
Parameters
Parameter | Description |
---|---|
opts[:repo_url] | Aura.Common.repo_url/0 |
opts[:page] | Aura.Common.start_page/0 |
opts[:per_page] | Aura.Packages.per_page/0 |
opts[:sort] | Aura.Packages.sort_order/0 |
opts[:search] | Aura.Packages.search_term/0 |
API Details
Method | Path | Controller | Action |
---|---|---|---|
GET | /packages | PackageController | :index |
GET | /repos/opts[:repo] /packages | PackageController | :index |
Examples
# request packages,
# from the local test instance
# scoped to the repo "hexpm"
# sorted by total downloads
# starting with page 2
iex> alias Aura.Packages
iex> opts = [repo_url: "http://localhost:4000/api", repo: "hexpm",
...> sort: :total_downloads]
iex> packages = Packages.stream_packages(
...> opts ++ [page: 2])
iex> Enum.empty?(packages)
false
# Use search term
iex> alias Aura.Packages
iex> opts = [repo_url: "http://localhost:4000/api", repo: "hexpm",
...> sort: :total_downloads, per_page: 5]
iex> packages = Packages.stream_packages(
...> opts ++ [search: "nerves"]) |> Enum.take(50)
iex> Enum.empty?(packages)
false