Note: This SDK is Swift 3.0 thanks to UberJason. Please use Xcode 8 and later 😀
##Synopsis Capital One Nessie API SDK written in Swift, using SwiftyJSON for JSON parsing. This SDK can be easily embedded in an iOS project.
##Installation
- Download the entire SDK directory.
- Open the
Nessie-iOS-Wrapper.xcworkspace
file. - Set your API Key in
NSEClient.swift
whereprivate var key = ""
- Start working by either:
- Creating a new Project Target and add your work there.
- Adding your files directly into the
Nessie-iOS-Wrapper
target. SeeNessieTestProj
for examples.
##Usage and Examples
####Important Note
Any parameter marked as optional in the Nessie documentation are also optional in the SDK. They are simply marked as an Optional
type in Swift. For instance, accountType
is an optional field here:
In the getAccounts()
call, accountType
is optional. If you wish to get all accounts regardless of account type, just pass in a nil
value for accountType:
AccountRequest().getAccounts(nil, completion:{(response, error) in
...
)}
####Creating a Customer
func testPostCustomer() {
// construct the Customer object you want to create
// in this case, address is an object so it needs its own initializer
let address = Address(streetName: "Street", streetNumber: "1", city: "City", state: "VA", zipCode: "12345")
let customerToCreate = Customer(firstName: "Victor", lastName: "Lopez", address: address, customerId: "sup3rc00la1ph4num3r1cId")
// send the request using the wrapper!
CustomerRequest().postCustomer(customerToCreate, completion:{(response, error) in
if (error != nil) {
// handling the error. You could alternatively not have this block if you so choose
print(error)
} else {
// map the response and determine how to use i
// in this case, we only print to console
let customerResponse = response as BaseResponse<Customer>?
let message = customerResponse?.message
let customerCreated = customerResponse?.object
print("\(message): \(customerCreated)")
self.testPutCustomer(customerCreated!)
}
})
}
####Retrieving Customers
func testGetCustomers() {
// Retrieve all the Customers!
CustomerRequest().getCustomers({(response, error) in
if (error != nil) {
// optionally handle the error here
print(error)
} else {
// we are expecting back an array of customers. Type check!
if let array = response as Array<Customer>? {
// if there are Customers in the result, print the first Customer
if array.count > 0 {
let customer = array[0] as Customer?
self.testGetCustomer(customer!.customerId)
print(array)
} else {
print("No accounts found")
}
}
}
})
}
You can find examples here.