Skip to content

Commit

Permalink
Merge pull request cronofy#106 from cronofy/available-periods
Browse files Browse the repository at this point in the history
Available periods support
  • Loading branch information
AdamWhittingham authored Apr 29, 2021
2 parents cbd9d56 + 8ea3b9d commit 500592c
Show file tree
Hide file tree
Showing 5 changed files with 146 additions and 1 deletion.
10 changes: 10 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
## [1.3.0]
* add AvailablePeriod create, read, delete and bulkDelete [#105] [#106]
* add support for empty descriptions [#103]
* add support for subscriptions on baseUpsertEvent [#104]

## [1.2.0]

* add support for the Batch endpoint [#97]
Expand Down Expand Up @@ -75,10 +80,15 @@
[1.1.9]: https://github.com/cronofy/cronofy-php/releases/tag/v1.1.9
[1.1.10]: https://github.com/cronofy/cronofy-php/releases/tag/v1.1.10
[1.2.0]: https://github.com/cronofy/cronofy-php/releases/tag/v1.2.0
[1.2.0]: https://github.com/cronofy/cronofy-php/releases/tag/v1.3.0

[#32]: https://github.com/cronofy/cronofy-php/pull/76
[#33]: https://github.com/cronofy/cronofy-php/pull/74
[#34]: https://github.com/cronofy/cronofy-php/pull/77
[#94]: https://github.com/cronofy/cronofy-php/pull/94
[#86]: https://github.com/cronofy/cronofy-php/pull/86
[#97]: https://github.com/cronofy/cronofy-php/pull/97
[#103]: https://github.com/cronofy/cronofy-php/pull/103
[#104]: https://github.com/cronofy/cronofy-php/pull/104
[#105]: https://github.com/cronofy/cronofy-php/pull/105
[#106]: https://github.com/cronofy/cronofy-php/pull/106
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "cronofy/cronofy",
"description": "PHP wrapper for Cronofy's unified calendar API",
"version": "v1.2.0",
"version": "v1.3.0",
"require": {
"php": "^7.1"
},
Expand Down
40 changes: 40 additions & 0 deletions dev-smoke-test.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,9 @@
$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',
Expand Down Expand Up @@ -59,4 +62,41 @@
}
}

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);
}
63 changes: 63 additions & 0 deletions src/Cronofy.php
Original file line number Diff line number Diff line change
Expand Up @@ -961,6 +961,69 @@ public function getSmartInvite($smart_invite_id, $recipient_email)

return $this->apiKeyHttpGet("/" . self::API_VERSION . "/smart_invites", $urlParams);
}

public function readAvailablePeriods($params)
{
/*
Date from: The minimum Date from which to return available periods. OPTIONAL
Date to: The Date to return available periods up until.
Note that the results will not include available periods occurring on this date. OPTIONAL
String tzid: A String representing a known time zone identifier from the IANA Time Zone Database. OPTIONAL
Boolean localized_times: A Boolean specifying whether the available periods should have their start and end times
returned with any available localization information. If not provided the start and end times will be
returned as simple Time values. OPTIONAL
returns $result - Array of available_periods
*/

$url = $this->apiUrl("/" . self::API_VERSION . "/available_periods");

return new PagedResultIterator($this, "available_periods", $this->getAuthHeaders(), $url, $this->urlParams($params));
}

public function createAvailablePeriod($params)
{
/*
String available_period_id: The String that uniquely identifies the available period. The first request made
for an available_period_id will create an available period for the account and subsequent requests will
update its details. REQUIRED
Time start: The start time can be provided as a simple Time string or an object with two attributes, time and tzid. REQUIRED
Time end: The end time can be provided as a simple Time string or an object with two attributes, time and tzid. REQUIRED
String tzid: A String representing a known time zone identifier from the IANA Time Zone Database.
*/

$postfields = array(
'available_period_id' => $params['available_period_id'],
'start' => $params['start'],
'end' => $params['end'],
);

if (!empty($params['tzid'])) {
$postFields['tzid'] = $params['tzid'];
}

return $this->httpPost("/" . self::API_VERSION . "/available_periods", $postfields);
}

public function deleteAvailablePeriod($params)
{
/*
String available_period_id: The String that uniquely identifies the available period. REQUIRED
returns true on success, associative array of errors on failure
*/

$postFields = ['available_period_id' => $params["available_period_id"]];

return $this->httpDelete("/" . self::API_VERSION . "/available_periods/", $postFields);
}

public function bulkDeleteAvailablePeriods()
{
return $this->httpDelete("/" . self::API_VERSION . "/available_periods", [
'delete_all' => true,
]);
}

public function getAvailabilityRule($availability_rule_id)
{
Expand Down
32 changes: 32 additions & 0 deletions tests/CronofyTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -676,4 +676,36 @@ public function testConferencingServiceAuthorization()
$this->assertNotNull($actual);
$this->assertEquals($actual, $response);
}

public function testDeleteAvailablePeriod()
{
$params = ["available_period_id" => "avp_456"];

$http = $this->createMock(HttpRequest::class);
$http->expects($this->once())
->method('httpDelete')
->with(
$this->equalTo('https://api.cronofy.com/v1/available_periods/'),
$this->equalTo($params),
$this->equalTo([
'Authorization: Bearer accessToken',
'Host: api.cronofy.com',
'Content-Type: application/json; charset=utf-8',
])
)
->will($this->returnValue(["{'foo': 'bar'}", 200]));

$cronofy = new Cronofy([
"client_id" => "clientId",
"client_secret" => "clientSecret",
"access_token" => "accessToken",
"refresh_token" => "refreshToken",
"http_client" => $http,
]);

$actual = $cronofy->deleteAvailablePeriod([
"available_period_id" => "avp_456",
]);
$this->assertNotNull($actual);
}
}

0 comments on commit 500592c

Please sign in to comment.