diff options
author | Azul <azul@riseup.net> | 2016-09-12 11:42:02 +0200 |
---|---|---|
committer | Azul <azul@riseup.net> | 2016-09-12 11:42:02 +0200 |
commit | ce09dd9c21d79e2260f9436e41f9970b42935b27 (patch) | |
tree | f620f8bf3d7386d8a5a48b1feb0a18c58269c128 /lib | |
parent | f18d698d09afda894a568de79c5770704a0c9de7 (diff) |
[wip] nicknym source query implemented
Also changed Nickserver::Response to not include the status code.
This may be okay for error responses but in most cases we want to
have a parsable message and not some status code prepended to it.
Diffstat (limited to 'lib')
-rw-r--r-- | lib/nickserver/dispatcher.rb | 8 | ||||
-rw-r--r-- | lib/nickserver/error_response.rb | 7 | ||||
-rw-r--r-- | lib/nickserver/nicknym/source.rb | 14 | ||||
-rw-r--r-- | lib/nickserver/response.rb | 8 |
4 files changed, 28 insertions, 9 deletions
diff --git a/lib/nickserver/dispatcher.rb b/lib/nickserver/dispatcher.rb index 9a031ab..7a584e5 100644 --- a/lib/nickserver/dispatcher.rb +++ b/lib/nickserver/dispatcher.rb @@ -29,7 +29,7 @@ module Nickserver def respond_to(params, headers) request = Nickserver::Request.new params, headers response = handle request - send_response response.status, response.content + send_response response end protected @@ -51,12 +51,12 @@ module Nickserver RequestHandlers::LocalEmailHandler, RequestHandlers::HkpEmailHandler, RequestHandlers::FingerprintHandler, - Proc.new { Nickserver::Response.new(404, "Not Found\n") } + Proc.new { Nickserver::Response.new(404, "404 Not Found\n") } ] end - def send_response(status = 200, content = '') - responder.respond status, content + def send_response(response) + responder.respond response.status, response.content end attr_reader :responder diff --git a/lib/nickserver/error_response.rb b/lib/nickserver/error_response.rb index 1065e4e..9d53630 100644 --- a/lib/nickserver/error_response.rb +++ b/lib/nickserver/error_response.rb @@ -7,5 +7,12 @@ module Nickserver @message = message + "\n" end + def content + "#{status} #{message}" + end + + protected + + attr_reader :message end end diff --git a/lib/nickserver/nicknym/source.rb b/lib/nickserver/nicknym/source.rb index 1be0c2a..3957cdd 100644 --- a/lib/nickserver/nicknym/source.rb +++ b/lib/nickserver/nicknym/source.rb @@ -1,14 +1,26 @@ require 'nickserver/source' +require 'nickserver/response' module Nickserver module Nicknym class Source < Nickserver::Source def available_for?(domain) - status, _body = adapter.get "https://#{domain}/provider.json" + status, _body = get "#{domain}/provider.json" status == 200 end + def query(email) + status, body = get "nicknym.#{email.domain}", address: email.to_s + return Nickserver::Response.new(status, body) + end + + protected + + def get(*args) + args[0] = "https://#{args.first}" + adapter.get *args + end end end end diff --git a/lib/nickserver/response.rb b/lib/nickserver/response.rb index c55d359..372da36 100644 --- a/lib/nickserver/response.rb +++ b/lib/nickserver/response.rb @@ -1,15 +1,15 @@ module Nickserver class Response - attr_reader :status, :message + attr_reader :status, :body - def initialize(status, message) + def initialize(status, body) @status = status - @message = message + @body = body end def content - "#{status} #{message}" + body end end end |