Initial commit, WIP.
This commit is contained in:
26
src/API.php
Normal file
26
src/API.php
Normal file
@@ -0,0 +1,26 @@
|
||||
<?php
|
||||
/**
|
||||
* User: junade
|
||||
* Date: 13/01/2017
|
||||
* Time: 16:34
|
||||
*/
|
||||
|
||||
namespace Cloudflare\API;
|
||||
|
||||
|
||||
use Cloudflare\API\Auth\Auth;
|
||||
|
||||
class API
|
||||
{
|
||||
private $auth;
|
||||
|
||||
public function __construct(Auth $auth, bool $verifyAuth = true)
|
||||
{
|
||||
$this->auth = $auth;
|
||||
}
|
||||
|
||||
public function verifyAuth()
|
||||
{
|
||||
|
||||
}
|
||||
}
|
||||
65
src/Adapter/Adapter.php
Normal file
65
src/Adapter/Adapter.php
Normal file
@@ -0,0 +1,65 @@
|
||||
<?php
|
||||
/**
|
||||
* User: junade
|
||||
* Date: 13/01/2017
|
||||
* Time: 16:06
|
||||
*/
|
||||
|
||||
namespace Cloudflare\API\Adapter;
|
||||
|
||||
use Cloudflare\API\Auth\Auth;
|
||||
|
||||
/**
|
||||
* Interface Adapter
|
||||
* @package Cloudflare\API\Adapter
|
||||
* Note that the $body fields expect a JSON key value store.
|
||||
*/
|
||||
interface Adapter
|
||||
{
|
||||
/**
|
||||
* Adapter constructor.
|
||||
*
|
||||
* @param Auth $auth
|
||||
* @param String $baseURI
|
||||
*/
|
||||
public function __construct(Auth $auth, String $baseURI);
|
||||
|
||||
/**
|
||||
* Sends a GET request.
|
||||
* Per Robustness Principle - not including the ability to send a body with a GET request (though possible in the
|
||||
* RFCs, it is never useful).
|
||||
*
|
||||
* @param String $uri
|
||||
* @param array $headers
|
||||
*
|
||||
* @return mixed
|
||||
*/
|
||||
public function get(String $uri, array $headers);
|
||||
|
||||
/**
|
||||
* @param String $uri
|
||||
* @param array $headers
|
||||
* @param array $body
|
||||
*
|
||||
* @return mixed
|
||||
*/
|
||||
public function post(String $uri, array $headers, array $body);
|
||||
|
||||
/**
|
||||
* @param String $uri
|
||||
* @param array $headers
|
||||
* @param array $body
|
||||
*
|
||||
* @return mixed
|
||||
*/
|
||||
public function put(String $uri, array $headers, array $body);
|
||||
|
||||
/**
|
||||
* @param String $uri
|
||||
* @param array $headers
|
||||
* @param array $body
|
||||
*
|
||||
* @return mixed
|
||||
*/
|
||||
public function delete(String $uri, array $headers, array $body);
|
||||
}
|
||||
62
src/Adapter/Guzzle.php
Normal file
62
src/Adapter/Guzzle.php
Normal file
@@ -0,0 +1,62 @@
|
||||
<?php
|
||||
/**
|
||||
* User: junade
|
||||
* Date: 13/01/2017
|
||||
* Time: 18:26
|
||||
*/
|
||||
|
||||
namespace Cloudflare\API\Adapter;
|
||||
|
||||
|
||||
use Cloudflare\API\Auth\Auth;
|
||||
use GuzzleHttp\Client;
|
||||
|
||||
class Guzzle implements Adapter
|
||||
{
|
||||
private $client;
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
public function __construct(Auth $auth, String $baseURI = "https://api.cloudflare.com/client/v4/")
|
||||
{
|
||||
$this->client = new Client([
|
||||
'base_uri' => $baseURI
|
||||
]);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
public function get(String $uri, array $headers = array())
|
||||
{
|
||||
$response = $this->client->get($uri, $headers);
|
||||
var_dump((string)$response);
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
public function post(String $uri, array $headers = array(), array $body = array())
|
||||
{
|
||||
// TODO: Implement post() method.
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
public function put(String $uri, array $headers = array(), array $body = array())
|
||||
{
|
||||
// TODO: Implement put() method.
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
public function delete(String $uri, array $headers = array(), array $body = array())
|
||||
{
|
||||
// TODO: Implement delete() method.
|
||||
}
|
||||
}
|
||||
29
src/Auth/APIKey.php
Normal file
29
src/Auth/APIKey.php
Normal file
@@ -0,0 +1,29 @@
|
||||
<?php
|
||||
/**
|
||||
* User: junade
|
||||
* Date: 13/01/2017
|
||||
* Time: 16:55
|
||||
*/
|
||||
|
||||
namespace Cloudflare\API\Auth;
|
||||
|
||||
|
||||
class APIKey implements Auth
|
||||
{
|
||||
private $email;
|
||||
private $apiKey;
|
||||
|
||||
public function __construct(String $email, String $apiKey)
|
||||
{
|
||||
$this->email = $email;
|
||||
$this->apiKey = $apiKey;
|
||||
}
|
||||
|
||||
public function getHeaders(): array
|
||||
{
|
||||
return [
|
||||
'X-Auth-Email' => $this->email,
|
||||
'X-Auth-Key' => $this->apiKey
|
||||
];
|
||||
}
|
||||
}
|
||||
14
src/Auth/Auth.php
Normal file
14
src/Auth/Auth.php
Normal file
@@ -0,0 +1,14 @@
|
||||
<?php
|
||||
/**
|
||||
* User: junade
|
||||
* Date: 13/01/2017
|
||||
* Time: 16:52
|
||||
*/
|
||||
|
||||
namespace Cloudflare\API\Auth;
|
||||
|
||||
|
||||
interface Auth
|
||||
{
|
||||
public function getHeaders(): array;
|
||||
}
|
||||
26
src/Auth/UserServiceKey.php
Normal file
26
src/Auth/UserServiceKey.php
Normal file
@@ -0,0 +1,26 @@
|
||||
<?php
|
||||
/**
|
||||
* User: junade
|
||||
* Date: 13/01/2017
|
||||
* Time: 18:01
|
||||
*/
|
||||
|
||||
namespace Cloudflare\API\Auth;
|
||||
|
||||
|
||||
class UserServiceKey implements Auth
|
||||
{
|
||||
private $userServiceKey;
|
||||
|
||||
public function __construct(String $userServiceKey)
|
||||
{
|
||||
$this->userServiceKey = $userServiceKey;
|
||||
}
|
||||
|
||||
public function getHeaders(): array
|
||||
{
|
||||
return [
|
||||
'X-Auth-User-Service-Key' => $this->userServiceKey,
|
||||
];
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user