Skip to content

Commit

Permalink
add: added Segments
Browse files Browse the repository at this point in the history
  • Loading branch information
petrealessio committed Sep 5, 2024
1 parent fb84573 commit a47fcb2
Show file tree
Hide file tree
Showing 8 changed files with 222 additions and 0 deletions.
128 changes: 128 additions & 0 deletions src/Api/Resources/SegmentsApi.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,128 @@
<?php

namespace OfflineAgency\LaravelEmailChef\Api\Resources;

use Carbon\Carbon;
use OfflineAgency\LaravelEmailChef\Api\Api;
use OfflineAgency\LaravelEmailChef\Entities\Error;
use OfflineAgency\LaravelEmailChef\Entities\Segments\SegmentCollection;
use OfflineAgency\LaravelEmailChef\Entities\Segments\Segment;
use OfflineAgency\LaravelEmailChef\Entities\Segments\SegmentCount;
use OfflineAgency\LaravelEmailChef\Entities\Segments\ContactsCount;
use OfflineAgency\LaravelEmailChef\Entities\Segments\CreateSegment;
use OfflineAgency\LaravelEmailChef\Entities\Segments\UpdateSegment;
use OfflineAgency\LaravelEmailChef\Entities\Segments\SegmentDeletion;

class SegmentsApi extends Api
{
public function getCollection(
string $list_id,
?int $limit,
?int $offset
) {
$response = $this->get('segments', [
'list_id' => $list_id,
'limit' => $limit,
'offset' => $offset,
]);

if (! $response->success) {
return new Error($response->data);
}

$getCollection = $response->data;

return new SegmentCollection($getCollection);
}

public function getInstance(
string $segment_id
)
{
$response = $this->get('lists/251338/segments/' . $segment_id);

if (! $response->success) {
return new Error($response->data);
}

$getInstance = $response->data;

return new Segment($getInstance);
}

public function getCount(
string $list_id
)
{
$response = $this->get('lists/' . $list_id . '/segments/count?');

if (! $response->success) {
return new Error($response->data);
}

$getCount = $response->data;

return new SegmentCount($getCount);
}

public function getContactsCount(
string $segment_id
)
{
$response = $this->get('segments/' . $segment_id . '/contacts/count');

if (! $response->success) {
return new Error($response->data);
}

$getContactsCount = $response->data;

return new ContactsCount($$getContactsCount);
}

public function createInstance(
array $body
)
{
$response = $this->post('segments ', $body);

if (! $response->success) {
return new Error($response->data);
}

$createInstance = $response->data;

return new CreateSegment($createInstance);
}

public function updateInstance(
string $segment_id,
array $body
)
{
$response = $this->put('segments/'. $segment_id, $body);

if (! $response->success) {
return new Error($response->data);
}

$updateInstance = $response->data;

return new UpdateSegment($updateInstance);
}

public function deleteInstance(
string $segment_id
)
{
$response = $this->destroy('segments/'. $segment_id);

if (! $response->success) {
return new Error($response->data);
}

$deleteInstance = $response->data;

return new SegmentDeletion($deleteInstance);
}
}
12 changes: 12 additions & 0 deletions src/Entities/Segments/ContactsCount.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<?php

namespace OfflineAgency\LaravelEmailChef\Entities\Segments;

use OfflineAgency\LaravelEmailChef\Entities\AbstractEntity;

class ContactsCount extends AbstractEntity
{
public string $match_count;

public string $total_count;
}
10 changes: 10 additions & 0 deletions src/Entities/Segments/CreateSegment.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<?php

namespace OfflineAgency\LaravelEmailChef\Entities\Segments;

use OfflineAgency\LaravelEmailChef\Entities\AbstractEntity;

class CreateSegment extends AbstractEntity
{
public object $body;
}
20 changes: 20 additions & 0 deletions src/Entities/Segments/Segment.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
<?php

namespace OfflineAgency\LaravelEmailChef\Entities\Segments;

use OfflineAgency\LaravelEmailChef\Entities\AbstractEntity;

class Segment extends AbstractEntity
{
public string $id;

public string $list_id;

public string $logic;

public array $condition_groups;

public string $name;

public string $description;
}
20 changes: 20 additions & 0 deletions src/Entities/Segments/SegmentCollection.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
<?php

namespace OfflineAgency\LaravelEmailChef\Entities\Segments;

use OfflineAgency\LaravelEmailChef\Entities\AbstractEntity;

class SegmentCollection extends AbstractEntity
{
public string $id;

public string $name;

public string $description;

public string $match_count;

public string $total_count;

public $last_refresh_time;
}
10 changes: 10 additions & 0 deletions src/Entities/Segments/SegmentCount.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<?php

namespace OfflineAgency\LaravelEmailChef\Entities\Segments;

use OfflineAgency\LaravelEmailChef\Entities\AbstractEntity;

class SegmentCount extends AbstractEntity
{
public string $totalcount;
}
12 changes: 12 additions & 0 deletions src/Entities/Segments/SegmentDeletion.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<?php

namespace OfflineAgency\LaravelEmailChef\Entities\Segments;

use OfflineAgency\LaravelEmailChef\Entities\AbstractEntity;

class SegmentDeletion extends AbstractEntity
{
public string $status;

public string $id;
}
10 changes: 10 additions & 0 deletions src/Entities/Segments/UpdateSegment.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<?php

namespace OfflineAgency\LaravelEmailChef\Entities\Segments;

use OfflineAgency\LaravelEmailChef\Entities\AbstractEntity;

class UpdateSegment extends AbstractEntity
{
public object $body;
}

0 comments on commit a47fcb2

Please sign in to comment.