BudgetKit
is an iOS framework wrapper for the YNAB (You Need A Budget) Public API. It manages authentication, network calls, and model objects associated with the API. No need to worry about networking or JSON parsing, simply import BudgetKit
and start developing your iOS app using the YNAB API!
BudgetKit is available through CocoaPods. To install it, simply add the following line to your Podfile:
pod 'BudgetKit'
Install the pod by running pod install
. You may need to run pod repo update
first.
Include BudgetKit
anywhere you need to call the YNAB API or use a YNAB model object with:
import BudgetKit
Refer to the YNAB Authentication Overview for guidance on how to obtain a personal access token and/or OAuth client ID.
Login using a personal access token. This is used for testing and has the option to force a failure to test error handling.
YNAB.login(personalAccessToken: String, shouldFail: Bool = false, authenticated: (() -> Void), failed: @escaping ((Error) -> Void))
Login using OAuth. This is the standard method used for logging in to YNAB. You'll use this in any release version of your app.
YNAB.login(clientID: String, redirectURI: String, state: String?, authenticated: @escaping (() -> Void), failed: @escaping ((Error) -> Void))
API calls that return data take a YNABCompletion<T>
which is just a typealias for a closure using a Result
object. Here are the definitions for each:
public typealias YNABCompletion<T> = ((Result<T>) -> Void)
public enum Result<T> {
case success(T)
case failure(Error)
}
Switch on the result
to handle success and failure cases:
YNAB.getCategory(budgetID: budgetID, categoryID: categoryID) { (result) in
switch result {
case .success(let category):
// Do something with the category
case .failure(let error):
// Handle the error
}
}
Calls to the API are simple. Here are a few examples:
Get Budget by ID
Returns a single budget with all related entities. This resource is effectively a full budget export.
YNAB.getBudget(id: UUID, completion: @escaping YNABCompletion<BudgetDetail>)
Get Transactions for a Payee
Returns all transactions for a specified payee.
YNAB.getTransactionListForPayee(budgetID: UUID?, payeeID: UUID, completion: @escaping YNABCompletion<[TransactionDetail]>)
Stuart Daubenmire, dauby88@icloud.com
BudgetKit is available under the MIT license. See the LICENSE file for more info.