-
Notifications
You must be signed in to change notification settings - Fork 8
Expand file tree
/
Copy pathzerobounce.php
More file actions
46 lines (45 loc) · 1.34 KB
/
zerobounce.php
File metadata and controls
46 lines (45 loc) · 1.34 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
<?php
class ZeroBounceAPI {
private $key;
private $baseURL = "https://api.zerobounce.net/v2/";
function __construct($key){
$this->key = $key;
}
/**
* this function is used for authentication and http api calls
*/
private function api_call($method, array $params){
$params['api_key'] = $this->key;
$paramsURI = http_build_query($params);
$url = "{$this->baseURL}{$method}?{$paramsURI}";
if(!isset($this->ch)){
$this->ch = curl_init();
curl_setopt($this->ch, CURLOPT_SSLVERSION, 6);
curl_setopt($this->ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($this->ch, CURLOPT_CONNECTTIMEOUT, 15);
curl_setopt($this->ch, CURLOPT_TIMEOUT, 150);
}
curl_setopt($this->ch, CURLOPT_URL, $url);
$response = curl_exec($this->ch);
$responseJSON = json_decode($response, true);
if(json_last_error() !== JSON_ERROR_NONE){
throw new \Exception("Invalid Response", 1);
}
if(isset($response['error'])){
throw new \Exception($response['error'], 2);
}
return $responseJSON;
}
/**
* wrapper for api_call/getcredits
*/
public function get_credits(){
return $this->api_call("getcredits",[]);
}
/**
* wrapper for api_call/validate
*/
public function validate($email, $ip){
return $this->api_call("validate",["email" => $email, "ip_address" => $ip]);
}
}