|
1
|
|
|
<?php |
|
2
|
|
|
/** |
|
3
|
|
|
* @author Oleg Krivtsov <[email protected]> |
|
4
|
|
|
* @date 07 October 2016 |
|
5
|
|
|
* @copyright (c) 2016, Web Marketing ROI |
|
6
|
|
|
*/ |
|
7
|
|
|
namespace WebMarketingROI\OptimizelyPHP\Service\v2; |
|
8
|
|
|
|
|
9
|
|
|
use WebMarketingROI\OptimizelyPHP\Resource\v2\Page; |
|
10
|
|
|
|
|
11
|
|
|
/** |
|
12
|
|
|
* Provides methods for working with Optimizely project pages. |
|
13
|
|
|
*/ |
|
14
|
|
|
class Pages |
|
15
|
|
|
{ |
|
16
|
|
|
/** |
|
17
|
|
|
* Optimizely API Client. |
|
18
|
|
|
* @var WebMarketingROI\OptimizelyPHP\OptimizelyApiClient |
|
19
|
|
|
*/ |
|
20
|
|
|
private $client; |
|
21
|
|
|
|
|
22
|
|
|
/** |
|
23
|
|
|
* Constructor. |
|
24
|
|
|
*/ |
|
25
|
5 |
|
public function __construct($client) |
|
26
|
|
|
{ |
|
27
|
5 |
|
$this->client = $client; |
|
28
|
5 |
|
} |
|
29
|
|
|
|
|
30
|
|
|
/** |
|
31
|
|
|
* List all Pages for a project. |
|
32
|
|
|
* @param integer $projectId |
|
33
|
|
|
* @param integer $page |
|
34
|
|
|
* @param integer $perPage |
|
35
|
|
|
* @return array[Page] |
|
|
|
|
|
|
36
|
|
|
* @throws \Exception |
|
37
|
|
|
*/ |
|
38
|
1 |
View Code Duplication |
public function listAll($projectId, $page=0, $perPage=10) |
|
|
|
|
|
|
39
|
|
|
{ |
|
40
|
1 |
|
if ($page<0) { |
|
41
|
|
|
throw new \Exception('Invalid page number passed'); |
|
42
|
|
|
} |
|
43
|
|
|
|
|
44
|
1 |
|
if ($perPage<0) { |
|
45
|
|
|
throw new \Exception('Invalid page size passed'); |
|
46
|
|
|
} |
|
47
|
|
|
|
|
48
|
1 |
|
$response = $this->client->sendApiRequest('/pages', |
|
49
|
|
|
array( |
|
50
|
1 |
|
'project_id'=>$projectId, |
|
51
|
1 |
|
'page'=>$page, |
|
52
|
|
|
'per_page'=>$perPage |
|
53
|
1 |
|
)); |
|
54
|
|
|
|
|
55
|
1 |
|
$pages = array(); |
|
56
|
1 |
|
foreach ($response as $pageInfo) { |
|
57
|
1 |
|
$page = new Page($pageInfo); |
|
58
|
1 |
|
$pages[] = $page; |
|
59
|
1 |
|
} |
|
60
|
|
|
|
|
61
|
1 |
|
return $pages; |
|
62
|
|
|
} |
|
63
|
|
|
|
|
64
|
|
|
/** |
|
65
|
|
|
* Get metadata for a single Page |
|
66
|
|
|
* @param integer $pageId |
|
67
|
|
|
* @return Page |
|
68
|
|
|
* @throws \Exception |
|
69
|
|
|
*/ |
|
70
|
1 |
View Code Duplication |
public function get($pageId) |
|
|
|
|
|
|
71
|
|
|
{ |
|
72
|
1 |
|
if (!is_int($pageId)) { |
|
73
|
|
|
throw new \Exception("Integer page ID expected, while got '$pageId'"); |
|
74
|
|
|
} |
|
75
|
|
|
|
|
76
|
1 |
|
$response = $this->client->sendApiRequest("/pages/$pageId"); |
|
77
|
|
|
|
|
78
|
1 |
|
$page = new Page($response); |
|
79
|
|
|
|
|
80
|
1 |
|
return $page; |
|
81
|
|
|
} |
|
82
|
|
|
|
|
83
|
|
|
/** |
|
84
|
|
|
* Create a new Page in a provided Project |
|
85
|
|
|
* @param Page $page |
|
86
|
|
|
*/ |
|
87
|
1 |
|
public function create($page) |
|
88
|
|
|
{ |
|
89
|
1 |
|
if (!($page instanceOf Page)) { |
|
90
|
|
|
throw new \Exception("Expected argument of type Page"); |
|
91
|
|
|
} |
|
92
|
|
|
|
|
93
|
1 |
|
$postData = $page->toArray(); |
|
94
|
|
|
|
|
95
|
1 |
|
$response = $this->client->sendApiRequest("/pages", array(), 'POST', |
|
96
|
1 |
|
$postData, array(201)); |
|
97
|
|
|
|
|
98
|
1 |
|
return new Page($response); |
|
99
|
|
|
} |
|
100
|
|
|
|
|
101
|
|
|
/** |
|
102
|
|
|
* Update a Page in a provided Project |
|
103
|
|
|
* @param integer $pageId |
|
104
|
|
|
* @param Audience $page |
|
105
|
|
|
* @throws \Exception |
|
106
|
|
|
*/ |
|
107
|
1 |
|
public function update($pageId, $page) |
|
108
|
|
|
{ |
|
109
|
1 |
|
if (!($page instanceOf Page)) { |
|
110
|
|
|
throw new \Exception("Expected argument of type Page"); |
|
111
|
|
|
} |
|
112
|
|
|
|
|
113
|
1 |
|
$postData = $page->toArray(); |
|
114
|
|
|
|
|
115
|
1 |
|
$response = $this->client->sendApiRequest("/pages/$pageId", array(), 'PATCH', |
|
116
|
1 |
|
$postData, array(200)); |
|
117
|
|
|
|
|
118
|
1 |
|
return new Page($response); |
|
119
|
|
|
} |
|
120
|
|
|
|
|
121
|
|
|
/** |
|
122
|
|
|
* Delete a Page within a Project by ID. |
|
123
|
|
|
* @param integer $pageId |
|
124
|
|
|
* @throws \Exception |
|
125
|
|
|
*/ |
|
126
|
1 |
|
public function delete($pageId) |
|
127
|
|
|
{ |
|
128
|
1 |
|
$response = $this->client->sendApiRequest("/pages/$pageId", array(), 'DELETE', |
|
|
|
|
|
|
129
|
1 |
|
array(), array(200)); |
|
130
|
1 |
|
} |
|
131
|
|
|
} |
|
132
|
|
|
|
|
133
|
|
|
|
|
134
|
|
|
|
|
135
|
|
|
|
|
136
|
|
|
|
|
137
|
|
|
|
|
138
|
|
|
|
This check marks PHPDoc comments that could not be parsed by our parser. To see which comment annotations we can parse, please refer to our documentation on supported doc-types.