You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

86 lines
2.3 KiB

4 years ago
  1. <?php
  2. /**
  3. * GetAccountsRequest.php
  4. * Copyright (c) 2020 james@firefly-iii.org
  5. *
  6. * This file is part of the Firefly III Spectre importer
  7. * (https://github.com/firefly-iii/spectre-importer).
  8. *
  9. * This program is free software: you can redistribute it and/or modify
  10. * it under the terms of the GNU Affero General Public License as
  11. * published by the Free Software Foundation, either version 3 of the
  12. * License, or (at your option) any later version.
  13. *
  14. * This program is distributed in the hope that it will be useful,
  15. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  16. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  17. * GNU Affero General Public License for more details.
  18. *
  19. * You should have received a copy of the GNU Affero General Public License
  20. * along with this program. If not, see <https://www.gnu.org/licenses/>.
  21. */
  22. declare(strict_types=1);
  23. namespace App\Services\Spectre\Request;
  24. use App\Exceptions\ImporterErrorException;
  25. use App\Services\Shared\Response\Response;
  26. use App\Services\Spectre\Response\ErrorResponse;
  27. use App\Services\Spectre\Response\GetAccountsResponse;
  28. use GuzzleHttp\Exception\GuzzleException;
  29. use Illuminate\Support\Facades\Log;
  30. /**
  31. * Class GetAccountsRequest
  32. * TODO is not yet paginated.
  33. */
  34. class GetAccountsRequest extends Request
  35. {
  36. public string $connection;
  37. /**
  38. * ListConnectionsRequest constructor.
  39. */
  40. public function __construct(string $url, string $appId, string $secret)
  41. {
  42. $this->type = 'all';
  43. $this->setBase($url);
  44. $this->setAppId($appId);
  45. $this->setSecret($secret);
  46. $this->setUrl('accounts');
  47. }
  48. /**
  49. * @throws GuzzleException
  50. */
  51. public function get(): Response
  52. {
  53. Log::debug('GetAccountsRequest::get()');
  54. $this->setParameters(
  55. [
  56. 'connection_id' => $this->connection,
  57. ]
  58. );
  59. try {
  60. $response = $this->authenticatedGet();
  61. } catch (ImporterErrorException $e) {
  62. // JSON thing.
  63. return new ErrorResponse($e->json ?? []);
  64. }
  65. return new GetAccountsResponse($response['data']);
  66. }
  67. public function post(): Response
  68. {
  69. // Implement post() method.
  70. }
  71. public function put(): Response
  72. {
  73. // Implement put() method.
  74. }
  75. }