Skip to content

Commit

Permalink
Helper Class Implementation (#3)
Browse files Browse the repository at this point in the history
* RealTagHelper Class Implementation

* Updated README.md with Helper Class Usage and Response Properties List

* updated unit test to reflect new Success/Error checking
  • Loading branch information
westonwatson authored May 31, 2019
1 parent d80efe9 commit dc1e798
Show file tree
Hide file tree
Showing 5 changed files with 304 additions and 89 deletions.
258 changes: 173 additions & 85 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,33 +9,180 @@ A PHP Client for the iLeads RealTag API ([Website](https://www.realtag.com/))
![GitHub contributors](https://img.shields.io/github/contributors/westonwatson/realtag.svg)
![GitHub issues](https://img.shields.io/github/issues/westonwatson/realtag.svg)

### Notes
* If you don't already use an autoloader and don't require the classes manually, the RealTag PHP Client will attempt to use Composer's Autoloader. So, if you're not using this library via Composer, make sure you include both the Client class and the Helper Class manually (`require`, `require_once`).
* You can request any attribute of the API response, realtag will lookup the requested property in all API Response Sections (ie- Property, EstimatedData, Forclosure, etc).
* The client library will trigger a PHP `E_USER_NOTICE` if something isn't configured correctly. Or an invalid property attribute is requested.
* The PHP RealTag Client defaults to Production Mode `$devMode == false`. Make sure to enable `$devMode` if you don't want to hit the production service.
* If you have any questions of comments, feel free to open a Github Issue, or submit a pull request with your proposed changes. Any/All Help is greatly appreciated! 😃

### Available Attributes

##### Success
##### Error
##### Product
##### Version
##### LeadID
##### Requested

##### OriginalRequest (stdClass)
> "FullName",
"AddressLine1",
"AddressLine2",
"City",
"State",
"Zip",
"ExternalID",
>>##### AllFields (stdClass)
>> "FullName",
"AddressLine1",
"City",
"State",
"Zip",
"ExternalID",
"AVM",
"ConfidenceScore",
"HighValue",
"LowValue",
"Value",

##### Foreclosure (stdClass)
> "NODorForeclosure",
"DefaultAmount",
"DefaultDate",

##### Property (stdClass)
> "IsHomeOwner",
"OwnerName",
"IsOwnerOccupied",
"Address",
"UnitNumber",
"City",
"State",
"Zip",
"APN",
"County",
"CensusTract",
"FIPSCode",
"FIPSCensusCombo",
"PropertyUse",
"LandUseDescription",
"CountyUse",
"StateLandUseDescription",
"Bathrooms",
"Bedrooms",
"BasementSqFt",
"Fireplaces",
"CentralCooling",
"ParkingType",
"GarageSqFt",
"GarageTotalCars",
"LandValue",
"LotAreaSqFt",
"Pool",
"TotalAssesedValueAmount",
"RoofSurfaceDescription",
"TotalLivingAreaSqFt",
"GrossLivingAreaSqFt",
"TotalAdjustmentLivingSqFt",
"TotalRooms",
"TotalStories",
"YearBuilt",
"Schooldistrict",
"Realestatetotaltaxamount",
"LastSaleDate",
"LastSalePrice",
"PricePerSquareFoot",
"Improvementvalue",
"Zoning",
"Taxyear",
"Totaltaxablevalueamount",
"PhoneNumber",
"MailingAddress",
"MailingCity",
"MailingState",
"MailingPostalCode",
"PlusFourPostalCode",
"HouseNumber",
"DirectionPrefix",
"StreetName",
"StreetSuffix",
"DirectionSuffix",
"ApartmentOrUnit",
"SiteInfluenceDescription",
"FloodZoneIdentifier",
"RoofTypeDescription",
"FoundationMaterialDescription",
"ConditionsDescription",
"ConstructionQualityTypeDescription",
"OtherPropertyImprovementsDescription",
"ExteriorWallsIdentifier",
"ConstructionTypeDescription",
"ImprovementValueAmount",
"BasementType",
"BasementDescription",
"BasementFinishedAreaSqFt",
"LenderName",
"TitleCompanyName",
"OpenLienAmount",
"OpenLienCount",
"LastLoanDate",

##### Liens (array)

> "TransactionNumber",
"TransactionType",
"SaleDocumentNumberIdentifier",
"SaleDeedTypeDescription",
"SaleDeedTypeDamarCode",
"SaleRecordingDate",
"SaleDate",
"OneSaleTypeDescription",
"SaleStampAmount",
"SalesPriceAmount",
"SaleSellerName",
"SaleBuyerNames",
"SaleTitleCompanyName",
"SaleTransferDocumentNumberIdentifier",
"SaleOwnerTransferIndicator",
"CorporateBuyer",
"Borrower1Names",
"VestingDescription",
"LastSaleIndicator",
"MortgageAmount",

##### EstimatedData (stdClass)
> "MortgageTerm",
"MortgageInterestRate",
"MortgagePayment",
"MortgageAgeInMonths",
"MortgageBalance",
"LTV",
"Equity",


### Example(s)

```
<?php
namespace Example\RealTagImplementation;
use westonwatson\realtag\RealTag;
use westonwatson\realtag\RealTagHelper;
class RealTagUsage
{
const MY_API_TOKEN = 'ThisTokenProvided/ByYour-iLeadsSalesRep==';
const MY_API_TOKEN = 'aNUn3eP7ep26ix/wDFDcZUEuFO5jxGEaL8a4hUW8q5FzoyQ5iCHyzg==';
/**
* @var bool
*/
private $devMode = false;
/**
* @var RealTag
*/
private $client;
/**
* @var array
* @var RealTagHelper
*/
private $lead = [];
private $realtag;
/**
* @var \stdClass
Expand All @@ -49,95 +196,36 @@ class RealTagUsage
*/
public function __construct($devMode = false)
{
$this->devMode = $devMode;
$this->client = new RealTag(self::MY_API_TOKEN, $devMode);
}
/**
* @param array $lead
*
* @throws \Exception
*/
public function setPropertyInfo(array $lead)
{
$this->lead = $lead;
$this->response = $this->client->call($lead);
echo "\nOUTPUT\n";
echo print_r($this->response, true);
}
/**
* @return mixed
*/
public function getPropertyCounty()
{
return $this->response->Property->County;
}
/**
* @return mixed
*/
public function getPropertyRoomCount()
{
return $this->response->Property->Bedrooms;
$this->realtag = new RealTagHelper(self::MY_API_TOKEN, $devMode);
}
/**
* @return mixed
*/
public function getPropertyBathCount()
public function getHomeEquityInfo()
{
return $this->response->Property->Bathrooms;
$this->realtag->setProperty([
"FullName" => "Barack Obama",
"AddressLine1" => "1600 Pennsylvania Ave., NW",
"City" => "Washington",
"State" => "DC",
"Zip" => "20500",
"ExternalID" => "change20500",
]);
}
/**
* @return mixed
*/
public function getPropertyZoningType()
public function showRoomCount()
{
return $this->response->Property->Zoning;
echo "This property has {$this->realtag->Bedrooms} bedrooms and {$this->realtag->Bedrooms} bathrooms.\n";
}
/**
* @return mixed
*/
public function getEstimatedMortgageTerm()
public function showMortgageTerm()
{
return $this->response->EstimatedData->MortgageTerm;
}
/**
* @return mixed
*/
public function getEstimatedMortgagePaymentAmount()
{
return $this->response->EstimatedData->MortgagePayment;
echo "The owner of this property pays an estimated \${$this->realtag->MortgagePayment}, {$this->realtag->MortgageTerm} times a year.\n";
}
}
$realtagUsage = new RealTagUsage(true);
$realtagUsage->setPropertyInfo(
[
"FullName" => "Barack Obama",
"AddressLine1" => "1600 Pennsylvania Ave., NW",
"City" => "Washington",
"State" => "DC",
"Zip" => "20500",
"ExternalID" => "change20500",
]
);
$roomCount = $realtagUsage->getPropertyRoomCount();
$bathCount = $realtagUsage->getPropertyBathCount();
echo "This property has {$roomCount} bedrooms and {$bathCount} bathrooms.\n";
$mortgageAmount = $realtagUsage->getEstimatedMortgagePaymentAmount();
$mortgageTerm = $realtagUsage->getEstimatedMortgageTerm();
echo "The owner of this property pays an estimated \${$mortgageAmount}, {$mortgageTerm} times a year.\n";
$realtagUsage->getHomeEquityInfo();
$realtagUsage->showMortgageTerm();
$realtagUsage->showRoomCount();
```


5 changes: 4 additions & 1 deletion src/HttpRequest.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,11 @@

interface HttpRequest
{
public function setUrl(string $url);
public function setHeaders(array $headers);
public function setPostData($data);
public function setOption(string $name, $value);
public function execute();
public function getInfo(string $name);
public function execute();
public function close();
}
15 changes: 13 additions & 2 deletions src/RealTag.php
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,10 @@ class RealTag
*/
public function __construct(string $token, $devMode = false, HttpRequest $curl_request = null)
{
require_once __DIR__ . '/../vendor/autoload.php';
if (!class_exists(\Composer\Autoload\ClassLoader::class)) {
trigger_error("Autoloader not found, manually requiring composer autoloader now...", E_USER_NOTICE);
require_once __DIR__ . '/../vendor/autoload.php';
}

$this->token = $token;
$this->endpoint = $devMode ? self::REALTAG_DEV_ENDPOINT : self::REALTAG_PROD_ENDPOINT;
Expand Down Expand Up @@ -87,7 +90,15 @@ public function call(array $data)

$raw_response = $this->ch->execute();

return $this->decodeResponse($raw_response);
$response = $this->decodeResponse($raw_response);

if (strlen($response->Error) > 0) {
trigger_error("RealTag API Error: {$response->Error}", E_USER_WARNING);
} elseif (!$response->Success) {
trigger_error("Unknown RealTag API Error Encountered", E_USER_WARNING);
}

return $response;
}

/**
Expand Down
Loading

0 comments on commit dc1e798

Please sign in to comment.