Skip to content

Instantly share code, notes, and snippets.

@abhinavlal
Created October 25, 2012 13:52
Show Gist options
  • Save abhinavlal/3952660 to your computer and use it in GitHub Desktop.
Save abhinavlal/3952660 to your computer and use it in GitHub Desktop.
<?php
/*
* returns the DND Status of given phone number.
*
*/
require_once 'init.php';
class updateDNDStatus
{
private $_apiKey;
private $_httpClient;
public function __construct($apiKey) {
$this->_apiKey = $apiKey;
$this->_httpClient = new Zend_Http_Client("https://dncindia.com/dacx/jsonCommand");
}
public function scrubNumber($mobileNumber){
$filter = new Turbodoc_Forms_Filter_Mobile();
$filteredNumber = $filter->filter($mobileNumber);
$validator = new Turbodoc_Forms_Validator_Mobile();
if($validator->isValid($filteredNumber)){
$data = array(
'number' => substr($filteredNumber, 2, 12),
'apiKey' => $this->_apiKey,
'categories' => array(),
);
$dataEncoded = json_encode($data);
$this->_httpClient->setParameterGet("command", "singleScrubApi");
$this->_httpClient->setParameterGet("data", $dataEncoded);
$response = $this->_httpClient->request("GET");
if($response->getStatus() == 200){
var_dump(json_decode($response->getBody(), true));
}
else{
throw new Exception("Request Failed");
}
}
else{
throw new Exception("Mobile Number is not valid.");
}
}
}
$phone = $GLOBALS['argv']['1'];
$updateDND = new updateDNDStatus(API_KEY);
$updateDND->scrubNumber($phone);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment