Class: Conversant::V3::Services::CDN::Domain
- Inherits:
-
Object
- Object
- Conversant::V3::Services::CDN::Domain
- Defined in:
- lib/conversant/v3/services/cdn/domain.rb
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.
-
#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 81 |
# 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) if response&.[]('list') domains = response['list'].to_json redis.set(key, domains, ex: 600) else return [] end 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.message}" [] 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.
173 174 175 176 177 178 179 180 181 182 183 184 185 186 |
# File 'lib/conversant/v3/services/cdn/domain.rb', line 173 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.message}" nil end |
#find(domain_id) ⇒ OpenStruct?
Find domain by ID
99 100 101 |
# File 'lib/conversant/v3/services/cdn/domain.rb', line 99 def find(domain_id) all.find { |domain| domain.id == domain_id } end |
#find_by(params) ⇒ OpenStruct?
Find domain by attributes
117 118 119 |
# File 'lib/conversant/v3/services/cdn/domain.rb', line 117 def find_by(params) all.find { |domain| domain.name == params[:name] } 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.
201 202 203 204 205 206 207 208 |
# File 'lib/conversant/v3/services/cdn/domain.rb', line 201 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.message}" 0 end |