. */ namespace FireflyIII\Services\FireflyIIIOrg\Update; use Exception; use FireflyIII\Exceptions\FireflyException; use GuzzleHttp\Client; use GuzzleHttp\Exception\GuzzleException; use JsonException; use Log; /** * Class UpdateRequest */ class UpdateRequest implements UpdateRequestInterface { /** * @param string $channel * * @return array * @throws FireflyException */ public function getVersion(string $channel): array { $uri = config('firefly.update_endpoint'); Log::debug(sprintf('Going to call %s', $uri)); try { $client = new Client(); $options = [ 'headers' => [ 'User-Agent' => sprintf('FireflyIII/%s/%s', config('firefly.version'), $channel), ], ]; $res = $client->request('GET', $uri, $options); } catch (GuzzleException|Exception $e) { throw new FireflyException(sprintf('Response error from update check: %s', $e->getMessage())); } if (200 !== $res->getStatusCode()) { throw new FireflyException(sprintf('Returned error code %d from update check.', $res->getStatusCode())); } $body = (string)$res->getBody(); try { $json = json_decode($body, true, 512, JSON_THROW_ON_ERROR); } catch (JsonException $e) { throw new FireflyException('Invalid JSON in server response.'); } if (!isset($json['firefly_iii'][$channel])) { throw new FireflyException(sprintf('Unknown update channel "%s"', $channel)); } return $json['firefly_iii'][$channel]; } }