1. Go to this page and download the library: Download albawebstudio/petfinder-api library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
namespace App\Http\Controllers;
use albawebstudio\PetfinderApi\PetfinderConnector;
class PetfinderApiController extends Controller
{
public function __construct()
{
PetfinderConnector::init(
config('petfinder.key'),
config('petfinder.secret'),
config('petfinder.organization'),
);
}
}
namespace App\Http\Controllers;
use albawebstudio\PetfinderApi\Animal;
use albawebstudio\PetfinderApi\exceptions\InvalidAuthorizationException;
use albawebstudio\PetfinderApi\exceptions\InvalidRequestException;
use albawebstudio\PetfinderApi\exceptions\PetfinderConnectorException;
class AnimalController extends PetfinderApiController
{
/**
* @var Animal
*/
protected Animal $api;
public function __construct()
{
parent::__construct();
$this->api = new Animal();
}
/**
* @throws InvalidAuthorizationException
* @throws InvalidRequestException
* @throws PetfinderConnectorException
*/
public function index()
{
return $this->api->animals([]);
}
/**
* @param int $animalId
* @return array
* @throws InvalidAuthorizationException
* @throws InvalidRequestException
* @throws PetfinderConnectorException
*/
public function show(int $animalId): array
{
return $this->api->animal($animalId);
}
/**
* Return all animal types from Petfinder
*
* @return array
* @throws InvalidAuthorizationException
* @throws InvalidRequestException
* @throws PetfinderConnectorException
*/
public function types(): array
{
return $this->api->types();
}
/**
* Return specific animal type from Petfinder
*
* @param string $type
* @return array
* @throws InvalidAuthorizationException
* @throws InvalidRequestException
* @throws PetfinderConnectorException
*/
public function type(string $type): array
{
return $this->api->type($type);
}
/**
* Return all breeds for specific animal type from Petfinder
* @param string $type
* @return array
* @throws InvalidAuthorizationException
* @throws InvalidRequestException
* @throws PetfinderConnectorException
*/
public function breeds(string $type): array
{
return $this->api->breeds($type);
}
}
namespace App\Http\Controllers;
use albawebstudio\PetfinderApi\exceptions\InvalidAuthorizationException;
use albawebstudio\PetfinderApi\exceptions\InvalidRequestException;
use albawebstudio\PetfinderApi\exceptions\PetfinderConnectorException;
use albawebstudio\PetfinderApi\Organization;
class OrganizationController extends PetfinderApiController
{
/**
* @var Organization
*/
protected Organization $api;
public function __construct()
{
parent::__construct();
$this->api = new Organization();
}
/**
* @return array
* @throws InvalidAuthorizationException
* @throws InvalidRequestException
* @throws PetfinderConnectorException
*/
public function index(): array
{
return $this->api->organizations([]);
}
/**
* @param string $organizationId
* @return array
* @throws InvalidAuthorizationException
* @throws InvalidRequestException
* @throws PetfinderConnectorException
*/
public function show(string $organizationId): array
{
return $this->api->organization($organizationId);
}
}