This package is a client for the https://validation.app API. It allows you to submit an email for validation and receive the response from the API in a typed fashion.
Note: You must first have an API key and tokens available from the https://validation.app platform.
To start using EmailValidation, in your Package.swift add the following
.package(url: "https://github.com/validationapp/swift-sdk.git", from: "0.0.1")
Initialize the EmailValidator
:
let httpClient = HTTPClient(..)
let validator = EmailValidator(httpClient: httpClient, apiKey: "ADD_YOUR_API_KEY_HERE", eventLoop: eventLoop)
If you are in a Vapor app, you can do something like this:
extension Request {
var emailValidator: EmailValidator {
if self.application.environment == .testing {
return MockEmailValidator()
} else {
return EmailValidatorAPI(
httpClient: self.application.http.client.shared,
apiKey: "ADD_YOUR_API_KEY_HERE"
)
}
}
}
Once you have an EmailValidator
object, you can call .validate(email: "email-goes-here")
on it to get back a EmailValidationResponse
object:
let response = try await validator.validate(email: "[email protected]")
XCTAssertEqual(response.data.request_email, "[email protected]") // True
If you have the EmailValidator
installed as an extension in your Vapor app, you can use it in routes:
func myRoute(req: Request) async throws -> EmailValidationResponse {
try await req.emailValidator.validate(email: "[email protected]")
}
link |
Stars: 3 |
Last commit: 2 years ago |
Full Changelog: https://github.com/validationapp/swift-sdk/compare/0.0.4...0.0.5
Swiftpack is being maintained by Petr Pavlik | @ptrpavlik | @swiftpackco | API | Analytics