Skip to content

Commit

Permalink
fix credo warnings
Browse files Browse the repository at this point in the history
  • Loading branch information
aarongraham committed Dec 12, 2023
1 parent 4c001e6 commit d2d9e68
Show file tree
Hide file tree
Showing 2 changed files with 58 additions and 47 deletions.
2 changes: 1 addition & 1 deletion lib/ex_twilio/request_validator.ex
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ defmodule ExTwilio.RequestValidator do

defp compute_hmac(data, key), do: hmac(:sha, key, data)

# TODO: remove when we require OTP 22
# remove when we require OTP 22
if System.otp_release() >= "22" do
defp hmac(digest, key, data), do: :crypto.mac(:hmac, digest, key, data)
else
Expand Down
103 changes: 57 additions & 46 deletions lib/ex_twilio/url_generator.ex
Original file line number Diff line number Diff line change
Expand Up @@ -41,52 +41,8 @@ defmodule ExTwilio.UrlGenerator do
@spec build_url(atom, String.t() | nil, list) :: String.t()
def build_url(module, id \\ nil, options \\ []) do
{url, options} =
case Module.split(module) do
["ExTwilio", "TaskRouter" | _] ->
options = add_workspace_to_options(module, options)
url = add_segments(Config.task_router_url(), module, id, options)
{url, options}

["ExTwilio", "ProgrammableChat" | _] ->
url = add_segments(Config.programmable_chat_url(), module, id, options)
{url, options}

["ExTwilio", "Notify" | _] ->
url = add_segments(Config.notify_url(), module, id, options)
{url, options}

["ExTwilio", "Events" | _] ->
url = add_segments(Config.events_url(), module, id, options)
{url, options}

["ExTwilio", "Fax" | _] ->
url = add_segments(Config.fax_url(), module, id, options)
{url, options}

["ExTwilio", "Studio" | _] ->
options = add_flow_to_options(module, options)
url = add_segments(Config.studio_url(), module, id, options)
{url, options}

["ExTwilio", "Video" | _] ->
url = add_segments(Config.video_url(), module, id, options)
{url, options}

["ExTwilio", "Insights", "Voice" | _] ->
url = add_segments(Config.voice_insights_url(), module, id, options)
{url, options}

["ExTwilio", "InstalledAddOn" | _] ->
options = add_installed_add_on_to_options(module, options)
url = add_segments(Config.preview_url(), module, id, options)
{url, options}

_ ->
# Add Account SID segment if not already present
options = add_account_to_options(module, options)
url = add_segments(Config.base_url(), module, id, options) <> ".json"
{url, options}
end
Module.split(module)
|> construct_url(module, id, options)

# Append querystring
if Keyword.has_key?(options, :query) do
Expand All @@ -96,6 +52,61 @@ defmodule ExTwilio.UrlGenerator do
end
end

defp construct_url(["ExTwilio", "TaskRouter" | _], module, id, options) do
options = add_workspace_to_options(module, options)
url = add_segments(Config.task_router_url(), module, id, options)
{url, options}
end

defp construct_url(["ExTwilio", "ProgrammableChat" | _], module, id, options) do
url = add_segments(Config.programmable_chat_url(), module, id, options)
{url, options}
end

defp construct_url(["ExTwilio", "Notify" | _], module, id, options) do
url = add_segments(Config.notify_url(), module, id, options)
{url, options}
end

defp construct_url(["ExTwilio", "Events" | _], module, id, options) do
url = add_segments(Config.events_url(), module, id, options)
{url, options}
end

defp construct_url(["ExTwilio", "Fax" | _], module, id, options) do
url = add_segments(Config.fax_url(), module, id, options)
{url, options}
end

defp construct_url(["ExTwilio", "Studio" | _], module, id, options) do
options = add_flow_to_options(module, options)
url = add_segments(Config.studio_url(), module, id, options)
{url, options}
end

defp construct_url(["ExTwilio", "Video" | _], module, id, options) do
url = add_segments(Config.video_url(), module, id, options)
{url, options}
end

defp construct_url(["ExTwilio", "Insights", "Voice" | _], module, id, options) do
url = add_segments(Config.voice_insights_url(), module, id, options)
{url, options}
end

defp construct_url(["ExTwilio", "InstalledAddOn" | _], module, id, options) do
options = add_installed_add_on_to_options(module, options)
url = add_segments(Config.preview_url(), module, id, options)
{url, options}
end

defp construct_url(_, module, id, options) do
# Add Account SID segment if not already present
options = add_account_to_options(module, options)
url = add_segments(Config.base_url(), module, id, options) <> ".json"
{url, options}
end

defp add_segments(url, module, id, options) do
# Append parents
url = url <> build_segments(:parent, normalize_parents(module.parents), options)
Expand Down

0 comments on commit d2d9e68

Please sign in to comment.