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.

98 regels
2.9 KiB

  1. %% Vendored from hex_core v0.6.8, do not edit manually
  2. -module(r3_hex_api_user).
  3. -export([
  4. create/4,
  5. get/2,
  6. me/1,
  7. reset_password/2
  8. ]).
  9. %% @doc
  10. %% Gets the authenticated user.
  11. %%
  12. %% Examples:
  13. %%
  14. %% ```
  15. %% > r3_hex_api_user:me(r3_hex_core:default_config()).
  16. %% {ok, {200, ..., #{
  17. %% <<"email">> => <<"user@example.com">>,
  18. %% <<"full_name">> => <<"John Doe">>,
  19. %% <<"handles">> => #{...},
  20. %% <<"inserted_at">> => <<"2014-04-21T17:20:12Z">>,
  21. %% <<"level">> => <<"full">>,
  22. %% <<"updated_at">> => <<"2019-08-04T19:28:05Z">>,
  23. %% <<"url">> => <<"https://hex.pm/api/users/user">>,
  24. %% <<"username">> => <<"user">>
  25. %% }}}
  26. %% '''
  27. %% @end
  28. -spec me(r3_hex_core:config()) -> r3_hex_api:response().
  29. me(Config) when is_map(Config) ->
  30. r3_hex_api:get(Config, ["users", "me"]).
  31. %% @doc
  32. %% Creates a new user account.
  33. %%
  34. %% Examples:
  35. %%
  36. %% ```
  37. %% > r3_hex_api_user:create(r3_hex_core:default_config(), <<"user">>, <<"hunter42">>, <<"user@example.com">>).
  38. %% {ok, {201, ..., #{
  39. %% <<"email">> => <<"user@example.com">>,
  40. %% <<"full_name">> => <<"John Doe">>,
  41. %% <<"handles">> => #{...},
  42. %% <<"inserted_at">> => <<"2014-04-21T17:20:12Z">>,
  43. %% <<"level">> => <<"full">>,
  44. %% <<"updated_at">> => <<"2019-08-04T19:28:05Z">>,
  45. %% <<"url">> => <<"https://hex.pm/api/users/user">>,
  46. %% <<"username">> => <<"user">>
  47. %% }}}
  48. %% '''
  49. %% @end
  50. -spec create(r3_hex_core:config(), binary(), binary(), binary()) -> r3_hex_api:response().
  51. create(Config, Username, Password, Email)
  52. when is_map(Config) and is_binary(Username) and is_binary(Password) and is_binary(Email) ->
  53. Params = #{
  54. <<"username">> => Username,
  55. <<"password">> => Password,
  56. <<"email">> => Email
  57. },
  58. r3_hex_api:post(Config, ["users"], Params).
  59. %% @doc
  60. %% Resets the user's password.
  61. %%
  62. %% Examples:
  63. %%
  64. %% ```
  65. %% > r3_hex_api_user:reset_password(r3_hex_core:default_config(), <<"user">>).
  66. %% {ok, {204, ..., nil}}
  67. %% '''
  68. %% @end
  69. -spec reset_password(r3_hex_core:config(), binary()) -> r3_hex_api:response().
  70. reset_password(Config, Username) when is_map(Config) and is_binary(Username) ->
  71. r3_hex_api:post(Config, ["users", Username, "reset"], #{}).
  72. %% @doc
  73. %% Gets a user.
  74. %%
  75. %% Examples:
  76. %%
  77. %% ```
  78. %% > r3_hex_api_user:get(r3_hex_core:default_config()).
  79. %% {ok, {200, ..., #{
  80. %% <<"email">> => <<"user@example.com">>,
  81. %% <<"full_name">> => <<"John Doe">>,
  82. %% <<"handles">> => #{...},
  83. %% <<"inserted_at">> => <<"2014-04-21T17:20:12Z">>,
  84. %% <<"level">> => <<"full">>,
  85. %% <<"updated_at">> => <<"2019-08-04T19:28:05Z">>,
  86. %% <<"url">> => <<"https://hex.pm/api/users/user">>,
  87. %% <<"username">> => <<"user">>
  88. %% }}}
  89. %% '''
  90. %% @end
  91. -spec get(r3_hex_core:config(), binary()) -> r3_hex_api:response().
  92. get(Config, Username) when is_map(Config) and is_binary(Username) ->
  93. r3_hex_api:get(Config, ["users", Username]).