Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Repair phpipam php client #16

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 8 additions & 19 deletions php-client/class.phpipam-api.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,17 +8,7 @@
*/
class phpipam_api_client {

/**
* Debug flag for curl
*
* (default value: false)
*
* @var bool
* @access public
*/
public $debug = false;

/**
/**
* API server URL
*
* (default value: false)
Expand Down Expand Up @@ -387,9 +377,7 @@ private function validate_php_extensions () {
* @return void
*/
public function set_debug ($debug = false) {
if(is_bool($debug)) {
$this->debug = $debug;
}
/* Do nothing. */
}

/**
Expand Down Expand Up @@ -656,7 +644,6 @@ private function curl_set_connection ($token_file) {
CURLOPT_RETURNTRANSFER => 1,
CURLOPT_URL => $url,
CURLOPT_HEADER => 0,
CURLOPT_VERBOSE => $this->debug,
CURLOPT_TIMEOUT => 30,
CURLOPT_HTTPHEADER => array("Content-Type: application/json"),
CURLOPT_USERAGENT => 'phpipam-api php class',
Expand All @@ -681,7 +668,10 @@ private function curl_set_params ($params) {
// params set ?
if (is_array($params) && !$this->api_encrypt ) {
if (sizeof($params)>0) {
curl_setopt($this->Connection, CURLOPT_URL, $this->api_url.$this->api_app_id.str_replace("//", "/", "/".$this->api_server_controller."/".$this->api_server_identifiers."/?".http_build_query($params)));
if ($this->api_server_method === 'GET')
curl_setopt($this->Connection, CURLOPT_URL, $this->api_url.$this->api_app_id.str_replace("//", "/", "/".$this->api_server_controller."/".$this->api_server_identifiers."/?".http_build_query($params)));
else
curl_setopt($this->Connection, CURLOPT_POSTFIELDS, json_encode($params));
}
}
// encrypt
Expand Down Expand Up @@ -728,8 +718,8 @@ private function curl_add_token_header ($token_file) {
$token = @file($token_file);
// save token
if(isset($token[0])) {
$this->token = $token[0];
$this->token_expires = $token[1];
$this->token = trim($token[0]);
$this->token_expires = trim($token[1]);

// is token still valid ?
if (strlen($this->token)<2 && $this->token_expires < time()) {
Expand Down Expand Up @@ -860,7 +850,6 @@ private function curl_authenticate () {
CURLOPT_RETURNTRANSFER => 1,
CURLOPT_URL => $this->api_url.$this->api_app_id."/user/",
CURLOPT_HEADER => 0,
CURLOPT_VERBOSE => $this->debug,
CURLOPT_TIMEOUT => 30,
CURLOPT_USERAGENT => 'phpipam-api php class',
// ssl
Expand Down