Swiftpack.co - validationapp/swift-sdk as Swift Package

Swiftpack.co is a collection of thousands of indexed Swift packages. Search packages.
See all packages published by validationapp.
validationapp/swift-sdk 0.0.5
A Swift SDK for the validation.app service
⭐️ 3
🕓 2 years ago
macOS
.package(url: "https://github.com/validationapp/swift-sdk.git", from: "0.0.5")

Swift EmailValidation

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.

Installation:

To start using EmailValidation, in your Package.swift add the following

.package(url: "https://github.com/validationapp/swift-sdk.git", from: "0.0.1")

Usage:

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]")
}

Swiftpack is being maintained by Petr Pavlik | @ptrpavlik | @swiftpackco | API | Analytics