Class: Ipecache::Plugins::MaxCDN

Inherits:
Plugin
  • Object
show all
Defined in:
lib/ipecache/plugins/maxcdn.rb

Instance Method Summary collapse

Methods inherited from Plugin

#continue_on_error, #enabled?, hook, hooks, #initialize, #log_file, name, #name, #plugin_puts, #plugin_puts_error, #quiet_mode, #urls

Constructor Details

This class inherits a constructor from Ipecache::Plugins::Plugin

Instance Method Details

#performObject



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
35
36
37
38
39
40
41
# File 'lib/ipecache/plugins/maxcdn.rb', line 9

def perform
  safe_require 'maxcdn'

  [ :alias, :token, :secret, :zone ].each do |key|
    confirm!(key)
  end

  zone = config.zone.to_i

  plugin_puts "Beginning URL Purge from MaxCDN..."

  api = ::MaxCDN::Client.new(config.alias, config.token, config.secret)

  urls.each do |u|
    url = u.chomp
    plugin_puts ("Purging #{url}")

    begin
      response = api.purge(zone, url)

      if response["code"] != 200
        plugin_puts_error(url, "Response Code: #{response["code"]}")
        plugin_puts_error(url, response.to_s)
        exit 1 unless continue_on_error
      else
        plugin_puts "Purge successful!"
      end
    rescue MaxCDN::APIException => e
      plugin_puts_error(url, "Response: #{e}")
      exit 1 unless continue_on_error
    end
  end
end