Class: SimpleCloudfrontInvalidator::CloudfrontClient

Inherits:
Object
  • Object
show all
Defined in:
lib/simple-cloudfront-invalidator.rb

Instance Method Summary collapse

Constructor Details

#initialize(aws_account, aws_secret, distribution) ⇒ CloudfrontClient

Returns a new instance of CloudfrontClient.



10
11
12
13
14
# File 'lib/simple-cloudfront-invalidator.rb', line 10

def initialize(, aws_secret, distribution)
  @aws_account = 
  @aws_secret = aws_secret
  @distribution = distribution
end

Instance Method Details

#invalidate(items) ⇒ Object



16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
# File 'lib/simple-cloudfront-invalidator.rb', line 16

def invalidate(items)
  items = prefix_with_slash(items)
  body = %|
    <InvalidationBatch>
      <Paths>
        <Quantity>#{items.length}</Quantity>
        <Items>
          #{to_xml items}
        </Items>
      </Paths>
      <CallerReference>#{Time.now.utc.to_i}</CallerReference>
    </InvalidationBatch>
  |
  res = sign_and_call(
    "https://cloudfront.amazonaws.com/2012-05-05/distribution/#{@distribution}/invalidation",
    Net::HTTP::Post, body)
  return { :text_report => create_report(items),
           :invalidated_items_count => items.length }
end