summaryrefslogtreecommitdiff
path: root/lib/nickserver/couch_db/source.rb
blob: b30fdfc5a28ad1568636093e58efd337717081c2 (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
#
# This class allows querying couch for public keys.
#
require 'nickserver/source'
require 'nickserver/couch_db/response'
require 'nickserver/config'

module Nickserver::CouchDB
  class Source < Nickserver::Source

    VIEW = '/_design/Identity/_view/pgp_key_by_email'

    def query(nick)
      adapter.get url, query: query_for(nick) do |status, body|
        yield Response.new(nick, status: status, body: body)
      end
    end

    protected

    def url
      Nickserver::Config.couch_url + VIEW
    end

    def query_for(nick)
      { reduce: "false", key: "\"#{nick}\"" }
    end

    attr_reader :config
  end
end