Skip to content

Instantly share code, notes, and snippets.

@mansha99
Created August 11, 2023 17:49
Show Gist options
  • Select an option

  • Save mansha99/f5cfe283737d5555bd751dcd86dc1b8b to your computer and use it in GitHub Desktop.

Select an option

Save mansha99/f5cfe283737d5555bd751dcd86dc1b8b to your computer and use it in GitHub Desktop.
Repository implementation
<?php
namespace App\Repos;
use App\Contracts\GithubUserRepo;
use Exception;
use Illuminate\Support\Facades\Http;
class GithubUserRepoHttpImpl implements GithubUserRepo
{
public function getUser(string $username)
{
$response = Http::get('https://api.github.com/users/' . $username);
if ($response->status() == 404) {
throw new Exception("User " . $username . " does not exist");
}
return $response->json();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment