-
Notifications
You must be signed in to change notification settings - Fork 44
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
campaigns API: trigger action, create campaign, set content
- Loading branch information
Justinas Pošiūnas
committed
May 18, 2016
1 parent
44aad54
commit 125ff8e
Showing
4 changed files
with
100 additions
and
1 deletion.
There are no files selected for viewing
This file contains 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,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']; | ||
} | ||
} |
This file contains 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 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,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); | ||
} | ||
|
||
} |
This file contains 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