Skip to content

Commit

Permalink
Added missing segments API calls (v11) (#178)
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
rcerljenko authored Dec 8, 2023
1 parent 1e1ddf8 commit af80fa0
Show file tree
Hide file tree
Showing 28 changed files with 1,097 additions and 0 deletions.
10 changes: 10 additions & 0 deletions src/Dto/AbstractDto.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<?php

declare(strict_types=1);

namespace OneSignal\Dto;

interface AbstractDto
{
public function toArray(): array;
}
18 changes: 18 additions & 0 deletions src/Dto/Filter/AbstractFilter.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<?php

declare(strict_types=1);

namespace OneSignal\Dto\Filter;

use OneSignal\Dto\AbstractDto;

abstract class AbstractFilter implements AbstractDto
{
public const GT = '>';

public const LT = '<';

public const EQ = '=';

public const NEQ = '!=';
}
43 changes: 43 additions & 0 deletions src/Dto/Filter/AmountSpentFilter.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
<?php

declare(strict_types=1);

namespace OneSignal\Dto\Filter;

final class AmountSpentFilter extends AbstractFilter
{
public const GT = '>';

public const LT = '<';

public const EQ = '=';

/**
* @var self::GT|self::LT|self::EQ
*/
protected string $relation;

/**
* @var int|float
*/
protected $value;

/**
* @param self::GT|self::LT|self::EQ $relation
* @param int|float $value
*/
public function __construct(string $relation, $value)
{
$this->relation = $relation;
$this->value = $value;
}

public function toArray(): array
{
return [
'field' => 'amount_spent',
'relation' => $this->relation,
'value' => $this->value,
];
}
}
33 changes: 33 additions & 0 deletions src/Dto/Filter/AppVersionFilter.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
<?php

declare(strict_types=1);

namespace OneSignal\Dto\Filter;

final class AppVersionFilter extends AbstractFilter
{
/**
* @var self::GT|self::LT|self::EQ|self::NEQ
*/
protected string $relation;

protected string $value;

/**
* @param self::GT|self::LT|self::EQ|self::NEQ $relation
*/
public function __construct(string $relation, string $value)
{
$this->relation = $relation;
$this->value = $value;
}

public function toArray(): array
{
return [
'field' => 'app_version',
'relation' => $this->relation,
'value' => $this->value,
];
}
}
41 changes: 41 additions & 0 deletions src/Dto/Filter/BoughtSkuFilter.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
<?php

declare(strict_types=1);

namespace OneSignal\Dto\Filter;

final class BoughtSkuFilter extends AbstractFilter
{
/**
* @var self::GT|self::LT|self::EQ
*/
protected string $relation;

protected string $key;

/**
* @var int|float
*/
protected $value;

/**
* @param self::GT|self::LT|self::EQ $relation
* @param int|float $value
*/
public function __construct(string $relation, string $key, $value)
{
$this->relation = $relation;
$this->key = $key;
$this->value = $value;
}

public function toArray(): array
{
return [
'field' => 'bought_sku',
'relation' => $this->relation,
'key' => $this->key,
'value' => $this->value,
];
}
}
42 changes: 42 additions & 0 deletions src/Dto/Filter/ConditionalFilter.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
<?php

declare(strict_types=1);

namespace OneSignal\Dto\Filter;

final class ConditionalFilter extends AbstractFilter
{
public const AND = 'AND';

public const OR = 'OR';

/**
* @var self::AND|self::OR
*/
protected string $operator;

/**
* @param self::AND|self::OR $operator
*/
public function __construct(string $operator)
{
$this->operator = $operator;
}

/**
* @param self::AND|self::OR $operator
*/
public function setOperator(string $operator): self
{
$this->operator = $operator;

return $this;
}

public function toArray(): array
{
return [
'operator' => $this->operator,
];
}
}
24 changes: 24 additions & 0 deletions src/Dto/Filter/CountryFilter.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
<?php

declare(strict_types=1);

namespace OneSignal\Dto\Filter;

final class CountryFilter extends AbstractFilter
{
protected string $value;

public function __construct(string $value)
{
$this->value = $value;
}

public function toArray(): array
{
return [
'field' => 'country',
'relation' => self::EQ,
'value' => $this->value,
];
}
}
37 changes: 37 additions & 0 deletions src/Dto/Filter/FirstSessionFilter.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
<?php

declare(strict_types=1);

namespace OneSignal\Dto\Filter;

final class FirstSessionFilter extends AbstractFilter
{
/**
* @var self::GT|self::LT
*/
protected string $relation;

/**
* @var int|float
*/
protected $hoursAgo;

/**
* @param self::GT|self::LT $relation
* @param int|float $hoursAgo
*/
public function __construct(string $relation, $hoursAgo)
{
$this->relation = $relation;
$this->hoursAgo = $hoursAgo;
}

public function toArray(): array
{
return [
'field' => 'first_session',
'relation' => $this->relation,
'hours_ago' => $this->hoursAgo,
];
}
}
33 changes: 33 additions & 0 deletions src/Dto/Filter/LanguageFilter.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
<?php

declare(strict_types=1);

namespace OneSignal\Dto\Filter;

final class LanguageFilter extends AbstractFilter
{
/**
* @var self::EQ|self::NEQ
*/
protected string $relation;

protected string $value;

/**
* @param self::EQ|self::NEQ $relation
*/
public function __construct(string $relation, string $value)
{
$this->relation = $relation;
$this->value = $value;
}

public function toArray(): array
{
return [
'field' => 'language',
'relation' => $this->relation,
'value' => $this->value,
];
}
}
37 changes: 37 additions & 0 deletions src/Dto/Filter/LastSessionFilter.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
<?php

declare(strict_types=1);

namespace OneSignal\Dto\Filter;

final class LastSessionFilter extends AbstractFilter
{
/**
* @var self::GT|self::LT
*/
protected string $relation;

/**
* @var int|float
*/
protected $hoursAgo;

/**
* @param self::GT|self::LT $relation
* @param int|float $hoursAgo
*/
public function __construct(string $relation, $hoursAgo)
{
$this->relation = $relation;
$this->hoursAgo = $hoursAgo;
}

public function toArray(): array
{
return [
'field' => 'last_session',
'relation' => $this->relation,
'hours_ago' => $this->hoursAgo,
];
}
}
31 changes: 31 additions & 0 deletions src/Dto/Filter/LocationFilter.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
<?php

declare(strict_types=1);

namespace OneSignal\Dto\Filter;

final class LocationFilter extends AbstractFilter
{
protected int $radius;

protected float $lat;

protected float $long;

public function __construct(int $radius, float $lat, float $long)
{
$this->radius = $radius;
$this->lat = $lat;
$this->long = $long;
}

public function toArray(): array
{
return [
'field' => 'location',
'radius' => $this->radius,
'lat' => $this->lat,
'long' => $this->long,
];
}
}
33 changes: 33 additions & 0 deletions src/Dto/Filter/SessionCountFilter.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
<?php

declare(strict_types=1);

namespace OneSignal\Dto\Filter;

final class SessionCountFilter extends AbstractFilter
{
/**
* @var self::GT|self::LT|self::EQ|self::NEQ
*/
protected string $relation;

protected int $value;

/**
* @param self::GT|self::LT|self::EQ|self::NEQ $relation
*/
public function __construct(string $relation, int $value)
{
$this->relation = $relation;
$this->value = $value;
}

public function toArray(): array
{
return [
'field' => 'session_count',
'relation' => $this->relation,
'value' => $this->value,
];
}
}
Loading

0 comments on commit af80fa0

Please sign in to comment.