library/PostcodeNl/Api/RestClient.php
protected function _doRestCall($url, array $data = [])
	{
		// Connect using cURL
		$ch = curl_init();
		// Set the HTTP request type
		curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'GET');
		// Set URL to connect to
		curl_setopt($ch, CURLOPT_URL, $url);
		// We want the response returned to us.
		curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
		// Maximum number of seconds allowed to set up the connection.
		curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, self::CONNECTTIMEOUT);
		// Maximum number of seconds allowed to receive the response.
		curl_setopt($ch, CURLOPT_TIMEOUT, self::TIMEOUT);

		// The Postcode.nl API uses HTTP BASIC authentication (https://en.wikipedia.org/wiki/Basic_access_authentication)
		curl_setopt($ch, CURLOPT_HTTPAUTH, CURLAUTH_BASIC);
		// Use key as 'username' and secret as 'password'
		curl_setopt($ch, CURLOPT_USERPWD, $this->_appKey .':'. $this->_appSecret);
		// Identify this client with a User Agent
		curl_setopt($ch, CURLOPT_USERAGENT, 'PostcodeNl_Api_RestClient/' . self::VERSION .' PHP/'. phpversion());

		// Various debug options
		if ($this->_debugEnabled)
		{
			curl_setopt($ch, CURLINFO_HEADER_OUT, true);
			curl_setopt($ch, CURLOPT_HEADER, true);
		}

		// Do the request
		$response = curl_exec($ch);
		// Remember the HTTP status code we receive
		$responseStatusCode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
		$responseStatusCodeClass = floor($responseStatusCode/100)*100;
		// Any errors? Remember them now.
		$curlError = curl_error($ch);
		$curlErrorNr = curl_errno($ch);

		if ($this->_debugEnabled)
		{
			$this->_debugData['request'] = curl_getinfo($ch, CURLINFO_HEADER_OUT);
			$this->_debugData['response'] = $response;

			// Strip off header that was added for debug purposes.
			$response = substr($response, strpos($response, "\r\n\r\n") + 4);
		}

		// And close the cURL handle
		curl_close($ch);

		if ($curlError)
		{
			// We could not connect, cURL has the reason. (we hope)
			throw new PostcodeNl_Api_RestClient_ClientException('Connection error `'. $curlErrorNr .'`: `'. $curlError .'`', $curlErrorNr);
		}

		// Parse the response as JSON, will be null if not parsable JSON.
		$jsonResponse = json_decode($response, true);

		$this->_lastResponseData = $jsonResponse;

		return [
			'statusCode' => $responseStatusCode,
			'statusCodeClass' => $responseStatusCodeClass,
			'data' => $jsonResponse,
		];
	}
protected function _doRestCall($url, array $data = [])
	{
		// Connect using cURL
		$ch = curl_init();
		// Set the HTTP request type
		curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'GET');
		// Set URL to connect to
		curl_setopt($ch, CURLOPT_URL, $url);
		// We want the response returned to us.
		curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
		// Maximum number of seconds allowed to set up the connection.
		curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, self::CONNECTTIMEOUT);
		// Maximum number of seconds allowed to receive the response.
		curl_setopt($ch, CURLOPT_TIMEOUT, self::TIMEOUT);

		// The Postcode.nl API uses HTTP BASIC authentication (https://en.wikipedia.org/wiki/Basic_access_authentication)
		curl_setopt($ch, CURLOPT_HTTPAUTH, CURLAUTH_BASIC);
		// Use key as 'username' and secret as 'password'
		curl_setopt($ch, CURLOPT_USERPWD, $this->_appKey .':'. $this->_appSecret);
		// Identify this client with a User Agent
		curl_setopt($ch, CURLOPT_USERAGENT, 'PostcodeNl_Api_RestClient/' . self::VERSION .' PHP/'. phpversion());

		// Various debug options
		if ($this->_debugEnabled)
		{
			curl_setopt($ch, CURLINFO_HEADER_OUT, true);
			curl_setopt($ch, CURLOPT_HEADER, true);
		}

		// Do the request
		$response = curl_exec($ch);
		// Remember the HTTP status code we receive
		$responseStatusCode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
		$responseStatusCodeClass = floor($responseStatusCode/100)*100;
		// Any errors? Remember them now.
		$curlError = curl_error($ch);
		$curlErrorNr = curl_errno($ch);

		if ($this->_debugEnabled)
		{
			$this->_debugData['request'] = curl_getinfo($ch, CURLINFO_HEADER_OUT);
			$this->_debugData['response'] = $response;

			// Strip off header that was added for debug purposes.
			$response = substr($response, strpos($response, "\r\n\r\n") + 4);
		}

		// And close the cURL handle
		curl_close($ch);

		if ($curlError)
		{
			// We could not connect, cURL has the reason. (we hope)
			throw new PostcodeNl_Api_RestClient_ClientException('Connection error `'. $curlErrorNr .'`: `'. $curlError .'`', $curlErrorNr);
		}

		// Parse the response as JSON, will be null if not parsable JSON.
		$jsonResponse = json_decode($response, true);

		$this->_lastResponseData = $jsonResponse;

		return [
			'statusCode' => $responseStatusCode,
			'statusCodeClass' => $responseStatusCodeClass,
			'data' => $jsonResponse,
		];
	}
