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

module Nickserver::CouchDB
  class Source

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

    def initialize(adapter)
      @adapter = adapter
    end

    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

    def adapter
      @adapter
      # Nickserver::Adapters::Http.new(config)
    end

    attr_reader :config
  end
end