forked from cronofy/cronofy-php
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdev-smoke-test.php
119 lines (94 loc) · 2.86 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
<?php declare(strict_types=1);
require_once __DIR__ . '/vendor/autoload.php';
use Cronofy\Batch\Batch;
use Cronofy\Exception\CronofyException;
use Cronofy\Exception\PartialBatchFailureException;
$cronofy = new Cronofy\Cronofy([
"client_id" => $_ENV["CLIENT_ID"],
"client_secret" => $_ENV["CLIENT_SECRET"],
"access_token" => $_ENV["ACCESS_TOKEN"],
"refresh_token" => $_ENV["REFRESH_TOKEN"],
"data_center" => $_ENV["DATACENTER"]
]);
$calendarId = $_ENV["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,
];
$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";
}
}
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);
}
echo "\n";
echo "Creating event with recurrence\n";
$recurrenceEventParams = $testEventData;
$recurrenceEventParams['recurrence'] = [
"rules" => [
[
"frequency" => "daily",
"interval" => 2,
"count" => 3,
],
],
];
$cronofy->upsertEvent($recurrenceEventParams);