protected function _doRestCall ( $ url , array $ data = [ ] ) { // Connect using cURL $ ch = curl_init ( ) ; // Set the HTTP request type curl_setopt ( $ ch , CURLOPT_CUSTOMREQUEST , 'GET' ) ; // Set URL to connect to curl_setopt ( $ ch , CURLOPT_URL , $ url ) ; // We want the response returned to us. curl_setopt ( $ ch , CURLOPT_RETURNTRANSFER , true ) ; // Maximum number of seconds allowed to set up the connection. curl_setopt ( $ ch , CURLOPT_CONNECTTIMEOUT , self :: CONNECTTIMEOUT ) ; // Maximum number of seconds allowed to receive the response. curl_setopt ( $ ch , CURLOPT_TIMEOUT , self :: TIMEOUT ) ; // The Postcode.nl API uses HTTP BASIC authentication (https://en.wikipedia.org/wiki/Basic_access_authentication) curl_setopt ( $ ch , CURLOPT_HTTPAUTH , CURLAUTH_BASIC ) ; // Use key as 'username' and secret as 'password' curl_setopt ( $ ch , CURLOPT_USERPWD , $ this -> _appKey . ':' . $ this -> _appSecret ) ; // Identify this client with a User Agent curl_setopt ( $ ch , CURLOPT_USERAGENT , 'PostcodeNl_Api_RestClient/' . self :: VERSION . ' PHP/' . phpversion ( ) ) ; // Various debug options if ( $ this -> _debugEnabled ) { curl_setopt ( $ ch , CURLINFO_HEADER_OUT , true ) ; curl_setopt ( $ ch , CURLOPT_HEADER , true ) ; } // Do the request $ response = curl_exec ( $ ch ) ; // Remember the HTTP status code we receive $ responseStatusCode = curl_getinfo ( $ ch , CURLINFO_HTTP_CODE ) ; $ responseStatusCodeClass = floor ( $ responseStatusCode / 100 ) * 100 ; // Any errors? Remember them now. $ curlError = curl_error ( $ ch ) ; $ curlErrorNr = curl_errno ( $ ch ) ; if ( $ this -> _debugEnabled ) { $ this -> _debugData [ 'request' ] = curl_getinfo ( $ ch , CURLINFO_HEADER_OUT ) ; $ this -> _debugData [ 'response' ] = $ response ; // Strip off header that was added for debug purposes. $ response = substr ( $ response , strpos ( $ response , "\r\n\r\n" ) + 4 ) ; } // And close the cURL handle curl_close ( $ ch ) ; if ( $ curlError ) { // We could not connect, cURL has the reason. (we hope) throw new PostcodeNl_Api_RestClient_ClientException ( 'Connection error `' . $ curlErrorNr . '`: `' . $ curlError . '`' , $ curlErrorNr ) ; } // Parse the response as JSON, will be null if not parsable JSON. $ jsonResponse = json_decode ( $ response , true ) ; $ this -> _lastResponseData = $ jsonResponse ; return [ 'statusCode' => $ responseStatusCode , 'statusCodeClass' => $ responseStatusCodeClass , 'data' => $ jsonResponse , ] ; }
Perform a REST call to the Postcode.nl API

@param string $url
@param array $data
@return array
@throws PostcodeNl_Api_RestClient_ClientException
Perform a REST call to the Postcode . nl API