Skip to content

Commit

Permalink
Added custom single house access and responses
Browse files Browse the repository at this point in the history
  • Loading branch information
M1ke committed Dec 1, 2016
1 parent e2c172f commit 6970472
Show file tree
Hide file tree
Showing 5 changed files with 44 additions and 7 deletions.
15 changes: 10 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,23 +33,28 @@ Now you can create or use any object without having to worry about requiring its
echo "A problem happened: ".$e->getMessage();
}

var_dump($send_houses->responseJson()->isSuccess());
var_dump($send_houses->responseJson()->isSuccess()); // true if request succeeded

$inserted = $send_houses->responseCountInserted(); // outputs number inserted
$updated = $send_houses->responseCountUpdated(); // outputs number updated

## Send one property to StuRents

$data = [
... // see https://sturents.com/software/developer/house-create
];
$send_houses = new \Sturents\Api\CreateOrUpdateHouses(LANDLORD_ID, API_KEY);
$send_houses->setJson($data);
$create_house = new \Sturents\Api\CreateOrUpdateHouses(LANDLORD_ID, API_KEY);
$create_house->setJson($data);
try {
$send_houses->send();
$create_house->send();
}
catch (\Exception $e){
echo "A problem happened: ".$e->getMessage();
}

var_dump($send_houses->responseJson()->isSuccess());
var_dump($create_house->responseJson()->isSuccess()); // true if request succeeded

$affected_id = $create_house->responseAffectedProperty(); // outputs an integer

## Fetch data from StuRents

Expand Down
2 changes: 1 addition & 1 deletion src/CreateOrUpdateHouse.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
* Class CreateOrUpdateHouse
* @package Sturents\Api
*/
class CreateOrUpdateHouse extends Send {
class CreateOrUpdateHouse extends SingleHouse {

public function send(){
$this->sendInternal(Fixtures::URI_HOUSE, Fixtures::METHOD_POST);
Expand Down
18 changes: 18 additions & 0 deletions src/SendHouses.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,22 @@ class SendHouses extends Send {
public function send(){
$this->sendInternal(Fixtures::URI_HOUSES, Fixtures::METHOD_POST);
}

/**
* @return string
*/
public function responseCountInserted(){
$json = $this->responseJson();

return (int) $json->counts->inserted;
}

/**
* @return string
*/
public function responseCountUpdated(){
$json = $this->responseJson();

return (int) $json->counts->updated;
}
}
14 changes: 14 additions & 0 deletions src/SingleHouse.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<?php
namespace Sturents\Api;

abstract class SingleHouse extends Send {

/**
* @return int
*/
public function responseAffectedProperty(){
$json = $this->responseJson();

return (int) $json->sturents_id;
}
}
2 changes: 1 addition & 1 deletion src/UpdateHouse.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
* Class UpdateHouse
* @package Sturents\Api
*/
class UpdateHouse extends Send {
class UpdateHouse extends SingleHouse {

public function send(){
$this->sendInternal(Fixtures::URI_HOUSE, Fixtures::METHOD_PUT);
Expand Down

0 comments on commit 6970472

Please sign in to comment.