Merge pull request #1890 from CachetHQ/fixes

Fixed the integrations
This commit is contained in:
Graham Campbell
2016-06-03 17:11:00 +01:00
4 changed files with 41 additions and 11 deletions

View File

@@ -69,7 +69,7 @@ class DashboardController extends Controller
$subscribers = $this->getSubscribers();
$entries = null;
if ($feed = $this->feed->entries()) {
if ($feed = $this->feed->latest()) {
$entries = array_slice($feed->channel->item, 0, 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;
}
}

View File

@@ -29,6 +29,13 @@ class Feed
*/
const URL = 'https://blog.alt-three.com/tag/cachet/rss';
/**
* The failed status indicator.
*
* @var int
*/
const FAILED = 1;
/**
* The cache repository instance.
*
@@ -58,13 +65,13 @@ class Feed
}
/**
* Returns the entries.
* Returns the latest entries.
*
* @return array
* @return array|null
*/
public function entries()
public function latest()
{
return $this->cache->remember('feeds', 720, function () {
$result = $this->cache->remember('feeds', 720, function () {
try {
$xml = simplexml_load_string((new Client())->get($this->url, [
'headers' => ['Accept' => 'application/rss+xml', 'User-Agent' => defined('CACHET_VERSION') ? 'cachet/'.constant('CACHET_VERSION') : 'cachet'],
@@ -72,8 +79,10 @@ class Feed
return json_decode(json_encode($xml));
} catch (Exception $e) {
// Do nothing, this isn't critical.
return self::FAILED;
}
});
return $result === self::FAILED ? null : $result;
}
}

View File

@@ -23,6 +23,13 @@ class Releases
*/
const URL = 'https://api.github.com/repos/cachethq/cachet/releases/latest';
/**
* The failed status indicator.
*
* @var int
*/
const FAILED = 1;
/**
* The cache repository instance.
*