From a5f0d8ac2752ff99567ebceff1aae0d055a5d213 Mon Sep 17 00:00:00 2001 From: nelsonic Date: Thu, 2 Apr 2020 22:57:38 +0100 Subject: [PATCH] define inject/0 function to inject HTTPoison dependency #35 --- lib/elixir_auth_google.ex | 11 +++++++---- mix.exs | 2 +- 2 files changed, 8 insertions(+), 5 deletions(-) diff --git a/lib/elixir_auth_google.ex b/lib/elixir_auth_google.ex index 3e85050..08c0d9a 100644 --- a/lib/elixir_auth_google.ex +++ b/lib/elixir_auth_google.ex @@ -3,11 +3,13 @@ defmodule ElixirAuthGoogle do Minimalist Google OAuth Authentication for Elixir Apps. Extensively tested, documented, maintained and in active use in production. """ - @httpoison Mix.env() == :test && ElixirAuthGoogle.HTTPoisonMock || HTTPoison @google_auth_url "https://accounts.google.com/o/oauth2/v2/auth?response_type=code" @google_token_url "https://oauth2.googleapis.com/token" @google_user_profile "https://www.googleapis.com/oauth2/v3/userinfo" + def inject() do + Mix.env() == :test && ElixirAuthGoogle.HTTPoisonMock || HTTPoison + end @doc """ `get_baseurl_from_conn/1` derives the base URL from the conn struct @@ -62,7 +64,7 @@ defmodule ElixirAuthGoogle do def get_token(code, conn) do env = Mix.env() IO.inspect(env, label: "env") - IO.inspect(@httpoison, label: "@httpoison") + httpoison = inject() body = Poison.encode!( %{ client_id: System.get_env("GOOGLE_CLIENT_ID"), client_secret: System.get_env("GOOGLE_CLIENT_SECRET"), @@ -71,7 +73,7 @@ defmodule ElixirAuthGoogle do code: code }) IO.inspect(body, label: "body") - @httpoison.post(@google_token_url, body) + httpoison.post(@google_token_url, body) |> parse_body_response() |> IO.inspect(label: "get_token() response") end @@ -86,8 +88,9 @@ defmodule ElixirAuthGoogle do """ @spec get_user_profile(String.t) :: String.t def get_user_profile(token) do + httpoison = inject() "#{@google_user_profile}?access_token=#{token}" - |> @httpoison.get() + |> httpoison.get() |> parse_body_response() |> IO.inspect(label: "get_user_profile() response") end diff --git a/mix.exs b/mix.exs index 30e786a..55bc659 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 "1.1.2" + @version "1.1.3" def project do [