indy2kro / buxfer-api
Buxfer API客户端库
1.1.1
2022-05-30 06:53 UTC
Requires
- php: >=7.3
- ext-curl: *
- guzzlehttp/guzzle: ~7.4
Requires (Dev)
- overtrue/phplint: ^3.0
- phpcompatibility/php-compatibility: ^9.3
- phploc/phploc: ^7.0
- phpmetrics/phpmetrics: ^2.7
- phpstan/phpstan: ^0.12
- phpunit/phpunit: ^9.5
- sebastian/phpcpd: ^6.0
- squizlabs/php_codesniffer: ^3.6
- vimeo/psalm: ^4.10
README
PHP中的完整Buxfer API库实现。
使用Guzzle HTTP客户端和cURL进行HTTPS请求到Buxfer。注意:使用API需要一个有效的Buxfer.com账户。
请参阅https://www.buxfer.com/help/api以获取完整的API描述。
操作
允许的API操作
- login($username, $password) - 使用Buxfer.com凭据登录,对于所有其他API操作都是强制性的
- listAccounts() - 返回包含所有账户信息的数组
- listLoans() - 返回包含所有贷款的数组
- listTags() - 返回包含所有标签的数组
- listBudgets() - 返回包含所有预算的数组
- listReminders() - 返回包含所有提醒的数组
- listGroups() - 返回包含所有组的数组
- listContacts() - 返回包含所有联系人的数组
- uploadStatement($statement) - 上传一个声明
- listTransactions($filters) - 返回基于以下过滤器的交易数组:accountId OR accountName,tagId OR tagName,startDate AND endDate OR month,budgetId OR budgetName,contactId OR contactName,groupId OR groupName
- addTransaction($transaction) - 添加新交易 - 请参阅(add_transaction)的完整API参数描述
其他有用的方法
- public function __construct(Array $config = array(), HttpClient $httpClient = null) - 构造函数,可以接收配置参数(与当前配置合并),HttpClient对象(扩展自GuzzleHttpClient)
- getLastDuration() - 获取最后请求的持续时间(浮点数)
- getToken() - 获取登录后收到的令牌
- getConfig() - 获取配置数组
- setConfig($config) - 设置配置数组(与当前配置合并)
如果发生错误,将抛出一个新的 \BuxferApi\Exception。
配置
默认配置使用 - 可以使用构造函数参数或setConfig()覆盖任何参数
protected $_config = array( 'user_agent' => 'PHP BuxferApi ' . self::VERSION, 'timeout' => 10, 'handler' => null, );
示例用法
$config = array( 'buxfer_username' => 'testuser@testaccount.com', 'buxfer_password' => 'testpassword', 'buxfer_accountId' => '1000000', ); $buxferApi = new \BuxferApi\Client($buxferConfig); $buxferApi->login($config['buxfer_username'], $config['buxfer_password']); // list existing transactions $transactions = $buxferApi->listTransactions($config['buxfer_accountId']); // add new transaction $newTransaction = array( 'accountId' => $config['buxfer_accountId'], 'date' => '2020-02-11 10:20:00', 'type' => 'expense', 'amount' => '10.20', 'description' => 'Test transaction', 'tags' => 'mytag1,mytag2' ); $buxferApi->addTransaction($transaction);