Skip to content

Commit

Permalink
Merge pull request #4 from rgkeith3/grey/add-installed-add-on-resources
Browse files Browse the repository at this point in the history
add installed add on resources
  • Loading branch information
Trevor Fenn authored May 18, 2023
2 parents b62870f + 9a7973c commit d882bba
Show file tree
Hide file tree
Showing 4 changed files with 46 additions and 0 deletions.
2 changes: 2 additions & 0 deletions lib/ex_twilio/config.ex
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,8 @@ defmodule ExTwilio.Config do

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

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

@doc """
A light wrapper around `Application.get_env/2`, providing automatic support for
`{:system, "VAR"}` tuples.
Expand Down
18 changes: 18 additions & 0 deletions lib/ex_twilio/resources/add_on/installed_add_on.ex
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
defmodule ExTwilio.InstalledAddOn do
defstruct [
:sid,
:account_sid,
:friendly_name,
:description,
:configuration,
:unique_name,
:date_created,
:date_updated,
:url,
:links
]

use ExTwilio.Resource, import: [:stream, :all, :create, :destroy, :find, :update]

def parents, do: [:marketplace]
end
15 changes: 15 additions & 0 deletions lib/ex_twilio/resources/add_on/installed_add_on_extension.ex
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
defmodule ExTwilio.InstalledAddOn.Extension do
defstruct [
:sid,
:installed_add_on_sid,
:friendly_name,
:product_name,
:unique_name,
:enabled,
:url
]

use ExTwilio.Resource, import: [:stream, :all, :create, :destroy, :find, :update]

def parents, do: [:installed_add_on]
end
11 changes: 11 additions & 0 deletions lib/ex_twilio/url_generator.ex
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,11 @@ defmodule ExTwilio.UrlGenerator do
url = add_segments(Config.video_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)
Expand Down Expand Up @@ -164,6 +169,12 @@ defmodule ExTwilio.UrlGenerator do
Keyword.put_new(options, :flow, Keyword.get(options, :flow_sid))
end

defp add_installed_add_on_to_options(ExTwilio.InstalledAddOn.Extension, options) do
Keyword.put_new(options, :installed_add_on, Keyword.get(options, :installed_add_on_sid))
end

defp add_installed_add_on_to_options(_, options), do: options

@spec add_workspace_to_options(atom, list) :: list
defp add_workspace_to_options(_module, options) do
Keyword.put_new(options, :workspace, Config.workspace_sid())
Expand Down

0 comments on commit d882bba

Please sign in to comment.