diff options
Diffstat (limited to 'lib')
-rw-r--r-- | lib/nickserver/hkp/response.rb | 18 | ||||
-rw-r--r-- | lib/nickserver/server.rb | 8 |
2 files changed, 21 insertions, 5 deletions
diff --git a/lib/nickserver/hkp/response.rb b/lib/nickserver/hkp/response.rb new file mode 100644 index 0000000..c52e25f --- /dev/null +++ b/lib/nickserver/hkp/response.rb @@ -0,0 +1,18 @@ +module Nickserver::Hkp + class Response + + attr_reader :status, :content + + def initialize(uid, key) + @content = format_response(address: uid, openpgp: key) + @status = 200 + end + + protected + + def format_response(map) + map.to_json + end + + end +end diff --git a/lib/nickserver/server.rb b/lib/nickserver/server.rb index 82fb376..c6615d2 100644 --- a/lib/nickserver/server.rb +++ b/lib/nickserver/server.rb @@ -5,6 +5,7 @@ silence_warnings do end require 'json' require 'nickserver/couch_db/source' +require 'nickserver/hkp/response' require 'nickserver/adapters/em_http' @@ -97,7 +98,8 @@ module Nickserver else @fetcher = Nickserver::Hkp::FetchKey.new @fetcher.get(uid).callback {|key| - send_response content: format_response(address: uid, openpgp: 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 @@ -108,10 +110,6 @@ module Nickserver end end - def format_response(map) - map.to_json - end - # # Return true if the user address is for a user of this service provider. # e.g. if the provider is example.org, then alice@example.org returns true. |