forked from pionl/smart-emailing-v3
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Contactlists, Emails and Newsletter endpoints (pionl#7)
Add contactlist API
- Loading branch information
1 parent
2900ddb
commit ba2aa04
Showing
10 changed files
with
385 additions
and
7 deletions.
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
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
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,72 @@ | ||
<?php declare(strict_types=1); | ||
|
||
namespace SmartEmailing\v3\Request\Contactlists; | ||
|
||
use SmartEmailing\v3\Api; | ||
use SmartEmailing\v3\Exceptions\InvalidFormatException; | ||
use SmartEmailing\v3\Request\AbstractRequest; | ||
|
||
class Contactlist extends AbstractRequest implements \JsonSerializable | ||
{ | ||
|
||
private const ALL_FIELDS = [ | ||
'id', | ||
'name', | ||
'category', | ||
'publicname', | ||
'sendername', | ||
'senderemail', | ||
'replyto', | ||
'signature', | ||
'segment_id', | ||
]; | ||
|
||
/** @var string[] */ | ||
private $select = self::ALL_FIELDS; | ||
|
||
/** @var int */ | ||
private $listId; | ||
|
||
public function __construct(Api $api, int $listId) | ||
{ | ||
parent::__construct($api); | ||
|
||
$this->listId = $listId; | ||
} | ||
|
||
public function select(array $select): self | ||
{ | ||
InvalidFormatException::checkAllowedValues($select, self::ALL_FIELDS); | ||
|
||
$this->select = $select; | ||
return $this; | ||
} | ||
|
||
protected function endpoint(): string | ||
{ | ||
return 'contactlists/' . $this->listId; | ||
} | ||
|
||
protected function options(): array | ||
{ | ||
return [ | ||
'json' => $this->jsonSerialize() | ||
]; | ||
} | ||
|
||
private function toArray(): array | ||
{ | ||
return [ | ||
'select' => implode(',', $this->select), | ||
]; | ||
} | ||
|
||
/** | ||
* @return array | ||
*/ | ||
public function jsonSerialize() | ||
{ | ||
return $this->toArray(); | ||
} | ||
|
||
} |
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,28 @@ | ||
<?php declare(strict_types=1); | ||
|
||
namespace SmartEmailing\v3\Request\Contactlists; | ||
|
||
use SmartEmailing\v3\Api; | ||
|
||
class ContactlistEndpoint | ||
{ | ||
|
||
/** @var Api */ | ||
private $api; | ||
|
||
public function __construct(Api $api) | ||
{ | ||
$this->api = $api; | ||
} | ||
|
||
public function lists(): Contactlists | ||
{ | ||
return new Contactlists($this->api); | ||
} | ||
|
||
public function get(int $listId): Contactlist | ||
{ | ||
return new Contactlist($this->api, $listId); | ||
} | ||
|
||
} |
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,61 @@ | ||
<?php declare(strict_types=1); | ||
|
||
namespace SmartEmailing\v3\Request\Contactlists; | ||
|
||
use SmartEmailing\v3\Exceptions\InvalidFormatException; | ||
use SmartEmailing\v3\Request\AbstractRequest; | ||
|
||
class Contactlists extends AbstractRequest implements \JsonSerializable | ||
{ | ||
|
||
private const ALL_FIELDS = [ | ||
'id', | ||
'name', | ||
'category', | ||
'publicname', | ||
'sendername', | ||
'senderemail', | ||
'replyto', | ||
'signature', | ||
'segment_id', | ||
]; | ||
|
||
/** @var string[] */ | ||
private $select = self::ALL_FIELDS; | ||
|
||
public function select(array $select): self | ||
{ | ||
InvalidFormatException::checkAllowedValues($select, self::ALL_FIELDS); | ||
|
||
$this->select = $select; | ||
return $this; | ||
} | ||
|
||
protected function endpoint(): string | ||
{ | ||
return 'contactlists'; | ||
} | ||
|
||
protected function options(): array | ||
{ | ||
return [ | ||
'json' => $this->jsonSerialize() | ||
]; | ||
} | ||
|
||
private function toArray(): array | ||
{ | ||
return [ | ||
'select' => implode(',', $this->select), | ||
]; | ||
} | ||
|
||
/** | ||
* @return array | ||
*/ | ||
public function jsonSerialize() | ||
{ | ||
return $this->toArray(); | ||
} | ||
|
||
} |
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,95 @@ | ||
<?php declare(strict_types=1); | ||
|
||
namespace SmartEmailing\v3\Request\Email; | ||
|
||
use SmartEmailing\v3\Api; | ||
use SmartEmailing\v3\Exceptions\PropertyRequiredException; | ||
use SmartEmailing\v3\Request\AbstractRequest; | ||
|
||
class Email extends AbstractRequest implements \JsonSerializable | ||
{ | ||
|
||
/** @var string */ | ||
private $title; | ||
|
||
/** @var string|null */ | ||
private $name; | ||
|
||
/** @var string|null */ | ||
private $htmlBody; | ||
|
||
/** @var string|null */ | ||
private $textBody; | ||
|
||
public function __construct(Api $api, string $title) | ||
{ | ||
parent::__construct($api); | ||
$this->title = $title; | ||
} | ||
|
||
public function setName(string $name): self | ||
{ | ||
$this->name = $name; | ||
return $this; | ||
} | ||
|
||
public function setHtmlBody(string $htmlBody): self | ||
{ | ||
$this->htmlBody = $htmlBody; | ||
return $this; | ||
} | ||
|
||
public function setTextBody(string $textBody): self | ||
{ | ||
$this->textBody = $textBody; | ||
return $this; | ||
} | ||
|
||
protected function endpoint(): string | ||
{ | ||
return 'emails'; | ||
} | ||
|
||
protected function method() | ||
{ | ||
return 'POST'; | ||
} | ||
|
||
protected function options(): array | ||
{ | ||
if ($this->htmlBody === null && $this->textBody === null) { | ||
throw new PropertyRequiredException("At least one of the properties must be set: 'htmlBody', 'textBody'"); | ||
} | ||
|
||
return [ | ||
'json' => $this->jsonSerialize() | ||
]; | ||
} | ||
|
||
private function toArray(): array | ||
{ | ||
$data = [ | ||
'title' => $this->title, | ||
'name' => $this->name ?: $this->title, | ||
]; | ||
|
||
if ($this->htmlBody) { | ||
$data['htmlbody'] = $this->htmlBody; | ||
} | ||
|
||
if ($this->textBody) { | ||
$data['textbody'] = $this->textBody; | ||
} | ||
|
||
return $data; | ||
} | ||
|
||
/** | ||
* @return array | ||
*/ | ||
public function jsonSerialize() | ||
{ | ||
return $this->toArray(); | ||
} | ||
|
||
} |
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,23 @@ | ||
<?php declare(strict_types=1); | ||
|
||
namespace SmartEmailing\v3\Request\Email; | ||
|
||
use SmartEmailing\v3\Api; | ||
|
||
class EmailsEndpoint | ||
{ | ||
|
||
/** @var Api */ | ||
private $api; | ||
|
||
public function __construct(Api $api) | ||
{ | ||
$this->api = $api; | ||
} | ||
|
||
public function createNew(string $title): Email | ||
{ | ||
return new Email($this->api, $title); | ||
} | ||
|
||
} |
Oops, something went wrong.