1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace wlbrough\clearbit; |
4
|
|
|
|
5
|
|
|
use wlbrough\clearbit\Abstracts\Api; |
6
|
|
|
|
7
|
|
|
class EnrichmentApi extends Api |
8
|
|
|
{ |
9
|
|
|
private static $apiUrlTemplate = 'https://pk:@%s%s.clearbit.com/v2/%s/find?%s=%s'; |
10
|
|
|
private $httpClient = null; |
11
|
|
|
|
12
|
24 |
|
public function __construct($key, $client = null) |
13
|
|
|
{ |
14
|
24 |
|
self::$apiUrlTemplate = preg_replace('(pk)', $key, self::$apiUrlTemplate); |
15
|
24 |
|
$this->httpClient = $client; |
16
|
24 |
|
} |
17
|
|
|
|
18
|
6 |
|
public function combined($email) |
19
|
|
|
{ |
20
|
6 |
|
$apiUrl = $this->composeUrl('person', 'combined', 'email', $email); |
21
|
6 |
|
return $this->call($apiUrl, $this->httpClient); |
22
|
|
|
} |
23
|
|
|
|
24
|
6 |
|
public function person($email, $subscribe = false) |
25
|
|
|
{ |
26
|
6 |
|
$apiUrl = $this->composeUrl('person', 'people', 'email', $email); |
27
|
|
|
|
28
|
6 |
|
if ($subscribe) { |
29
|
|
|
$apiUrl .= '&subscribe=true'; |
30
|
|
|
} |
31
|
|
|
|
32
|
6 |
|
return $this->call($apiUrl, $this->httpClient); |
33
|
|
|
} |
34
|
|
|
|
35
|
|
|
public function flagPerson($personId, $corrected = null) |
36
|
|
|
{ |
37
|
|
|
$apiUrl = "https://person.clearbit.com/v1/people/$personId/flag"; |
38
|
|
|
return $this->post($apiUrl, $corrected, 200, $this->httpClient); |
39
|
|
|
} |
40
|
|
|
|
41
|
6 |
|
public function company($domain) |
42
|
|
|
{ |
43
|
6 |
|
$apiUrl = $this->composeUrl('company', 'companies', 'domain', $domain); |
44
|
6 |
|
return $this->call($apiUrl, $this->httpClient); |
45
|
|
|
} |
46
|
|
|
|
47
|
3 |
|
public function flagCompany($domain, $corrected = null) |
48
|
|
|
{ |
49
|
|
|
$apiUrl = "https://company.clearbit.com/v2/companies/flag?domain=$domain"; |
50
|
|
|
return $this->post($apiUrl, $corrected, 200, $this->httpClient); |
51
|
3 |
|
} |
52
|
|
|
|
53
|
18 |
|
private function composeUrl($subdomain, $path, $query, $parameter) |
54
|
|
|
{ |
55
|
18 |
|
$streaming = $this->useStreaming ? '' : '-streaming'; |
56
|
18 |
|
return sprintf(self::$apiUrlTemplate, $subdomain, $streaming, $path, $query, $parameter); |
57
|
|
|
} |
58
|
|
|
} |
59
|
|
|
|