inmovilla-api-client
is a PHP library that provides an interface for interacting with the Inmovilla real estate API. It simplifies requests, pagination, and data handling, allowing developers to focus on building applications.
Note: This project is not affiliated with, endorsed by, or maintained by Inmovilla.
- API Configuration: Easy setup using
.ini
files or arrays. - Request Handling: Supports batch requests and flexible filtering.
- DTOs: Data transfer objects for working with API data in a structured way.
- Pagination: Handles paginated responses seamlessly.
- PSR Compliance: Built with PSR-7, PSR-11, and PSR-18 standards.
- PHP: 7.4 or higher.
- Composer: For dependency management.
- Required PHP extensions:
ext-json
ext-curl
Install the package using Composer:
composer require inigo-aldama/inmovilla-api-client
Create a configuration file (e.g., config/api.ini
) with the following content:
api_url = "https://api.inmovilla.com/v1"
domain = "example.com"
agency = "my-agency"
password = "my-password"
language = 1
Load the configuration with:
use Inmovilla\ApiClient\ApiClientConfig;
$config = ApiClientConfig::fromIniFile('config/api.ini');
Alternatively, use an array for configuration:
$config = ApiClientConfig::fromArray([
'AGENCY' => 'my-agency',
'PASSWORD' => 'my-password',
'LANGUAGE' => 1,
'API_URL' => 'https://api.inmovilla.com/v1',
'DOMAIN' => 'example.com',
]);
This example demonstrates how to retrieve cities, their zones, and properties associated with those zones, as well as fetch detailed property information.
<?php
use Inmovilla\Repository\CiudadRepository;
use Inmovilla\Repository\ZonaRepository;
use Inmovilla\Repository\PropiedadRepository;
use Inmovilla\Repository\PropiedadFichaRepository;
$cities = $cityRepository->findAll();
foreach ($cities->items as $city) {
$zones = $zoneRepository->findByCity($city->cod_ciu);
foreach ($zones->items as $zone) {
$properties = $propertyRepository->findByZone($zone->cod_zona);
foreach ($properties->items as $property) {
$details = $propertyDetailsRepository->findOneByCodOffer($property->cod_ofer);
}
}
}
To add custom functionality to a repository, you can extend the base class and implement your own methods. Here’s an example of adding a method to fetch properties with an elevator:
<?php
namespace Inmovilla\Repository;
use Inmovilla\DTO\Pagination\PaginacionPropiedadesDTO;
class CustomPropertyRepository extends PropiedadRepository
{
public function findWithElevator(int $startPosition = 1, int $numElements = 100, string $order = 'precioinmo, precioalq'): PaginacionPropiedadesDTO
{
$where = $this->buildWhereClause(['ascensor' => 1]);
$response = $this->addRequest(PaginacionPropiedadesDTO::ARRAY_DATA_KEY, $startPosition, $numElements, $where, $order);
return PaginacionPropiedadesDTO::fromArray($response);
}
}
$customPropertyRepository = new CustomPropertyRepository($client);
$propertiesWithElevator = $customPropertyRepository->findWithElevator();
foreach ($propertiesWithElevator->items as $property) {
echo "Property: Ref=" . $property->ref . PHP_EOL;
}
If you want to bypass the repositories, you can use the API client directly to make custom requests:
<?php
use Inmovilla\ApiClient\ApiClientConfig;
use Inmovilla\ApiClient\ApiClientFactory;
use GuzzleHttp\Client as GuzzleClient;
use GuzzleHttp\Psr7\HttpFactory;
$config = ApiClientConfig::fromIniFile('config/api.ini');
$httpClient = new GuzzleClient();
$requestFactory = new HttpFactory();
$client = ApiClientFactory::createFromConfig($config, $httpClient, $requestFactory);
$request = new Request('properties', 1, 100, 'ascensor=1', 'precioinmo, precioalq');
$requestBatch = new RequestBatch();
$requestBatch->addRequest($request);
$response = $client->sendRequest($requestBatch);
foreach ($response['properties'] as $property) {
echo "Property: Ref=" . $property['ref'] . PHP_EOL;
}
The library uses DTOs (Data Transfer Objects) to map API responses to structured PHP objects. Below are the key DTOs and their purposes:
CiudadDTO
: Represents a city.ZonaDTO
: Represents a zone within a city.
PropiedadDTO
: Represents a property in a property listing.PropiedadFichaDTO
: Represents detailed information about a specific property. This is retrieved when querying property details using its offer code.
PaginacionPropiedadesDTO
: Handles paginated property listings.PaginacionCiudadesDTO
: Handles paginated city data.PaginacionZonasDTO
: Handles paginated zone data.PaginacionDestacadosDTO
: Handles paginated "featured" properties.
Run PHPUnit tests to validate functionality:
./vendor/bin/phpunit --testdox
- Fork the repository.
- Create a new branch (
git checkout -b feature/new-feature
). - Commit your changes (
git commit -m 'Add new feature'
). - Push to your branch (
git push origin feature/new-feature
). - Open a pull request.
This project is licensed under the MIT License.
- Author: Iñigo Aldama Gómez
- Repository: inmovilla-api-client