1
0
Fork 0
mirror of https://github.com/fog/fog.git synced 2022-11-09 13:51:43 -05:00
fog--fog/lib/fog/aws/models/cdn/streaming_distribution.rb

78 lines
2.5 KiB
Ruby
Raw Normal View History

require 'fog/core/model'
require 'fog/aws/models/cdn/invalidations'
require 'fog/aws/models/cdn/distribution_helper'
module Fog
module CDN
class AWS
class StreamingDistribution < Fog::Model
include Fog::CDN::AWS::DistributionHelper
identity :id, :aliases => 'Id'
attribute :caller_reference, :aliases => 'CallerReference'
attribute :last_modified_time, :aliases => 'LastModifiedTime'
attribute :status, :aliases => 'Status'
attribute :s3_origin, :aliases => 'S3Origin'
attribute :cname, :aliases => 'CNAME'
attribute :comment, :aliases => 'Comment'
attribute :enabled, :aliases => 'Enabled'
attribute :logging, :aliases => 'Logging'
attribute :domain, :aliases => 'DomainName'
attribute :etag, :aliases => ['Etag', 'ETag']
# items part of DistributionConfig
CONFIG = [ :caller_reference, :cname, :comment, :enabled, :logging ]
def initialize(new_attributes = {})
super(distribution_config_to_attributes(new_attributes))
end
def save
requires_one :s3_origin
options = attributes_to_options
response = identity ? put_distribution_config(identity, etag, options) : post_distribution(options)
etag = response.headers['ETag']
merge_attributes(response.body)
true
end
private
def delete_distribution(identity, etag)
2012-12-22 18:31:58 -05:00
service.delete_streaming_distribution(identity, etag)
end
def put_distribution_config(identity, etag, options)
2012-12-22 18:31:58 -05:00
service.put_streaming_distribution_config(identity, etag, options)
end
def post_distribution(options = {})
2012-12-22 18:31:58 -05:00
service.post_streaming_distribution(options)
end
def attributes_to_options
options = {
'CallerReference' => caller_reference,
'S3Origin' => s3_origin,
'CNAME' => cname,
'Comment' => comment,
'Enabled' => enabled,
'Logging' => logging,
}
options.reject! { |k,v| v.nil? }
options.reject! { |k,v| v.respond_to?(:empty?) && v.empty? }
options
end
def distribution_config_to_attributes(new_attributes = {})
new_attributes.merge(new_attributes.delete('StreamingDistributionConfig') || {})
end
end
end
end
end