diff options
author | Azul <azul@riseup.net> | 2016-08-30 12:38:43 +0200 |
---|---|---|
committer | Azul <azul@riseup.net> | 2016-08-31 12:14:52 +0200 |
commit | 625416ac16a1216240fc4c48aa19802ef8a967a1 (patch) | |
tree | f3a4a54627fcae49bf896f5f58e60b506f9a55d4 /lib/nickserver | |
parent | b22e23eb9f5a1cb3e37ab2a26b1091183574f4e4 (diff) |
wip: key lookup by address via leaps nicknym
I added a RequestHandler that uses Nicknym::Source - but that has not
been implemented yet.
Diffstat (limited to 'lib/nickserver')
-rw-r--r-- | lib/nickserver/email_address.rb | 6 | ||||
-rw-r--r-- | lib/nickserver/nicknym/source.rb | 14 | ||||
-rw-r--r-- | lib/nickserver/request_handlers/leap_email_handler.rb | 36 |
3 files changed, 55 insertions, 1 deletions
diff --git a/lib/nickserver/email_address.rb b/lib/nickserver/email_address.rb index 2b3f2c2..c5d5df7 100644 --- a/lib/nickserver/email_address.rb +++ b/lib/nickserver/email_address.rb @@ -30,7 +30,11 @@ module Nickserver end def domain?(domain) - address.end_with? "@#{domain}" + domain == self.domain + end + + def domain + address.split('@')[1] end def to_s diff --git a/lib/nickserver/nicknym/source.rb b/lib/nickserver/nicknym/source.rb new file mode 100644 index 0000000..1be0c2a --- /dev/null +++ b/lib/nickserver/nicknym/source.rb @@ -0,0 +1,14 @@ +require 'nickserver/source' + +module Nickserver + module Nicknym + class Source < Nickserver::Source + + def available_for?(domain) + status, _body = adapter.get "https://#{domain}/provider.json" + status == 200 + end + + end + end +end diff --git a/lib/nickserver/request_handlers/leap_email_handler.rb b/lib/nickserver/request_handlers/leap_email_handler.rb new file mode 100644 index 0000000..548bc8a --- /dev/null +++ b/lib/nickserver/request_handlers/leap_email_handler.rb @@ -0,0 +1,36 @@ +require 'nickserver/email_address' +require 'nickserver/nicknym/source' + +module Nickserver + module RequestHandlers + class LeapEmailHandler < Base + + def handle + source.query(email) if request.email && remote_email? && nicknym_email? + end + + protected + + def source + @source ||= Nicknym::Source.new + end + + def remote_email? + !email.domain?(domain) + end + + def nicknym_email? + source.available_for?(email.domain) + end + + def email + @email ||= EmailAddress.new(request.email) + end + + def domain + Config.domain || request.domain + end + + end + end +end |