-
Notifications
You must be signed in to change notification settings - Fork 31
/
dev-smoke-test.php
213 lines (178 loc) · 4.95 KB
/
dev-smoke-test.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
<?php declare(strict_types=1);
require_once __DIR__ . '/vendor/autoload.php';
use Cronofy\Batch\Batch;
use Cronofy\Exception\CronofyException;
use Cronofy\Exception\PartialBatchFailureException;
$testBatch = false;
$testAvailablePeriod = false;
$testRecurrence = false;
$testRTS = true;
$dataCenter = getenv("DATACENTER");
$cronofy = new Cronofy\Cronofy([
"client_id" => getenv("CLIENT_ID"),
"client_secret" => getenv("CLIENT_SECRET"),
"access_token" => getenv("ACCESS_TOKEN"),
"refresh_token" => getenv("REFRESH_TOKEN"),
"data_center" => $dataCenter,
]);
$sub = getenv("SUB");
$calendarId = getenv("CALENDAR_ID");
$start = date("Y-m-d", strtotime('tomorrow')) . "T09:30:00Z";
$end = date("Y-m-d", strtotime('tomorrow')) . "T10:00:00Z";
$yesterday = date("Y-m-d", strtotime('yesterday'));
$next_week = date("Y-m-d", strtotime('next week'));
$testEventId = 'php-smoke-test-001';
$testEventData = [
'calendar_id' => $calendarId,
'event_id' => $testEventId,
'summary' => 'PHP SDK test event 001',
'description' => 'Just checking this thing is on!',
'start' => $start,
'end' => $end,
];
echo "Writing test events to " . $dataCenter . ", account " . $sub . ", calendar " . $calendarId . "\n";
if ( $testBatch ) {
$batch = Batch::create()
->upsertEvent($calendarId, $testEventData)
->deleteEvent($calendarId, $testEventId)
->deleteEvent("fake-calendar-id", "just-want-it-to-fail")
->upsertEvent($calendarId, []);
try {
$result = $cronofy->executeBatch($batch);
} catch (PartialBatchFailureException $exception) {
echo "PARTIAL FAILURE\n\n";
$result = $exception->result();
} finally {
foreach ($result->responses() as $index=>$response) {
echo "Request " . $index . " - " . $response->request()->method() . " " . $response->request()->relativeUrl() . "\n";
echo $response->hasSuccessStatus() ? " Success" : " Failed";
echo "\n";
echo " status " . $response->status() . "\n";
echo " headers ";
$headers = $response->headers();
print_r($headers);
echo "\n";
echo " data ";
$data = $response->data();
print_r($data);
echo "\n\n";
}
}
}
if( $testAvailablePeriod ) {
echo "Creating AvailablePeriod\n";
$ap_id = "test_available_period_001";
$params = [
"available_period_id" => $ap_id,
"start" => $start,
"end" => $end,
];
$cronofy->createAvailablePeriod($params);
echo "Reading Available Period\n";
$readParams = [
"from" => $yesterday,
"to" => $next_week,
"tzid" => "Europe/London",
];
$periods = $cronofy->readAvailablePeriods($readParams);
foreach($periods->each() as $available_period){
print_r($available_period);
}
echo "\n";
echo "Deleting Available Period\n";
$params = [
"available_period_id" => $ap_id,
];
$result = $cronofy->deleteAvailablePeriod($params);
print_r($result);
$periods = $cronofy->readAvailablePeriods($readParams);
foreach($periods->each() as $available_period){
print_r($available_period);
}
}
if( $testRecurrence ) {
echo "\n";
echo "Creating event with recurrence\n";
$recurrenceEventParams = $testEventData;
$recurrenceEventParams['recurrence'] = [
"rules" => [
[
"frequency" => "daily",
"interval" => 2,
"count" => 3,
],
],
];
$cronofy->upsertEvent($recurrenceEventParams);
echo "\n";
}
if($testRTS){
echo "Checking RTS\n";
$event = [
"event_id" => "php-smoke-test-002",
"summary" => "Add to Calendar test event",
];
$availability = [
"participants" => [
[
"members" => [
[
"sub" => $sub,
"calendar_ids" => [$calendarId]
]
],
"required" => "all"
]
],
"event" => $event,
"required_duration" => [
"minutes" => 60
],
"available_periods" => [
[
"start" => $start,
"end" => $end
]
]
];
$target_calendars = [
[
"sub" => $sub,
"calendar_id" => $calendarId
]
];
$tzid = 'Europe/London';
$params = [
"event" => $event,
"target_calendars" => $target_calendars,
"availability" => $availability,
"tzid" => $tzid,
"oauth" => [
"redirect_uri" => "http://local.cronofy.com/redirect"
],
"formatting" => [
"hour_format" => "H",
],
"minimum_notice" => [
"hours" => 2
],
"redirect_urls" => [
"completed_url" => "http://local.cronofy.com/complete",
"no_times_suitable_url" => "http://local.cronofy.com/need_more_times_please",
],
"callback_urls" => [
"completed_url" => "http://local.cronofy.com/callback/complete",
],
"event_creation" => "single",
];
$rts = $cronofy->realTimeScheduling($params);
echo "RTS Created:\n";
print_r($rts);
$rts_id = $rts["real_time_scheduling"]["real_time_scheduling_id"];
echo "Cancelling RTS\n";
$params =[
"id" => $rts_id,
"display_message" => "Testing disable"
];
$cronofy->realTimeSchedulingDisable($params);
}