diff --git a/README.md b/README.md index c40161b..cb84f3e 100755 --- a/README.md +++ b/README.md @@ -6,37 +6,39 @@ ## Installation -NOTE: This is current in Development. No tagged versions are available at this current point in time. Hopefully we will have enough functionality to tag a release soon. - -The recommended way to install this package is via the Packagist Dependency Manager ([brettt89/incapsula-sdk](https://packagist.org/packages/brettt89/incapsula-sdk)). +The recommended way to install this package is via the Packagist Dependency Manager ([brettt89/incapsula-api-php](https://packagist.org/packages/brettt89/incapsula-api-php)). ```bash -$ composer require brettt89/incapsula-sdk dev-master +$ composer require brettt89/incapsula-api-php ``` ## Incapsula API version 1 The Incapsula API can be found [here](https://docs.imperva.com/bundle/cloud-application-security/page/api/api.htm). -Each API call is provided via a similarly named function within various classes in the **Incapsula\API** namespace: +Each API call is provided via a similarly named function within various classes in the **IncapsulaAPI** namespace: - [x] [Account](https://docs.imperva.com/bundle/cloud-application-security/page/api/accounts-api.htm) - [x] [Sites](https://docs.imperva.com/bundle/cloud-application-security/page/api/sites-api.htm) - [x] [DDoS Protection](https://docs.imperva.com/bundle/cloud-application-security/page/api/ddos-for-networks.htm) -- [ ] [Traffic Statistics and Details](https://docs.imperva.com/bundle/cloud-application-security/page/api/traffic-api.htm) (coming soon) -- [ ] [Login Protect](https://docs.imperva.com/bundle/cloud-application-security/page/api/login-protect-api.htm) (coming soon) -- [ ] [Integration API](https://docs.imperva.com/bundle/cloud-application-security/page/api/integration-api.htm) (coming soon) -- [ ] [Infrastructure Protection Test Alerts](https://docs.imperva.com/bundle/cloud-application-security/page/api/network-ddos-api.htm) (coming soon) +- [ ] [Traffic Statistics and Details](https://docs.imperva.com/bundle/cloud-application-security/page/api/traffic-api.htm) +- [ ] [Login Protect](https://docs.imperva.com/bundle/cloud-application-security/page/api/login-protect-api.htm) +- [ ] [Integration API](https://docs.imperva.com/bundle/cloud-application-security/page/api/integration-api.htm) +- [ ] [Infrastructure Protection Test Alerts](https://docs.imperva.com/bundle/cloud-application-security/page/api/network-ddos-api.htm) -Note that this repository is currently under development, additional classes and endpoints being actively added. +Note that this repository is currently under development, additional endpoints are being actively added. ## Getting Started ```php -$key = new Incapsula\API\Auth('Api-ID', 'Api-Key'); -$adapter = new Incapsula\API\Guzzle($key); -$account = new Incapsula\API\Account($adapter); +$key = new IncapsulaAPI\Auth\ApiKey('Api-ID', 'Api-Key'); +$adapter = new IncapsulaAPI\Adapter\Guzzle($key); +$account = new IncapsulaAPI\Endpoint\Account($adapter); $account_id = 123456; print_r($account->getSites($account_id)); ``` + +## Contributions + +Please submit any contributions as a pull request to the `master` branch. diff --git a/SECURITY.md b/SECURITY.md index 3f64c6f..028a567 100644 --- a/SECURITY.md +++ b/SECURITY.md @@ -2,11 +2,10 @@ ## Supported Versions -This package is currently in-development. | Version | Supported | | ------- | ------------------ | -| master | :white_check_mark: | +| 1.0.0 | :white_check_mark: | ## Reporting a Vulnerability diff --git a/composer.json b/composer.json index 5a32cb3..f17b5db 100755 --- a/composer.json +++ b/composer.json @@ -21,7 +21,7 @@ ], "autoload": { "psr-4": { - "Incapsula\\API\\": "src/" + "IncapsulaAPI\\": "src/" } }, "autoload-dev": { diff --git a/src/API.php b/src/API.php deleted file mode 100755 index acd35ad..0000000 --- a/src/API.php +++ /dev/null @@ -1,10 +0,0 @@ -adapter = $adapter; - } - - public function getAdapter(): Adapter - { - return $this->adapter; - } -} diff --git a/src/Account.php b/src/Endpoint/Account.php similarity index 99% rename from src/Account.php rename to src/Endpoint/Account.php index 3fa2b37..6d41f79 100755 --- a/src/Account.php +++ b/src/Endpoint/Account.php @@ -1,8 +1,8 @@ adapter = $adapter; + } + + public function getAdapter(): AdapterInterface + { + return $this->adapter; + } +} diff --git a/src/Endpoint/EndpointInterface.php b/src/Endpoint/EndpointInterface.php new file mode 100755 index 0000000..419611a --- /dev/null +++ b/src/Endpoint/EndpointInterface.php @@ -0,0 +1,10 @@ +createMock(\Incapsula\API\ApiKey::class, ['toArray']); + $auth = $this->createMock(\IncapsulaAPI\Auth\ApiKey::class, ['toArray']); $auth->method('toArray') ->willReturn(['X-Testing' => 'Test']); - $this->adapter = new \Incapsula\API\Guzzle($auth); + $this->adapter = new \IncapsulaAPI\Adapter\Guzzle($auth); } public function testRequest() @@ -38,7 +38,7 @@ public function testRequest() public function testCheckError() { - $class = new \ReflectionClass(\Incapsula\API\Guzzle::class); + $class = new \ReflectionClass(\IncapsulaAPI\Adapter\Guzzle::class); $method = $class->getMethod('checkError'); $method->setAccessible(true); @@ -54,25 +54,25 @@ public function testCheckError() $property_debug_info->setAccessible(true); $property_debug_info->setValue($this->adapter, ['problem' => 'Test Problem']); - $this->expectException(\Incapsula\API\IncapsulaException::class); + $this->expectException(\IncapsulaAPI\Adapter\IncapsulaException::class); $method->invoke($this->adapter); } public function testParseResponseJSONException() { - $class = new \ReflectionClass(\Incapsula\API\Guzzle::class); + $class = new \ReflectionClass(\IncapsulaAPI\Adapter\Guzzle::class); $method = $class->getMethod('parseResponse'); $method->setAccessible(true); $response = $this->getPsr7JsonResponseForFixture('notJson'); - $this->expectException(\Incapsula\API\JSONException::class); + $this->expectException(\IncapsulaAPI\Adapter\JSONException::class); $method->invokeArgs($this->adapter, [$response]); } public function testParseResponse() { - $class = new \ReflectionClass(\Incapsula\API\Guzzle::class); + $class = new \ReflectionClass(\IncapsulaAPI\Adapter\Guzzle::class); $method = $class->getMethod('parseResponse'); $method->setAccessible(true); @@ -86,7 +86,7 @@ public function testParseResponse() public function testGetDebugInfo() { - $class = new \ReflectionClass(\Incapsula\API\Guzzle::class); + $class = new \ReflectionClass(\IncapsulaAPI\Adapter\Guzzle::class); $property = $class->getProperty('debug_info'); $property->setAccessible(true); diff --git a/tests/ApiKeyTest.php b/tests/Auth/ApiKeyTest.php similarity index 78% rename from tests/ApiKeyTest.php rename to tests/Auth/ApiKeyTest.php index 9cd2b63..be7ba83 100755 --- a/tests/ApiKeyTest.php +++ b/tests/Auth/ApiKeyTest.php @@ -1,12 +1,12 @@ toArray(); $this->assertArrayHasKey('api_id', $parameters); diff --git a/tests/AccountTest.php b/tests/Endpoints/AccountTest.php similarity index 96% rename from tests/AccountTest.php rename to tests/Endpoints/AccountTest.php index b6a1e78..6af322b 100755 --- a/tests/AccountTest.php +++ b/tests/Endpoints/AccountTest.php @@ -1,17 +1,17 @@ endpoint)) { - $this->endpoint = new \Incapsula\API\Account($this->getAdapter()); + $this->endpoint = new \IncapsulaAPI\Endpoint\Account($this->getAdapter()); } return $this->endpoint; } diff --git a/tests/DDoSProtection.php b/tests/Endpoints/DDoSProtection.php similarity index 96% rename from tests/DDoSProtection.php rename to tests/Endpoints/DDoSProtection.php index 0445eea..ff6a532 100755 --- a/tests/DDoSProtection.php +++ b/tests/Endpoints/DDoSProtection.php @@ -1,17 +1,17 @@ endpoint)) { - $this->endpoint = new \Incapsula\API\DDoSProtection($this->getAdapter()); + $this->endpoint = new \IncapsulaAPI\Endpoint\DDoSProtection($this->getAdapter()); } return $this->endpoint; } diff --git a/tests/Site/CacheRulesTest.php b/tests/Endpoints/Site/CacheRulesTest.php similarity index 91% rename from tests/Site/CacheRulesTest.php rename to tests/Endpoints/Site/CacheRulesTest.php index 9d08832..baaba9e 100755 --- a/tests/Site/CacheRulesTest.php +++ b/tests/Endpoints/Site/CacheRulesTest.php @@ -1,17 +1,17 @@ endpoint)) { - $this->endpoint = new \Incapsula\API\Site\CacheRules($this->getAdapter()); + $this->endpoint = new \IncapsulaAPI\Endpoint\Site\CacheRules($this->getAdapter()); } return $this->endpoint; } diff --git a/tests/Site/CachingTest.php b/tests/Endpoints/Site/CachingTest.php similarity index 96% rename from tests/Site/CachingTest.php rename to tests/Endpoints/Site/CachingTest.php index fdbc1d9..2d0f954 100755 --- a/tests/Site/CachingTest.php +++ b/tests/Endpoints/Site/CachingTest.php @@ -1,17 +1,17 @@ endpoint)) { - $this->endpoint = new \Incapsula\API\Site\Caching($this->getAdapter(), 12345); + $this->endpoint = new \IncapsulaAPI\Endpoint\Site\Caching($this->getAdapter(), 12345); } return $this->endpoint; } diff --git a/tests/Site/DataCentersTest.php b/tests/Endpoints/Site/DataCentersTest.php similarity index 93% rename from tests/Site/DataCentersTest.php rename to tests/Endpoints/Site/DataCentersTest.php index 9b9739b..3dd08ee 100755 --- a/tests/Site/DataCentersTest.php +++ b/tests/Endpoints/Site/DataCentersTest.php @@ -1,17 +1,17 @@ endpoint)) { - $this->endpoint = new \Incapsula\API\Site\DataCenters($this->getAdapter(), 12345); + $this->endpoint = new \IncapsulaAPI\Endpoint\Site\DataCenters($this->getAdapter(), 12345); } return $this->endpoint; } diff --git a/tests/Site/RulesTest.php b/tests/Endpoints/Site/RulesTest.php similarity index 92% rename from tests/Site/RulesTest.php rename to tests/Endpoints/Site/RulesTest.php index b0f0ce5..f917502 100755 --- a/tests/Site/RulesTest.php +++ b/tests/Endpoints/Site/RulesTest.php @@ -1,17 +1,17 @@ endpoint)) { - $this->endpoint = new \Incapsula\API\Site\Rules($this->getAdapter(), 12345); + $this->endpoint = new \IncapsulaAPI\Endpoint\Site\Rules($this->getAdapter(), 12345); } return $this->endpoint; } diff --git a/tests/SiteTest.php b/tests/Endpoints/SiteTest.php similarity index 98% rename from tests/SiteTest.php rename to tests/Endpoints/SiteTest.php index c596409..06a3482 100755 --- a/tests/SiteTest.php +++ b/tests/Endpoints/SiteTest.php @@ -1,17 +1,17 @@ endpoint)) { - $this->endpoint = new \Incapsula\API\Site($this->getAdapter()); + $this->endpoint = new \IncapsulaAPI\Endpoint\Site($this->getAdapter()); } return $this->endpoint; } diff --git a/tests/Endpoints/TestEndpointInterface.php b/tests/Endpoints/TestEndpointInterface.php new file mode 100755 index 0000000..aa8e15d --- /dev/null +++ b/tests/Endpoints/TestEndpointInterface.php @@ -0,0 +1,10 @@ +getPsr7JsonResponseForFixture($fixture); - $this->adapter = $this->getMockBuilder(\Incapsula\API\Adapter::class) + $this->adapter = $this->getMockBuilder(\IncapsulaAPI\Adapter\AdapterInterface::class) ->setMethods(['request']) ->getMock();