Skip to content

Commit

Permalink
Implementation for get campaigns endpoint.
Browse files Browse the repository at this point in the history
  • Loading branch information
tadaspaplauskas committed Nov 2, 2016
1 parent 1d59e6c commit 878da57
Show file tree
Hide file tree
Showing 3 changed files with 72 additions and 0 deletions.
23 changes: 23 additions & 0 deletions src/Api/Campaigns.php
Original file line number Diff line number Diff line change
Expand Up @@ -55,4 +55,27 @@ public function cancel($campaignId)

return $response['body'];
}

/**
* Get collection of items
* @param array $fields
* @return [type]
*/
public function get($type = 'sent', $fields = ['*'])
{
// filter anything that is not an available type
$type = in_array($type, ['sent', 'draft', 'outbox']) ? $type : 'sent';

$params = $this->prepareParams();

if ( ! empty($fields) && is_array($fields) && $fields != ['*']) {
$params['fields'] = $fields;
}

$response = $this->restClient->get($this->endpoint . '/' . $type, $params);

$entities = $this->generateCollection($response['body']);

return $entities;
}
}
25 changes: 25 additions & 0 deletions tests/CampaignsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,4 +30,29 @@ public function create_campaign()
$this->campaignsApi->delete($campaign->id);
}

/** @test **/
public function get_campaigns()
{
// see drafts
$drafts = $this->campaignsApi->get('draft');

$this->assertContainsValue($drafts, 'status', 'draft');
$this->assertDoesNotContainValue($drafts, 'status', 'sent');
$this->assertDoesNotContainValue($drafts, 'status', 'outbox');

// see outbox
$outbox = $this->campaignsApi->get('outbox');

$this->assertContainsValue($outbox, 'status', 'outbox');
$this->assertDoesNotContainValue($outbox, 'status', 'sent');
$this->assertDoesNotContainValue($outbox, 'status', 'draft');

// see sent
$sent = $this->campaignsApi->get();

$this->assertContainsValue($sent, 'status', 'sent');
$this->assertDoesNotContainValue($sent, 'status', 'outbox');
$this->assertDoesNotContainValue($sent, 'status', 'draft');
}

}
24 changes: 24 additions & 0 deletions tests/MlTestCase.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,4 +38,28 @@ protected function addSubscribers($groupId, $count = 5)
return $addedSubscribers->imported;
}

protected function assertContainsValue($list, $key, $value)
{
return $this->assertTrue($this->containsValue($list, $key, $value));
}

protected function assertDoesNotContainValue($list, $key, $value)
{
return $this->assertFalse($this->containsValue($list, $key, $value));
}

protected function containsValue($list, $key, $value)
{
$found = false;

foreach ($list as $item) {
if ($item->$key === $value) {
$found = true;
break;
}
}

return $found;
}

}

0 comments on commit 878da57

Please sign in to comment.