Cleanup the segment repositories

This code should now work on guzzle 4, guzzle 5 and guzzle 6.
This commit is contained in:
Graham Campbell
2015-05-28 19:17:23 +01:00
parent 65b1038b84
commit e93fda4d53
3 changed files with 21 additions and 11 deletions

View File

@@ -19,14 +19,18 @@ use Illuminate\Database\QueryException;
class CacheRepository implements RepositoryInterface
{
/**
* The underlying segment repository instance.
*
* @var \CachetHQ\Cachet\Segment\RepositoryInterface
*/
protected $repository;
/**
* Instantiates a new instance of the Cache Repository.
* Create a new segment cache repository instance.
*
* @param \CachetHQ\Cachet\Segment\RepositoryInterface $repository
*
* @return void
*/
public function __construct(RepositoryInterface $repository)
{
@@ -34,14 +38,12 @@ class CacheRepository implements RepositoryInterface
}
/**
* Determines whether to use the segment_write_key setting or to fetch a new.
* Returns the segment write key.
*
* @return string
*/
public function fetch()
{
$writeKey = null;
// We might not be setup yet.
try {
// Firstly, does the setting exist?

View File

@@ -16,20 +16,24 @@ use GuzzleHttp\ClientInterface;
class HttpRepository implements RepositoryInterface
{
/**
* @var \Guzzle\GuzzleClient
* The guzzle client instance.
*
* @var \GuzzleHttp\ClientInterface
*/
protected $client;
/**
* The url to use.
*
* @var string
*/
protected $url;
/**
* Instantiates a new instance of the SegmentApi class.
* Create a new segment http repository instance.
*
* @param \Guzzle\GuzzleClient $client
* @param string $url
* @param \GuzzleHttp\ClientInterface $client
* @param string $url
*/
public function __construct(ClientInterface $client, $url)
{
@@ -38,12 +42,16 @@ class HttpRepository implements RepositoryInterface
}
/**
* Fetches the segment_write_key from the given url.
* Returns the segment write key.
*
* @return string
*/
public function fetch()
{
return $this->client->get($this->url)->json()['segment_write_key'];
$response = $this->client->get($this->url);
$body = json_decode($response->getBody());
return $body['segment_write_key'];
}
}

View File

@@ -14,7 +14,7 @@ namespace CachetHQ\Cachet\Segment;
interface RepositoryInterface
{
/**
* Returns the segment_write_key.
* Returns the segment write key.
*
* @return string
*/