Skip to content

zerobounce/zero-bounce-ios-sdk

Repository files navigation

ZeroBounce iOS SDK

This SDK contains methods for interacting easily with ZeroBounce API. More information about ZeroBounce you can find in the official documentation.

Installation (CocoaPods)

Add the pod to your Podfile pod 'ZeroBounceSDK' and run pod install

USAGE

Import the SDK in your file:

import ZeroBounceSDK

Initialize the SDK with your api key:

ZeroBounceSDK.shared.initialize(apiKey: "<YOUR_API_KEY>")

Examples

Then you can use any of the SDK methods, for example:

  • Validate an email address
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
        }
    }
}
  • Validate up to 100 email addresses using Batch Email Validator
// 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))")
    }
}
  • Find the email and other domain formats based on a given domain name
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))")
    }
}
  • Check how many credits you have left on your account
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))")
    }
}
  • Check if your email inbox has been active in the past 30, 60, 90, 180, 365, 730 or 1095 days
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))")
    }
}
  • Check your API usage for a given period of time
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))")
    }
}
  • The sendfile API allows user to send a file for bulk email validation
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))")
    }
}
  • The getfile API allows users to get the validation results file for the file been submitted using sendfile API
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))")
    }
}
  • Check the status of a file uploaded via "sendFile" method
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))")
    }
}
  • Deletes the file that was submitted using scoring sendfile API. File can be deleted only when its status is Complete
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))")
    }
}

AI Scoring API

  • The scoringSendFile API allows user to send a file for bulk email validation
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))")
    }
}
  • The scoringGetFile API allows users to get the validation results file for the file been submitted using scoringSendFile API
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))")
    }
}
  • Check the status of a file uploaded via "scoringSendFile" method
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))")
    }
}
  • Deletes the file that was submitted using scoring scoringSendFile API. File can be deleted only when its status is Complete
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))")
    }
}

Sample App

  • 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: