summaryrefslogtreecommitdiff
path: root/lib/nickserver/request_handlers/local_email_handler.rb
diff options
context:
space:
mode:
authorazul <azul@riseup.net>2016-08-29 10:19:22 +0000
committerazul <azul@riseup.net>2016-08-29 10:19:22 +0000
commit6e2d31e3f7c515f65d92533bcdb035438461a00c (patch)
tree4efa7445db3a0521a14d75e626d64f85434a3ea5 /lib/nickserver/request_handlers/local_email_handler.rb
parentc134e0940a44ba3fb3f0f8ee86faa8053a9e0b44 (diff)
parent0784391a21b75ca52892e992a614b0f927ade00e (diff)
Merge branch 'refactor/request-handling' into 'master'
refactor: restructure the way we handle requests to make it more consistent. Requests are handled at a lot of different ways in different styles right now. Let's make this more consistent and flexible to add email lookup at other leap providers. See merge request !2
Diffstat (limited to 'lib/nickserver/request_handlers/local_email_handler.rb')
-rw-r--r--lib/nickserver/request_handlers/local_email_handler.rb32
1 files changed, 32 insertions, 0 deletions
diff --git a/lib/nickserver/request_handlers/local_email_handler.rb b/lib/nickserver/request_handlers/local_email_handler.rb
new file mode 100644
index 0000000..1f2abc2
--- /dev/null
+++ b/lib/nickserver/request_handlers/local_email_handler.rb
@@ -0,0 +1,32 @@
+require 'nickserver/email_address'
+require 'nickserver/error_response'
+require 'nickserver/couch_db/source'
+
+module Nickserver
+ module RequestHandlers
+ class LocalEmailHandler
+
+ def call(request)
+ return nil unless request.email
+ domain = Config.domain || request.domain
+ return missing_domain_response if domain.nil? || domain == ''
+ email = EmailAddress.new(request.email)
+ return nil unless email.domain?(domain)
+ source.query email
+ end
+
+ protected
+
+ attr_reader :domain
+
+ def source
+ Nickserver::CouchDB::Source.new
+ end
+
+ def missing_domain_response
+ ErrorResponse.new "HTTP request must include a Host header."
+ end
+
+ end
+ end
+end