Finished Guzzle implementation, started work on Endpoints.

This commit is contained in:
Junade Ali
2017-02-01 18:07:33 +00:00
parent a49c655e77
commit 5fcb00153b
15 changed files with 912 additions and 44 deletions

View File

@@ -10,6 +10,7 @@ namespace Cloudflare\API\Adapter;
use Cloudflare\API\Auth\Auth;
use GuzzleHttp\Client;
use Psr\Http\Message\ResponseInterface;
class Guzzle implements Adapter
{
@@ -20,8 +21,12 @@ class Guzzle implements Adapter
*/
public function __construct(Auth $auth, String $baseURI = "https://api.cloudflare.com/client/v4/")
{
$headers = $auth->getHeaders();
$this->client = new Client([
'base_uri' => $baseURI
'base_uri' => $baseURI,
'headers' => $headers,
'Accept' => 'application/json'
]);
}
@@ -29,34 +34,71 @@ class Guzzle implements Adapter
/**
* @inheritDoc
*/
public function get(String $uri, array $headers = array())
public function get(String $uri, array $headers = array()): ResponseInterface
{
$response = $this->client->get($uri, $headers);
var_dump((string)$response);
$response = $this->client->get($uri, ['headers' => $headers]);
return $response;
}
/**
* @inheritDoc
*/
public function post(String $uri, array $headers = array(), array $body = array())
public function post(String $uri, array $headers = array(), array $body = array()): ResponseInterface
{
// TODO: Implement post() method.
$response = $this->client->post($uri, [
'headers' => $headers,
'form_params' => $body
]
);
return $response;
}
/**
* @inheritDoc
*/
public function put(String $uri, array $headers = array(), array $body = array())
public function put(String $uri, array $headers = array(), array $body = array()): ResponseInterface
{
// TODO: Implement put() method.
$jsonBody = json_encode($body);
$response = $this->client->put($uri, [
'headers' => $headers,
'body' => $jsonBody
]
);
return $response;
}
/**
* @inheritDoc
*/
public function delete(String $uri, array $headers = array(), array $body = array())
public function patch(String $uri, array $headers = array(), array $body = array()): ResponseInterface
{
// TODO: Implement delete() method.
$jsonBody = json_encode($body);
$response = $this->client->patch($uri, [
'headers' => $headers,
'body' => $jsonBody
]
);
return $response;
}
/**
* @inheritDoc
*/
public function delete(String $uri, array $headers = array(), array $body = array()): ResponseInterface
{
$response = $this->client->delete($uri, [
'headers' => $headers,
'form_params' => $body
]
);
return $response;
}
}