summaryrefslogtreecommitdiff
path: root/lib/nickserver/hkp/fetch_key_info.rb
diff options
context:
space:
mode:
authorAzul <azul@riseup.net>2016-06-11 15:19:50 +0200
committerAzul <azul@riseup.net>2016-06-14 10:36:58 +0200
commitf567ed80427d43019ceb1aaf77d4bc6c01e62729 (patch)
tree8698f379be2d0706e19b72134019a0aa044f132d /lib/nickserver/hkp/fetch_key_info.rb
parent92c86fc4e1e6dcb86793992e69dfd0608c118c9a (diff)
use adapter for FetchKeyInfo
Diffstat (limited to 'lib/nickserver/hkp/fetch_key_info.rb')
-rw-r--r--lib/nickserver/hkp/fetch_key_info.rb28
1 files changed, 12 insertions, 16 deletions
diff --git a/lib/nickserver/hkp/fetch_key_info.rb b/lib/nickserver/hkp/fetch_key_info.rb
index b7481d0..b23af15 100644
--- a/lib/nickserver/hkp/fetch_key_info.rb
+++ b/lib/nickserver/hkp/fetch_key_info.rb
@@ -1,30 +1,26 @@
-require 'em-http'
-
#
# used to fetch an array of KeyInfo objects that match the given uid.
#
module Nickserver; module Hkp
class FetchKeyInfo
- include EM::Deferrable
- def search(uid)
+ def initialize(adapter)
+ @adapter = adapter
+ end
+
+ def search(uid, &block)
# in practice, exact=on seems to have no effect
params = {op: 'vindex', search: uid, exact: 'on', options: 'mr', fingerprint: 'on'}
- EventMachine::HttpRequest.new(Config.hkp_url).get(query: params).callback {|http|
- parser = ParseKeyInfo.new http.response_header, http.response
- keys = parser.keys(uid)
- if keys.any?
- self.succeed keys
- else
- self.fail parser.status(uid), parser.msg(uid)
- end
- }.errback {|http|
- self.fail 500, http.error
- }
- self
+ adapter.get(Config.hkp_url, query: params) do |status, response|
+ parser = ParseKeyInfo.new status, response
+ yield parser.status_for(uid), parser.response_for(uid)
+ end
end
+ protected
+ attr_reader :adapter
+
end
end; end