Skip to content

Commit

Permalink
Extract configuration/connection/errors into their own files
Browse files Browse the repository at this point in the history
  • Loading branch information
jayzes committed Jan 31, 2012
1 parent 9f97dfc commit f986025
Show file tree
Hide file tree
Showing 4 changed files with 70 additions and 52 deletions.
56 changes: 4 additions & 52 deletions lib/akamai.rb
Original file line number Original file line Diff line number Diff line change
@@ -1,7 +1,11 @@
require 'tempfile' require 'tempfile'
require 'net/ftp' require 'net/ftp'
require 'soap/wsdlDriver' require 'soap/wsdlDriver'

require 'akamai/version' require 'akamai/version'
require 'akamai/errors'
require 'akamai/configuration'
require 'akamai/connection'


module Akamai module Akamai
class << self class << self
Expand All @@ -18,58 +22,6 @@ def self.connection
@connection ||= Connection.new(configuration) @connection ||= Connection.new(configuration)
end end


class Configuration
attr_accessor :cachecontrol_username,
:cachecontrol_password,
:cachecontrol_domain,
:cachecontrol_purge_action,
:netstorage_username,
:netstorage_password,
:netstorage_ftp_host,
:netstorage_public_host,
:netstorage_basedir,
:wsdl_url

def initialize(args = {})
self.wsdl_url = 'http://ccuapi.akamai.com/ccuapi-axis.wsdl'
self.cachecontrol_domain = "production"
self.cachecontrol_purge_action = "remove"

for key, val in args
send("#{key}=".to_sym, val)
end
end

end

class Connection
attr_accessor :config

def initialize(args = {})
@config = args.kind_of?(Configuration) ? args : Configuration.new(args)
end

def driver
return @driver if @driver

@driver = SOAP::WSDLDriverFactory.new(config.wsdl_url).create_rpc_driver
@driver.options['protocol.http.ssl_config.verify_mode'] = OpenSSL::SSL::VERIFY_NONE
@driver.options["protocol.http.basic_auth"] << [config.wsdl_url, config.cachecontrol_username, config.cachecontrol_password]
@driver
end

def purge(*urls)
result = driver.purgeRequest(config.cachecontrol_username, config.cachecontrol_password, '', ["domain=#{config.cachecontrol_domain}", "action=#{config.cachecontrol_purge_action}"], urls)
raise PurgeError, result.inspect unless result.resultCode == '100'
true
end

class Error < StandardError
end
class PurgeError < StandardError
end
end

def self.purge(*urls) def self.purge(*urls)
connection.purge(*urls) connection.purge(*urls)
end end
Expand Down
29 changes: 29 additions & 0 deletions lib/akamai/configuration.rb
Original file line number Original file line Diff line number Diff line change
@@ -0,0 +1,29 @@
module Akamai

class Configuration

attr_accessor :cachecontrol_username,
:cachecontrol_password,
:cachecontrol_domain,
:cachecontrol_purge_action,
:netstorage_username,
:netstorage_password,
:netstorage_ftp_host,
:netstorage_public_host,
:netstorage_basedir,
:wsdl_url

def initialize(args = {})
self.wsdl_url = 'http://ccuapi.akamai.com/ccuapi-axis.wsdl'
self.cachecontrol_domain = "production"
self.cachecontrol_purge_action = "remove"

for key, val in args
send("#{key}=".to_sym, val)
end

end

end

end
28 changes: 28 additions & 0 deletions lib/akamai/connection.rb
Original file line number Original file line Diff line number Diff line change
@@ -0,0 +1,28 @@
module Akamai

class Connection

attr_accessor :config

def initialize(args = {})
@config = args.kind_of?(Configuration) ? args : Configuration.new(args)
end

def driver
return @driver if @driver

@driver = SOAP::WSDLDriverFactory.new(config.wsdl_url).create_rpc_driver
@driver.options['protocol.http.ssl_config.verify_mode'] = OpenSSL::SSL::VERIFY_NONE
@driver.options["protocol.http.basic_auth"] << [config.wsdl_url, config.cachecontrol_username, config.cachecontrol_password]
@driver
end

def purge(*urls)
result = driver.purgeRequest(config.cachecontrol_username, config.cachecontrol_password, '', ["domain=#{config.cachecontrol_domain}", "action=#{config.cachecontrol_purge_action}"], urls)
raise PurgeError, result.inspect unless result.resultCode == '100'
true
end

end

end
9 changes: 9 additions & 0 deletions lib/akamai/errors.rb
Original file line number Original file line Diff line number Diff line change
@@ -0,0 +1,9 @@
module Akamai

class Error < StandardError
end

class PurgeError < StandardError
end

end

0 comments on commit f986025

Please sign in to comment.