Code Monkey home page Code Monkey logo

sponsors's Introduction

Hi there ๐Ÿ‘‹

I'm Dries, open-source maintainer and one of the core team members of Laravel where I maintain the first-party libraries. I also do the weekly releases of all the first-party packages.

In my free time I've built and maintain various open-source projects of my own like:

  • Lemon Squeezy for Laravel - A package to easily integrate your Laravel application with Lemon Squeezy
  • Blade UI Kit - A set of renderless components to utilise in your Laravel Blade views
  • Blade Icons - Easily use SVG icons in your Laravel Blade views
  • Dotfiles - Start using dotfiles on your Mac
  • Laravel.io - The Laravel community portal
  • VatCalculator - Handle all the hard stuff related to EU MOSS tax/vat regulations

Working on open-source is my great joy in life and I want to be able to do that as much and as long as I possible can. I hope you like what I work on and that some of it is useful to you. Thanks for visiting!

If you found anything that I built useful for you or your company, consider sponsoring me โค๏ธ

sponsors's People

Contributors

caneco avatar driesvints avatar gummibeer avatar voidgraphics avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar

sponsors's Issues

Fake GraphQL requests with HTTP client

To speed things up we should fake the GraphQL requests. This will also be necessary to allow pull requests from GitHub since those won't be authenticated with a token and thus all PR's will fail.

We should also keep a portion of an integration test suite with a real token but those tests can be skipped if no token is set on the environment.

Automatically grant and revoke perks

One of the bigger features I'd like to develop over time for this library is the ability to automatically grant and revoke perks. The way that this would work is that the library would offer a common interface for granting and revoking perks as well as an integration with either GitHub Webhooks or the Laravel Scheduler to check periodically for updates and then handle revoking or granting perks.

The actual implementations of whatever perk would be a custom implementation for the consumer of the library. This would open the door for an entire ecosystem of perks like a collection of integrations with different services and what not.

The interface would look as follows:

interface Perk
{
    public function grant(): bool;
    public function revoke(): bool;
    public function tiers(): array;
}

A practical example could be to grant access to a Discord server when you're sponsoring someone:

final class DiscordServerPerk implements Perk
{
    public function grant(): bool
    {
        // handle the logic to grant access to the server...
    }

    public function revoke(): bool
    {
        // handle the logic to revoke access to the server...
    }

    public function tiers(): array
    {
        // return the tiers that allow access to this perk...
    }
}

By returning the tiers that allow access to the perk the library should be able to automatically grant or revoke the perk depending when a user is changing tiers. If they're changing to a new tier that's also in the tiers list of the perk, nothing would change of course.

This idea is a little rough and there's probably tons of edge cases but it would be worth to explore a PoC for this.

More sponsorship methods

Extend the API with even more useful methods:

// Check if driesvints has a sponsor listing...
$client->hasSponsorsListing('driesvints');

// Check if driesvints can sponsor nunomaduro...
$client->canSponsor('driesvints', 'nunomaduro');

// Check if driesvints is privately sponsored by nunomaduro...
$client->isPrivatelySponsoredBy('driesvints', 'nunomaduro');

Check sponsorship tiers

With this library it should be possible to check if users are sponsoring through specific tiers. This will allow for even more fine-graned ACL capabilities and perk-granting.

The API would look as something like below. The used token is that of the "driesvints" GitHub account.

// Check if nunomaduro is sponsoring driesvints on the "$5 a month" tier:
$client->hasTier('nunomaduro', '$5 a month');

// Through the Sponsorable trait...
$user->hasTier('$5 a month');

// If the Sponsorable has its own token set and wants to check if they are sponsoring on a specific account:
$user->hasTierOn('$5 a month', 'nunomaduro');

These requests would always need to be made from the viewer's standpoint so the used token will need to be properly set. These API's probably need to be fleshed out some more.

GraphQL field of "tier":

tier {
    closestLesserValueTier {
        name
    }
    createdAt
    isCustomAmount
    isOneTime
    monthlyPriceInCents
    monthlyPriceInDollars
    name
    updatedAt
}

