|
|
@ -16,8 +16,6 @@ |
|
|
|
]). |
|
|
|
-define(ERL_CONTENT_TYPE, <<"application/vnd.hex+erlang">>). |
|
|
|
|
|
|
|
-import(rebar_utils, [to_list/1]). |
|
|
|
|
|
|
|
get(Config, Path) -> |
|
|
|
request(Config, get, Path, undefined). |
|
|
|
|
|
|
@ -30,24 +28,26 @@ put(Config, Path, Body) -> |
|
|
|
delete(Config, Path) -> |
|
|
|
request(Config, delete, Path, undefined). |
|
|
|
|
|
|
|
%% OTP 21+ |
|
|
|
-ifdef (OTP_RELEASE). |
|
|
|
encode_query_string(List0) -> |
|
|
|
%% uri_string:compose_query/1 only accepts proplists where values are lists |
|
|
|
Pairs = lists:map(fun ({K, V}) -> {to_list(K), to_list(V)} |
|
|
|
end, List0), |
|
|
|
list_to_binary(uri_string:compose_query(Pairs)). |
|
|
|
-else. |
|
|
|
-if(?OTP_RELEASE >= 23). |
|
|
|
-compile({nowarn_deprecated_function, [{http_uri, encode, 1}]}). |
|
|
|
-endif. |
|
|
|
-endif. |
|
|
|
|
|
|
|
%% @private |
|
|
|
encode_query_string(List) -> |
|
|
|
QueryString = |
|
|
|
join("&", |
|
|
|
lists:map(fun ({K, V}) -> to_list(K) ++ "=" ++ to_list(V) |
|
|
|
lists:map(fun |
|
|
|
({K, V}) when is_atom(V) -> |
|
|
|
atom_to_list(K) ++ "=" ++ atom_to_list(V); |
|
|
|
({K, V}) when is_binary(V) -> |
|
|
|
atom_to_list(K) ++ "=" ++ binary_to_list(V); |
|
|
|
({K, V}) when is_integer(V) -> |
|
|
|
atom_to_list(K) ++ "=" ++ integer_to_list(V) |
|
|
|
end, List)), |
|
|
|
Encoded = http_uri:encode(QueryString), |
|
|
|
list_to_binary(Encoded). |
|
|
|
-endif. |
|
|
|
|
|
|
|
|
|
|
|
%% @private |
|
|
|
build_repository_path(#{api_repository := Repo}, Path) when is_binary(Repo) -> |
|
|
@ -61,20 +61,9 @@ build_organization_path(#{api_organization := Org}, Path) when is_binary(Org) -> |
|
|
|
build_organization_path(#{api_organization := undefined}, Path) -> |
|
|
|
Path. |
|
|
|
|
|
|
|
%% OTP 21+ |
|
|
|
-ifdef (OTP_RELEASE). |
|
|
|
%% @private |
|
|
|
join_path_segments(Segments) -> |
|
|
|
Concatenated = join(<<"/">>, Segments), |
|
|
|
%% uri_string:recompose/1 accepts path segments as a list, |
|
|
|
%% both strings and binaries |
|
|
|
list_to_binary(uri_string:recompose(#{path => Concatenated})). |
|
|
|
-else. |
|
|
|
%% @private |
|
|
|
join_path_segments(Segments) -> |
|
|
|
erlang:iolist_to_binary(join(<<"/">>, lists:map(fun encode/1, Segments))). |
|
|
|
-endif. |
|
|
|
|
|
|
|
|
|
|
|
%%==================================================================== |
|
|
|
%% Internal functions |
|
|
@ -103,13 +92,10 @@ request(Config, Method, Path, Body) when is_binary(Path) and is_map(Config) -> |
|
|
|
Other |
|
|
|
end. |
|
|
|
|
|
|
|
%% OTP < 21 |
|
|
|
-ifndef (OTP_RELEASE). |
|
|
|
encode(Binary) when is_binary(Binary) -> |
|
|
|
encode(binary_to_list(Binary)); |
|
|
|
encode(String) when is_list(String) -> |
|
|
|
http_uri:encode(String). |
|
|
|
-endif. |
|
|
|
|
|
|
|
build_url(Path, #{api_url := URI}) -> |
|
|
|
<<URI/binary, "/", Path/binary>>. |
|
|
|