mirror of
https://github.com/firefly-iii/firefly-iii.git
synced 2025-10-25 13:10:35 +00:00
Lots of new code for Spectre import.
This commit is contained in:
101
app/Services/Spectre/Object/Account.php
Normal file
101
app/Services/Spectre/Object/Account.php
Normal file
@@ -0,0 +1,101 @@
|
||||
<?php
|
||||
/**
|
||||
* Account.php
|
||||
* Copyright (c) 2018 thegrumpydictator@gmail.com
|
||||
*
|
||||
* This file is part of Firefly III.
|
||||
*
|
||||
* Firefly III is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* Firefly III is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with Firefly III. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace FireflyIII\Services\Spectre\Object;
|
||||
|
||||
use Carbon\Carbon;
|
||||
|
||||
/**
|
||||
* Class Account
|
||||
*/
|
||||
class Account extends SpectreObject
|
||||
{
|
||||
/** @var float */
|
||||
private $balance;
|
||||
/** @var Carbon */
|
||||
private $createdAt;
|
||||
/** @var string */
|
||||
private $currencyCode;
|
||||
/** @var array */
|
||||
private $extra = [];
|
||||
/** @var int */
|
||||
private $id;
|
||||
/** @var int */
|
||||
private $loginId;
|
||||
/** @var string */
|
||||
private $name;
|
||||
/** @var string */
|
||||
private $nature;
|
||||
/** @var Carbon */
|
||||
private $updatedAt;
|
||||
|
||||
/**
|
||||
* Account constructor.
|
||||
*
|
||||
* @param array $data
|
||||
*/
|
||||
public function __construct(array $data)
|
||||
{
|
||||
$this->id = $data['id'];
|
||||
$this->loginId = $data['login_id'];
|
||||
$this->currencyCode = $data['currency_code'];
|
||||
$this->balance = $data['balance'];
|
||||
$this->name = $data['name'];
|
||||
$this->nature = $data['nature'];
|
||||
$this->createdAt = new Carbon($data['created_at']);
|
||||
$this->updatedAt = new Carbon($data['updated_at']);
|
||||
|
||||
foreach ($data['extra'] as $key => $value) {
|
||||
$this->extra[$key] = $value;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @return int
|
||||
*/
|
||||
public function getId(): int
|
||||
{
|
||||
return $this->id;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array
|
||||
*/
|
||||
public function toArray(): array
|
||||
{
|
||||
$array = [
|
||||
'balance' => $this->balance,
|
||||
'created_at' => $this->createdAt->toIso8601String(),
|
||||
'currency_code' => $this->currencyCode,
|
||||
'extra' => $this->extra,
|
||||
'id' => $this->id,
|
||||
'login_id' => $this->loginId,
|
||||
'name' => $this->name,
|
||||
'nature' => $this->nature,
|
||||
'updated_at' => $this->updatedAt->toIso8601String(),
|
||||
];
|
||||
|
||||
return $array;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -163,6 +163,46 @@ class Attempt extends SpectreObject
|
||||
return $this->failMessage;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array
|
||||
*/
|
||||
public function toArray(): array
|
||||
{
|
||||
$array = [
|
||||
'api_mode' => $this->apiMode,
|
||||
'api_version' => $this->apiVersion,
|
||||
'automatic_fetch' => $this->automaticFetch,
|
||||
'categorize' => $this->categorize,
|
||||
'created_at' => $this->createdAt->toIso8601String(),
|
||||
'consent_given_at' => $this->consentGivenAt->toIso8601String(),
|
||||
'consent_types' => $this->consentTypes,
|
||||
'custom_fields' => $this->customFields,
|
||||
'daily_refresh' => $this->dailyRefresh,
|
||||
'device_type' => $this->deviceType,
|
||||
'user_agent' => $this->userAgent,
|
||||
'remote_ip' => $this->remoteIp,
|
||||
'exclude_accounts' => $this->excludeAccounts,
|
||||
'fail_at' => $this->failAt->toIso8601String(),
|
||||
'fail_error_class' => $this->failErrorClass,
|
||||
'fail_message' => $this->failMessage,
|
||||
'fetch_type' => $this->fetchType,
|
||||
'finished' => $this->finished,
|
||||
'finished_recent' => $this->finishedRecent,
|
||||
'from_date' => $this->fromDate->toIso8601String(),
|
||||
'id' => $this->id,
|
||||
'interactive' => $this->interactive,
|
||||
'locale' => $this->locale,
|
||||
'partial' => $this->partial,
|
||||
'show_consent_confirmation' => $this->showConsentInformation,
|
||||
'stages' => $this->stages,
|
||||
'store_credentials' => $this->storeCredentials,
|
||||
'success_at' => $this->successAt->toIso8601String(),
|
||||
'to_date' => $this->toDate->toIso8601String(),
|
||||
'updated_at' => $this->updatedAt->toIso8601String(),
|
||||
];
|
||||
|
||||
return $array;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
@@ -37,4 +37,12 @@ class Holder extends SpectreObject
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array
|
||||
*/
|
||||
public function toArray(): array
|
||||
{
|
||||
return [];
|
||||
}
|
||||
}
|
||||
@@ -96,6 +96,14 @@ class Login extends SpectreObject
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* @return int
|
||||
*/
|
||||
public function getId(): int
|
||||
{
|
||||
return $this->id;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return Attempt
|
||||
*/
|
||||
@@ -104,5 +112,35 @@ class Login extends SpectreObject
|
||||
return $this->lastAttempt;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array
|
||||
*/
|
||||
public function toArray(): array
|
||||
{
|
||||
$array = [
|
||||
'consent_given_at' => $this->consentGivenAt->toIso8601String(),
|
||||
'consent_types' => $this->consentTypes,
|
||||
'country_code' => $this->countryCode,
|
||||
'created_at' => $this->createdAt->toIso8601String(),
|
||||
'updated_at' => $this->updatedAt->toIso8601String(),
|
||||
'customer_id' => $this->customerId,
|
||||
'daily_refresh' => $this->dailyRefresh,
|
||||
'holder_info' => $this->holderInfo->toArray(),
|
||||
'id' => $this->id,
|
||||
'last_attempt' => $this->lastAttempt->toArray(),
|
||||
'last_success_at' => $this->lastSuccessAt->toIso8601String(),
|
||||
'next_refresh_possible_at' => $this->nextRefreshPossibleAt,
|
||||
'provider_code' => $this->providerCode,
|
||||
'provider_id' => $this->providerId,
|
||||
'provider_name' => $this->providerName,
|
||||
'show_consent_confirmation' => $this->showConsentConfirmation,
|
||||
'status' => $this->status,
|
||||
'store_credentials' => $this->storeCredentials,
|
||||
|
||||
];
|
||||
|
||||
return $array;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
41
app/Services/Spectre/Object/Transaction.php
Normal file
41
app/Services/Spectre/Object/Transaction.php
Normal file
@@ -0,0 +1,41 @@
|
||||
<?php
|
||||
/**
|
||||
* Transaction.php
|
||||
* Copyright (c) 2018 thegrumpydictator@gmail.com
|
||||
*
|
||||
* This file is part of Firefly III.
|
||||
*
|
||||
* Firefly III is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* Firefly III is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with Firefly III. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace FireflyIII\Services\Spectre\Object;
|
||||
|
||||
/**
|
||||
* Class Transaction
|
||||
*/
|
||||
class Transaction extends SpectreObject
|
||||
{
|
||||
/**
|
||||
* Transaction constructor.
|
||||
*
|
||||
* @param array $data
|
||||
*/
|
||||
public function __construct(array $data) {
|
||||
var_dump($data);
|
||||
exit;
|
||||
}
|
||||
|
||||
}
|
||||
93
app/Services/Spectre/Request/ListAccountsRequest.php
Normal file
93
app/Services/Spectre/Request/ListAccountsRequest.php
Normal file
@@ -0,0 +1,93 @@
|
||||
<?php
|
||||
/**
|
||||
* ListAccountsRequest.php
|
||||
* Copyright (c) 2018 thegrumpydictator@gmail.com
|
||||
*
|
||||
* This file is part of Firefly III.
|
||||
*
|
||||
* Firefly III is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* Firefly III is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with Firefly III. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace FireflyIII\Services\Spectre\Request;
|
||||
|
||||
use FireflyIII\Exceptions\FireflyException;
|
||||
use FireflyIII\Services\Spectre\Exception\SpectreException;
|
||||
use FireflyIII\Services\Spectre\Object\Account;
|
||||
use FireflyIII\Services\Spectre\Object\Login;
|
||||
use Log;
|
||||
|
||||
/**
|
||||
* Class ListAccountsRequest
|
||||
*/
|
||||
class ListAccountsRequest extends SpectreRequest
|
||||
{
|
||||
/** @var array */
|
||||
private $accounts = [];
|
||||
/** @var Login */
|
||||
private $login;
|
||||
|
||||
/**
|
||||
* @throws SpectreException
|
||||
* @throws FireflyException
|
||||
*/
|
||||
public function call(): void
|
||||
{
|
||||
$hasNextPage = true;
|
||||
$nextId = 0;
|
||||
while ($hasNextPage) {
|
||||
Log::debug(sprintf('Now calling ListAccountsRequest for next_id %d', $nextId));
|
||||
$parameters = ['from_id' => $nextId, 'login_id' => $this->login->getId()];
|
||||
$uri = '/api/v3/accounts?' . http_build_query($parameters);
|
||||
$response = $this->sendSignedSpectreGet($uri, []);
|
||||
|
||||
// count entries:
|
||||
Log::debug(sprintf('Found %d entries in data-array', count($response['data'])));
|
||||
|
||||
// extract next ID
|
||||
$hasNextPage = false;
|
||||
if (isset($response['meta']['next_id']) && intval($response['meta']['next_id']) > $nextId) {
|
||||
$hasNextPage = true;
|
||||
$nextId = $response['meta']['next_id'];
|
||||
Log::debug(sprintf('Next ID is now %d.', $nextId));
|
||||
} else {
|
||||
Log::debug('No next page.');
|
||||
}
|
||||
|
||||
// store customers:
|
||||
foreach ($response['data'] as $accountArray) {
|
||||
$this->accounts[] = new Account($accountArray);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array
|
||||
*/
|
||||
public function getAccounts(): array
|
||||
{
|
||||
return $this->accounts;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Login $login
|
||||
*/
|
||||
public function setLogin(Login $login): void
|
||||
{
|
||||
$this->login = $login;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
90
app/Services/Spectre/Request/ListTransactionsRequest.php
Normal file
90
app/Services/Spectre/Request/ListTransactionsRequest.php
Normal file
@@ -0,0 +1,90 @@
|
||||
<?php
|
||||
/**
|
||||
* ListTransactionsRequest.php
|
||||
* Copyright (c) 2018 thegrumpydictator@gmail.com
|
||||
*
|
||||
* This file is part of Firefly III.
|
||||
*
|
||||
* Firefly III is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* Firefly III is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with Firefly III. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace FireflyIII\Services\Spectre\Request;
|
||||
|
||||
use FireflyIII\Services\Spectre\Object\Account;
|
||||
use FireflyIII\Services\Spectre\Object\Transaction;
|
||||
use Log;
|
||||
/**
|
||||
* Class ListTransactionsRequest
|
||||
*/
|
||||
class ListTransactionsRequest extends SpectreRequest
|
||||
{
|
||||
/** @var Account */
|
||||
private $account;
|
||||
/** @var array */
|
||||
private $transactions = [];
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
public function call(): void
|
||||
{
|
||||
$hasNextPage = true;
|
||||
$nextId = 0;
|
||||
while ($hasNextPage) {
|
||||
Log::debug(sprintf('Now calling ListTransactionsRequest for next_id %d', $nextId));
|
||||
$parameters = ['from_id' => $nextId,'account_id' => $this->account->getId()];
|
||||
$uri = '/api/v3/transactions?' . http_build_query($parameters);
|
||||
$response = $this->sendSignedSpectreGet($uri, []);
|
||||
|
||||
// count entries:
|
||||
Log::debug(sprintf('Found %d entries in data-array', count($response['data'])));
|
||||
|
||||
// extract next ID
|
||||
$hasNextPage = false;
|
||||
if (isset($response['meta']['next_id']) && intval($response['meta']['next_id']) > $nextId) {
|
||||
$hasNextPage = true;
|
||||
$nextId = $response['meta']['next_id'];
|
||||
Log::debug(sprintf('Next ID is now %d.', $nextId));
|
||||
} else {
|
||||
Log::debug('No next page.');
|
||||
}
|
||||
|
||||
// store customers:
|
||||
foreach ($response['data'] as $transactionArray) {
|
||||
$this->transactions[] = new Transaction($transactionArray);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array
|
||||
*/
|
||||
public function getTransactions(): array
|
||||
{
|
||||
return $this->transactions;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @param Account $account
|
||||
*/
|
||||
public function setAccount(Account $account): void
|
||||
{
|
||||
$this->account = $account;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user