This SDK contains methods for interacting easily with ZeroBounce API. More information about ZeroBounce you can find in the official documentation.
Add the pod to your Podfile
pod 'ZeroBounceSDK'
and run
pod install
Import the SDK in your file:
import ZeroBounceSDK
Initialize the SDK with your api key:
ZeroBounceSDK.shared.initialize(apiKey: "<YOUR_API_KEY>")
Then you can use any of the SDK methods, for example:
let email = "<EMAIL_ADDRESS>" // The email address you want to validate
let ipAddress = "127.0.0.1" // The IP Address the email signed up from (Optional)
ZeroBounceSDK.shared.validate(email: email, ipAddress: ipAddress) { result in
switch result {
case .Success(let response):
NSLog("validate success response=\(response)")
case .Failure(let error):
NSLog("validate failure error=\(String(describing: error))")
switch error as? ZBError {
case ZBError.notInitialized:
break
case ZBError.decodeError(let messages):
/// decodeError is used to extract and decode errors and messages
/// when they are not part of the response object
break
default:
break
}
}
}
// The email addresses you want to validate
let emails = [
["email_address": "<EMAIL_ADDRESS_1>"],
["email_address": "<EMAIL_ADDRESS_2>", "ip_address": "127.0.0.1"]
]
ZeroBounceSDK.shared.validateBatch(emails: emails) { result in
switch result {
case .Success(let response):
NSLog("validate success response=\(response)")
case .Failure(let error):
NSLog("validate failure error=\(String(describing: error))")
}
}
let domain = "<DOMAIN_NAME>" // The domain name for which to find the email format
let firstName = "<FIRST_NAME>" // The first name whose email format is being searched (Optional)
let middleName = "<MIDDLE_NAME>" // The middle name whose email format is being searched (Optional)
let lastName = "<LAST_NAME>" // The last name whose email format is being searched (Optional)
ZeroBounceSDK.shared.guessFormat(
domain: domain,
firstName: firstName,
middleName: middleName,
lastName: lastName
) { result in
switch result {
case .Success(let response):
NSLog("guessFormat success response=\(response)")
case .Failure(let error):
NSLog("guessFormat failure error=\(String(describing: error))")
}
}
ZeroBounceSDK.shared.getCredits() { result in
switch result {
case .Success(let response):
NSLog("getCredits success response=\(response)")
let credits = response.credits
case .Failure(let error):
NSLog("getCredits failure error=\(String(describing: error))")
}
}
let email = "<EMAIL_ADDRESS>" // The email address you want to check
ZeroBounceSDK.shared.getActivityData(email: email) { result in
switch result {
case .Success(let response):
NSLog("getActivityData success response=\(response)")
case .Failure(let error):
NSLog("getActivityData failure error=\(String(describing: error))")
}
}
let startDate = Date(); // The start date of when you want to view API usage
let endDate = Date(); // The end date of when you want to view API usage
ZeroBounceSDK.shared.getApiUsage(startDate: startDate, endDate: endDate) { result in
switch result {
case .Success(let response):
NSLog("getApiUsage success response=\(response)")
case .Failure(let error):
NSLog("getApiUsage failure error=\(String(describing: error))")
}
}
let filePath = File("<FILE_PATH>"); // The csv or txt file
let emailAddressColumn = 3; // The index of "email" column in the file. Index starts at 1
let firstNameColumn = 3; // The index of "first name" column in the file
let lastNameColumn = 3; // The index of "last name" column in the file
let genderColumn = 3; // The index of "gender" column in the file
let ipAddressColumn = 3; // The index of "IP address" column in the file
let hasHeaderRow = true; // If this is `true` the first row is considered as table headers
let returnUrl = "https://domain.com/called/after/processing/request";
ZeroBounceSDK.shared.sendFile(
filePath: filePath,
emailAddressColumn: emailAddressColumn,
returnUrl: returnUrl,
firstNameColumn: firstNameColumn,
lastNameColumn: lastNameColumn,
genderColumn: genderColumn,
ipAddressColumn: ipAddressColumn,
hasHeaderRow: hasHeaderRow
) { result in
switch result {
case .Success(let response):
NSLog("sendFile success response=\(response)")
case .Failure(let error):
NSLog("sendFile failure error=\(String(describing: error))")
}
}
let fileId = "<FILE_ID>"; // The returned file ID when calling sendfile API
ZeroBounceSDK.shared.getfile(fileId: fileId) { result in
switch result {
case .Success(let response):
NSLog("getfile success response=\(response)")
case .Failure(let error):
NSLog("getfile failure error=\(String(describing: error))")
}
}
let fileId = "<FILE_ID>"; // The returned file ID when calling sendfile API
ZeroBounceSDK.shared.fileStatus(fileId: fileId) { result in
switch result {
case .Success(let response):
NSLog("fileStatus success response=\(response)")
case .Failure(let error):
NSLog("fileStatus failure error=\(String(describing: error))")
}
}
let fileId = "<FILE_ID>"; // The returned file ID when calling sendfile API
ZeroBounceSDK.shared.deleteFile(fileId: fileId) { result in
switch result {
case .Success(let response):
NSLog("deleteFile success response=\(response)")
case .Failure(let error):
NSLog("deleteFile failure error=\(String(describing: error))")
}
}
let filePath = File("<FILE_PATH>"); // The csv or txt file
let emailAddressColumn = 3; // The index of "email" column in the file. Index starts at 1
let hasHeaderRow = true; // If this is `true` the first row is considered as table headers
let returnUrl = "https://domain.com/called/after/processing/request";
ZeroBounceSDK.shared.scoringSendFile(
filePath: filePath,
emailAddressColumn: emailAddressColumn,
returnUrl: returnUrl,
hasHeaderRow: hasHeaderRow
) { result in
switch result {
case .Success(let response):
NSLog("sendFile success response=\(response)")
case .Failure(let error):
NSLog("sendFile failure error=\(String(describing: error))")
}
}
let fileId = "<FILE_ID>"; // The returned file ID when calling scoringSendFile API
ZeroBounceSDK.shared.scoringGetfile(fileId: fileId) { result in
switch result {
case .Success(let response):
NSLog("getfile success response=\(response)")
case .Failure(let error):
NSLog("getfile failure error=\(String(describing: error))")
}
}
let fileId = "<FILE_ID>"; // The returned file ID when calling scoringSendFile API
ZeroBounceSDK.shared.scoringFileStatus(fileId: fileId) { result in
switch result {
case .Success(let response):
NSLog("fileStatus success response=\(response)")
case .Failure(let error):
NSLog("fileStatus failure error=\(String(describing: error))")
}
}
let fileId = "<FILE_ID>"; // The returned file ID when calling scoringSendFile API
ZeroBounceSDK.shared.scoringDeleteFile(fileId: fileId) { result in
switch result {
case .Success(let response):
NSLog("deleteFile success response=\(response)")
case .Failure(let error):
NSLog("deleteFile failure error=\(String(describing: error))")
}
}
- You can also clone the repo and access the Sample App inside the project to check out some examples. Just initialize the SDK with your own API key and uncomment the endpoint that you want to test.
Any of the following email addresses can be used for testing the API, no credits are charged for these test email addresses:
- [email protected]
- [email protected]
- [email protected]
- [email protected]
- [email protected]
- [email protected]
- [email protected]
- [email protected]
- [email protected]
- [email protected]
- [email protected]
- [email protected]
- [email protected]
- [email protected]
- [email protected]
- [email protected]
- [email protected]
- [email protected]
- [email protected]
- [email protected]
- [email protected]
- [email protected]
- [email protected]
- [email protected]
- [email protected]
- [email protected]
- [email protected]
- [email protected]
- [email protected]