Skip to content

Commit

Permalink
Merge pull request #95 from mogic-le/cal-source
Browse files Browse the repository at this point in the history
Add calendar source parameter
  • Loading branch information
freekmurze authored Sep 8, 2022
2 parents 65cea2b + fabbd23 commit a2c6d1d
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 0 deletions.
18 changes: 18 additions & 0 deletions src/Components/Calendar.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@ class Calendar extends Component implements HasTimezones

private ?string $productIdentifier = null;

private ?string $source = null;

public static function create(string $name = null): Calendar
{
return new self($name);
Expand Down Expand Up @@ -146,6 +148,18 @@ public function refreshInterval(int $minutes): Calendar
return $this;
}

/**
* Identifies a location where a client can retrieve updated data for the calendar.
*
* @link https://datatracker.ietf.org/doc/html/rfc7986#section-5.7
*/
public function source(string $source): self
{
$this->source = $source;

return $this;
}

public function get(): string
{
return $this->toString();
Expand Down Expand Up @@ -173,6 +187,10 @@ protected function payload(): ComponentPayload
$this->description,
fn () => TextProperty::create('DESCRIPTION', $this->description)->addAlias('X-WR-CALDESC')
)
->optional(
$this->source,
fn () => TextProperty::create('SOURCE', $this->source)->addParameter(new Parameter('VALUE', 'URI'))
)
->optional(
$this->refreshInterval,
fn () => DurationProperty::create('REFRESH-INTERVAL', $this->refreshInterval)->addParameter(new Parameter('VALUE', 'DURATION'))
Expand Down
12 changes: 12 additions & 0 deletions tests/Components/CalendarTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,18 @@ public function a_refresh_rate_can_be_set()
->expectParameterValue('VALUE', 'DURATION');
}

/** @test */
public function a_source_can_be_set()
{
$payload = Calendar::create()
->source('https://example.org/cal.ics')
->resolvePayload();

PropertyExpectation::create($payload, 'SOURCE')
->expectValue('https://example.org/cal.ics')
->expectParameterValue('VALUE', 'URI');
}

/** @test */
public function it_will_automatically_add_multiple_timezone_components()
{
Expand Down

0 comments on commit a2c6d1d

Please sign in to comment.