-
Notifications
You must be signed in to change notification settings - Fork 82
Added missing segments API calls (v11) #178
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 10 commits
Commits
Show all changes
51 commits
Select commit
Hold shift + click to select a range
739bbe5
added segments api calls
rcerljenko f1b309e
php cs fixer fix
rcerljenko d37c6bc
moved to phpdoc payload array
rcerljenko 32cde31
fix erros
rcerljenko 21b93b9
fix errors
rcerljenko 7bf3d11
introduce dto
rcerljenko 0ce5531
introduce dto
rcerljenko 87924c6
introduce dto
rcerljenko bd3440a
fixes
rcerljenko 15ce5cb
removed general purpose pagination dto
rcerljenko 2cbd763
requested changes
rcerljenko 88a9a0d
requested changes
rcerljenko 45ce096
requested changes
rcerljenko 30f411a
requested changes
rcerljenko 310f776
requested changes
rcerljenko 2b73275
requested changes
rcerljenko 59b8b9d
Merge branch 'master' into feature/segments
rcerljenko ec753de
removed []
rcerljenko c40dfe9
Merge branch 'feature/segments' of https://github.com/rcerljenko/ones…
rcerljenko ae0120e
added filters dto
rcerljenko a9ef92b
added filters dto
rcerljenko 4b00629
added filters dto
rcerljenko 9b52286
fixes
rcerljenko 6285d84
added missing relation key
rcerljenko 177f1a8
moved value to extra params
rcerljenko 95d5307
added relation constants
rcerljenko 19a01fc
introduce separate dtos for every filter type
rcerljenko 079542e
renamed filters
rcerljenko d039ac9
change request
rcerljenko 171a390
change request
rcerljenko 22b53da
namespace change to singular
rcerljenko e3c5be8
namespace change to singular
rcerljenko 4e8157f
move operands to abstract class
rcerljenko 7dec6e5
null check filters
rcerljenko 4b26aaf
fix
rcerljenko 72c928e
added response objects
rcerljenko 71ba641
added response objects
rcerljenko 9abc5e3
added exception handling
rcerljenko 3f75b40
added exception handling
rcerljenko ec9ad0d
added exception handling
rcerljenko e0587b5
added request and response to exception
rcerljenko 5fb5974
added request and response to exception - fixes
rcerljenko 2a91971
added separate makeRequest method
rcerljenko 3566e53
added separate makeRequest method
rcerljenko e67cd5d
added separate makeRequest method
rcerljenko c721474
added separate makeRequest method
rcerljenko 2337167
added list and delete segments tests
rcerljenko 1d81fca
added requested changes
rcerljenko 4d5caf6
removed unused method
rcerljenko ccc897d
changes
rcerljenko 0886d6e
added test for create segment
rcerljenko File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace OneSignal\Dto\Segments; | ||
|
||
use OneSignal\Dto\AbstractDto; | ||
|
||
class CreateSegment implements AbstractDto | ||
{ | ||
protected string $name; | ||
rcerljenko marked this conversation as resolved.
Show resolved
Hide resolved
rcerljenko marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
protected array $filters = []; | ||
rcerljenko marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
/** | ||
* @param array<int, array> $filters | ||
rcerljenko marked this conversation as resolved.
Show resolved
Hide resolved
|
||
*/ | ||
public function __construct(string $name, array $filters = []) | ||
{ | ||
$this->name = $name; | ||
$this->filters = $filters; | ||
} | ||
|
||
public function setName(string $name): self | ||
rcerljenko marked this conversation as resolved.
Show resolved
Hide resolved
rcerljenko marked this conversation as resolved.
Show resolved
Hide resolved
|
||
{ | ||
$this->name = $name; | ||
|
||
return $this; | ||
} | ||
|
||
/** | ||
* @param array<int, array> $filters | ||
*/ | ||
public function setFilters(array $filters = []): self | ||
rcerljenko marked this conversation as resolved.
Show resolved
Hide resolved
rcerljenko marked this conversation as resolved.
Show resolved
Hide resolved
|
||
{ | ||
$this->filters = $filters; | ||
|
||
return $this; | ||
} | ||
|
||
public function toArray(): array | ||
{ | ||
return [ | ||
'name' => $this->name, | ||
'filters' => $this->filters, | ||
]; | ||
} | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace OneSignal\Dto\Segments; | ||
|
||
use OneSignal\Dto\AbstractDto; | ||
|
||
class ListSegments implements AbstractDto | ||
{ | ||
protected ?int $limit = null; | ||
rcerljenko marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
protected ?int $offset = null; | ||
rcerljenko marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
public function __construct(?int $limit = null, ?int $offset = null) | ||
rcerljenko marked this conversation as resolved.
Show resolved
Hide resolved
|
||
{ | ||
$this->limit = $limit; | ||
$this->offset = $offset; | ||
} | ||
|
||
public function setLimit(?int $limit = null): self | ||
rcerljenko marked this conversation as resolved.
Show resolved
Hide resolved
|
||
{ | ||
$this->limit = $limit; | ||
|
||
return $this; | ||
} | ||
|
||
public function setOffset(?int $offset = null): self | ||
rcerljenko marked this conversation as resolved.
Show resolved
Hide resolved
|
||
{ | ||
$this->offset = $offset; | ||
|
||
return $this; | ||
} | ||
|
||
public function toArray(): array | ||
rcerljenko marked this conversation as resolved.
Show resolved
Hide resolved
|
||
{ | ||
$query = []; | ||
|
||
if ($this->limit !== null) { | ||
$query['limit'] = $this->limit; | ||
} | ||
|
||
if ($this->offset !== null) { | ||
$query['offset'] = $this->offset; | ||
} | ||
|
||
return $query; | ||
} | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace OneSignal; | ||
|
||
use OneSignal\Dto\Segments\CreateSegment; | ||
use OneSignal\Dto\Segments\ListSegments; | ||
|
||
class Segments extends AbstractApi | ||
{ | ||
public function __construct(OneSignal $client) | ||
{ | ||
parent::__construct($client); | ||
} | ||
|
||
/** | ||
* Get information about all segments. | ||
* | ||
* Application authentication key and ID must be set. | ||
*/ | ||
public function list(ListSegments $listSegmentsDto): array | ||
{ | ||
$app_id = $this->client->getConfig()->getApplicationId(); | ||
|
||
$request = $this->createRequest('GET', '/apps/'.$app_id.'/segments?'.http_build_query($listSegmentsDto->toArray())); | ||
$request = $request->withHeader('Authorization', "Basic {$this->client->getConfig()->getApplicationAuthKey()}"); | ||
|
||
return $this->client->sendRequest($request); | ||
rcerljenko marked this conversation as resolved.
Show resolved
Hide resolved
|
||
} | ||
|
||
/** | ||
* Create new segment with provided data. | ||
* | ||
* Application authentication key and ID must be set. | ||
*/ | ||
public function create(CreateSegment $createSegmentDto): array | ||
{ | ||
$app_id = $this->client->getConfig()->getApplicationId(); | ||
|
||
$request = $this->createRequest('POST', '/apps/'.$app_id.'/segments'); | ||
rcerljenko marked this conversation as resolved.
Show resolved
Hide resolved
|
||
$request = $request->withHeader('Authorization', "Basic {$this->client->getConfig()->getApplicationAuthKey()}"); | ||
$request = $request->withHeader('Content-Type', 'application/json'); | ||
$request = $request->withBody($this->createStream($createSegmentDto->toArray())); | ||
|
||
return $this->client->sendRequest($request); | ||
} | ||
|
||
/** | ||
* Delete segment. | ||
* | ||
* Application authentication key and ID must be set. | ||
* | ||
* @param string $id Segment ID | ||
rcerljenko marked this conversation as resolved.
Show resolved
Hide resolved
|
||
*/ | ||
public function delete(string $id): array | ||
{ | ||
$app_id = $this->client->getConfig()->getApplicationId(); | ||
|
||
$request = $this->createRequest('DELETE', '/apps/'.$app_id.'/segments/'.$id); | ||
rcerljenko marked this conversation as resolved.
Show resolved
Hide resolved
|
||
$request = $request->withHeader('Authorization', "Basic {$this->client->getConfig()->getApplicationAuthKey()}"); | ||
|
||
return $this->client->sendRequest($request); | ||
} | ||
} |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.