summaryrefslogtreecommitdiff
path: root/lib/nickserver/nicknym
diff options
context:
space:
mode:
authorAzul <azul@riseup.net>2016-09-13 16:45:28 +0200
committerAzul <azul@riseup.net>2016-09-16 12:12:34 +0200
commitf5bf2c6554f0e541c75d90fdcf4f0095e9801d4d (patch)
tree9ec4a4af2a3dcae4beccb3eb2a32856a69529c20 /lib/nickserver/nicknym
parentec875169b0231d84bb8c55bbe91c52b896561f1e (diff)
test: properly test nicknym source + fixes
Diffstat (limited to 'lib/nickserver/nicknym')
-rw-r--r--lib/nickserver/nicknym/source.rb20
1 files changed, 14 insertions, 6 deletions
diff --git a/lib/nickserver/nicknym/source.rb b/lib/nickserver/nicknym/source.rb
index 0776a36..45daeaf 100644
--- a/lib/nickserver/nicknym/source.rb
+++ b/lib/nickserver/nicknym/source.rb
@@ -6,20 +6,28 @@ module Nickserver
class Source < Nickserver::Source
def available_for?(domain)
- status, _body = get "#{domain}/provider.json"
- status == 200
+ status, body = adapter.get "https://#{domain}/provider.json"
+ status == 200 && provider_with_mx?(body)
end
def query(email)
- status, body = get "nicknym.#{email.domain}", address: email.to_s
+ status, body = nicknym_get 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)
+ def nicknym_get(domain, query = {})
+ url = "https://nicknym.#{domain}:#{Config.port}"
+ adapter.get(url, query: query)
+ end
+
+ def provider_with_mx?(provider_json)
+ provider = JSON.parse provider_json
+ services = provider['services'] || []
+ services.include?('mx')
+ rescue JSON::ParserError
+ return false
end
end
end