https://github.com/libec/ynab-kmp-api
A multiplatform Kotlin library for a public YNAB API
https://github.com/libec/ynab-kmp-api
Last synced: 2 months ago
JSON representation
A multiplatform Kotlin library for a public YNAB API
- Host: GitHub
- URL: https://github.com/libec/ynab-kmp-api
- Owner: libec
- Created: 2024-04-08T16:17:19.000Z (about 2 years ago)
- Default Branch: main
- Last Pushed: 2024-12-06T09:19:39.000Z (over 1 year ago)
- Last Synced: 2024-12-06T10:24:45.695Z (over 1 year ago)
- Language: Kotlin
- Homepage:
- Size: 244 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 5
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
[YNAB](https://www.ynab.com/) (You Need A Budget) is a great piece of budgeting software with a [public API](https://api.ynab.com/). This is a multiplatform Kotlin library for that API that compiles for JVM for Android and LLVM for iOS.
The feature set is not 1:1 to the public API, but it's a good starting point built on solid foundations.
## Motivation
I'm an iOS developer interested in sharing code across platforms without compromising the native experience. I knew zero Kotlin before this, but learning by doing is my jam, and doing something useful like sharing data access code is a great starting point that is just a step away from sharing business logic to ensure consistency across the whole product.
## Usage
Check `EndToEndTests` in Kotlin and in Swift for a executable example of how to use the library.
Replace null with your token (also, don't commit your access token to git):
```kotlin
val accessToken: String? = null
```
Inject your access token to start a session:
```kotlin
val ynabSession = YnabSession(UserAuthentication(accessToken))
```
Session scoped repositories hold your data for the lifetime of the session:
```kotlin
val budgetRepository = ynabSession.getBudgetsRepository()
val accountsRepository = ynabSession.getAccountsRepository()
val payeesRepository = ynabSession.getPayeesRepository()
val categoriesRepository = ynabSession.getCategoriesRepository()
val transactionsRepository = ynabSession.getTransactionsRepository()
```
Fetch your data:
```kotlin
budgetRepository.fetchAllBudgets()
accountsRepository.fetchAccounts(budgetId = budget.id)
payeesRepository.fetchPayees(budgetId = budget.id)
categoriesRepository.fetchCategories(budgetId = budget.id)
```
Subscribe to updates:
```kotlin
budgetRepository.budgets.map { budgets ->
// Do your domain or presentation magic here
}
categoriesRepository.categories.map { categories ->
// Do your domain or presentation magic here
}
```
## Why bother with Repositories and not just expose Resources
To [quote myself](https://mobileit.cz/Blog/Pages/swift-ui-and-architecture-state.aspx):
> A repository is a design pattern that abstracts data access logic from business access logic by exposing the collection-like interface to access business entities. The actual implementation of the interface might communicate with the database, REST API, and what your project requires...
A repository is a great place for possible implementation of caching and compilation of delta requests as described in the [public API](https://api.ynab.com/).