blob: dd29c2a25f5738beb13caad59c5ab823dd70de43 (
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
31
32
33
34
35
36
37
38
39
40
|
#
# This class allows querying couch for public keys.
#
require 'nickserver/source'
require 'nickserver/couch_db/response'
require 'nickserver/config'
module Nickserver::CouchDB
class Error < StandardError; end
class Source < Nickserver::Source
VIEW = '/_design/Identity/_view/pgp_key_by_email'
UNEXPECTED_RESPONSE_CODES = [401, 500]
def query(nick)
status, body = adapter.get url, query: query_for(nick)
handle_unexpected_responses(status, body)
Response.new(nick, status: status, body: body)
end
protected
def handle_unexpected_responses(status, body)
if UNEXPECTED_RESPONSE_CODES.include? status
raise Error.new("Couch responded with #{status}: #{body}")
end
end
def url
Nickserver::Config.couch_url + VIEW
end
def query_for(nick)
{ reduce: "false", key: "\"#{nick}\"" }
end
attr_reader :config
end
end
|