# iOS SDK

# Installation(CocoaPods)

CocoaPods is a dependency manager for Cocoa projects. For usage and installation instructions, visit their website. To integrate EndpassSDK into your Xcode project using CocoaPods, specify it in your Podfile:

  • Update your Podfile with the following contents

    target 'YourAppTargetName' do
        use_frameworks!
        pod 'EndpassSDK'
    end
    
  • Install dependencies

    pod install
    
  • Open the newly created .xcworkspace

  • Import the library to any of your classes by using import EndpassSDK and begin working on your project

All api calls contain two types of input data:

And two types of outpute data:

  • data: Data model
  • error: Error contain error code and message

# Initialization SDK

To use EndpassSDK you need to enter AppID

EPSecurityManager.initialOAuth(appId: "YOUR_APPLICATION_ID")

# Get User information

        EPUserManager.request(
            endpoint: EPPublicConstants.getUserEndpoint(),
            responseModel: EPUserDataResponse.self,
            success: { data in
                print(data)
        }) { error in
            print("Code: \(error.errorCode). Message: \(error.errorDescription)")
        }

# Get User address

        EPUserManager.request(
            endpoint: EPPublicConstants.getUserAddressEndpoint(),
            responseModel: EPUserAddressesResponse.self,
            success: { data in
                print(data)
        }) { error in
            print("Code: \(error.errorCode). Message: \(error.errorDescription)")
        }

# Get User personal

        EPUserManager.request(
            endpoint: EPPublicConstants.getUserPersonalInfoEndpoint(),
            responseModel: EPUserPersonalDataResponse.self,
            success: { data in
                print(data)
        }) { error in
            print("Code: \(error.errorCode). Message: \(error.errorDescription)")
        }

# Get App scopes

        EPUserManager.request(
            endpoint: EPPublicConstants.getUserScopesEndpoint(),
            responseModel: EPUserScopesResponse.self,
            success: { data in
                print(data)
        }) { error in
            print("Code: \(error.errorCode). Message: \(error.errorDescription)")
        }

# Get documents

        EPDocumentsManager.request(
            endpoint: EPPublicConstants.getDocumentsEndpoint(),
            responseModel: EPPublicDocumentListResponse.self,
            success: { data in
                print(data)
        }) { error in
            print("Code: \(error.errorCode). Message: \(error.errorDescription)")
        }

# URL constants

-     getUserEndpoint = "/user"
-     getUserAddressEndpoint = "/user/address"
-     getUserPersonalInfoEndpoint = "/user/info/personal"
-     getUserScopesEndpoint = "/scopes"
-     getDocumentsEndpoint = "/documents"

# Data models

# EPUserDataResponse

public struct EPUserDataResponse: Codable {
    public let id: String
    public let email: String?
    public let phones: [Phone]?
}

// MARK: - Phone
public struct Phone: Codable {
    public let id: String
    public let createdAt: Int
    public let status: String
    public let country: String
    public let number: String
    public let main: Bool
}

# EPUserAddressesResponse

public struct EPUserAddressesResponseElement: Codable {
    public let main: Bool
    public let createdAt: Int
    public let apartmentNumber: String
    public let streetNumber: String
    public let street: String
    public let city: String
    public let stateRegion: String
    public let country: String
    public let postalCode: String
    public let lat: Double
    public let lng: Double
    public let verified: Bool

}

public typealias EPUserAddressesResponse = [EPUserAddressesResponseElement]

# EPUserPersonalDataResponse

public struct EPUserPersonalDataResponse: Codable {
    public let id: String
    public let firstName: String
    public let lastName: String
    public let dateOfBirth: Int
}

# EPUserScopesResponse

public struct EPUserScopesResponse: Codable {
    public let scopes: [String]
}

# EPPublicDocumentListResponse

public struct EPPublicDocumentElement: Codable {
    public let id: String
    public let createdAt: Int
    public let status: EPPublicConstants.DocumentStatusType
    public let documentType: EPPublicConstants.DocumentType
}

public typealias EPPublicDocumentListResponse = [EPPublicDocumentElement?]

# DocumentType

    public enum DocumentType: String, Codable {
        case Passport
        case DriverLicense
        case ProofOfAddress
        case IdCard
        
        public func getLocalize() -> String {
            switch self {
            case .Passport:
                return "Passport"
            case .DriverLicense:
                return "Driver License"
            case .ProofOfAddress:
                return "Proof of Address"
            case .IdCard:
                return "Id Card"
            }
        }
    }

# AreaType

    public enum AreaType: String, Codable {
        case Internal
    }

# DocumentStatusType

    public enum DocumentStatusType: String, Codable {
        case Draft
        case Recognition
        case NotReadable
        case NotVerified
        case Verified
        case PendingReview

        public func getLocalize() -> String {
            switch self {
            case .Draft:
                return "Draft"
            case .Recognition:
                return "Recognizing"
            case .NotReadable:
                return "Not readable"
            case .NotVerified:
                return "Not verified"
            case .Verified:
                return "Verified"
            case .PendingReview:
                return "Pending review"
            }
        }
    }

# Errors description

    {
        public var errorCode: Int
        public var errorDescription: String?
    }
errorCode errorDescription information
630 Access denied Check whether you have permissions to request user data in your app and whether the appID is correct
332 Message contains parsing error Couldn't parse the response from the server to the data model
338 Personal data is empty The user did not fill in personal data
352 Message contains User API connection error Send information about the error to our technical support service
724 User dissmissed The user closed the document selection window
732 Data is nil An error occurred when requesting documents, no data
749 Access denied Check whether you have permissions to request document data in your app and whether the appID is correct
791 The application has no required documents The user didn't upload the entire list of requested documents
7127 Message contains Documents API connection error Send information about the error to our technical support service