Skip to content

Commit 125ff8e

Browse files
author
Justinas Pošiūnas
committed
campaigns API: trigger action, create campaign, set content
1 parent 44aad54 commit 125ff8e

File tree

4 files changed

+100
-1
lines changed

4 files changed

+100
-1
lines changed

src/Api/Campaigns.php

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
<?php
2+
3+
namespace MailerLiteApi\Api;
4+
5+
use MailerLiteApi\Common\ApiAbstract;
6+
7+
class Campaigns extends ApiAbstract {
8+
9+
protected $endpoint = 'campaigns';
10+
11+
/**
12+
* Add custom html to campaign
13+
*
14+
* @param int $campaignId
15+
* @param array $contentData
16+
* @param array $params
17+
* @return [type]
18+
*/
19+
public function addContent($campaignId, $contentData = [], $params = [])
20+
{
21+
$endpoint = $this->endpoint . '/' . $campaignId . '/content';
22+
23+
$response = $this->restClient->put($endpoint, $contentData);
24+
25+
return $response['body'];
26+
}
27+
28+
/**
29+
* Trigger action: send
30+
*
31+
* @param int $campaignId
32+
* @param array $settingsData
33+
* @return [type]
34+
*/
35+
public function send($campaignId, $settingsData)
36+
{
37+
$endpoint = $this->endpoint . '/' . $campaignId . '/actions/send';
38+
39+
$response = $this->restClient->post($endpoint, $settingsData);
40+
41+
return $response['body'];
42+
}
43+
44+
/**
45+
* Trigger action: cancel
46+
*
47+
* @param int $campaignId
48+
* @return [type]
49+
*/
50+
public function cancel($campaignId)
51+
{
52+
$endpoint = $this->endpoint . '/' . $campaignId . '/actions/cancel';
53+
54+
$response = $this->restClient->post($endpoint);
55+
56+
return $response['body'];
57+
}
58+
}

src/Mailerlite.php

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,14 @@ public function subscribers()
6565
return new \MailerLiteApi\Api\Subscribers($this->restClient);
6666
}
6767

68+
/**
69+
* @return \MailerLiteApi\Api\Campaigns
70+
*/
71+
public function campaigns()
72+
{
73+
return new \MailerLiteApi\Api\Campaigns($this->restClient);
74+
}
75+
6876
/**
6977
* @param string $version
7078
* @return string

tests/CampaignsTest.php

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
<?php
2+
3+
namespace MailerLiteApi\Tests;
4+
5+
use MailerLiteApi\MailerLite;
6+
use MailerLiteApi\Api\Campaigns;
7+
8+
class CampaignsTest extends MlTestCase
9+
{
10+
protected $campaignsApi;
11+
12+
protected function setUp()
13+
{
14+
$this->campaignsApi = (new MailerLite(API_KEY))->campaigns();
15+
}
16+
17+
/** @test **/
18+
public function create_campaign()
19+
{
20+
$campaignData = [
21+
'subject' => 'Regular Campaign Subject',
22+
'type' => 'regular',
23+
'groups' => [2984475, 3237221] // TODO: improve this with creating new groups
24+
];
25+
26+
$campaign = $this->campaignsApi->create($campaignData);
27+
28+
$this->assertTrue($campaign->campaign_type == $campaignData['type']);
29+
30+
$this->campaignsApi->delete($field->id);
31+
}
32+
33+
}

tests/FieldsTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
namespace MailerLiteApi\Tests;
44

55
use MailerLiteApi\MailerLite;
6-
use MailerLiteApi\Resources\Fields;
6+
use MailerLiteApi\Api\Fields;
77

88
class FieldsTest extends MlTestCase
99
{

0 commit comments

Comments
 (0)