1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
|
%% Vendored from hex_core v0.5.0, do not edit manually
-module(r3_hex_api_release).
-export([
delete/3,
get/3,
publish/2,
retire/4,
unretire/3
]).
%% @doc
%% Gets package release.
%%
%% Examples:
%%
%% ```
%% > r3_hex_api:get_release(<<"package">>, <<"1.0.0">>, r3_hex_core:default_config()).
%% {ok, {200, ..., #{
%% <<"version">> => <<"1.0.0">>,
%% <<"meta">> => #{
%% <<"description">> => ...,
%% <<"licenses">> => ...,
%% <<"links">> => ...,
%% <<"maintainers">> => ...
%% },
%% ...}}}
%% '''
%% @end
get(Config, Name, Version) when is_binary(Name) and is_binary(Version) and is_map(Config) ->
Path = r3_hex_api:build_repository_path(Config, ["packages", Name, "releases", Version]),
r3_hex_api:get(Config, Path).
publish(Config, Tarball) when is_binary(Tarball) and is_map(Config) ->
Path = r3_hex_api:build_repository_path(Config, ["publish"]),
TarballContentType = "application/octet-stream",
Config2 = put_header(<<"content-length">>, integer_to_binary(byte_size(Tarball)), Config),
Body = {TarballContentType, Tarball},
r3_hex_api:post(Config2, Path, Body).
delete(Config, Name, Version) when is_binary(Name) and is_binary(Version) and is_map(Config) ->
Path = r3_hex_api:build_repository_path(Config, ["packages", Name, "releases", Version]),
r3_hex_api:delete(Config, Path).
retire(Config, Name, Version, Params) when is_binary(Name) and is_binary(Version) and is_map(Config) ->
Path = r3_hex_api:build_repository_path(Config, ["packages", Name, "releases", Version, "retire"]),
r3_hex_api:post(Config, Path, Params).
unretire(Config, Name, Version) when is_binary(Name) and is_binary(Version) and is_map(Config) ->
Path = r3_hex_api:build_repository_path(Config, ["packages", Name, "releases", Version, "retire"]),
r3_hex_api:delete(Config, Path).
%%====================================================================
%% Internal functions
%%====================================================================
put_header(Name, Value, Config) ->
Headers = maps:get(http_headers, Config, #{}),
Headers2 = maps:put(Name, Value, Headers),
maps:put(http_headers, Headers2, Config).
|