Sha256: 567508cdaa898d1f0fab8c9a5862bba4a379e8a9b061b49291a61fd86ab93ecc

Contents?: true

Size: 1.81 KB

Versions: 2

Compression:

Stored size: 1.81 KB

Contents

require 'fog/rackspace/client'

module Fog
  module CDN
    class Rackspace
      class Real
        # Purges CDN Edge Cache for all objects inside of this container
        # 
        # :email, An valid email address or comma seperated 
        # list of emails to be notified once purge is complete .
        #
        #    obj.purge_from_cdn
        #    => true
        #
        #  or 
        #                                     
        #   obj.purge_from_cdn("User@domain.com")
        #   => true
        #                                                
        #  or
        #                                                         
        #   obj.purge_from_cdn("User@domain.com, User2@domain.com")
        #   => true
        def purge_from_cdn(distribution_id, name, email=nil)
#          raise Exception::CDNNotAvailable unless cdn_available?
          auth_token = self.instance_variable_get("@auth_token")
          path       = self.instance_variable_get("@path")
          host       = self.instance_variable_get("@host")
          scheme     = self.
                      instance_variable_get("@connection").
                      instance_variable_get("@excon").
                      instance_variable_get("@connection")[:scheme]
          headers = {}
          headers = {"X-Purge-Email" => email} if email
          url = scheme + "://" + host + path
          begin
            SwiftClient.delete_object(url, auth_token, distribution_id, name, nil, {})
            true
          rescue ClientException => e
            raise StandardError, "Error Unable to Purge Object: #{@name}" unless (e.status.to_s =~ /^20.$/)
            false
          end
        end

        private
          def cdn_available?
            @cdn_available ||= self.container.connection.cdn_available?
          end
      end
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
fog_tractical-1.1.4 lib/fog/rackspace/requests/cdn/purge.rb
fog_tractical-1.1.3 lib/fog/rackspace/requests/cdn/purge.rb