diff options
-rw-r--r-- | lib/nickserver/reel_server.rb | 2 | ||||
-rw-r--r-- | lib/nickserver/request_handler.rb | 28 | ||||
-rw-r--r-- | lib/nickserver/source.rb | 3 | ||||
-rw-r--r-- | test/unit/request_handler_test.rb | 5 |
4 files changed, 10 insertions, 28 deletions
diff --git a/lib/nickserver/reel_server.rb b/lib/nickserver/reel_server.rb index 6f05e0b..549b738 100644 --- a/lib/nickserver/reel_server.rb +++ b/lib/nickserver/reel_server.rb @@ -32,7 +32,7 @@ module Nickserver protected def handler_for(request) - RequestHandler.new(request, Nickserver::Adapters::CelluloidHttp.new) + RequestHandler.new(request) end def params(request) diff --git a/lib/nickserver/request_handler.rb b/lib/nickserver/request_handler.rb index da9bcb3..239ac5f 100644 --- a/lib/nickserver/request_handler.rb +++ b/lib/nickserver/request_handler.rb @@ -33,9 +33,8 @@ module Nickserver attr_reader :params, :headers end - def initialize(responder, adapter) + def initialize(responder) @responder = responder - @adapter = adapter end def respond_to(params, headers) @@ -57,9 +56,9 @@ module Nickserver def handler_for_request(request) if request.email - EmailHandler.new adapter + EmailHandler.new elsif request.fingerprint - FingerprintHandler.new adapter + FingerprintHandler.new else Proc.new { Nickserver::Response.new(404, "Not Found\n") } end @@ -67,10 +66,6 @@ module Nickserver class EmailHandler - def initialize(adapter) - @adapter = adapter - end - def call(request) email = EmailAddress.new(request.email) if email.invalid? @@ -84,9 +79,9 @@ module Nickserver def send_key(email, request) if local_address?(email, request) - source = Nickserver::CouchDB::Source.new(adapter) + source = Nickserver::CouchDB::Source.new else - source = Nickserver::Hkp::Source.new(adapter) + source = Nickserver::Hkp::Source.new end source.query(email) rescue MissingHostHeader @@ -102,29 +97,20 @@ module Nickserver def local_address?(email, request) email.domain?(Config.domain || request.domain) end - - attr_reader :adapter end class FingerprintHandler - def initialize(adapter) - @adapter = adapter - end - def call(request) fingerprint = request.fingerprint if fingerprint.length == 40 && !fingerprint[/\H/] - source = Nickserver::Hkp::Source.new(adapter) + source = Nickserver::Hkp::Source.new source.get_key_by_fingerprint(fingerprint) else ErrorResponse.new('Fingerprint invalid: ' + fingerprint) end end - protected - - attr_reader :adapter end class ErrorResponse < Nickserver::Response @@ -138,7 +124,7 @@ module Nickserver responder.respond status, content end - attr_reader :responder, :adapter + attr_reader :responder class MissingHostHeader < StandardError end diff --git a/lib/nickserver/source.rb b/lib/nickserver/source.rb index b8135da..78f245b 100644 --- a/lib/nickserver/source.rb +++ b/lib/nickserver/source.rb @@ -1,13 +1,12 @@ module Nickserver class Source - def initialize(adapter) + def initialize(adapter = Nickserver::Adapters::CelluloidHttp.new) @adapter = adapter end protected attr_reader :adapter - end end diff --git a/test/unit/request_handler_test.rb b/test/unit/request_handler_test.rb index 6c7a036..d938706 100644 --- a/test/unit/request_handler_test.rb +++ b/test/unit/request_handler_test.rb @@ -63,14 +63,11 @@ class Nickserver::RequestHandlerTest < Minitest::Test end def handler - Nickserver::RequestHandler.new responder, adapter + Nickserver::RequestHandler.new responder end def responder @responder ||= Minitest::Mock.new end - def adapter - @adapter ||= Minitest::Mock.new - end end |