Skip to content

Commit

Permalink
update to guzzlehttp 6.2.1
Browse files Browse the repository at this point in the history
  • Loading branch information
JWaldecker committed Oct 11, 2016
1 parent 6b98035 commit 0002785
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 19 deletions.
16 changes: 11 additions & 5 deletions composer.json
Original file line number Diff line number Diff line change
@@ -1,28 +1,34 @@
{
"name": "zzantares/proxmoxve",
"name": "lumaserv/proxmoxve",
"type": "library",
"description": "A simple PHP 5.4+ Proxmox API client.",
"keywords": ["Proxmox", "API", "KVM", "OpenVZ", "Virtualization"],
"homepage": "https://github.com/ZzAntares/ProxmoxVE",
"license": "MIT",
"version": "1.1",

"authors": [
{
"name": "César Muñoz",
"email": "[email protected]",
"role": "Developer"
},
{
"name": "LUMASERV Systems",
"email": "[email protected]",
"role": "Developer"
}
],

"support": {
"issues": "https://github.com/ZzAntares/ProxmoxVE/issues",
"source": "https://github.com/ZzAntares/ProxmoxVE"
"issues": "https://github.com/LUMASERV/ProxmoxVE/issues",
"source": "https://github.com/LUMASERV/ProxmoxVE"
},

"require": {
"php": ">=5.3.0",
"php": ">=5.5",
"lib-curl": "*",
"guzzlehttp/guzzle": "~4.0"
"guzzlehttp/guzzle": "6.2.1"
},

"require-dev": {
Expand Down
37 changes: 23 additions & 14 deletions src/Proxmox.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,10 @@

namespace ProxmoxVE;

use GuzzleHttp\Client;
use ProxmoxVE\Exception\MalformedCredentialsException;
use ProxmoxVE\Exception\AuthenticationException;
use Psr\Http\Message\ResponseInterface;

/**
* ProxmoxVE class. In order to interact with the proxmox server, the desired
Expand Down Expand Up @@ -54,17 +56,18 @@ class Proxmox
*/
private $authToken;

/** @var Client $httpClient */
private $httpClient;


/**
* Constructor.
*
* @param mixed $credentials Credentials object or associative array holding
* the login data.
*
* @throws \ProxmoxVE\Exception\MalformedCredentialsException If bad args
* supplied.
* @throws \ProxmoxVE\Exception\AuthenticationException If given credentials
* are not valid.
* @param string $responseType
* @param null $httpClient
*/
public function __construct(
$credentials,
Expand All @@ -89,7 +92,7 @@ public function __construct(
* @param string $method HTTP method used in the request, by default
* 'GET' method will be used.
*
* @return \Guzzle\Http\Message\Response
* @return ResponseInterface
*
* @throws \InvalidArgumentException If the given HTTP method is not one of
* 'GET', 'POST', 'PUT', 'DELETE',
Expand All @@ -106,7 +109,8 @@ private function requestResource($actionPath, $params = [], $method = 'GET')
$headers = [
'CSRFPreventionToken' => $this->authToken->getCsrf(),
];
}
} else
$headers = [];

switch ($method) {
case 'GET':
Expand All @@ -123,7 +127,7 @@ private function requestResource($actionPath, $params = [], $method = 'GET')
'exceptions' => false,
'cookies' => $cookies,
'headers' => $headers,
'body' => $params,
'form_params' => $params,
]);
break;
case 'PUT':
Expand All @@ -132,7 +136,7 @@ private function requestResource($actionPath, $params = [], $method = 'GET')
'exceptions' => false,
'cookies' => $cookies,
'headers' => $headers,
'body' => $params,
'form_params' => $params,
]);
break;
case 'DELETE':
Expand All @@ -141,7 +145,7 @@ private function requestResource($actionPath, $params = [], $method = 'GET')
'exceptions' => false,
'cookies' => $cookies,
'headers' => $headers,
'body' => $params,
'form_params' => $params,
]);
break;
default:
Expand All @@ -154,7 +158,7 @@ private function requestResource($actionPath, $params = [], $method = 'GET')
/**
* Parses the response to the desired return type.
*
* @param string $response Response sent by the Proxmox server.
* @param ResponseInterface $response Response sent by the Proxmox server.
*
* @return mixed The parsed response, depending on the response type can be
* an array or a string.
Expand All @@ -163,12 +167,17 @@ private function processHttpResponse($response)
{
switch ($this->fakeType) {
case 'pngb64':
$base64 = base64_encode($response->getBody());
$base64 = base64_encode($response->getBody()->__toString());
return 'data:image/png;base64,' . $base64;
break;
case 'object': // 'object' not supported yet, we return array instead.
case 'array':
return $response->json();
$result = json_decode($response->getBody()->__toString(), true);
if (json_last_error() == JSON_ERROR_NONE) {
return $result;
} else {
return $response;
}
break;
default:
return $response->getBody()->__toString();
Expand All @@ -184,7 +193,7 @@ private function processHttpResponse($response)
*/
public function setHttpClient($httpClient = null)
{
$this->httpClient = $httpClient ?: new \GuzzleHttp\Client();
$this->httpClient = $httpClient ?: new Client();
}


Expand All @@ -210,7 +219,7 @@ public function login()
],
]);

$response = $response->json();
$response = json_decode($response->getBody()->__toString(), true);

if (!$response['data']) {
$error = 'Can not login using credentials: ' . $this->credentials;
Expand Down

0 comments on commit 0002785

Please sign in to comment.