Skip to content

Commit

Permalink
remove brand updates (#95)
Browse files Browse the repository at this point in the history
  • Loading branch information
ADandyGuyInSpace authored Sep 18, 2024
1 parent c678e17 commit 720c4aa
Show file tree
Hide file tree
Showing 3 changed files with 60 additions and 20 deletions.
20 changes: 8 additions & 12 deletions lib/telnyx/api_resource.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,6 @@ class APIResource < TelnyxObject
attr_accessor :save_with_parent

class << self
attr_accessor :base_path

def inherited(subclass)
super
@descendants ||= []
Expand All @@ -30,24 +28,19 @@ def self.resource_url(inner_id = nil)
if self == APIResource
raise NotImplementedError, "APIResource is an abstract class. You should perform actions on its subclasses"
end

# Determine the base path
base_path = self.base_path || "/v2"

# Namespaces are separated in object names with periods (.) and in URLs
# with forward slashes (/), so replace the former with the latter.
return "#{base_path}/#{resource_path(inner_id)}" if respond_to?("resource_path")
return "#{base_path}/#{self::RESOURCE_PATH}" if const_defined?("RESOURCE_PATH")
return "/v2/#{resource_path(inner_id)}" if respond_to?("resource_path")
return "/v2/#{self::RESOURCE_PATH}" if const_defined?("RESOURCE_PATH")

object_name = self::OBJECT_NAME.downcase
keywords = %w[generate summarize global_ip_usage global_ip_latency global_ip_assignment_usage global_ip_assignment_health sub_request campaign]
url_segment = object_name.tr(".", "/")
keywords.any? { |keyword| url_segment.include?(keyword) } ? "#{base_path}/#{url_segment}" : "#{base_path}/#{url_segment}s"
keywords.any? { |keyword| url_segment.include?(keyword) } ? "/v2/#{url_segment}" : "/v2/#{url_segment}s"
end

def self.identified_resource_url(id)
base_path = self.base_path || "/v2"
return "#{base_path}/#{resource_path(id)}" if respond_to?("resource_path")
return "/v2/#{resource_path(id)}" if respond_to?("resource_path")

"#{resource_url}/#{CGI.escape(id)}"
end
Expand All @@ -61,14 +54,17 @@ def self.identified_resource_url(id)
def self.save_nested_resource(name)
define_method(:"#{name}=") do |value|
super(value)

# The parent setter will perform certain useful operations like
# converting to an APIResource if appropriate. Refresh our argument
# value to whatever it mutated to.
value = send(name)

# Note that the value may be subresource, but could also be a scalar
# (like a tokenized card's ID for example), so we check the type before
# setting #save_with_parent here.
value.save_with_parent = true if value.is_a?(APIResource)

value
end
end
Expand All @@ -77,7 +73,7 @@ def resource_url
unless (id = self["id"])
raise InvalidRequestError, "Could not determine which URL to request: #{self.class} instance has invalid ID: #{id.inspect}"
end
return self.class.resource_url(id).to_s if self.class.respond_to?("resource_path")
return self.class.resource_url(id).to_s if self.class.respond_to?("resource_path") # Use resource_path defined paths

"#{self.class.resource_url}/#{CGI.escape(id)}"
end
Expand Down
8 changes: 0 additions & 8 deletions lib/telnyx/brand.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,5 @@ class Brand < APIResource

OBJECT_NAME = "brand".freeze
RESOURCE_PATH = "brand".freeze
def self.create(params = {}, opts = {})
params[:entityType] ||= "PRIVATE_PROFIT"
params[:displayName] ||= "Default Display Name"
params[:country] ||= "US"
params[:email] ||= "[email protected]"
params[:vertical] ||= "COMMUNICATION"
super(params, opts)
end
end
end
52 changes: 52 additions & 0 deletions lib/telnyx/campaign.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
# frozen_string_literal: true

module Telnyx
class Campaign < APIResource
extend Telnyx::APIOperations::List
extend Telnyx::APIOperations::Create
include Telnyx::APIOperations::Delete
include Telnyx::APIOperations::Save
extend APIOperations::NestedResource

ACTIONS = %w[mnoMetadata operationStatus].freeze
ACTIONS.each do |action|
nested_resource_class_methods action,
path: %W[#{action}],
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)
end

def sharing(params = {}, opts = {})
resp, opts = request(:get, "/10dlc/campaign/#{campaignId.gsub(/\s+/, '+')}/sharing", params, opts)
Util.convert_to_telnyx_object(resp.data, opts)
end

def osr_attributes(params = {}, opts = {})
resp, opts = request(:get, "/10dlc/campaign/#{campaignId.gsub(/\s+/, '+')}/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"

inner_id.nil? ? "#{path_prefix}/#{object_path}" : "#{path_prefix}/#{object_path}/#{CGI.escape(inner_id)}"
end

OBJECT_NAME = "campaign".freeze
end
end

0 comments on commit 720c4aa

Please sign in to comment.