2015-01-23 17:24:34 +00:00
|
|
|
<?php
|
|
|
|
|
2015-04-19 08:52:39 +01:00
|
|
|
/*
|
|
|
|
* This file is part of Cachet.
|
|
|
|
*
|
2015-07-06 17:37:01 +01:00
|
|
|
* (c) Alt Three Services Limited
|
2015-04-19 08:52:39 +01:00
|
|
|
*
|
|
|
|
* For the full copyright and license information, please view the LICENSE
|
|
|
|
* file that was distributed with this source code.
|
|
|
|
*/
|
|
|
|
|
2015-01-23 17:24:34 +00:00
|
|
|
namespace CachetHQ\Cachet\Segment;
|
|
|
|
|
|
|
|
use GuzzleHttp\ClientInterface;
|
|
|
|
|
|
|
|
class HttpRepository implements RepositoryInterface
|
|
|
|
{
|
|
|
|
/**
|
2015-05-28 19:17:23 +01:00
|
|
|
* The guzzle client instance.
|
|
|
|
*
|
|
|
|
* @var \GuzzleHttp\ClientInterface
|
2015-01-23 17:24:34 +00:00
|
|
|
*/
|
|
|
|
protected $client;
|
|
|
|
|
|
|
|
/**
|
2015-05-28 19:17:23 +01:00
|
|
|
* The url to use.
|
|
|
|
*
|
2015-01-23 17:24:34 +00:00
|
|
|
* @var string
|
|
|
|
*/
|
|
|
|
protected $url;
|
|
|
|
|
|
|
|
/**
|
2015-05-28 19:17:23 +01:00
|
|
|
* Create a new segment http repository instance.
|
2015-01-23 17:24:34 +00:00
|
|
|
*
|
2015-05-28 19:17:23 +01:00
|
|
|
* @param \GuzzleHttp\ClientInterface $client
|
|
|
|
* @param string $url
|
2015-01-23 17:24:34 +00:00
|
|
|
*/
|
|
|
|
public function __construct(ClientInterface $client, $url)
|
|
|
|
{
|
|
|
|
$this->client = $client;
|
|
|
|
$this->url = $url;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2015-05-28 19:17:23 +01:00
|
|
|
* Returns the segment write key.
|
2015-01-23 17:24:34 +00:00
|
|
|
*
|
|
|
|
* @return string
|
|
|
|
*/
|
|
|
|
public function fetch()
|
|
|
|
{
|
2015-05-28 19:17:23 +01:00
|
|
|
$response = $this->client->get($this->url);
|
|
|
|
|
|
|
|
$body = json_decode($response->getBody());
|
|
|
|
|
2015-05-29 20:32:14 +01:00
|
|
|
return $body->segment_write_key;
|
2015-01-23 17:24:34 +00:00
|
|
|
}
|
|
|
|
}
|