diff options
author | Zara Gebru <zgebru@thoughtworks.com> | 2016-07-12 12:08:49 +0200 |
---|---|---|
committer | Zara Gebru <zgebru@thoughtworks.com> | 2016-07-12 12:08:49 +0200 |
commit | 67d5d8d5257e59155d4ce3a76ef4ec315b4b2994 (patch) | |
tree | db0e00a2fa1cf23dc4a7d8c387d6d99350c8cc5e /lib | |
parent | d7599715c6d24534dcccbe29cfc058e534039053 (diff) |
[refactor] encapsulate get key by email
in order to get key by fp as well
Diffstat (limited to 'lib')
-rw-r--r-- | lib/nickserver/request_handler.rb | 23 |
1 files changed, 14 insertions, 9 deletions
diff --git a/lib/nickserver/request_handler.rb b/lib/nickserver/request_handler.rb index 608db83..bc6d519 100644 --- a/lib/nickserver/request_handler.rb +++ b/lib/nickserver/request_handler.rb @@ -10,14 +10,14 @@ module Nickserver end def respond_to(params, headers) - email = get_email_from_params(params) - if email.nil? - send_not_found - elsif email.invalid? - send_error("Not a valid address") + if params && params["address"] && params["address"].any? + by_email(params, headers) + elsif params && params["fingerprint"] && params["fingerprint"].any? + # do something else else - send_key(email, headers) + send_not_found end + rescue RuntimeError => exc puts "Error: #{exc}" puts exc.backtrace @@ -26,12 +26,17 @@ module Nickserver protected - def get_email_from_params(params) - if params && params["address"] && params["address"].any? - EmailAddress.new(params["address"].first) + def by_email(params, headers) + email = EmailAddress.new(params["address"].first) + if email.invalid? + send_error("Not a valid address") + else + send_key(email, headers) end end + #def by_fingerprint(params) + def send_key(email, headers) if local_address?(email, headers) source = Nickserver::CouchDB::Source.new(adapter) |