From e93fda4d539b5a50eca81500cfae76bc9160f755 Mon Sep 17 00:00:00 2001 From: Graham Campbell Date: Thu, 28 May 2015 19:17:23 +0100 Subject: [PATCH] Cleanup the segment repositories This code should now work on guzzle 4, guzzle 5 and guzzle 6. --- app/Segment/CacheRepository.php | 10 ++++++---- app/Segment/HttpRepository.php | 20 ++++++++++++++------ app/Segment/RepositoryInterface.php | 2 +- 3 files changed, 21 insertions(+), 11 deletions(-) diff --git a/app/Segment/CacheRepository.php b/app/Segment/CacheRepository.php index 3d2aac6f..c561c719 100644 --- a/app/Segment/CacheRepository.php +++ b/app/Segment/CacheRepository.php @@ -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? diff --git a/app/Segment/HttpRepository.php b/app/Segment/HttpRepository.php index 029be396..f99570c1 100644 --- a/app/Segment/HttpRepository.php +++ b/app/Segment/HttpRepository.php @@ -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']; } } diff --git a/app/Segment/RepositoryInterface.php b/app/Segment/RepositoryInterface.php index aed580b1..bac83a2c 100644 --- a/app/Segment/RepositoryInterface.php +++ b/app/Segment/RepositoryInterface.php @@ -14,7 +14,7 @@ namespace CachetHQ\Cachet\Segment; interface RepositoryInterface { /** - * Returns the segment_write_key. + * Returns the segment write key. * * @return string */