Skip to content

Commit

Permalink
campaigns API: trigger action, create campaign, set content
Browse files Browse the repository at this point in the history
  • Loading branch information
Justinas Pošiūnas committed May 18, 2016
1 parent 44aad54 commit 125ff8e
Show file tree
Hide file tree
Showing 4 changed files with 100 additions and 1 deletion.
58 changes: 58 additions & 0 deletions src/Api/Campaigns.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
<?php

namespace MailerLiteApi\Api;

use MailerLiteApi\Common\ApiAbstract;

class Campaigns extends ApiAbstract {

protected $endpoint = 'campaigns';

/**
* Add custom html to campaign
*
* @param int $campaignId
* @param array $contentData
* @param array $params
* @return [type]
*/
public function addContent($campaignId, $contentData = [], $params = [])
{
$endpoint = $this->endpoint . '/' . $campaignId . '/content';

$response = $this->restClient->put($endpoint, $contentData);

return $response['body'];
}

/**
* Trigger action: send
*
* @param int $campaignId
* @param array $settingsData
* @return [type]
*/
public function send($campaignId, $settingsData)
{
$endpoint = $this->endpoint . '/' . $campaignId . '/actions/send';

$response = $this->restClient->post($endpoint, $settingsData);

return $response['body'];
}

/**
* Trigger action: cancel
*
* @param int $campaignId
* @return [type]
*/
public function cancel($campaignId)
{
$endpoint = $this->endpoint . '/' . $campaignId . '/actions/cancel';

$response = $this->restClient->post($endpoint);

return $response['body'];
}
}
8 changes: 8 additions & 0 deletions src/Mailerlite.php
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,14 @@ public function subscribers()
return new \MailerLiteApi\Api\Subscribers($this->restClient);
}

/**
* @return \MailerLiteApi\Api\Campaigns
*/
public function campaigns()
{
return new \MailerLiteApi\Api\Campaigns($this->restClient);
}

/**
* @param string $version
* @return string
Expand Down
33 changes: 33 additions & 0 deletions tests/CampaignsTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
<?php

namespace MailerLiteApi\Tests;

use MailerLiteApi\MailerLite;
use MailerLiteApi\Api\Campaigns;

class CampaignsTest extends MlTestCase
{
protected $campaignsApi;

protected function setUp()
{
$this->campaignsApi = (new MailerLite(API_KEY))->campaigns();
}

/** @test **/
public function create_campaign()
{
$campaignData = [
'subject' => 'Regular Campaign Subject',
'type' => 'regular',
'groups' => [2984475, 3237221] // TODO: improve this with creating new groups
];

$campaign = $this->campaignsApi->create($campaignData);

$this->assertTrue($campaign->campaign_type == $campaignData['type']);

$this->campaignsApi->delete($field->id);
}

}
2 changes: 1 addition & 1 deletion tests/FieldsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
namespace MailerLiteApi\Tests;

use MailerLiteApi\MailerLite;
use MailerLiteApi\Resources\Fields;
use MailerLiteApi\Api\Fields;

class FieldsTest extends MlTestCase
{
Expand Down

0 comments on commit 125ff8e

Please sign in to comment.