From e81c1a8cf274a13903be00c74c975c0cb2c20995 Mon Sep 17 00:00:00 2001 From: Azul Date: Sat, 2 Jul 2016 13:16:35 +0200 Subject: refactor: turn EmailAddress into a class, cleanup --- lib/nickserver/hkp/client.rb | 5 +++-- lib/nickserver/hkp/parse_key_info.rb | 10 ++++++---- 2 files changed, 9 insertions(+), 6 deletions(-) (limited to 'lib/nickserver/hkp') diff --git a/lib/nickserver/hkp/client.rb b/lib/nickserver/hkp/client.rb index d9a9b48..1fbe7a2 100644 --- a/lib/nickserver/hkp/client.rb +++ b/lib/nickserver/hkp/client.rb @@ -21,7 +21,7 @@ module Nickserver; module Hkp # used to fetch an array of KeyInfo objects that match the given email # def get_key_infos_by_email(email, &block) - get op: 'vindex', search: email, fingerprint: 'on' + get op: 'vindex', search: email.to_s, fingerprint: 'on' end # @@ -38,7 +38,8 @@ module Nickserver; module Hkp def get(query) # in practice, exact=on seems to have no effect query = {exact: 'on', options: 'mr'}.merge query - adapter.get Config.hkp_url, query: query + response = adapter.get Config.hkp_url, query: query + return response end end end; end diff --git a/lib/nickserver/hkp/parse_key_info.rb b/lib/nickserver/hkp/parse_key_info.rb index 9d59d6b..2f928a0 100644 --- a/lib/nickserver/hkp/parse_key_info.rb +++ b/lib/nickserver/hkp/parse_key_info.rb @@ -19,7 +19,8 @@ module Nickserver; module Hkp @vindex_result = vindex_result end - def status_for(uid) + def status_for(email) + uid = email.to_s if hkp_ok? && keys(uid).empty? error_status(uid) else @@ -27,7 +28,8 @@ module Nickserver; module Hkp end end - def response_for(uid) + def response_for(email) + uid = email.to_s if keys(uid).any? keys(uid) else @@ -35,6 +37,8 @@ module Nickserver; module Hkp end end + protected + def keys(uid) key_infos(uid).reject { |key| error_for_key(key) } end @@ -47,8 +51,6 @@ module Nickserver; module Hkp end end - protected - attr_reader :status attr_reader :vindex_result -- cgit v1.2.3