You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

49 lines
1.4 KiB

  1. %% Vendored from hex_core v0.5.0, do not edit manually
  2. -module(r3_hex_api_package).
  3. -export([get/2, search/3]).
  4. %% @doc
  5. %% Gets package.
  6. %%
  7. %% Examples:
  8. %%
  9. %% ```
  10. %% > r3_hex_api_package:get(r3_hex_core:default_config(), <<"package">>).
  11. %% {ok, {200, ..., #{
  12. %% <<"name">> => <<"package1">>,
  13. %% <<"meta">> => #{
  14. %% <<"description">> => ...,
  15. %% <<"licenses">> => ...,
  16. %% <<"links">> => ...,
  17. %% <<"maintainers">> => ...
  18. %% },
  19. %% ...,
  20. %% <<"releases">> => [
  21. %% #{<<"url">> => ..., <<"version">> => <<"0.5.0">>}],
  22. %% #{<<"url">> => ..., <<"version">> => <<"1.0.0">>}],
  23. %% ...
  24. %% ]}}}
  25. %% '''
  26. %% @end
  27. get(Config, Name) when is_binary(Name) and is_map(Config) ->
  28. Path = r3_hex_api:build_repository_path(Config, ["packages", Name]),
  29. r3_hex_api:get(Config, Path).
  30. %% @doc
  31. %% Searches packages.
  32. %%
  33. %% Examples:
  34. %%
  35. %% ```
  36. %% > r3_hex_api_package:search(r3_hex_core:default_config(), <<"package">>, []).
  37. %% {ok, {200, ..., [
  38. %% #{<<"name">> => <<"package1">>, ...},
  39. %% ...
  40. %% ]}}
  41. %% '''
  42. search(Config, Query, SearchParams) when is_binary(Query) and is_list(SearchParams) and is_map(Config) ->
  43. QueryString = r3_hex_api:encode_query_string([{search, Query} | SearchParams]),
  44. Path = r3_hex_api:join_path_segments(r3_hex_api:build_repository_path(Config, ["packages"])),
  45. PathQuery = <<Path/binary, "?", QueryString/binary>>,
  46. r3_hex_api:get(Config, PathQuery).