Skip to content

Commit

Permalink
refactor insights url generator and add annotation support
Browse files Browse the repository at this point in the history
  • Loading branch information
aarongraham committed Dec 15, 2023
1 parent c09cb58 commit 436f53f
Show file tree
Hide file tree
Showing 5 changed files with 36 additions and 3 deletions.
2 changes: 1 addition & 1 deletion lib/ex_twilio/config.ex
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ defmodule ExTwilio.Config do

def video_url, do: "https://video.twilio.com/v1"

def voice_insights_url, do: "https://insights.twilio.com/v1/Voice"
def voice_insights_url, do: "https://insights.twilio.com/v1"

def preview_url, do: "https://preview.twilio.com/marketplace"

Expand Down
23 changes: 23 additions & 0 deletions lib/ex_twilio/resources/insights/annotation.ex
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
defmodule ExTwilio.Insights.Annotation do
@moduledoc """
Represents Voice Insights Annotation Resource.
- [Twilio docs](https://www.twilio.com/docs/voice/voice-insights/api/call/call-annotation-resource)
"""

defstruct [
:call_sid,
:answered_by,
:connectivity_issue,
:quality_issues,
:spam,
:call_score,
:comment,
:incident
]

use ExTwilio.Resource, import: [:find, :create]

def parents, do: [%ExTwilio.Parent{module: ExTwilio.Insights.Voice, key: :call_sid}]
def resource_name, do: "Annotation"
end
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
defmodule ExTwilio.Insights.Voice.Settings do
defmodule ExTwilio.Insights.Settings do
@moduledoc """
Represents Voice Insights Settings Resource.
Expand All @@ -14,4 +14,6 @@ defmodule ExTwilio.Insights.Voice.Settings do
]

use ExTwilio.Resource, import: [:find, :create]

def resource_name, do: "Voice/Settings"
end
8 changes: 8 additions & 0 deletions lib/ex_twilio/resources/insights/voice.ex
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
defmodule ExTwilio.Insights.Voice do
@moduledoc """
This is module only exists to add "Voice" to url before each of the Insights urls
the Insights urls seem to break the pattern of the rest of the Twilio base urls
"""

def resource_name, do: "Voice"
end
2 changes: 1 addition & 1 deletion lib/ex_twilio/url_generator.ex
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ defmodule ExTwilio.UrlGenerator do
{url, options}
end

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

0 comments on commit 436f53f

Please sign in to comment.