Class: Cloudfront::Helpers::StreamingDistribution
- Inherits:
-
Object
- Object
- Cloudfront::Helpers::StreamingDistribution
- Includes:
- Utils::ConfigurationChecker, Utils::XmlSerializer
- Defined in:
- lib/cloudfront/helpers/streaming_distribution.rb
Instance Attribute Summary collapse
-
#caller_reference ⇒ Object
Returns the value of attribute caller_reference.
-
#cnames ⇒ Object
Returns the value of attribute cnames.
-
#comment ⇒ Object
Returns the value of attribute comment.
-
#domain_name ⇒ Object
Returns the value of attribute domain_name.
-
#enabled ⇒ Object
Returns the value of attribute enabled.
-
#logging ⇒ Object
Returns the value of attribute logging.
-
#origin_access_identity ⇒ Object
Returns the value of attribute origin_access_identity.
-
#price_class ⇒ Object
Returns the value of attribute price_class.
-
#trusted_signers ⇒ Object
Returns the value of attribute trusted_signers.
Attributes included from Utils::ConfigurationChecker
Class Method Summary collapse
-
.from_hash(hash) ⇒ Object
Creates a distribution configuration wrapper from a hash { “StreamingDistributionConfig” => { “CallerReference” => “unique description for this distribution”, “S3Origin” => { … see s3Origin }, “Aliases” => { “Quantity” => “number of CNAME aliases”, “Items” => { “CNAME” => “CNAME alias” } }, “Comment” => “comment about the distribution”, “Logging” => { “Enabled” => “true | false”, “Bucket” => “Amazon S3 bucket for logs”, “Prefix” => “prefix for log file names” }, “TrustedSigners” => { “Quantity” => “number of trusted signers”, “Items” => { “AwsAccountNumber” => “self | AWS account that can create n signed URLs” } }, “PriceClass” => “maximum price class for the distribution”, “Enabled” => “true | false” } }.
Instance Method Summary collapse
-
#build_xml(xml) ⇒ Object
<StreamingDistributionConfig xmlns=“cloudfront.amazonaws.com/doc/2012-07-01/”> <CallerReference>unique description for this distribution</CallerReference> <S3Origin> <DNSName>CloudFront domain name assigned to the distribution</DNSName> <OriginAccessIdentity>origin-access-identity/cloudfront/ID</OriginAccessIdentity> </S3Origin> <Aliases> …
-
#initialize(&block) ⇒ StreamingDistribution
constructor
A new instance of StreamingDistribution.
- #validate ⇒ Object
Methods included from Utils::XmlSerializer
Methods included from Utils::ConfigurationChecker
Constructor Details
#initialize(&block) ⇒ StreamingDistribution
Returns a new instance of StreamingDistribution.
24 25 26 27 28 29 30 31 32 33 34 35 36 37 |
# File 'lib/cloudfront/helpers/streaming_distribution.rb', line 24 def initialize(&block) #setting default values @caller_reference = Cloudfront::Utils::Util.generate_caller_reference @s3_origin = S3Origin.new @cnames = [] @comment = "Created with cloudfront Gem, visit https://github.com/Belkacem/cloudfront" @logging = Logging.new @trusted_signers = [] @price_class = "PriceClass_All" @enabled = false #set value from block instance_eval &block if block_given? end |
Instance Attribute Details
#caller_reference ⇒ Object
Returns the value of attribute caller_reference.
14 15 16 |
# File 'lib/cloudfront/helpers/streaming_distribution.rb', line 14 def caller_reference @caller_reference end |
#cnames ⇒ Object
Returns the value of attribute cnames.
14 15 16 |
# File 'lib/cloudfront/helpers/streaming_distribution.rb', line 14 def cnames @cnames end |
#comment ⇒ Object
Returns the value of attribute comment.
14 15 16 |
# File 'lib/cloudfront/helpers/streaming_distribution.rb', line 14 def comment @comment end |
#domain_name ⇒ Object
Returns the value of attribute domain_name.
14 15 16 |
# File 'lib/cloudfront/helpers/streaming_distribution.rb', line 14 def domain_name @domain_name end |
#enabled ⇒ Object
Returns the value of attribute enabled.
14 15 16 |
# File 'lib/cloudfront/helpers/streaming_distribution.rb', line 14 def enabled @enabled end |
#logging ⇒ Object
Returns the value of attribute logging.
14 15 16 |
# File 'lib/cloudfront/helpers/streaming_distribution.rb', line 14 def logging @logging end |
#origin_access_identity ⇒ Object
Returns the value of attribute origin_access_identity.
14 15 16 |
# File 'lib/cloudfront/helpers/streaming_distribution.rb', line 14 def origin_access_identity @origin_access_identity end |
#price_class ⇒ Object
Returns the value of attribute price_class.
14 15 16 |
# File 'lib/cloudfront/helpers/streaming_distribution.rb', line 14 def price_class @price_class end |
#trusted_signers ⇒ Object
Returns the value of attribute trusted_signers.
14 15 16 |
# File 'lib/cloudfront/helpers/streaming_distribution.rb', line 14 def trusted_signers @trusted_signers end |
Class Method Details
.from_hash(hash) ⇒ Object
Creates a distribution configuration wrapper from a hash {
"StreamingDistributionConfig" => {
"CallerReference" => "unique description for this distribution",
"S3Origin" => {
... see s3Origin
},
"Aliases" => {
"Quantity" => "number of CNAME aliases",
"Items" => {
"CNAME" => "CNAME alias"
}
},
"Comment" => "comment about the distribution",
"Logging" => {
"Enabled" => "true | false",
"Bucket" => "Amazon S3 bucket for logs",
"Prefix" => "prefix for log file names"
},
"TrustedSigners" => {
"Quantity" => "number of trusted signers",
"Items" => {
"AwsAccountNumber" => "self | AWS account that can create \n signed URLs"
}
},
"PriceClass" => "maximum price class for the distribution",
"Enabled" => "true | false"
}
}
99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 |
# File 'lib/cloudfront/helpers/streaming_distribution.rb', line 99 def self.from_hash(hash) hash = hash["StreamingDistributionConfig"] || hash self.new do self.caller_reference = hash["CallerReference"] origin = S3Origin.from_hash(hash) self.domain_name = origin.domain_name self.origin_access_identity = origin.origin_access_identity self.cnames = Aliases.from_hash(hash).cnames # Aliases class contains the code that extract cnames self.comment = hash["Comment"] self.logging = Logging.from_hash(hash) self.trusted_signers = TrustedSigners.from_hash(hash).trusted_signers self.price_class = hash["PriceClass"] || "PriceClass_All" self.enabled = (hash["Enabled"] || "false").to_bool end end |
Instance Method Details
#build_xml(xml) ⇒ Object
<StreamingDistributionConfig xmlns=“cloudfront.amazonaws.com/doc/2012-07-01/”>
<CallerReference>unique description for this distribution</CallerReference>
<S3Origin>
<DNSName>CloudFront domain name assigned to the distribution</DNSName>
<OriginAccessIdentity>origin-access-identity/cloudfront/ID</OriginAccessIdentity>
</S3Origin>
<Aliases>
... see Aliases class
</Aliases>
<Comment>comment about the distribution</Comment>
<Logging>
... see Logging class.
</Logging>
<TrustedSigners>
... see TrustedSigners.
</TrustedSigners>
<PriceClass>maximum price class for the distribution</PriceClass>
<Enabled>true | false</Enabled>
</StreamingDistributionConfig>
134 135 136 137 138 139 140 141 142 143 144 145 146 |
# File 'lib/cloudfront/helpers/streaming_distribution.rb', line 134 def build_xml(xml) check_configuration xml.StreamingDistributionConfig('xmlns' => "http://cloudfront.amazonaws.com/doc/#{Cloudfront::Utils::Api.version}/") { xml.CallerReference @caller_reference @s3_origin.build_xml(xml) @aliases.build_xml(xml) xml.Comment @comment @logging.build_xml(xml) @trusted_signers_container.build_xml(xml) xml.PriceClass @price_class xml.Enabled @enabled } end |
#validate ⇒ Object
39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 |
# File 'lib/cloudfront/helpers/streaming_distribution.rb', line 39 def validate this = self # s3_origin, aliases and trusted_signers_container are internal structures. @s3_origin = S3Origin.new do self.domain_name = this.domain_name self.origin_access_identity = this.origin_access_identity end @aliases = Aliases.new do self.cnames = this.cnames end @trusted_signers_container = TrustedSigners.new do #self.enabled = true self.trusted_signers = this.trusted_signers end @logging. = "undefined" # Error checking .push "The caller_reference shouldn't be empty" if @caller_reference.empty? @s3_origin.check_configuration @aliases.check_configuration @logging.check_configuration @trusted_signers_container.check_configuration .push "price_class is invalid should be in #{Cloudfront::Utils::Util::PRICE_CLASS.join(', ')}" unless Cloudfront::Utils::Util::PRICE_CLASS.include?(@price_class) .push "enabled should be a boolean" unless !!@enabled == @enabled end |