1: <?php
2: namespace Ctct\Components\EmailMarketing;
3:
4: use Ctct\Components\Component;
5:
6: /**
7: * Represents a campaign Test Send in Constant Contact
8: *
9: * @package Components
10: * @subpackage EmailMarketing
11: * @author Constant Contact
12: */
13: class TestSend extends Component
14: {
15: /**
16: * Format of the email to send (HTML, TEXT, HTML_AND_TEXT)
17: * @var string
18: */
19: public $format;
20:
21: /**
22: * Personal message to send along with the test send
23: * @var
24: */
25: public $personal_message;
26:
27: /**
28: * Array of email addresses to send the test send to
29: * @var array
30: */
31: public $email_addresses = array();
32:
33: /**
34: * Factory method to create a TestSend object from an array
35: * @param array $props - associative array of initial properties to set
36: * @return TestSend
37: */
38: public static function create(array $props)
39: {
40: $test_send = new TestSend();
41: $test_send->format = parent::getValue($props, "format");
42: $test_send->personal_message = parent::getValue($props, "personal_message");
43:
44: foreach ($props['email_addresses'] as $email_address) {
45: $test_send->email_addresses[] = $email_address;
46: }
47:
48: return $test_send;
49: }
50:
51: /**
52: * Add an email address to the set of addresses to send the test send too
53: * @param string $email_address
54: */
55: public function addEmail($email_address)
56: {
57: $this->email_addresses[] = $email_address;
58: }
59:
60: /**
61: * Create json used for a POST/PUT request, also handles removing attributes that will cause errors if sent
62: * @return string
63: */
64: public function toJson()
65: {
66: $testSend = clone $this;
67: if ($testSend->personal_message == null) {
68: unset($testSend->personal_message);
69: }
70: return json_encode($testSend);
71: }
72: }
73: