private function apiCall($action, $data) {
    switch($this->_sandbox) {
      case true:
          $url = $this->_servers['sandbox'];
          break;
        default:
          $url = $this->_servers['production'];
    }

    switch($action) {
      case 'new':
        $url = $url.'/protected/json/users/new?api_key='.$this->_apiKey;
        $postData = http_build_query($data);
        $opts = array(
          'http' => array(
          'method'  => 'POST',
          'timeout' => $this->_serverTimeout,
          'header'  => "Content-Type: application/x-www-form-urlencoded\r\n" .
                       "Content-Length: ".strlen($postData) ."\r\n".
                       "User-Agent: phpSec (http://phpseclib.com)\r\n",
          'content' => $postData,
          'ignore_errors' => true,
        ));

      break;

      case 'verify':
        $url = $url.'/protected/json/verify/'.$data['token'].'/'.$data['authy_id'].'?api_key='.$this->_apiKey.'&force=true';

        $opts = array(
          'http' => array(
          'method'  => 'GET',
          'timeout' => $this->_serverTimeout,
          'header'  => "User-Agent: phpSec (http://phpseclib.com)",
          'ignore_errors' => true,
        ));

      break;

      case 'sms':
        $url = $url.'/protected/json/sms/'.$data['authy_id'].'?api_key='.$this->_apiKey;

        if($data['force'] === true) {
          $url = $url.'&force=true';
        }

        $opts = array(
          'http' => array(
          'method'  => 'GET',
          'timeout' => $this->_serverTimeout,
          'header'  => "User-Agent: phpSec (http://phpseclib.com)",
          'ignore_errors' => true,
        ));

      break;

    }

    $context = stream_context_create($opts);
    $result  = @file_get_contents($url, false, $context);

    if($result === false) {
      return false;
    }

    return json_decode($result);
   }
private function apiCall($action, $data) {
    switch($this->_sandbox) {
      case true:
          $url = $this->_servers['sandbox'];
          break;
        default:
          $url = $this->_servers['production'];
    }

    switch($action) {
      case 'new':
        $url = $url.'/protected/json/users/new?api_key='.$this->_apiKey;
        $postData = http_build_query($data);
        $opts = array(
          'http' => array(
          'method'  => 'POST',
          'timeout' => $this->_serverTimeout,
          'header'  => "Content-Type: application/x-www-form-urlencoded\r\n" .
                       "Content-Length: ".strlen($postData) ."\r\n".
                       "User-Agent: phpSec (http://phpseclib.com)\r\n",
          'content' => $postData,
          'ignore_errors' => true,
        ));

      break;

      case 'verify':
        $url = $url.'/protected/json/verify/'.$data['token'].'/'.$data['authy_id'].'?api_key='.$this->_apiKey.'&force=true';

        $opts = array(
          'http' => array(
          'method'  => 'GET',
          'timeout' => $this->_serverTimeout,
          'header'  => "User-Agent: phpSec (http://phpseclib.com)",
          'ignore_errors' => true,
        ));

      break;

      case 'sms':
        $url = $url.'/protected/json/sms/'.$data['authy_id'].'?api_key='.$this->_apiKey;

        if($data['force'] === true) {
          $url = $url.'&force=true';
        }

        $opts = array(
          'http' => array(
          'method'  => 'GET',
          'timeout' => $this->_serverTimeout,
          'header'  => "User-Agent: phpSec (http://phpseclib.com)",
          'ignore_errors' => true,
        ));

      break;

    }

    $context = stream_context_create($opts);
    $result  = @file_get_contents($url, false, $context);

    if($result === false) {
      return false;
    }

    return json_decode($result);
   }
private function apiCall ( $ action , $ data ) { switch ( $ this -> _sandbox ) { case true : $ url = $ this -> _servers [ 'sandbox' ] ; break ; default : $ url = $ this -> _servers [ 'production' ] ; } switch ( $ action ) { case 'new' : $ url = $ url . '/protected/json/users/new?api_key=' . $ this -> _apiKey ; $ postData = http_build_query ( $ data ) ; $ opts = array ( 'http' => array ( 'method' => 'POST' , 'timeout' => $ this -> _serverTimeout , 'header' => "Content-Type: application/x-www-form-urlencoded\r\n" . "Content-Length: " . strlen ( $ postData ) . "\r\n" . "User-Agent: phpSec (http://phpseclib.com)\r\n" , 'content' => $ postData , 'ignore_errors' => true , ) ) ; break ; case 'verify' : $ url = $ url . '/protected/json/verify/' . $ data [ 'token' ] . '/' . $ data [ 'authy_id' ] . '?api_key=' . $ this -> _apiKey . '&force=true' ; $ opts = array ( 'http' => array ( 'method' => 'GET' , 'timeout' => $ this -> _serverTimeout , 'header' => "User-Agent: phpSec (http://phpseclib.com)" , 'ignore_errors' => true , ) ) ; break ; case 'sms' : $ url = $ url . '/protected/json/sms/' . $ data [ 'authy_id' ] . '?api_key=' . $ this -> _apiKey ; if ( $ data [ 'force' ] === true ) { $ url = $ url . '&force=true' ; } $ opts = array ( 'http' => array ( 'method' => 'GET' , 'timeout' => $ this -> _serverTimeout , 'header' => "User-Agent: phpSec (http://phpseclib.com)" , 'ignore_errors' => true , ) ) ; break ; } $ context = stream_context_create ( $ opts ) ; $ result = @ file_get_contents ( $ url , false , $ context ) ; if ( $ result === false ) { return false ; } return json_decode ( $ result ) ; }
Performs a call to the Authy API.

@param string $action
Action to perform: should be 'new' or 'verify'

@param array $data
Data to perform the action with.

@throws \phpSec\Exception\IOException If the Auty API server is unreachable.

@return object
Decoded JSON results from Authy server.
Performs a call to the Authy API .