summaryrefslogtreecommitdiff
path: root/lib/nickserver/hkp/fetch_key_info.rb
blob: b7481d02dff16f00e6aa6263f51c4aabcad0ca4e (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
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)
      # 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
    end

  end

end; end