StuRents API Helper
Install using composer:, (*1)
php composer.phar require sturents/api
Wait, what's Composer?
Composer is the de-facto package manager for PHP projects. If you haven't used it before it is very simple to set up., (*2)
- Visit the Composer download page and follow instructions to download composer into your project root.
- You should now have a file called
composer.phar in your project root. You can run various commands using this file.
- Start by running
php composer.phar init to create your composer.json file. This file stores all your project configuration and dependencies.
- Now either run the command at the top of the readme to install the StuRents API, or add
"sturents/api": "*" to the "require" object inside your composer.json file.
To use Composer dependencies inside a PHP file is simple - just the following to the top of your file:, (*3)
require_once __DIR__.'/vendor/autoload.php';
Now you can create or use any object without having to worry about requiring its files - Composer and PHP's autoloader will handle that for you., (*4)
Send a property to StuRents
$data = [
... // see https://sturents.com/software/developer/house-create
];
$create_house = new \Sturents\Api\CreateOrUpdateHouse(LANDLORD_ID, API_KEY);
$create_house->setJson($data);
try {
$create_house->send();
}
catch (\Exception $e){
echo "A problem happened: ".$e->getMessage();
}
var_dump($create_house->responseJson()->isSuccess()); // true if request succeeded
$affected_id = $create_house->responseAffectedProperty(); // outputs an integer
Fetch data from StuRents
$fetch_houses = new \Sturents\Api\FetchHouses(LANDLORD_ID, PUBLIC_KEY);
try {
$fetch_houses->fetchAll();
$properties = $fetch_houses->getProperties();
}
catch (\Exception $e){
echo "A problem happened: ".$e->getMessage();
}
echo count($properties) // echo, e.g. 1