diff --git a/README.md b/README.md index e13b7af..86228d6 100644 --- a/README.md +++ b/README.md @@ -36,4 +36,6 @@ GithubSponsors::fromOrganization('Astrotomic')->all(); // all sponsors for given GithubSponsors::fromViewer()->cursor(); // lazy collection - using less memory GithubSponsors::fromViewer()->select('login', 'name', 'avatarUrl')->all(); // select specific attributes + +GithubSponsors::fromViewer()->isSponsor('Gummibeer'); // check if someone is a sponsor ``` diff --git a/src/GithubSponsors.php b/src/GithubSponsors.php index 3120121..6ae0940 100644 --- a/src/GithubSponsors.php +++ b/src/GithubSponsors.php @@ -11,6 +11,7 @@ use Illuminate\Support\Facades\Http; use Illuminate\Support\Fluent; use Illuminate\Support\LazyCollection; +use Illuminate\Support\Str; class GithubSponsors { @@ -66,6 +67,14 @@ public function all(): Collection return $this->cursor()->collect(); } + public function isSponsor(string $login): bool + { + return $this + ->select('login') + ->cursor() + ->contains(fn(Fluent $sponsor): bool => $sponsor->login === $login); + } + public function cursor(): LazyCollection { return LazyCollection::make(function (): Generator { diff --git a/tests/Feature/GithubSponsorsTest.php b/tests/Feature/GithubSponsorsTest.php index 93bab7a..bf401f7 100644 --- a/tests/Feature/GithubSponsorsTest.php +++ b/tests/Feature/GithubSponsorsTest.php @@ -61,3 +61,19 @@ ->__typename->toBeString()->toBeIn(['User', 'Organization']) ->login->toBeString(); }); + +it('checks if someone is a sponsor') + ->expect(fn() => GithubSponsors::fromOrganization('larabelles')->isSponsor('Gummibeer')) + ->toBeTrue(); + +it('checks if someone is a sponsor is casesensitive') + ->expect(fn() => GithubSponsors::fromOrganization('larabelles')->isSponsor('gummibeer')) + ->toBeFalse(); + +it('checks if someone is not a sponsor') + ->expect(fn() => GithubSponsors::fromViewer()->isSponsor('Gummibeer')) + ->toBeFalse(); + +it('checks if an organization is a sponsor') + ->expect(fn() => GithubSponsors::fromViewer()->isSponsor('spatie')) + ->toBeTrue();