### Facade usage for Ahrefs endpoints Source: https://github.com/jeffersongoncalves/laravel-ahrefs/blob/master/README.md Usage examples via the facade. Shows how to call each endpoint with optional parameters. The 'mode' values accepted are 'domain' (default), 'subdomains', 'prefix', and 'exact' for backlinks(), refDomains(), organicKeywords(), and topPages(). ```php use JeffersonGoncalves\Ahrefs\Facades\Ahrefs; Ahrefs::domainRating('example.com'); Ahrefs::backlinks('example.com', mode: 'subdomains', limit: 50); Ahrefs::refDomains('example.com', mode: 'domain', limit: 100); Ahrefs::organicKeywords('example.com', mode: 'exact', country: 'us', limit: 20); Ahrefs::topPages('example.com', mode: 'domain', country: 'br', limit: 10); Ahrefs::keywordOverview(['laravel', 'php'], country: 'us'); // or a single keyword / comma-separated string Ahrefs::keywordOverview('laravel', country: 'us'); Ahrefs::keywordSuggestions('laravel', country: 'us', limit: 25); Ahrefs::serpOverview('laravel', country: 'us'); ``` -------------------------------- ### Install laravel-ahrefs with Composer Source: https://github.com/jeffersongoncalves/laravel-ahrefs/blob/master/README.md Install the package via Composer. ```bash composer require jeffersongoncalves/laravel-ahrefs ``` -------------------------------- ### Catch RequestException Source: https://github.com/jeffersongoncalves/laravel-ahrefs/blob/master/README.md Error handling example. A non-2xx response throws Illuminate\Http\Client\RequestException. ```php use Illuminate\Http\Client\RequestException; try { $rating = Ahrefs::domainRating('example.com'); } catch (RequestException $e) { // $e->response->status(), $e->response->json(), ... } ``` -------------------------------- ### Private get() helper in Ahrefs client Source: https://github.com/jeffersongoncalves/laravel-ahrefs/blob/master/resources/boost/skills/ahrefs-development/SKILL.md Builds the HTTP request with base URL, Bearer token, and JSON acceptance. Strips null query parameters via array_filter() and throws RequestException on non-2xx responses. Returns decoded JSON array or [] if not an array. ```php private function get(string $endpoint, array $query): array { $response = Http::baseUrl($this->baseUrl()) ->withToken($this->token()) ->acceptJson() ->get($endpoint, array_filter($query, fn ($value) => $value !== null)); $response->throw(); $data = $response->json(); return is_array($data) ? $data : []; } ``` -------------------------------- ### Run static analysis Source: https://github.com/jeffersongoncalves/laravel-ahrefs/blob/master/README.md Run static analysis. ```bash composer analyse ``` -------------------------------- ### Run tests Source: https://github.com/jeffersongoncalves/laravel-ahrefs/blob/master/README.md Run the test suite. ```bash composer test ``` -------------------------------- ### Run code formatting Source: https://github.com/jeffersongoncalves/laravel-ahrefs/blob/master/README.md Run code formatting. ```bash composer format ``` -------------------------------- ### Config options for ahrefs.php Source: https://github.com/jeffersongoncalves/laravel-ahrefs/blob/master/README.md Configuration file for the package. When 'ahrefs.token' is null, the client falls back to config('services.ahrefs.token'). ```php // config/ahrefs.php return [ 'token' => env('AHREFS_API_KEY'), 'base_url' => env('AHREFS_BASE_URL', 'https://api.ahrefs.com/v3'), ]; ``` -------------------------------- ### Publish ahrefs-config Source: https://github.com/jeffersongoncalves/laravel-ahrefs/blob/master/README.md Optionally publish the configuration file. ```bash php artisan vendor:publish --tag="ahrefs-config" ``` -------------------------------- ### Resolve Ahrefs client via app() Source: https://github.com/jeffersongoncalves/laravel-ahrefs/blob/master/README.md Alternative usage by injecting or resolving the underlying client. ```php use JeffersonGoncalves\Ahrefs\Ahrefs; $ahrefs = app(Ahrefs::class); $ahrefs->domainRating('example.com'); ``` -------------------------------- ### Set AHREFS_API_KEY in .env Source: https://github.com/jeffersongoncalves/laravel-ahrefs/blob/master/README.md Add your Ahrefs API token to the .env file. Generate a token at https://app.ahrefs.com/api/keys. ```env AHREFS_API_KEY=your-ahrefs-api-token ``` -------------------------------- ### Success test for domain rating Source: https://github.com/jeffersongoncalves/laravel-ahrefs/blob/master/resources/boost/skills/ahrefs-development/SKILL.md Uses Http::fake() to mock the domain-rating endpoint and asserts the client returns the expected array. The fake pattern includes the /v3 base path. ```php it('fetches the domain rating', function () { Http::fake([ 'api.ahrefs.com/v3/site-explorer/domain-rating*' => Http::response(['domain_rating' => 74.2], 200), ]); expect(app(Ahrefs::class)->domainRating('example.com'))->toBe(['domain_rating' => 74.2]); }); ``` -------------------------------- ### Token resolution method Source: https://github.com/jeffersongoncalves/laravel-ahrefs/blob/master/resources/boost/skills/ahrefs-development/SKILL.md Resolves the Bearer token from config('ahrefs.token') or falls back to config('services.ahrefs.token'). Returns empty string if not a string. ```php private function token(): string { $token = config('ahrefs.token') ?? config('services.ahrefs.token'); return is_string($token) ? $token : ''; } ``` -------------------------------- ### Error test for non-2xx response Source: https://github.com/jeffersongoncalves/laravel-ahrefs/blob/master/resources/boost/skills/ahrefs-development/SKILL.md Mocks a 401 response and asserts that the client throws RequestException. The fake pattern must match the full request path including /v3. ```php it('throws on a non-2xx response', function () { Http::fake([ 'api.ahrefs.com/v3/site-explorer/domain-rating*' => Http::response(['error' => 'unauthorized'], 401), ]); expect(fn () => app(Ahrefs::class)->domainRating('example.com')) ->toThrow(RequestException::class); }); ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.