diff --git a/README.md b/README.md index f8984c6..fcea022 100644 --- a/README.md +++ b/README.md @@ -101,6 +101,16 @@ $client = new Client(getenv('GH_SPONSORS_TOKEN')); This will be the client we'll use throughout the rest of these docs. We'll re-use the `$client` variable in the below examples. +Additionally, you have two named constructors that you can use: `withEnv` that accepts an environment variable and `withToken` that accepts a token. + +```php +use GitHub\Sponsors\Client; + +$client = Client::withEnv('GH_SPONSORS_TOKEN'); + +$client = Client::withToken(getenv('GH_SPONSORS_TOKEN')); +``` + ### Initializing the client using Laravel If you're using Laravel, the client is already bound to the container as a singleton. Simply retrieve it from the container: diff --git a/src/Client.php b/src/Client.php index c4cd844..3567a35 100644 --- a/src/Client.php +++ b/src/Client.php @@ -20,6 +20,16 @@ public function __construct(string $token, Factory $http = null) $this->token = $token; } + public static function withEnv(string $env, Factory $http = null): self + { + return new self(getenv($env), $http); + } + + public static function withToken(string $token, Factory $http = null): self + { + return new self($token, $http); + } + public function viewer(): Viewer { return new Viewer($this);