-
Notifications
You must be signed in to change notification settings - Fork 19
Expand file tree
/
Copy pathUSEnrichmentGenericExample.php
More file actions
89 lines (70 loc) · 2.98 KB
/
Copy pathUSEnrichmentGenericExample.php
File metadata and controls
89 lines (70 loc) · 2.98 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
<?php
require_once(__DIR__ . '/../src/BasicAuthCredentials.php');
// require_once(__DIR__ . '/../src/SharedCredentials.php');
require_once(__DIR__ . '/../src/ClientBuilder.php');
require_once(__DIR__ . '/../src/US_Enrichment/Client.php');
require_once(__DIR__ . '/../src/US_Enrichment/Lookup.php');
use SmartyStreets\PhpSdk\BasicAuthCredentials;
// use SmartyStreets\PhpSdk\SharedCredentials;
use SmartyStreets\PhpSdk\ClientBuilder;
use SmartyStreets\PhpSdk\US_Enrichment\Result;
use SmartyStreets\PhpSdk\US_Enrichment\Lookup;
$lookupExample = new USEnrichmentGenericExample();
$lookupExample->run();
class USEnrichmentGenericExample
{
public function run()
{
// $authId = 'Your SmartyStreets Auth ID here';
// $authToken = 'Your SmartyStreets Auth Token here';
// We recommend storing your secret keys in environment variables instead---it's safer!
$authId = getenv('SMARTY_AUTH_ID');
$authToken = getenv('SMARTY_AUTH_TOKEN');
// For client-side requests (browser/mobile), use SharedCredentials:
// $credentials = new SharedCredentials($key, $hostname);
$credentials = new BasicAuthCredentials($authId, $authToken);
$client = (new ClientBuilder($credentials))
->buildUsEnrichmentApiClient();
// The generic lookup method allows you to specify any dataset and subset.
// This is useful for accessing new datasets that may not yet have dedicated methods.
//
// Available dataset/subset combinations include:
// "property" / "principal"
// "geo-reference" / null
// "secondary" / null
// "secondary" / "count"
$dataSetName = "property";
$dataSubsetName = "principal";
// You can send a lookup by SmartyKey:
// $smartyKey = "325023201";
// $result = $client->sendGenericLookup($smartyKey, $dataSetName, $dataSubsetName);
// Or by address using a Lookup object:
$lookup = new Lookup();
$lookup->setStreet("56 Union Ave");
$lookup->setCity("Somerville");
$lookup->setState("NJ");
$lookup->setZipcode("08876");
// You can also send an address in freeform:
// $lookup->setFreeform("56 Union Ave Somerville NJ 08876");
try {
$result = $client->sendGenericLookup($lookup, $dataSetName, $dataSubsetName);
if ($result != null) {
$this->displayResult($result[0]);
}
else {
echo("No results found. This means the address is likely not valid.\n");
}
}
catch (Exception $ex) {
echo($ex->getMessage());
}
}
public function displayResult(Result $result)
{
echo("Results for input: " . $result->smartyKey . ", " . $result->dataSetName . ", " . $result->dataSubsetName . "\n\n");
if ($result->matchedAddress != null) {
var_dump($result->matchedAddress);
}
var_dump($result->attributes);
}
}