Use Guzzle, not Requests library.

This commit is contained in:
James Cole
2018-06-06 21:20:21 +02:00
parent 073dedd483
commit 20044427b4
9 changed files with 90 additions and 215 deletions

View File

@@ -26,7 +26,9 @@ namespace FireflyIII\Services\Github\Request;
use Exception;
use FireflyIII\Exceptions\FireflyException;
use FireflyIII\Services\Github\Object\Release;
use Requests;
use GuzzleHttp\Client;
use GuzzleHttp\Exception\GuzzleException;
use Log;
use SimpleXMLElement;
/**
@@ -41,30 +43,34 @@ class UpdateRequest implements GithubRequest
*
* @throws FireflyException
*/
public function call()
public function call(): void
{
$uri = 'https://github.com/firefly-iii/firefly-iii/releases.atom';
Log::debug(sprintf('Going to call %s', $uri));
try {
$response = Requests::get($uri);
} catch (Exception $e) {
$client = new Client();
$res = $client->request('GET', $uri);
} catch (GuzzleException|Exception $e) {
throw new FireflyException(sprintf('Response error from Github: %s', $e->getMessage()));
}
if ($response->status_code !== 200) {
throw new FireflyException(sprintf('Returned code %d, error: %s', $response->status_code, $response->body));
if ($res->getStatusCode() !== 200) {
throw new FireflyException(sprintf('Returned code %d, error: %s', $res->getStatusCode(), $res->getBody()->getContents()));
}
$releaseXml = new SimpleXMLElement($response->body, LIBXML_NOCDATA);
$releaseXml = new SimpleXMLElement($res->getBody()->getContents(), LIBXML_NOCDATA);
//fetch the products for each category
if (isset($releaseXml->entry)) {
Log::debug(sprintf('Count of entries is: %d', \count($releaseXml->entry)));
foreach ($releaseXml->entry as $entry) {
$array = [
$array = [
'id' => (string)$entry->id,
'updated' => (string)$entry->updated,
'title' => (string)$entry->title,
'content' => (string)$entry->content,
];
Log::debug(sprintf('Found version %s', $entry->title));
$this->releases[] = new Release($array);
}
}