PageRenderTime 35ms CodeModel.GetById 18ms RepoModel.GetById 0ms app.codeStats 0ms

/src/MessageManagement/Account.php

https://gitlab.com/blueprintmrk/dyn-php
PHP | 796 lines | 349 code | 115 blank | 332 comment | 16 complexity | 2f0a3eee563f9797c2fee909a177a986 MD5 | raw file
  1. <?php
  2. namespace Dyn\MessageManagement;
  3. use InvalidArgumentException;
  4. use DateTime;
  5. class Account
  6. {
  7. /**
  8. * @var string
  9. */
  10. protected $username;
  11. /**
  12. * @var string
  13. */
  14. protected $password;
  15. /**
  16. * @var string
  17. */
  18. protected $accountName;
  19. /**
  20. * @var string
  21. */
  22. protected $companyName;
  23. /**
  24. * @var string
  25. */
  26. protected $address;
  27. /**
  28. * @var string
  29. */
  30. protected $city;
  31. /**
  32. * @var string
  33. */
  34. protected $state;
  35. /**
  36. * @var string
  37. */
  38. protected $country;
  39. /**
  40. * @var string
  41. */
  42. protected $zipCode;
  43. /**
  44. * @var string
  45. */
  46. protected $phone;
  47. /**
  48. * @var string
  49. */
  50. protected $userType;
  51. /**
  52. * @var DateTime
  53. */
  54. protected $created;
  55. /**
  56. * @var string
  57. */
  58. protected $apiKey;
  59. /**
  60. * @var string
  61. */
  62. protected $timeZone;
  63. /**
  64. * Boucne callback URL
  65. *
  66. * @var string
  67. */
  68. protected $bounceUrl;
  69. /**
  70. * Spam complaint callback URL
  71. *
  72. * @var string
  73. */
  74. protected $spamUrl;
  75. /**
  76. * Unsubscribe callback URL
  77. *
  78. * @var string
  79. */
  80. protected $unsubscribeUrl;
  81. /**
  82. * @var boolean
  83. */
  84. protected $trackLinks;
  85. /**
  86. * @var boolean
  87. */
  88. protected $trackOpens;
  89. /**
  90. * @var string
  91. */
  92. protected $testMode;
  93. /**
  94. * @var boolean
  95. */
  96. protected $trackUnsubscribes;
  97. /**
  98. * @var integer
  99. */
  100. protected $maxSampleCount;
  101. /**
  102. * @var string
  103. */
  104. protected $contactName;
  105. /**
  106. * @var integer
  107. */
  108. protected $emailsSent;
  109. /**
  110. * Creates an Account instance from the supplied JSON data
  111. *
  112. * @param stdClass $json
  113. * @return self
  114. */
  115. public static function fromJson($json)
  116. {
  117. $account = new static();
  118. $account->setUsername($json->username)
  119. ->setCompanyName($json->companyname)
  120. ->setAddress($json->address)
  121. ->setCity($json->city)
  122. ->setState($json->state)
  123. ->setCountry($json->country)
  124. ->setZipCode($json->zipcode)
  125. ->setPhone($json->phone)
  126. ->setUserType($json->usertype)
  127. ->setCreated($json->created)
  128. ->setApiKey($json->apikey)
  129. ->setTimeZone($json->timezone)
  130. ->setTrackLinks($json->tracklinks)
  131. ->setTrackOpens($json->trackopens)
  132. ->setTestMode($json->testmode)
  133. ->setTrackUnsubscribes($json->trackunsubscribes)
  134. ->setContactName($json->contactname)
  135. ->setEmailsSent($json->emailssent);
  136. if (isset($json->bounceurl)) {
  137. $account->setBounceUrl($json->bounceurl);
  138. }
  139. if (isset($json->spamurl)) {
  140. $account->setSpamUrl($json->spamurl);
  141. }
  142. if (isset($json->unsuburl)) {
  143. $account->setUnsubscribeUrl($json->unsuburl);
  144. }
  145. if (isset($json->accountname)) {
  146. $account->setAccountName($json->accountname);
  147. }
  148. if (isset($json->max_sample_count)) {
  149. $account->setMaxSampleCount($json->max_sample_count);
  150. }
  151. return $account;
  152. }
  153. /**
  154. * Returns an array of account properties suitable for use in various
  155. * API calls.
  156. *
  157. * @return array
  158. */
  159. public function toApiParams()
  160. {
  161. return array(
  162. 'username' => $this->getUsername(),
  163. 'password' => $this->getPassword(),
  164. 'companyname' => $this->getCompanyName(),
  165. 'phone' => $this->getPhone(),
  166. 'address' => $this->getAddress(),
  167. 'city' => $this->getCity(),
  168. 'state' => $this->getState(),
  169. 'zipcode' => $this->getZipCode(),
  170. 'country' => $this->getCountry(),
  171. 'timezone' => $this->getTimeZone(),
  172. 'bounceurl' => $this->getBounceUrl(),
  173. 'spamurl' => $this->getSpamUrl(),
  174. 'unsubscribeurl' => $this->getUnsubscribeUrl(),
  175. 'trackopens' => $this->getTrackOpens() ? '1' : '0',
  176. 'tracklinks' => $this->getTrackLinks() ? '1' : '0',
  177. 'trackunsubscribes' => $this->getTrackUnsubscribes() ? '1' : '0',
  178. 'generatenewapikey' => '0', // TODO
  179. );
  180. }
  181. /**
  182. * Setter for username
  183. *
  184. * @param string $username
  185. */
  186. public function setUsername($username)
  187. {
  188. if (filter_var($username, FILTER_VALIDATE_EMAIL) === false) {
  189. throw new InvalidArgumentException('Invalid username specified');
  190. }
  191. $this->username = $username;
  192. return $this;
  193. }
  194. /**
  195. * Getter for username
  196. *
  197. * @return string
  198. */
  199. public function getUsername()
  200. {
  201. return $this->username;
  202. }
  203. /**
  204. * Setter for password
  205. *
  206. * @param string $password
  207. */
  208. public function setPassword($password)
  209. {
  210. $this->password = $password;
  211. return $this;
  212. }
  213. /**
  214. * Getter for password
  215. *
  216. * @return string
  217. */
  218. public function getPassword()
  219. {
  220. return $this->password;
  221. }
  222. /**
  223. * Setter for account name
  224. *
  225. * @param string $accountName
  226. */
  227. public function setAccountName($accountName)
  228. {
  229. $this->accountName = $accountName;
  230. return $this;
  231. }
  232. /**
  233. * Getter for account name
  234. *
  235. * @return string
  236. */
  237. public function getAccountName()
  238. {
  239. return $this->accountName;
  240. }
  241. /**
  242. * Setter for company name
  243. *
  244. * @param string $companyName
  245. */
  246. public function setCompanyName($companyName)
  247. {
  248. $this->companyName = $companyName;
  249. return $this;
  250. }
  251. /**
  252. * Getter for company name
  253. *
  254. * @return string
  255. */
  256. public function getCompanyName()
  257. {
  258. return $this->companyName;
  259. }
  260. /**
  261. * Setter for address
  262. *
  263. * @param string $address
  264. */
  265. public function setAddress($address)
  266. {
  267. $this->address = $address;
  268. return $this;
  269. }
  270. /**
  271. * Getter for address
  272. *
  273. * @return string
  274. */
  275. public function getAddress()
  276. {
  277. return $this->address;
  278. }
  279. /**
  280. * Setter for city
  281. *
  282. * @param string $city
  283. */
  284. public function setCity($city)
  285. {
  286. $this->city = $city;
  287. return $this;
  288. }
  289. /**
  290. * Getter for city
  291. *
  292. * @return string
  293. */
  294. public function getCity()
  295. {
  296. return $this->city;
  297. }
  298. /**
  299. * Setter for state
  300. *
  301. * @param string $state
  302. */
  303. public function setState($state)
  304. {
  305. $this->state = $state;
  306. return $this;
  307. }
  308. /**
  309. * Getter for state
  310. *
  311. * @return string
  312. */
  313. public function getState()
  314. {
  315. return $this->state;
  316. }
  317. /**
  318. * Setter for country
  319. *
  320. * @param string $country
  321. */
  322. public function setCountry($country)
  323. {
  324. $this->country = $country;
  325. return $this;
  326. }
  327. /**
  328. * Getter for country
  329. *
  330. * @return string
  331. */
  332. public function getCountry()
  333. {
  334. return $this->country;
  335. }
  336. /**
  337. * Setter for zip code
  338. *
  339. * @param string $zipCode
  340. */
  341. public function setZipCode($zipCode)
  342. {
  343. $this->zipCode = $zipCode;
  344. return $this;
  345. }
  346. /**
  347. * Getter for zip code
  348. *
  349. * @return string
  350. */
  351. public function getZipCode()
  352. {
  353. return $this->zipCode;
  354. }
  355. /**
  356. * Setter for phone number
  357. *
  358. * @param string $phone
  359. */
  360. public function setPhone($phone)
  361. {
  362. $this->phone = $phone;
  363. return $this;
  364. }
  365. /**
  366. * Getter for phone number
  367. *
  368. * @return string
  369. */
  370. public function getPhone()
  371. {
  372. return $this->phone;
  373. }
  374. /**
  375. * Setter for user type
  376. *
  377. * @param string $userType
  378. */
  379. public function setUserType($userType)
  380. {
  381. $this->userType = $userType;
  382. return $this;
  383. }
  384. /**
  385. * Getter for user type
  386. *
  387. * @return string
  388. */
  389. public function getUserType()
  390. {
  391. return $this->userType;
  392. }
  393. /**
  394. * Setter for created date
  395. *
  396. * Converts the date to a PHP DateTime object if required
  397. *
  398. * @param DateTime|string $created
  399. */
  400. public function setCreated($created)
  401. {
  402. if (!($created instanceof DateTime)) {
  403. $created = new DateTime($created);
  404. }
  405. $this->created = $created;
  406. return $this;
  407. }
  408. /**
  409. * Getter for created date
  410. *
  411. * @return DateTime
  412. */
  413. public function getCreated()
  414. {
  415. return $this->created;
  416. }
  417. /**
  418. * Setter for API key
  419. *
  420. * @param string $apiKey
  421. */
  422. public function setApiKey($apiKey)
  423. {
  424. $this->apiKey = $apiKey;
  425. return $this;
  426. }
  427. /**
  428. * Getter for API key
  429. *
  430. * @return string
  431. */
  432. public function getApiKey()
  433. {
  434. return $this->apiKey;
  435. }
  436. /**
  437. * Setter for time zone
  438. *
  439. * @param string $timeZone
  440. */
  441. public function setTimeZone($timeZone)
  442. {
  443. $this->timeZone = $timeZone;
  444. return $this;
  445. }
  446. /**
  447. * Getter for time zone
  448. *
  449. * @return string
  450. */
  451. public function getTimeZone()
  452. {
  453. return $this->timeZone;
  454. }
  455. /**
  456. * Setter for bounce URL
  457. *
  458. * @param string $bounceUrl
  459. */
  460. public function setBounceUrl($bounceUrl)
  461. {
  462. $this->bounceUrl = $bounceUrl;
  463. return $this;
  464. }
  465. /**
  466. * Getter for bounce URL
  467. *
  468. * @return string
  469. */
  470. public function getBounceUrl()
  471. {
  472. return $this->bounceUrl;
  473. }
  474. /**
  475. * Setter for spam URL
  476. *
  477. * @param string $spamUrl
  478. */
  479. public function setSpamUrl($spamUrl)
  480. {
  481. $this->spamUrl = $spamUrl;
  482. return $this;
  483. }
  484. /**
  485. * Getter for spam URL
  486. *
  487. * @return string
  488. */
  489. public function getSpamUrl()
  490. {
  491. return $this->spamUrl;
  492. }
  493. /**
  494. * Setter for unsubscribe URL
  495. *
  496. * @param string $unsubscribeUrl
  497. */
  498. public function setUnsubscribeUrl($unsubscribeUrl)
  499. {
  500. $this->unsubscribeUrl = $unsubscribeUrl;
  501. return $this;
  502. }
  503. /**
  504. * Getter for unsubscribe URL
  505. *
  506. * @return string
  507. */
  508. public function getUnsubscribeUrl()
  509. {
  510. return $this->unsubscribeUrl;
  511. }
  512. /**
  513. * Setter for track links
  514. *
  515. * @param boolean|string $trackLinks
  516. */
  517. public function setTrackLinks($trackLinks)
  518. {
  519. if (is_numeric($trackLinks)) {
  520. if ($trackLinks > 1 || $trackLinks < 0) {
  521. throw new InvalidArgumentException(
  522. 'Invalid value supplied for Account::setTrackLinks()'
  523. );
  524. }
  525. $trackLinks = (bool)$trackLinks;
  526. } elseif (!is_bool($trackLinks)) {
  527. throw new InvalidArgumentException(
  528. 'Invalid value supplied for Account::setTrackLinks()'
  529. );
  530. }
  531. $this->trackLinks = $trackLinks;
  532. return $this;
  533. }
  534. /**
  535. * Getter for track links
  536. *
  537. * @return boolean
  538. */
  539. public function getTrackLinks()
  540. {
  541. return $this->trackLinks;
  542. }
  543. /**
  544. * Setter for track opens
  545. *
  546. * @param boolean|string $trackOpens
  547. */
  548. public function setTrackOpens($trackOpens)
  549. {
  550. if (is_numeric($trackOpens)) {
  551. if ($trackOpens > 1 || $trackOpens < 0) {
  552. throw new InvalidArgumentException(
  553. 'Invalid value supplied for Account::setTrackOpens()'
  554. );
  555. }
  556. $trackOpens = (bool)$trackOpens;
  557. } elseif (!is_bool($trackOpens)) {
  558. throw new InvalidArgumentException(
  559. 'Invalid value supplied for Account::setTrackOpens()'
  560. );
  561. }
  562. $this->trackOpens = $trackOpens;
  563. return $this;
  564. }
  565. /**
  566. * Getter for track opens
  567. *
  568. * @return boolean
  569. */
  570. public function getTrackOpens()
  571. {
  572. return $this->trackOpens;
  573. }
  574. /**
  575. * Setter for test mode
  576. *
  577. * @param string $testMode
  578. */
  579. public function setTestMode($testMode)
  580. {
  581. $this->testMode = $testMode;
  582. return $this;
  583. }
  584. /**
  585. * Getter for test mode
  586. *
  587. * @return string
  588. */
  589. public function getTestMode()
  590. {
  591. return $this->testMode;
  592. }
  593. /**
  594. * Setter for track unsubscribes
  595. *
  596. * @param boolean|string $trackUnsubscribes
  597. */
  598. public function setTrackUnsubscribes($trackUnsubscribes)
  599. {
  600. if (is_numeric($trackUnsubscribes)) {
  601. if ($trackUnsubscribes > 1 || $trackUnsubscribes < 0) {
  602. throw new InvalidArgumentException(
  603. 'Invalid value supplied for Account::setTrackUnsubscribes()'
  604. );
  605. }
  606. $trackUnsubscribes = (bool)$trackUnsubscribes;
  607. } elseif (!is_bool($trackUnsubscribes)) {
  608. throw new InvalidArgumentException(
  609. 'Invalid value supplied for Account::setTrackUnsubscribes()'
  610. );
  611. }
  612. $this->trackUnsubscribes = $trackUnsubscribes;
  613. return $this;
  614. }
  615. /**
  616. * Getter for track unsubscribes
  617. *
  618. * @return boolean
  619. */
  620. public function getTrackUnsubscribes()
  621. {
  622. return $this->trackUnsubscribes;
  623. }
  624. /**
  625. * Setter for max sample count
  626. *
  627. * @param integer $maxSampleCount
  628. */
  629. public function setMaxSampleCount($maxSampleCount)
  630. {
  631. $this->maxSampleCount = $maxSampleCount;
  632. return $this;
  633. }
  634. /**
  635. * Getter for max sample count
  636. *
  637. * @return integer
  638. */
  639. public function getMaxSampleCount()
  640. {
  641. return $this->maxSampleCount;
  642. }
  643. /**
  644. * Setter for contact name
  645. *
  646. * @param string $contactName
  647. */
  648. public function setContactName($contactName)
  649. {
  650. $this->contactName = $contactName;
  651. return $this;
  652. }
  653. /**
  654. * Getter for contact name
  655. *
  656. * @return string
  657. */
  658. public function getContactName()
  659. {
  660. return $this->contactName;
  661. }
  662. /**
  663. * Setter for emails sent
  664. *
  665. * @param integer $emailsSent
  666. */
  667. public function setEmailsSent($emailsSent)
  668. {
  669. $this->emailsSent = $emailsSent;
  670. return $this;
  671. }
  672. /**
  673. * Getter for emails sent
  674. *
  675. * @return integer
  676. */
  677. public function getEmailsSent()
  678. {
  679. return $this->emailsSent;
  680. }
  681. }