Fixed the integrations

This commit is contained in:
Graham Campbell
2016-06-03 17:07:36 +01:00
parent 3e8801d8d4
commit abf83361e8
4 changed files with 41 additions and 11 deletions
+19 -5
View File
@@ -11,6 +11,7 @@
namespace CachetHQ\Cachet\Integrations;
use Exception;
use GuzzleHttp\Client;
use Illuminate\Contracts\Cache\Repository;
@@ -23,6 +24,13 @@ class Credits
*/
const URL = 'https://cachethq.io/credits';
/**
* The failed status indicator.
*
* @var int
*/
const FAILED = 1;
/**
* The cache repository instance.
*
@@ -54,14 +62,20 @@ class Credits
/**
* Returns the latest credits.
*
* @return array
* @return array|null
*/
public function latest()
{
return $this->cache->remember('credits', 2880, function () {
return json_decode((new Client())->get($this->url, [
'headers' => ['Accept' => 'application/json', 'User-Agent' => defined('CACHET_VERSION') ? 'cachet/'.constant('CACHET_VERSION') : 'cachet'],
])->getBody(), true);
$result = $this->cache->remember('credits', 2880, function () {
try {
return json_decode((new Client())->get($this->url, [
'headers' => ['Accept' => 'application/json', 'User-Agent' => defined('CACHET_VERSION') ? 'cachet/'.constant('CACHET_VERSION') : 'cachet'],
])->getBody(), true);
catch (Exception $e) {
return self::FAILED;
}
});
return $result === self::FAILED ? null : $result;
}
}