zhan3333 / sturents-api
1.2.1
2017-08-11 12:56 UTC
Requires
- php: >=5.5.0
- guzzlehttp/guzzle: ~6.0
Requires (Dev)
- m1ke/git-php-lint: 1.0.0
README
Install using composer:
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.
- 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 yourcomposer.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 yourcomposer.json
file.
To use Composer dependencies inside a PHP file is simple - just the following to the top of your file:
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.
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