| @@ 90-105 (lines=16) @@ | ||
| 87 | * Create a new Page in a provided Project |
|
| 88 | * @param Page $page |
|
| 89 | */ |
|
| 90 | public function create($page) |
|
| 91 | { |
|
| 92 | if (!($page instanceOf Page)) { |
|
| 93 | throw new Exception("Expected argument of type Page"); |
|
| 94 | } |
|
| 95 | ||
| 96 | $postData = $page->toArray(); |
|
| 97 | ||
| 98 | $result = $this->client->sendApiRequest("/pages", array(), 'POST', |
|
| 99 | $postData); |
|
| 100 | ||
| 101 | $page = new Page($result->getDecodedJsonData()); |
|
| 102 | $result->setPayload($page); |
|
| 103 | ||
| 104 | return $result; |
|
| 105 | } |
|
| 106 | ||
| 107 | /** |
|
| 108 | * Update a Page in a provided Project |
|
| @@ 114-129 (lines=16) @@ | ||
| 111 | * @return Result |
|
| 112 | * @throws Exception |
|
| 113 | */ |
|
| 114 | public function update($pageId, $page) |
|
| 115 | { |
|
| 116 | if (!($page instanceOf Page)) { |
|
| 117 | throw new Exception("Expected argument of type Page"); |
|
| 118 | } |
|
| 119 | ||
| 120 | $postData = $page->toArray(); |
|
| 121 | ||
| 122 | $result = $this->client->sendApiRequest("/pages/$pageId", array(), 'PATCH', |
|
| 123 | $postData); |
|
| 124 | ||
| 125 | $page = new Page($result->getDecodedJsonData()); |
|
| 126 | $result->setPayload($page); |
|
| 127 | ||
| 128 | return $result; |
|
| 129 | } |
|
| 130 | ||
| 131 | /** |
|
| 132 | * Delete a Page within a Project by ID. |
|
| @@ 72-85 (lines=14) @@ | ||
| 69 | * @return Result |
|
| 70 | * @throws Exception |
|
| 71 | */ |
|
| 72 | public function get($audienceId) |
|
| 73 | { |
|
| 74 | if (!is_int($audienceId)) { |
|
| 75 | throw new Exception("Integer audience ID expected, while got '$audienceId'", |
|
| 76 | Exception::CODE_INVALID_ARG); |
|
| 77 | } |
|
| 78 | ||
| 79 | $result = $this->client->sendApiRequest("/audiences/$audienceId"); |
|
| 80 | ||
| 81 | $audience = new Audience($result->getDecodedJsonData()); |
|
| 82 | $result->setPayload($audience); |
|
| 83 | ||
| 84 | return $result; |
|
| 85 | } |
|
| 86 | ||
| 87 | /** |
|
| 88 | * Create an Audience for a Project. |
|
| @@ 91-107 (lines=17) @@ | ||
| 88 | * Create an Audience for a Project. |
|
| 89 | * @param Result |
|
| 90 | */ |
|
| 91 | public function create($audience) |
|
| 92 | { |
|
| 93 | if (!($audience instanceOf \WebMarketingROI\OptimizelyPHP\Resource\v2\Audience)) { |
|
| 94 | throw new Exception("Expected argument of type Audience", |
|
| 95 | Exception::CODE_INVALID_ARG); |
|
| 96 | } |
|
| 97 | ||
| 98 | $postData = $audience->toArray(); |
|
| 99 | ||
| 100 | $result = $this->client->sendApiRequest("/audiences", array(), 'POST', |
|
| 101 | $postData, array(201)); |
|
| 102 | ||
| 103 | $audience = new Audience($result->getDecodedJsonData()); |
|
| 104 | $result->setPayload($audience); |
|
| 105 | ||
| 106 | return $result; |
|
| 107 | } |
|
| 108 | ||
| 109 | /** |
|
| 110 | * Update an Audience for a Project |
|
| @@ 115-131 (lines=17) @@ | ||
| 112 | * @param Result |
|
| 113 | * @throws Exception |
|
| 114 | */ |
|
| 115 | public function update($audienceId, $audience) |
|
| 116 | { |
|
| 117 | if (!($audience instanceOf \WebMarketingROI\OptimizelyPHP\Resource\v2\Audience)) { |
|
| 118 | throw new Exception("Expected argument of type Audience", |
|
| 119 | Exception::CODE_INVALID_ARG); |
|
| 120 | } |
|
| 121 | ||
| 122 | $postData = $audience->toArray(); |
|
| 123 | ||
| 124 | $result = $this->client->sendApiRequest("/audiences/$audienceId", array(), 'PATCH', |
|
| 125 | $postData, array(200)); |
|
| 126 | ||
| 127 | $audience = new Audience($result->getDecodedJsonData()); |
|
| 128 | $result->setPayload($audience); |
|
| 129 | ||
| 130 | return $result; |
|
| 131 | } |
|
| 132 | } |
|
| 133 | ||
| 134 | ||
| @@ 81-93 (lines=13) @@ | ||
| 78 | * @return Result |
|
| 79 | * @throws Exception |
|
| 80 | */ |
|
| 81 | public function get($campaignId) |
|
| 82 | { |
|
| 83 | if (!is_int($campaignId)) { |
|
| 84 | throw new Exception("Integer campaign ID expected, while got '$campaignId'"); |
|
| 85 | } |
|
| 86 | ||
| 87 | $result = $this->client->sendApiRequest("/campaigns/$campaignId"); |
|
| 88 | ||
| 89 | $campaign = new Campaign($result->getDecodedJsonData()); |
|
| 90 | $result->setPayload($campaign); |
|
| 91 | ||
| 92 | return $result; |
|
| 93 | } |
|
| 94 | ||
| 95 | /** |
|
| 96 | * Get campaign results |
|
| @@ 78-91 (lines=14) @@ | ||
| 75 | * @return Result |
|
| 76 | * @throws Exception |
|
| 77 | */ |
|
| 78 | public function get($eventId) |
|
| 79 | { |
|
| 80 | if (!is_int($eventId)) { |
|
| 81 | throw new Exception("Integer event ID expected, while got '$eventId'", |
|
| 82 | Exception::CODE_INVALID_ARG); |
|
| 83 | } |
|
| 84 | ||
| 85 | $result = $this->client->sendApiRequest("/events/$eventId"); |
|
| 86 | ||
| 87 | $event = new Event($result->getDecodedJsonData()); |
|
| 88 | $result->setPayload($event); |
|
| 89 | ||
| 90 | return $result; |
|
| 91 | } |
|
| 92 | ||
| 93 | /** |
|
| 94 | * Creates a new click event. |
|
| @@ 151-167 (lines=17) @@ | ||
| 148 | * @return Result |
|
| 149 | * @throws Exception |
|
| 150 | */ |
|
| 151 | public function updateClickEvent($pageId, $eventId, $event) |
|
| 152 | { |
|
| 153 | if (!($event instanceOf ClickEvent)) { |
|
| 154 | throw new Exception("Expected argument of type ClickEvent", |
|
| 155 | Exception::CODE_INVALID_ARG); |
|
| 156 | } |
|
| 157 | ||
| 158 | $postData = $event->toArray(); |
|
| 159 | ||
| 160 | $result = $this->client->sendApiRequest("/pages/$pageId/click_events/$eventId", array(), 'PATCH', |
|
| 161 | $postData); |
|
| 162 | ||
| 163 | $event = new ClickEvent($result->getDecodedJsonData()); |
|
| 164 | $result->setPayload($event); |
|
| 165 | ||
| 166 | return $result; |
|
| 167 | } |
|
| 168 | ||
| 169 | /** |
|
| 170 | * Updates the given custom event. |
|
| @@ 177-193 (lines=17) @@ | ||
| 174 | * @return Result |
|
| 175 | * @throws Exception |
|
| 176 | */ |
|
| 177 | public function updateCustomEvent($pageId, $eventId, $event) |
|
| 178 | { |
|
| 179 | if (!($event instanceOf CustomEvent)) { |
|
| 180 | throw new Exception("Expected argument of type CustomEvent", |
|
| 181 | Exception::CODE_INVALID_ARG); |
|
| 182 | } |
|
| 183 | ||
| 184 | $postData = $event->toArray(); |
|
| 185 | ||
| 186 | $result = $this->client->sendApiRequest("/pages/$pageId/custom_events/$eventId", array(), 'PATCH', |
|
| 187 | $postData); |
|
| 188 | ||
| 189 | $event = new CustomEvent($result->getDecodedJsonData()); |
|
| 190 | $result->setPayload($event); |
|
| 191 | ||
| 192 | return $result; |
|
| 193 | } |
|
| 194 | } |
|
| 195 | ||
| 196 | ||
| @@ 72-85 (lines=14) @@ | ||
| 69 | * @return Result |
|
| 70 | * @throws Exception |
|
| 71 | */ |
|
| 72 | public function get($attributeId) |
|
| 73 | { |
|
| 74 | if (!is_int($attributeId)) { |
|
| 75 | throw new Exception("Integer attribute ID expected, while got '$attributeId'", |
|
| 76 | Exception::CODE_INVALID_ARG); |
|
| 77 | } |
|
| 78 | ||
| 79 | $result = $this->client->sendApiRequest("/attributes/$attributeId"); |
|
| 80 | ||
| 81 | $attribute = new Attribute($result->getDecodedJsonData()); |
|
| 82 | $result->setPayload($attribute); |
|
| 83 | ||
| 84 | return $result; |
|
| 85 | } |
|
| 86 | ||
| 87 | /** |
|
| 88 | * Create an Attribue |
|
| @@ 91-107 (lines=17) @@ | ||
| 88 | * Create an Attribue |
|
| 89 | * @param Result |
|
| 90 | */ |
|
| 91 | public function create($attribute) |
|
| 92 | { |
|
| 93 | if (!($attribute instanceOf \WebMarketingROI\OptimizelyPHP\Resource\v2\Attribute)) { |
|
| 94 | throw new Exception("Expected argument of type Attribute", |
|
| 95 | Exception::CODE_INVALID_ARG); |
|
| 96 | } |
|
| 97 | ||
| 98 | $postData = $attribute->toArray(); |
|
| 99 | ||
| 100 | $result = $this->client->sendApiRequest("/attributes", array(), 'POST', |
|
| 101 | $postData, array(201)); |
|
| 102 | ||
| 103 | $attribute = new Attribute($result->getDecodedJsonData()); |
|
| 104 | $result->setPayload($attribute); |
|
| 105 | ||
| 106 | return $result; |
|
| 107 | } |
|
| 108 | ||
| 109 | /** |
|
| 110 | * Update an Attribute by ID |
|
| @@ 116-132 (lines=17) @@ | ||
| 113 | * @return Result |
|
| 114 | * @throws Exception |
|
| 115 | */ |
|
| 116 | public function update($attributeId, $attribute) |
|
| 117 | { |
|
| 118 | if (!($attribute instanceOf \WebMarketingROI\OptimizelyPHP\Resource\v2\Attribute)) { |
|
| 119 | throw new Exception("Expected argument of type Attribute", |
|
| 120 | Exception::CODE_INVALID_ARG); |
|
| 121 | } |
|
| 122 | ||
| 123 | $postData = $attribute->toArray(); |
|
| 124 | ||
| 125 | $result = $this->client->sendApiRequest("/attributes/$attributeId", array(), 'PATCH', |
|
| 126 | $postData, array(200)); |
|
| 127 | ||
| 128 | $attribute = new Attribute($result->getDecodedJsonData()); |
|
| 129 | $result->setPayload($attribute); |
|
| 130 | ||
| 131 | return $result; |
|
| 132 | } |
|
| 133 | ||
| 134 | /** |
|
| 135 | * Delete Attribute by ID |
|