MondoKit is a Swift framework wrapping the Mondo API at https://getmondo.co.uk/docs/
- iOS 9.0+
- Xcode 7.2+
Carthage is a decentralized dependency manager that builds your dependencies and provides you with binary frameworks.
To integrate MondoKit into your Xcode project using Carthage, specify it in your Cartfile
:
github "pollarm/MondoKit"
Run carthage update --platform iOS --no-use-binaries
to build the framework and it's dependencies and drag the built Alamofire.framework, KeychainAccess.framework, SwiftyJSONDecodable.framework, SwiftyJSON.framework and MondoKit.framework
into your Xcode project.
CocoaPods 0.39.0+ is required to build MondoKit.
To integrate MondoKit into your Xcode project using CocoaPods, specify it in your Podfile
:
platform :ios, '9.0'
use_frameworks!
pod 'MondoKit'
Then, run the following command:
$ pod install
Initialising the MondAPI is achieved as follows and should be done before you do anything else with the MondoAPI class, so probably in applicationDidFinishLaunchingWithOptions
.
MondoAPI.instance.initialiseWithClientId(mondoClientId, clientSecret : mondoClientSecret)
One option is to store your Mondo clientId and clientSecret in a property list file called MondoKeys.plist (don't forget to .gitignore this file). You can then initialise the MondoAPI as follows:
guard let mondoKeysPath = NSBundle.mainBundle().pathForResource("MondoKeys", ofType: "plist"),
mondoKeys = NSDictionary(contentsOfFile: mondoKeysPath),
mondoClientId = mondoKeys["clientId"] as? String,
mondoClientSecret = mondoKeys["clientSecret"] as? String else {
assertionFailure("MondoKeys.plist containing 'clientId' and 'clientSecret' required but not found in main bundle")
return false
}
MondoAPI.instance.initialiseWithClientId(mondoClientId, clientSecret : mondoClientSecret)
MondoAPI provides a ViewController implemetation to manage 3-legged authorization with the API. It also stores authorization details (accessToken, expiresIn etc.) securely in the KeyChain in the event of a successful authorization so you don't need to login every time you run your app.
To check if MondoAPI is already authorized for a user:
if MondoAPI.instance.isAuthorized { ... proceed ... }
If not then request an auth ViewController specifiying the callback closure to deal with the result and present it:
else {
let oauthViewController = MondoAPI.instance.newAuthViewController() { (success, error) in
if success {
self.dismissViewControllerAnimated(true) {
// proceed now we're logged in
}
else {
// present error to user
}
}
presentViewController(oauthViewController, animated: true, completion: nil)
}
MondoAPI.instance.listAccounts() { (accounts, error) in ... }
MondoAPI.instance.getBalanceForAccount(account) { (balance, error) in ... }
MondoAPI.instance.listTransactionsForAccount(account) { (transactions, error) in ... }
eg. using Optional expand
parameter
MondoAPI.instance.listTransactionsForAccount(account, expand: "merchant") { (transactions, error) in ... }
eg. using Optional pagination
parameter
MondoAPI.instance.listTransactionsForAccount(account, pagination: MondoAPI.Pagination(limit: 50, since: .Date(NSDate()), before: NSDate())) { (transactions, error) in ... }
MondoAPI.instance.getTransactionForId(id, expand: "merchant") { (transaction, error) in ... }
MondoAPI.instance.annotateTransaction(transaction, withKey "aKey", value: "aValue") { (transaction, error) in ... }
MondoAPI.instance.listFeedForAccount(account) { (feedItems, error) in ... }