Skip to content
This repository has been archived by the owner on Jan 9, 2021. It is now read-only.

Commit

Permalink
add all table data requests (#26)
Browse files Browse the repository at this point in the history
* add delete rows request and minor fixes

* changed README.md and CHANGELOG.md

* add clear table request

* move WhereCondition to new namespace

* recreate WhereCondition in old namespace to not break backward compatibility

* modify CHANGELOG.md

* add rows count request

* add get table summary and details
  • Loading branch information
AmsTaFFix authored and liderman committed Aug 21, 2017
1 parent 5f428aa commit 8a73625
Show file tree
Hide file tree
Showing 32 changed files with 1,746 additions and 94 deletions.
7 changes: 7 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,13 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.
## [Unreleased]
### Added
- ```ErrorMessage::__toString()```
- Delete rows request
- Clear table request
- Get rows count request
- Get list of tables request
### Deprecated
- \Citilink\ExpertSenderApi\Model\DataTablesGetDataPostRequest\WhereCondition, use \Citilink\ExpertSenderApi\Model\WhereCondition insted

## [1.1.0] - 2017-08-17
### Added
- feature to subscribe to new event "expert_sender_api.request.exception_thrown"
Expand Down
110 changes: 109 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,17 @@ _fork of [LinguaLeo/expert-sender-api](https://github.com/LinguaLeo/expert-sende
- [Get removed subscribers](#get-removed-subscribers)
- [Get bounces list](#get-bounces-list)
- [Data Tables](#data-tables)
- [Get list of tables](#get-list-of-tables)
- [Tables summary](#tables-summary)
- [Table details](#table-details)
- [Get data](#get-data)
- [Count rows](#count-rows)
- [Clear table](#clear-table)
- [Add row](#add-row)
- [Add multiple rows](#add-multiple-rows)
- [Update row](#update-row)
- [Delete row](#delete-row)
- [Delete rows](#delete-rows)

## Requirements

Expand Down Expand Up @@ -345,13 +351,57 @@ foreach ($response->getBounces() as $bounce) {

## Data Tables
[documentation](https://sites.google.com/a/expertsender.com/api-documentation/methods/datatables)
### Get list of tables
[documentation](https://sites.google.com/a/expertsender.com/api-documentation/methods/datatables/get-list-of-tables)
#### Tables summary
```php
$response = $api->dataTables()->getTablesList();
if ($response->isOk()) {
foreach ($response->getTables() as $table)) {
echo $table->getId();
echo $table->getName();
echo $table->getColumnsCount();
echo $table->getRelationshipsCount();
echo $table->getRelationshipsDestinationCount();
echo $table->getRowsCount();
echo $table->getSize();
}
} else {
// handle errors
}
```
#### Table details
```php
$response = $api->dataTables()->getTablesList('table-name');
if ($response->isOk()) {
foreach ($response->getTables() as $table)) {
echo $table->getId();
echo $table->getName();
echo $table->getColumnsCount();
echo $table->getRelationshipsCount();
echo $table->getRelationshipsDestinationCount();
echo $table->getRowsCount();
echo $table->getDescription();
foreach ($table->getColumns() as $column) {
echo $column->getName();
echo $column->getColumnType();
echo $column->getLength();
echo $column->getDefaultValue() ?: 'No default value';
echo $column->isPrimaryKey() ? 'true' : 'false';
echo $column->isRequired() ? 'true' : 'false';
}
}
} else {
// handle errors
}
```
### Get data
[documentation](https://sites.google.com/a/expertsender.com/api-documentation/methods/datatables/get-data)
```php
// ...
use Citilink\ExpertSenderApi\Enum\DataTablesGetDataPostRequest\Direction;
use Citilink\ExpertSenderApi\Enum\DataTablesGetDataPostRequest\Operator;
use Citilink\ExpertSenderApi\Model\DataTablesGetDataPostRequest\WhereCondition;
use Citilink\ExpertSenderApi\Model\WhereCondition;
use Citilink\ExpertSenderApi\Model\DataTablesGetDataPostRequest\OrderByRule;
// ...
// limit is optional, and null by default
Expand Down Expand Up @@ -389,6 +439,39 @@ if ($response->isOk()) {
// handle errors
}
```
### Count rows
[documentation](https://sites.google.com/a/expertsender.com/api-documentation/methods/datatables/count-rows)
```php
// ...
use Citilink\ExpertSenderApi\Enum\DataTablesGetDataPostRequest\Operator;
use Citilink\ExpertSenderApi\Model\WhereCondition;
// ...
$response = $api->dataTables()->getRowsCount(
'table-name',
[
new WhereCondition('Column1', Operator::EQUAL(), 12),
new WhereCondition('Column2', Operator::GREATER(), 12.53),
new WhereCondition('Column3', Operator::LOWER(), -0.56),
new WhereCondition('Column5', Operator::LIKE(), 'string'),
]
);

if ($response->isOk()) {
$count = $response->getCount();
} else {
// handle errors
}
```
### Clear table
[documentation](https://sites.google.com/a/expertsender.com/api-documentation/methods/datatables/clear-table)
```php
$response = $api->dataTables()->clearTable('table-name');
if ($response->isOk()) {
// table has been cleared
} else {
// handle errors
}
```
### Add row
Use [add multiple rows method](#add-multiple-rows) to insert one row
### Add multiple rows
Expand Down Expand Up @@ -489,3 +572,28 @@ if ($response->isOk()) {
}
}
```
### Delete rows
[documentation](https://sites.google.com/a/expertsender.com/api-documentation/methods/datatables/delete-rows)
```php
// ...
use Citilink\ExpertSenderApi\Model\DataTablesDeleteRowsPostRequest\Filter;
use Citilink\ExpertSenderApi\Enum\DataTablesDeleteRowsPostRequest\FilterOperator;
// ...
$response = $api->dataTables()->deleteRows(
'table-name',
[
new Filter('Column1', FilterOperator::EQ(), 12),
new Filter('Column2', FilterOperator::GE(), 56.7),
new Filter('Column3', FilterOperator::EQ(), 'string'),
new Filter('Column4', FilterOperator::GT(), 89.234),
new Filter('Column5', FilterOperator::LT(), 87.3),
new Filter('Column6', FilterOperator::LE(), 98),
]
);

if ($response->isOk()) {
$count = $response->getCount();
} else {
// handle errors
}
```
45 changes: 45 additions & 0 deletions src/Enum/DataTablesDeleteRowsPostRequest/FilterOperator.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
<?php
declare(strict_types=1);

namespace Citilink\ExpertSenderApi\Enum\DataTablesDeleteRowsPostRequest;

use MyCLabs\Enum\Enum;

/**
* Filter operator
*
* @method static FilterOperator EQ()
* @method static FilterOperator GT()
* @method static FilterOperator LT()
* @method static FilterOperator GE()
* @method static FilterOperator LE()
*
* @author Nikita Sapogov <[email protected]>
*/
class FilterOperator extends Enum
{
/**
* Equals
*/
const EQ = 'EQ';

/**
* Greater than
*/
const GT = 'GT';

/**
* Less than
*/
const LT = 'LT';

/**
* Greater or equals
*/
const GE = 'GE';

/**
* Less or equals
*/
const LE = 'LE';
}
76 changes: 76 additions & 0 deletions src/Model/DataTablesDeleteRowsPostRequest/Filter.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
<?php
declare(strict_types=1);

namespace Citilink\ExpertSenderApi\Model\DataTablesDeleteRowsPostRequest;

use Citilink\ExpertSenderApi\Enum\DataTablesDeleteRowsPostRequest\FilterOperator;
use Webmozart\Assert\Assert;

/**
* Filter for delete many rows
*
* @author Nikita Sapogov <[email protected]>
*/
class Filter
{
/**
* @var string Name
*/
private $name;

/**
* @var string Value
*/
private $value;

/**
* @var FilterOperator Operator
*/
private $operator;

/**
* Constructor.
*
* @param string $name Name
* @param FilterOperator $operator Operator
* @param int|string|float $value Value
*/
public function __construct(string $name, FilterOperator $operator, $value)
{
Assert::notEmpty($name);
Assert::scalar($value);
$this->name = $name;
$this->value = strval($value);
$this->operator = $operator;
}

/**
* Get name
*
* @return string Name
*/
public function getName(): string
{
return $this->name;
}

/**
* Get value
*
* @return string Value
*/
public function getValue(): string
{
return $this->value;
}

/**
* Get operator
*
* @return FilterOperator Operator
*/
public function getOperator(): FilterOperator
{
return $this->operator;
}
}
65 changes: 9 additions & 56 deletions src/Model/DataTablesGetDataPostRequest/WhereCondition.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,74 +4,27 @@
namespace Citilink\ExpertSenderApi\Model\DataTablesGetDataPostRequest;

use Citilink\ExpertSenderApi\Enum\DataTablesGetDataPostRequest\Operator;
use Webmozart\Assert\Assert;

/**
* Where condition for get table data
* Where condition
*
* @deprecated Use {@see \Citilink\ExpertSenderApi\Model\WhereCondition} instead
*
* @author Nikita Sapogov <[email protected]>
*/
class WhereCondition
class WhereCondition extends \Citilink\ExpertSenderApi\Model\WhereCondition
{
/**
* @var string Column name
*/
private $columnName;

/**
* @var Operator Operator
*/
private $operator;

/**
* @var string Value
*/
private $value;

/**
* Constructor
* Constructor.
*
* @param string $columnName Column name
* @param Operator $operator Operator
* @param string|int|float $value Value
* @param float|int|string $value Value
*/
public function __construct(string $columnName, Operator $operator, $value)
public function __construct($columnName, Operator $operator, $value)
{
Assert::scalar($value);
Assert::notEmpty($columnName);
Assert::notEmpty($value);
$this->columnName = $columnName;
$this->operator = $operator;
$this->value = strval($value);
}
@trigger_error('use \Citilink\ExpertSenderApi\Model\WhereCondition instead', E_USER_DEPRECATED);

/**
* Get column name
*
* @return string Column name
*/
public function getColumnName(): string
{
return $this->columnName;
}

/**
* Get operator
*
* @return Operator Operator
*/
public function getOperator(): Operator
{
return $this->operator;
}

/**
* Get value
*
* @return string Value
*/
public function getValue(): string
{
return $this->value;
parent::__construct($columnName, $operator, $value);
}
}
Loading

0 comments on commit 8a73625

Please sign in to comment.