Skip to content

Commit

Permalink
Init commit (#94)
Browse files Browse the repository at this point in the history
* Create testing framework
* First pass on bug fixing around 10DLC
  • Loading branch information
ADandyGuyInSpace authored Jul 31, 2024
1 parent 1e5646e commit 082a6c6
Show file tree
Hide file tree
Showing 9 changed files with 150 additions and 1 deletion.
2 changes: 2 additions & 0 deletions lib/telnyx.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
11 changes: 11 additions & 0 deletions lib/telnyx/brand.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
10 changes: 10 additions & 0 deletions lib/telnyx/campaign.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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"
Expand Down
16 changes: 16 additions & 0 deletions lib/telnyx/messaging_hosted_number.rb
Original file line number Diff line number Diff line change
@@ -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
5 changes: 5 additions & 0 deletions lib/telnyx/messaging_hosted_number_order.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
6 changes: 5 additions & 1 deletion lib/telnyx/sim_card.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 4 additions & 0 deletions lib/telnyx/texml_application.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,10 @@
module Telnyx
class TexmlApplication < APIResource
extend Telnyx::APIOperations::List
extend Telnyx::APIOperations::Create
include Telnyx::APIOperations::Delete
include Telnyx::APIOperations::Save
extend APIOperations::NestedResource

OBJECT_NAME = "texml_application".freeze
end
Expand Down
53 changes: 53 additions & 0 deletions test/telnyx/brand_test.rb
Original file line number Diff line number Diff line change
@@ -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
44 changes: 44 additions & 0 deletions test/telnyx/messaging_hosted_number_order_test.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
# frozen_string_literal: true

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 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

0 comments on commit 082a6c6

Please sign in to comment.