Skip to content

Commit

Permalink
add isSponsor() method to check if someone is a sponsor
Browse files Browse the repository at this point in the history
  • Loading branch information
Gummibeer committed Aug 20, 2021
1 parent 2e378e7 commit 9bdabd9
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 0 deletions.
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
```
9 changes: 9 additions & 0 deletions src/GithubSponsors.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
use Illuminate\Support\Facades\Http;
use Illuminate\Support\Fluent;
use Illuminate\Support\LazyCollection;
use Illuminate\Support\Str;

class GithubSponsors
{
Expand Down Expand Up @@ -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 {
Expand Down
16 changes: 16 additions & 0 deletions tests/Feature/GithubSponsorsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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();

0 comments on commit 9bdabd9

Please sign in to comment.