diff options
author | Miha Petkovsek <miha.petkovsek@gmail.com> | 2016-11-23 18:23:27 +0100 |
---|---|---|
committer | Miha Petkovsek <miha.petkovsek@gmail.com> | 2016-11-23 18:23:27 +0100 |
commit | 989c13160c781b9bf419cd84c0a9760e1c4e2b05 (patch) | |
tree | 70d2539bde716a323fd1819e1995339f931af680 | |
parent | 234d3667b356f192243fa019b993b65391b05469 (diff) | |
download | phpipam-api-clients-989c13160c781b9bf419cd84c0a9760e1c4e2b05.tar.gz |
Added response headers to API->response_headers
-rw-r--r-- | php-client/class.phpipam-api.php | 25 | ||||
-rw-r--r-- | php-client/example.php | 21 |
2 files changed, 37 insertions, 9 deletions
diff --git a/php-client/class.phpipam-api.php b/php-client/class.phpipam-api.php index 686a16b..a668dd2 100644 --- a/php-client/class.phpipam-api.php +++ b/php-client/class.phpipam-api.php @@ -200,6 +200,12 @@ class phpipam_api_client { "message" => "" ); + /** + * Reponse headers + * + * @var array + */ + public $response_headers = array (); @@ -538,7 +544,7 @@ class phpipam_api_client { * @return void */ public function set_api_identifiers ($identifiers) { - $this->api_server_identifiers = false; // clear this to forget any previous settings + $this->api_server_identifiers = false; // clear this to forget any previous settings if(is_array($identifiers)) { if(sizeof($identifiers)>0 && !$this->api_encrypt) { // reset @@ -624,6 +630,8 @@ class phpipam_api_client { // save result $this->result = (array) $res; } + // save reult + $this->curl_save_headers (); } /** @@ -654,7 +662,9 @@ class phpipam_api_client { CURLOPT_USERAGENT => 'phpipam-api php class', // ssl CURLOPT_SSL_VERIFYHOST => false, - CURLOPT_SSL_VERIFYPEER => false + CURLOPT_SSL_VERIFYPEER => false, + // save headers + CURLINFO_HEADER_OUT => true ) ); } @@ -825,6 +835,17 @@ class phpipam_api_client { } /** + * Store result code + * + * @method curl_save_result_code + * @return void + */ + private function curl_save_headers () { + // save result and result code + $this->response_headers = curl_getinfo($this->Connection); + } + + /** * send authenticate request and save token if provided, otherwise throw error. * * @access private diff --git a/php-client/example.php b/php-client/example.php index 9d3eb9e..483da00 100644 --- a/php-client/example.php +++ b/php-client/example.php @@ -16,15 +16,22 @@ $API = new phpipam_api_client ($api_url, $api_app_id, $api_key, $api_username, $ # debug - only to debug curl $API->set_debug (true); # execute - result is stored to $API->result, save it to own array if multiple calls needed after execute - -$API->execute ("POST", "addresses", array("first_free", "7"), array(), $token_file); - - -// $API->execute ("DELETE", "subnets", array(7, "permissions"), array(), $token_file); -// $API->execute ("POST", "vrf", array(), array("number"=>"114","name"=>"API"), $token_file); -# ger result +$API->execute ("GET", "addresses", array("first_free", "7"), array(), $token_file); +# get result $result = $API->get_result(); +/** + * Some examples + * + * Delete, POST examples + * $API->execute ("DELETE", "subnets", array(7, "permissions"), array(), $token_file); + * $API->execute ("POST", "vrf", array(), array("number"=>"114","name"=>"API"), $token_file); + * + * Get headers in array + * $response_headers = $API->response_headers (); + */ + # print result +print_r($response_headers); print_r(json_decode($result, true)); ?> |