Você não pode selecionar mais de 25 tópicos Os tópicos devem começar com uma letra ou um número, podem incluir traços ('-') e podem ter até 35 caracteres.

51 linhas
1.6 KiB

  1. %% Vendored from hex_core v0.6.8, do not edit manually
  2. -module(r3_hex_api_package).
  3. -export([get/2, search/3]).
  4. %% @doc
  5. %% Gets a 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. -spec get(r3_hex_core:config(), binary()) -> r3_hex_api:response().
  28. get(Config, Name) when is_map(Config) and is_binary(Name)->
  29. Path = r3_hex_api:build_repository_path(Config, ["packages", Name]),
  30. r3_hex_api:get(Config, Path).
  31. %% @doc
  32. %% Searches packages.
  33. %%
  34. %% Examples:
  35. %%
  36. %% ```
  37. %% > r3_hex_api_package:search(r3_hex_core:default_config(), <<"package">>, []).
  38. %% {ok, {200, ..., [
  39. %% #{<<"name">> => <<"package1">>, ...},
  40. %% ...
  41. %% ]}}
  42. %% '''
  43. -spec search(r3_hex_core:config(), binary(), list(binary())) -> r3_hex_api:response().
  44. search(Config, Query, SearchParams) when is_map(Config) and is_binary(Query) and is_list(SearchParams) ->
  45. QueryString = r3_hex_api:encode_query_string([{search, Query} | SearchParams]),
  46. Path = r3_hex_api:join_path_segments(r3_hex_api:build_repository_path(Config, ["packages"])),
  47. PathQuery = <<Path/binary, "?", QueryString/binary>>,
  48. r3_hex_api:get(Config, PathQuery).