Name: hex_erl
Owner: Hex
Description: Reference implementation of Hex specifications
Created: 2018-03-02 13:04:14.0
Updated: 2018-05-21 21:32:18.0
Pushed: 2018-05-21 21:32:16.0
Size: 134
Language: Erlang
GitHub Committers
User | Most Recent Commit | # Commits |
---|
Other Committers
User | Most Recent Commit | # Commits |
---|
Reference implementation of Hex specifications: https://github.com/hexpm/specifications.
Get all package names:
repo:get_names().
{ok,
#{package => [
#{name => <<"package1">>},
#{name => <<"package2">>},
...
]},
[{etag, ...}, ...]}
Note: By default, we fetch data from repo.hex.pm using built-in httpc-based adapter. See section below about configuring HTTP client.
Get all package versions from repository:
repo:get_versions().
{ok,
#{packages => [
#{name => <<"package1">>, retired => [], versions => [<<"1.0.0">>]},
#{name => <<"package2">>, retired => [], versions => [<<"0.5.0">>]},
]},
[{etag, ...}, ...]}
Get package releases from repository:
repo:get_package(<<"package1">>).
{ok,
#{releases => [
#{checksum => ..., version => <<"0.5.0">>, dependencies => []}],
#{checksum => ..., version => <<"1.0.0">>, dependencies => []}],
]},
[{etag, ...}, ...]}
Get package from HTTP API:
api:get_package(<<"package1">>).
{ok,
#{
<<"name">> => <<"package1">>,
<<"meta">> => #{
<<"description">> => ...,
<<"licenses">> => ...,
<<"links">> => ...,
<<"maintainers">> => ...,
},
...,
<<"releases">> => [
#{<<"url">> => ..., <<"version">> => <<"0.5.0">>}],
#{<<"url">> => ..., <<"version">> => <<"1.0.0">>}],
...
]
},
[{etag, ...}, ...]}
Get package tarball:
Tarball, _Opts} = hex_repo:get_tarball(<<"package1">>, <<"1.0.0">>).
Unpack package tarball:
#{checksum := Checksum, contents := Contents, metadata := Metadata}} = hex_tarball:unpack(Tarball, memory).
Create package tarball:
{Tarball, Checksum}} = hex_tarball:create(Metadata, Contents).
By default, hex_repo
and hex_api
functions are using built-in httpc-based adapter and are calling
https://repo.hex.pm and https://hex.pm/api respectively.
See hex_repo:default_options()
and hex_api:default_options()
for available configuration options.
HTTP client configuration can be overriden as follows:
ons = [{client, #{adapter => my_hackney_adapter, user_agent_fragment => <<"(hackney/1.12.1) (my_app/0.1.0)">>}}].
repo:get_names(Options).
y_hackney_adapter.erl
ule(my_hackney_adapter).
aviour(hex_http).
Add to rebar.config
:
s, [
ex_erl, {git, "git://github.com/hexpm/hex_erl.git"}}
Add to mix.exs
:
deps do
{:hex_erl, github: "hexpm/hex_erl"}