Skip to content

Commit

Permalink
Merge branch 'riccagroup-master'
Browse files Browse the repository at this point in the history
  • Loading branch information
schaitanya committed Jul 27, 2017
2 parents 07f2ce7 + 881774b commit a83d8c6
Show file tree
Hide file tree
Showing 4 changed files with 103 additions and 20 deletions.
20 changes: 9 additions & 11 deletions composer.json
Original file line number Diff line number Diff line change
@@ -1,15 +1,13 @@
{
"name": "kickbox/kickbox",
"version": "2.2.2",
"version": "2.2.3",
"description": "Official kickbox API library client for PHP",
"homepage": "http://kickbox.io",
"authors": [
{
"name": "Chaitanya Surapaneni",
"email": "chaitanya.surapaneni@kickbox.io",
"homepage": "https://github.com/kickboxio"
}
],
"authors": [{
"name": "Chaitanya Surapaneni",
"email": "chaitanya.surapaneni@kickbox.io",
"homepage": "https://github.com/kickboxio"
}],
"keywords": [
"free",
"email",
Expand Down Expand Up @@ -38,13 +36,13 @@
"friendsofphp/php-cs-fixer": "^2.3"
},
"support": {
"email": "help@kickbox.io",
"email": "help@kickbox.io",
"docs": "https://docs.kickbox.io",
"issues": "https://github.com/kickboxio/kickbox-php/issues"
},
"scripts":{
"scripts": {
"test": "./vendor/bin/phpunit",
"fix-style": "./vendor/bin/php-cs-fixer fix ."
},
"license": "MIT"
}
}
52 changes: 52 additions & 0 deletions lib/Kickbox/Api/Kickbox.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,4 +31,56 @@ public function verify($email, array $options = [])

return $this->client->get('/v2/verify', $body, $options);
}

/**
* Start a verify batch process
* @param array $emails List of Email addresses
* @param array $options Options for PUT request
* @return \Kickbox\HttpClient\Response
*/
public function verifyBatch($emails, array $options = [])
{
if(empty($options['headers'])) {
$options['headers'] = [];
}
$options['headers'] = array_merge([
'Content-Type' => 'text/csv',
'X-Kickbox-Filename' => 'Batch API Process - '.date('m-d-Y-H-i-s')
], $options['headers']);
$emails = join("\n", $emails);
return $this->client->put('/v2/verify-batch', $emails, $options);
}

/**
* Get a batch result
* @param integer $id Batch ID to check
* @param array $options Options for GET request
* @return \Kickbox\HttpClient\Response
*/
public function getBatchResults($id, array $options = []) {
return $this->client->get('/v2/verify-batch/'.$id, [], $options);
}

/**
* Check if an email is isDisposable
* @param string $email Email address to check
* @param array $options Options for GET request
* @return \Kickbox\HttpClient\Response
*/
public function isDisposable($email, array $options = []) {
$options = array_merge([
'base_uri' => 'https://open.kickbox.io',
'api_version' => 'v1',
], $options);
return $this->client->get('/v1/disposable/'.$email, [], $options);
}

/**
* Check the credit balance
* @param array $options Options for GET request
* @return \Kickbox\HttpClient\Response
*/
public function getCreditBalance(array $options = []) {
return $this->client->get('/v2/balance', [], $options);
}
}
33 changes: 33 additions & 0 deletions lib/Kickbox/Api/KickboxInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,37 @@ interface KickboxInterface
* @throws \ErrorException|\RuntimeException
*/
public function verify($email, array $options = []);

/**
* @method verifyBatch
* @param array $emails
* @param array $options
* @return Response
* @throws \ErrorException|\RuntimeException
*/
public function verifyBatch($emails, array $options = []);

/**
* @param integer $id
* @param array $options
* @return Response
* @throws \ErrorException|\RuntimeException
*/
public function getBatchResults($id, array $options = []);


/**
* @param string $email
* @param array $options
* @return Response
* @throws \ErrorException|\RuntimeException
*/
public function isDisposable($email, array $options = []);

/**
* @param array $options
* @return Response
* @throws \ErrorException|\RuntimeException
*/
public function getCreditBalance(array $options = []);
}
18 changes: 9 additions & 9 deletions lib/Kickbox/HttpClient/HttpClient.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ class HttpClient implements HttpClientInterface
'base_uri' => 'https://api.kickbox.io',
'api_version' => 'v2',
'headers' => [
'user-agent' => 'kickbox-php/2.2.2 (https://github.com/kickboxio/kickbox-php)'
'user-agent' => 'kickbox-php/2.2.3 (https://github.com/kickboxio/kickbox-php)'
]
];

Expand Down Expand Up @@ -81,27 +81,27 @@ public function put($path, $body, array $options = [])

/**
* @param $path
* @param array $body
* @param $body
* @param string $httpMethod
* @param array $options
* @return Response
* @throws \ErrorException|\RuntimeException
*/
private function request($path, array $body = [], $httpMethod = 'GET', array $options = [])
private function request($path, $body, $httpMethod = 'GET', array $options = [])
{
if (isset($options['body'])) {
$body = array_merge($options['body'], $body);
}

$headers = [];
if (isset($options['headers'])) {
$headers = $options['headers'];
unset($options['headers']);
}

$options['body'] = json_encode($body);
unset($options['body']);

if(!empty($body))
$options['body'] = $body;

$options['headers'] = array_merge($headers, self::$options['headers']);
$options = array_merge($options, self::$options);
$options = array_merge(self::$options, $options);

try {
$response = $this->client->request($httpMethod, $path, $options);
Expand Down

0 comments on commit a83d8c6

Please sign in to comment.