Skip to content

Commit af80fa0

Browse files
authored
Added missing segments API calls (v11) (#178)
* added segments api calls * php cs fixer fix * moved to phpdoc payload array * fix erros * fix errors * introduce dto * introduce dto * introduce dto * fixes * removed general purpose pagination dto * requested changes * requested changes * requested changes * requested changes * requested changes * requested changes * removed [] * added filters dto * added filters dto * added filters dto * fixes * added missing relation key * moved value to extra params * added relation constants * introduce separate dtos for every filter type * renamed filters * change request * change request * namespace change to singular * namespace change to singular * move operands to abstract class * null check filters * fix * added response objects * added response objects * added exception handling * added exception handling * added exception handling * added request and response to exception * added request and response to exception - fixes * added separate makeRequest method * added separate makeRequest method * added separate makeRequest method * added separate makeRequest method * added list and delete segments tests * added requested changes * removed unused method * changes * added test for create segment
1 parent 1e1ddf8 commit af80fa0

28 files changed

+1097
-0
lines changed

src/Dto/AbstractDto.php

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace OneSignal\Dto;
6+
7+
interface AbstractDto
8+
{
9+
public function toArray(): array;
10+
}

src/Dto/Filter/AbstractFilter.php

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace OneSignal\Dto\Filter;
6+
7+
use OneSignal\Dto\AbstractDto;
8+
9+
abstract class AbstractFilter implements AbstractDto
10+
{
11+
public const GT = '>';
12+
13+
public const LT = '<';
14+
15+
public const EQ = '=';
16+
17+
public const NEQ = '!=';
18+
}

src/Dto/Filter/AmountSpentFilter.php

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace OneSignal\Dto\Filter;
6+
7+
final class AmountSpentFilter extends AbstractFilter
8+
{
9+
public const GT = '>';
10+
11+
public const LT = '<';
12+
13+
public const EQ = '=';
14+
15+
/**
16+
* @var self::GT|self::LT|self::EQ
17+
*/
18+
protected string $relation;
19+
20+
/**
21+
* @var int|float
22+
*/
23+
protected $value;
24+
25+
/**
26+
* @param self::GT|self::LT|self::EQ $relation
27+
* @param int|float $value
28+
*/
29+
public function __construct(string $relation, $value)
30+
{
31+
$this->relation = $relation;
32+
$this->value = $value;
33+
}
34+
35+
public function toArray(): array
36+
{
37+
return [
38+
'field' => 'amount_spent',
39+
'relation' => $this->relation,
40+
'value' => $this->value,
41+
];
42+
}
43+
}

src/Dto/Filter/AppVersionFilter.php

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace OneSignal\Dto\Filter;
6+
7+
final class AppVersionFilter extends AbstractFilter
8+
{
9+
/**
10+
* @var self::GT|self::LT|self::EQ|self::NEQ
11+
*/
12+
protected string $relation;
13+
14+
protected string $value;
15+
16+
/**
17+
* @param self::GT|self::LT|self::EQ|self::NEQ $relation
18+
*/
19+
public function __construct(string $relation, string $value)
20+
{
21+
$this->relation = $relation;
22+
$this->value = $value;
23+
}
24+
25+
public function toArray(): array
26+
{
27+
return [
28+
'field' => 'app_version',
29+
'relation' => $this->relation,
30+
'value' => $this->value,
31+
];
32+
}
33+
}

src/Dto/Filter/BoughtSkuFilter.php

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace OneSignal\Dto\Filter;
6+
7+
final class BoughtSkuFilter extends AbstractFilter
8+
{
9+
/**
10+
* @var self::GT|self::LT|self::EQ
11+
*/
12+
protected string $relation;
13+
14+
protected string $key;
15+
16+
/**
17+
* @var int|float
18+
*/
19+
protected $value;
20+
21+
/**
22+
* @param self::GT|self::LT|self::EQ $relation
23+
* @param int|float $value
24+
*/
25+
public function __construct(string $relation, string $key, $value)
26+
{
27+
$this->relation = $relation;
28+
$this->key = $key;
29+
$this->value = $value;
30+
}
31+
32+
public function toArray(): array
33+
{
34+
return [
35+
'field' => 'bought_sku',
36+
'relation' => $this->relation,
37+
'key' => $this->key,
38+
'value' => $this->value,
39+
];
40+
}
41+
}

src/Dto/Filter/ConditionalFilter.php

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace OneSignal\Dto\Filter;
6+
7+
final class ConditionalFilter extends AbstractFilter
8+
{
9+
public const AND = 'AND';
10+
11+
public const OR = 'OR';
12+
13+
/**
14+
* @var self::AND|self::OR
15+
*/
16+
protected string $operator;
17+
18+
/**
19+
* @param self::AND|self::OR $operator
20+
*/
21+
public function __construct(string $operator)
22+
{
23+
$this->operator = $operator;
24+
}
25+
26+
/**
27+
* @param self::AND|self::OR $operator
28+
*/
29+
public function setOperator(string $operator): self
30+
{
31+
$this->operator = $operator;
32+
33+
return $this;
34+
}
35+
36+
public function toArray(): array
37+
{
38+
return [
39+
'operator' => $this->operator,
40+
];
41+
}
42+
}

src/Dto/Filter/CountryFilter.php

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace OneSignal\Dto\Filter;
6+
7+
final class CountryFilter extends AbstractFilter
8+
{
9+
protected string $value;
10+
11+
public function __construct(string $value)
12+
{
13+
$this->value = $value;
14+
}
15+
16+
public function toArray(): array
17+
{
18+
return [
19+
'field' => 'country',
20+
'relation' => self::EQ,
21+
'value' => $this->value,
22+
];
23+
}
24+
}

src/Dto/Filter/FirstSessionFilter.php

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace OneSignal\Dto\Filter;
6+
7+
final class FirstSessionFilter extends AbstractFilter
8+
{
9+
/**
10+
* @var self::GT|self::LT
11+
*/
12+
protected string $relation;
13+
14+
/**
15+
* @var int|float
16+
*/
17+
protected $hoursAgo;
18+
19+
/**
20+
* @param self::GT|self::LT $relation
21+
* @param int|float $hoursAgo
22+
*/
23+
public function __construct(string $relation, $hoursAgo)
24+
{
25+
$this->relation = $relation;
26+
$this->hoursAgo = $hoursAgo;
27+
}
28+
29+
public function toArray(): array
30+
{
31+
return [
32+
'field' => 'first_session',
33+
'relation' => $this->relation,
34+
'hours_ago' => $this->hoursAgo,
35+
];
36+
}
37+
}

src/Dto/Filter/LanguageFilter.php

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace OneSignal\Dto\Filter;
6+
7+
final class LanguageFilter extends AbstractFilter
8+
{
9+
/**
10+
* @var self::EQ|self::NEQ
11+
*/
12+
protected string $relation;
13+
14+
protected string $value;
15+
16+
/**
17+
* @param self::EQ|self::NEQ $relation
18+
*/
19+
public function __construct(string $relation, string $value)
20+
{
21+
$this->relation = $relation;
22+
$this->value = $value;
23+
}
24+
25+
public function toArray(): array
26+
{
27+
return [
28+
'field' => 'language',
29+
'relation' => $this->relation,
30+
'value' => $this->value,
31+
];
32+
}
33+
}

src/Dto/Filter/LastSessionFilter.php

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace OneSignal\Dto\Filter;
6+
7+
final class LastSessionFilter extends AbstractFilter
8+
{
9+
/**
10+
* @var self::GT|self::LT
11+
*/
12+
protected string $relation;
13+
14+
/**
15+
* @var int|float
16+
*/
17+
protected $hoursAgo;
18+
19+
/**
20+
* @param self::GT|self::LT $relation
21+
* @param int|float $hoursAgo
22+
*/
23+
public function __construct(string $relation, $hoursAgo)
24+
{
25+
$this->relation = $relation;
26+
$this->hoursAgo = $hoursAgo;
27+
}
28+
29+
public function toArray(): array
30+
{
31+
return [
32+
'field' => 'last_session',
33+
'relation' => $this->relation,
34+
'hours_ago' => $this->hoursAgo,
35+
];
36+
}
37+
}

0 commit comments

Comments
 (0)