CocoaPods trunk is moving to be read-only. Read more on the blog, there are 18 months to go.

MondoKit 0.2.1

MondoKit 0.2.1

TestsTested
LangLanguage SwiftSwift
License MIT
ReleasedLast Release Feb 2016
SPMSupports SPM

Maintained by Mike Pollard.



 
Depends on:
SwiftyJSON~> 2.3
SwiftyJSONDecodable~> 0.1
Alamofire~> 3.0
KeychainAccess>= 0
 

MondoKit 0.2.1

MondoKit

MondoKit is a Swift framework wrapping the Mondo API at https://getmondo.co.uk/docs/

Requirements

  • iOS 9.0+
  • Xcode 7.2+

Installation

Getting started

Initialization

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)

Authentication

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)
}

listAccounts

MondoAPI.instance.listAccounts() { (accounts, error) in ... }

getBalanceForAccount

MondoAPI.instance.getBalanceForAccount(account) { (balance, error) in ... }

listTransactions

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 ... }

getTransactionForId

MondoAPI.instance.getTransactionForId(id, expand: "merchant") { (transaction, error) in ... }

annotateTransaction

MondoAPI.instance.annotateTransaction(transaction, withKey "aKey", value: "aValue") { (transaction, error) in ... }

listFeedForAccount

MondoAPI.instance.listFeedForAccount(account) { (feedItems, error) in ... }