feat(meetup): add Meetup implementation
This commit is contained in:
parent
f3eda70384
commit
5ab4097ace
|
@ -26,5 +26,5 @@ services:
|
||||||
# add more service definitions when explicit configuration is needed
|
# add more service definitions when explicit configuration is needed
|
||||||
# please note that last definitions always *replace* previous ones
|
# please note that last definitions always *replace* previous ones
|
||||||
App\EventRepository:
|
App\EventRepository:
|
||||||
class: App\Tests\FakeEventRepository
|
class: App\MeetupEventRepository
|
||||||
public: true
|
public: true
|
||||||
|
|
35
src/MeetupEventRepository.php
Normal file
35
src/MeetupEventRepository.php
Normal file
|
@ -0,0 +1,35 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App;
|
||||||
|
|
||||||
|
use Symfony\Contracts\HttpClient\HttpClientInterface;
|
||||||
|
use Tightenco\Collect\Support\Collection;
|
||||||
|
|
||||||
|
final class MeetupEventRepository implements EventRepository
|
||||||
|
{
|
||||||
|
private HttpClientInterface $client;
|
||||||
|
|
||||||
|
public function __construct(
|
||||||
|
HttpClientInterface $client
|
||||||
|
) {
|
||||||
|
$this->client = $client;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getConfirmedAttendees(): Collection
|
||||||
|
{
|
||||||
|
$response = $this->client->request('GET', 'https://api.meetup.com/php-south-wales/events/282265786/rsvps');
|
||||||
|
|
||||||
|
$rsvps = json_decode($response->getContent());
|
||||||
|
|
||||||
|
return Collection::make($rsvps)
|
||||||
|
->filter(fn (\stdClass $rsvp): bool => $rsvp->response == 'yes')
|
||||||
|
->filter(fn (\stdClass $attendee): bool => !$attendee->member->event_context->host)
|
||||||
|
->map(function (\stdClass $attendee): \stdClass {
|
||||||
|
$attendee->is_attending = true;
|
||||||
|
$attendee->is_host = false;
|
||||||
|
|
||||||
|
return $attendee;
|
||||||
|
})
|
||||||
|
;
|
||||||
|
}
|
||||||
|
}
|
|
@ -21,6 +21,6 @@ trait EventRepositoryContractTest
|
||||||
{
|
{
|
||||||
$attendees = $this->repository->getConfirmedAttendees();
|
$attendees = $this->repository->getConfirmedAttendees();
|
||||||
|
|
||||||
$this->assertFalse($attendees->pluck('is_host')->contains(true));
|
$this->assertSame([false], $attendees->pluck('is_host')->unique()->toArray());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -9,19 +9,24 @@ use Tightenco\Collect\Support\Collection;
|
||||||
|
|
||||||
final class FakeEventRepository implements EventRepository
|
final class FakeEventRepository implements EventRepository
|
||||||
{
|
{
|
||||||
private static array $rsvps = [
|
private static array $rsvps = [];
|
||||||
['name' => 'Oliver Davies.', 'is_attending' => true, 'is_host' => true],
|
|
||||||
['name' => 'matthew s.', 'is_attending' => true, 'is_host' => false],
|
public function __construct()
|
||||||
['name' => 'Michael P.', 'is_attending' => true, 'is_host' => false],
|
{
|
||||||
['name' => 'Kathryn "Kat" R.', 'is_attending' => true, 'is_host' => false],
|
self::$rsvps = [
|
||||||
['name' => 'Did not attend', 'is_attending' => false, 'is_host' => false],
|
(object) ['name' => 'Oliver Davies.', 'is_attending' => true, 'is_host' => true],
|
||||||
];
|
(object) ['name' => 'matthew s.', 'is_attending' => true, 'is_host' => false],
|
||||||
|
(object) ['name' => 'Michael P.', 'is_attending' => true, 'is_host' => false],
|
||||||
|
(object) ['name' => 'Kathryn "Kat" R.', 'is_attending' => true, 'is_host' => false],
|
||||||
|
(object) ['name' => 'Did not attend', 'is_attending' => false, 'is_host' => false],
|
||||||
|
];
|
||||||
|
}
|
||||||
|
|
||||||
public function getConfirmedAttendees(): Collection
|
public function getConfirmedAttendees(): Collection
|
||||||
{
|
{
|
||||||
return Collection::make(self::$rsvps)
|
return Collection::make(self::$rsvps)
|
||||||
->filter(fn (array $attendee): bool => $attendee['is_attending'])
|
->filter(fn (\stdClass $attendee): bool => $attendee->is_attending)
|
||||||
->filter(fn (array $attendee): bool => !$attendee['is_host'])
|
->filter(fn (\stdClass $attendee): bool => !$attendee->is_host)
|
||||||
;
|
;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -15,6 +15,10 @@ final class FakeEventRepositoryTest extends KernelTestCase
|
||||||
{
|
{
|
||||||
self::bootKernel();
|
self::bootKernel();
|
||||||
|
|
||||||
|
$container = static::$container;
|
||||||
|
|
||||||
|
$container->set(EventRepository::class, new FakeEventRepository());
|
||||||
|
|
||||||
$this->repository = static::$container->get(EventRepository::class);
|
$this->repository = static::$container->get(EventRepository::class);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
23
tests/MeetupEventRepositoryTest.php
Normal file
23
tests/MeetupEventRepositoryTest.php
Normal file
|
@ -0,0 +1,23 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Tests;
|
||||||
|
|
||||||
|
use App\EventRepository;
|
||||||
|
use Symfony\Bundle\FrameworkBundle\Test\KernelTestCase;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @group api
|
||||||
|
*/
|
||||||
|
final class MeetupEventRepositoryTest extends KernelTestCase
|
||||||
|
{
|
||||||
|
use EventRepositoryContractTest;
|
||||||
|
|
||||||
|
private EventRepository $repository;
|
||||||
|
|
||||||
|
public function setUp(): void
|
||||||
|
{
|
||||||
|
self::bootKernel();
|
||||||
|
|
||||||
|
$this->repository = self::$container->get(EventRepository::class);
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in a new issue