All tiers also have internal ID's on their node through their GraphQL field. But these aren't surfaced in the UI of GitHub Sponsors.

Create new Sponsorships

With a newly added createSponsorship mutation to the GitHub GraphQL API it should be possible to integrate this into the library.

// Make the current authenticated user sponsor the target account...
$client->sponsor('driesvints');

It's only possible of course to start sponsorships from the authenticated account. So implementations of the Sponsorable trait should have their own token set.

Sync sponsorships with GitHub webhooks

It would be cool if we could sync incoming GitHub webhooks into a database table so sponsorships can be checked against a persistent storage instead of performing GraphQL API calls.

We could leverage Spatie's https://github.com/spatie/laravel-github-webhooks package for this maybe.

This is atm a pretty vague idea as I'm not sure how practically this would be. Would we only sync sponsorships for the authed user on the client? Or more?

Also see https://docs.github.com/en/developers/webhooks-and-events/webhooks/webhook-events-and-payloads#sponsorship

Dedicated docs site

Ideally we'd build a dedicated documentation website with separate PHP-only and Laravel sections so it's more clear how to use the library in specific situations.

Caching

Performing GraphQL calls can be costly and take quite a bit of time. Ideally I'd like to have dedicated caching support in the library. Most calls to check for sponsorships of GitHub users or to retrieve a list of sponsors don't need to be checked every second.

The way I see it we can ship a decorator for the GitHubSponsors client. This would look like as follows:

final class CachedGitHubSponsors
{
    public function __construct(
        private GitHubSponsors $client
    ) {}
    
    public function isSponsoredBy(string $account, string $sponsor, bool $isAccountAnOrganization = false): bool
    {
        // check cached status

        return $this->client->isSponsoredBy($account, $sponsor, $isAccountAnOrganization);
    }

    // ...
}

Maybe a common interface is needed?

I think this class should require a Psr\SimpleCache\CacheInterface implementation to handle the caching. For Laravel it can be retrieved from the already set cache store. We can add options to the github-sponsors.php config file to set the specific cache store and timeouts.

Retrieve sponsorships

Retrieving a list of sponsorships should be a core feature of this library. With this, people can display the sponsorships on their app/website as well as do additional syncing in their app. The sponsorships on a GitHub account can be retrieved with the sponsorshipsAsMaintainer field. Ideally, you we'd hydrate a new GitHubSponsor object with the data from the GitHub account.

The api could like like this:

// Retrieve all sponsors of driesvints...
$sponsors = $client->sponsors('driesvints');

// With the Sponsorable trait...
$sponsors = $user->sponsors();

// Check if a user has sponsors...
$sponsors = $user->hasSponsors();

Which would return a lazy collection. I'd also opt to implement a cursor based paginator approach as well:

// Retrieve all sponsors of driesvints...
$sponsors = $client->paginateSponsors('driesvints');

Which would return an instance of Illuminate\Pagination\CursorPaginator. I'd also make use of BuildsWithQueries to resolve the cursor from the request for a Laravel implementation. See PaginationState.

Drop organization methods

Ideally we'd like to get rid of the organization methods so the user doesn't needs to know up front if they're checking a user or organization. An idea opted by @claudiodekker was to perform both the user and organization query with the username login and check which one would give the result:

query { 
  user(login: "driesvints") {
    viewerIsSponsoring
  },
  organization(login: "driesvints") {
    viewerIsSponsoring
  }
}

I think this would work. We'd have to rewrite some internals but then we could drop organization specific methods in the library.

Implement a check to see if a username and token belong together

For our Sponsorable trait we offer to set a GitHub username and token on the implementing class. But we don't actually check if the user or the token belong together. It would be good if we offered a way to users to do this or to either do this ourselves in the library before making API requests.

The way we could check this is to auth the client with the token and retrieve the user details, then check if the username is the same as the one set on the object.

Track sponsored amounts

It'd be cool if the library could track sponsored amounts of users. This could enable new ways to grant users perks based on how much someone has sponsored already.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.