-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathHunter.php
200 lines (178 loc) · 4.18 KB
/
Hunter.php
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
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
<?php
namespace Hiraya;
use GuzzleHttp\Client;
use GuzzleHttp\Exception\RequestException;
class Hunter extends Client
{
const BASE_URI = 'https://api.hunter.io/v2/';
/** @var array */
protected $query = [];
/**
* Client constructor.
* @param string $apiKey
*/
public function __construct($apiKey)
{
parent::__construct();
$this->query = [
'api_key' => $apiKey,
];
}
/**
* Trigger API call
*
* @param $method
* @param $uri
* @param array $options
* @return string
*/
private function trigger($method, $uri, array $options = [])
{
try {
$response = parent::$method(self::BASE_URI.$uri, $options)
->getBody()
->getContents();
} catch (RequestException $e) {
$response = $e->getResponse()->getBody()->getContents();
}
return $response;
}
/**
* Returns all the email addresses from a domain
*
* @param string $domain
* @param array $options
* @return string
*/
public function searchDomain($domain, $options = [])
{
$this->query = array_merge($this->query, $options);
$query = array_merge($this->query, [
'domain' => $domain,
]);
return $this->trigger('GET', 'domain-search', [
'query' => $query,
]);
}
/**
* Generates the most likely email address from a domain
*
* @param $domain
* @param $first_name
* @param $last_name
* @return string
*/
public function findEmail($domain, $first_name, $last_name)
{
return $this->trigger('GET', 'email-finder', [
'query' => array_merge($this->query, [
'domain' => $domain,
'first_name' => $first_name,
'last_name' => $last_name,
])
]);
}
/**
* Verifies the deliverability of an email address
*
* @param $email
* @return string
*/
public function verifyEmail($email)
{
return $this->trigger('GET', 'email-verifier', [
'query' => array_merge($this->query, [
'email' => $email,
])
]);
}
/**
* Counts how many email addresses are there in a domain
*
* @param $domain
* @param string $type
* @return string
*/
public function countEmail($domain, $type = 'generic')
{
return $this->trigger('GET', 'email-count', [
'query' => [
'domain' => $domain,
'type' => $type,
]
]);
}
/**
* Retrieves information regarding your account
*
* @return string
*/
public function displayAccount()
{
return $this->trigger('GET', 'account', [
'query' => $this->query
]);
}
/**
* Retrieves all the leads saved in your account
*
* @return string
*/
public function listLeads()
{
return $this->trigger('GET', 'leads', [
'query' => $this->query
]);
}
/**
* Retrieves all the fields of a lead
*
* @param $id
* @return string
*/
public function getLead($id)
{
return $this->trigger('GET',"leads/$id", [
'query' => $this->query
]);
}
/**
* Creates a new lead
*
* @param $data
* @return string
*/
public function createLead(array $data)
{
return $this->trigger('POST', 'leads', [
'query' => $this->query,
'form_params' => $data,
]);
}
/**
* Updates an existing lead
*
* @param $id
* @param array $data
* @return string
*/
public function updateLead($id, array $data)
{
return $this->trigger('PUT', "leads/$id", [
'query' => $this->query,
'form_params' => $data,
]);
}
/**
* Deletes an existing lead
*
* @param $id
* @return string
*/
public function deleteLead($id)
{
return $this->trigger('DELETE',"leads/$id", [
'query' => $this->query
]);
}
}