@@ -9,276 +9,276 @@ |
||
9 | 9 | |
10 | 10 | class AddressBookGroupUnitTests extends \PHPUnit\Framework\TestCase |
11 | 11 | { |
12 | - public static $createdGroups = []; |
|
13 | - |
|
14 | - public static function setUpBeforeClass() |
|
15 | - { |
|
16 | - Route4Me::setApiKey(Constants::API_KEY); |
|
17 | - |
|
18 | - $abg = new AddressBookGroup(); |
|
19 | - |
|
20 | - $createParameters= [ |
|
21 | - 'group_name' => 'All Group', |
|
22 | - 'group_color' => '92e1c0', |
|
23 | - 'filter' => [ |
|
24 | - 'condition' => 'AND', |
|
25 | - 'rules' => [[ |
|
26 | - 'id' => 'address_1', |
|
27 | - 'field' => 'address_1', |
|
28 | - 'operator' => 'not_equal', |
|
29 | - 'value' => 'qwerty123456' |
|
30 | - ]] |
|
31 | - ] |
|
32 | - ]; |
|
33 | - |
|
34 | - $createdAddressBookGroup = AddressBookGroup::fromArray( |
|
35 | - $abg->createAddressBookGroup($createParameters) |
|
36 | - ); |
|
37 | - |
|
38 | - self::$createdGroups[] = $createdAddressBookGroup; |
|
39 | - |
|
40 | - $createParameters= [ |
|
41 | - 'group_name' => 'All Group', |
|
42 | - 'group_color' => '92e1c0', |
|
43 | - 'filter' => [ |
|
44 | - 'condition' => 'AND', |
|
45 | - 'rules' => [[ |
|
46 | - 'id' => 'address_1', |
|
47 | - 'field' => 'address_1', |
|
48 | - 'operator' => 'not_equal', |
|
49 | - 'value' => 'qwerty123456' |
|
50 | - ]] |
|
51 | - ] |
|
52 | - ]; |
|
53 | - |
|
54 | - $createdAddressBookGroup = AddressBookGroup::fromArray( |
|
55 | - $abg->createAddressBookGroup($createParameters) |
|
56 | - ); |
|
57 | - |
|
58 | - self::$createdGroups[] = $createdAddressBookGroup; |
|
59 | - } |
|
60 | - |
|
61 | - public function testFromArray() |
|
62 | - { |
|
63 | - $addressBookGroup = AddressBookGroup::fromArray([ |
|
64 | - 'group_id' => '137F9F99544DB34C160B2B9AF8FC6A12', |
|
65 | - 'group_name' => 'Ocassion example', |
|
66 | - 'group_color' => '92e1c0', |
|
67 | - 'group_icon' => 'emoji-pushpin', |
|
68 | - 'member_id' => 444333, |
|
69 | - 'filter' => [ |
|
70 | - 'condition' => 'AND', |
|
71 | - 'rules' => [ |
|
72 | - [ |
|
73 | - 'id' => 'custom_data.occasion', |
|
74 | - 'field' => 'custom_data.occasion', |
|
75 | - 'operator' => 'equal', |
|
76 | - 'value' => '100' |
|
77 | - ]] |
|
78 | - ] |
|
79 | - ]); |
|
80 | - |
|
81 | - $this->assertEquals('137F9F99544DB34C160B2B9AF8FC6A12', $addressBookGroup->group_id); |
|
82 | - $this->assertEquals('Ocassion example', $addressBookGroup->group_name); |
|
83 | - $this->assertEquals('92e1c0', $addressBookGroup->group_color); |
|
84 | - $this->assertEquals('emoji-pushpin', $addressBookGroup->group_icon); |
|
85 | - $this->assertEquals(444333, $addressBookGroup->member_id); |
|
86 | - $this->assertEquals([ |
|
87 | - 'condition' => 'AND', |
|
88 | - 'rules' => [ |
|
89 | - [ |
|
90 | - 'id' => 'custom_data.occasion', |
|
91 | - 'field' => 'custom_data.occasion', |
|
92 | - 'operator' => 'equal', |
|
93 | - 'value' => '100' |
|
94 | - ]] |
|
95 | - ], $addressBookGroup->filter); |
|
96 | - } |
|
97 | - |
|
98 | - public function testGetAddressBookGroup() |
|
99 | - { |
|
100 | - $groupId = self::$createdGroups[0]->group_id; |
|
101 | - |
|
102 | - $abg = new AddressBookGroup(); |
|
103 | - |
|
104 | - $result = AddressBookGroup::fromArray( |
|
105 | - $abg->getAddressBookGroup(['group_id' => $groupId]) |
|
106 | - ); |
|
107 | - |
|
108 | - $this->assertNotNull($result); |
|
109 | - $this->assertContainsOnlyInstancesOf(AddressBookGroup::class, [$result]); |
|
110 | - } |
|
111 | - |
|
112 | - public function testUpdateAddressBookGroup() |
|
113 | - { |
|
114 | - $groupId = self::$createdGroups[0]->group_id; |
|
115 | - |
|
116 | - $updateParameters= [ |
|
117 | - 'group_id' => $groupId, |
|
118 | - 'group_color' => '7bd148' |
|
119 | - ]; |
|
120 | - |
|
121 | - $result = AddressBookGroup::fromArray( |
|
122 | - AddressBookGroup::updateAddressBookGroup($updateParameters) |
|
123 | - ); |
|
124 | - |
|
125 | - $this->assertNotNull($result); |
|
126 | - $this->assertContainsOnlyInstancesOf(AddressBookGroup::class, [$result]); |
|
127 | - $this->assertEquals('7bd148', $result->group_color); |
|
128 | - } |
|
129 | - |
|
130 | - public function testRemoveAddressBookGroup() |
|
131 | - { |
|
132 | - $groupId = end(self::$createdGroups)->group_id; |
|
133 | - |
|
134 | - $removeParameters= [ |
|
135 | - 'group_id' => $groupId |
|
136 | - ]; |
|
137 | - |
|
138 | - $result = AddressBookGroup::removeAddressBookGroup($removeParameters); |
|
139 | - |
|
140 | - $this->assertNotNull($result); |
|
141 | - $this->assertTrue(isset($result['status'])); |
|
142 | - $this->assertTrue($result['status']); |
|
143 | - |
|
144 | - self::$createdGroups[] = array_pop(self::$createdGroups); |
|
145 | - } |
|
146 | - |
|
147 | - public function testCreateAddressBookGroup() |
|
148 | - { |
|
149 | - $createParameters= [ |
|
150 | - 'group_name' => 'All Group', |
|
151 | - 'group_color' => '92e2cd', |
|
152 | - 'filter' => [ |
|
153 | - 'condition' => 'AND', |
|
154 | - 'rules' => [[ |
|
155 | - 'id' => 'address_1', |
|
156 | - 'field' => 'address_1', |
|
157 | - 'operator' => 'not_equal', |
|
158 | - 'value' => 'qwerty654321' |
|
159 | - ]] |
|
160 | - ] |
|
161 | - ]; |
|
162 | - |
|
163 | - $createdAddressBookGroup = AddressBookGroup::fromArray( |
|
164 | - AddressBookGroup::createAddressBookGroup($createParameters) |
|
165 | - ); |
|
166 | - |
|
167 | - $this->assertNotNull($createdAddressBookGroup); |
|
168 | - $this->assertContainsOnlyInstancesOf(AddressBookGroup::class, [$createdAddressBookGroup]); |
|
169 | - $this->assertEquals('92e2cd', $createdAddressBookGroup->group_color); |
|
170 | - |
|
171 | - self::$createdGroups[] = $createdAddressBookGroup; |
|
172 | - } |
|
173 | - |
|
174 | - public function testSearchAddressBookGroups() |
|
175 | - { |
|
176 | - $searchParameters = [ |
|
177 | - 'fields' => ['address_id', 'address_1', 'address_group'], |
|
178 | - 'limit' => 10, |
|
179 | - 'offset' => 0, |
|
180 | - 'filter' => [ |
|
181 | - 'query' => "Louisville", |
|
182 | - "display" => "all" |
|
183 | - ] |
|
184 | - ]; |
|
185 | - |
|
186 | - $addressBookGroups = SearchResponse::fromArray( |
|
187 | - AddressBookGroup::searchAddressBookGroups($searchParameters) |
|
188 | - ); |
|
189 | - |
|
190 | - $this->assertNotNull($addressBookGroups); |
|
191 | - $this->assertTrue(sizeof($addressBookGroups->fields)==3); |
|
192 | - $this->assertContains('address_id', $addressBookGroups->fields); |
|
193 | - $this->assertContains('address_1', $addressBookGroups->fields); |
|
194 | - $this->assertContains('address_group', $addressBookGroups->fields); |
|
195 | - |
|
196 | - $this->assertNotNull($addressBookGroups->results); |
|
197 | - |
|
198 | - if (sizeof($addressBookGroups->results)>0) { |
|
199 | - $this->assertContains('Louisville', implode(", ", $addressBookGroups->results[0])); |
|
200 | - } |
|
201 | - } |
|
202 | - |
|
203 | - public function testGetAddressBookContactsByGroup() |
|
204 | - { |
|
205 | - //$this->markTestSkipped('must be revisited.'); |
|
206 | - |
|
207 | - $groupId = self::$createdGroups[0]->group_id; |
|
208 | - |
|
209 | - $searchParameters = [ |
|
210 | - 'fields' => ['address_id'], |
|
211 | - 'group_id' => $groupId, |
|
212 | - ]; |
|
213 | - |
|
214 | - $result = AddressBookGroup::getAddressBookContactsByGroup($searchParameters); |
|
215 | - |
|
216 | - $this->assertNotNull($result); |
|
217 | - $this->assertTrue(isset($result['total'])); |
|
218 | - $this->assertTrue(isset($result['results'])); |
|
219 | - $this->assertTrue(is_array($result['results'])); |
|
220 | - } |
|
221 | - |
|
222 | - public function testGetAddressBookGroups() |
|
223 | - { |
|
224 | - $addressBookGroupParameters = [ |
|
225 | - 'limit' => 20, |
|
226 | - 'offset' => 0, |
|
227 | - ]; |
|
228 | - |
|
229 | - $addressBookGroups = AddressBookGroup::getAddressBookGroups($addressBookGroupParameters); |
|
230 | - |
|
231 | - $this->assertNotNull($addressBookGroups); |
|
232 | - |
|
233 | - $firstGroup = AddressBookGroup::fromArray( |
|
234 | - $addressBookGroups[0] |
|
235 | - ); |
|
236 | - |
|
237 | - $this->assertTrue(sizeof($addressBookGroups)>0); |
|
238 | - $this->assertContainsOnlyInstancesOf(AddressBookGroup::class, [$firstGroup]); |
|
239 | - } |
|
240 | - |
|
241 | - public function testgGetRandomAddressBookGroup() |
|
242 | - { |
|
243 | - $addressBookGroupParameters = [ |
|
244 | - 'limit' => 20, |
|
245 | - 'offset' => 0, |
|
246 | - ]; |
|
247 | - |
|
248 | - $randomGroup = AddressBookGroup::fromArray( |
|
249 | - AddressBookGroup::getRandomAddressBookGroup($addressBookGroupParameters) |
|
250 | - ); |
|
251 | - |
|
252 | - $this->assertNotNull($randomGroup); |
|
253 | - $this->assertContainsOnlyInstancesOf(AddressBookGroup::class, [$randomGroup]); |
|
254 | - } |
|
255 | - |
|
256 | - public function testGetAddressBookGroupIdByName() |
|
257 | - { |
|
258 | - $firstGroup = self::$createdGroups[0]; |
|
259 | - |
|
260 | - $groupIds = AddressBookGroup::getAddressBookGroupIdByName($firstGroup->group_name); |
|
261 | - |
|
262 | - $this->assertNotNull($groupIds); |
|
263 | - $this->assertTrue(in_array($firstGroup->group_id, $groupIds)); |
|
264 | - } |
|
265 | - |
|
266 | - public static function tearDownAfterClass() |
|
267 | - { |
|
268 | - foreach (self::$createdGroups as $createdGroup) { |
|
269 | - $groupId = $createdGroup->group_id; |
|
270 | - |
|
271 | - $removeParameters= [ |
|
272 | - 'group_id' => $groupId |
|
273 | - ]; |
|
274 | - |
|
275 | - $result = AddressBookGroup::removeAddressBookGroup($removeParameters); |
|
276 | - |
|
277 | - if ($result!=null && isset($result['status']) && isset($result['status'])) { |
|
278 | - echo "The address book group ".$groupId." removed successfully <br>"; |
|
279 | - } else { |
|
280 | - echo "Cannot remove the address book group ".$groupId."<br>"; |
|
281 | - } |
|
282 | - } |
|
283 | - } |
|
12 | + public static $createdGroups = []; |
|
13 | + |
|
14 | + public static function setUpBeforeClass() |
|
15 | + { |
|
16 | + Route4Me::setApiKey(Constants::API_KEY); |
|
17 | + |
|
18 | + $abg = new AddressBookGroup(); |
|
19 | + |
|
20 | + $createParameters= [ |
|
21 | + 'group_name' => 'All Group', |
|
22 | + 'group_color' => '92e1c0', |
|
23 | + 'filter' => [ |
|
24 | + 'condition' => 'AND', |
|
25 | + 'rules' => [[ |
|
26 | + 'id' => 'address_1', |
|
27 | + 'field' => 'address_1', |
|
28 | + 'operator' => 'not_equal', |
|
29 | + 'value' => 'qwerty123456' |
|
30 | + ]] |
|
31 | + ] |
|
32 | + ]; |
|
33 | + |
|
34 | + $createdAddressBookGroup = AddressBookGroup::fromArray( |
|
35 | + $abg->createAddressBookGroup($createParameters) |
|
36 | + ); |
|
37 | + |
|
38 | + self::$createdGroups[] = $createdAddressBookGroup; |
|
39 | + |
|
40 | + $createParameters= [ |
|
41 | + 'group_name' => 'All Group', |
|
42 | + 'group_color' => '92e1c0', |
|
43 | + 'filter' => [ |
|
44 | + 'condition' => 'AND', |
|
45 | + 'rules' => [[ |
|
46 | + 'id' => 'address_1', |
|
47 | + 'field' => 'address_1', |
|
48 | + 'operator' => 'not_equal', |
|
49 | + 'value' => 'qwerty123456' |
|
50 | + ]] |
|
51 | + ] |
|
52 | + ]; |
|
53 | + |
|
54 | + $createdAddressBookGroup = AddressBookGroup::fromArray( |
|
55 | + $abg->createAddressBookGroup($createParameters) |
|
56 | + ); |
|
57 | + |
|
58 | + self::$createdGroups[] = $createdAddressBookGroup; |
|
59 | + } |
|
60 | + |
|
61 | + public function testFromArray() |
|
62 | + { |
|
63 | + $addressBookGroup = AddressBookGroup::fromArray([ |
|
64 | + 'group_id' => '137F9F99544DB34C160B2B9AF8FC6A12', |
|
65 | + 'group_name' => 'Ocassion example', |
|
66 | + 'group_color' => '92e1c0', |
|
67 | + 'group_icon' => 'emoji-pushpin', |
|
68 | + 'member_id' => 444333, |
|
69 | + 'filter' => [ |
|
70 | + 'condition' => 'AND', |
|
71 | + 'rules' => [ |
|
72 | + [ |
|
73 | + 'id' => 'custom_data.occasion', |
|
74 | + 'field' => 'custom_data.occasion', |
|
75 | + 'operator' => 'equal', |
|
76 | + 'value' => '100' |
|
77 | + ]] |
|
78 | + ] |
|
79 | + ]); |
|
80 | + |
|
81 | + $this->assertEquals('137F9F99544DB34C160B2B9AF8FC6A12', $addressBookGroup->group_id); |
|
82 | + $this->assertEquals('Ocassion example', $addressBookGroup->group_name); |
|
83 | + $this->assertEquals('92e1c0', $addressBookGroup->group_color); |
|
84 | + $this->assertEquals('emoji-pushpin', $addressBookGroup->group_icon); |
|
85 | + $this->assertEquals(444333, $addressBookGroup->member_id); |
|
86 | + $this->assertEquals([ |
|
87 | + 'condition' => 'AND', |
|
88 | + 'rules' => [ |
|
89 | + [ |
|
90 | + 'id' => 'custom_data.occasion', |
|
91 | + 'field' => 'custom_data.occasion', |
|
92 | + 'operator' => 'equal', |
|
93 | + 'value' => '100' |
|
94 | + ]] |
|
95 | + ], $addressBookGroup->filter); |
|
96 | + } |
|
97 | + |
|
98 | + public function testGetAddressBookGroup() |
|
99 | + { |
|
100 | + $groupId = self::$createdGroups[0]->group_id; |
|
101 | + |
|
102 | + $abg = new AddressBookGroup(); |
|
103 | + |
|
104 | + $result = AddressBookGroup::fromArray( |
|
105 | + $abg->getAddressBookGroup(['group_id' => $groupId]) |
|
106 | + ); |
|
107 | + |
|
108 | + $this->assertNotNull($result); |
|
109 | + $this->assertContainsOnlyInstancesOf(AddressBookGroup::class, [$result]); |
|
110 | + } |
|
111 | + |
|
112 | + public function testUpdateAddressBookGroup() |
|
113 | + { |
|
114 | + $groupId = self::$createdGroups[0]->group_id; |
|
115 | + |
|
116 | + $updateParameters= [ |
|
117 | + 'group_id' => $groupId, |
|
118 | + 'group_color' => '7bd148' |
|
119 | + ]; |
|
120 | + |
|
121 | + $result = AddressBookGroup::fromArray( |
|
122 | + AddressBookGroup::updateAddressBookGroup($updateParameters) |
|
123 | + ); |
|
124 | + |
|
125 | + $this->assertNotNull($result); |
|
126 | + $this->assertContainsOnlyInstancesOf(AddressBookGroup::class, [$result]); |
|
127 | + $this->assertEquals('7bd148', $result->group_color); |
|
128 | + } |
|
129 | + |
|
130 | + public function testRemoveAddressBookGroup() |
|
131 | + { |
|
132 | + $groupId = end(self::$createdGroups)->group_id; |
|
133 | + |
|
134 | + $removeParameters= [ |
|
135 | + 'group_id' => $groupId |
|
136 | + ]; |
|
137 | + |
|
138 | + $result = AddressBookGroup::removeAddressBookGroup($removeParameters); |
|
139 | + |
|
140 | + $this->assertNotNull($result); |
|
141 | + $this->assertTrue(isset($result['status'])); |
|
142 | + $this->assertTrue($result['status']); |
|
143 | + |
|
144 | + self::$createdGroups[] = array_pop(self::$createdGroups); |
|
145 | + } |
|
146 | + |
|
147 | + public function testCreateAddressBookGroup() |
|
148 | + { |
|
149 | + $createParameters= [ |
|
150 | + 'group_name' => 'All Group', |
|
151 | + 'group_color' => '92e2cd', |
|
152 | + 'filter' => [ |
|
153 | + 'condition' => 'AND', |
|
154 | + 'rules' => [[ |
|
155 | + 'id' => 'address_1', |
|
156 | + 'field' => 'address_1', |
|
157 | + 'operator' => 'not_equal', |
|
158 | + 'value' => 'qwerty654321' |
|
159 | + ]] |
|
160 | + ] |
|
161 | + ]; |
|
162 | + |
|
163 | + $createdAddressBookGroup = AddressBookGroup::fromArray( |
|
164 | + AddressBookGroup::createAddressBookGroup($createParameters) |
|
165 | + ); |
|
166 | + |
|
167 | + $this->assertNotNull($createdAddressBookGroup); |
|
168 | + $this->assertContainsOnlyInstancesOf(AddressBookGroup::class, [$createdAddressBookGroup]); |
|
169 | + $this->assertEquals('92e2cd', $createdAddressBookGroup->group_color); |
|
170 | + |
|
171 | + self::$createdGroups[] = $createdAddressBookGroup; |
|
172 | + } |
|
173 | + |
|
174 | + public function testSearchAddressBookGroups() |
|
175 | + { |
|
176 | + $searchParameters = [ |
|
177 | + 'fields' => ['address_id', 'address_1', 'address_group'], |
|
178 | + 'limit' => 10, |
|
179 | + 'offset' => 0, |
|
180 | + 'filter' => [ |
|
181 | + 'query' => "Louisville", |
|
182 | + "display" => "all" |
|
183 | + ] |
|
184 | + ]; |
|
185 | + |
|
186 | + $addressBookGroups = SearchResponse::fromArray( |
|
187 | + AddressBookGroup::searchAddressBookGroups($searchParameters) |
|
188 | + ); |
|
189 | + |
|
190 | + $this->assertNotNull($addressBookGroups); |
|
191 | + $this->assertTrue(sizeof($addressBookGroups->fields)==3); |
|
192 | + $this->assertContains('address_id', $addressBookGroups->fields); |
|
193 | + $this->assertContains('address_1', $addressBookGroups->fields); |
|
194 | + $this->assertContains('address_group', $addressBookGroups->fields); |
|
195 | + |
|
196 | + $this->assertNotNull($addressBookGroups->results); |
|
197 | + |
|
198 | + if (sizeof($addressBookGroups->results)>0) { |
|
199 | + $this->assertContains('Louisville', implode(", ", $addressBookGroups->results[0])); |
|
200 | + } |
|
201 | + } |
|
202 | + |
|
203 | + public function testGetAddressBookContactsByGroup() |
|
204 | + { |
|
205 | + //$this->markTestSkipped('must be revisited.'); |
|
206 | + |
|
207 | + $groupId = self::$createdGroups[0]->group_id; |
|
208 | + |
|
209 | + $searchParameters = [ |
|
210 | + 'fields' => ['address_id'], |
|
211 | + 'group_id' => $groupId, |
|
212 | + ]; |
|
213 | + |
|
214 | + $result = AddressBookGroup::getAddressBookContactsByGroup($searchParameters); |
|
215 | + |
|
216 | + $this->assertNotNull($result); |
|
217 | + $this->assertTrue(isset($result['total'])); |
|
218 | + $this->assertTrue(isset($result['results'])); |
|
219 | + $this->assertTrue(is_array($result['results'])); |
|
220 | + } |
|
221 | + |
|
222 | + public function testGetAddressBookGroups() |
|
223 | + { |
|
224 | + $addressBookGroupParameters = [ |
|
225 | + 'limit' => 20, |
|
226 | + 'offset' => 0, |
|
227 | + ]; |
|
228 | + |
|
229 | + $addressBookGroups = AddressBookGroup::getAddressBookGroups($addressBookGroupParameters); |
|
230 | + |
|
231 | + $this->assertNotNull($addressBookGroups); |
|
232 | + |
|
233 | + $firstGroup = AddressBookGroup::fromArray( |
|
234 | + $addressBookGroups[0] |
|
235 | + ); |
|
236 | + |
|
237 | + $this->assertTrue(sizeof($addressBookGroups)>0); |
|
238 | + $this->assertContainsOnlyInstancesOf(AddressBookGroup::class, [$firstGroup]); |
|
239 | + } |
|
240 | + |
|
241 | + public function testgGetRandomAddressBookGroup() |
|
242 | + { |
|
243 | + $addressBookGroupParameters = [ |
|
244 | + 'limit' => 20, |
|
245 | + 'offset' => 0, |
|
246 | + ]; |
|
247 | + |
|
248 | + $randomGroup = AddressBookGroup::fromArray( |
|
249 | + AddressBookGroup::getRandomAddressBookGroup($addressBookGroupParameters) |
|
250 | + ); |
|
251 | + |
|
252 | + $this->assertNotNull($randomGroup); |
|
253 | + $this->assertContainsOnlyInstancesOf(AddressBookGroup::class, [$randomGroup]); |
|
254 | + } |
|
255 | + |
|
256 | + public function testGetAddressBookGroupIdByName() |
|
257 | + { |
|
258 | + $firstGroup = self::$createdGroups[0]; |
|
259 | + |
|
260 | + $groupIds = AddressBookGroup::getAddressBookGroupIdByName($firstGroup->group_name); |
|
261 | + |
|
262 | + $this->assertNotNull($groupIds); |
|
263 | + $this->assertTrue(in_array($firstGroup->group_id, $groupIds)); |
|
264 | + } |
|
265 | + |
|
266 | + public static function tearDownAfterClass() |
|
267 | + { |
|
268 | + foreach (self::$createdGroups as $createdGroup) { |
|
269 | + $groupId = $createdGroup->group_id; |
|
270 | + |
|
271 | + $removeParameters= [ |
|
272 | + 'group_id' => $groupId |
|
273 | + ]; |
|
274 | + |
|
275 | + $result = AddressBookGroup::removeAddressBookGroup($removeParameters); |
|
276 | + |
|
277 | + if ($result!=null && isset($result['status']) && isset($result['status'])) { |
|
278 | + echo "The address book group ".$groupId." removed successfully <br>"; |
|
279 | + } else { |
|
280 | + echo "Cannot remove the address book group ".$groupId."<br>"; |
|
281 | + } |
|
282 | + } |
|
283 | + } |
|
284 | 284 | } |
@@ -14,205 +14,205 @@ |
||
14 | 14 | |
15 | 15 | final class PodWorkflowsTests extends \PHPUnit\Framework\TestCase |
16 | 16 | { |
17 | - public static ?string $created_guid = null; |
|
18 | - |
|
19 | - public static function setUpBeforeClass() : void |
|
20 | - { |
|
21 | - Route4Me::setApiKey(Constants::API_KEY); |
|
22 | - } |
|
23 | - |
|
24 | - public function testOptionCanBeCreateEmpty() : void |
|
25 | - { |
|
26 | - $this->assertInstanceOf(Option::class, new Option()); |
|
27 | - } |
|
28 | - |
|
29 | - public function testOptionCanBeCreateFromArray() : void |
|
30 | - { |
|
31 | - $this->assertInstanceOf(Option::class, new Option([ |
|
32 | - 'name' => '1', |
|
33 | - 'value' => '2' |
|
34 | - ])); |
|
35 | - } |
|
36 | - |
|
37 | - public function testActionCanBeCreateEmpty() : void |
|
38 | - { |
|
39 | - $this->assertInstanceOf(Action::class, new Action()); |
|
40 | - } |
|
41 | - |
|
42 | - public function testActionCanBeCreateFromArray() : void |
|
43 | - { |
|
44 | - $this->assertInstanceOf(Action::class, new Action([ |
|
45 | - 'title' => 'ti', |
|
46 | - 'type' => 'ty', |
|
47 | - 'required' => false, |
|
48 | - 'options' => [ |
|
49 | - [ |
|
50 | - 'name' => '2', |
|
51 | - 'value' => '3' |
|
52 | - ], [ |
|
53 | - 'name' => '4', |
|
54 | - 'value' => '5' |
|
55 | - ] |
|
56 | - ] |
|
57 | - ])); |
|
58 | - } |
|
59 | - |
|
60 | - public function testResponsePodWorkflowCanBeCreateEmpty() : void |
|
61 | - { |
|
62 | - $this->assertInstanceOf(ResponsePodWorkflow::class, new ResponsePodWorkflow()); |
|
63 | - } |
|
64 | - |
|
65 | - public function testResponsePodWorkflowBeCreateFromArray() : void |
|
66 | - { |
|
67 | - $this->assertInstanceOf(ResponsePodWorkflow::class, new ResponsePodWorkflow([ |
|
68 | - 'workflow_guid' => '1', |
|
69 | - 'workflow_id' => '2', |
|
70 | - 'root_member_id' => 3, |
|
71 | - 'is_enabled' => false, |
|
72 | - 'is_default' => false, |
|
73 | - 'title' => '4', |
|
74 | - 'done_actions' => [ |
|
75 | - [ |
|
76 | - 'title' => 'da_ti1', |
|
77 | - 'type' => 'da_ty1', |
|
78 | - 'required' => false, |
|
79 | - 'options' => [ |
|
80 | - [ |
|
81 | - 'name' => 'da_21', |
|
82 | - 'value' => 'da_31' |
|
83 | - ], [ |
|
84 | - 'name' => 'da_41', |
|
85 | - 'value' => 'da_51' |
|
86 | - ] |
|
87 | - ] |
|
88 | - ], [ |
|
89 | - 'title' => 'da_ti2', |
|
90 | - 'type' => 'da_ty2', |
|
91 | - 'required' => false, |
|
92 | - 'options' => [ |
|
93 | - [ |
|
94 | - 'name' => 'da_22', |
|
95 | - 'value' => 'da_32' |
|
96 | - ], [ |
|
97 | - 'name' => 'da_42', |
|
98 | - 'value' => 'da_52' |
|
99 | - ] |
|
100 | - ] |
|
101 | - ] |
|
102 | - ], |
|
103 | - 'failed_actions' => [[ |
|
104 | - 'title' => 'fa_ti', |
|
105 | - 'type' => 'fa_ty', |
|
106 | - 'required' => false, |
|
107 | - 'options' => [ |
|
108 | - [ |
|
109 | - 'name' => 'fa_2', |
|
110 | - 'value' => 'fa_3' |
|
111 | - ], [ |
|
112 | - 'name' => 'fa_4', |
|
113 | - 'value' => 'fa_5' |
|
114 | - ] |
|
115 | - ] |
|
116 | - ]], |
|
117 | - ])); |
|
118 | - } |
|
119 | - |
|
120 | - public function testPodWorkflowsCanBeCreateEmpty() : void |
|
121 | - { |
|
122 | - $this->assertInstanceOf(PodWorkflows::class, new PodWorkflows()); |
|
123 | - } |
|
124 | - |
|
125 | - public function testCreateMustReturnResponsePodWorkflow() : void |
|
126 | - { |
|
127 | - $pod_workflows = new PodWorkflows(); |
|
128 | - $res_pod = $pod_workflows->createPodWorkflow([ |
|
129 | - 'workflow_id' => 'workflow_super_ID', |
|
130 | - 'is_enabled' => false, |
|
131 | - 'is_default' => false, |
|
132 | - 'title' => 'Super title from 15', |
|
133 | - 'done_actions' => [[ |
|
134 | - 'title' => 'Signee Name', |
|
135 | - 'type' => 'signeeName', |
|
136 | - 'required' => true |
|
137 | - ]], |
|
138 | - 'failed_actions' => [[ |
|
139 | - 'title' => 'Signee Name Failed', |
|
140 | - 'type' => 'signeeName', |
|
141 | - 'required' => false |
|
142 | - ]] |
|
143 | - ]); |
|
144 | - |
|
145 | - $this->assertInstanceOf(ResponsePodWorkflow::class, $res_pod); |
|
146 | - $this->assertNotNull($res_pod->workflow_guid); |
|
147 | - $this->assertEquals($res_pod->title, 'Super title from 15'); |
|
17 | + public static ?string $created_guid = null; |
|
18 | + |
|
19 | + public static function setUpBeforeClass() : void |
|
20 | + { |
|
21 | + Route4Me::setApiKey(Constants::API_KEY); |
|
22 | + } |
|
23 | + |
|
24 | + public function testOptionCanBeCreateEmpty() : void |
|
25 | + { |
|
26 | + $this->assertInstanceOf(Option::class, new Option()); |
|
27 | + } |
|
28 | + |
|
29 | + public function testOptionCanBeCreateFromArray() : void |
|
30 | + { |
|
31 | + $this->assertInstanceOf(Option::class, new Option([ |
|
32 | + 'name' => '1', |
|
33 | + 'value' => '2' |
|
34 | + ])); |
|
35 | + } |
|
36 | + |
|
37 | + public function testActionCanBeCreateEmpty() : void |
|
38 | + { |
|
39 | + $this->assertInstanceOf(Action::class, new Action()); |
|
40 | + } |
|
41 | + |
|
42 | + public function testActionCanBeCreateFromArray() : void |
|
43 | + { |
|
44 | + $this->assertInstanceOf(Action::class, new Action([ |
|
45 | + 'title' => 'ti', |
|
46 | + 'type' => 'ty', |
|
47 | + 'required' => false, |
|
48 | + 'options' => [ |
|
49 | + [ |
|
50 | + 'name' => '2', |
|
51 | + 'value' => '3' |
|
52 | + ], [ |
|
53 | + 'name' => '4', |
|
54 | + 'value' => '5' |
|
55 | + ] |
|
56 | + ] |
|
57 | + ])); |
|
58 | + } |
|
59 | + |
|
60 | + public function testResponsePodWorkflowCanBeCreateEmpty() : void |
|
61 | + { |
|
62 | + $this->assertInstanceOf(ResponsePodWorkflow::class, new ResponsePodWorkflow()); |
|
63 | + } |
|
64 | + |
|
65 | + public function testResponsePodWorkflowBeCreateFromArray() : void |
|
66 | + { |
|
67 | + $this->assertInstanceOf(ResponsePodWorkflow::class, new ResponsePodWorkflow([ |
|
68 | + 'workflow_guid' => '1', |
|
69 | + 'workflow_id' => '2', |
|
70 | + 'root_member_id' => 3, |
|
71 | + 'is_enabled' => false, |
|
72 | + 'is_default' => false, |
|
73 | + 'title' => '4', |
|
74 | + 'done_actions' => [ |
|
75 | + [ |
|
76 | + 'title' => 'da_ti1', |
|
77 | + 'type' => 'da_ty1', |
|
78 | + 'required' => false, |
|
79 | + 'options' => [ |
|
80 | + [ |
|
81 | + 'name' => 'da_21', |
|
82 | + 'value' => 'da_31' |
|
83 | + ], [ |
|
84 | + 'name' => 'da_41', |
|
85 | + 'value' => 'da_51' |
|
86 | + ] |
|
87 | + ] |
|
88 | + ], [ |
|
89 | + 'title' => 'da_ti2', |
|
90 | + 'type' => 'da_ty2', |
|
91 | + 'required' => false, |
|
92 | + 'options' => [ |
|
93 | + [ |
|
94 | + 'name' => 'da_22', |
|
95 | + 'value' => 'da_32' |
|
96 | + ], [ |
|
97 | + 'name' => 'da_42', |
|
98 | + 'value' => 'da_52' |
|
99 | + ] |
|
100 | + ] |
|
101 | + ] |
|
102 | + ], |
|
103 | + 'failed_actions' => [[ |
|
104 | + 'title' => 'fa_ti', |
|
105 | + 'type' => 'fa_ty', |
|
106 | + 'required' => false, |
|
107 | + 'options' => [ |
|
108 | + [ |
|
109 | + 'name' => 'fa_2', |
|
110 | + 'value' => 'fa_3' |
|
111 | + ], [ |
|
112 | + 'name' => 'fa_4', |
|
113 | + 'value' => 'fa_5' |
|
114 | + ] |
|
115 | + ] |
|
116 | + ]], |
|
117 | + ])); |
|
118 | + } |
|
119 | + |
|
120 | + public function testPodWorkflowsCanBeCreateEmpty() : void |
|
121 | + { |
|
122 | + $this->assertInstanceOf(PodWorkflows::class, new PodWorkflows()); |
|
123 | + } |
|
124 | + |
|
125 | + public function testCreateMustReturnResponsePodWorkflow() : void |
|
126 | + { |
|
127 | + $pod_workflows = new PodWorkflows(); |
|
128 | + $res_pod = $pod_workflows->createPodWorkflow([ |
|
129 | + 'workflow_id' => 'workflow_super_ID', |
|
130 | + 'is_enabled' => false, |
|
131 | + 'is_default' => false, |
|
132 | + 'title' => 'Super title from 15', |
|
133 | + 'done_actions' => [[ |
|
134 | + 'title' => 'Signee Name', |
|
135 | + 'type' => 'signeeName', |
|
136 | + 'required' => true |
|
137 | + ]], |
|
138 | + 'failed_actions' => [[ |
|
139 | + 'title' => 'Signee Name Failed', |
|
140 | + 'type' => 'signeeName', |
|
141 | + 'required' => false |
|
142 | + ]] |
|
143 | + ]); |
|
144 | + |
|
145 | + $this->assertInstanceOf(ResponsePodWorkflow::class, $res_pod); |
|
146 | + $this->assertNotNull($res_pod->workflow_guid); |
|
147 | + $this->assertEquals($res_pod->title, 'Super title from 15'); |
|
148 | 148 | |
149 | - self::$created_guid = $res_pod->workflow_guid; |
|
150 | - } |
|
151 | - |
|
152 | - public function testGetAllPodWorkflowsMustReturnResponsePodWorkflows() : void |
|
153 | - { |
|
154 | - $pod_workflows = new PodWorkflows(); |
|
155 | - $result = $pod_workflows->getAllPodWorkflows([ |
|
156 | - 'search_query' => 'Super title from 15', |
|
157 | - 'order_by' => [['last_updated_timestamp', 'asc']], |
|
158 | - 'per_page' => 5 |
|
159 | - ]); |
|
160 | - |
|
161 | - $this->assertInstanceOf(ResponsePodWorkflows::class, $result); |
|
162 | - $this->assertNotNull($result->next_page_cursor); |
|
163 | - } |
|
164 | - |
|
165 | - public function testGetPodWorkflowMustReturnResponsePodWorkflow() : void |
|
166 | - { |
|
167 | - $pod_workflows = new PodWorkflows(); |
|
168 | - $res_pod = $pod_workflows->getPodWorkflow(self::$created_guid); |
|
169 | - |
|
170 | - $this->assertInstanceOf(ResponsePodWorkflow::class, $res_pod); |
|
171 | - $this->assertNotNull($res_pod->workflow_guid); |
|
172 | - $this->assertEquals($res_pod->workflow_guid, self::$created_guid); |
|
173 | - } |
|
174 | - |
|
175 | - public function testupdatePodWorkflowMustReturnUpdatedResponsePodWorkflow() : void |
|
176 | - { |
|
177 | - $pod_workflows = new PodWorkflows(); |
|
178 | - $res_pod = $pod_workflows->updatePodWorkflow(self::$created_guid, [ |
|
179 | - 'workflow_id' => 'workflow_super_ID', |
|
180 | - 'is_enabled' => false, |
|
181 | - 'is_default' => false, |
|
182 | - 'title' => 'A new Super title from 15', |
|
183 | - 'done_actions' => [[ |
|
184 | - 'title' => 'Signee Name', |
|
185 | - 'type' => 'signeeName', |
|
186 | - 'required' => true |
|
187 | - ]], |
|
188 | - 'failed_actions' => [[ |
|
189 | - 'title' => 'Signee Name Failed', |
|
190 | - 'type' => 'signeeName', |
|
191 | - 'required' => false |
|
192 | - ]] |
|
193 | - ]); |
|
194 | - |
|
195 | - $this->assertInstanceOf(ResponsePodWorkflow::class, $res_pod); |
|
196 | - $this->assertNotNull($res_pod->title); |
|
197 | - $this->assertEquals($res_pod->title, 'A new Super title from 15'); |
|
198 | - } |
|
199 | - |
|
200 | - public function testDeleteMustReturnDeletedResponsePodWorkflow() : void |
|
201 | - { |
|
202 | - $pod_workflows = new PodWorkflows(); |
|
203 | - $result = $pod_workflows->deletePodWorkflow(self::$created_guid); |
|
204 | - |
|
205 | - $this->assertNotNull($result); |
|
206 | - self::$created_guid = null; |
|
207 | - } |
|
208 | - |
|
209 | - public static function tearDownAfterClass() : void |
|
210 | - { |
|
211 | - sleep(5); |
|
212 | - |
|
213 | - if (self::$created_guid !== null) { |
|
214 | - $pod_workflows = new PodWorkflows(); |
|
215 | - $pod_workflows->deletePodWorkflow(self::$created_guid); |
|
216 | - } |
|
217 | - } |
|
149 | + self::$created_guid = $res_pod->workflow_guid; |
|
150 | + } |
|
151 | + |
|
152 | + public function testGetAllPodWorkflowsMustReturnResponsePodWorkflows() : void |
|
153 | + { |
|
154 | + $pod_workflows = new PodWorkflows(); |
|
155 | + $result = $pod_workflows->getAllPodWorkflows([ |
|
156 | + 'search_query' => 'Super title from 15', |
|
157 | + 'order_by' => [['last_updated_timestamp', 'asc']], |
|
158 | + 'per_page' => 5 |
|
159 | + ]); |
|
160 | + |
|
161 | + $this->assertInstanceOf(ResponsePodWorkflows::class, $result); |
|
162 | + $this->assertNotNull($result->next_page_cursor); |
|
163 | + } |
|
164 | + |
|
165 | + public function testGetPodWorkflowMustReturnResponsePodWorkflow() : void |
|
166 | + { |
|
167 | + $pod_workflows = new PodWorkflows(); |
|
168 | + $res_pod = $pod_workflows->getPodWorkflow(self::$created_guid); |
|
169 | + |
|
170 | + $this->assertInstanceOf(ResponsePodWorkflow::class, $res_pod); |
|
171 | + $this->assertNotNull($res_pod->workflow_guid); |
|
172 | + $this->assertEquals($res_pod->workflow_guid, self::$created_guid); |
|
173 | + } |
|
174 | + |
|
175 | + public function testupdatePodWorkflowMustReturnUpdatedResponsePodWorkflow() : void |
|
176 | + { |
|
177 | + $pod_workflows = new PodWorkflows(); |
|
178 | + $res_pod = $pod_workflows->updatePodWorkflow(self::$created_guid, [ |
|
179 | + 'workflow_id' => 'workflow_super_ID', |
|
180 | + 'is_enabled' => false, |
|
181 | + 'is_default' => false, |
|
182 | + 'title' => 'A new Super title from 15', |
|
183 | + 'done_actions' => [[ |
|
184 | + 'title' => 'Signee Name', |
|
185 | + 'type' => 'signeeName', |
|
186 | + 'required' => true |
|
187 | + ]], |
|
188 | + 'failed_actions' => [[ |
|
189 | + 'title' => 'Signee Name Failed', |
|
190 | + 'type' => 'signeeName', |
|
191 | + 'required' => false |
|
192 | + ]] |
|
193 | + ]); |
|
194 | + |
|
195 | + $this->assertInstanceOf(ResponsePodWorkflow::class, $res_pod); |
|
196 | + $this->assertNotNull($res_pod->title); |
|
197 | + $this->assertEquals($res_pod->title, 'A new Super title from 15'); |
|
198 | + } |
|
199 | + |
|
200 | + public function testDeleteMustReturnDeletedResponsePodWorkflow() : void |
|
201 | + { |
|
202 | + $pod_workflows = new PodWorkflows(); |
|
203 | + $result = $pod_workflows->deletePodWorkflow(self::$created_guid); |
|
204 | + |
|
205 | + $this->assertNotNull($result); |
|
206 | + self::$created_guid = null; |
|
207 | + } |
|
208 | + |
|
209 | + public static function tearDownAfterClass() : void |
|
210 | + { |
|
211 | + sleep(5); |
|
212 | + |
|
213 | + if (self::$created_guid !== null) { |
|
214 | + $pod_workflows = new PodWorkflows(); |
|
215 | + $pod_workflows->deletePodWorkflow(self::$created_guid); |
|
216 | + } |
|
217 | + } |
|
218 | 218 | } |
@@ -18,137 +18,137 @@ |
||
18 | 18 | */ |
19 | 19 | class PodWorkflows extends Common |
20 | 20 | { |
21 | - public function __construct() |
|
22 | - { |
|
23 | - Route4Me::setBaseUrl(''); |
|
24 | - } |
|
21 | + public function __construct() |
|
22 | + { |
|
23 | + Route4Me::setBaseUrl(''); |
|
24 | + } |
|
25 | 25 | |
26 | - /** |
|
27 | - * Create a new PodWorkflow by sending the corresponding data. |
|
28 | - * |
|
29 | - * @since 1.2.10 |
|
30 | - * |
|
31 | - * @param array $params |
|
32 | - * string workflow_id - PodWorkflow ID, |
|
33 | - * int [root_member_id] - Member ID, |
|
34 | - * bool is_enabled - If true, the PodWorkflow is enabled, |
|
35 | - * bool is_default - If true, the PodWorkflow is default, |
|
36 | - * string title - The title of PodWorkflow, |
|
37 | - * Action[] [done_actions] - Array of done actions, |
|
38 | - * Action[] [failed_actions] - Array of failed actions, |
|
39 | - * @return ResponsePodWorkflow |
|
40 | - * @throws Exception\ApiError |
|
41 | - */ |
|
42 | - public function createPodWorkflow(array $params) : ResponsePodWorkflow |
|
43 | - { |
|
44 | - $allBodyFields = ['workflow_id', 'root_member_id', 'is_enabled', 'is_default', |
|
45 | - 'title', 'done_actions', 'failed_actions']; |
|
26 | + /** |
|
27 | + * Create a new PodWorkflow by sending the corresponding data. |
|
28 | + * |
|
29 | + * @since 1.2.10 |
|
30 | + * |
|
31 | + * @param array $params |
|
32 | + * string workflow_id - PodWorkflow ID, |
|
33 | + * int [root_member_id] - Member ID, |
|
34 | + * bool is_enabled - If true, the PodWorkflow is enabled, |
|
35 | + * bool is_default - If true, the PodWorkflow is default, |
|
36 | + * string title - The title of PodWorkflow, |
|
37 | + * Action[] [done_actions] - Array of done actions, |
|
38 | + * Action[] [failed_actions] - Array of failed actions, |
|
39 | + * @return ResponsePodWorkflow |
|
40 | + * @throws Exception\ApiError |
|
41 | + */ |
|
42 | + public function createPodWorkflow(array $params) : ResponsePodWorkflow |
|
43 | + { |
|
44 | + $allBodyFields = ['workflow_id', 'root_member_id', 'is_enabled', 'is_default', |
|
45 | + 'title', 'done_actions', 'failed_actions']; |
|
46 | 46 | |
47 | - return $this->toResponsePodWorkflow(Route4Me::makeRequst([ |
|
48 | - 'url' => Endpoint::POD_WORKFLOW, |
|
49 | - 'method' => 'POST', |
|
50 | - 'HTTPHEADER' => 'Content-Type: application/json', |
|
51 | - 'body' => Route4Me::generateRequestParameters($allBodyFields, $params) |
|
52 | - ])); |
|
53 | - } |
|
47 | + return $this->toResponsePodWorkflow(Route4Me::makeRequst([ |
|
48 | + 'url' => Endpoint::POD_WORKFLOW, |
|
49 | + 'method' => 'POST', |
|
50 | + 'HTTPHEADER' => 'Content-Type: application/json', |
|
51 | + 'body' => Route4Me::generateRequestParameters($allBodyFields, $params) |
|
52 | + ])); |
|
53 | + } |
|
54 | 54 | |
55 | - /** |
|
56 | - * Get the list of all PodWorkflow filtered by specifying the corresponding query parameters. |
|
57 | - * |
|
58 | - * @since 1.2.10 |
|
59 | - * |
|
60 | - * @param array [$params] |
|
61 | - * int [per_page] - Number of PodWorkflows per page, |
|
62 | - * string [cursor] |
|
63 | - * string [search_query] - Search in the PodWorkflows by the corresponding query phrase. |
|
64 | - * array [order_by] - Array of pairs PodWorkflow field and its sorting direction, |
|
65 | - * e.g. [["title", "asc"], ["last_updated_timestamp", "desc"]] |
|
66 | - * @return ResponsePodWorkflows |
|
67 | - * @throws Exception\ApiError |
|
68 | - */ |
|
69 | - public function getAllPodWorkflows(?array $params = null) : ResponsePodWorkflows |
|
70 | - { |
|
71 | - $allBodyFields = ['per_page', 'cursor', 'search_query', 'order_by']; |
|
55 | + /** |
|
56 | + * Get the list of all PodWorkflow filtered by specifying the corresponding query parameters. |
|
57 | + * |
|
58 | + * @since 1.2.10 |
|
59 | + * |
|
60 | + * @param array [$params] |
|
61 | + * int [per_page] - Number of PodWorkflows per page, |
|
62 | + * string [cursor] |
|
63 | + * string [search_query] - Search in the PodWorkflows by the corresponding query phrase. |
|
64 | + * array [order_by] - Array of pairs PodWorkflow field and its sorting direction, |
|
65 | + * e.g. [["title", "asc"], ["last_updated_timestamp", "desc"]] |
|
66 | + * @return ResponsePodWorkflows |
|
67 | + * @throws Exception\ApiError |
|
68 | + */ |
|
69 | + public function getAllPodWorkflows(?array $params = null) : ResponsePodWorkflows |
|
70 | + { |
|
71 | + $allBodyFields = ['per_page', 'cursor', 'search_query', 'order_by']; |
|
72 | 72 | |
73 | - $result = Route4Me::makeRequst([ |
|
74 | - 'url' => Endpoint::POD_WORKFLOW, |
|
75 | - 'method' => 'GET', |
|
76 | - 'query' => Route4Me::generateRequestParameters($allBodyFields, $params) |
|
77 | - ]); |
|
73 | + $result = Route4Me::makeRequst([ |
|
74 | + 'url' => Endpoint::POD_WORKFLOW, |
|
75 | + 'method' => 'GET', |
|
76 | + 'query' => Route4Me::generateRequestParameters($allBodyFields, $params) |
|
77 | + ]); |
|
78 | 78 | |
79 | - if (is_array($result) && isset($result['data'])) { |
|
80 | - return new ResponsePodWorkflows($result); |
|
81 | - } |
|
82 | - throw new ApiError('Can not convert result to ResponsePodWorkflows object.'); |
|
83 | - } |
|
79 | + if (is_array($result) && isset($result['data'])) { |
|
80 | + return new ResponsePodWorkflows($result); |
|
81 | + } |
|
82 | + throw new ApiError('Can not convert result to ResponsePodWorkflows object.'); |
|
83 | + } |
|
84 | 84 | |
85 | - /** |
|
86 | - * Get the PodWorkflow by specifying the PodWorkflow GUID. |
|
87 | - * |
|
88 | - * @since 1.2.10 |
|
89 | - * |
|
90 | - * @param string $workflow_guid - PodWorkflow GUID. |
|
91 | - * @return ResponsePodWorkflow |
|
92 | - * @throws Exception\ApiError |
|
93 | - */ |
|
94 | - public function getPodWorkflow(string $workflow_guid) : ResponsePodWorkflow |
|
95 | - { |
|
96 | - return $this->toResponsePodWorkflow(Route4Me::makeRequst([ |
|
97 | - 'url' => Endpoint::POD_WORKFLOW . '/' . $workflow_guid, |
|
98 | - 'method' => 'GET' |
|
99 | - ])); |
|
100 | - } |
|
85 | + /** |
|
86 | + * Get the PodWorkflow by specifying the PodWorkflow GUID. |
|
87 | + * |
|
88 | + * @since 1.2.10 |
|
89 | + * |
|
90 | + * @param string $workflow_guid - PodWorkflow GUID. |
|
91 | + * @return ResponsePodWorkflow |
|
92 | + * @throws Exception\ApiError |
|
93 | + */ |
|
94 | + public function getPodWorkflow(string $workflow_guid) : ResponsePodWorkflow |
|
95 | + { |
|
96 | + return $this->toResponsePodWorkflow(Route4Me::makeRequst([ |
|
97 | + 'url' => Endpoint::POD_WORKFLOW . '/' . $workflow_guid, |
|
98 | + 'method' => 'GET' |
|
99 | + ])); |
|
100 | + } |
|
101 | 101 | |
102 | - /** |
|
103 | - * Update the PodWorkflow by specifying the GUID and the corresponding PodWorkflow parameters. |
|
104 | - * |
|
105 | - * @since 1.2.10 |
|
106 | - * |
|
107 | - * @param string $workflow_guid - PodWorkflow GUID. |
|
108 | - * @param array $params - PodWorkflow properties, look for more |
|
109 | - * information in createPodWorkflow |
|
110 | - * @return ResponsePodWorkflow |
|
111 | - * @throws Exception\ApiError |
|
112 | - */ |
|
113 | - public function updatePodWorkflow(string $workflow_guid, array $params) : ResponsePodWorkflow |
|
114 | - { |
|
115 | - $allBodyFields = ['workflow_id', 'root_member_id', 'is_enabled', 'is_default', |
|
116 | - 'title', 'done_actions', 'failed_actions']; |
|
102 | + /** |
|
103 | + * Update the PodWorkflow by specifying the GUID and the corresponding PodWorkflow parameters. |
|
104 | + * |
|
105 | + * @since 1.2.10 |
|
106 | + * |
|
107 | + * @param string $workflow_guid - PodWorkflow GUID. |
|
108 | + * @param array $params - PodWorkflow properties, look for more |
|
109 | + * information in createPodWorkflow |
|
110 | + * @return ResponsePodWorkflow |
|
111 | + * @throws Exception\ApiError |
|
112 | + */ |
|
113 | + public function updatePodWorkflow(string $workflow_guid, array $params) : ResponsePodWorkflow |
|
114 | + { |
|
115 | + $allBodyFields = ['workflow_id', 'root_member_id', 'is_enabled', 'is_default', |
|
116 | + 'title', 'done_actions', 'failed_actions']; |
|
117 | 117 | |
118 | - return $this->toResponsePodWorkflow(Route4Me::makeRequst([ |
|
119 | - 'url' => Endpoint::POD_WORKFLOW . '/' . $workflow_guid, |
|
120 | - 'method' => 'PUT', |
|
121 | - 'HTTPHEADER' => 'Content-Type: application/json', |
|
122 | - 'body' => Route4Me::generateRequestParameters($allBodyFields, $params) |
|
123 | - ])); |
|
124 | - } |
|
118 | + return $this->toResponsePodWorkflow(Route4Me::makeRequst([ |
|
119 | + 'url' => Endpoint::POD_WORKFLOW . '/' . $workflow_guid, |
|
120 | + 'method' => 'PUT', |
|
121 | + 'HTTPHEADER' => 'Content-Type: application/json', |
|
122 | + 'body' => Route4Me::generateRequestParameters($allBodyFields, $params) |
|
123 | + ])); |
|
124 | + } |
|
125 | 125 | |
126 | - /** |
|
127 | - * Delete the PodWorkflow by specifying the GUID. |
|
128 | - * |
|
129 | - * @since 1.2.10 |
|
130 | - * |
|
131 | - * @param string $workflow_guid - PodWorkflow GUID. |
|
132 | - * @return bool |
|
133 | - * @throws Exception\ApiError |
|
134 | - */ |
|
135 | - public function deletePodWorkflow(string $workflow_guid) : bool |
|
136 | - { |
|
137 | - $res = Route4Me::makeRequst([ |
|
138 | - 'url' => Endpoint::POD_WORKFLOW . '/' . $workflow_guid, |
|
139 | - 'method' => 'DELETE' |
|
140 | - ]); |
|
141 | - return isset($res); |
|
142 | - } |
|
126 | + /** |
|
127 | + * Delete the PodWorkflow by specifying the GUID. |
|
128 | + * |
|
129 | + * @since 1.2.10 |
|
130 | + * |
|
131 | + * @param string $workflow_guid - PodWorkflow GUID. |
|
132 | + * @return bool |
|
133 | + * @throws Exception\ApiError |
|
134 | + */ |
|
135 | + public function deletePodWorkflow(string $workflow_guid) : bool |
|
136 | + { |
|
137 | + $res = Route4Me::makeRequst([ |
|
138 | + 'url' => Endpoint::POD_WORKFLOW . '/' . $workflow_guid, |
|
139 | + 'method' => 'DELETE' |
|
140 | + ]); |
|
141 | + return isset($res); |
|
142 | + } |
|
143 | 143 | |
144 | - private function toResponsePodWorkflow($result) : ResponsePodWorkflow |
|
145 | - { |
|
146 | - if (is_array($result) && isset($result['data'])) { |
|
147 | - $data = $result['data']; |
|
148 | - if (is_array($data)) { |
|
149 | - return new ResponsePodWorkflow($data); |
|
150 | - } |
|
151 | - } |
|
152 | - throw new ApiError('Can not convert result to ResponsePodWorkflow object.'); |
|
153 | - } |
|
144 | + private function toResponsePodWorkflow($result) : ResponsePodWorkflow |
|
145 | + { |
|
146 | + if (is_array($result) && isset($result['data'])) { |
|
147 | + $data = $result['data']; |
|
148 | + if (is_array($data)) { |
|
149 | + return new ResponsePodWorkflow($data); |
|
150 | + } |
|
151 | + } |
|
152 | + throw new ApiError('Can not convert result to ResponsePodWorkflow object.'); |
|
153 | + } |
|
154 | 154 | } |
@@ -14,36 +14,36 @@ |
||
14 | 14 | */ |
15 | 15 | class ResponsePodWorkflows extends Common |
16 | 16 | { |
17 | - /** |
|
18 | - * An array of PodWorkflows |
|
19 | - */ |
|
20 | - public ?array $data = null; |
|
17 | + /** |
|
18 | + * An array of PodWorkflows |
|
19 | + */ |
|
20 | + public ?array $data = null; |
|
21 | 21 | |
22 | - /** |
|
23 | - * Name of next page cursor |
|
24 | - */ |
|
25 | - public ?string $next_page_cursor = null; |
|
22 | + /** |
|
23 | + * Name of next page cursor |
|
24 | + */ |
|
25 | + public ?string $next_page_cursor = null; |
|
26 | 26 | |
27 | - /** |
|
28 | - * Total items count |
|
29 | - */ |
|
30 | - public ?int $total_items_count = null; |
|
27 | + /** |
|
28 | + * Total items count |
|
29 | + */ |
|
30 | + public ?int $total_items_count = null; |
|
31 | 31 | |
32 | - public function __construct(?array $params = null) |
|
33 | - { |
|
34 | - if ($params !== null) { |
|
35 | - foreach ($this as $key => $value) { |
|
36 | - if (isset($params[$key])) { |
|
37 | - if ($key === 'data') { |
|
38 | - $this->{$key} = array(); |
|
39 | - foreach ($params[$key] as $pod_wf => $value) { |
|
40 | - array_push($this->{$key}, new ResponsePodWorkflow($value)); |
|
41 | - } |
|
42 | - } else { |
|
43 | - $this->{$key} = $params[$key]; |
|
44 | - } |
|
45 | - } |
|
46 | - } |
|
47 | - } |
|
48 | - } |
|
32 | + public function __construct(?array $params = null) |
|
33 | + { |
|
34 | + if ($params !== null) { |
|
35 | + foreach ($this as $key => $value) { |
|
36 | + if (isset($params[$key])) { |
|
37 | + if ($key === 'data') { |
|
38 | + $this->{$key} = array(); |
|
39 | + foreach ($params[$key] as $pod_wf => $value) { |
|
40 | + array_push($this->{$key}, new ResponsePodWorkflow($value)); |
|
41 | + } |
|
42 | + } else { |
|
43 | + $this->{$key} = $params[$key]; |
|
44 | + } |
|
45 | + } |
|
46 | + } |
|
47 | + } |
|
48 | + } |
|
49 | 49 | } |
@@ -14,66 +14,66 @@ |
||
14 | 14 | */ |
15 | 15 | class ResponsePodWorkflow extends Common |
16 | 16 | { |
17 | - /** |
|
18 | - * PodWorkflow GUID |
|
19 | - */ |
|
20 | - public ?string $workflow_guid = null; |
|
17 | + /** |
|
18 | + * PodWorkflow GUID |
|
19 | + */ |
|
20 | + public ?string $workflow_guid = null; |
|
21 | 21 | |
22 | - /** |
|
23 | - * PodWorkflow ID |
|
24 | - */ |
|
25 | - public ?string $workflow_id = null; |
|
22 | + /** |
|
23 | + * PodWorkflow ID |
|
24 | + */ |
|
25 | + public ?string $workflow_id = null; |
|
26 | 26 | |
27 | - /** |
|
28 | - * Member ID |
|
29 | - */ |
|
30 | - public ?int $root_member_id = null; |
|
27 | + /** |
|
28 | + * Member ID |
|
29 | + */ |
|
30 | + public ?int $root_member_id = null; |
|
31 | 31 | |
32 | - /** |
|
33 | - * If true, the PodWorkflow is enabled |
|
34 | - */ |
|
35 | - public ?bool $is_enabled = null; |
|
32 | + /** |
|
33 | + * If true, the PodWorkflow is enabled |
|
34 | + */ |
|
35 | + public ?bool $is_enabled = null; |
|
36 | 36 | |
37 | - /** |
|
38 | - * If true, the PodWorkflow is default |
|
39 | - */ |
|
40 | - public ?bool $is_default = null; |
|
37 | + /** |
|
38 | + * If true, the PodWorkflow is default |
|
39 | + */ |
|
40 | + public ?bool $is_default = null; |
|
41 | 41 | |
42 | - /** |
|
43 | - * The title of PodWorkflow |
|
44 | - */ |
|
45 | - public ?string $title = null; |
|
42 | + /** |
|
43 | + * The title of PodWorkflow |
|
44 | + */ |
|
45 | + public ?string $title = null; |
|
46 | 46 | |
47 | - /** |
|
48 | - * Done actions as array of Actions |
|
49 | - */ |
|
50 | - public ?array $done_actions = null; |
|
47 | + /** |
|
48 | + * Done actions as array of Actions |
|
49 | + */ |
|
50 | + public ?array $done_actions = null; |
|
51 | 51 | |
52 | - /** |
|
53 | - * Failed actions as array of Actions |
|
54 | - */ |
|
55 | - public ?array $failed_actions = null; |
|
52 | + /** |
|
53 | + * Failed actions as array of Actions |
|
54 | + */ |
|
55 | + public ?array $failed_actions = null; |
|
56 | 56 | |
57 | - /** |
|
58 | - * The Timestamp of last update |
|
59 | - */ |
|
60 | - public ?int $last_updated_timestamp = null; |
|
57 | + /** |
|
58 | + * The Timestamp of last update |
|
59 | + */ |
|
60 | + public ?int $last_updated_timestamp = null; |
|
61 | 61 | |
62 | - public function __construct(?array $params = null) |
|
63 | - { |
|
64 | - if ($params !== null) { |
|
65 | - foreach ($this as $key => $value) { |
|
66 | - if (isset($params[$key])) { |
|
67 | - if ($key === 'done_actions' || $key === 'failed_actions') { |
|
68 | - $this->{$key} = array(); |
|
69 | - foreach ($params[$key] as $action => $value) { |
|
70 | - array_push($this->{$key}, new Action($value)); |
|
71 | - } |
|
72 | - } else { |
|
73 | - $this->{$key} = $params[$key]; |
|
74 | - } |
|
75 | - } |
|
76 | - } |
|
77 | - } |
|
78 | - } |
|
62 | + public function __construct(?array $params = null) |
|
63 | + { |
|
64 | + if ($params !== null) { |
|
65 | + foreach ($this as $key => $value) { |
|
66 | + if (isset($params[$key])) { |
|
67 | + if ($key === 'done_actions' || $key === 'failed_actions') { |
|
68 | + $this->{$key} = array(); |
|
69 | + foreach ($params[$key] as $action => $value) { |
|
70 | + array_push($this->{$key}, new Action($value)); |
|
71 | + } |
|
72 | + } else { |
|
73 | + $this->{$key} = $params[$key]; |
|
74 | + } |
|
75 | + } |
|
76 | + } |
|
77 | + } |
|
78 | + } |
|
79 | 79 | } |
@@ -13,20 +13,20 @@ |
||
13 | 13 | */ |
14 | 14 | class Option extends Common |
15 | 15 | { |
16 | - /** |
|
17 | - * Title of action |
|
18 | - */ |
|
19 | - public ?string $name = null; |
|
16 | + /** |
|
17 | + * Title of action |
|
18 | + */ |
|
19 | + public ?string $name = null; |
|
20 | 20 | |
21 | - /** |
|
22 | - * Type of action |
|
23 | - */ |
|
24 | - public ?string $value = null; |
|
21 | + /** |
|
22 | + * Type of action |
|
23 | + */ |
|
24 | + public ?string $value = null; |
|
25 | 25 | |
26 | - public function __construct(?array $params = null) |
|
27 | - { |
|
28 | - if ($params !== null) { |
|
29 | - $this->fillFromArray($params); |
|
30 | - } |
|
31 | - } |
|
26 | + public function __construct(?array $params = null) |
|
27 | + { |
|
28 | + if ($params !== null) { |
|
29 | + $this->fillFromArray($params); |
|
30 | + } |
|
31 | + } |
|
32 | 32 | } |
@@ -14,41 +14,41 @@ |
||
14 | 14 | */ |
15 | 15 | class Action extends Common |
16 | 16 | { |
17 | - /** |
|
18 | - * Title of action |
|
19 | - */ |
|
20 | - public ?string $title = null; |
|
17 | + /** |
|
18 | + * Title of action |
|
19 | + */ |
|
20 | + public ?string $title = null; |
|
21 | 21 | |
22 | - /** |
|
23 | - * Type of action |
|
24 | - */ |
|
25 | - public ?string $type = null; |
|
22 | + /** |
|
23 | + * Type of action |
|
24 | + */ |
|
25 | + public ?string $type = null; |
|
26 | 26 | |
27 | - /** |
|
28 | - * If true, the action is required |
|
29 | - */ |
|
30 | - public ?bool $required = null; |
|
27 | + /** |
|
28 | + * If true, the action is required |
|
29 | + */ |
|
30 | + public ?bool $required = null; |
|
31 | 31 | |
32 | - /** |
|
33 | - * Options of the action as array of Options |
|
34 | - */ |
|
35 | - public ?array $options = null; |
|
32 | + /** |
|
33 | + * Options of the action as array of Options |
|
34 | + */ |
|
35 | + public ?array $options = null; |
|
36 | 36 | |
37 | - public function __construct(?array $params = null) |
|
38 | - { |
|
39 | - if ($params !== null) { |
|
40 | - foreach ($this as $key => $value) { |
|
41 | - if (isset($params[$key])) { |
|
42 | - if ($key === 'options') { |
|
43 | - $this->{$key} = array(); |
|
44 | - foreach ($params[$key] as $option => $value) { |
|
45 | - array_push($this->{$key}, new Option($value)); |
|
46 | - } |
|
47 | - } else { |
|
48 | - $this->{$key} = $params[$key]; |
|
49 | - } |
|
50 | - } |
|
51 | - } |
|
52 | - } |
|
53 | - } |
|
37 | + public function __construct(?array $params = null) |
|
38 | + { |
|
39 | + if ($params !== null) { |
|
40 | + foreach ($this as $key => $value) { |
|
41 | + if (isset($params[$key])) { |
|
42 | + if ($key === 'options') { |
|
43 | + $this->{$key} = array(); |
|
44 | + foreach ($params[$key] as $option => $value) { |
|
45 | + array_push($this->{$key}, new Option($value)); |
|
46 | + } |
|
47 | + } else { |
|
48 | + $this->{$key} = $params[$key]; |
|
49 | + } |
|
50 | + } |
|
51 | + } |
|
52 | + } |
|
53 | + } |
|
54 | 54 | } |
@@ -7,374 +7,374 @@ |
||
7 | 7 | |
8 | 8 | class Route4Me |
9 | 9 | { |
10 | - public static $apiKey; |
|
11 | - public static $baseUrl = Endpoint::BASE_URL; |
|
12 | - |
|
13 | - public static function setApiKey($apiKey) |
|
14 | - { |
|
15 | - self::$apiKey = $apiKey; |
|
16 | - } |
|
17 | - |
|
18 | - public static function getApiKey() |
|
19 | - { |
|
20 | - return self::$apiKey; |
|
21 | - } |
|
22 | - |
|
23 | - public static function setBaseUrl($baseUrl) |
|
24 | - { |
|
25 | - self::$baseUrl = $baseUrl; |
|
26 | - } |
|
27 | - |
|
28 | - public static function getBaseUrl() |
|
29 | - { |
|
30 | - return self::$baseUrl; |
|
31 | - } |
|
32 | - |
|
33 | - /** |
|
34 | - * Make request with CURL |
|
35 | - * |
|
36 | - * @since 1.2.3 changed error handling |
|
37 | - * @since 1.2.8 added $options['return_headers'] |
|
38 | - * |
|
39 | - * @param array $options |
|
40 | - * string url - HTTP URL. |
|
41 | - * string method - HTTP method. |
|
42 | - * string api_key - API key to access to route4me server. |
|
43 | - * array query - Array of query parameters. |
|
44 | - * array body - Array of body parameters. |
|
45 | - * string HTTPHEADER - Content type of body e.g. |
|
46 | - * 'Content-Type: application/json' |
|
47 | - * 'Content-Type: multipart/form-data' |
|
48 | - * array HTTPHEADERS - Array of headers. |
|
49 | - * string FILE - Path to uploading file. |
|
50 | - * array return_headers - Array of response headers to return as a result. |
|
51 | - * @throws Exception\ApiError |
|
52 | - */ |
|
53 | - public static function makeRequst($options) |
|
54 | - { |
|
55 | - $method = isset($options['method']) ? $options['method'] : 'GET'; |
|
56 | - $query = isset($options['query']) |
|
57 | - ? array_filter($options['query'], function ($x) { |
|
58 | - return !is_null($x); |
|
59 | - }) : []; |
|
60 | - |
|
61 | - $body = isset($options['body']) ? $options['body'] : null; |
|
62 | - $file = isset($options['FILE']) ? $options['FILE'] : null; |
|
63 | - $headers = [ |
|
64 | - 'User-Agent: Route4Me php-sdk', |
|
65 | - ]; |
|
66 | - |
|
67 | - $return_headers = (isset($options['return_headers']) ? $options['return_headers'] : null); |
|
68 | - |
|
69 | - if (isset($options['HTTPHEADER'])) { |
|
70 | - $headers[] = $options['HTTPHEADER']; |
|
71 | - } |
|
72 | - |
|
73 | - if (isset($options['HTTPHEADERS'])) { |
|
74 | - foreach ($options['HTTPHEADERS'] as $header) { |
|
75 | - $headers[] = $header; |
|
76 | - } |
|
77 | - } |
|
78 | - |
|
79 | - $ch = curl_init(); |
|
80 | - |
|
81 | - $url = isset($options['url']) |
|
82 | - ? $options['url'] . '?' . http_build_query(array_merge( |
|
83 | - $query, |
|
84 | - ['api_key' => self::getApiKey()] |
|
85 | - )) : ''; |
|
86 | - |
|
87 | - $baseUrl = self::getBaseUrl(); |
|
88 | - |
|
89 | - $curlOpts = [ |
|
90 | - CURLOPT_URL => $baseUrl.$url, |
|
91 | - CURLOPT_RETURNTRANSFER => true, |
|
92 | - CURLOPT_TIMEOUT => 120, |
|
93 | - CURLOPT_FOLLOWLOCATION => true, |
|
94 | - CURLOPT_SSL_VERIFYHOST => false, |
|
95 | - CURLOPT_SSL_VERIFYPEER => false, |
|
96 | - CURLOPT_HTTPHEADER => $headers, |
|
97 | - ]; |
|
98 | - |
|
99 | - curl_setopt_array($ch, $curlOpts); |
|
100 | - |
|
101 | - // read response headers if need |
|
102 | - $response_headers = []; |
|
103 | - if ($return_headers) { |
|
104 | - curl_setopt($ch, CURLOPT_HEADERFUNCTION, function ($curl, $header) use (&$response_headers) { |
|
105 | - $len = strlen($header); |
|
106 | - $header = explode(':', $header, 2); |
|
107 | - if (count($header) >= 2) { |
|
108 | - $response_headers[strtolower(trim($header[0]))] = trim($header[1]); |
|
109 | - } |
|
110 | - return $len; |
|
111 | - }); |
|
112 | - } |
|
113 | - |
|
114 | - if (null != $file) { |
|
115 | - $cfile = new \CURLFile($file, '', ''); |
|
116 | - $body['strFilename']=$cfile; |
|
117 | - curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true); |
|
118 | - curl_setopt($ch, CURLOPT_POST, true); |
|
119 | - curl_setopt($ch, CURLOPT_POSTFIELDS, $body); |
|
120 | - } else { |
|
121 | - switch ($method) { |
|
122 | - case 'DELETE': |
|
123 | - curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'DELETE'); |
|
124 | - break; |
|
125 | - case 'DELETEARRAY': |
|
126 | - curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'DELETE'); |
|
127 | - curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($query)); |
|
128 | - break; |
|
129 | - case 'PUT': |
|
130 | - curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'PUT'); |
|
131 | - break; |
|
132 | - case 'POST': |
|
133 | - if (isset($body)) { |
|
134 | - if (isset($options['HTTPHEADER']) |
|
135 | - && strpos($options['HTTPHEADER'], 'multipart/form-data') > 0) { |
|
136 | - $bodyData = $body; |
|
137 | - } else { |
|
138 | - $bodyData = json_encode($body); |
|
139 | - } |
|
140 | - curl_setopt($ch, CURLOPT_POST, 1); |
|
141 | - curl_setopt($ch, CURLOPT_POSTREDIR, 7); |
|
142 | - curl_setopt($ch, CURLOPT_POSTFIELDS, $bodyData); |
|
143 | - } |
|
144 | - break; |
|
145 | - case 'ADD': |
|
146 | - curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($query)); |
|
147 | - break; |
|
148 | - case 'PATCH': |
|
149 | - if (isset($body)) { |
|
150 | - $bodyData = json_encode($body); |
|
151 | - if (isset($options['HTTPHEADER'])) { |
|
152 | - if (strpos($options['HTTPHEADER'], 'multipart/form-data') > 0) { |
|
153 | - $bodyData = $body; |
|
154 | - } |
|
155 | - } |
|
156 | - curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'PATCH'); |
|
157 | - curl_setopt($ch, CURLOPT_POSTFIELDS, $bodyData); |
|
158 | - } |
|
159 | - break; |
|
160 | - } |
|
161 | - |
|
162 | - if (is_numeric(array_search($method, ['DELETE', 'PUT']))) { |
|
163 | - if (isset($body)) { |
|
164 | - curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($body)); |
|
165 | - } |
|
166 | - } |
|
167 | - } |
|
168 | - |
|
169 | - $result = curl_exec($ch); |
|
170 | - $code = curl_getinfo($ch, CURLINFO_HTTP_CODE); |
|
171 | - curl_close($ch); |
|
172 | - |
|
173 | - $json = null; |
|
174 | - if (strpos($result, '<?xml') > -1) { |
|
175 | - $xml = simplexml_load_string($result); |
|
176 | - $json = self::object2array($xml); |
|
177 | - } else { |
|
178 | - $json = json_decode($result, true); |
|
179 | - } |
|
180 | - if (200 == $code || 201 == $code || 202 == $code || 204 == $code) { |
|
181 | - if (isset($json['errors'])) { |
|
182 | - throw new ApiError(implode(', ', $json['errors']), $code, $result); |
|
183 | - } else { |
|
184 | - // return response headers if they were asked for |
|
185 | - if (count($response_headers) !== 0) { |
|
186 | - $res = [ |
|
187 | - 'code' => $code, |
|
188 | - 'data' => $json |
|
189 | - ]; |
|
190 | - foreach ($return_headers as $key => $value) { |
|
191 | - // most headers has char '-' but it is forbidden in PHP names replace it with '_' |
|
192 | - $res[strtolower(str_replace('-', '_', $value))] = |
|
193 | - (isset($response_headers[$value]) ? $response_headers[$value] : null); |
|
194 | - } |
|
195 | - return $res; |
|
196 | - } |
|
197 | - if (204 == $code) { |
|
198 | - return true; |
|
199 | - } |
|
200 | - return $json; |
|
201 | - } |
|
202 | - } elseif (isset($code) && (!isset($result) || !$result)) { |
|
203 | - throw new ApiError('', $code, $result); |
|
204 | - } else { |
|
205 | - if (isset($json['messages'])) { |
|
206 | - $msg = ''; |
|
207 | - foreach ($json['messages'] as $key => $value) { |
|
208 | - if ($msg !== '') { |
|
209 | - $msg .= PHP_EOL; |
|
210 | - } |
|
211 | - $msg .= $key . ': ' . (is_array($value) ? implode(', ', $value) : $value); |
|
212 | - } |
|
213 | - throw new ApiError($msg, $code, $result); |
|
214 | - } elseif (isset($json['error']) && !empty($json['error'])) { |
|
215 | - throw new ApiError($json['error'], $code, $result); |
|
216 | - } elseif (isset($json['error'])) { |
|
217 | - $msg = ''; |
|
218 | - foreach ($json['errors'] as $key => $value) { |
|
219 | - if ($msg !== '') { |
|
220 | - $msg .= PHP_EOL; |
|
221 | - } |
|
222 | - $msg .= $value; |
|
223 | - } |
|
224 | - throw new ApiError($msg, $code, $result); |
|
225 | - } else { |
|
226 | - throw new ApiError($result, $code, $result); |
|
227 | - } |
|
228 | - } |
|
229 | - } |
|
230 | - |
|
231 | - /** |
|
232 | - * @param $object: JSON object |
|
233 | - */ |
|
234 | - public static function object2array($object) |
|
235 | - { |
|
236 | - return @json_decode(@json_encode($object), 1); |
|
237 | - } |
|
238 | - |
|
239 | - /** |
|
240 | - * Prints on the screen main keys and values of the array. |
|
241 | - * |
|
242 | - * @param $results: object to be printed on the screen |
|
243 | - * @param $deepPrinting: if true, object will be printed recursively |
|
244 | - */ |
|
245 | - public static function simplePrint($results, $deepPrinting = null) |
|
246 | - { |
|
247 | - if (isset($results)) { |
|
248 | - if (is_array($results)) { |
|
249 | - foreach ($results as $key => $result) { |
|
250 | - if (is_array($result)) { |
|
251 | - foreach ($result as $key1 => $result1) { |
|
252 | - if (is_array($result1)) { |
|
253 | - if ($deepPrinting) { |
|
254 | - echo "<br>$key1 ------><br>"; |
|
255 | - self::simplePrint($result1, true); |
|
256 | - echo '------<br>'; |
|
257 | - } else { |
|
258 | - echo $key1.' --> '.'Array() <br>'; |
|
259 | - } |
|
260 | - } else { |
|
261 | - if (is_object($result1)) { |
|
262 | - if ($deepPrinting) { |
|
263 | - echo "<br>$key1 ------><br>"; |
|
264 | - $oarray = (array) $result1; |
|
265 | - self::simplePrint($oarray, true); |
|
266 | - echo '------<br>'; |
|
267 | - } else { |
|
268 | - echo $key1.' --> '.'Object <br>'; |
|
269 | - } |
|
270 | - } else { |
|
271 | - if (!is_null($result1)) { |
|
272 | - echo $key1.' --> '.$result1.'<br>'; |
|
273 | - } |
|
274 | - } |
|
275 | - } |
|
276 | - } |
|
277 | - } else { |
|
278 | - if (is_object($result)) { |
|
279 | - if ($deepPrinting) { |
|
280 | - echo "<br>$key ------><br>"; |
|
281 | - $oarray = (array) $result; |
|
282 | - self::simplePrint($oarray, true); |
|
283 | - echo '------<br>'; |
|
284 | - } else { |
|
285 | - echo $key.' --> '.'Object <br>'; |
|
286 | - } |
|
287 | - } else { |
|
288 | - if (!is_null($result)) { |
|
289 | - echo $key.' --> '.$result.'<br>'; |
|
290 | - } |
|
291 | - } |
|
292 | - } |
|
293 | - //echo "<br>"; |
|
294 | - } |
|
295 | - } |
|
296 | - } |
|
297 | - } |
|
298 | - |
|
299 | - /** |
|
300 | - * Generates query or body parameters. |
|
301 | - * |
|
302 | - * @param $allFields: all known fields could be used for parameters generation |
|
303 | - * @param $params: input parameters (array or object) |
|
304 | - */ |
|
305 | - public static function generateRequestParameters($allFields, $params) |
|
306 | - { |
|
307 | - $generatedParams = []; |
|
308 | - |
|
309 | - if (is_array($params)) { |
|
310 | - foreach ($allFields as $field) { |
|
311 | - if (isset($params[$field])) { |
|
312 | - $generatedParams[$field] = $params[$field]; |
|
313 | - } |
|
314 | - } |
|
315 | - } elseif (is_object($params)) { |
|
316 | - foreach ($allFields as $field) { |
|
317 | - if (isset($params->{$field})) { |
|
318 | - $generatedParams[$field] = $params->{$field}; |
|
319 | - } |
|
320 | - } |
|
321 | - } |
|
322 | - |
|
323 | - return $generatedParams; |
|
324 | - } |
|
325 | - |
|
326 | - /** |
|
327 | - * Returns an array of the object properties. |
|
328 | - * |
|
329 | - * @param $object: An object |
|
330 | - * @param $exclude: array of the object parameters to be excluded from the returned array |
|
331 | - */ |
|
332 | - public static function getObjectProperties($object, $exclude) |
|
333 | - { |
|
334 | - $objectParameters = []; |
|
335 | - |
|
336 | - foreach (get_object_vars($object) as $key => $value) { |
|
337 | - if (property_exists($object, $key)) { |
|
338 | - if (!is_numeric(array_search($key, $exclude))) { |
|
339 | - array_push($objectParameters, $key); |
|
340 | - } |
|
341 | - } |
|
342 | - } |
|
343 | - |
|
344 | - return $objectParameters; |
|
345 | - } |
|
346 | - |
|
347 | - /** |
|
348 | - * Returns url path generated from the array of the fields and parameters. |
|
349 | - * |
|
350 | - * @param $allFields; array of the paossible fields (parameter names) |
|
351 | - * @param $params: input parameters (array or object) |
|
352 | - */ |
|
353 | - public static function generateUrlPath($allFields, $params) |
|
354 | - { |
|
355 | - $generatedPath = ''; |
|
356 | - |
|
357 | - if (is_array($params)) { |
|
358 | - foreach ($allFields as $field) { |
|
359 | - if (isset($params[$field])) { |
|
360 | - $generatedPath .= $params[$field].'/'; |
|
361 | - } |
|
362 | - } |
|
363 | - } elseif (is_object($params)) { |
|
364 | - foreach ($allFields as $field) { |
|
365 | - if (isset($params->{$field})) { |
|
366 | - $generatedPath .= $params->{$field}.'/'; |
|
367 | - } |
|
368 | - } |
|
369 | - } |
|
370 | - |
|
371 | - return $generatedPath; |
|
372 | - } |
|
373 | - |
|
374 | - public static function getFileRealPath($fileName) |
|
375 | - { |
|
376 | - $rpath = function_exists('curl_file_create') ? curl_file_create(realpath($fileName)) : '@'.realpath($fileName); |
|
377 | - |
|
378 | - return $rpath; |
|
379 | - } |
|
10 | + public static $apiKey; |
|
11 | + public static $baseUrl = Endpoint::BASE_URL; |
|
12 | + |
|
13 | + public static function setApiKey($apiKey) |
|
14 | + { |
|
15 | + self::$apiKey = $apiKey; |
|
16 | + } |
|
17 | + |
|
18 | + public static function getApiKey() |
|
19 | + { |
|
20 | + return self::$apiKey; |
|
21 | + } |
|
22 | + |
|
23 | + public static function setBaseUrl($baseUrl) |
|
24 | + { |
|
25 | + self::$baseUrl = $baseUrl; |
|
26 | + } |
|
27 | + |
|
28 | + public static function getBaseUrl() |
|
29 | + { |
|
30 | + return self::$baseUrl; |
|
31 | + } |
|
32 | + |
|
33 | + /** |
|
34 | + * Make request with CURL |
|
35 | + * |
|
36 | + * @since 1.2.3 changed error handling |
|
37 | + * @since 1.2.8 added $options['return_headers'] |
|
38 | + * |
|
39 | + * @param array $options |
|
40 | + * string url - HTTP URL. |
|
41 | + * string method - HTTP method. |
|
42 | + * string api_key - API key to access to route4me server. |
|
43 | + * array query - Array of query parameters. |
|
44 | + * array body - Array of body parameters. |
|
45 | + * string HTTPHEADER - Content type of body e.g. |
|
46 | + * 'Content-Type: application/json' |
|
47 | + * 'Content-Type: multipart/form-data' |
|
48 | + * array HTTPHEADERS - Array of headers. |
|
49 | + * string FILE - Path to uploading file. |
|
50 | + * array return_headers - Array of response headers to return as a result. |
|
51 | + * @throws Exception\ApiError |
|
52 | + */ |
|
53 | + public static function makeRequst($options) |
|
54 | + { |
|
55 | + $method = isset($options['method']) ? $options['method'] : 'GET'; |
|
56 | + $query = isset($options['query']) |
|
57 | + ? array_filter($options['query'], function ($x) { |
|
58 | + return !is_null($x); |
|
59 | + }) : []; |
|
60 | + |
|
61 | + $body = isset($options['body']) ? $options['body'] : null; |
|
62 | + $file = isset($options['FILE']) ? $options['FILE'] : null; |
|
63 | + $headers = [ |
|
64 | + 'User-Agent: Route4Me php-sdk', |
|
65 | + ]; |
|
66 | + |
|
67 | + $return_headers = (isset($options['return_headers']) ? $options['return_headers'] : null); |
|
68 | + |
|
69 | + if (isset($options['HTTPHEADER'])) { |
|
70 | + $headers[] = $options['HTTPHEADER']; |
|
71 | + } |
|
72 | + |
|
73 | + if (isset($options['HTTPHEADERS'])) { |
|
74 | + foreach ($options['HTTPHEADERS'] as $header) { |
|
75 | + $headers[] = $header; |
|
76 | + } |
|
77 | + } |
|
78 | + |
|
79 | + $ch = curl_init(); |
|
80 | + |
|
81 | + $url = isset($options['url']) |
|
82 | + ? $options['url'] . '?' . http_build_query(array_merge( |
|
83 | + $query, |
|
84 | + ['api_key' => self::getApiKey()] |
|
85 | + )) : ''; |
|
86 | + |
|
87 | + $baseUrl = self::getBaseUrl(); |
|
88 | + |
|
89 | + $curlOpts = [ |
|
90 | + CURLOPT_URL => $baseUrl.$url, |
|
91 | + CURLOPT_RETURNTRANSFER => true, |
|
92 | + CURLOPT_TIMEOUT => 120, |
|
93 | + CURLOPT_FOLLOWLOCATION => true, |
|
94 | + CURLOPT_SSL_VERIFYHOST => false, |
|
95 | + CURLOPT_SSL_VERIFYPEER => false, |
|
96 | + CURLOPT_HTTPHEADER => $headers, |
|
97 | + ]; |
|
98 | + |
|
99 | + curl_setopt_array($ch, $curlOpts); |
|
100 | + |
|
101 | + // read response headers if need |
|
102 | + $response_headers = []; |
|
103 | + if ($return_headers) { |
|
104 | + curl_setopt($ch, CURLOPT_HEADERFUNCTION, function ($curl, $header) use (&$response_headers) { |
|
105 | + $len = strlen($header); |
|
106 | + $header = explode(':', $header, 2); |
|
107 | + if (count($header) >= 2) { |
|
108 | + $response_headers[strtolower(trim($header[0]))] = trim($header[1]); |
|
109 | + } |
|
110 | + return $len; |
|
111 | + }); |
|
112 | + } |
|
113 | + |
|
114 | + if (null != $file) { |
|
115 | + $cfile = new \CURLFile($file, '', ''); |
|
116 | + $body['strFilename']=$cfile; |
|
117 | + curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true); |
|
118 | + curl_setopt($ch, CURLOPT_POST, true); |
|
119 | + curl_setopt($ch, CURLOPT_POSTFIELDS, $body); |
|
120 | + } else { |
|
121 | + switch ($method) { |
|
122 | + case 'DELETE': |
|
123 | + curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'DELETE'); |
|
124 | + break; |
|
125 | + case 'DELETEARRAY': |
|
126 | + curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'DELETE'); |
|
127 | + curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($query)); |
|
128 | + break; |
|
129 | + case 'PUT': |
|
130 | + curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'PUT'); |
|
131 | + break; |
|
132 | + case 'POST': |
|
133 | + if (isset($body)) { |
|
134 | + if (isset($options['HTTPHEADER']) |
|
135 | + && strpos($options['HTTPHEADER'], 'multipart/form-data') > 0) { |
|
136 | + $bodyData = $body; |
|
137 | + } else { |
|
138 | + $bodyData = json_encode($body); |
|
139 | + } |
|
140 | + curl_setopt($ch, CURLOPT_POST, 1); |
|
141 | + curl_setopt($ch, CURLOPT_POSTREDIR, 7); |
|
142 | + curl_setopt($ch, CURLOPT_POSTFIELDS, $bodyData); |
|
143 | + } |
|
144 | + break; |
|
145 | + case 'ADD': |
|
146 | + curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($query)); |
|
147 | + break; |
|
148 | + case 'PATCH': |
|
149 | + if (isset($body)) { |
|
150 | + $bodyData = json_encode($body); |
|
151 | + if (isset($options['HTTPHEADER'])) { |
|
152 | + if (strpos($options['HTTPHEADER'], 'multipart/form-data') > 0) { |
|
153 | + $bodyData = $body; |
|
154 | + } |
|
155 | + } |
|
156 | + curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'PATCH'); |
|
157 | + curl_setopt($ch, CURLOPT_POSTFIELDS, $bodyData); |
|
158 | + } |
|
159 | + break; |
|
160 | + } |
|
161 | + |
|
162 | + if (is_numeric(array_search($method, ['DELETE', 'PUT']))) { |
|
163 | + if (isset($body)) { |
|
164 | + curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($body)); |
|
165 | + } |
|
166 | + } |
|
167 | + } |
|
168 | + |
|
169 | + $result = curl_exec($ch); |
|
170 | + $code = curl_getinfo($ch, CURLINFO_HTTP_CODE); |
|
171 | + curl_close($ch); |
|
172 | + |
|
173 | + $json = null; |
|
174 | + if (strpos($result, '<?xml') > -1) { |
|
175 | + $xml = simplexml_load_string($result); |
|
176 | + $json = self::object2array($xml); |
|
177 | + } else { |
|
178 | + $json = json_decode($result, true); |
|
179 | + } |
|
180 | + if (200 == $code || 201 == $code || 202 == $code || 204 == $code) { |
|
181 | + if (isset($json['errors'])) { |
|
182 | + throw new ApiError(implode(', ', $json['errors']), $code, $result); |
|
183 | + } else { |
|
184 | + // return response headers if they were asked for |
|
185 | + if (count($response_headers) !== 0) { |
|
186 | + $res = [ |
|
187 | + 'code' => $code, |
|
188 | + 'data' => $json |
|
189 | + ]; |
|
190 | + foreach ($return_headers as $key => $value) { |
|
191 | + // most headers has char '-' but it is forbidden in PHP names replace it with '_' |
|
192 | + $res[strtolower(str_replace('-', '_', $value))] = |
|
193 | + (isset($response_headers[$value]) ? $response_headers[$value] : null); |
|
194 | + } |
|
195 | + return $res; |
|
196 | + } |
|
197 | + if (204 == $code) { |
|
198 | + return true; |
|
199 | + } |
|
200 | + return $json; |
|
201 | + } |
|
202 | + } elseif (isset($code) && (!isset($result) || !$result)) { |
|
203 | + throw new ApiError('', $code, $result); |
|
204 | + } else { |
|
205 | + if (isset($json['messages'])) { |
|
206 | + $msg = ''; |
|
207 | + foreach ($json['messages'] as $key => $value) { |
|
208 | + if ($msg !== '') { |
|
209 | + $msg .= PHP_EOL; |
|
210 | + } |
|
211 | + $msg .= $key . ': ' . (is_array($value) ? implode(', ', $value) : $value); |
|
212 | + } |
|
213 | + throw new ApiError($msg, $code, $result); |
|
214 | + } elseif (isset($json['error']) && !empty($json['error'])) { |
|
215 | + throw new ApiError($json['error'], $code, $result); |
|
216 | + } elseif (isset($json['error'])) { |
|
217 | + $msg = ''; |
|
218 | + foreach ($json['errors'] as $key => $value) { |
|
219 | + if ($msg !== '') { |
|
220 | + $msg .= PHP_EOL; |
|
221 | + } |
|
222 | + $msg .= $value; |
|
223 | + } |
|
224 | + throw new ApiError($msg, $code, $result); |
|
225 | + } else { |
|
226 | + throw new ApiError($result, $code, $result); |
|
227 | + } |
|
228 | + } |
|
229 | + } |
|
230 | + |
|
231 | + /** |
|
232 | + * @param $object: JSON object |
|
233 | + */ |
|
234 | + public static function object2array($object) |
|
235 | + { |
|
236 | + return @json_decode(@json_encode($object), 1); |
|
237 | + } |
|
238 | + |
|
239 | + /** |
|
240 | + * Prints on the screen main keys and values of the array. |
|
241 | + * |
|
242 | + * @param $results: object to be printed on the screen |
|
243 | + * @param $deepPrinting: if true, object will be printed recursively |
|
244 | + */ |
|
245 | + public static function simplePrint($results, $deepPrinting = null) |
|
246 | + { |
|
247 | + if (isset($results)) { |
|
248 | + if (is_array($results)) { |
|
249 | + foreach ($results as $key => $result) { |
|
250 | + if (is_array($result)) { |
|
251 | + foreach ($result as $key1 => $result1) { |
|
252 | + if (is_array($result1)) { |
|
253 | + if ($deepPrinting) { |
|
254 | + echo "<br>$key1 ------><br>"; |
|
255 | + self::simplePrint($result1, true); |
|
256 | + echo '------<br>'; |
|
257 | + } else { |
|
258 | + echo $key1.' --> '.'Array() <br>'; |
|
259 | + } |
|
260 | + } else { |
|
261 | + if (is_object($result1)) { |
|
262 | + if ($deepPrinting) { |
|
263 | + echo "<br>$key1 ------><br>"; |
|
264 | + $oarray = (array) $result1; |
|
265 | + self::simplePrint($oarray, true); |
|
266 | + echo '------<br>'; |
|
267 | + } else { |
|
268 | + echo $key1.' --> '.'Object <br>'; |
|
269 | + } |
|
270 | + } else { |
|
271 | + if (!is_null($result1)) { |
|
272 | + echo $key1.' --> '.$result1.'<br>'; |
|
273 | + } |
|
274 | + } |
|
275 | + } |
|
276 | + } |
|
277 | + } else { |
|
278 | + if (is_object($result)) { |
|
279 | + if ($deepPrinting) { |
|
280 | + echo "<br>$key ------><br>"; |
|
281 | + $oarray = (array) $result; |
|
282 | + self::simplePrint($oarray, true); |
|
283 | + echo '------<br>'; |
|
284 | + } else { |
|
285 | + echo $key.' --> '.'Object <br>'; |
|
286 | + } |
|
287 | + } else { |
|
288 | + if (!is_null($result)) { |
|
289 | + echo $key.' --> '.$result.'<br>'; |
|
290 | + } |
|
291 | + } |
|
292 | + } |
|
293 | + //echo "<br>"; |
|
294 | + } |
|
295 | + } |
|
296 | + } |
|
297 | + } |
|
298 | + |
|
299 | + /** |
|
300 | + * Generates query or body parameters. |
|
301 | + * |
|
302 | + * @param $allFields: all known fields could be used for parameters generation |
|
303 | + * @param $params: input parameters (array or object) |
|
304 | + */ |
|
305 | + public static function generateRequestParameters($allFields, $params) |
|
306 | + { |
|
307 | + $generatedParams = []; |
|
308 | + |
|
309 | + if (is_array($params)) { |
|
310 | + foreach ($allFields as $field) { |
|
311 | + if (isset($params[$field])) { |
|
312 | + $generatedParams[$field] = $params[$field]; |
|
313 | + } |
|
314 | + } |
|
315 | + } elseif (is_object($params)) { |
|
316 | + foreach ($allFields as $field) { |
|
317 | + if (isset($params->{$field})) { |
|
318 | + $generatedParams[$field] = $params->{$field}; |
|
319 | + } |
|
320 | + } |
|
321 | + } |
|
322 | + |
|
323 | + return $generatedParams; |
|
324 | + } |
|
325 | + |
|
326 | + /** |
|
327 | + * Returns an array of the object properties. |
|
328 | + * |
|
329 | + * @param $object: An object |
|
330 | + * @param $exclude: array of the object parameters to be excluded from the returned array |
|
331 | + */ |
|
332 | + public static function getObjectProperties($object, $exclude) |
|
333 | + { |
|
334 | + $objectParameters = []; |
|
335 | + |
|
336 | + foreach (get_object_vars($object) as $key => $value) { |
|
337 | + if (property_exists($object, $key)) { |
|
338 | + if (!is_numeric(array_search($key, $exclude))) { |
|
339 | + array_push($objectParameters, $key); |
|
340 | + } |
|
341 | + } |
|
342 | + } |
|
343 | + |
|
344 | + return $objectParameters; |
|
345 | + } |
|
346 | + |
|
347 | + /** |
|
348 | + * Returns url path generated from the array of the fields and parameters. |
|
349 | + * |
|
350 | + * @param $allFields; array of the paossible fields (parameter names) |
|
351 | + * @param $params: input parameters (array or object) |
|
352 | + */ |
|
353 | + public static function generateUrlPath($allFields, $params) |
|
354 | + { |
|
355 | + $generatedPath = ''; |
|
356 | + |
|
357 | + if (is_array($params)) { |
|
358 | + foreach ($allFields as $field) { |
|
359 | + if (isset($params[$field])) { |
|
360 | + $generatedPath .= $params[$field].'/'; |
|
361 | + } |
|
362 | + } |
|
363 | + } elseif (is_object($params)) { |
|
364 | + foreach ($allFields as $field) { |
|
365 | + if (isset($params->{$field})) { |
|
366 | + $generatedPath .= $params->{$field}.'/'; |
|
367 | + } |
|
368 | + } |
|
369 | + } |
|
370 | + |
|
371 | + return $generatedPath; |
|
372 | + } |
|
373 | + |
|
374 | + public static function getFileRealPath($fileName) |
|
375 | + { |
|
376 | + $rpath = function_exists('curl_file_create') ? curl_file_create(realpath($fileName)) : '@'.realpath($fileName); |
|
377 | + |
|
378 | + return $rpath; |
|
379 | + } |
|
380 | 380 | } |
@@ -20,58 +20,58 @@ |
||
20 | 20 | |
21 | 21 | // new PoD Workflow |
22 | 22 | $params = [ |
23 | - 'workflow_id' => 'workflow_super_ID', |
|
24 | - 'is_enabled' => false, |
|
25 | - 'is_default' => false, |
|
26 | - 'title' => 'Super title from 15', |
|
27 | - 'done_actions' => [[ |
|
28 | - 'title' => 'Signee Name', |
|
29 | - 'type' => 'signeeName', |
|
30 | - 'required' => true |
|
31 | - ]], |
|
32 | - 'failed_actions' => [[ |
|
33 | - 'title' => 'Signee Name Failed', |
|
34 | - 'type' => 'signeeName', |
|
35 | - 'required' => false |
|
36 | - ]] |
|
23 | + 'workflow_id' => 'workflow_super_ID', |
|
24 | + 'is_enabled' => false, |
|
25 | + 'is_default' => false, |
|
26 | + 'title' => 'Super title from 15', |
|
27 | + 'done_actions' => [[ |
|
28 | + 'title' => 'Signee Name', |
|
29 | + 'type' => 'signeeName', |
|
30 | + 'required' => true |
|
31 | + ]], |
|
32 | + 'failed_actions' => [[ |
|
33 | + 'title' => 'Signee Name Failed', |
|
34 | + 'type' => 'signeeName', |
|
35 | + 'required' => false |
|
36 | + ]] |
|
37 | 37 | ]; |
38 | 38 | |
39 | 39 | $pws = new PodWorkflows(); |
40 | 40 | |
41 | 41 | try { |
42 | - // create |
|
43 | - $new_pod = $pws->createPodWorkflow($params); |
|
42 | + // create |
|
43 | + $new_pod = $pws->createPodWorkflow($params); |
|
44 | 44 | |
45 | - if (isset($new_pod->workflow_guid)) { |
|
46 | - $created_pod_guid = $new_pod->workflow_guid; |
|
47 | - echo 'Created PodWorkflow with GUID: ' . $created_pod_guid . PHP_EOL; |
|
45 | + if (isset($new_pod->workflow_guid)) { |
|
46 | + $created_pod_guid = $new_pod->workflow_guid; |
|
47 | + echo 'Created PodWorkflow with GUID: ' . $created_pod_guid . PHP_EOL; |
|
48 | 48 | |
49 | - // read |
|
50 | - $read_pod = $pws->getPodWorkflow($created_pod_guid); |
|
51 | - echo 'Read PodWorkflow with GUID: ' . $read_pod->workflow_guid . PHP_EOL; |
|
49 | + // read |
|
50 | + $read_pod = $pws->getPodWorkflow($created_pod_guid); |
|
51 | + echo 'Read PodWorkflow with GUID: ' . $read_pod->workflow_guid . PHP_EOL; |
|
52 | 52 | |
53 | - // update |
|
54 | - $params['title'] = 'A new Super title from 15'; |
|
55 | - $updated_pod = $pws->updatePodWorkflow($created_pod_guid, $params); |
|
56 | - echo 'Updated PodWorkflow with GUID: ' . $updated_pod->workflow_guid |
|
57 | - . ', new title is "'. $updated_pod->title . '"' . PHP_EOL; |
|
53 | + // update |
|
54 | + $params['title'] = 'A new Super title from 15'; |
|
55 | + $updated_pod = $pws->updatePodWorkflow($created_pod_guid, $params); |
|
56 | + echo 'Updated PodWorkflow with GUID: ' . $updated_pod->workflow_guid |
|
57 | + . ', new title is "'. $updated_pod->title . '"' . PHP_EOL; |
|
58 | 58 | |
59 | - //delete |
|
60 | - $res = $pws->deletePodWorkflow($created_pod_guid); |
|
61 | - echo 'Deleted PodWorkflow with GUID: ' . $created_pod_guid . PHP_EOL; |
|
62 | - } else { |
|
63 | - echo 'Error creating PodWorkflow.' . PHP_EOL; |
|
64 | - } |
|
59 | + //delete |
|
60 | + $res = $pws->deletePodWorkflow($created_pod_guid); |
|
61 | + echo 'Deleted PodWorkflow with GUID: ' . $created_pod_guid . PHP_EOL; |
|
62 | + } else { |
|
63 | + echo 'Error creating PodWorkflow.' . PHP_EOL; |
|
64 | + } |
|
65 | 65 | } catch (Exception | ApiError $e) { |
66 | - echo 'Error, Code: ' . $e->getCode() . PHP_EOL . 'Message: ' . $e->getMessage() . PHP_EOL; |
|
66 | + echo 'Error, Code: ' . $e->getCode() . PHP_EOL . 'Message: ' . $e->getMessage() . PHP_EOL; |
|
67 | 67 | |
68 | - if ($created_pod_guid) { |
|
69 | - echo 'Cleanup PodWorkflow with GUID: ' . $created_pod_guid . PHP_EOL; |
|
70 | - try { |
|
71 | - $pws->deletePodWorkflow($created_pod_guid); |
|
72 | - } catch (Exception | ApiError $e) { |
|
73 | - echo 'Error: Cleanup.' . PHP_EOL; |
|
74 | - echo $e->getMessage() . PHP_EOL; |
|
75 | - } |
|
76 | - } |
|
68 | + if ($created_pod_guid) { |
|
69 | + echo 'Cleanup PodWorkflow with GUID: ' . $created_pod_guid . PHP_EOL; |
|
70 | + try { |
|
71 | + $pws->deletePodWorkflow($created_pod_guid); |
|
72 | + } catch (Exception | ApiError $e) { |
|
73 | + echo 'Error: Cleanup.' . PHP_EOL; |
|
74 | + echo $e->getMessage() . PHP_EOL; |
|
75 | + } |
|
76 | + } |
|
77 | 77 | } |