Skip to content

Commit

Permalink
Add getEventInfo().
Browse files Browse the repository at this point in the history
  • Loading branch information
westy92 committed Dec 29, 2022
1 parent ca9246a commit 7cbff4c
Show file tree
Hide file tree
Showing 11 changed files with 396 additions and 1 deletion.
22 changes: 22 additions & 0 deletions src/Client.php
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,9 @@ public function __construct(string $apiKey)
$this->client = $this->clientBuilder();
}

/**
* Gets the Events for the provided Date
*/
public function getEvents(?string $date = null, bool $adult = false, ?string $timezone = null): Model\GetEventsResponse
{
$params = ['adult' => var_export($adult, true)];
Expand All @@ -67,6 +70,25 @@ public function getEvents(?string $date = null, bool $adult = false, ?string $ti
return $this->request('events', $params, Model\GetEventsResponse::class);
}

/**
* Gets the Event Info for the provided Event
*/
public function getEventInfo(string $id, ?int $start = null, ?int $end = null): Model\GetEventInfoResponse {
if (empty($id)) {
throw new \InvalidArgumentException('Event id is required.');
}
$params = [
'id' => $id,
];
if ($start != null) {
$params['start'] = intval($start);
}
if ($end != null) {
$params['end'] = intval($end);
}
return $this->request('event', $params, Model\GetEventInfoResponse::class);
}

/**
* Searches for Events with the given criteria
*/
Expand Down
32 changes: 32 additions & 0 deletions src/model/AlternateName.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
<?php

namespace Westy92\HolidayEventApi\Model;

use Symfony\Component\Serializer\Annotation\SerializedName;

/**
* Information about an Event's Alternate Name
*/
final class AlternateName
{
/**
* An Event's Alternate Name
*/
public string $name;
/**
* The first year this Alternate Name was in effect (null implies none or unknown)
*/
#[SerializedName('first_year')]
public ?int $firstYear;
/**
* The last year this Alternate Name was in effect (null implies none or unknown)
*/
#[SerializedName('last_year')]
public ?int $lastYear;

public function __construct(string $name, ?int $firstYear, ?int $lastYear) {
$this->name = $name;
$this->firstYear = $firstYear;
$this->lastYear = $lastYear;
}
}
73 changes: 73 additions & 0 deletions src/model/EventInfo.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
<?php

namespace Westy92\HolidayEventApi\Model;

use Symfony\Component\Serializer\Annotation\SerializedName;
/**
* Information about an Event
*/
final class EventInfo extends EventSummary
{
/**
* Whether this Event is unsafe for children or viewing at work
*/
public bool $adult;
/**
* The Event's Alternate Names
* @var AlternateName[]
*/
#[SerializedName('alternate_names')]
public array $alternateNames;
/**
* The Event's hashtags
* @var ?string[]
*/
public ?array $hashtags;
/**
* The Event's images
*/
public ?ImageInfo $image;
/**
* The Event's sources
* @var ?string[]
*/
public ?array $sources;
/**
* The Event's description
*/
public ?RichText $description;
/**
* How to observe the Event
*/
#[SerializedName('how_to_observe')]
public ?RichText $howToObserve;
/**
* Patterns defining when the Event is observed
* @var ?Pattern[]
*/
public ?array $patterns;
/**
* The Event's founders
* @var ?FounderInfo[]
*/
public ?array $founders;
/**
* The Event Occurrences (when it occurs)
* @var ?Occurrence[]
*/
public ?array $occurrences;

public function __construct(bool $adult, array $alternateNames, ?array $hashtags, ?ImageInfo $image, ?array $sources, ?RichText $description, ?RichText $howToObserve, ?array $patterns, ?array $founders, ?array $occurrences, string $id, string $name, string $url) {
$this->adult = $adult;
$this->alternateNames = $alternateNames;
$this->hashtags = $hashtags;
$this->image = $image;
$this->sources = $sources;
$this->description = $description;
$this->howToObserve = $howToObserve;
$this->patterns = $patterns;
$this->founders = $founders;
$this->occurrences = $occurrences;
parent::__construct(id: $id, name: $name, url: $url);
}
}
2 changes: 1 addition & 1 deletion src/model/EventSummary.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
/**
* A summary of an Event
*/
final class EventSummary
class EventSummary
{
/**
* The Event Id
Expand Down
28 changes: 28 additions & 0 deletions src/model/FounderInfo.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
<?php

namespace Westy92\HolidayEventApi\Model;

/**
* Information about an Event Founder
*/
final class FounderInfo
{
/**
* The Founder's name
*/
public string $name;
/**
* A link to the Founder
*/
public ?string $url;
/**
* The date the Event was founded
*/
public ?string $date;

public function __construct(string $name, ?string $url, ?string $date) {
$this->name = $name;
$this->url = $url;
$this->date = $date;
}
}
18 changes: 18 additions & 0 deletions src/model/GetEventInfoResponse.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<?php

namespace Westy92\HolidayEventApi\Model;
/**
* The Response returned by getEventInfo
*/
final class GetEventInfoResponse extends StandardResponse
{
/**
* The Event Info
*/
public EventInfo $event;

public function __construct(EventInfo $event, ?RateLimit $rateLimit = null) {
$this->event = $event;
parent::__construct($rateLimit);
}
}
28 changes: 28 additions & 0 deletions src/model/ImageInfo.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
<?php

namespace Westy92\HolidayEventApi\Model;

/**
* Information about an Event image
*/
final class ImageInfo
{
/**
* A small image
*/
public string $small;
/**
* A medium image
*/
public string $medium;
/**
* A large image
*/
public string $large;

public function __construct(string $small, string $medium, string $large) {
$this->small = $small;
$this->medium = $medium;
$this->large = $large;
}
}
23 changes: 23 additions & 0 deletions src/model/Occurrence.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
<?php

namespace Westy92\HolidayEventApi\Model;

/**
* Information about an Event's Occurrence
*/
final class Occurrence
{
/**
* The date or timestamp the Event occurs
*/
public string $date;
/**
* The length (in days) of the Event occurrence
*/
public int $length;

public function __construct(string $date, int $length) {
$this->date = $date;
$this->length = $length;
}
}
49 changes: 49 additions & 0 deletions src/model/Pattern.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
<?php

namespace Westy92\HolidayEventApi\Model;

use Symfony\Component\Serializer\Annotation\SerializedName;

/**
* Information about an Event's Pattern
*/
final class Pattern
{
/**
* The first year this event is observed (null implies none or unknown)
*/
#[SerializedName('first_year')]
public ?int $firstYear;
/**
* The last year this event is observed (null implies none or unknown)
*/
#[SerializedName('last_year')]
public ?int $lastYear;
/**
* A description of how this event is observed (formatted as plain text)
*/
public string $observed;
/**
* A description of how this event is observed (formatted as HTML)
*/
#[SerializedName('observed_html')]
public string $observedHtml;
/**
* A description of how this event is observed (formatted as Markdown)
*/
#[SerializedName('observed_markdown')]
public string $observedMarkdown;
/**
* For how many days this event is celebrated
*/
public int $length;

public function __construct(?int $firstYear, ?int $lastYear, string $observed, string $observedHtml, string $observedMarkdown, int $length) {
$this->firstYear = $firstYear;
$this->lastYear = $lastYear;
$this->observed = $observed;
$this->observedHtml = $observedHtml;
$this->observedMarkdown = $observedMarkdown;
$this->length = $length;
}
}
28 changes: 28 additions & 0 deletions src/model/RichText.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
<?php

namespace Westy92\HolidayEventApi\Model;

/**
* Formatted Text
*/
final class RichText
{
/**
* Formatted as plain text
*/
public ?string $text;
/**
* Formatted as HTML
*/
public ?string $html;
/**
* Formatted as Markdown
*/
public ?string $markdown;

public function __construct(?string $text, ?string $html, ?string $markdown) {
$this->text = $text;
$this->html = $html;
$this->markdown = $markdown;
}
}

0 comments on commit 7cbff4c

Please sign in to comment.