Class: AkamaiPurger

Inherits:
Object
  • Object
show all
Defined in:
lib/akamai_purger.rb

Constant Summary collapse

WSDL_URL =
"https://ccuapi.akamai.com/ccuapi-axis.wsdl"

Instance Method Summary collapse

Constructor Details

#initialize(args) ⇒ AkamaiPurger

Returns a new instance of AkamaiPurger.



9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
# File 'lib/akamai_purger.rb', line 9

def initialize(args)
  opts = OptionParser.new do |opts|
    opts.banner = "Usage: #{File.basename($0)} [options]"

    opts.on('-h', '--help', 'Show this message') do
      puts opts
      exit 1
    end
    
    opts.on('-u', '--user [USER]', 'Specifies the Akamai username to connect as.') do |user|
      @username = user
    end
    
    opts.on('-p', '--password [PASSWORD]', "Specifies the password for the Akamai user.") do |pass|
      @password = pass
    end
    
    opts.on('-l', '--url [URL]', "Specifies the URL to purge.") do |url|
      @url = url
    end
    
    
  end
  
  @args = opts.parse!(args)
end

Instance Method Details

#runObject



36
37
38
39
40
41
42
43
44
45
46
# File 'lib/akamai_purger.rb', line 36

def run
  
  puts "User, password, and URL must be supplied!" unless @username && @password && @url
  
  puts "Sending purge request for #{@url}."
  driver = SOAP::WSDLDriverFactory.new(WSDL_URL).create_rpc_driver
  driver.options["protocol.http.basic_auth"] << [WSDL_URL, @username, @password]
  result = driver.purgeRequest(@username, @password, '', [], @url)
  
  puts "Purge request #{ result.resultCode == '100' ? 'was successful' : 'failed' }."
end