Skip to content

Commit

Permalink
Update Class Name, Package Name, and ready docs for 1.0.0 release
Browse files Browse the repository at this point in the history
  • Loading branch information
brettt89 committed Jul 22, 2020
1 parent 398f542 commit db7a711
Show file tree
Hide file tree
Showing 34 changed files with 140 additions and 146 deletions.
28 changes: 15 additions & 13 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
3 changes: 1 addition & 2 deletions SECURITY.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
],
"autoload": {
"psr-4": {
"Incapsula\\API\\": "src/"
"IncapsulaAPI\\": "src/"
}
},
"autoload-dev": {
Expand Down
10 changes: 0 additions & 10 deletions src/API.php

This file was deleted.

4 changes: 2 additions & 2 deletions src/Adapter.php → src/Adapter/AdapterInterface.php
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
<?php

namespace Incapsula\API;
namespace IncapsulaAPI\Adapter;

interface Adapter
interface AdapterInterface
{
public function request(string $uri, ...$options): \stdClass;
}
10 changes: 5 additions & 5 deletions src/Guzzle.php → src/Adapter/Guzzle.php
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
<?php

namespace Incapsula\API;
namespace IncapsulaAPI\Adapter;

use Incapsula\API\Adapter;
use Incapsula\API\Auth;
use IncapsulaAPI\Adapter\AdapterInterface;
use IncapsulaAPI\Auth\AuthInterface;
use GuzzleHttp\Client;
use GuzzleHttp\RequestOptions;
use Psr\Http\Message\ResponseInterface;

class Guzzle implements Adapter
class Guzzle implements AdapterInterface
{
private $client;
private $body = [];
Expand All @@ -20,7 +20,7 @@ class Guzzle implements Adapter
/**
* @inheritDoc
*/
public function __construct(Auth $auth, string $baseURI = null)
public function __construct(AuthInterface $auth, string $baseURI = null)
{
if ($baseURI === null) {
$baseURI = 'https://my.incapsula.com/';
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?php

namespace Incapsula\API;
namespace IncapsulaAPI\Adapter;

class IncapsulaException extends \Exception
{
Expand Down
2 changes: 1 addition & 1 deletion src/JSONException.php → src/Adapter/JSONException.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?php

namespace Incapsula\API;
namespace IncapsulaAPI\Adapter;

class JSONException extends \Exception
{
Expand Down
7 changes: 0 additions & 7 deletions src/AdapterException.php

This file was deleted.

8 changes: 0 additions & 8 deletions src/Auth.php

This file was deleted.

6 changes: 3 additions & 3 deletions src/ApiKey.php → src/Auth/ApiKey.php
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
<?php

namespace Incapsula\API;
namespace IncapsulaAPI\Auth;

use Incapsula\API\Auth;
use IncapsulaAPI\Auth\AuthInterface;

class ApiKey implements Auth
class ApiKey implements AuthInterface
{
private $apiId;
private $apiKey;
Expand Down
8 changes: 8 additions & 0 deletions src/Auth/AuthInterface.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<?php

namespace IncapsulaAPI\Auth;

interface AuthInterface
{
public function toArray(): array;
}
22 changes: 0 additions & 22 deletions src/Endpoint.php

This file was deleted.

4 changes: 2 additions & 2 deletions src/Account.php → src/Endpoint/Account.php
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
<?php

namespace Incapsula\API;
namespace IncapsulaAPI\Endpoint;

use Incapsula\API\Endpoint;
use IncapsulaAPI\Endpoint\Endpoint;

class Account extends Endpoint
{
Expand Down
4 changes: 2 additions & 2 deletions src/DDoSProtection.php → src/Endpoint/DDoSProtection.php
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
<?php

namespace Incapsula\API;
namespace IncapsulaAPI\Endpoint;

use Incapsula\API\Endpoint;
use IncapsulaAPI\Endpoint\Endpoint;

// @todo - Error from Incapsula - "Operation not allowed"
class DDoSProtection extends Endpoint
Expand Down
22 changes: 22 additions & 0 deletions src/Endpoint/Endpoint.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
<?php

namespace IncapsulaAPI\Endpoint;

use IncapsulaAPI\Endpoint\EndpointInterface;
use IncapsulaAPI\Adapter\AdapterInterface;

abstract class Endpoint implements EndpointInterface
{
private $adapter;
private $body;

public function __construct(AdapterInterface $adapter)
{
$this->adapter = $adapter;
}

public function getAdapter(): AdapterInterface
{
return $this->adapter;
}
}
10 changes: 10 additions & 0 deletions src/Endpoint/EndpointInterface.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<?php

namespace IncapsulaAPI\Endpoint;

use IncapsulaAPI\Adapter\AdapterInterface;

interface EndpointInterface
{
public function getAdapter(): AdapterInterface;
}
4 changes: 2 additions & 2 deletions src/Site.php → src/Endpoint/Site.php
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
<?php

namespace Incapsula\API;
namespace IncapsulaAPI\Endpoint;

use Incapsula\API\Endpoint;
use IncapsulaAPI\Endpoint\Endpoint;

class Site extends Endpoint
{
Expand Down
4 changes: 2 additions & 2 deletions src/Site/CacheRules.php → src/Endpoint/Site/CacheRules.php
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
<?php

namespace Incapsula\API\Site;
namespace IncapsulaAPI\Endpoint\Site;

use Incapsula\API\Endpoint;
use IncapsulaAPI\Endpoint\Endpoint;

class CacheRules extends Endpoint
{
Expand Down
4 changes: 2 additions & 2 deletions src/Site/Caching.php → src/Endpoint/Site/Caching.php
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
<?php

namespace Incapsula\API\Site;
namespace IncapsulaAPI\Endpoint\Site;

use Incapsula\API\Endpoint;
use IncapsulaAPI\Endpoint\Endpoint;

class Caching extends Endpoint
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
<?php

namespace Incapsula\API\Site;
namespace IncapsulaAPI\Endpoint\Site;

use Incapsula\API\Endpoint;
use IncapsulaAPI\Endpoint\Endpoint;

class DataCenters extends Endpoint
{
Expand Down
4 changes: 2 additions & 2 deletions src/Site/Rules.php → src/Endpoint/Site/Rules.php
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
<?php

namespace Incapsula\API\Site;
namespace IncapsulaAPI\Endpoint\Site;

use Incapsula\API\Endpoint;
use IncapsulaAPI\Endpoint\Endpoint;

class Rules extends Endpoint
{
Expand Down
18 changes: 9 additions & 9 deletions tests/GuzzleTest.php → tests/Adapter/GuzzleTest.php
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
<?php

namespace Incapsula\API\Test;
namespace IncapsulaAPI\Test\Adapter;

class GuzzleTest extends \TestCase
{
private $client;

public function setUp(): void
{
$auth = $this->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()
Expand All @@ -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);

Expand All @@ -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);

Expand All @@ -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);

Expand Down
4 changes: 2 additions & 2 deletions tests/ApiKeyTest.php → tests/Auth/ApiKeyTest.php
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
<?php

namespace Incapsula\API\Test;
namespace IncapsulaAPI\Test\Auth;

class ApiKeyTest extends \TestCase
{
public function testGetRequestParameters()
{
$auth = new \Incapsula\API\ApiKey('123456789', 'abcdefghijklymnop-123456789');
$auth = new \IncapsulaAPI\Auth\ApiKey('123456789', 'abcdefghijklymnop-123456789');
$parameters = $auth->toArray();

$this->assertArrayHasKey('api_id', $parameters);
Expand Down
Loading

0 comments on commit db7a711

Please sign in to comment.