mirror of
https://github.com/mgerb/classic-wow-forums
synced 2026-01-10 09:02:50 +00:00
character list end point
This commit is contained in:
@@ -7,7 +7,9 @@ defmodule MyApp.BattleNet.User do
|
|||||||
# grab user information from battle net api - use token for auth
|
# grab user information from battle net api - use token for auth
|
||||||
@spec get_user(String.t | {atom, any}) :: {:ok, battle_net_user} | {:error, any}
|
@spec get_user(String.t | {atom, any}) :: {:ok, battle_net_user} | {:error, any}
|
||||||
def get_user(access_token) when is_binary(access_token) do
|
def get_user(access_token) when is_binary(access_token) do
|
||||||
HTTPoison.get(resource_url("account/user", access_token))
|
access_token
|
||||||
|
|> resource_url("account/user")
|
||||||
|
|> HTTPoison.get
|
||||||
|> parse_user_response(access_token)
|
|> parse_user_response(access_token)
|
||||||
end
|
end
|
||||||
def get_user({:ok, access_token}), do: get_user(access_token)
|
def get_user({:ok, access_token}), do: get_user(access_token)
|
||||||
@@ -26,7 +28,19 @@ defmodule MyApp.BattleNet.User do
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
defp resource_url(path, access_token) do
|
@spec get_user_characters(String.t) :: {:ok, map} | {:error, any}
|
||||||
|
def get_user_characters(access_token) do
|
||||||
|
access_token
|
||||||
|
|> resource_url("wow/user/characters")
|
||||||
|
|> HTTPoison.get
|
||||||
|
|> parse_character_response
|
||||||
|
end
|
||||||
|
|
||||||
|
defp parse_character_response({:error, error}), do: {:error, error}
|
||||||
|
defp parse_character_response({:ok, %HTTPoison.Response{body: body}}), do: Poison.decode(body)
|
||||||
|
|
||||||
|
defp resource_url(access_token, path) do
|
||||||
"#{api_url()}/#{path}?access_token=#{access_token}"
|
"#{api_url()}/#{path}?access_token=#{access_token}"
|
||||||
end
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -22,4 +22,19 @@ defmodule MyAppWeb.BattleNetController do
|
|||||||
|>Response.json(output)
|
|>Response.json(output)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
# TODO: cache this end point
|
||||||
|
def characters(conn, _params) do
|
||||||
|
token = conn
|
||||||
|
|> MyApp.Guardian.Plug.current_claims
|
||||||
|
|> Map.get("access_token")
|
||||||
|
|
||||||
|
{output, status} = token
|
||||||
|
|> BattleNet.User.get_user_characters
|
||||||
|
|> Response.put_resp
|
||||||
|
|
||||||
|
conn
|
||||||
|
|>put_status(status)
|
||||||
|
|>Response.json(output)
|
||||||
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -16,6 +16,9 @@ defmodule MyAppWeb.Router do
|
|||||||
|
|
||||||
scope "/battlenet" do
|
scope "/battlenet" do
|
||||||
get "/authorize", BattleNetController, :authorize
|
get "/authorize", BattleNetController, :authorize
|
||||||
|
|
||||||
|
pipe_through [:api_auth]
|
||||||
|
get "/characters", BattleNetController, :characters
|
||||||
end
|
end
|
||||||
|
|
||||||
scope "/user" do
|
scope "/user" do
|
||||||
|
|||||||
Reference in New Issue
Block a user