From f9d58d5a10ac4e9e07cca3816e37c399c0ffe9f7 Mon Sep 17 00:00:00 2001 From: Logan Leger Date: Wed, 25 Aug 2021 16:21:15 -0500 Subject: [PATCH] Add Programmable Messaging APIs --- lib/ex_twilio/config.ex | 2 + .../programmable_messaging/alpha_sender.ex | 29 ++++++++++++++ .../programmable_messaging/phone_number.ex | 30 +++++++++++++++ .../programmable_messaging/service.ex | 38 +++++++++++++++++++ .../programmable_messaging/short_code.ex | 30 +++++++++++++++ lib/ex_twilio/url_generator.ex | 4 ++ 6 files changed, 133 insertions(+) create mode 100644 lib/ex_twilio/resources/programmable_messaging/alpha_sender.ex create mode 100644 lib/ex_twilio/resources/programmable_messaging/phone_number.ex create mode 100644 lib/ex_twilio/resources/programmable_messaging/service.ex create mode 100644 lib/ex_twilio/resources/programmable_messaging/short_code.ex diff --git a/lib/ex_twilio/config.ex b/lib/ex_twilio/config.ex index 3e6b638..365ff32 100644 --- a/lib/ex_twilio/config.ex +++ b/lib/ex_twilio/config.ex @@ -69,6 +69,8 @@ defmodule ExTwilio.Config do def video_url, do: "https://video.twilio.com/v1" + def programmable_messaging_url, do: "https://messaging.twilio.com/v1" + @doc """ A light wrapper around `Application.get_env/2`, providing automatic support for `{:system, "VAR"}` tuples. diff --git a/lib/ex_twilio/resources/programmable_messaging/alpha_sender.ex b/lib/ex_twilio/resources/programmable_messaging/alpha_sender.ex new file mode 100644 index 0000000..1b3700d --- /dev/null +++ b/lib/ex_twilio/resources/programmable_messaging/alpha_sender.ex @@ -0,0 +1,29 @@ +defmodule ExTwilio.ProgrammableMessaging.AlphaSender do + @moduledoc """ + Represents an AlphaSender resource in the Twilio Programmable Messaging API. + + - [Twilio docs](https://www.twilio.com/docs/messaging/services/api/alphasender-resource) + """ + defstruct sid: nil, + account_sid: nil, + service_sid: nil, + date_created: nil, + date_updated: nil, + alpha_sender: nil, + capabilities: nil, + url: nil + + use ExTwilio.Resource, + import: [ + :stream, + :all, + :find, + :create, + :destroy + ] + + def parents, + do: [ + %ExTwilio.Parent{module: ExTwilio.ProgrammableMessaging.Service, key: :service} + ] +end diff --git a/lib/ex_twilio/resources/programmable_messaging/phone_number.ex b/lib/ex_twilio/resources/programmable_messaging/phone_number.ex new file mode 100644 index 0000000..29de4c9 --- /dev/null +++ b/lib/ex_twilio/resources/programmable_messaging/phone_number.ex @@ -0,0 +1,30 @@ +defmodule ExTwilio.ProgrammableMessaging.PhoneNumber do + @moduledoc """ + Represents a PhoneNumber resource in the Twilio Programmable Messaging API. + + - [Twilio docs](https://www.twilio.com/docs/messaging/services/api/phonenumber-resource) + """ + defstruct sid: nil, + account_sid: nil, + service_sid: nil, + date_created: nil, + date_updated: nil, + phone_number: nil, + country_code: nil, + capabilities: nil, + url: nil + + use ExTwilio.Resource, + import: [ + :stream, + :all, + :find, + :create, + :destroy + ] + + def parents, + do: [ + %ExTwilio.Parent{module: ExTwilio.ProgrammableMessaging.Service, key: :service} + ] +end diff --git a/lib/ex_twilio/resources/programmable_messaging/service.ex b/lib/ex_twilio/resources/programmable_messaging/service.ex new file mode 100644 index 0000000..dd2666b --- /dev/null +++ b/lib/ex_twilio/resources/programmable_messaging/service.ex @@ -0,0 +1,38 @@ +defmodule ExTwilio.ProgrammableMessaging.Service do + @moduledoc """ + Represents a Service resource in the Twilio Programmable Messaging API. + + - [Twilio docs](https://www.twilio.com/docs/messaging/services/api) + """ + defstruct sid: nil, + account_sid: nil, + friendly_name: nil, + date_created: nil, + date_updated: nil, + inbound_request_url: nil, + inbound_method: nil, + fallback_url: nil, + fallback_method: nil, + status_callback: nil, + sticky_sender: nil, + mms_converter: nil, + smart_encoding: nil, + scan_message_content: nil, + fallback_to_long_code: nil, + area_code_geomatch: nil, + synchronous_validation: nil, + validity_period: nil, + url: nil, + links: nil, + use_inbound_webhook_on_number: nil + + use ExTwilio.Resource, + import: [ + :stream, + :all, + :find, + :create, + :update, + :destroy + ] +end diff --git a/lib/ex_twilio/resources/programmable_messaging/short_code.ex b/lib/ex_twilio/resources/programmable_messaging/short_code.ex new file mode 100644 index 0000000..7235d5e --- /dev/null +++ b/lib/ex_twilio/resources/programmable_messaging/short_code.ex @@ -0,0 +1,30 @@ +defmodule ExTwilio.ProgrammableMessaging.ShortCode do + @moduledoc """ + Represents a ShortCode resource in the Twilio Programmable Messaging API. + + - [Twilio docs](https://www.twilio.com/docs/messaging/services/api/shortcode-resource) + """ + defstruct sid: nil, + account_sid: nil, + service_sid: nil, + date_created: nil, + date_updated: nil, + short_code: nil, + country_code: nil, + capabilities: nil, + url: nil + + use ExTwilio.Resource, + import: [ + :stream, + :all, + :find, + :create, + :destroy + ] + + def parents, + do: [ + %ExTwilio.Parent{module: ExTwilio.ProgrammableMessaging.Service, key: :service} + ] +end diff --git a/lib/ex_twilio/url_generator.ex b/lib/ex_twilio/url_generator.ex index a00af1d..36ab32c 100644 --- a/lib/ex_twilio/url_generator.ex +++ b/lib/ex_twilio/url_generator.ex @@ -68,6 +68,10 @@ defmodule ExTwilio.UrlGenerator do url = add_segments(Config.video_url(), module, id, options) {url, options} + ["ExTwilio", "ProgrammableMessaging" | _] -> + url = add_segments(Config.programmable_messaging_url(), module, id, options) + {url, options} + _ -> # Add Account SID segment if not already present options = add_account_to_options(module, options)