Created
January 5, 2026 22:20
-
-
Save dabiddo/ad0fab27e50a2599fc40794a3363363c to your computer and use it in GitHub Desktop.
EB Ge properties
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <?php | |
| require_once 'PropertyDTO.php'; | |
| //This file must be inside src/ directory | |
| class ApiService { | |
| private string $apiKey = 'API_KEY'; //remember to put the API Key | |
| private string $baseUrl = 'https://api.stagingeb.com/v1/properties'; | |
| public function getProperties(int $page = 1): array { | |
| $url = $this->baseUrl . "?page=" . $page . "&limit=20"; | |
| $ch = curl_init($url); | |
| curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); | |
| curl_setopt($ch, CURLOPT_HTTPHEADER, [ | |
| 'X-Authorization: ' . $this->apiKey, | |
| 'accept: application/json' | |
| ]); | |
| $response = curl_exec($ch); | |
| $data = json_decode($response, true); | |
| curl_close($ch); | |
| $properties = []; | |
| if (isset($data['content'])) { | |
| foreach ($data['content'] as $item) { | |
| $properties[] = new PropertyDTO($item); | |
| } | |
| } | |
| return [ | |
| 'list' => $properties, | |
| 'total' => $data['pagination']['total'] ?? 0 | |
| ]; | |
| } | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <?php | |
| //Display the Property list from EasyBroker into cards with pagination. | |
| require_once 'src/ApiService.php'; | |
| $page = isset($_GET['page']) ? (int)$_GET['page'] : 1; | |
| $service = new ApiService(); | |
| $result = $service->getProperties($page); | |
| $properties = $result['list']; | |
| ?> | |
| <!DOCTYPE html> | |
| <html lang="en"> | |
| <head> | |
| <meta charset="UTF-8"> | |
| <title>Property Listing</title> | |
| <style> | |
| body { font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif; background: #f4f7f6; padding: 20px; } | |
| .grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(300px, 1fr)); gap: 20px; } | |
| .card { background: white; border-radius: 10px; overflow: hidden; box-shadow: 0 4px 6px rgba(0,0,0,0.1); } | |
| .card img { width: 100%; height: 200px; object-fit: cover; } | |
| .card-content { padding: 15px; } | |
| .price { color: #27ae60; font-weight: bold; font-size: 1.2em; } | |
| .location { font-size: 0.9em; color: #666; } | |
| .nav { margin-top: 30px; text-align: center; } | |
| .btn { padding: 10px 20px; background: #3498db; color: white; text-decoration: none; border-radius: 5px; } | |
| </style> | |
| </head> | |
| <body> | |
| <h1>Available Properties (Total: <?= $result['total'] ?>)</h1> | |
| <div class="grid"> | |
| <?php foreach ($properties as $prop): ?> | |
| <div class="card"> | |
| <img src="<?= $prop->image ?>" alt="Property Image"> | |
| <div class="card-content"> | |
| <div class="price"><?= $prop->currency ?> <?= $prop->price ?></div> | |
| <h3><?= htmlspecialchars($prop->title) ?></h3> | |
| <p class="location">📍 <?= htmlspecialchars($prop->location) ?></p> | |
| <small>Tipo: <?= $prop->type ?> | ID: <?= $prop->id ?></small> | |
| </div> | |
| </div> | |
| <?php endforeach; ?> | |
| </div> | |
| <div class="nav"> | |
| <?php if ($page > 1): ?> | |
| <a href="?page=<?= $page - 1 ?>" class="btn">Previous Page</a> | |
| <?php endif; ?> | |
| <a href="?page=<?= $page + 1 ?>" class="btn">Next Page</a> | |
| </div> | |
| </body> | |
| </html> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <?php | |
| //This file must be inside the src/ directory | |
| //Since we only need to display the Property basic info, the DTO will be basic | |
| class PropertyDTO { | |
| public string $id; | |
| public string $title; | |
| public string $image; | |
| public string $location; | |
| public string $price; | |
| public string $currency; | |
| public string $type; | |
| public function __construct(array $data) { | |
| $this->id = $data['public_id'] ?? 'N/A'; | |
| $this->title = $data['title'] ?? 'N/A'; | |
| $this->image = $data['title_image_thumb'] ?? 'https://placehold.co/600x400'; | |
| $this->location = $data['location'] ?? 'Unknown'; | |
| $this->type = $data['property_type'] ?? 'Property'; | |
| $this->price = $data['operations'][0]['formatted_amount'] ?? 'N/A'; | |
| $this->currency = $data['operations'][0]['currency'] ?? 'MX'; | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment