24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
|
# File 'lib/mailchecker.rb', line 24
def self.validate_email email
params = { email: email, token: Mailchecker.token, domain: Mailchecker.domain, format: :json }
uri = URI.parse Mailchecker.url + "?" + params.to_param
http = Net::HTTP.new uri.host, uri.port
request = Net::HTTP::Get.new uri.request_uri
response = http.request request
case response.code.to_i
when 200
nil
when 422
I18n.t :wrong_format, scope: [:mailchecker, :errors, :messages], default: 'the format is not valid ([email protected])'
when 502
I18n.t :wrong_gateway, scope: [:mailchecker, :errors, :messages], default: 'the domain is not responding'
when 406
I18n.t :temporary_email, scope: [:mailchecker, :errors, :messages], default: 'this kind of email is not valid (temporary email)'
when 400
raise "Some parameters are missing... did you add the right token in the init file or the domain is valid?"
else
raise "Please report this issue (probably a lack of a new functionality), the status code is #{response.code}"
end
end
|