Skip to content

Commit

Permalink
Merge branch 'release/v1.1'
Browse files Browse the repository at this point in the history
  • Loading branch information
sjhand committed Feb 11, 2023
2 parents d78044f + f830f84 commit d66cd61
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 3 deletions.
8 changes: 7 additions & 1 deletion .env.example
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
# Debugging mode
DEBUG_MODE="false"

# Security key preventing public access
SECRET_KEY=""

Expand All @@ -14,4 +17,7 @@ NOTION_DATE_PROPERTY_NAME="Date"
NOTION_STATUS_PROPERTY_NAME="Status"

# Notion status to exclude in the iCal feed
NOTION_EXCLUDE_STATUS = "Done"
NOTION_EXCLUDE_STATUS="Done"

#Suggested update frequency for clients in ISO 8601 format
TTL="PT5M"
6 changes: 5 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
#Changelog
# Changelog
## 1.1
### Added
* Debug mode
* Suggested refresh interval for clients

## 1.0
* Initial release
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@ Make sure you add the key in the 'k' GET variable.

To run this script, you will need to add the following environment variables to your .env file

`DEBUG_MODE` Debugging mode (prints content if true)

`SECRET_KEY` Security key preventing public access

`NOTION_API_KEY` Notion API key
Expand All @@ -41,6 +43,8 @@ To run this script, you will need to add the following environment variables to

`NOTION_EXCLUDE_STATUS` Notion status to exclude in the iCal feed

`TTL` Suggested update frequency for clients in [ISO 8601](https://en.wikipedia.org/wiki/ISO_8601#Durations) format

## Changelog

Can be found [here](CHANGELOG.md)
17 changes: 16 additions & 1 deletion index.php
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@
'direction' => 'descending',
]
],
]),
], JSON_THROW_ON_ERROR),
'headers' => [
'Accept' => 'application/json',
'Authorization' => 'Bearer ' . $_ENV['NOTION_API_KEY'],
Expand All @@ -58,6 +58,8 @@
]);
} catch (GuzzleException $e) {
die($e->getMessage());
} catch (JsonException $e) {
die($e->getMessage());
}

$result = json_decode($response->getBody(), false);
Expand All @@ -83,9 +85,22 @@

// Create calendar
$calendar = new Calendar($events);
try {
$dateInterval = new DateInterval($_ENV['TTL'] ?? 'PT5M');
} catch (Exception $e) {
die($e->getMessage());
}
$calendar->setPublishedTTL($dateInterval);
$componentFactory = new CalendarFactory();
$calendarComponent = $componentFactory->createCalendar($calendar);

if (isset($_ENV['DEBUG_MODE']) && $_ENV['DEBUG_MODE'] === 'true') {
echo '<pre>';
echo $calendarComponent;
echo '</pre>';
exit();
}

header('Content-Type: text/calendar; charset=utf-8');
header('Content-Disposition: attachment; filename="cal.ics"');
echo $calendarComponent;
Expand Down

0 comments on commit d66cd61

Please sign in to comment.