Files
firefly-iii/app/Services/Ynab/Request/GetBudgetsRequest.php

74 lines
2.2 KiB
PHP
Raw Normal View History

2018-07-29 21:02:03 +02:00
<?php
/**
* GetBudgetsRequest.php
2020-02-16 13:56:35 +01:00
* Copyright (c) 2019 james@firefly-iii.org
2018-07-29 21:02:03 +02:00
*
* This file is part of Firefly III (https://github.com/firefly-iii).
2018-07-29 21:02:03 +02:00
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as
* published by the Free Software Foundation, either version 3 of the
* License, or (at your option) any later version.
2018-07-29 21:02:03 +02:00
*
* This program is distributed in the hope that it will be useful,
2018-07-29 21:02:03 +02:00
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
2018-07-29 21:02:03 +02:00
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
2018-07-29 21:02:03 +02:00
*/
declare(strict_types=1);
namespace FireflyIII\Services\Ynab\Request;
use Log;
/**
* Class GetBudgetsRequest
*
2019-07-31 16:53:09 +02:00
* @codeCoverageIgnore
* @deprecated
2018-07-29 21:02:03 +02:00
*/
class GetBudgetsRequest extends YnabRequest
{
/** @var array */
public $budgets;
public function __construct()
{
parent::__construct();
$this->budgets = [];
}
/**
*
*/
public function call(): void
{
Log::debug('Now in GetBudgetsRequest::call()');
$uri = $this->api . '/budgets';
Log::debug(sprintf('URI is %s', $uri));
$result = $this->authenticatedGetRequest($uri, []);
2018-09-09 07:57:15 +02:00
Log::debug('Raw GetBudgetsRequest result', $result);
2018-07-29 21:02:03 +02:00
// expect data in [data][budgets]
$rawBudgets = $result['data']['budgets'] ?? [];
$freshBudgets = [];
foreach ($rawBudgets as $rawBudget) {
2018-09-09 11:18:05 +02:00
Log::debug(sprintf('Raw content of budget is: %s', json_encode($rawBudget)));
Log::debug(sprintf('Content of currency format is: %s', json_encode($rawBudget['currency_format'] ?? [])));
2018-09-09 07:57:15 +02:00
Log::debug(sprintf('ISO code is: %s', $rawBudget['currency_format']['iso_code'] ?? '(none)'));
2018-07-29 21:02:03 +02:00
$freshBudgets[] = [
'id' => $rawBudget['id'],
'name' => $rawBudget['name'],
2018-09-09 07:57:15 +02:00
'currency_code' => $rawBudget['currency_format']['iso_code'] ?? null,
2018-07-29 21:02:03 +02:00
];
}
$this->budgets = $freshBudgets;
}
2018-12-31 07:48:23 +01:00
}