Skip to content

Commit

Permalink
Merge pull request #22 from dwyl/transform-map-keys-to-atoms-issue#20
Browse files Browse the repository at this point in the history
Transform map keys to atoms issue #20
  • Loading branch information
SimonLab authored Dec 5, 2019
2 parents b443914 + d61d47c commit 3d05d28
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 9 deletions.
12 changes: 7 additions & 5 deletions lib/elixir_auth_google.ex
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
2 changes: 1 addition & 1 deletion mix.exs
Original file line number Diff line number Diff line change
Expand Up @@ -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
[
Expand Down
7 changes: 4 additions & 3 deletions test/elixir_auth_google_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 3d05d28

Please sign in to comment.