diff --git a/lib/elixir_auth_google.ex b/lib/elixir_auth_google.ex index d506901..c4c5b8f 100644 --- a/lib/elixir_auth_google.ex +++ b/lib/elixir_auth_google.ex @@ -16,7 +16,7 @@ defmodule ElixirAuthGoogle do def get_baseurl_from_conn(%{host: h, port: p}) when h == "localhost" do "http://#{h}:#{p}" end - + def get_baseurl_from_conn(%{host: h}) do "https://#{h}" end @@ -90,9 +90,11 @@ defmodule ElixirAuthGoogle do body = Map.get(response, :body) if body == nil do {:error, :no_body} - else - Poison.decode(body) # should return an {:ok, map} tuple for consistecy? - end + else # make keys of map atoms for easier access in templates + {:ok, str_key_map} = Poison.decode(body) + atom_key_map = for {key, val} <- str_key_map, into: %{}, + do: {String.to_atom(key), val} + {:ok, atom_key_map} + end # https://stackoverflow.com/questions/31990134 end - end diff --git a/mix.exs b/mix.exs index d1afcdd..691742b 100644 --- a/mix.exs +++ b/mix.exs @@ -2,7 +2,7 @@ defmodule ElixirAuthGoogle.MixProject do use Mix.Project @description "Minimalist Google OAuth Authentication for Elixir Apps" - @version "0.1.0" + @version "0.2.0" def project do [ diff --git a/test/elixir_auth_google_test.exs b/test/elixir_auth_google_test.exs index 23a3ba4..af6eafc 100644 --- a/test/elixir_auth_google_test.exs +++ b/test/elixir_auth_google_test.exs @@ -35,11 +35,12 @@ defmodule ElixirAuthGoogleTest do host: "localhost", port: 4000 } - assert ElixirAuthGoogle.get_token("ok_code", conn) == {:ok, %{"access_token" => "token1"}} + {:ok, res} = ElixirAuthGoogle.get_token("ok_code", conn) + assert res == %{access_token: "token1"} end - test "get user profile" do - assert ElixirAuthGoogle.get_user_profile("123") == {:ok, %{"name" => "dwyl"}} + test "get_user_profile/1" do + assert ElixirAuthGoogle.get_user_profile("123") == {:ok, %{name: "dwyl"}} end test "return error with incorrect token" do