Skip to content

Commit

Permalink
feat(Rest): add c:get_current_user/0
Browse files Browse the repository at this point in the history
  • Loading branch information
SpaceEEC committed Aug 17, 2019
1 parent 0e5085c commit fcc7474
Show file tree
Hide file tree
Showing 4 changed files with 568 additions and 494 deletions.
4 changes: 4 additions & 0 deletions lib/mix/tasks/bangify.ex
Original file line number Diff line number Diff line change
Expand Up @@ -183,6 +183,10 @@ defmodule Mix.Tasks.Bangify do
"(#{format_type(params)}) :: #{return} | no_return()"
end

defp format_type_bang({:type, _, :fun, [params, {:atom, 0, :ok}]}) do
"(#{format_type(params)}) :: :ok | no_return()"
end

defp format_type({:type, _, :fun, [params, return]}) do
"(#{format_type(params)}) :: #{format_type(return)}"
end
Expand Down
11 changes: 9 additions & 2 deletions lib/rest.ex
Original file line number Diff line number Diff line change
Expand Up @@ -1541,8 +1541,15 @@ defmodule Crux.Rest do
"""
Version.since("0.2.0")

@callback get_user(user :: Util.user_id_resolvable() | String.t()) ::
{:ok, User.t()} | {:error, term()}
@callback get_user(user :: Util.user_id_resolvable()) :: {:ok, User.t()} | {:error, term()}

@doc """
Gets the current user from the api.
For more information see [Discord Docs](https://discordapp.com/developers/docs/resources/user#get-current-user).
"""
Version.since("0.2.1")
@callback get_current_user() :: {:ok, User.t()} | {:error, term()}

@typedoc """
Used to modify the currently logged in `c:modify_current_user/1`.
Expand Down
9 changes: 9 additions & 0 deletions lib/rest/functions.ex
Original file line number Diff line number Diff line change
Expand Up @@ -1090,6 +1090,15 @@ defmodule Crux.Rest.Functions do
|> Request.set_transform(User)
end

@impl true
def get_current_user() do
path = Endpoints.me()

:get
|> Request.new(path)
|> Request.set_transform(User)
end

@impl true
def modify_current_user(data) do
path = Endpoints.me()
Expand Down

0 comments on commit fcc7474

Please sign in to comment.