52 Commits
1.0.5 ... 1.1.1

Author SHA1 Message Date
Junade
a3a346ccb2 Merge pull request #62 from powerkent/fix-refresh-cache
fix: Cloudflare Api doesn't like empty tags
2018-08-28 15:01:57 +01:00
Junade
deb420d087 Update Zones.php 2018-08-28 14:58:25 +01:00
Junade
640b787540 Merge branch 'master' into fix-refresh-cache 2018-08-28 14:53:47 +01:00
Junade
8df0ec5511 Merge pull request #63 from maximivanov/feature/purgeCacheHosts
Add support for host-based cache purge
2018-08-28 14:49:49 +01:00
Junade
938065cdf3 Merge pull request #64 from mjrider/patch-1
Fixes issue with creating a MX record
2018-08-28 14:49:11 +01:00
Robbert Müller
9076d714f4 Fixes problem with creating an MX record
Fixes #60
php api expects a string and cloudflare api expects a int
this keeps everybody happy without changing API's
2018-08-28 08:47:50 +02:00
Max Ivanov
c9d2782b88 Add support for host-based cache purge 2018-08-23 16:13:56 +01:00
Lemoine
1cca3e0724 fix: Cloudflare Api doesn't like empty tags 2018-08-23 14:54:21 +02:00
Junade
63be6cf154 Merge pull request #54 from darinrandal/refactor-clean
Cleanup, refactoring, and removal of duplicate code
2018-05-19 21:23:57 +01:00
Darin Randal
c06fe79ad0 Removed more object casting 2018-04-12 23:19:09 -04:00
Darin Randal
cca073c809 Code cleanup / Quality of Life updates
Adapter::get, post, put, patch and delete all had non-optional parameters for $headers and $query or $body. These have been made optional. I also re-ordered the parameters as $headers was never used while $query/$body were heavily used. I also condensed and removed some duplicate calls so that every call to Adapter::get/post sends that call to Adapter::request. It could use a magic method to do this but it might make it more difficult to test.
2018-04-12 23:11:04 -04:00
Junade
35ce8eadf1 Merge pull request #51 from cloudflare/SOPS-161
SOPS-161 :: Add Custom Hostname endpoints to cloudflare-php
2018-03-18 23:47:42 -07:00
Junade Ali
d95573976e SOPS-161 :: Lint changes 2018-03-18 23:45:06 -07:00
Junade Ali
3bfd5e17f1 SOPS-161 :: Add Custom Hostname endpoints to cloudflare-php 2018-03-18 23:40:09 -07:00
Junade
19a4f481d3 Merge pull request #48 from anthonysterling/fix/issue-46
Nest payload for forwarding_url page rule action in value block
2018-03-05 14:21:59 -06:00
Junade
9c56941516 Merge pull request #49 from darinrandal/add-priority-for-dns-creation
MX records need ability to set priority
2018-03-05 14:20:38 -06:00
Darin Randal
e18a64e7e4 MX records need ability to set priority 2018-03-05 11:38:18 -05:00
Anthony Sterling
3585dde8ea Fixed merge conflict 2018-02-27 09:45:51 +00:00
Anthony Sterling
730b0c97ee Nest payload for forwarding_url page rule action in value block 2018-02-27 09:40:50 +00:00
Junade
dc53414c2a Merge pull request #45 from darinrandal/master
Fix name of jumpstart zone add option to jump_start
2018-01-30 14:30:46 +13:00
Darin Randal
a628cac283 Update phpdoc to match camelCase variable 2018-01-23 10:09:36 -05:00
Darin Randal
0112425a61 Rename $jump_start to $jumpStart to follow camelCase conventions for variables 2018-01-23 10:08:40 -05:00
Darin Randal
fe854e1b21 Update zone tests to reflect correctly named jumpstart option 2018-01-23 10:01:51 -05:00
Darin Randal
45cb8ee539 Fix name of jumpstart zone add option to jump_start 2018-01-23 09:57:14 -05:00
Junade
cd2fd73cc3 Merge pull request #42 from JorgenPhi/master
AnalyticsDashboard params are not headers
2017-12-26 18:52:26 +00:00
Jorgen Phillips
bd83c6d48a Fix test 2017-12-24 12:48:22 -06:00
Jorgen Phillips
4e3d307bdd AnalyticsDashboard params are not headers
Also 'continuous' needs to be a string for the API to process it.
2017-12-24 12:41:38 -06:00
Junade
99d89e7dc3 Merge pull request #39 from MeekLogic/master
Fixed checkError index out of range
2017-11-27 16:50:05 +08:00
Tyler Vigario
55e81fe02c Fixed checkError index out of range 2017-11-26 19:23:31 -08:00
Junade
d00a1d3f44 Merge pull request #38 from kleisauke/cleanup
Cleanup / fixes
2017-11-25 11:49:35 +08:00
Kleis Auke Wolthuizen
c8e85d2582 Add firewall access rules endpoint (#37)
* Add firewall access rules endpoint

* Configuration is an object

Maybe this needs to be defined in a seperate namespace (e.g. Cloudflare\API\Configuration) because it's no longer an array.

* Incorporate review
2017-11-25 11:45:18 +08:00
Kleis Auke Wolthuizen
ff42f334a5 PHP !== Java 2017-11-21 17:57:31 +01:00
Kleis Auke Wolthuizen
dfa299c895 Remove unused imports 2017-11-21 17:54:30 +01:00
Kleis Auke Wolthuizen
e1864a6824 Drop unneeded arguments 2017-11-21 17:52:59 +01:00
Kleis Auke Wolthuizen
c9d21466aa assertCount should be used instead 2017-11-21 17:50:28 +01:00
Kleis Auke Wolthuizen
b15b4ecc51 Class autoloading correctness 2017-11-21 17:49:29 +01:00
Kleis Auke Wolthuizen
0aa9f6c05a Fix null pointer exception 2017-11-21 17:48:03 +01:00
Kleis Auke Wolthuizen
a09478eb2f Return type doesn't match 2017-11-21 17:47:22 +01:00
Kleis Auke Wolthuizen
f6cb9a8e30 Argument PHPDoc missing 2017-11-21 17:46:53 +01:00
Kleis Auke Wolthuizen
bc9e15a557 Required parameter is missing 2017-11-21 17:46:07 +01:00
Kleis Auke Wolthuizen
5caae74370 Use $array[] instead of array_push 2017-11-21 17:43:47 +01:00
Kleis Auke Wolthuizen
ee4a42ea06 Replace alias functions with origin functions 2017-11-21 17:41:21 +01:00
Kleis Auke Wolthuizen
90eaea7be2 Use === null instead 2017-11-21 17:39:42 +01:00
Kleis Auke Wolthuizen
dac1e15e2d Fix loop which doesn't loop 2017-11-21 17:35:58 +01:00
Kleis Auke Wolthuizen
a4224265d8 Switch from stdClass to object casting 2017-11-21 17:35:01 +01:00
Kleis Auke Wolthuizen
4f3f82b1ba Remove redundant parentheses 2017-11-21 17:28:47 +01:00
Kleis Auke Wolthuizen
7c9ea4874d Shorten the fully qualified class names 2017-11-21 17:27:47 +01:00
Kleis Auke Wolthuizen
0920fc48b2 Remove unnecessary double quotes 2017-11-21 17:25:41 +01:00
Junade
65e4f29bc0 Merge pull request #35 from thellimist/patch-2
Add Contribution Document
2017-11-08 21:28:57 +01:00
Tyler Vigario
3453e44158 Added changeDevelopmentMode & getAnalyticsDashboard to Zones (#32)
* Added toggleDevelopmentMode to Zones

* Improved success checking
Added PHPUnit test (I think?)

* Fixed success checking

* Fixed test

* Ran PHP CS Fixer

* Added getAnalyticsDashboard to Zones
Renamed toggleDevelopmentMode to changeDevelopmentMode to be uniform

* Fixed test (hopefully)

* Trying it a different way

* Another attempt

* Lol I guess we are just supressing errors for this one?
2017-11-08 21:26:32 +01:00
Kan Yilmaz
8ee1bbcc6f Update README.md 2017-11-06 09:06:23 -08:00
Kan Yilmaz
d8b2093eed Create CONTRIBUTING.md 2017-11-06 09:04:19 -08:00
55 changed files with 1515 additions and 523 deletions

17
CONTRIBUTING.md Normal file
View File

@@ -0,0 +1,17 @@
# Contributing to Cloudflare PHP API Binding
👍🎉 First off, thanks for taking the time to contribute! 🎉👍
## How To Contribute
We welcome community contribution to this repository. To help add functionality or address issues, please take the following steps:
* Fork the repository from the master branch.
* Create a new branch for your features / fixes.
* Make the changes you wish to see.
* Add tests for all changes.
* Run `make fix` command to ensure the code is styled.
* Run `make test` command to ensure the tests pass.
* Create a pull request with details of what changes have been made and explanation of new behaviour.
* Ensure documentation contains the correct information.
* Pull requests will be reviewed and hopefully merged into a release.

View File

@@ -11,7 +11,6 @@ The recommended way to install this package is via the Packagist Dependency Mana
The Cloudflare API can be found [here](https://api.cloudflare.com/).
Each API call is provided via a similarly named function within various classes in the **Cloudflare\API\Endpoints** namespace:
- [x] [DNS Records](https://www.cloudflare.com/dns/)
- [x] Zones
- [x] User Administration (partial)
@@ -19,7 +18,7 @@ Each API call is provided via a similarly named function within various classes
- [x] [Page Rules](https://support.cloudflare.com/hc/en-us/articles/200168306-Is-there-a-tutorial-for-Page-Rules-)
- [x] [Web Application Firewall (WAF)](https://www.cloudflare.com/waf/)
- [ ] Virtual DNS Management
- [ ] Custom hostnames
- [x] Custom hostnames
- [x] Zone Lockdown and User-Agent Block rules
- [ ] Organization Administration
- [x] [Railgun](https://www.cloudflare.com/railgun/) administration
@@ -38,6 +37,10 @@ $user = new Cloudflare\API\Endpoints\User($adapter);
echo $user->getUserID();
```
## Contributions
We welcome community contribution to this repository. [CONTRIBUTING.md](CONTRIBUTING.md) will help you start contributing.
## Licensing
Licensed under the 3-clause BSD license. See the [LICENSE](LICENSE) file for details.

View File

@@ -21,55 +21,56 @@ interface Adapter
* Adapter constructor.
*
* @param Auth $auth
* @param String $baseURI
* @param string $baseURI
*/
public function __construct(Auth $auth, 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 string $uri
* @param array $data
* @param array $headers
*
* @return mixed
*/
public function get(String $uri, array $query, array $headers): ResponseInterface;
public function get(string $uri, array $data = [], array $headers = []): ResponseInterface;
/**
* @param String $uri
* @param string $uri
* @param array $data
* @param array $headers
* @param array $body
*
* @return mixed
*/
public function post(String $uri, array $headers, array $body): ResponseInterface;
public function post(string $uri, array $data = [], array $headers = []): ResponseInterface;
/**
* @param String $uri
* @param string $uri
* @param array $data
* @param array $headers
* @param array $body
*
* @return mixed
*/
public function put(String $uri, array $headers, array $body): ResponseInterface;
public function put(string $uri, array $data = [], array $headers = []): ResponseInterface;
/**
* @param String $uri
* @param string $uri
* @param array $data
* @param array $headers
* @param array $body
*
* @return mixed
*/
public function patch(String $uri, array $headers, array $body): ResponseInterface;
public function patch(string $uri, array $data = [], array $headers = []): ResponseInterface;
/**
* @param String $uri
* @param string $uri
* @param array $data
* @param array $headers
* @param array $body
*
* @return mixed
*/
public function delete(String $uri, array $headers, array $body): ResponseInterface;
public function delete(string $uri, array $data = [], array $headers = []): ResponseInterface;
}

View File

@@ -18,10 +18,10 @@ class Guzzle implements Adapter
/**
* @inheritDoc
*/
public function __construct(Auth $auth, String $baseURI = null)
public function __construct(Auth $auth, string $baseURI = null)
{
if ($baseURI === null) {
$baseURI = "https://api.cloudflare.com/client/v4/";
$baseURI = 'https://api.cloudflare.com/client/v4/';
}
$headers = $auth->getHeaders();
@@ -37,79 +37,56 @@ class Guzzle implements Adapter
/**
* @inheritDoc
*/
public function get(String $uri, array $query = [], array $headers = []): ResponseInterface
public function get(string $uri, array $data = [], array $headers = []): ResponseInterface
{
$response = $this->client->get($uri, ['query' => $query, 'headers' => $headers]);
$this->checkError($response);
return $response;
return $this->request('get', $uri, $data, $headers);
}
/**
* @inheritDoc
*/
public function post(String $uri, array $headers = [], array $body = []): ResponseInterface
public function post(string $uri, array $data = [], array $headers = []): ResponseInterface
{
$response = $this->client->post(
$uri,
[
'headers' => $headers,
'json' => $body
]
);
$this->checkError($response);
return $response;
return $this->request('post', $uri, $data, $headers);
}
/**
* @inheritDoc
*/
public function put(String $uri, array $headers = [], array $body = []): ResponseInterface
public function put(string $uri, array $data = [], array $headers = []): ResponseInterface
{
$response = $this->client->put(
$uri,
[
'headers' => $headers,
'json' => $body
]
);
$this->checkError($response);
return $response;
return $this->request('put', $uri, $data, $headers);
}
/**
* @inheritDoc
*/
public function patch(String $uri, array $headers = [], array $body = []): ResponseInterface
public function patch(string $uri, array $data = [], array $headers = []): ResponseInterface
{
$response = $this->client->patch(
$uri,
[
'headers' => $headers,
'json' => $body
]
);
$this->checkError($response);
return $response;
return $this->request('patch', $uri, $data, $headers);
}
/**
* @inheritDoc
*/
public function delete(String $uri, array $headers = [], array $body = []): ResponseInterface
public function delete(string $uri, array $data = [], array $headers = []): ResponseInterface
{
$response = $this->client->delete(
$uri,
[
'headers' => $headers,
'json' => $body
]
);
return $this->request('delete', $uri, $data, $headers);
}
public function request(string $method, string $uri, array $data = [], array $headers = [])
{
if (!in_array($method, ['get', 'post', 'put', 'patch', 'delete'])) {
throw new \InvalidArgumentException('Request method must be get, post, put, patch, or delete');
}
$response = $this->client->$method($uri, [
'headers' => $headers,
($method === 'get' ? 'query' : 'json') => $data,
]);
$this->checkError($response);
return $response;
}
@@ -121,14 +98,12 @@ class Guzzle implements Adapter
throw new JSONException();
}
if (isset($json->errors)) {
foreach ($json->errors as $error) {
throw new ResponseException($error->message, $error->code);
}
if (isset($json->errors) && count($json->errors) >= 1) {
throw new ResponseException($json->errors[0]->message, $json->errors[0]->code);
}
if (isset($json->success) && ($json->success === false)) {
throw new ResponseException("Request was unsuccessful.");
if (isset($json->success) && !$json->success) {
throw new ResponseException('Request was unsuccessful.');
}
}
}

View File

@@ -12,7 +12,7 @@ class APIKey implements Auth
private $email;
private $apiKey;
public function __construct(String $email, String $apiKey)
public function __construct(string $email, string $apiKey)
{
$this->email = $email;
$this->apiKey = $apiKey;

View File

@@ -11,7 +11,7 @@ class UserServiceKey implements Auth
{
private $userServiceKey;
public function __construct(String $userServiceKey)
public function __construct(string $userServiceKey)
{
$this->userServiceKey = $userServiceKey;
}

View File

@@ -0,0 +1,28 @@
<?php
namespace Cloudflare\API\Configurations;
class AccessRules implements Configurations
{
private $config;
public function setIP(string $value)
{
$this->config = ['target' => 'ip', 'value' => $value];
}
public function setIPRange(string $value)
{
$this->config = ['target' => 'ip_range', 'value' => $value];
}
public function setCountry(string $value)
{
$this->config = ['target' => 'country', 'value' => $value];
}
public function getArray(): array
{
return $this->config;
}
}

View File

@@ -14,28 +14,28 @@ class PageRulesActions implements Configurations
public function setAlwaysOnline(bool $active)
{
$this->addConfigurationOption("always_online", [
$this->addConfigurationOption('always_online', [
'value' => $this->getBoolAsOnOrOff($active)
]);
}
public function setAlwaysUseHTTPS(bool $active)
{
$this->addConfigurationOption("always_use_https", [
$this->addConfigurationOption('always_use_https', [
'value' => $this->getBoolAsOnOrOff($active)
]);
}
public function setBrowserCacheTTL(int $ttl)
{
$this->addConfigurationOption("browser_cache_ttl", [
$this->addConfigurationOption('browser_cache_ttl', [
'value' => $ttl
]);
}
public function setBrowserIntegrityCheck(bool $active)
{
$this->addConfigurationOption("browser_check", [
$this->addConfigurationOption('browser_check', [
'value' => $this->getBoolAsOnOrOff($active)
]);
}
@@ -43,35 +43,35 @@ class PageRulesActions implements Configurations
public function setBypassCacheOnCookie(string $value)
{
if (preg_match('/^([a-zA-Z0-9\.=|_*-]+)$/i', $value) < 1) {
throw new ConfigurationsException("Invalid cookie string.");
throw new ConfigurationsException('Invalid cookie string.');
}
$this->addConfigurationOption("bypass_cache_on_cookie", [
$this->addConfigurationOption('bypass_cache_on_cookie', [
'value' => $value
]);
}
public function setCacheByDeviceType(bool $active)
{
$this->addConfigurationOption("cache_by_device_type", [
$this->addConfigurationOption('cache_by_device_type', [
'value' => $this->getBoolAsOnOrOff($active)
]);
}
public function setCacheKey(string $value)
{
$this->addConfigurationOption("cache_key", [
$this->addConfigurationOption('cache_key', [
'value' => $value
]);
}
public function setCacheLevel(string $value)
{
if (!in_array($value, ["bypass", "basic", "simplified", "aggressive", "cache_everything"])) {
throw new ConfigurationsException("Invalid cache level");
if (!in_array($value, ['bypass', 'basic', 'simplified', 'aggressive', 'cache_everything'])) {
throw new ConfigurationsException('Invalid cache level');
}
$this->addConfigurationOption("cache_level", [
$this->addConfigurationOption('cache_level', [
'value' => $value
]);
}
@@ -79,31 +79,31 @@ class PageRulesActions implements Configurations
public function setCacheOnCookie(string $value)
{
if (preg_match('/^([a-zA-Z0-9\.=|_*-]+)$/i', $value) < 1) {
throw new ConfigurationsException("Invalid cookie string.");
throw new ConfigurationsException('Invalid cookie string.');
}
$this->addConfigurationOption("cache_on_cookie", [
$this->addConfigurationOption('cache_on_cookie', [
'value' => $value
]);
}
public function setDisableApps(bool $active)
{
$this->addConfigurationOption("disable_apps", [
$this->addConfigurationOption('disable_apps', [
'value' => $this->getBoolAsOnOrOff($active)
]);
}
public function setDisablePerformance(bool $active)
{
$this->addConfigurationOption("disable_performance", [
$this->addConfigurationOption('disable_performance', [
'value' => $this->getBoolAsOnOrOff($active)
]);
}
public function setDisableSecurity(bool $active)
{
$this->addConfigurationOption("disable_security", [
$this->addConfigurationOption('disable_security', [
'value' => $this->getBoolAsOnOrOff($active)
]);
}
@@ -111,17 +111,17 @@ class PageRulesActions implements Configurations
public function setEdgeCacheTTL(int $value)
{
if ($value > 2419200) {
throw new ConfigurationsException("Edge Cache TTL too high.");
throw new ConfigurationsException('Edge Cache TTL too high.');
}
$this->addConfigurationOption("edge_cache_ttl", [
$this->addConfigurationOption('edge_cache_ttl', [
'value' => $value
]);
}
public function setEmailObfuscation(bool $active)
{
$this->addConfigurationOption("disable_security", [
$this->addConfigurationOption('disable_security', [
'value' => $this->getBoolAsOnOrOff($active)
]);
}
@@ -133,35 +133,37 @@ class PageRulesActions implements Configurations
}
$this->addConfigurationOption("forwarding_url", [
'status_code' => $statusCode,
'url' => $forwardingUrl,
'value' => [
'status_code' => $statusCode,
'url' => $forwardingUrl,
],
]);
}
public function setHostHeaderOverride(bool $active)
{
$this->addConfigurationOption("host_header_override", [
$this->addConfigurationOption('host_header_override', [
'value' => $this->getBoolAsOnOrOff($active)
]);
}
public function setHotlinkProtection(bool $active)
{
$this->addConfigurationOption("hotlink_protection", [
$this->addConfigurationOption('hotlink_protection', [
'value' => $this->getBoolAsOnOrOff($active)
]);
}
public function setIPGeoLocationHeader(bool $active)
{
$this->addConfigurationOption("ip_geolocation", [
$this->addConfigurationOption('ip_geolocation', [
'value' => $this->getBoolAsOnOrOff($active)
]);
}
public function setMinification(bool $html, bool $css, bool $javascript)
{
$this->addConfigurationOption("minification", [
$this->addConfigurationOption('minification', [
'html' => $this->getBoolAsOnOrOff($html),
'css' => $this->getBoolAsOnOrOff($css),
'js' => $this->getBoolAsOnOrOff($javascript),
@@ -170,124 +172,124 @@ class PageRulesActions implements Configurations
public function setMirage(bool $active)
{
$this->addConfigurationOption("mirage", [
$this->addConfigurationOption('mirage', [
'value' => $this->getBoolAsOnOrOff($active)
]);
}
public function setOriginErrorPagePassthru(bool $active)
{
$this->addConfigurationOption("origin_error_page_pass_thru", [
$this->addConfigurationOption('origin_error_page_pass_thru', [
'value' => $this->getBoolAsOnOrOff($active)
]);
}
public function setQueryStringSort(bool $active)
{
$this->addConfigurationOption("sort_query_string_for_cache", [
$this->addConfigurationOption('sort_query_string_for_cache', [
'value' => $this->getBoolAsOnOrOff($active)
]);
}
public function setDisableRailgun(bool $active)
{
$this->addConfigurationOption("disable_railgun", [
$this->addConfigurationOption('disable_railgun', [
'value' => $this->getBoolAsOnOrOff($active)
]);
}
public function setResolveOverride(bool $value)
{
$this->addConfigurationOption("resolve_override", [
$this->addConfigurationOption('resolve_override', [
'value' => $value
]);
}
public function setRespectStrongEtag(bool $active)
{
$this->addConfigurationOption("respect_strong_etag", [
$this->addConfigurationOption('respect_strong_etag', [
'value' => $this->getBoolAsOnOrOff($active)
]);
}
public function setResponseBuffering(bool $active)
{
$this->addConfigurationOption("response_buffering", [
$this->addConfigurationOption('response_buffering', [
'value' => $this->getBoolAsOnOrOff($active)
]);
}
public function setRocketLoader(string $value)
{
if (!in_array($value, ["off", "manual", "automatic"])) {
if (!in_array($value, ['off', 'manual', 'automatic'])) {
throw new ConfigurationsException('Rocket Loader can only be off, automatic, or manual.');
}
$this->addConfigurationOption("rocket_loader", [
$this->addConfigurationOption('rocket_loader', [
'value' => $value
]);
}
public function setSecurityLevel(string $value)
{
if (!in_array($value, ["off", "essentially_off", "low", "medium", "high", "under_attack"])) {
if (!in_array($value, ['off', 'essentially_off', 'low', 'medium', 'high', 'under_attack'])) {
throw new ConfigurationsException('Can only be set to off, essentially_off, low, medium, high or under_attack.');
}
$this->addConfigurationOption("security_level", [
$this->addConfigurationOption('security_level', [
'value' => $value
]);
}
public function setServerSideExcludes(bool $active)
{
$this->addConfigurationOption("server_side_exclude", [
$this->addConfigurationOption('server_side_exclude', [
'value' => $this->getBoolAsOnOrOff($active)
]);
}
public function setSmartErrors(bool $active)
{
$this->addConfigurationOption("smart_errors", [
$this->addConfigurationOption('smart_errors', [
'value' => $this->getBoolAsOnOrOff($active)
]);
}
public function setSSL(string $value)
{
if (!in_array($value, ["off", "flexible", "full", "strict", "origin_pull"])) {
if (!in_array($value, ['off', 'flexible', 'full', 'strict', 'origin_pull'])) {
throw new ConfigurationsException('Can only be set to off, flexible, full, strict, origin_pull.');
}
$this->addConfigurationOption("smart_errors", [
$this->addConfigurationOption('smart_errors', [
'value' => $value
]);
}
public function setTrueClientIpHeader(bool $active)
{
$this->addConfigurationOption("true_client_ip_header", [
$this->addConfigurationOption('true_client_ip_header', [
'value' => $this->getBoolAsOnOrOff($active)
]);
}
public function setWAF(bool $active)
{
$this->addConfigurationOption("waf", [
$this->addConfigurationOption('waf', [
'value' => $this->getBoolAsOnOrOff($active)
]);
}
public function setAutomatedHTTPSRewrites(bool $active)
{
$this->addConfigurationOption("automatic_https_rewrites", [
$this->addConfigurationOption('automatic_https_rewrites', [
'value' => $this->getBoolAsOnOrOff($active)
]);
}
public function setOpportunisticEncryption(bool $active)
{
$this->addConfigurationOption("opportunistic_encryption", [
$this->addConfigurationOption('opportunistic_encryption', [
'value' => $this->getBoolAsOnOrOff($active)
]);
}
@@ -301,7 +303,7 @@ class PageRulesActions implements Configurations
{
$configuration['id'] = $setting;
array_push($this->configs, (object) $configuration);
array_push($this->configs, $configuration);
}
private function getBoolAsOnOrOff(bool $value): string

View File

@@ -14,13 +14,15 @@ class PageRulesTargets implements Configurations
public function __construct(string $queryUrl)
{
$target = new \stdClass();
$target->target = 'url';
$target->constraint = new \stdClass();
$target->constraint->operator = "matches";
$target->constraint->value = $queryUrl;
$this->targets = [$target];
$this->targets = [
[
'target' => 'url',
'constraint' => [
'operator' => 'matches',
'value' => $queryUrl
]
]
];
}
public function getArray(): array

View File

@@ -14,11 +14,7 @@ class UARules implements Configurations
public function addUA(string $value)
{
$object = new \stdClass();
$object->target = "ua";
$object->value = $value;
array_push($this->configs, $object);
$this->configs[] = ['target' => 'ua', 'value' => $value];
}
public function getArray(): array

View File

@@ -14,20 +14,12 @@ class ZoneLockdown implements Configurations
public function addIP(string $value)
{
$object = new \stdClass();
$object->target = "ip";
$object->value = $value;
array_push($this->configs, $object);
$this->configs[] = ['target' => 'ip', 'value' => $value];
}
public function addIPRange(string $value)
{
$object = new \stdClass();
$object->target = "ip_range";
$object->value = $value;
array_push($this->configs, $object);
$this->configs[] = ['target' => 'ip_range', 'value' => $value];
}
public function getArray(): array

View File

@@ -0,0 +1,153 @@
<?php
namespace Cloudflare\API\Endpoints;
use Cloudflare\API\Adapter\Adapter;
use Cloudflare\API\Configurations\Configurations;
class AccessRules implements API
{
private $adapter;
public function __construct(Adapter $adapter)
{
$this->adapter = $adapter;
}
/**
* @SuppressWarnings(PHPMD.ExcessiveParameterList)
*
* @param string $zoneID
* @param string $scopeType
* @param string $mode
* @param string $configurationTarget
* @param string $configurationValue
* @param int $page
* @param int $perPage
* @param string $order
* @param string $direction
* @param string $match
* @param string $notes
* @return \stdClass
*/
public function listRules(
string $zoneID,
string $scopeType = '',
string $mode = '',
string $configurationTarget = '',
string $configurationValue = '',
int $page = 1,
int $perPage = 50,
string $order = '',
string $direction = '',
string $match = 'all',
string $notes = ''
): \stdClass {
$query = [
'page' => $page,
'per_page' => $perPage,
'match' => $match
];
if (!empty($scopeType)) {
$query['scope_type'] = $scopeType;
}
if (!empty($mode)) {
$query['mode'] = $mode;
}
if (!empty($configurationTarget)) {
$query['configuration_target'] = $configurationTarget;
}
if (!empty($configurationValue)) {
$query['configuration_value'] = $configurationValue;
}
if (!empty($order)) {
$query['order'] = $order;
}
if (!empty($direction)) {
$query['direction'] = $direction;
}
if (!empty($notes)) {
$query['notes'] = $notes;
}
$data = $this->adapter->get('zones/' . $zoneID . '/firewall/access_rules/rules', $query);
$body = json_decode($data->getBody());
return (object)['result' => $body->result, 'result_info' => $body->result_info];
}
public function createRule(
string $zoneID,
string $mode,
Configurations $configuration,
string $notes = null
): bool {
$options = [
'mode' => $mode,
'configuration' => $configuration->getArray()
];
if ($notes !== null) {
$options['notes'] = $notes;
}
$query = $this->adapter->post('zones/' . $zoneID . '/firewall/access_rules/rules', $options);
$body = json_decode($query->getBody());
if (isset($body->result->id)) {
return true;
}
return false;
}
public function updateRule(
string $zoneID,
string $ruleID,
string $mode,
string $notes = null
): bool {
$options = [
'mode' => $mode
];
if ($notes !== null) {
$options['notes'] = $notes;
}
$query = $this->adapter->patch('zones/' . $zoneID . '/firewall/access_rules/rules/' . $ruleID, $options);
$body = json_decode($query->getBody());
if (isset($body->result->id)) {
return true;
}
return false;
}
public function deleteRule(string $zoneID, string $ruleID, string $cascade = 'none'): bool
{
$options = [
'cascade' => $cascade
];
$data = $this->adapter->delete('zones/' . $zoneID . '/firewall/access_rules/rules/' . $ruleID, $options);
$body = json_decode($data->getBody());
if (isset($body->result->id)) {
return true;
}
return false;
}
}

View File

@@ -0,0 +1,150 @@
<?php
/**
* Created by PhpStorm.
* User: junade
* Date: 18/03/2018
* Time: 21:46
*/
namespace Cloudflare\API\Endpoints;
use Cloudflare\API\Adapter\Adapter;
class CustomHostnames implements API
{
private $adapter;
public function __construct(Adapter $adapter)
{
$this->adapter = $adapter;
}
/**
* @SuppressWarnings(PHPMD.BooleanArgumentFlag)
*
* @param string $zoneID
* @param string $hostname
* @param string $sslMethod
* @param string $sslType
* @return \stdClass
*/
public function addHostname(string $zoneID, string $hostname, string $sslMethod = 'http', string $sslType = 'dv'): \stdClass
{
$options = [
'hostname' => $hostname,
'ssl' => [
'method' => $sslMethod,
'type' => $sslType
]
];
$zone = $this->adapter->post('zones/'.$zoneID.'/custom_hostnames', $options);
$body = json_decode($zone->getBody());
return $body->result;
}
/**
* @param string $zoneID
* @param string $hostname
* @param string $id
* @param int $page
* @param int $perPage
* @param string $order
* @param string $direction
* @param int $ssl
* @return \stdClass
*/
public function listHostnames(
string $zoneID,
string $hostname = '',
string $hostnameID = '',
int $page = 1,
int $perPage = 20,
string $order = '',
string $direction = '',
int $ssl = 0
): \stdClass {
$query = [
'page' => $page,
'per_page' => $perPage,
'ssl' => $ssl
];
if (!empty($hostname)) {
$query['hostname'] = $hostname;
}
if (!empty($hostnameID)) {
$query['id'] = $hostnameID;
}
if (!empty($order)) {
$query['order'] = $order;
}
if (!empty($direction)) {
$query['direction'] = $direction;
}
$zone = $this->adapter->get('zones/'.$zoneID.'/custom_hostnames', $query);
$body = json_decode($zone->getBody());
return (object)['result' => $body->result, 'result_info' => $body->result_info];
}
/**
* @param string $zoneID
* @param string $hostnameID
* @return mixed
*/
public function getHostname(string $zoneID, string $hostnameID)
{
$zone = $this->adapter->get('zones/'.$zoneID.'/custom_hostnames/'.$hostnameID);
$body = json_decode($zone->getBody());
return $body->result;
}
/**
* @SuppressWarnings(PHPMD.BooleanArgumentFlag)
*
* @param string $zoneID
* @param string $hostnameID
* @param string $sslMethod
* @param string $sslType
* @return \stdClass
*/
public function updateHostname(string $zoneID, string $hostnameID, string $sslMethod = '', string $sslType = ''): \stdClass
{
$query = [];
if (!empty($sslMethod)) {
$query['method'] = $sslMethod;
}
if (!empty($sslType)) {
$query['type'] = $sslType;
}
$options = [
'ssl' => $query
];
$zone = $this->adapter->patch('zones/'.$zoneID.'/custom_hostnames/'.$hostnameID, $options);
$body = json_decode($zone->getBody());
return $body->result;
}
/**
* @param string $zoneID
* @param string $hostnameID
* @return \stdClass
*/
public function deleteHostname(string $zoneID, string $hostnameID): \stdClass
{
$zone = $this->adapter->delete('zones/'.$zoneID.'/custom_hostnames/'.$hostnameID);
$body = json_decode($zone->getBody());
return $body;
}
}

View File

@@ -28,6 +28,7 @@ class DNS implements API
* @param string $content
* @param int $ttl
* @param bool $proxied
* @param string $priority
* @return bool
*/
public function addRecord(
@@ -36,7 +37,8 @@ class DNS implements API
string $name,
string $content,
int $ttl = 0,
bool $proxied = true
bool $proxied = true,
string $priority = ''
): bool {
$options = [
'type' => $type,
@@ -49,7 +51,11 @@ class DNS implements API
$options['ttl'] = $ttl;
}
$user = $this->adapter->post('zones/' . $zoneID . '/dns_records', [], $options);
if (!empty($priority)) {
$options['priority'] = (int)$priority;
}
$user = $this->adapter->post('zones/' . $zoneID . '/dns_records', $options);
$body = json_decode($user->getBody());
@@ -62,14 +68,14 @@ class DNS implements API
public function listRecords(
string $zoneID,
string $type = "",
string $name = "",
string $content = "",
string $type = '',
string $name = '',
string $content = '',
int $page = 1,
int $perPage = 20,
string $order = "",
string $direction = "",
string $match = "all"
string $order = '',
string $direction = '',
string $match = 'all'
): \stdClass {
$query = [
'page' => $page,
@@ -97,32 +103,28 @@ class DNS implements API
$query['direction'] = $direction;
}
$user = $this->adapter->get('zones/' . $zoneID . '/dns_records', $query, []);
$user = $this->adapter->get('zones/' . $zoneID . '/dns_records', $query);
$body = json_decode($user->getBody());
$result = new \stdClass();
$result->result = $body->result;
$result->result_info = $body->result_info;
return $result;
return (object)['result' => $body->result, 'result_info' => $body->result_info];
}
public function getRecordDetails(string $zoneID, string $recordID): \stdClass
{
$user = $this->adapter->get('zones/' . $zoneID . '/dns_records/' . $recordID, [], []);
$user = $this->adapter->get('zones/' . $zoneID . '/dns_records/' . $recordID);
$body = json_decode($user->getBody());
return $body->result;
}
public function updateRecordDetails(string $zoneID, string $recordID, array $details): \stdClass
{
$response = $this->adapter->put('zones/' . $zoneID . '/dns_records/' . $recordID, [], $details);
$response = $this->adapter->put('zones/' . $zoneID . '/dns_records/' . $recordID, $details);
return json_decode($response->getBody());
}
public function deleteRecord(string $zoneID, string $recordID): bool
{
$user = $this->adapter->delete('zones/' . $zoneID . '/dns_records/' . $recordID, [], []);
$user = $this->adapter->delete('zones/' . $zoneID . '/dns_records/' . $recordID);
$body = json_decode($user->getBody());

View File

@@ -21,7 +21,7 @@ class IPs implements API
public function listIPs(): \stdClass
{
$ips = $this->adapter->get('ips', [], []);
$ips = $this->adapter->get('ips');
$body = json_decode($ips->getBody());
return $body->result;

View File

@@ -52,7 +52,7 @@ class PageRules implements API
}
$query = $this->adapter->post('zones/' . $zoneID . '/pagerules', [], $options);
$query = $this->adapter->post('zones/' . $zoneID . '/pagerules', $options);
$body = json_decode($query->getBody());
@@ -70,19 +70,19 @@ class PageRules implements API
string $direction = null,
string $match = null
): array {
if (is_null($status) && !in_array($status, ['active', 'disabled'])) {
if ($status === null && !in_array($status, ['active', 'disabled'])) {
throw new EndpointException('Page Rules can only be listed by status of active or disabled.');
}
if (is_null($order) && !in_array($order, ['status', 'priority'])) {
if ($order === null && !in_array($order, ['status', 'priority'])) {
throw new EndpointException('Page Rules can only be ordered by status or priority.');
}
if (is_null($direction) && !in_array($direction, ['asc', 'desc'])) {
if ($direction === null && !in_array($direction, ['asc', 'desc'])) {
throw new EndpointException('Direction of Page Rule ordering can only be asc or desc.');
}
if (is_null($match) && !in_array($match, ['all', 'any'])) {
if ($match === null && !in_array($match, ['all', 'any'])) {
throw new EndpointException('Match can only be any or all.');
}
@@ -93,7 +93,7 @@ class PageRules implements API
'match' => $match
];
$user = $this->adapter->get('zones/' . $zoneID . '/pagerules', $query, []);
$user = $this->adapter->get('zones/' . $zoneID . '/pagerules', $query);
$body = json_decode($user->getBody());
return $body->result;
@@ -101,7 +101,7 @@ class PageRules implements API
public function getPageRuleDetails(string $zoneID, string $ruleID): \stdClass
{
$user = $this->adapter->get('zones/' . $zoneID . '/pagerules/' . $ruleID, [], []);
$user = $this->adapter->get('zones/' . $zoneID . '/pagerules/' . $ruleID);
$body = json_decode($user->getBody());
return $body->result;
}
@@ -115,7 +115,7 @@ class PageRules implements API
): bool {
$options = [];
if ($active !== null) {
if ($target !== null) {
$options['targets'] = $target->getArray();
}
@@ -132,7 +132,7 @@ class PageRules implements API
}
$query = $this->adapter->patch('zones/' . $zoneID . '/pagerules', [], $options);
$query = $this->adapter->patch('zones/' . $zoneID . '/pagerules', $options);
$body = json_decode($query->getBody());
@@ -145,7 +145,7 @@ class PageRules implements API
public function deletePageRule(string $zoneID, string $ruleID): bool
{
$user = $this->adapter->delete('zones/' . $zoneID . '/pagerules/' . $ruleID, [], []);
$user = $this->adapter->delete('zones/' . $zoneID . '/pagerules/' . $ruleID);
$body = json_decode($user->getBody());

View File

@@ -26,7 +26,7 @@ class Railgun implements API
'name' => $name,
];
$user = $this->adapter->post('railguns', [], $query);
$user = $this->adapter->post('railguns', $query);
$body = json_decode($user->getBody());
return $body;
@@ -35,7 +35,7 @@ class Railgun implements API
public function list(
int $page = 1,
int $perPage = 20,
string $direction = ""
string $direction = ''
): \stdClass {
$query = [
'page' => $page,
@@ -46,20 +46,16 @@ class Railgun implements API
$query['direction'] = $direction;
}
$user = $this->adapter->get('railguns', $query, []);
$user = $this->adapter->get('railguns', $query);
$body = json_decode($user->getBody());
$result = new \stdClass();
$result->result = $body->result;
$result->result_info = $body->result_info;
return $result;
return (object)['result' => $body->result, 'result_info' => $body->result_info];
}
public function get(
string $railgunID
): \stdClass {
$user = $this->adapter->get('railguns/' . $railgunID, [], []);
$user = $this->adapter->get('railguns/' . $railgunID);
$body = json_decode($user->getBody());
return $body->result;
@@ -68,14 +64,10 @@ class Railgun implements API
public function getZones(
string $railgunID
): \stdClass {
$user = $this->adapter->get('railguns/' . $railgunID . '/zones', [], []);
$user = $this->adapter->get('railguns/' . $railgunID . '/zones');
$body = json_decode($user->getBody());
$result = new \stdClass();
$result->result = $body->result;
$result->result_info = $body->result_info;
return $result;
return (object)['result' => $body->result, 'result_info' => $body->result_info];
}
public function update(
@@ -86,7 +78,7 @@ class Railgun implements API
'enabled' => $status
];
$user = $this->adapter->patch('railguns/' . $railgunID, [], $query);
$user = $this->adapter->patch('railguns/' . $railgunID, $query);
$body = json_decode($user->getBody());
return $body->result;
@@ -95,7 +87,7 @@ class Railgun implements API
public function delete(
string $railgunID
): bool {
$user = $this->adapter->delete('railguns/' . $railgunID, [], []);
$user = $this->adapter->delete('railguns/' . $railgunID);
$body = json_decode($user->getBody());
if (isset($body->result->id)) {

View File

@@ -8,6 +8,7 @@
namespace Cloudflare\API\Endpoints;
use Cloudflare\API\Configurations\Configurations;
use Cloudflare\API\Adapter\Adapter;
class UARules implements API
@@ -29,20 +30,16 @@ class UARules implements API
'per_page' => $perPage
];
$user = $this->adapter->get('zones/' . $zoneID . '/firewall/ua_rules', $query, []);
$user = $this->adapter->get('zones/' . $zoneID . '/firewall/ua_rules', $query);
$body = json_decode($user->getBody());
$result = new \stdClass();
$result->result = $body->result;
$result->result_info = $body->result_info;
return $result;
return (object)['result' => $body->result, 'result_info' => $body->result_info];
}
public function createRule(
string $zoneID,
string $mode,
\Cloudflare\API\Configurations\Configurations $configuration,
Configurations $configuration,
string $ruleID = null,
string $description = null
): bool {
@@ -59,7 +56,7 @@ class UARules implements API
$options['description'] = $description;
}
$user = $this->adapter->post('zones/' . $zoneID . '/firewall/ua_rules', [], $options);
$user = $this->adapter->post('zones/' . $zoneID . '/firewall/ua_rules', $options);
$body = json_decode($user->getBody());
@@ -72,7 +69,7 @@ class UARules implements API
public function getRuleDetails(string $zoneID, string $blockID): \stdClass
{
$user = $this->adapter->get('zones/' . $zoneID . '/firewall/ua_rules/' . $blockID, []);
$user = $this->adapter->get('zones/' . $zoneID . '/firewall/ua_rules/' . $blockID);
$body = json_decode($user->getBody());
return $body->result;
}
@@ -94,7 +91,7 @@ class UARules implements API
$options['description'] = $description;
}
$user = $this->adapter->put('zones/' . $zoneID . '/firewall/ua_rules/' . $ruleID, [], $options);
$user = $this->adapter->put('zones/' . $zoneID . '/firewall/ua_rules/' . $ruleID, $options);
$body = json_decode($user->getBody());
@@ -107,7 +104,7 @@ class UARules implements API
public function deleteRule(string $zoneID, string $ruleID): bool
{
$user = $this->adapter->delete('zones/' . $zoneID . '/firewall/ua_rules/' . $ruleID, [], []);
$user = $this->adapter->delete('zones/' . $zoneID . '/firewall/ua_rules/' . $ruleID);
$body = json_decode($user->getBody());

View File

@@ -20,24 +20,24 @@ class User implements API
public function getUserDetails(): \stdClass
{
$user = $this->adapter->get('user', [], []);
$user = $this->adapter->get('user');
$body = json_decode($user->getBody());
return $body->result;
}
public function getUserID(): string
{
return ($this->getUserDetails())->id;
return $this->getUserDetails()->id;
}
public function getUserEmail(): string
{
return ($this->getUserDetails())->email;
return $this->getUserDetails()->email;
}
public function updateUserDetails(array $details): \stdClass
{
$response = $this->adapter->patch("user", [], $details);
$response = $this->adapter->patch('user', $details);
return json_decode($response->getBody());
}
}

View File

@@ -10,7 +10,7 @@ namespace Cloudflare\API\Endpoints;
use Cloudflare\API\Adapter\Adapter;
class WAF implements \Cloudflare\API\Endpoints\API
class WAF implements API
{
private $adapter;
@@ -23,9 +23,9 @@ class WAF implements \Cloudflare\API\Endpoints\API
string $zoneID,
int $page = 1,
int $perPage = 20,
string $order = "",
string $direction = "",
string $match = "all"
string $order = '',
string $direction = '',
string $match = 'all'
): \stdClass {
$query = [
'page' => $page,
@@ -41,14 +41,10 @@ class WAF implements \Cloudflare\API\Endpoints\API
$query['direction'] = $direction;
}
$user = $this->adapter->get('zones/' . $zoneID . '/firewall/waf/packages', $query, []);
$user = $this->adapter->get('zones/' . $zoneID . '/firewall/waf/packages', $query);
$body = json_decode($user->getBody());
$result = new \stdClass();
$result->result = $body->result;
$result->result_info = $body->result_info;
return $result;
return (object)['result' => $body->result, 'result_info' => $body->result_info];
}
@@ -56,7 +52,7 @@ class WAF implements \Cloudflare\API\Endpoints\API
string $zoneID,
string $packageID
): \stdClass {
$user = $this->adapter->get('zones/' . $zoneID . '/firewall/waf/packages/' . $packageID, [], []);
$user = $this->adapter->get('zones/' . $zoneID . '/firewall/waf/packages/' . $packageID);
$body = json_decode($user->getBody());
return $body->result;
@@ -67,9 +63,9 @@ class WAF implements \Cloudflare\API\Endpoints\API
string $packageID,
int $page = 1,
int $perPage = 20,
string $order = "",
string $direction = "",
string $match = "all"
string $order = '',
string $direction = '',
string $match = 'all'
): \stdClass {
$query = [
'page' => $page,
@@ -84,14 +80,10 @@ class WAF implements \Cloudflare\API\Endpoints\API
if (!empty($direction)) {
$query['direction'] = $direction;
}
$user = $this->adapter->get('zones/' . $zoneID . '/firewall/waf/packages/' . $packageID . '/rules', $query, []);
$user = $this->adapter->get('zones/' . $zoneID . '/firewall/waf/packages/' . $packageID . '/rules', $query);
$body = json_decode($user->getBody());
$result = new \stdClass();
$result->result = $body->result;
$result->result_info = $body->result_info;
return $result;
return (object)['result' => $body->result, 'result_info' => $body->result_info];
}
public function getRuleInfo(
@@ -99,11 +91,7 @@ class WAF implements \Cloudflare\API\Endpoints\API
string $packageID,
string $ruleID
): \stdClass {
$user = $this->adapter->get(
'zones/' . $zoneID . '/firewall/waf/packages/' . $packageID . '/rules/' . $ruleID,
[],
[]
);
$user = $this->adapter->get('zones/' . $zoneID . '/firewall/waf/packages/' . $packageID . '/rules/' . $ruleID);
$body = json_decode($user->getBody());
return $body->result;
@@ -121,7 +109,6 @@ class WAF implements \Cloudflare\API\Endpoints\API
$user = $this->adapter->patch(
'zones/' . $zoneID . '/firewall/waf/packages/' . $packageID . '/rules/' . $ruleID,
[],
$query
);
$body = json_decode($user->getBody());
@@ -134,9 +121,9 @@ class WAF implements \Cloudflare\API\Endpoints\API
string $packageID,
int $page = 1,
int $perPage = 20,
string $order = "",
string $direction = "",
string $match = "all"
string $order = '',
string $direction = '',
string $match = 'all'
): \stdClass {
$query = [
'page' => $page,
@@ -154,16 +141,11 @@ class WAF implements \Cloudflare\API\Endpoints\API
$user = $this->adapter->get(
'zones/' . $zoneID . '/firewall/waf/packages/' . $packageID . '/groups',
$query,
[]
$query
);
$body = json_decode($user->getBody());
$result = new \stdClass();
$result->result = $body->result;
$result->result_info = $body->result_info;
return $result;
return (object)['result' => $body->result, 'result_info' => $body->result_info];
}
public function getGroupInfo(
@@ -171,11 +153,7 @@ class WAF implements \Cloudflare\API\Endpoints\API
string $packageID,
string $groupID
): \stdClass {
$user = $this->adapter->get(
'zones/' . $zoneID . '/firewall/waf/packages/' . $packageID . '/groups/' . $groupID,
[],
[]
);
$user = $this->adapter->get('zones/' . $zoneID . '/firewall/waf/packages/' . $packageID . '/groups/' . $groupID);
$body = json_decode($user->getBody());
return $body->result;
@@ -193,7 +171,6 @@ class WAF implements \Cloudflare\API\Endpoints\API
$user = $this->adapter->patch(
'zones/' . $zoneID . '/firewall/waf/packages/' . $packageID . '/groups/' . $groupID,
[],
$query
);
$body = json_decode($user->getBody());

View File

@@ -29,14 +29,10 @@ class ZoneLockdown implements API
'per_page' => $perPage
];
$user = $this->adapter->get('zones/' . $zoneID . '/firewall/lockdowns', $query, []);
$user = $this->adapter->get('zones/' . $zoneID . '/firewall/lockdowns', $query);
$body = json_decode($user->getBody());
$result = new \stdClass();
$result->result = $body->result;
$result->result_info = $body->result_info;
return $result;
return (object)['result' => $body->result, 'result_info' => $body->result_info];
}
public function createLockdown(
@@ -59,7 +55,7 @@ class ZoneLockdown implements API
$options['description'] = $description;
}
$user = $this->adapter->post('zones/' . $zoneID . '/firewall/lockdowns', [], $options);
$user = $this->adapter->post('zones/' . $zoneID . '/firewall/lockdowns', $options);
$body = json_decode($user->getBody());
@@ -72,7 +68,7 @@ class ZoneLockdown implements API
public function getLockdownDetails(string $zoneID, string $lockdownID): \stdClass
{
$user = $this->adapter->get('zones/' . $zoneID . '/firewall/lockdowns/' . $lockdownID, [], []);
$user = $this->adapter->get('zones/' . $zoneID . '/firewall/lockdowns/' . $lockdownID);
$body = json_decode($user->getBody());
return $body->result;
}
@@ -94,7 +90,7 @@ class ZoneLockdown implements API
$options['description'] = $description;
}
$user = $this->adapter->put('zones/' . $zoneID . '/firewall/lockdowns/' . $lockdownID, [], $options);
$user = $this->adapter->put('zones/' . $zoneID . '/firewall/lockdowns/' . $lockdownID, $options);
$body = json_decode($user->getBody());
@@ -107,7 +103,7 @@ class ZoneLockdown implements API
public function deleteLockdown(string $zoneID, string $lockdownID): bool
{
$user = $this->adapter->delete('zones/' . $zoneID . '/firewall/lockdowns/' . $lockdownID, [], []);
$user = $this->adapter->delete('zones/' . $zoneID . '/firewall/lockdowns/' . $lockdownID);
$body = json_decode($user->getBody());

View File

@@ -23,31 +23,29 @@ class Zones implements API
* @SuppressWarnings(PHPMD.BooleanArgumentFlag)
*
* @param string $name
* @param bool $jumpstart
* @param bool $jumpStart
* @param string $organizationID
* @return \stdClass
*/
public function addZone(string $name, bool $jumpstart = false, string $organizationID = ''): \stdClass
public function addZone(string $name, bool $jumpStart = false, string $organizationID = ''): \stdClass
{
$options = [
'name' => $name,
'jumpstart' => $jumpstart
'jump_start' => $jumpStart
];
if (!empty($organizationID)) {
$organization = new \stdClass();
$organization->id = $organizationID;
$options["organization"] = $organization;
$options['organization'] = ['id' => $organizationID];
}
$user = $this->adapter->post('zones', [], $options);
$user = $this->adapter->post('zones', $options);
$body = json_decode($user->getBody());
return $body->result;
}
public function activationCheck(string $zoneID): bool
{
$user = $this->adapter->put('zones/' . $zoneID . '/activation_check', [], []);
$user = $this->adapter->put('zones/' . $zoneID . '/activation_check');
$body = json_decode($user->getBody());
if (isset($body->result->id)) {
@@ -58,13 +56,13 @@ class Zones implements API
}
public function listZones(
string $name = "",
string $status = "",
string $name = '',
string $status = '',
int $page = 1,
int $perPage = 20,
string $order = "",
string $direction = "",
string $match = "all"
string $order = '',
string $direction = '',
string $match = 'all'
): \stdClass {
$query = [
'page' => $page,
@@ -88,27 +86,60 @@ class Zones implements API
$query['direction'] = $direction;
}
$user = $this->adapter->get('zones', $query, []);
$user = $this->adapter->get('zones', $query);
$body = json_decode($user->getBody());
$result = new \stdClass();
$result->result = $body->result;
$result->result_info = $body->result_info;
return $result;
return (object)['result' => $body->result, 'result_info' => $body->result_info];
}
public function getZoneID(string $name = ""): string
public function getZoneID(string $name = ''): string
{
$zones = $this->listZones($name);
if (sizeof($zones->result) < 1) {
throw new EndpointException("Could not find zones with specified name.");
if (count($zones->result) < 1) {
throw new EndpointException('Could not find zones with specified name.');
}
return $zones->result[0]->id;
}
/**
* @SuppressWarnings(PHPMD.BooleanArgumentFlag)
*
* @param string $zoneID
* @param string $since
* @param string $until
* @param bool $continuous
* @return \stdClass
*/
public function getAnalyticsDashboard(string $zoneID, string $since = '-10080', string $until = '0', bool $continuous = true): \stdClass
{
$response = $this->adapter->get('zones/' . $zoneID . '/analytics/dashboard', ['since' => $since, 'until' => $until, 'continuous' => var_export($continuous, true)]);
return json_decode($response->getBody())->result;
}
/**
* @SuppressWarnings(PHPMD.BooleanArgumentFlag)
*
* @param string $zoneID
* @param bool $enable
* @return bool
*/
public function changeDevelopmentMode(string $zoneID, bool $enable = false): bool
{
$response = $this->adapter->patch('zones/' . $zoneID . '/settings/development_mode', ['value' => $enable ? 'on' : 'off']);
$body = json_decode($response->getBody());
if ($body->success) {
return true;
}
return false;
}
/**
* Purge Everything
* @param string $zoneID
@@ -116,7 +147,7 @@ class Zones implements API
*/
public function cachePurgeEverything(string $zoneID): bool
{
$user = $this->adapter->delete('zones/' . $zoneID . '/purge_cache', [], ["purge_everything" => true]);
$user = $this->adapter->delete('zones/' . $zoneID . '/purge_cache', ['purge_everything' => true]);
$body = json_decode($user->getBody());
@@ -127,18 +158,26 @@ class Zones implements API
return false;
}
public function cachePurge(string $zoneID, array $files = null, array $tags = null): bool
public function cachePurge(string $zoneID, array $files = null, array $tags = null, array $hosts = null): bool
{
if (is_null($files) && is_null($tags)) {
throw new EndpointException("No files or tags to purge.");
if ($files === null && $tags === null && $hosts === null) {
throw new EndpointException('No files, tags or hosts to purge.');
}
$options = [
'files' => $files,
'tags' => $tags
];
$options = [];
if (!is_null($files)) {
$options['files'] = $files;
}
$user = $this->adapter->delete('zones/' . $zoneID . '/purge_cache', [], $options);
if (!is_null($tags)) {
$options['tags'] = $tags;
}
if (!is_null($hosts)) {
$options['hosts'] = $hosts;
}
$user = $this->adapter->delete('zones/' . $zoneID . '/purge_cache', $options);
$body = json_decode($user->getBody());

View File

@@ -29,66 +29,64 @@ class GuzzleTest extends TestCase
$response = $this->client->get('https://httpbin.org/get');
$headers = $response->getHeaders();
$this->assertEquals("application/json", $headers["Content-Type"][0]);
$this->assertEquals('application/json', $headers['Content-Type'][0]);
$body = json_decode($response->getBody());
$this->assertEquals("Test", $body->headers->{"X-Testing"});
$this->assertEquals('Test', $body->headers->{'X-Testing'});
$response = $this->client->get('https://httpbin.org/get', [], ['X-Another-Test' => 'Test2']);
$body = json_decode($response->getBody());
$this->assertEquals("Test2", $body->headers->{"X-Another-Test"});
$this->assertEquals('Test2', $body->headers->{'X-Another-Test'});
}
public function testPost()
{
$response = $this->client->post('https://httpbin.org/post', [], ['X-Post-Test' => 'Testing a POST request.']);
$response = $this->client->post('https://httpbin.org/post', ['X-Post-Test' => 'Testing a POST request.']);
$headers = $response->getHeaders();
$this->assertEquals("application/json", $headers["Content-Type"][0]);
$this->assertEquals('application/json', $headers['Content-Type'][0]);
$body = json_decode($response->getBody());
$this->assertEquals("Testing a POST request.", $body->json->{"X-Post-Test"});
$this->assertEquals('Testing a POST request.', $body->json->{'X-Post-Test'});
}
public function testPut()
{
$response = $this->client->put('https://httpbin.org/put', [], ['X-Put-Test' => 'Testing a PUT request.']);
$response = $this->client->put('https://httpbin.org/put', ['X-Put-Test' => 'Testing a PUT request.']);
$headers = $response->getHeaders();
$this->assertEquals("application/json", $headers["Content-Type"][0]);
$this->assertEquals('application/json', $headers['Content-Type'][0]);
$body = json_decode($response->getBody());
$this->assertEquals("Testing a PUT request.", $body->json->{"X-Put-Test"});
$this->assertEquals('Testing a PUT request.', $body->json->{'X-Put-Test'});
}
public function testPatch()
{
$response = $this->client->patch(
'https://httpbin.org/patch',
[],
['X-Patch-Test' => 'Testing a PATCH request.']
);
$headers = $response->getHeaders();
$this->assertEquals("application/json", $headers["Content-Type"][0]);
$this->assertEquals('application/json', $headers['Content-Type'][0]);
$body = json_decode($response->getBody());
$this->assertEquals("Testing a PATCH request.", $body->json->{"X-Patch-Test"});
$this->assertEquals('Testing a PATCH request.', $body->json->{'X-Patch-Test'});
}
public function testDelete()
{
$response = $this->client->delete(
'https://httpbin.org/delete',
[],
['X-Delete-Test' => 'Testing a DELETE request.']
);
$headers = $response->getHeaders();
$this->assertEquals("application/json", $headers["Content-Type"][0]);
$this->assertEquals('application/json', $headers['Content-Type'][0]);
$body = json_decode($response->getBody());
$this->assertEquals("Testing a DELETE request.", $body->json->{"X-Delete-Test"});
$this->assertEquals('Testing a DELETE request.', $body->json->{'X-Delete-Test'});
}
public function testErrors()

View File

@@ -18,6 +18,6 @@ class APIKeyTest extends TestCase
$this->assertEquals('example@example.com', $headers['X-Auth-Email']);
$this->assertEquals('1234567893feefc5f0q5000bfo0c38d90bbeb', $headers['X-Auth-Key']);
$this->assertEquals(2, sizeof($headers));
$this->assertCount(2, $headers);
}
}

View File

@@ -6,8 +6,6 @@
* Time: 20:08
*/
use Cloudflare\API\Auth\None;
class NoneTest extends TestCase
{
public function testGetHeaders()

View File

@@ -9,7 +9,7 @@ class UserServiceKeyTest extends TestCase
{
public function testGetHeaders()
{
$auth = new \Cloudflare\API\Auth\UserServiceKey("v1.0-e24fd090c02efcfecb4de8f4ff246fd5c75b48946fdf0ce26c59f91d0d90797b-cfa33fe60e8e34073c149323454383fc9005d25c9b4c502c2f063457ef65322eade065975001a0b4b4c591c5e1bd36a6e8f7e2d4fa8a9ec01c64c041e99530c2-07b9efe0acd78c82c8d9c690aacb8656d81c369246d7f996a205fe3c18e9254a");
$auth = new \Cloudflare\API\Auth\UserServiceKey('v1.0-e24fd090c02efcfecb4de8f4ff246fd5c75b48946fdf0ce26c59f91d0d90797b-cfa33fe60e8e34073c149323454383fc9005d25c9b4c502c2f063457ef65322eade065975001a0b4b4c591c5e1bd36a6e8f7e2d4fa8a9ec01c64c041e99530c2-07b9efe0acd78c82c8d9c690aacb8656d81c369246d7f996a205fe3c18e9254a');
$headers = $auth->getHeaders();
$this->assertArrayHasKey('X-Auth-User-Service-Key', $headers);
@@ -19,6 +19,6 @@ class UserServiceKeyTest extends TestCase
$headers['X-Auth-User-Service-Key']
);
$this->assertEquals(1, sizeof($headers));
$this->assertCount(1, $headers);
}
}

View File

@@ -14,14 +14,14 @@ class ConfigurationsUARulesTest extends TestCase
$configuration->addUA('Mozilla/5.0 (Macintosh; Intel Mac OS X 10_12_5) AppleWebKit/603.2.4 (KHTML, like Gecko) Version/10.1.1 Safari/603.2.4');
$array = $configuration->getArray();
$this->assertEquals(1, sizeof($array));
$this->assertCount(1, $array);
$this->assertObjectHasAttribute('target', $array[0]);
$this->assertEquals('ua', $array[0]->target);
$this->assertObjectHasAttribute('value', $array[0]);
$this->assertArrayHasKey('target', $array[0]);
$this->assertEquals('ua', $array[0]['target']);
$this->assertArrayHasKey('value', $array[0]);
$this->assertEquals(
'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_12_5) AppleWebKit/603.2.4 (KHTML, like Gecko) Version/10.1.1 Safari/603.2.4',
$array[0]->value
$array[0]['value']
);
}
}

View File

@@ -0,0 +1,34 @@
<?php
/**
* Created by PhpStorm.
* User: junade
* Date: 05/09/2017
* Time: 13:50
*/
class ConfigurationsZoneLockdownTest extends TestCase
{
public function testGetArray()
{
$configuration = new \Cloudflare\API\Configurations\ZoneLockdown();
$configuration->addIP('1.2.3.4');
$array = $configuration->getArray();
$this->assertCount(1, $array);
$this->assertArrayHasKey('target', $array[0]);
$this->assertEquals('ip', $array[0]['target']);
$this->assertArrayHasKey('value', $array[0]);
$this->assertEquals('1.2.3.4', $array[0]['value']);
$configuration->addIPRange('1.2.3.4/24');
$array = $configuration->getArray();
$this->assertCount(2, $array);
$this->assertArrayHasKey('target', $array[1]);
$this->assertEquals('ip_range', $array[1]['target']);
$this->assertArrayHasKey('value', $array[1]);
$this->assertEquals('1.2.3.4/24', $array[1]['value']);
}
}

View File

@@ -0,0 +1,21 @@
<?php
use Cloudflare\API\Configurations\PageRulesActions;
class PageRulesActionTest extends TestCase
{
public function testForwardingURLConfigurationIsApplied()
{
$identifier = 'forwarding_url';
$statusCode = 301;
$forwardingURL = 'https://www.example.org/';
$actions = new PageRulesActions();
$actions->setForwardingURL($statusCode, $forwardingURL);
$configuration = $actions->getArray();
$this->assertCount(1, $configuration);
$this->assertEquals($identifier, $configuration[0]['id']);
$this->assertEquals($statusCode, $configuration[0]['value']['status_code']);
$this->assertEquals($forwardingURL, $configuration[0]['value']['url']);
}
}

View File

@@ -15,8 +15,8 @@ class PageRulesTargetTest extends TestCase
$targets = new PageRulesTargets('junade.com/*');
$array = $targets->getArray();
$this->assertEquals(1, sizeof($array));
$this->assertEquals("junade.com/*", $array[0]->constraint->value);
$this->assertEquals("matches", $array[0]->constraint->operator);
$this->assertCount(1, $array);
$this->assertEquals('junade.com/*', $array[0]['constraint']['value']);
$this->assertEquals('matches', $array[0]['constraint']['operator']);
}
}

View File

@@ -1,34 +0,0 @@
<?php
/**
* Created by PhpStorm.
* User: junade
* Date: 05/09/2017
* Time: 13:50
*/
class ConfigurationZoneLockdownTest extends TestCase
{
public function testGetArray()
{
$configuration = new \Cloudflare\API\Configurations\ZoneLockdown();
$configuration->addIP('1.2.3.4');
$array = $configuration->getArray();
$this->assertEquals(1, sizeof($array));
$this->assertObjectHasAttribute('target', $array[0]);
$this->assertEquals('ip', $array[0]->target);
$this->assertObjectHasAttribute('value', $array[0]);
$this->assertEquals('1.2.3.4', $array[0]->value);
$configuration->addIPRange('1.2.3.4/24');
$array = $configuration->getArray();
$this->assertEquals(2, sizeof($array));
$this->assertObjectHasAttribute('target', $array[1]);
$this->assertEquals('ip_range', $array[1]->target);
$this->assertObjectHasAttribute('value', $array[1]);
$this->assertEquals('1.2.3.4/24', $array[1]->value);
}
}

View File

@@ -0,0 +1,108 @@
<?php
class AccessRulesTest extends TestCase
{
public function testListRules()
{
$response = $this->getPsr7JsonResponseForFixture('Endpoints/listAccessRules.json');
$mock = $this->getMockBuilder(\Cloudflare\API\Adapter\Adapter::class)->getMock();
$mock->method('get')->willReturn($response);
$mock->expects($this->once())
->method('get')
->with(
$this->equalTo('zones/023e105f4ecef8ad9ca31a8372d0c353/firewall/access_rules/rules'),
$this->equalTo([
'page' => 1,
'per_page' => 50,
'match' => 'all'
])
);
$zones = new \Cloudflare\API\Endpoints\AccessRules($mock);
$result = $zones->listRules('023e105f4ecef8ad9ca31a8372d0c353');
$this->assertObjectHasAttribute('result', $result);
$this->assertObjectHasAttribute('result_info', $result);
$this->assertEquals('92f17202ed8bd63d69a66b86a49a8f6b', $result->result[0]->id);
$this->assertEquals(1, $result->result_info->page);
}
public function testCreateRule()
{
$config = new \Cloudflare\API\Configurations\AccessRules();
$config->setIP('1.2.3.4');
$response = $this->getPsr7JsonResponseForFixture('Endpoints/createAccessRule.json');
$mock = $this->getMockBuilder(\Cloudflare\API\Adapter\Adapter::class)->getMock();
$mock->method('post')->willReturn($response);
$mock->expects($this->once())
->method('post')
->with(
$this->equalTo('zones/023e105f4ecef8ad9ca31a8372d0c353/firewall/access_rules/rules'),
$this->equalTo([
'mode' => 'challenge',
'configuration' => $config->getArray(),
'notes' => 'This rule is on because of an event that occured on date X',
])
);
$rules = new \Cloudflare\API\Endpoints\AccessRules($mock);
$rules->createRule(
'023e105f4ecef8ad9ca31a8372d0c353',
'challenge',
$config,
'This rule is on because of an event that occured on date X'
);
}
public function testUpdateRule()
{
$response = $this->getPsr7JsonResponseForFixture('Endpoints/updateAccessRule.json');
$mock = $this->getMockBuilder(\Cloudflare\API\Adapter\Adapter::class)->getMock();
$mock->method('patch')->willReturn($response);
$mock->expects($this->once())
->method('patch')
->with(
$this->equalTo('zones/023e105f4ecef8ad9ca31a8372d0c353/firewall/access_rules/rules/92f17202ed8bd63d69a66b86a49a8f6b'),
$this->equalTo([
'mode' => 'challenge',
'notes' => 'This rule is on because of an event that occured on date X',
])
);
$rules = new \Cloudflare\API\Endpoints\AccessRules($mock);
$rules->updateRule(
'023e105f4ecef8ad9ca31a8372d0c353',
'92f17202ed8bd63d69a66b86a49a8f6b',
'challenge',
'This rule is on because of an event that occured on date X'
);
}
public function testDeleteRule()
{
$response = $this->getPsr7JsonResponseForFixture('Endpoints/deleteAccessRule.json');
$mock = $this->getMockBuilder(\Cloudflare\API\Adapter\Adapter::class)->getMock();
$mock->method('delete')->willReturn($response);
$mock->expects($this->once())
->method('delete')
->with(
$this->equalTo('zones/023e105f4ecef8ad9ca31a8372d0c353/firewall/access_rules/rules/92f17202ed8bd63d69a66b86a49a8f6b'),
$this->equalTo([
'cascade' => 'none'
])
);
$rules = new \Cloudflare\API\Endpoints\AccessRules($mock);
$rules->deleteRule('023e105f4ecef8ad9ca31a8372d0c353', '92f17202ed8bd63d69a66b86a49a8f6b');
}
}

View File

@@ -0,0 +1,133 @@
<?php
/**
* Created by PhpStorm.
* User: junade
* Date: 18/03/2018
* Time: 22:23
*/
use Cloudflare\API\Endpoints\CustomHostnames;
class CustomHostnamesTest extends TestCase
{
public function testAddHostname()
{
$response = $this->getPsr7JsonResponseForFixture('Endpoints/createCustomHostname.json');
$mock = $this->getMockBuilder(\Cloudflare\API\Adapter\Adapter::class)->getMock();
$mock->method('post')->willReturn($response);
$mock->expects($this->once())
->method('post')
->with(
$this->equalTo('zones/023e105f4ecef8ad9ca31a8372d0c353/custom_hostnames'),
$this->equalTo([
'hostname' => 'app.example.com',
'ssl' => [
'method' => 'http',
'type' => 'dv'
]
])
);
$hostname = new CustomHostnames($mock);
$hostname->addHostname('023e105f4ecef8ad9ca31a8372d0c353', 'app.example.com', 'http', 'dv');
}
public function testListHostnames()
{
$response = $this->getPsr7JsonResponseForFixture('Endpoints/listHostnames.json');
$mock = $this->getMockBuilder(\Cloudflare\API\Adapter\Adapter::class)->getMock();
$mock->method('get')->willReturn($response);
$mock->expects($this->once())
->method('get')
->with(
$this->equalTo('zones/023e105f4ecef8ad9ca31a8372d0c353/custom_hostnames'),
$this->equalTo([
'hostname' => 'app.example.com',
'id' => '0d89c70d-ad9f-4843-b99f-6cc0252067e9',
'page' => 1,
'per_page' => 20,
'order' => 'ssl',
'direction' => 'desc',
'ssl' => 0
])
);
$zones = new \Cloudflare\API\Endpoints\CustomHostnames($mock);
$result = $zones->listHostnames('023e105f4ecef8ad9ca31a8372d0c353', 'app.example.com', '0d89c70d-ad9f-4843-b99f-6cc0252067e9', 1, 20, 'ssl', 'desc', 0);
$this->assertObjectHasAttribute('result', $result);
$this->assertObjectHasAttribute('result_info', $result);
$this->assertEquals('0d89c70d-ad9f-4843-b99f-6cc0252067e9', $result->result[0]->id);
$this->assertEquals(1, $result->result_info->page);
}
public function testGetHostname()
{
$response = $this->getPsr7JsonResponseForFixture('Endpoints/getHostname.json');
$mock = $this->getMockBuilder(\Cloudflare\API\Adapter\Adapter::class)->getMock();
$mock->method('get')->willReturn($response);
$mock->expects($this->once())
->method('get')
->with(
$this->equalTo('zones/023e105f4ecef8ad9ca31a8372d0c353/custom_hostnames/0d89c70d-ad9f-4843-b99f-6cc0252067e9')
);
$zones = new \Cloudflare\API\Endpoints\CustomHostnames($mock);
$result = $zones->getHostname('023e105f4ecef8ad9ca31a8372d0c353', '0d89c70d-ad9f-4843-b99f-6cc0252067e9', '0d89c70d-ad9f-4843-b99f-6cc0252067e9');
$this->assertObjectHasAttribute('id', $result);
$this->assertObjectHasAttribute('hostname', $result);
}
public function testUpdateHostname()
{
$response = $this->getPsr7JsonResponseForFixture('Endpoints/updateHostname.json');
$mock = $this->getMockBuilder(\Cloudflare\API\Adapter\Adapter::class)->getMock();
$mock->method('patch')->willReturn($response);
$mock->expects($this->once())
->method('patch')
->with(
$this->equalTo('zones/023e105f4ecef8ad9ca31a8372d0c353/custom_hostnames/0d89c70d-ad9f-4843-b99f-6cc0252067e9'),
$this->equalTo([
'ssl' => [
'method' => 'http',
'type' => 'dv'
]
])
);
$zones = new \Cloudflare\API\Endpoints\CustomHostnames($mock);
$result = $zones->updateHostname('023e105f4ecef8ad9ca31a8372d0c353', '0d89c70d-ad9f-4843-b99f-6cc0252067e9', 'http', 'dv');
$this->assertObjectHasAttribute('id', $result);
$this->assertObjectHasAttribute('hostname', $result);
}
public function testDeleteHostname()
{
$response = $this->getPsr7JsonResponseForFixture('Endpoints/deleteHostname.json');
$mock = $this->getMockBuilder(\Cloudflare\API\Adapter\Adapter::class)->getMock();
$mock->method('delete')->willReturn($response);
$mock->expects($this->once())
->method('delete')
->with(
$this->equalTo('zones/023e105f4ecef8ad9ca31a8372d0c353/custom_hostnames/0d89c70d-ad9f-4843-b99f-6cc0252067e9')
);
$zones = new \Cloudflare\API\Endpoints\CustomHostnames($mock);
$result = $zones->deleteHostname('023e105f4ecef8ad9ca31a8372d0c353', '0d89c70d-ad9f-4843-b99f-6cc0252067e9');
$this->assertEquals('0d89c70d-ad9f-4843-b99f-6cc0252067e9', $result->id);
}
}

View File

@@ -19,7 +19,6 @@ class DNSTest extends TestCase
->method('post')
->with(
$this->equalTo('zones/023e105f4ecef8ad9ca31a8372d0c353/dns_records'),
$this->equalTo([]),
$this->equalTo([
'type' => 'A',
'name' => 'example.com',
@@ -44,25 +43,25 @@ class DNSTest extends TestCase
->method('get')
->with(
$this->equalTo('zones/023e105f4ecef8ad9ca31a8372d0c353/dns_records'),
$this->equalTo([
'page' => 1,
'per_page' => 20,
'match' => 'all',
'type' => 'A',
'name' => 'example.com',
'content' => '127.0.0.1',
'order' => 'type',
'direction' => 'desc']),
$this->equalTo([])
$this->equalTo([
'page' => 1,
'per_page' => 20,
'match' => 'all',
'type' => 'A',
'name' => 'example.com',
'content' => '127.0.0.1',
'order' => 'type',
'direction' => 'desc',
])
);
$zones = new \Cloudflare\API\Endpoints\DNS($mock);
$result = $zones->listRecords("023e105f4ecef8ad9ca31a8372d0c353", "A", "example.com", "127.0.0.1", 1, 20, "type", "desc", "all");
$result = $zones->listRecords('023e105f4ecef8ad9ca31a8372d0c353', 'A', 'example.com', '127.0.0.1', 1, 20, 'type', 'desc');
$this->assertObjectHasAttribute('result', $result);
$this->assertObjectHasAttribute('result_info', $result);
$this->assertEquals("372e67954025e0ba6aaa6d586b9e0b59", $result->result[0]->id);
$this->assertEquals('372e67954025e0ba6aaa6d586b9e0b59', $result->result[0]->id);
$this->assertEquals(1, $result->result_info->page);
}
@@ -76,14 +75,13 @@ class DNSTest extends TestCase
$mock->expects($this->once())
->method('get')
->with(
$this->equalTo('zones/023e105f4ecef8ad9ca31a8372d0c353/dns_records/372e67954025e0ba6aaa6d586b9e0b59'),
$this->equalTo([])
$this->equalTo('zones/023e105f4ecef8ad9ca31a8372d0c353/dns_records/372e67954025e0ba6aaa6d586b9e0b59')
);
$dns = new \Cloudflare\API\Endpoints\DNS($mock);
$result = $dns->getRecordDetails("023e105f4ecef8ad9ca31a8372d0c353", "372e67954025e0ba6aaa6d586b9e0b59");
$result = $dns->getRecordDetails('023e105f4ecef8ad9ca31a8372d0c353', '372e67954025e0ba6aaa6d586b9e0b59');
$this->assertEquals("372e67954025e0ba6aaa6d586b9e0b59", $result->id);
$this->assertEquals('372e67954025e0ba6aaa6d586b9e0b59', $result->id);
}
public function testUpdateDNSRecord()
@@ -95,8 +93,8 @@ class DNSTest extends TestCase
$details = [
'type' => 'A',
'name' => "example.com",
'content' => "1.2.3.4",
'name' => 'example.com',
'content' => '1.2.3.4',
'ttl' => 120,
'proxied' => false,
];
@@ -105,14 +103,13 @@ class DNSTest extends TestCase
->method('put')
->with(
$this->equalTo('zones/023e105f4ecef8ad9ca31a8372d0c353/dns_records/372e67954025e0ba6aaa6d586b9e0b59'),
$this->equalTo([]),
$this->equalTo($details)
);
$dns = new \Cloudflare\API\Endpoints\DNS($mock);
$result = $dns->updateRecordDetails("023e105f4ecef8ad9ca31a8372d0c353", "372e67954025e0ba6aaa6d586b9e0b59", $details);
$result = $dns->updateRecordDetails('023e105f4ecef8ad9ca31a8372d0c353', '372e67954025e0ba6aaa6d586b9e0b59', $details);
$this->assertEquals("372e67954025e0ba6aaa6d586b9e0b59", $result->result->id);
$this->assertEquals('372e67954025e0ba6aaa6d586b9e0b59', $result->result->id);
foreach ($details as $property => $value) {
$this->assertEquals($result->result->{ $property }, $value);

View File

@@ -6,8 +6,6 @@
* Time: 20:16
*/
use Cloudflare\API\Endpoints\IPs;
class IPsTest extends TestCase
{
public function testListIPs()
@@ -20,13 +18,12 @@ class IPsTest extends TestCase
$mock->expects($this->once())
->method('get')
->with(
$this->equalTo('ips'),
$this->equalTo([])
$this->equalTo('ips')
);
$ips = new \Cloudflare\API\Endpoints\IPs($mock);
$ips = $ips->listIPs();
$this->assertObjectHasAttribute("ipv4_cidrs", $ips);
$this->assertObjectHasAttribute("ipv6_cidrs", $ips);
$this->assertObjectHasAttribute('ipv4_cidrs', $ips);
$this->assertObjectHasAttribute('ipv6_cidrs', $ips);
}
}

View File

@@ -6,8 +6,6 @@
* Time: 19:25
*/
use Cloudflare\API\Adapter\PageRules;
class PageRulesTest extends TestCase
{
public function testCreatePageRule()
@@ -25,7 +23,6 @@ class PageRulesTest extends TestCase
->method('post')
->with(
$this->equalTo('zones/023e105f4ecef8ad9ca31a8372d0c353/pagerules'),
$this->equalTo([]),
$this->equalTo([
'targets' => $target->getArray(),
'actions' => $action->getArray(),
@@ -56,8 +53,7 @@ class PageRulesTest extends TestCase
'order' => 'status',
'direction' => 'desc',
'match' => 'all'
]),
$this->equalTo([])
])
);
$pageRules = new \Cloudflare\API\Endpoints\PageRules($mock);
@@ -74,8 +70,7 @@ class PageRulesTest extends TestCase
$mock->expects($this->once())
->method('get')
->with(
$this->equalTo('zones/023e105f4ecef8ad9ca31a8372d0c353/pagerules/9a7806061c88ada191ed06f989cc3dac'),
$this->equalTo([])
$this->equalTo('zones/023e105f4ecef8ad9ca31a8372d0c353/pagerules/9a7806061c88ada191ed06f989cc3dac')
);
$pageRules = new \Cloudflare\API\Endpoints\PageRules($mock);
@@ -97,7 +92,6 @@ class PageRulesTest extends TestCase
->method('patch')
->with(
$this->equalTo('zones/023e105f4ecef8ad9ca31a8372d0c353/pagerules'),
$this->equalTo([]),
$this->equalTo([
'targets' => $target->getArray(),
'actions' => $action->getArray(),
@@ -122,9 +116,7 @@ class PageRulesTest extends TestCase
$mock->expects($this->once())
->method('delete')
->with(
$this->equalTo('zones/023e105f4ecef8ad9ca31a8372d0c353/pagerules/9a7806061c88ada191ed06f989cc3dac'),
$this->equalTo([]),
$this->equalTo([])
$this->equalTo('zones/023e105f4ecef8ad9ca31a8372d0c353/pagerules/9a7806061c88ada191ed06f989cc3dac')
);
$pageRules = new \Cloudflare\API\Endpoints\PageRules($mock);

View File

@@ -6,14 +6,12 @@
* Time: 11:20
*/
use Cloudflare\API\Endpoints\Railgun;
class RailgunTest extends TestCase
{
public function testcreate()
{
$details = [
'name' => "My Railgun",
'name' => 'My Railgun',
];
$response = $this->getPsr7JsonResponseForFixture('Endpoints/createRailgun.json');
@@ -25,7 +23,6 @@ class RailgunTest extends TestCase
->method('post')
->with(
$this->equalTo('railguns'),
$this->equalTo([]),
$this->equalTo(['name' => $details['name']])
);
@@ -54,12 +51,11 @@ class RailgunTest extends TestCase
'page' => 1,
'per_page' => 20,
'direction' => 'desc'
]),
$this->equalTo([])
])
);
$railgun = new \Cloudflare\API\Endpoints\Railgun($mock);
$result = $railgun->list(1, 20, "desc");
$result = $railgun->list(1, 20, 'desc');
$this->assertObjectHasAttribute('result', $result);
$this->assertObjectHasAttribute('result_info', $result);
@@ -75,14 +71,13 @@ class RailgunTest extends TestCase
$mock->expects($this->once())
->method('get')
->with(
$this->equalTo('railguns/e928d310693a83094309acf9ead50448'),
$this->equalTo([])
$this->equalTo('railguns/e928d310693a83094309acf9ead50448')
);
$railgun = new \Cloudflare\API\Endpoints\Railgun($mock);
$result = $railgun->get("e928d310693a83094309acf9ead50448");
$result = $railgun->get('e928d310693a83094309acf9ead50448');
$this->assertEquals("e928d310693a83094309acf9ead50448", $result->id);
$this->assertEquals('e928d310693a83094309acf9ead50448', $result->id);
}
public function testgetZones()
@@ -95,13 +90,11 @@ class RailgunTest extends TestCase
$mock->expects($this->once())
->method('get')
->with(
$this->equalTo('railguns/e928d310693a83094309acf9ead50448/zones'),
$this->equalTo([]),
$this->equalTo([])
$this->equalTo('railguns/e928d310693a83094309acf9ead50448/zones')
);
$railgun = new \Cloudflare\API\Endpoints\Railgun($mock);
$result = $railgun->getZones("e928d310693a83094309acf9ead50448");
$result = $railgun->getZones('e928d310693a83094309acf9ead50448');
$this->assertObjectHasAttribute('result', $result);
$this->assertObjectHasAttribute('result_info', $result);
@@ -122,14 +115,13 @@ class RailgunTest extends TestCase
->method('patch')
->with(
$this->equalTo('railguns/e928d310693a83094309acf9ead50448'),
$this->equalTo([]),
$this->equalTo($details)
);
$waf = new \Cloudflare\API\Endpoints\Railgun($mock);
$result = $waf->update("e928d310693a83094309acf9ead50448", true);
$result = $waf->update('e928d310693a83094309acf9ead50448', true);
$this->assertEquals("e928d310693a83094309acf9ead50448", $result->id);
$this->assertEquals('e928d310693a83094309acf9ead50448', $result->id);
}
public function testdelete()
@@ -142,12 +134,10 @@ class RailgunTest extends TestCase
$mock->expects($this->once())
->method('delete')
->with(
$this->equalTo('railguns/e928d310693a83094309acf9ead50448'),
$this->equalTo([]),
$this->equalTo([])
$this->equalTo('railguns/e928d310693a83094309acf9ead50448')
);
$waf = new \Cloudflare\API\Endpoints\Railgun($mock);
$waf->delete("e928d310693a83094309acf9ead50448");
$waf->delete('e928d310693a83094309acf9ead50448');
}
}

View File

@@ -22,17 +22,16 @@ class UARulesTest extends TestCase
$this->equalTo([
'page' => 1,
'per_page' => 20
]),
$this->equalTo([])
])
);
$zones = new \Cloudflare\API\Endpoints\UARules($mock);
$result = $zones->listRules("023e105f4ecef8ad9ca31a8372d0c353", 1, 20);
$result = $zones->listRules('023e105f4ecef8ad9ca31a8372d0c353');
$this->assertObjectHasAttribute('result', $result);
$this->assertObjectHasAttribute('result_info', $result);
$this->assertEquals("372e67954025e0ba6aaa6d586b9e0b59", $result->result[0]->id);
$this->assertEquals('372e67954025e0ba6aaa6d586b9e0b59', $result->result[0]->id);
$this->assertEquals(1, $result->result_info->page);
}
@@ -50,7 +49,6 @@ class UARulesTest extends TestCase
->method('post')
->with(
$this->equalTo('zones/023e105f4ecef8ad9ca31a8372d0c353/firewall/ua_rules'),
$this->equalTo([]),
$this->equalTo([
'mode' => 'js_challenge',
'id' => '372e67954025e0ba6aaa6d586b9e0b59',
@@ -79,14 +77,13 @@ class UARulesTest extends TestCase
$mock->expects($this->once())
->method('get')
->with(
$this->equalTo('zones/023e105f4ecef8ad9ca31a8372d0c353/firewall/ua_rules/372e67954025e0ba6aaa6d586b9e0b59'),
$this->equalTo([])
$this->equalTo('zones/023e105f4ecef8ad9ca31a8372d0c353/firewall/ua_rules/372e67954025e0ba6aaa6d586b9e0b59')
);
$lockdown = new \Cloudflare\API\Endpoints\UARules($mock);
$result = $lockdown->getRuleDetails("023e105f4ecef8ad9ca31a8372d0c353", "372e67954025e0ba6aaa6d586b9e0b59");
$result = $lockdown->getRuleDetails('023e105f4ecef8ad9ca31a8372d0c353', '372e67954025e0ba6aaa6d586b9e0b59');
$this->assertEquals("372e67954025e0ba6aaa6d586b9e0b59", $result->id);
$this->assertEquals('372e67954025e0ba6aaa6d586b9e0b59', $result->id);
}
public function testUpdateRule()
@@ -103,7 +100,6 @@ class UARulesTest extends TestCase
->method('put')
->with(
$this->equalTo('zones/023e105f4ecef8ad9ca31a8372d0c353/firewall/ua_rules/372e67954025e0ba6aaa6d586b9e0b59'),
$this->equalTo([]),
$this->equalTo([
'mode' => 'js_challenge',
'id' => '372e67954025e0ba6aaa6d586b9e0b59',
@@ -132,9 +128,7 @@ class UARulesTest extends TestCase
$mock->expects($this->once())
->method('delete')
->with(
$this->equalTo('zones/023e105f4ecef8ad9ca31a8372d0c353/firewall/ua_rules/372e67954025e0ba6aaa6d586b9e0b59'),
$this->equalTo([]),
$this->equalTo([])
$this->equalTo('zones/023e105f4ecef8ad9ca31a8372d0c353/firewall/ua_rules/372e67954025e0ba6aaa6d586b9e0b59')
);
$rules = new \Cloudflare\API\Endpoints\UARules($mock);

View File

@@ -17,10 +17,10 @@ class UserTest extends TestCase
$user = new \Cloudflare\API\Endpoints\User($mock);
$details = $user->getUserDetails();
$this->assertObjectHasAttribute("id", $details);
$this->assertEquals("7c5dae5552338874e5053f2534d2767a", $details->id);
$this->assertObjectHasAttribute("email", $details);
$this->assertEquals("user@example.com", $details->email);
$this->assertObjectHasAttribute('id', $details);
$this->assertEquals('7c5dae5552338874e5053f2534d2767a', $details->id);
$this->assertObjectHasAttribute('email', $details);
$this->assertEquals('user@example.com', $details->email);
}
public function testGetUserID()
@@ -31,7 +31,7 @@ class UserTest extends TestCase
$mock->method('get')->willReturn($response);
$user = new \Cloudflare\API\Endpoints\User($mock);
$this->assertEquals("7c5dae5552338874e5053f2534d2767a", $user->getUserID());
$this->assertEquals('7c5dae5552338874e5053f2534d2767a', $user->getUserID());
}
public function testGetUserEmail()
@@ -44,7 +44,7 @@ class UserTest extends TestCase
$mock->expects($this->once())->method('get');
$user = new \Cloudflare\API\Endpoints\User($mock);
$this->assertEquals("user@example.com", $user->getUserEmail());
$this->assertEquals('user@example.com', $user->getUserEmail());
}
public function testUpdateUserDetails()
@@ -56,9 +56,9 @@ class UserTest extends TestCase
$mock->expects($this->once())
->method('patch')
->with($this->equalTo('user'), $this->equalTo([]), $this->equalTo(['email' => 'user2@example.com']));
->with($this->equalTo('user'), $this->equalTo(['email' => 'user2@example.com']));
$user = new \Cloudflare\API\Endpoints\User($mock);
$user->updateUserDetails(['email' => "user2@example.com"]);
$user->updateUserDetails(['email' => 'user2@example.com']);
}
}

View File

@@ -6,8 +6,6 @@
* Time: 13:34
*/
use Cloudflare\API\Endpoints\WAF;
class WAFTest extends TestCase
{
public function testgetPackages()
@@ -27,17 +25,16 @@ class WAFTest extends TestCase
'match' => 'all',
'order' => 'status',
'direction' => 'desc'
]),
$this->equalTo([])
])
);
$waf = new \Cloudflare\API\Endpoints\WAF($mock);
$result = $waf->getPackages("023e105f4ecef8ad9ca31a8372d0c353", 1, 20, "status", "desc", "all");
$result = $waf->getPackages('023e105f4ecef8ad9ca31a8372d0c353', 1, 20, 'status', 'desc');
$this->assertObjectHasAttribute('result', $result);
$this->assertObjectHasAttribute('result_info', $result);
$this->assertEquals("a25a9a7e9c00afc1fb2e0245519d725b", $result->result[0]->id);
$this->assertEquals('a25a9a7e9c00afc1fb2e0245519d725b', $result->result[0]->id);
$this->assertEquals(1, $result->result_info->page);
}
@@ -51,14 +48,13 @@ class WAFTest extends TestCase
$mock->expects($this->once())
->method('get')
->with(
$this->equalTo('zones/023e105f4ecef8ad9ca31a8372d0c353/firewall/waf/packages/a25a9a7e9c00afc1fb2e0245519d725b'),
$this->equalTo([])
$this->equalTo('zones/023e105f4ecef8ad9ca31a8372d0c353/firewall/waf/packages/a25a9a7e9c00afc1fb2e0245519d725b')
);
$waf = new \Cloudflare\API\Endpoints\WAF($mock);
$result = $waf->getPackageInfo("023e105f4ecef8ad9ca31a8372d0c353", "a25a9a7e9c00afc1fb2e0245519d725b");
$result = $waf->getPackageInfo('023e105f4ecef8ad9ca31a8372d0c353', 'a25a9a7e9c00afc1fb2e0245519d725b');
$this->assertEquals("a25a9a7e9c00afc1fb2e0245519d725b", $result->id);
$this->assertEquals('a25a9a7e9c00afc1fb2e0245519d725b', $result->id);
}
public function testgetRules()
@@ -78,17 +74,16 @@ class WAFTest extends TestCase
'match' => 'all',
'order' => 'status',
'direction' => 'desc'
]),
$this->equalTo([])
])
);
$waf = new \Cloudflare\API\Endpoints\WAF($mock);
$result = $waf->getRules("023e105f4ecef8ad9ca31a8372d0c353", "a25a9a7e9c00afc1fb2e0245519d725b", 1, 20, "status", "desc", "all");
$result = $waf->getRules('023e105f4ecef8ad9ca31a8372d0c353', 'a25a9a7e9c00afc1fb2e0245519d725b', 1, 20, 'status', 'desc');
$this->assertObjectHasAttribute('result', $result);
$this->assertObjectHasAttribute('result_info', $result);
$this->assertEquals("92f17202ed8bd63d69a66b86a49a8f6b", $result->result[0]->id);
$this->assertEquals('92f17202ed8bd63d69a66b86a49a8f6b', $result->result[0]->id);
$this->assertEquals(1, $result->result_info->page);
}
@@ -102,14 +97,13 @@ class WAFTest extends TestCase
$mock->expects($this->once())
->method('get')
->with(
$this->equalTo('zones/023e105f4ecef8ad9ca31a8372d0c353/firewall/waf/packages/a25a9a7e9c00afc1fb2e0245519d725b/rules/f939de3be84e66e757adcdcb87908023'),
$this->equalTo([])
$this->equalTo('zones/023e105f4ecef8ad9ca31a8372d0c353/firewall/waf/packages/a25a9a7e9c00afc1fb2e0245519d725b/rules/f939de3be84e66e757adcdcb87908023')
);
$waf = new \Cloudflare\API\Endpoints\WAF($mock);
$result = $waf->getRuleInfo("023e105f4ecef8ad9ca31a8372d0c353", "a25a9a7e9c00afc1fb2e0245519d725b", "f939de3be84e66e757adcdcb87908023");
$result = $waf->getRuleInfo('023e105f4ecef8ad9ca31a8372d0c353', 'a25a9a7e9c00afc1fb2e0245519d725b', 'f939de3be84e66e757adcdcb87908023');
$this->assertEquals("f939de3be84e66e757adcdcb87908023", $result->id);
$this->assertEquals('f939de3be84e66e757adcdcb87908023', $result->id);
}
public function testupdateRule()
@@ -120,21 +114,20 @@ class WAFTest extends TestCase
$mock->method('patch')->willReturn($response);
$details = [
'mode' => "on",
'mode' => 'on',
];
$mock->expects($this->once())
->method('patch')
->with(
$this->equalTo('zones/023e105f4ecef8ad9ca31a8372d0c353/firewall/waf/packages/a25a9a7e9c00afc1fb2e0245519d725b/rules/f939de3be84e66e757adcdcb87908023'),
$this->equalTo([]),
$this->equalTo($details)
);
$waf = new \Cloudflare\API\Endpoints\WAF($mock);
$result = $waf->updateRule("023e105f4ecef8ad9ca31a8372d0c353", "a25a9a7e9c00afc1fb2e0245519d725b", "f939de3be84e66e757adcdcb87908023", "on");
$result = $waf->updateRule('023e105f4ecef8ad9ca31a8372d0c353', 'a25a9a7e9c00afc1fb2e0245519d725b', 'f939de3be84e66e757adcdcb87908023', 'on');
$this->assertEquals("f939de3be84e66e757adcdcb87908023", $result->id);
$this->assertEquals('f939de3be84e66e757adcdcb87908023', $result->id);
foreach ($details as $property => $value) {
$this->assertEquals($result->{ $property }, $value);
@@ -158,17 +151,16 @@ class WAFTest extends TestCase
'match' => 'all',
'order' => 'status',
'direction' => 'desc'
]),
$this->equalTo([])
])
);
$waf = new \Cloudflare\API\Endpoints\WAF($mock);
$result = $waf->getGroups("023e105f4ecef8ad9ca31a8372d0c353", "a25a9a7e9c00afc1fb2e0245519d725b", 1, 20, "status", "desc", "all");
$result = $waf->getGroups('023e105f4ecef8ad9ca31a8372d0c353', 'a25a9a7e9c00afc1fb2e0245519d725b', 1, 20, 'status', 'desc');
$this->assertObjectHasAttribute('result', $result);
$this->assertObjectHasAttribute('result_info', $result);
$this->assertEquals("de677e5818985db1285d0e80225f06e5", $result->result[0]->id);
$this->assertEquals('de677e5818985db1285d0e80225f06e5', $result->result[0]->id);
$this->assertEquals(1, $result->result_info->page);
}
@@ -182,14 +174,13 @@ class WAFTest extends TestCase
$mock->expects($this->once())
->method('get')
->with(
$this->equalTo('zones/023e105f4ecef8ad9ca31a8372d0c353/firewall/waf/packages/a25a9a7e9c00afc1fb2e0245519d725b/groups/de677e5818985db1285d0e80225f06e5'),
$this->equalTo([])
$this->equalTo('zones/023e105f4ecef8ad9ca31a8372d0c353/firewall/waf/packages/a25a9a7e9c00afc1fb2e0245519d725b/groups/de677e5818985db1285d0e80225f06e5')
);
$waf = new \Cloudflare\API\Endpoints\WAF($mock);
$result = $waf->getGroupInfo("023e105f4ecef8ad9ca31a8372d0c353", "a25a9a7e9c00afc1fb2e0245519d725b", "de677e5818985db1285d0e80225f06e5");
$result = $waf->getGroupInfo('023e105f4ecef8ad9ca31a8372d0c353', 'a25a9a7e9c00afc1fb2e0245519d725b', 'de677e5818985db1285d0e80225f06e5');
$this->assertEquals("de677e5818985db1285d0e80225f06e5", $result->id);
$this->assertEquals('de677e5818985db1285d0e80225f06e5', $result->id);
}
public function testupdateGroup()
@@ -200,21 +191,20 @@ class WAFTest extends TestCase
$mock->method('patch')->willReturn($response);
$details = [
'mode' => "off",
'mode' => 'off',
];
$mock->expects($this->once())
->method('patch')
->with(
$this->equalTo('zones/023e105f4ecef8ad9ca31a8372d0c353/firewall/waf/packages/a25a9a7e9c00afc1fb2e0245519d725b/groups/de677e5818985db1285d0e80225f06e5'),
$this->equalTo([]),
$this->equalTo($details)
);
$waf = new \Cloudflare\API\Endpoints\WAF($mock);
$result = $waf->updateGroup("023e105f4ecef8ad9ca31a8372d0c353", "a25a9a7e9c00afc1fb2e0245519d725b", "de677e5818985db1285d0e80225f06e5", "off");
$result = $waf->updateGroup('023e105f4ecef8ad9ca31a8372d0c353', 'a25a9a7e9c00afc1fb2e0245519d725b', 'de677e5818985db1285d0e80225f06e5', 'off');
$this->assertEquals("de677e5818985db1285d0e80225f06e5", $result->id);
$this->assertEquals('de677e5818985db1285d0e80225f06e5', $result->id);
foreach ($details as $property => $value) {
$this->assertEquals($result->{ $property }, $value);

View File

@@ -19,20 +19,19 @@ class ZoneLockdownTest extends TestCase
->method('get')
->with(
$this->equalTo('zones/023e105f4ecef8ad9ca31a8372d0c353/firewall/lockdowns'),
$this->equalTo([
'page' => 1,
'per_page' => 20,
]),
$this->equalTo([])
$this->equalTo([
'page' => 1,
'per_page' => 20,
])
);
$zones = new \Cloudflare\API\Endpoints\ZoneLockdown($mock);
$result = $zones->listLockdowns("023e105f4ecef8ad9ca31a8372d0c353", 1, 20);
$result = $zones->listLockdowns('023e105f4ecef8ad9ca31a8372d0c353');
$this->assertObjectHasAttribute('result', $result);
$this->assertObjectHasAttribute('result_info', $result);
$this->assertEquals("372e67954025e0ba6aaa6d586b9e0b59", $result->result[0]->id);
$this->assertEquals('372e67954025e0ba6aaa6d586b9e0b59', $result->result[0]->id);
$this->assertEquals(1, $result->result_info->page);
}
@@ -50,9 +49,8 @@ class ZoneLockdownTest extends TestCase
->method('post')
->with(
$this->equalTo('zones/023e105f4ecef8ad9ca31a8372d0c353/firewall/lockdowns'),
$this->equalTo([]),
$this->equalTo([
'urls' => ["api.mysite.com/some/endpoint*"],
'urls' => ['api.mysite.com/some/endpoint*'],
'id' => '372e67954025e0ba6aaa6d586b9e0b59',
'description' => 'Restrict access to these endpoints to requests from a known IP address',
'configurations' => $config->getArray(),
@@ -62,7 +60,7 @@ class ZoneLockdownTest extends TestCase
$zoneLockdown = new \Cloudflare\API\Endpoints\ZoneLockdown($mock);
$zoneLockdown->createLockdown(
'023e105f4ecef8ad9ca31a8372d0c353',
["api.mysite.com/some/endpoint*"],
['api.mysite.com/some/endpoint*'],
$config,
'372e67954025e0ba6aaa6d586b9e0b59',
'Restrict access to these endpoints to requests from a known IP address'
@@ -79,14 +77,13 @@ class ZoneLockdownTest extends TestCase
$mock->expects($this->once())
->method('get')
->with(
$this->equalTo('zones/023e105f4ecef8ad9ca31a8372d0c353/firewall/lockdowns/372e67954025e0ba6aaa6d586b9e0b59'),
$this->equalTo([])
$this->equalTo('zones/023e105f4ecef8ad9ca31a8372d0c353/firewall/lockdowns/372e67954025e0ba6aaa6d586b9e0b59')
);
$lockdown = new \Cloudflare\API\Endpoints\ZoneLockdown($mock);
$result = $lockdown->getLockdownDetails("023e105f4ecef8ad9ca31a8372d0c353", "372e67954025e0ba6aaa6d586b9e0b59");
$result = $lockdown->getLockdownDetails('023e105f4ecef8ad9ca31a8372d0c353', '372e67954025e0ba6aaa6d586b9e0b59');
$this->assertEquals("372e67954025e0ba6aaa6d586b9e0b59", $result->id);
$this->assertEquals('372e67954025e0ba6aaa6d586b9e0b59', $result->id);
}
public function testUpdateLockdown()
@@ -103,9 +100,8 @@ class ZoneLockdownTest extends TestCase
->method('put')
->with(
$this->equalTo('zones/023e105f4ecef8ad9ca31a8372d0c353/firewall/lockdowns/372e67954025e0ba6aaa6d586b9e0b59'),
$this->equalTo([]),
$this->equalTo([
'urls' => ["api.mysite.com/some/endpoint*"],
'urls' => ['api.mysite.com/some/endpoint*'],
'id' => '372e67954025e0ba6aaa6d586b9e0b59',
'description' => 'Restrict access to these endpoints to requests from a known IP address',
'configurations' => $config->getArray(),
@@ -116,7 +112,7 @@ class ZoneLockdownTest extends TestCase
$zoneLockdown->updateLockdown(
'023e105f4ecef8ad9ca31a8372d0c353',
'372e67954025e0ba6aaa6d586b9e0b59',
["api.mysite.com/some/endpoint*"],
['api.mysite.com/some/endpoint*'],
$config,
'Restrict access to these endpoints to requests from a known IP address'
);
@@ -135,9 +131,7 @@ class ZoneLockdownTest extends TestCase
$mock->expects($this->once())
->method('delete')
->with(
$this->equalTo('zones/023e105f4ecef8ad9ca31a8372d0c353/firewall/lockdowns/372e67954025e0ba6aaa6d586b9e0b59'),
$this->equalTo([]),
$this->equalTo([])
$this->equalTo('zones/023e105f4ecef8ad9ca31a8372d0c353/firewall/lockdowns/372e67954025e0ba6aaa6d586b9e0b59')
);
$zoneLockdown = new \Cloudflare\API\Endpoints\ZoneLockdown($mock);

View File

@@ -19,34 +19,33 @@ class ZonesTest extends TestCase
->method('post')
->with(
$this->equalTo('zones'),
$this->equalTo([]),
$this->equalTo(['name' => 'example.com', 'jumpstart' => false])
$this->equalTo(['name' => 'example.com', 'jump_start' => false])
);
$zones = new \Cloudflare\API\Endpoints\Zones($mock);
$result = $zones->addZone("example.com");
$result = $zones->addZone('example.com');
$this->assertObjectHasAttribute("id", $result);
$this->assertEquals("023e105f4ecef8ad9ca31a8372d0c353", $result->id);
$this->assertObjectHasAttribute('id', $result);
$this->assertEquals('023e105f4ecef8ad9ca31a8372d0c353', $result->id);
$response = $this->getPsr7JsonResponseForFixture('Endpoints/createPageRule.json');
$mock = $this->getMockBuilder(\Cloudflare\API\Adapter\Adapter::class)->getMock();
$mock->method('post')->willReturn($response);
$org = new stdClass();
$org->id = "01a7362d577a6c3019a474fd6f485823";
$mock->expects($this->once())
->method('post')
->with(
$this->equalTo('zones'),
$this->equalTo([]),
$this->equalTo(['name' => 'example.com', 'jumpstart' => true, 'organization' => $org])
$this->equalTo([
'name' => 'example.com',
'jump_start' => true,
'organization' => ['id' => '01a7362d577a6c3019a474fd6f485823']
])
);
$zones = new \Cloudflare\API\Endpoints\Zones($mock);
$zones->addZone("example.com", true, "01a7362d577a6c3019a474fd6f485823");
$zones->addZone('example.com', true, '01a7362d577a6c3019a474fd6f485823');
}
public function testActivationTest()
@@ -59,13 +58,11 @@ class ZonesTest extends TestCase
$mock->expects($this->once())
->method('put')
->with(
$this->equalTo('zones/c2547eb745079dac9320b638f5e225cf483cc5cfdda41/activation_check'),
$this->equalTo([]),
$this->equalTo([])
$this->equalTo('zones/c2547eb745079dac9320b638f5e225cf483cc5cfdda41/activation_check')
);
$zones = new \Cloudflare\API\Endpoints\Zones($mock);
$result = $zones->activationCheck("c2547eb745079dac9320b638f5e225cf483cc5cfdda41");
$result = $zones->activationCheck('c2547eb745079dac9320b638f5e225cf483cc5cfdda41');
$this->assertTrue($result);
}
@@ -81,25 +78,24 @@ class ZonesTest extends TestCase
->method('get')
->with(
$this->equalTo('zones'),
$this->equalTo([
'page' => 1,
'per_page' => 20,
'match' => 'all',
'name' => 'example.com',
'status' => 'active',
'order' => 'status',
'direction' => 'desc'
]),
$this->equalTo([])
$this->equalTo([
'page' => 1,
'per_page' => 20,
'match' => 'all',
'name' => 'example.com',
'status' => 'active',
'order' => 'status',
'direction' => 'desc',
])
);
$zones = new \Cloudflare\API\Endpoints\Zones($mock);
$result = $zones->listZones("example.com", "active", 1, 20, "status", "desc", "all");
$result = $zones->listZones('example.com', 'active', 1, 20, 'status', 'desc');
$this->assertObjectHasAttribute('result', $result);
$this->assertObjectHasAttribute('result_info', $result);
$this->assertEquals("023e105f4ecef8ad9ca31a8372d0c353", $result->result[0]->id);
$this->assertEquals('023e105f4ecef8ad9ca31a8372d0c353', $result->result[0]->id);
$this->assertEquals(1, $result->result_info->page);
}
@@ -114,19 +110,59 @@ class ZonesTest extends TestCase
->method('get')
->with(
$this->equalTo('zones'),
$this->equalTo([
'page' => 1,
'per_page' => 20,
'match' => 'all',
'name' => 'example.com',
]),
$this->equalTo([])
$this->equalTo([
'page' => 1,
'per_page' => 20,
'match' => 'all',
'name' => 'example.com',
])
);
$zones = new \Cloudflare\API\Endpoints\Zones($mock);
$result = $zones->getZoneID("example.com");
$result = $zones->getZoneID('example.com');
$this->assertEquals("023e105f4ecef8ad9ca31a8372d0c353", $result);
$this->assertEquals('023e105f4ecef8ad9ca31a8372d0c353', $result);
}
public function testGetAnalyticsDashboard()
{
$response = $this->getPsr7JsonResponseForFixture('Endpoints/getAnalyticsDashboard.json');
$mock = $this->getMockBuilder(\Cloudflare\API\Adapter\Adapter::class)->getMock();
$mock->method('get')->willReturn($response);
$mock->expects($this->once())
->method('get')
->with(
$this->equalTo('zones/c2547eb745079dac9320b638f5e225cf483cc5cfdda41/analytics/dashboard'),
$this->equalTo(['since' => '-10080', 'until' => '0', 'continuous' => var_export(true, true)])
);
$zones = new \Cloudflare\API\Endpoints\Zones($mock);
$analytics = $zones->getAnalyticsDashboard('c2547eb745079dac9320b638f5e225cf483cc5cfdda41');
$this->assertObjectHasAttribute('since', $analytics->totals);
$this->assertObjectHasAttribute('since', $analytics->timeseries[0]);
}
public function testChangeDevelopmentMode()
{
$response = $this->getPsr7JsonResponseForFixture('Endpoints/changeDevelopmentMode.json');
$mock = $this->getMockBuilder(\Cloudflare\API\Adapter\Adapter::class)->getMock();
$mock->method('patch')->willReturn($response);
$mock->expects($this->once())
->method('patch')
->with(
$this->equalTo('zones/c2547eb745079dac9320b638f5e225cf483cc5cfdda41/settings/development_mode'),
$this->equalTo(['value' => 'on'])
);
$zones = new \Cloudflare\API\Endpoints\Zones($mock);
$result = $zones->changeDevelopmentMode('c2547eb745079dac9320b638f5e225cf483cc5cfdda41', true);
$this->assertTrue($result);
}
public function testCachePurgeEverything()
@@ -140,12 +176,37 @@ class ZonesTest extends TestCase
->method('delete')
->with(
$this->equalTo('zones/c2547eb745079dac9320b638f5e225cf483cc5cfdda41/purge_cache'),
$this->equalTo([]),
$this->equalTo(["purge_everything" => true])
$this->equalTo(['purge_everything' => true])
);
$zones = new \Cloudflare\API\Endpoints\Zones($mock);
$result = $zones->cachePurgeEverything("c2547eb745079dac9320b638f5e225cf483cc5cfdda41");
$result = $zones->cachePurgeEverything('c2547eb745079dac9320b638f5e225cf483cc5cfdda41');
$this->assertTrue($result);
}
public function testCachePurgeHost()
{
$response = $this->getPsr7JsonResponseForFixture('Endpoints/cachePurgeHost.json');
$mock = $this->getMockBuilder(\Cloudflare\API\Adapter\Adapter::class)->getMock();
$mock->method('delete')->willReturn($response);
$mock->expects($this->once())
->method('delete')
->with(
$this->equalTo('zones/c2547eb745079dac9320b638f5e225cf483cc5cfdda41/purge_cache'),
$this->equalTo(
[
'files' => [],
'tags' => [],
'hosts' => ['dash.cloudflare.com']
]
)
);
$zones = new \Cloudflare\API\Endpoints\Zones($mock);
$result = $zones->cachePurge('c2547eb745079dac9320b638f5e225cf483cc5cfdda41', [], [], ['dash.cloudflare.com']);
$this->assertTrue($result);
}

View File

@@ -0,0 +1,8 @@
{
"success": true,
"errors": [],
"messages": [],
"result": {
"id": "023e105f4ecef8ad9ca31a8372d0c353"
}
}

View File

@@ -0,0 +1,12 @@
{
"result": {
"id": "development_mode",
"value": "on",
"modified_on": "2017-11-06T05:16:42.864300Z",
"time_remaining": 10800,
"editable": true
},
"success": true,
"errors": [],
"messages": []
}

View File

@@ -0,0 +1,30 @@
{
"success": true,
"errors": [
{}
],
"messages": [
{}
],
"result": {
"id": "92f17202ed8bd63d69a66b86a49a8f6b",
"notes": "This rule is on because of an event that occured on date X",
"allowed_modes": [
"whitelist",
"block",
"challenge"
],
"mode": "challenge",
"configuration": {
"target": "ip",
"value": "1.2.3.4"
},
"scope": {
"id": "7c5dae5552338874e5053f2534d2767a",
"email": "user@example.com",
"type": "user"
},
"created_on": "2014-01-01T05:20:00.12345Z",
"modified_on": "2014-01-01T05:20:00.12345Z"
}
}

View File

@@ -0,0 +1,20 @@
{
"success": true,
"errors": [
{}
],
"messages": [
{}
],
"result": {
"id": "0d89c70d-ad9f-4843-b99f-6cc0252067e9",
"hostname": "app.example.com",
"ssl": {
"status": "pending_validation",
"method": "http",
"type": "dv",
"cname_target": "dcv.digicert.com",
"cname": "810b7d5f01154524b961ba0cd578acc2.app.example.com"
}
}
}

View File

@@ -0,0 +1,12 @@
{
"success": true,
"errors": [
{}
],
"messages": [
{}
],
"result": {
"id": "92f17202ed8bd63d69a66b86a49a8f6b"
}
}

View File

@@ -0,0 +1,3 @@
{
"id": "0d89c70d-ad9f-4843-b99f-6cc0252067e9"
}

View File

@@ -0,0 +1,176 @@
{
"success": true,
"errors": [
{}
],
"messages": [
{}
],
"result": {
"totals": {
"since": "2015-01-01T12:23:00Z",
"until": "2015-01-02T12:23:00Z",
"requests": {
"all": 1234085328,
"cached": 1234085328,
"uncached": 13876154,
"content_type": {
"css": 15343,
"html": 1234213,
"javascript": 318236,
"gif": 23178,
"jpeg": 1982048
},
"country": {
"US": 4181364,
"AG": 37298,
"GI": 293846
},
"ssl": {
"encrypted": 12978361,
"unencrypted": 781263
},
"http_status": {
"200": 13496983,
"301": 283,
"400": 187936,
"402": 1828,
"404": 1293
}
},
"bandwidth": {
"all": 213867451,
"cached": 113205063,
"uncached": 113205063,
"content_type": {
"css": 237421,
"html": 1231290,
"javascript": 123245,
"gif": 1234242,
"jpeg": 784278
},
"country": {
"US": 123145433,
"AG": 2342483,
"GI": 984753
},
"ssl": {
"encrypted": 37592942,
"unencrypted": 237654192
}
},
"threats": {
"all": 23423873,
"country": {
"US": 123,
"CN": 523423,
"AU": 91
},
"type": {
"user.ban.ip": 123,
"hot.ban.unknown": 5324,
"macro.chl.captchaErr": 1341,
"macro.chl.jschlErr": 5323
}
},
"pageviews": {
"all": 5724723,
"search_engines": {
"googlebot": 35272,
"pingdom": 13435,
"bingbot": 5372,
"baidubot": 1345
}
},
"uniques": {
"all": 12343
}
},
"timeseries": [
{
"since": "2015-01-01T12:23:00Z",
"until": "2015-01-02T12:23:00Z",
"requests": {
"all": 1234085328,
"cached": 1234085328,
"uncached": 13876154,
"content_type": {
"css": 15343,
"html": 1234213,
"javascript": 318236,
"gif": 23178,
"jpeg": 1982048
},
"country": {
"US": 4181364,
"AG": 37298,
"GI": 293846
},
"ssl": {
"encrypted": 12978361,
"unencrypted": 781263
},
"http_status": {
"200": 13496983,
"301": 283,
"400": 187936,
"402": 1828,
"404": 1293
}
},
"bandwidth": {
"all": 213867451,
"cached": 113205063,
"uncached": 113205063,
"content_type": {
"css": 237421,
"html": 1231290,
"javascript": 123245,
"gif": 1234242,
"jpeg": 784278
},
"country": {
"US": 123145433,
"AG": 2342483,
"GI": 984753
},
"ssl": {
"encrypted": 37592942,
"unencrypted": 237654192
}
},
"threats": {
"all": 23423873,
"country": {
"US": 123,
"CN": 523423,
"AU": 91
},
"type": {
"user.ban.ip": 123,
"hot.ban.unknown": 5324,
"macro.chl.captchaErr": 1341,
"macro.chl.jschlErr": 5323
}
},
"pageviews": {
"all": 5724723,
"search_engines": {
"googlebot": 35272,
"pingdom": 13435,
"bingbot": 5372,
"baidubot": 1345
}
},
"uniques": {
"all": 12343
}
}
]
},
"query": {
"since": "2015-01-01T12:23:00Z",
"until": "2015-01-02T12:23:00Z",
"time_delta": 60
}
}

View File

@@ -0,0 +1,20 @@
{
"success": true,
"errors": [
{}
],
"messages": [
{}
],
"result": {
"id": "0d89c70d-ad9f-4843-b99f-6cc0252067e9",
"hostname": "app.example.com",
"ssl": {
"status": "pending_validation",
"method": "http",
"type": "dv",
"cname_target": "dcv.digicert.com",
"cname": "810b7d5f01154524b961ba0cd578acc2.app.example.com"
}
}
}

View File

@@ -0,0 +1,38 @@
{
"success": true,
"errors": [
{}
],
"messages": [
{}
],
"result": [
{
"id": "92f17202ed8bd63d69a66b86a49a8f6b",
"notes": "This rule is on because of an event that occured on date X",
"allowed_modes": [
"whitelist",
"block",
"challenge"
],
"mode": "challenge",
"configuration": {
"target": "ip",
"value": "1.2.3.4"
},
"scope": {
"id": "7c5dae5552338874e5053f2534d2767a",
"email": "user@example.com",
"type": "user"
},
"created_on": "2014-01-01T05:20:00.12345Z",
"modified_on": "2014-01-01T05:20:00.12345Z"
}
],
"result_info": {
"page": 1,
"per_page": 20,
"count": 1,
"total_count": 2000
}
}

View File

@@ -0,0 +1,28 @@
{
"success": true,
"errors": [
{}
],
"messages": [
{}
],
"result": [
{
"id": "0d89c70d-ad9f-4843-b99f-6cc0252067e9",
"hostname": "app.example.com",
"ssl": {
"status": "pending_validation",
"method": "http",
"type": "dv",
"cname_target": "dcv.digicert.com",
"cname": "810b7d5f01154524b961ba0cd578acc2.app.example.com"
}
}
],
"result_info": {
"page": 1,
"per_page": 20,
"count": 1,
"total_count": 2000
}
}

View File

@@ -0,0 +1,30 @@
{
"success": true,
"errors": [
{}
],
"messages": [
{}
],
"result": {
"id": "92f17202ed8bd63d69a66b86a49a8f6b",
"notes": "This rule is on because of an event that occured on date X",
"allowed_modes": [
"whitelist",
"block",
"challenge"
],
"mode": "challenge",
"configuration": {
"target": "ip",
"value": "1.2.3.4"
},
"scope": {
"id": "7c5dae5552338874e5053f2534d2767a",
"email": "user@example.com",
"type": "user"
},
"created_on": "2014-01-01T05:20:00.12345Z",
"modified_on": "2014-01-01T05:20:00.12345Z"
}
}

View File

@@ -0,0 +1,20 @@
{
"success": true,
"errors": [
{}
],
"messages": [
{}
],
"result": {
"id": "0d89c70d-ad9f-4843-b99f-6cc0252067e9",
"hostname": "app.example.com",
"ssl": {
"status": "pending_validation",
"method": "http",
"type": "dv",
"cname_target": "dcv.digicert.com",
"cname": "810b7d5f01154524b961ba0cd578acc2.app.example.com"
}
}
}

View File

@@ -11,7 +11,7 @@ abstract class TestCase extends PHPUnit_Framework_TestCase
* Returns a PSR7 Stream for a given fixture.
*
* @param string $fixture The fixture to create the stream for.
* @return Psr7Stream
* @return Psr7\Stream
*/
protected function getPsr7StreamForFixture($fixture): Psr7\Stream
{
@@ -31,7 +31,7 @@ abstract class TestCase extends PHPUnit_Framework_TestCase
*
* @param string $fixture The fixture to create the response for.
* @param integer $statusCode A HTTP Status Code for the response.
* @return Psr7Response
* @return Psr7\Response
*/
protected function getPsr7JsonResponseForFixture($fixture, $statusCode = 200): Psr7\Response
{