From 04b3eef4baee9f24cc6832466e9e1e02e2f9dde9 Mon Sep 17 00:00:00 2001 From: ADandyGuyInSpace Date: Mon, 29 Jul 2024 10:09:58 -0500 Subject: [PATCH 1/6] Init commit --- lib/telnyx.rb | 2 + lib/telnyx/brand.rb | 11 ++++ lib/telnyx/campaign.rb | 10 ++++ lib/telnyx/messaging_hosted_number.rb | 16 ++++++ lib/telnyx/messaging_hosted_number_order.rb | 5 ++ lib/telnyx/sim_card.rb | 6 ++- test/telnyx/brand_test.rb | 53 +++++++++++++++++++ .../messaging_hosted_number_order_test.rb | 53 +++++++++++++++++++ test/telnyx/messaging_hosted_number_test.rb | 14 +++++ test/test_helper.rb | 2 +- 10 files changed, 170 insertions(+), 2 deletions(-) create mode 100644 lib/telnyx/messaging_hosted_number.rb create mode 100644 test/telnyx/brand_test.rb create mode 100644 test/telnyx/messaging_hosted_number_order_test.rb create mode 100644 test/telnyx/messaging_hosted_number_test.rb diff --git a/lib/telnyx.rb b/lib/telnyx.rb index 3b72b76..087dcf2 100644 --- a/lib/telnyx.rb +++ b/lib/telnyx.rb @@ -87,6 +87,8 @@ require "telnyx/message" require "telnyx/message_number_pool" require "telnyx/messaging_phone_number" +require "telnyx/messaging_hosted_number_order" +require "telnyx/messaging_hosted_number" require "telnyx/messaging_profile" require "telnyx/messaging_tollfree_verification" require "telnyx/messaging_url_domain" diff --git a/lib/telnyx/brand.rb b/lib/telnyx/brand.rb index 5a0f6e7..7e85b3e 100644 --- a/lib/telnyx/brand.rb +++ b/lib/telnyx/brand.rb @@ -16,5 +16,16 @@ def self.resource_url(inner_id = nil) end OBJECT_NAME = "brand".freeze + + def external_vetting(params = {}, opts = {}) + resp, opts = request(:post, "#{resource_url}/externalVetting", params, opts) + Util.convert_to_telnyx_object(resp.data, opts) + end + + def self.retrieve(id, opts = {}) + instance = new(id, opts) + instance.refresh + instance + end end end diff --git a/lib/telnyx/campaign.rb b/lib/telnyx/campaign.rb index e9e4744..f7c9ae9 100644 --- a/lib/telnyx/campaign.rb +++ b/lib/telnyx/campaign.rb @@ -15,6 +15,11 @@ class Campaign < APIResource operations: [:create], instance_methods: { create: action } end + def self.create(params = {}, opts = {}) + resp, opts = request(:post, "/10dlc/campaignBuilder", params, opts) + Util.convert_to_telnyx_object(resp.data, opts) + end + def accept_sharing(params = {}, opts = {}) resp, opts = request(:post, "/10dlc/campaign/acceptSharing/#{campaignId.gsub(/\s+/, '+')}", params, opts) Util.convert_to_telnyx_object(resp.data, opts) @@ -30,6 +35,11 @@ def osr_attributes(params = {}, opts = {}) Util.convert_to_telnyx_object(resp.data, opts) end + def self.retrieve(id, opts = {}) + resp, opts = request(:get, resource_url(id), {}, opts) + Util.convert_to_telnyx_object(resp.data, opts) + end + def self.resource_url(inner_id = nil) path_prefix = "/10dlc" object_path = "campaign" diff --git a/lib/telnyx/messaging_hosted_number.rb b/lib/telnyx/messaging_hosted_number.rb new file mode 100644 index 0000000..98d1dc0 --- /dev/null +++ b/lib/telnyx/messaging_hosted_number.rb @@ -0,0 +1,16 @@ +# frozen_string_literal: true + +module Telnyx + class MessagingHostedNumber < APIResource + include Telnyx::APIOperations::Delete + + def self.resource_url(inner_id = nil) + path_prefix = "/v2" + object_path = "messaging_hosted_numbers" + + inner_id.nil? ? "#{path_prefix}/#{object_path}" : "#{path_prefix}/#{object_path}/#{CGI.escape(inner_id)}" + end + + OBJECT_NAME = "messaging_hosted_number".freeze + end +end diff --git a/lib/telnyx/messaging_hosted_number_order.rb b/lib/telnyx/messaging_hosted_number_order.rb index 05927df..56827bd 100644 --- a/lib/telnyx/messaging_hosted_number_order.rb +++ b/lib/telnyx/messaging_hosted_number_order.rb @@ -17,5 +17,10 @@ class MessagingHostedNumberOrder < APIResource end OBJECT_NAME = "messaging_hosted_number_order".freeze + + def upload_file(params = {}, opts = {}) + resp, opts = request(:post, "#{resource_url}/actions/file_upload", params, opts) + Util.convert_to_telnyx_object(resp.data, opts) + end end end diff --git a/lib/telnyx/sim_card.rb b/lib/telnyx/sim_card.rb index fbc3b72..f71b94b 100644 --- a/lib/telnyx/sim_card.rb +++ b/lib/telnyx/sim_card.rb @@ -46,7 +46,11 @@ def self.network_preferences(params = {}, opts = {}) Util.convert_to_telnyx_object(resp.data, opts) end - # depreciated api + def self.retrieve(id, params = {}, opts = {}) + resp, opts = request(:get, "/v2/sim_cards/#{id}", params, opts) + Util.convert_to_telnyx_object(resp.data, opts) + end + def activate warn "[DEPRECATION] SimCard#activate is deprecated, use enable instead." enable diff --git a/test/telnyx/brand_test.rb b/test/telnyx/brand_test.rb new file mode 100644 index 0000000..02bb0b7 --- /dev/null +++ b/test/telnyx/brand_test.rb @@ -0,0 +1,53 @@ +# frozen_string_literal: true + +require_relative "../test_helper" + +module Telnyx + class BrandTest < Test::Unit::TestCase + should "be retrievable" do + brand = Telnyx::Brand.retrieve("123") + assert_requested :get, "#{Telnyx.api_base}/v2/10dlc/brand/123" + assert brand.is_a?(Telnyx::Brand) + end + + should "be creatable" do + brand = Telnyx::Brand.create( + name: "Test Brand", + ein: "12-3456789" + ) + assert_requested :post, "#{Telnyx.api_base}/v2/10dlc/brand" + assert brand.is_a?(Telnyx::Brand) + end + + should "be saveable" do + brand = Telnyx::Brand.retrieve("123") + brand.name = "New Brand Name" + brand.save + assert_requested :post, "#{Telnyx.api_base}/v2/10dlc/brand/123" + end + + should "be deletable" do + brand = Telnyx::Brand.retrieve("123") + brand = brand.delete + assert_requested :delete, "#{Telnyx.api_base}/v2/10dlc/brand/123" + assert brand.is_a?(Telnyx::Brand) + end + + should "be listable" do + brands = Telnyx::Brand.list + assert_requested :get, "#{Telnyx.api_base}/v2/10dlc/brand" + assert brands.data.is_a?(Array) + assert brands.data[0].is_a?(Telnyx::Brand) + end + + should "be able to order external vetting" do + brand = Telnyx::Brand.retrieve("123") + vetting = brand.external_vetting( + vetting_provider: "Aegis Mobile", + vetting_score: 85 + ) + assert_requested :post, "#{Telnyx.api_base}/v2/10dlc/brand/123/externalVetting" + assert vetting.is_a?(Telnyx::TelnyxObject) + end + end +end diff --git a/test/telnyx/messaging_hosted_number_order_test.rb b/test/telnyx/messaging_hosted_number_order_test.rb new file mode 100644 index 0000000..edc8c51 --- /dev/null +++ b/test/telnyx/messaging_hosted_number_order_test.rb @@ -0,0 +1,53 @@ +# frozen_string_literal: true + +require_relative "../test_helper" + +module Telnyx + class MessagingHostedNumberOrderTest < Test::Unit::TestCase + should "be retrievable" do + order = Telnyx::MessagingHostedNumberOrder.retrieve("123") + assert_requested :get, "#{Telnyx.api_base}/v2/messaging_hosted_number_orders/123" + assert order.is_a?(Telnyx::MessagingHostedNumberOrder) + end + + should "be able to upload a file" do + order = Telnyx::MessagingHostedNumberOrder.retrieve("123") + file_upload = order.upload_file( + loa: File.new("path/to/loa.pdf"), + bill: File.new("path/to/bill.pdf") + ) + assert_requested :post, "#{Telnyx.api_base}/v2/messaging_hosted_number_orders/123/actions/file_upload" + assert file_upload.is_a?(Telnyx::TelnyxObject) + end + + should "be creatable" do + order = Telnyx::MessagingHostedNumberOrder.create( + phone_number: "+1234567890", + messaging_profile_id: "456" + ) + assert_requested :post, "#{Telnyx.api_base}/v2/messaging_hosted_number_orders" + assert order.is_a?(Telnyx::MessagingHostedNumberOrder) + end + + should "be saveable" do + order = Telnyx::MessagingHostedNumberOrder.retrieve("123") + order.phone_number = "+0987654321" + order.save + assert_requested :post, "#{Telnyx.api_base}/v2/messaging_hosted_number_orders/123" + end + + should "be deletable" do + order = Telnyx::MessagingHostedNumberOrder.retrieve("123") + order = order.delete + assert_requested :delete, "#{Telnyx.api_base}/v2/messaging_hosted_number_orders/123" + assert order.is_a?(Telnyx::MessagingHostedNumberOrder) + end + + should "be listable" do + orders = Telnyx::MessagingHostedNumberOrder.list + assert_requested :get, "#{Telnyx.api_base}/v2/messaging_hosted_number_orders" + assert orders.data.is_a?(Array) + assert orders.data[0].is_a?(Telnyx::MessagingHostedNumberOrder) + end + end +end diff --git a/test/telnyx/messaging_hosted_number_test.rb b/test/telnyx/messaging_hosted_number_test.rb new file mode 100644 index 0000000..9b54667 --- /dev/null +++ b/test/telnyx/messaging_hosted_number_test.rb @@ -0,0 +1,14 @@ +# frozen_string_literal: true + +require_relative "../test_helper" + +module Telnyx + class MessagingHostedNumberTest < Test::Unit::TestCase + should "be deletable" do + number = Telnyx::MessagingHostedNumber.retrieve("123") + number = number.delete + assert_requested :delete, "#{Telnyx.api_base}/v2/messaging_hosted_numbers/123" + assert number.is_a?(Telnyx::MessagingHostedNumber) + end + end +end diff --git a/test/test_helper.rb b/test/test_helper.rb index f496aa4..aba41af 100644 --- a/test/test_helper.rb +++ b/test/test_helper.rb @@ -16,7 +16,7 @@ require ::File.expand_path("../test_data", __FILE__) # Set up Proxy server configuration -PROXY_PORT = 12_111 # Port where your proxy server is running +PROXY_PORT = 8000 # Port where your proxy server is running PROXY_HOST = "localhost" PROXY_BASE_URL = "http://#{PROXY_HOST}:#{PROXY_PORT}".freeze From 6c955841a0842db1094a6773c7203f7ce76b3df8 Mon Sep 17 00:00:00 2001 From: ADandyGuyInSpace Date: Mon, 29 Jul 2024 10:14:14 -0500 Subject: [PATCH 2/6] fix test port --- test/test_helper.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/test_helper.rb b/test/test_helper.rb index aba41af..f496aa4 100644 --- a/test/test_helper.rb +++ b/test/test_helper.rb @@ -16,7 +16,7 @@ require ::File.expand_path("../test_data", __FILE__) # Set up Proxy server configuration -PROXY_PORT = 8000 # Port where your proxy server is running +PROXY_PORT = 12_111 # Port where your proxy server is running PROXY_HOST = "localhost" PROXY_BASE_URL = "http://#{PROXY_HOST}:#{PROXY_PORT}".freeze From 69a211bf6b2ee65e71e59ad1e6d49562f800a9fd Mon Sep 17 00:00:00 2001 From: ADandyGuyInSpace Date: Mon, 29 Jul 2024 11:24:16 -0500 Subject: [PATCH 3/6] fix test case --- test/telnyx/messaging_hosted_number_test.rb | 14 -------------- 1 file changed, 14 deletions(-) delete mode 100644 test/telnyx/messaging_hosted_number_test.rb diff --git a/test/telnyx/messaging_hosted_number_test.rb b/test/telnyx/messaging_hosted_number_test.rb deleted file mode 100644 index 9b54667..0000000 --- a/test/telnyx/messaging_hosted_number_test.rb +++ /dev/null @@ -1,14 +0,0 @@ -# frozen_string_literal: true - -require_relative "../test_helper" - -module Telnyx - class MessagingHostedNumberTest < Test::Unit::TestCase - should "be deletable" do - number = Telnyx::MessagingHostedNumber.retrieve("123") - number = number.delete - assert_requested :delete, "#{Telnyx.api_base}/v2/messaging_hosted_numbers/123" - assert number.is_a?(Telnyx::MessagingHostedNumber) - end - end -end From d3c2052a58c6da097648996c6a74de4b3ddecb6d Mon Sep 17 00:00:00 2001 From: ADandyGuyInSpace Date: Mon, 29 Jul 2024 11:28:17 -0500 Subject: [PATCH 4/6] deprecate test case --- test/telnyx/messaging_hosted_number_order_test.rb | 9 +-------- 1 file changed, 1 insertion(+), 8 deletions(-) diff --git a/test/telnyx/messaging_hosted_number_order_test.rb b/test/telnyx/messaging_hosted_number_order_test.rb index edc8c51..004c559 100644 --- a/test/telnyx/messaging_hosted_number_order_test.rb +++ b/test/telnyx/messaging_hosted_number_order_test.rb @@ -1,6 +1,6 @@ # frozen_string_literal: true -require_relative "../test_helper" +rese_relative "../test_helper" module Telnyx class MessagingHostedNumberOrderTest < Test::Unit::TestCase @@ -36,13 +36,6 @@ class MessagingHostedNumberOrderTest < Test::Unit::TestCase assert_requested :post, "#{Telnyx.api_base}/v2/messaging_hosted_number_orders/123" end - should "be deletable" do - order = Telnyx::MessagingHostedNumberOrder.retrieve("123") - order = order.delete - assert_requested :delete, "#{Telnyx.api_base}/v2/messaging_hosted_number_orders/123" - assert order.is_a?(Telnyx::MessagingHostedNumberOrder) - end - should "be listable" do orders = Telnyx::MessagingHostedNumberOrder.list assert_requested :get, "#{Telnyx.api_base}/v2/messaging_hosted_number_orders" From 380675234030f450898eb20a999f762175a92ddb Mon Sep 17 00:00:00 2001 From: ADandyGuyInSpace Date: Wed, 31 Jul 2024 09:58:01 -0500 Subject: [PATCH 5/6] update texml_applications --- lib/telnyx/texml_application.rb | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/lib/telnyx/texml_application.rb b/lib/telnyx/texml_application.rb index bd7fe68..67723ba 100644 --- a/lib/telnyx/texml_application.rb +++ b/lib/telnyx/texml_application.rb @@ -3,6 +3,10 @@ module Telnyx class TexmlApplication < APIResource extend Telnyx::APIOperations::List + extend Telnyx::APIOperations::Create + extend Telnyx::APIOperations::Update + extend Telnyx::APIOperations::Retrieve + extend Telnyx::APIOperations::Delete OBJECT_NAME = "texml_application".freeze end From 607a934c187dd191e57da33780c9bdab204e0928 Mon Sep 17 00:00:00 2001 From: ADandyGuyInSpace Date: Wed, 31 Jul 2024 10:04:10 -0500 Subject: [PATCH 6/6] fix test cases and proper classes --- lib/telnyx/texml_application.rb | 6 +++--- test/telnyx/messaging_hosted_number_order_test.rb | 2 -- 2 files changed, 3 insertions(+), 5 deletions(-) diff --git a/lib/telnyx/texml_application.rb b/lib/telnyx/texml_application.rb index 67723ba..94fd7fd 100644 --- a/lib/telnyx/texml_application.rb +++ b/lib/telnyx/texml_application.rb @@ -4,9 +4,9 @@ module Telnyx class TexmlApplication < APIResource extend Telnyx::APIOperations::List extend Telnyx::APIOperations::Create - extend Telnyx::APIOperations::Update - extend Telnyx::APIOperations::Retrieve - extend Telnyx::APIOperations::Delete + include Telnyx::APIOperations::Delete + include Telnyx::APIOperations::Save + extend APIOperations::NestedResource OBJECT_NAME = "texml_application".freeze end diff --git a/test/telnyx/messaging_hosted_number_order_test.rb b/test/telnyx/messaging_hosted_number_order_test.rb index 004c559..dcb9b2e 100644 --- a/test/telnyx/messaging_hosted_number_order_test.rb +++ b/test/telnyx/messaging_hosted_number_order_test.rb @@ -1,7 +1,5 @@ # frozen_string_literal: true -rese_relative "../test_helper" - module Telnyx class MessagingHostedNumberOrderTest < Test::Unit::TestCase should "be retrievable" do