From f1a1479bf3d95e717cb1356dfe2d19d9f18c9ab2 Mon Sep 17 00:00:00 2001 From: Eduardo Cunha Date: Thu, 18 Mar 2021 16:47:39 -0300 Subject: [PATCH 1/2] Fix Dialyzer errors --- lib/ex_twilio/api.ex | 33 ++++++++++++++----------------- lib/ex_twilio/jwt/access_token.ex | 2 +- lib/ex_twilio/url_generator.ex | 3 ++- 3 files changed, 18 insertions(+), 20 deletions(-) diff --git a/lib/ex_twilio/api.ex b/lib/ex_twilio/api.ex index 1700089..0fc46f9 100644 --- a/lib/ex_twilio/api.ex +++ b/lib/ex_twilio/api.ex @@ -15,7 +15,6 @@ defmodule ExTwilio.Api do Items are returned as instances of the given module's struct. For more details, see the documentation for each function. """ - use HTTPoison.Base alias ExTwilio.Config @@ -170,14 +169,25 @@ defmodule ExTwilio.Api do def auth_header(headers, _), do: headers + @spec format_data(any) :: binary + def format_data(data) + + def format_data(data) when is_map(data) do + data + |> Map.to_list() + |> Url.to_query_string() + end + + def format_data(data) when is_list(data) do + Url.to_query_string(data) + end + + def format_data(data), do: data + ### # HTTPotion API ### - @doc """ - Automatically adds the correct headers to each API request. - """ - @spec process_request_headers(list) :: list def process_request_headers(headers \\ []) do headers |> Keyword.put(:"Content-Type", "application/x-www-form-urlencoded; charset=UTF-8") @@ -187,17 +197,4 @@ defmodule ExTwilio.Api do def process_request_options(options) do Keyword.merge(options, Config.request_options()) end - - @spec format_data(data) :: binary - def format_data(data) when is_map(data) do - data - |> Map.to_list() - |> Url.to_query_string() - end - - def format_data(data) when is_list(data) do - Url.to_query_string(data) - end - - def format_data(data), do: data end diff --git a/lib/ex_twilio/jwt/access_token.ex b/lib/ex_twilio/jwt/access_token.ex index f22eb87..08aa2ea 100644 --- a/lib/ex_twilio/jwt/access_token.ex +++ b/lib/ex_twilio/jwt/access_token.ex @@ -95,7 +95,7 @@ defmodule ExTwilio.JWT.AccessToken do "cty" => "twilio-fpa;v=1" }) - Joken.generate_and_sign!(token_config, nil, signer) + Joken.generate_and_sign!(token_config, %{}, signer) end defp list_of_grants?(grants) when is_list(grants) do diff --git a/lib/ex_twilio/url_generator.ex b/lib/ex_twilio/url_generator.ex index 7fdb2a6..df3c8e9 100644 --- a/lib/ex_twilio/url_generator.ex +++ b/lib/ex_twilio/url_generator.ex @@ -147,6 +147,8 @@ defmodule ExTwilio.UrlGenerator do end @spec add_account_to_options(atom, list) :: list + defp add_account_to_options(module, options) + defp add_account_to_options(module, options) do if module == ExTwilio.Account and options[:account] == nil do options @@ -155,7 +157,6 @@ defmodule ExTwilio.UrlGenerator do end end - @spec add_account_to_options(atom, list) :: list defp add_flow_to_options(_module, options) do Keyword.put_new(options, :flow, Keyword.get(options, :flow_sid)) end From d83fda502b3f60d8ca44626212cbef935b6e86e9 Mon Sep 17 00:00:00 2001 From: Eduardo Cunha Date: Thu, 18 Mar 2021 16:48:01 -0300 Subject: [PATCH 2/2] Add a Dialyzer check to the CI tests --- bin/test | 2 ++ 1 file changed, 2 insertions(+) diff --git a/bin/test b/bin/test index 51c75e3..43b456a 100755 --- a/bin/test +++ b/bin/test @@ -13,6 +13,8 @@ MIX_ENV=test mix format --check-formatted || { echo 'Please format code with `mi MIX_ENV=test mix compile --warnings-as-errors --force || { echo 'Please fix all compiler warnings.'; exit 1; } +MIX_ENV=test mix dialyze || { echo 'Please fix all dialyzer errors.'; exit 1; } + MIX_ENV=test mix docs || { echo 'Elixir HTML docs were not generated!'; exit 1; } mix test || { echo 'Elixir tests failed!'; exit 1; }