Class: Conversant::V3::Services::CDN::Domain
- Inherits:
-
Object
- Object
- Conversant::V3::Services::CDN::Domain
- Defined in:
- lib/conversant/v3/services/cdn/domain.rb,
sig/conversant/v3/services/cdn.rbs
Overview
Domain management service for CDN domains
Provides comprehensive domain management functionality including:
- Domain listing and filtering
- Domain creation and configuration
- Domain lookup and search
- Storage usage calculations
Instance Attribute Summary collapse
-
#parent ⇒ CDN
readonly
The parent CDN service instance.
Instance Method Summary collapse
-
#all ⇒ Array<OpenStruct>, Array
Get all domains for the customer.
-
#create(payload) ⇒ Integer?
Create a new CDN domain.
-
#find(domain_id) ⇒ OpenStruct?
Find domain by ID.
-
#find_by(params) ⇒ OpenStruct?
Find domain by attributes.
-
#initialize(parent) ⇒ Domain
constructor
Initialize domain service.
- #logger ⇒ Object
- #redis ⇒ Object
-
#total_current_disk_usage ⇒ Integer
Calculate total disk usage for storage domains.
Constructor Details
#initialize(parent) ⇒ Domain
Initialize domain service
37 38 39 |
# File 'lib/conversant/v3/services/cdn/domain.rb', line 37 def initialize(parent) @parent = parent end |
Instance Attribute Details
#parent ⇒ CDN (readonly)
Returns the parent CDN service instance.
32 33 34 |
# File 'lib/conversant/v3/services/cdn/domain.rb', line 32 def parent @parent end |
Instance Method Details
#all ⇒ Array<OpenStruct>, Array
Get all domains for the customer
Retrieves all domains associated with the customer account. Results are cached in Redis for 10 minutes to improve performance.
58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 |
# File 'lib/conversant/v3/services/cdn/domain.rb', line 58 def all key = "customer.#{@parent.customer_id}.domain.all" domains = redis.get(key) if domains.nil? response = @parent.send(:call, 'GET', '/api/delivery_domains?pageSize=-1&pageNumber=-1') return [] if response.nil? response = JSON.parse(response) return [] unless response&.[]('list') domains = response['list'].to_json redis.set(key, domains, ex: 600) end JSON.parse(domains).map do |item| OpenStruct.new(item.merge(customer_id: @parent.customer_id)) end rescue StandardError => e logger.error "#{@parent.send(:identifier)}.METHOD:#{__method__}.EXCEPTION:#{e.}" [] end |
#create(payload) ⇒ Integer?
Create a new CDN domain
Creates a new CDN domain with the specified configuration. Automatically clears the domain cache upon successful creation.
172 173 174 175 176 177 178 179 180 181 182 183 184 185 |
# File 'lib/conversant/v3/services/cdn/domain.rb', line 172 def create(payload) response = @parent.send(:call, 'POST', '/api/v6/delivery_domain', payload) return nil if response.nil? response = JSON.parse(response) return nil unless response.to_i.positive? # Clear cache after creation redis.del("customer.#{@parent.customer_id}.domain.all") response rescue StandardError => e logger.error "#{@parent.send(:identifier)}.METHOD:#{__method__}.EXCEPTION:#{e.}" nil end |
#find(domain_id) ⇒ OpenStruct?
Find domain by ID
98 99 100 |
# File 'lib/conversant/v3/services/cdn/domain.rb', line 98 def find(domain_id) all.find { |domain| domain.id == domain_id } end |
#find_by(params) ⇒ OpenStruct?
Find domain by attributes
116 117 118 |
# File 'lib/conversant/v3/services/cdn/domain.rb', line 116 def find_by(params) all.find { |domain| domain.name == params[:name] } end |
#logger ⇒ Object
215 216 217 |
# File 'lib/conversant/v3/services/cdn/domain.rb', line 215 def logger @parent.send(:logger) end |
#redis ⇒ Object
211 212 213 |
# File 'lib/conversant/v3/services/cdn/domain.rb', line 211 def redis @parent.send(:redis) end |
#total_current_disk_usage ⇒ Integer
Calculate total disk usage for storage domains
Calculates the total current disk usage across all active storage domains (businessScenarioType=2, status=1) for the customer.
200 201 202 203 204 205 206 207 |
# File 'lib/conversant/v3/services/cdn/domain.rb', line 200 def total_current_disk_usage all.select do |item| item.businessScenarioType == 2 && item.status == 1 end.map(&:current_disk_usage).sum rescue StandardError => e logger.error "#{@parent.send(:identifier)}.METHOD:#{__method__}.EXCEPTION:#{e.}" 0 end |