private function apiCall($command, $data=array()) {
			if (!isset($this->rest_commands[$command])) {
				return false;
			}

			$cmd = $this->rest_commands[$command];

			$url = $cmd['url'];
			$url = str_replace(array('{k}', '{s}') ,array($this->nx_key, $this->nx_secret), $url);

			$parsed_data = array();
			foreach ($data as $k => $v) $parsed_data['{'.$k.'}'] = $v;
			$url = str_replace(array_keys($parsed_data) ,array_values($parsed_data), $url);

			$url = trim($this->rest_base_url, '/') . $url;
			$post_data = '';

			// If available, use CURL
			if (function_exists('curl_version')) {

				$to_nexmo = curl_init( $url );
				curl_setopt( $to_nexmo, CURLOPT_RETURNTRANSFER, true );
				curl_setopt( $to_nexmo, CURLOPT_SSL_VERIFYPEER, false);
				curl_setopt($to_nexmo, CURLOPT_HTTPHEADER, array('Accept: application/json'));

				if ($cmd['method'] == 'POST') {
					curl_setopt( $to_nexmo, CURLOPT_POST, true );
					curl_setopt( $to_nexmo, CURLOPT_POSTFIELDS, $post_data );
				}

				$from_nexmo = curl_exec( $to_nexmo );
				$curl_info = curl_getinfo($to_nexmo);
				$http_response_code = $curl_info['http_code'];
				curl_close ( $to_nexmo );

			} elseif (ini_get('allow_url_fopen')) {
				// No CURL available so try the awesome file_get_contents

				$opts = array('http' =>
					array(
						'method'  => 'GET',
						'header'  => 'Accept: application/json'
					)
				);

				if ($cmd['method'] == 'POST') {
					$opts['http']['method'] = 'POST';
					$opts['http']['header'] .= "\r\nContent-type: application/x-www-form-urlencoded";
					$opts['http']['content'] = $post_data;
				}

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

				// et the response code
				preg_match('/HTTP\/[^ ]+ ([0-9]+)/i', $http_response_header[0], $m);
				$http_response_code = $m[1];

			} else {
				// No way of sending a HTTP post :(
				return false;
			}

			$data = json_decode($from_nexmo, true);
			return array(
				'data' => $data,
				'http_code' => (int)$http_response_code
			);

		}
private function apiCall($command, $data=array()) {
			if (!isset($this->rest_commands[$command])) {
				return false;
			}

			$cmd = $this->rest_commands[$command];

			$url = $cmd['url'];
			$url = str_replace(array('{k}', '{s}') ,array($this->nx_key, $this->nx_secret), $url);

			$parsed_data = array();
			foreach ($data as $k => $v) $parsed_data['{'.$k.'}'] = $v;
			$url = str_replace(array_keys($parsed_data) ,array_values($parsed_data), $url);

			$url = trim($this->rest_base_url, '/') . $url;
			$post_data = '';

			// If available, use CURL
			if (function_exists('curl_version')) {

				$to_nexmo = curl_init( $url );
				curl_setopt( $to_nexmo, CURLOPT_RETURNTRANSFER, true );
				curl_setopt( $to_nexmo, CURLOPT_SSL_VERIFYPEER, false);
				curl_setopt($to_nexmo, CURLOPT_HTTPHEADER, array('Accept: application/json'));

				if ($cmd['method'] == 'POST') {
					curl_setopt( $to_nexmo, CURLOPT_POST, true );
					curl_setopt( $to_nexmo, CURLOPT_POSTFIELDS, $post_data );
				}

				$from_nexmo = curl_exec( $to_nexmo );
				$curl_info = curl_getinfo($to_nexmo);
				$http_response_code = $curl_info['http_code'];
				curl_close ( $to_nexmo );

			} elseif (ini_get('allow_url_fopen')) {
				// No CURL available so try the awesome file_get_contents

				$opts = array('http' =>
					array(
						'method'  => 'GET',
						'header'  => 'Accept: application/json'
					)
				);

				if ($cmd['method'] == 'POST') {
					$opts['http']['method'] = 'POST';
					$opts['http']['header'] .= "\r\nContent-type: application/x-www-form-urlencoded";
					$opts['http']['content'] = $post_data;
				}

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

				// et the response code
				preg_match('/HTTP\/[^ ]+ ([0-9]+)/i', $http_response_header[0], $m);
				$http_response_code = $m[1];

			} else {
				// No way of sending a HTTP post :(
				return false;
			}

			$data = json_decode($from_nexmo, true);
			return array(
				'data' => $data,
				'http_code' => (int)$http_response_code
			);

		}
private function apiCall ( $ command , $ data = array ( ) ) { if ( ! isset ( $ this -> rest_commands [ $ command ] ) ) { return false ; } $ cmd = $ this -> rest_commands [ $ command ] ; $ url = $ cmd [ 'url' ] ; $ url = str_replace ( array ( '{k}' , '{s}' ) , array ( $ this -> nx_key , $ this -> nx_secret ) , $ url ) ; $ parsed_data = array ( ) ; foreach ( $ data as $ k => $ v ) $ parsed_data [ '{' . $ k . '}' ] = $ v ; $ url = str_replace ( array_keys ( $ parsed_data ) , array_values ( $ parsed_data ) , $ url ) ; $ url = trim ( $ this -> rest_base_url , '/' ) . $ url ; $ post_data = '' ; // If available, use CURL if ( function_exists ( 'curl_version' ) ) { $ to_nexmo = curl_init ( $ url ) ; curl_setopt ( $ to_nexmo , CURLOPT_RETURNTRANSFER , true ) ; curl_setopt ( $ to_nexmo , CURLOPT_SSL_VERIFYPEER , false ) ; curl_setopt ( $ to_nexmo , CURLOPT_HTTPHEADER , array ( 'Accept: application/json' ) ) ; if ( $ cmd [ 'method' ] == 'POST' ) { curl_setopt ( $ to_nexmo , CURLOPT_POST , true ) ; curl_setopt ( $ to_nexmo , CURLOPT_POSTFIELDS , $ post_data ) ; } $ from_nexmo = curl_exec ( $ to_nexmo ) ; $ curl_info = curl_getinfo ( $ to_nexmo ) ; $ http_response_code = $ curl_info [ 'http_code' ] ; curl_close ( $ to_nexmo ) ; } elseif ( ini_get ( 'allow_url_fopen' ) ) { // No CURL available so try the awesome file_get_contents $ opts = array ( 'http' => array ( 'method' => 'GET' , 'header' => 'Accept: application/json' ) ) ; if ( $ cmd [ 'method' ] == 'POST' ) { $ opts [ 'http' ] [ 'method' ] = 'POST' ; $ opts [ 'http' ] [ 'header' ] .= "\r\nContent-type: application/x-www-form-urlencoded" ; $ opts [ 'http' ] [ 'content' ] = $ post_data ; } $ context = stream_context_create ( $ opts ) ; $ from_nexmo = file_get_contents ( $ url , false , $ context ) ; // et the response code preg_match ( '/HTTP\/[^ ]+ ([0-9]+)/i' , $ http_response_header [ 0 ] , $ m ) ; $ http_response_code = $ m [ 1 ] ; } else { // No way of sending a HTTP post :( return false ; } $ data = json_decode ( $ from_nexmo , true ) ; return array ( 'data' => $ data , 'http_code' => ( int ) $ http_response_code ) ; }
Run a REST command on Nexmo SMS services
@param $command
@param array $data
@return array|bool
Run a REST command on Nexmo SMS services