|
| 1 | +<?php |
| 2 | + |
| 3 | + |
| 4 | +namespace MailchimpAPI\Resources; |
| 5 | + |
| 6 | + |
| 7 | +use MailchimpAPI\Requests\MailchimpRequest; |
| 8 | +use MailchimpAPI\Settings\MailchimpSettings; |
| 9 | + |
| 10 | +/** |
| 11 | + * Class LandingPages |
| 12 | + * @package MailchimpAPI\Resources |
| 13 | + */ |
| 14 | +class LandingPages extends ApiResource |
| 15 | +{ |
| 16 | + /** |
| 17 | + * @var null |
| 18 | + */ |
| 19 | + private $page_id; |
| 20 | + |
| 21 | + /** |
| 22 | + * the url component for this endpoint |
| 23 | + */ |
| 24 | + const URL_COMPONENT = "/landing-pages/"; |
| 25 | + |
| 26 | + /** |
| 27 | + * the url component for publishing a landing page |
| 28 | + */ |
| 29 | + const PUBLISH_URL_COMPONENT = "/actions/publish/"; |
| 30 | + |
| 31 | + /** |
| 32 | + * the url component for unpublishing a landing page |
| 33 | + */ |
| 34 | + const UNPUBLISH_URL_COMPONENT = "/actions/unpublish/"; |
| 35 | + |
| 36 | + /** |
| 37 | + * LandingPages constructor. |
| 38 | + * @param MailchimpRequest $request |
| 39 | + * @param MailchimpSettings $settings |
| 40 | + * @param null $page_id |
| 41 | + */ |
| 42 | + public function __construct(MailchimpRequest $request, MailchimpSettings $settings, $page_id = null) |
| 43 | + { |
| 44 | + parent::__construct($request, $settings); |
| 45 | + $request->appendToEndpoint(self::URL_COMPONENT . $page_id); |
| 46 | + $this->page_id = $page_id; |
| 47 | + } |
| 48 | + |
| 49 | + /** |
| 50 | + * @return \MailchimpAPI\Responses\MailchimpResponse |
| 51 | + * @throws \MailchimpAPI\MailchimpException |
| 52 | + */ |
| 53 | + public function publish() |
| 54 | + { |
| 55 | + $this->throwIfNot("id", $this->page_id); |
| 56 | + return $this->postToActionEndpoint(self::PUBLISH_URL_COMPONENT); |
| 57 | + } |
| 58 | + |
| 59 | + /** |
| 60 | + * @return \MailchimpAPI\Responses\MailchimpResponse |
| 61 | + * @throws \MailchimpAPI\MailchimpException |
| 62 | + */ |
| 63 | + public function unpublish() |
| 64 | + { |
| 65 | + $this->throwIfNot("id", $this->page_id); |
| 66 | + return $this->postToActionEndpoint(self::UNPUBLISH_URL_COMPONENT); |
| 67 | + } |
| 68 | + |
| 69 | + /** |
| 70 | + * @return LandingPages\Content |
| 71 | + */ |
| 72 | + public function content() |
| 73 | + { |
| 74 | + return new LandingPages\Content( |
| 75 | + $this->getRequest(), |
| 76 | + $this->getSettings() |
| 77 | + ); |
| 78 | + } |
| 79 | +} |
0 commit comments