summaryrefslogtreecommitdiff
path: root/lib/nickserver
diff options
context:
space:
mode:
Diffstat (limited to 'lib/nickserver')
-rw-r--r--lib/nickserver/hkp/fetch_key.rb2
-rw-r--r--lib/nickserver/hkp/source.rb20
-rw-r--r--lib/nickserver/server.rb22
3 files changed, 27 insertions, 17 deletions
diff --git a/lib/nickserver/hkp/fetch_key.rb b/lib/nickserver/hkp/fetch_key.rb
index 55eeefa..fe00473 100644
--- a/lib/nickserver/hkp/fetch_key.rb
+++ b/lib/nickserver/hkp/fetch_key.rb
@@ -53,4 +53,4 @@ module Nickserver; module Hkp
end
end
-end; end \ No newline at end of file
+end; end
diff --git a/lib/nickserver/hkp/source.rb b/lib/nickserver/hkp/source.rb
new file mode 100644
index 0000000..79333f0
--- /dev/null
+++ b/lib/nickserver/hkp/source.rb
@@ -0,0 +1,20 @@
+require 'nickserver/hkp/response'
+module Nickserver::Hkp
+ class Source
+
+ def initialize(adapter)
+ end
+
+ def query(nick)
+ fetcher.get(nick).callback {|key|
+ yield Response.new(nick, key)
+ }.errback {|status, msg|
+ yield Nickserver::Response.new(status, msg)
+ }
+ end
+
+ def fetcher
+ Nickserver::Hkp::FetchKey.new
+ end
+ end
+end
diff --git a/lib/nickserver/server.rb b/lib/nickserver/server.rb
index c6615d2..2453f94 100644
--- a/lib/nickserver/server.rb
+++ b/lib/nickserver/server.rb
@@ -5,7 +5,7 @@ silence_warnings do
end
require 'json'
require 'nickserver/couch_db/source'
-require 'nickserver/hkp/response'
+require 'nickserver/hkp/source'
require 'nickserver/adapters/em_http'
@@ -91,22 +91,12 @@ module Nickserver
def send_key(uid)
if local_address?(uid)
- @source = Nickserver::CouchDB::Source.new(adapter)
- @source.query(uid) do |response|
- send_response(status: response.status, content: response.content)
- end
+ source = Nickserver::CouchDB::Source.new(adapter)
else
- @fetcher = Nickserver::Hkp::FetchKey.new
- @fetcher.get(uid).callback {|key|
- response = Nickserver::Hkp::Response.new(uid, key)
- send_response(status: response.status, content: response.content)
- }.errback {|status, msg|
- if status == 404
- send_not_found
- else
- send_response(status: status, content: msg)
- end
- }
+ source = Nickserver::Hkp::Source.new(adapter)
+ end
+ source.query(uid) do |response|
+ send_response(status: response.status, content: response.content)
end
end