<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
jeffersongoncalves / laravel-zero-api-client example snippets
use JeffersonGoncalves\LaravelZero\ApiClient\ApiException;
final class GitHubApiException extends ApiException
{
// Optional: GitHub returns { "message": "..." }, already handled by the base.
}
use JeffersonGoncalves\LaravelZero\ApiClient\AbstractApiClient;
use JeffersonGoncalves\LaravelZero\ApiClient\ApiException;
use JeffersonGoncalves\LaravelZero\ApiClient\Auth;
final class GitHubClient extends AbstractApiClient
{
public function __construct(string $token)
{
parent::__construct('https://api.github.com', Auth::bearer($token));
}
protected function newApiException(int $statusCode, array $body): ApiException
{
return GitHubApiException::fromResponse($statusCode, $body);
}
public function repo(string $owner, string $repo): array
{
return $this->get("repos/{$owner}/{$repo}");
}
}