MondoKit 0.2.1

MondoKit 0.2.1

测试已测试
语言语言 SwiftSwift
许可证 MIT
发布上次发布2016年2月
SPM支持 SPM

Mike Pollard 维护。



 
依赖项
SwiftyJSON~> 2.3
SwiftyJSONDecodable~> 0.1
Alamofire~> 3.0
KeychainAccess>= 0
 

MondoKit 0.2.1

MondoKit

MondoKit 是一个 Swift 框架,它包装了 Mondo API,详见 https://getmondo.co.uk/docs/

要求

  • iOS 9.0+
  • Xcode 7.2+

安装

入门

初始化

以下是如何初始化 MondAPI,应在您使用 MondoAPI 类之前完成,因此可能在 applicationDidFinishLaunchingWithOptions 中执行。

MondoAPI.instance.initialiseWithClientId(mondoClientId, clientSecret : mondoClientSecret)

一个选项是将您的 Mondo clientId 和 clientSecret 存储在名为 MondoKeys.plist 的属性列表文件中(别忘了将其添加到 .gitignore 文件中)。然后您可以按照以下方式初始化 MondoAPI:

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 提供了一个 ViewController 实现,用于管理与 API 的三腿授权。在授权成功的情况下,它还会将授权详细信息(accessToken、expiresIn 等)安全地存储在 KeyChain 中,这样您在每次运行应用程序时就不需要登录了。

要检查 MondoAPI 是否已授权给用户

if MondoAPI.instance.isAuthorized { ... proceed ... }

如果没有,则请求 auth ViewController,指定用于处理结果的回调闭包并显示它

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

例如,使用 Optional expand 参数

MondoAPI.instance.listTransactionsForAccount(account, expand: "merchant") { (transactions, error) in ... }

例如,使用 Optional pagination 参数

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