aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorValentin Popov <info@valentineus.link>2020-07-18 15:00:14 +0300
committerValentin Popov <info@valentineus.link>2020-07-18 15:00:14 +0300
commit131be3511360ba4083caf72d40c47d3f6d5c473f (patch)
tree8fddd0160b130a754dbbca582dcde3cf1acc8bdd
parenta52e2e198708cf3e24eda73cbbc5906593cc730a (diff)
downloadphp-epg-service-131be3511360ba4083caf72d40c47d3f6d5c473f.tar.xz
php-epg-service-131be3511360ba4083caf72d40c47d3f6d5c473f.zip
Added week of program
Signed-off-by: Valentin Popov <info@valentineus.link>
-rw-r--r--src/Repositories/ProgramRepository.php22
-rw-r--r--tests/Repositories/ProgramRepositoryTest.php3
2 files changed, 20 insertions, 5 deletions
diff --git a/src/Repositories/ProgramRepository.php b/src/Repositories/ProgramRepository.php
index 494b957..56884da 100644
--- a/src/Repositories/ProgramRepository.php
+++ b/src/Repositories/ProgramRepository.php
@@ -24,6 +24,7 @@ use EPGService\Entities\Program\CreditEntity;
use EPGService\Entities\ProgramEntity;
use EPGService\Environments\ServiceEnvironment;
use GuzzleHttp\Client;
+use GuzzleHttp\RequestOptions;
use RuntimeException;
use function is_array;
@@ -49,11 +50,18 @@ final class ProgramRepository implements BaseRepository {
private Client $client;
/**
+ * @var string
+ */
+ private string $week;
+
+ /**
* @param \EPGService\Environments\ServiceEnvironment $environment
* @param string $channel_id
+ * @param string $week
*/
- private function __construct(ServiceEnvironment $environment, string $channel_id) {
+ private function __construct(ServiceEnvironment $environment, string $channel_id, string $week) {
$this->channel_id = $channel_id;
+ $this->week = $week;
$this->client = new Client([
'base_uri' => $environment->getUrl(),
@@ -63,11 +71,12 @@ final class ProgramRepository implements BaseRepository {
/**
* @param \EPGService\Environments\ServiceEnvironment $environment
* @param string $channel_id
+ * @param string $week
*
* @return \EPGService\Repositories\ProgramRepository
*/
- public static function create(ServiceEnvironment $environment, string $channel_id): ProgramRepository {
- return new ProgramRepository($environment, $channel_id);
+ public static function create(ServiceEnvironment $environment, string $channel_id, string $week): ProgramRepository {
+ return new ProgramRepository($environment, $channel_id, $week);
}
/**
@@ -156,7 +165,12 @@ final class ProgramRepository implements BaseRepository {
*/
public function get(): array {
$uri = sprintf(self::METHOD, $this->channel_id);
- $response = $this->client->get($uri);
+
+ $response = $this->client->get($uri, [
+ RequestOptions::QUERY => [
+ 'week' => $this->week,
+ ],
+ ]);
$content = $response->getBody()->getContents();
$json = json_decode($content, true, 512, JSON_THROW_ON_ERROR);
diff --git a/tests/Repositories/ProgramRepositoryTest.php b/tests/Repositories/ProgramRepositoryTest.php
index f8a32d7..f943bb6 100644
--- a/tests/Repositories/ProgramRepositoryTest.php
+++ b/tests/Repositories/ProgramRepositoryTest.php
@@ -36,11 +36,12 @@ final class ProgramRepositoryTest extends TestCase {
* @throws \Exception
*/
public function testGetAction(): void {
+ $week = date('Y-m-d', strtotime('this week'));
$env = GetServiceEnvironment::get();
$channels = ChannelRepository::create($env)->get();
$channel = array_shift($channels);
- foreach (ProgramRepository::create($env, $channel->id)->get() as $program) {
+ foreach (ProgramRepository::create($env, $channel->id, $week)->get() as $program) {
/** @var \EPGService\Entities\ProgramEntity $program */
self::assertNotEmpty($program->channel_id);