petrica/php-ynab4

API 用于读取和写入 YNAB4 JSON 数据库的交易。

dev-master 2019-08-16 14:01 UTC

This package is not auto-updated.

Last update: 2020-01-02 20:41:36 UTC


README

从和到 YNAB4 JSON 数据库读取和写入交易。

先决条件

  • PHP 5.4+
  • composer

快速开始

将仓库克隆到磁盘上

git clone git@github.com:petrica/php-ynab4.git

运行 composer install 以创建必要的库

cd php-ynab4
composer install

试用示例应用

cd sample
php index.php

读取交易

# dropbox driver
$io = new YnabDropboxIO(new Client($auth['access_token'], "MTools"));
# or
# disk driver if you want to access directly on disk the budget database
$io = new YnabDiskIO();

# path to budget folder
$pathToBudget = '/app/ynab/Test~B5C2AEE7.ynab4';
# device id as UUID Version 1, if not provided a new device will be generated
$deviceId = null;
$ynab = new YnabClient($pathToBudget, $io, $deviceId);

# fetch transactions from diff files
$ynab->pull();

# get latest transactions
$transactions = $ynab->getTransactions();

# update device knowledge based on read transactions
$ynab->commit();

# store device id for future calls
$deviceId = $ynab->getDevice()->getDeviceGUID();

写入交易

# dropbox driver
$io = new YnabDropboxIO(new Client($auth['access_token'], "MTools"));
# or
# disk driver if you want to access directly on disk the budget database
$io = new YnabDiskIO();

# path to budget folder
$pathToBudget = '/app/ynab/Test~B5C2AEE7.ynab4';
# device id as UUID Version 1, if not provided a new device will be generated
$deviceId = null;
$ynab = new YnabClient($pathToBudget, $io, $deviceId);

$transaction = new YnabTransaction();
$transaction->setAccountId('UUID_ACCOUNT_TO_PUSH_TRANSACTION_TO');
$transaction->setAmount('-10.5');
$transaction->setMemo('Some memo');
$transaction->setDate(new \DateTime());

$ynab->setTransactions([
    $transaction
]);

# Create diff file for other devices to read the new transaction
$ynab->push();

# Update device knowledge based on new generated diff file
$ynab->commit();