diff --git a/README.md b/README.md index f59c3c0..ded0342 100644 --- a/README.md +++ b/README.md @@ -57,7 +57,7 @@ Retrieve all information about multiple events. Basic usage: ```php -$parameters = new \HnutiBrontosaurus\BisClient\Request\Event\EventParameters(); +$parameters = new \HnutiBrontosaurus\BisClient\Event\Request\EventParameters(); $events = $client->getEvents($parameters); // $parameters are optional // example of reading data @@ -71,19 +71,19 @@ foreach ($events as $event) { Events can be filtered by group, category, program or intended for: ```php -$parameters = new \HnutiBrontosaurus\BisClient\Request\Event\EventParameters(); +$parameters = new \HnutiBrontosaurus\BisClient\Event\Request\EventParameters(); // only camps -$parameters->setGroup(\HnutiBrontosaurus\BisClient\Enums\EventGroup::CAMP()); +$parameters->setGroup(\HnutiBrontosaurus\BisClient\Event\Group::CAMP()); // only events of "voluntary" category -$parameters->setCategory(\HnutiBrontosaurus\BisClient\Enums\EventCategory::VOLUNTEERING()); +$parameters->setCategory(\HnutiBrontosaurus\BisClient\Event\Category::VOLUNTEERING()); // only events of "PsB" program -$parameters->setProgram(\HnutiBrontosaurus\BisClient\Enums\Program::HOLIDAYS_WITH_BRONTOSAURUS()); +$parameters->setProgram(\HnutiBrontosaurus\BisClient\Event\Program::HOLIDAYS_WITH_BRONTOSAURUS()); // only events intended for first time participants -$parameters->setIntendedFor(\HnutiBrontosaurus\BisClient\Enums\IntendedFor::FIRST_TIME_PARTICIPANT()); +$parameters->setIntendedFor(\HnutiBrontosaurus\BisClient\Event\IntendedFor::FIRST_TIME_PARTICIPANT()); $events = $client->getEvents($parameters); ``` @@ -91,19 +91,19 @@ $events = $client->getEvents($parameters); Note that each method call rewrites the previous one: ```php -$parameters->setCategory(\HnutiBrontosaurus\BisClient\Enums\EventCategory::VOLUNTEERING()); -$parameters->setCategory(\HnutiBrontosaurus\BisClient\Enums\EventCategory::EXPERIENCE()); +$parameters->setCategory(\HnutiBrontosaurus\BisClient\Event\Category::VOLUNTEERING()); +$parameters->setCategory(\HnutiBrontosaurus\BisClient\Event\Category::EXPERIENCE()); // ⚠ result is only "EXPERIENCE" ``` You can set more values at once with method's plural complement: ```php -$parameters = new \HnutiBrontosaurus\BisClient\Request\Event\EventParameters(); +$parameters = new \HnutiBrontosaurus\BisClient\Event\Request\EventParameters(); $parameters->setCategories([ - \HnutiBrontosaurus\BisClient\Enums\EventCategory::VOLUNTEERING(), - \HnutiBrontosaurus\BisClient\Enums\EventCategory::EXPERIENCE(), + \HnutiBrontosaurus\BisClient\Event\Category::VOLUNTEERING(), + \HnutiBrontosaurus\BisClient\Event\Category::EXPERIENCE(), ]); $events = $client->getEvents($parameters); @@ -114,11 +114,11 @@ $events = $client->getEvents($parameters); Restrict retrieved events to be in given period: ```php -$parameters = new \HnutiBrontosaurus\BisClient\Request\Event\EventParameters(); +$parameters = new \HnutiBrontosaurus\BisClient\Event\Request\EventParameters(); -$parameters->setPeriod(\HnutiBrontosaurus\BisClient\Request\Event\Period::RUNNING_AND_FUTURE()); // default -$parameters->setPeriod(\HnutiBrontosaurus\BisClient\Request\Event\Period::RUNNING_ONLY()); -$parameters->setPeriod(\HnutiBrontosaurus\BisClient\Request\Event\Period::UNLIMITED()); +$parameters->setPeriod(\HnutiBrontosaurus\BisClient\Event\Request\Period::RUNNING_AND_FUTURE()); // default +$parameters->setPeriod(\HnutiBrontosaurus\BisClient\Event\Request\Period::RUNNING_ONLY()); +$parameters->setPeriod(\HnutiBrontosaurus\BisClient\Event\Request\Period::UNLIMITED()); $events = $client->getEvents($parameters); ``` @@ -135,7 +135,7 @@ $parameters->setDateEndLessThanOrEqualTo($date); $parameters->setDateEndGreaterThanOrEqualTo($date); ``` -If you need to reset default/previous setting: +If you need to reset default/previous dates: ```php // either @@ -155,7 +155,7 @@ $parameters->setDateStartLessThanOrEqualTo($date, reset: true); Choose whether you want to order by start or end date: ```php -$parameters = new \HnutiBrontosaurus\BisClient\Request\Event\EventParameters(); +$parameters = new \HnutiBrontosaurus\BisClient\Event\Request\EventParameters(); // sort events by date from or date to $parameters->orderByStartDate(); @@ -164,7 +164,7 @@ $parameters->orderByEndDate(); // default $events = $client->getEvents($parameters); ``` -Both methods have optional parameter `bool $desc` which obviously sorts events in DESC order: +Both methods have optional parameter `$desc` which allows to sort events in DESC order: ```php $parameters->orderByDateFrom(desc: true); @@ -175,7 +175,7 @@ $parameters->orderByDateFrom(desc: true); Limit the size of obtained events or remove the limit completely: ```php -$parameters = new \HnutiBrontosaurus\BisClient\Request\Event\EventParameters(); +$parameters = new \HnutiBrontosaurus\BisClient\Event\Request\EventParameters(); $parameters->setLimit(50); $parameters->removeLimit(); @@ -189,7 +189,7 @@ $events = $client->getEvents($parameters); For retrieving information about all administration units: ```php -$parameters = new \HnutiBrontosaurus\BisClient\Request\AdministrationUnit\AdministrationUnitParameters(); +$parameters = new \HnutiBrontosaurus\BisClient\AdministrationUnit\Request\AdministrationUnitParameters(); $administrationUnits = $client->getAdministrationUnits($parameters); // $parameters is optional foreach ($administrationUnits as $administrationUnit) { @@ -205,7 +205,7 @@ foreach ($administrationUnits as $administrationUnit) { Retrieving information about all opportunities: ```php -$parameters = new \HnutiBrontosaurus\BisClient\Request\Opportunity\OpportunityParameters(); +$parameters = new \HnutiBrontosaurus\BisClient\Opportunity\Request\OpportunityParameters(); $opportunities = $client->getOpportunities($parameters); // $parameters is optional foreach ($opportunities as $opportunity) { @@ -283,9 +283,10 @@ composer install - `docs` – instruction on how connection between brontoweb and BIS works (todo: move to brontoweb repo) - `src` – source code - - `Enums` – basic enum types - - `Request` – request-related value objects - - `Response` – response-related value objects and exceptions + - `AdministrationUnit` – value objects related to administration units + - `Event` – value objects related to events + - `Opportunity` – value objects related to opportunities + - `Response` – response value objects common to all endpoints - `BisClient` – client itself, serves for making requests to BIS API - `BisClientFactory` – takes configuration and creates instance of `BisClient` - `HttpClient` – wrapper around Guzzle client which adds BIS API specific pieces into the request diff --git a/src/AdministrationUnit/Category.php b/src/AdministrationUnit/Category.php new file mode 100644 index 0000000..bc33208 --- /dev/null +++ b/src/AdministrationUnit/Category.php @@ -0,0 +1,23 @@ +categories = [$category]; return $this; } /** - * @param AdministrationUnitCategory[] $categories + * @param Category[] $categories */ public function setCategories(array $categories): self { diff --git a/src/Response/AdministrationUnit/AdministrationUnit.php b/src/AdministrationUnit/Response/AdministrationUnit.php similarity index 84% rename from src/Response/AdministrationUnit/AdministrationUnit.php rename to src/AdministrationUnit/Response/AdministrationUnit.php index ba91d23..3702425 100644 --- a/src/Response/AdministrationUnit/AdministrationUnit.php +++ b/src/AdministrationUnit/Response/AdministrationUnit.php @@ -1,8 +1,8 @@ category->equals(AdministrationUnitCategory::CLUB()); + return $this->category->equals(Category::CLUB()); } public function isBaseUnit(): bool { - return $this->category->equals(AdministrationUnitCategory::BASIC_SECTION()); + return $this->category->equals(Category::BASIC_SECTION()); } public function isRegionalUnit(): bool { - return $this->category->equals(AdministrationUnitCategory::REGIONAL_CENTER()); + return $this->category->equals(Category::REGIONAL_CENTER()); } public function isOffice(): bool { - return $this->category->equals(AdministrationUnitCategory::HEADQUARTER()); + return $this->category->equals(Category::HEADQUARTER()); } diff --git a/src/BisClient.php b/src/BisClient.php index cc070c3..8d77882 100644 --- a/src/BisClient.php +++ b/src/BisClient.php @@ -2,13 +2,12 @@ namespace HnutiBrontosaurus\BisClient; -use HnutiBrontosaurus\BisClient\Request\AdministrationUnit\AdministrationUnitParameters; -use HnutiBrontosaurus\BisClient\Request\Event\EventParameters; -use HnutiBrontosaurus\BisClient\Request\Opportunity\OpportunityParameters; -use HnutiBrontosaurus\BisClient\Request\QueryParameters; -use HnutiBrontosaurus\BisClient\Response\AdministrationUnit\AdministrationUnit; -use HnutiBrontosaurus\BisClient\Response\Event\Event; -use HnutiBrontosaurus\BisClient\Response\Opportunity\Opportunity; +use HnutiBrontosaurus\BisClient\AdministrationUnit\Request\AdministrationUnitParameters as AdministrationUnitParameters; +use HnutiBrontosaurus\BisClient\AdministrationUnit\Response\AdministrationUnit; +use HnutiBrontosaurus\BisClient\Event\Request\EventParameters as EventParameters; +use HnutiBrontosaurus\BisClient\Event\Response\Event; +use HnutiBrontosaurus\BisClient\Opportunity\Request\OpportunityParameters as OpportunityParameters; +use HnutiBrontosaurus\BisClient\Opportunity\Response\Opportunity; final class BisClient diff --git a/src/Enums/AdministrationUnitCategory.php b/src/Enums/AdministrationUnitCategory.php deleted file mode 100644 index 7682048..0000000 --- a/src/Enums/AdministrationUnitCategory.php +++ /dev/null @@ -1,23 +0,0 @@ -groups = [$group]; return $this; } /** - * @param EventGroup[] $groups + * @param \HnutiBrontosaurus\BisClient\Event\Group[] $groups */ public function setGroups(array $groups): self { @@ -53,17 +51,17 @@ public function setGroups(array $groups): self // category - /** @var EventCategory[] */ + /** @var \HnutiBrontosaurus\BisClient\Event\Category[] */ private array $categories = []; - public function setCategory(EventCategory $category): self + public function setCategory(Category $category): self { $this->categories = [$category]; return $this; } /** - * @param EventCategory[] $categories + * @param Category[] $categories */ public function setCategories(array $categories): self { @@ -74,7 +72,7 @@ public function setCategories(array $categories): self // program - /** @var Program[] */ + /** @var \HnutiBrontosaurus\BisClient\Event\Program[] */ private array $programs = []; public function setProgram(Program $program): self @@ -105,7 +103,7 @@ public function setIntendedFor(IntendedFor $intendedFor): self } /** - * @param IntendedFor[] $intendedFor + * @param \HnutiBrontosaurus\BisClient\Event\IntendedFor[] $intendedFor */ public function setMultipleIntendedFor(array $intendedFor): self { diff --git a/src/Request/Event/Ordering.php b/src/Event/Request/Ordering.php similarity index 90% rename from src/Request/Event/Ordering.php rename to src/Event/Request/Ordering.php index 28178fd..4284380 100644 --- a/src/Request/Event/Ordering.php +++ b/src/Event/Request/Ordering.php @@ -1,6 +1,6 @@ categories = [$category]; return $this; } /** - * @param OpportunityCategory[] $categories + * @param Category[] $categories */ public function setCategories(array $categories): self { diff --git a/src/Response/Opportunity/Opportunity.php b/src/Opportunity/Response/Opportunity.php similarity index 94% rename from src/Response/Opportunity/Opportunity.php rename to src/Opportunity/Response/Opportunity.php index 26b3acd..d6c6760 100644 --- a/src/Response/Opportunity/Opportunity.php +++ b/src/Opportunity/Response/Opportunity.php @@ -1,9 +1,9 @@ category; } diff --git a/src/Request/QueryParameters.php b/src/QueryParameters.php similarity index 79% rename from src/Request/QueryParameters.php rename to src/QueryParameters.php index 009c23d..94c73f6 100644 --- a/src/Request/QueryParameters.php +++ b/src/QueryParameters.php @@ -1,6 +1,6 @@ setCategories([ - AdministrationUnitCategory::CLUB(), - AdministrationUnitCategory::BASIC_SECTION(), - AdministrationUnitCategory::REGIONAL_CENTER(), - AdministrationUnitCategory::HEADQUARTER(), + Category::CLUB(), + Category::BASIC_SECTION(), + Category::REGIONAL_CENTER(), + Category::HEADQUARTER(), ]); $units = $client->getAdministrationUnits($params); foreach ($units as $unit) { diff --git a/tests/events.php b/tests/events.php index 5ccd9fc..3d51c5b 100644 --- a/tests/events.php +++ b/tests/events.php @@ -1,11 +1,11 @@ setGroups([ - EventGroup::CAMP(), - EventGroup::WEEKEND_EVENT(), - EventGroup::OTHER(), + Group::CAMP(), + Group::WEEKEND_EVENT(), + Group::OTHER(), ]); $params->setCategories([ - EventCategory::VOLUNTEERING(), - EventCategory::EXPERIENCE(), - EventCategory::EDUCATIONAL_LECTURE(), - EventCategory::EDUCATIONAL_COURSE(), - EventCategory::EDUCATIONAL_OHB(), - EventCategory::EDUCATIONAL_EDUCATIONAL(), - EventCategory::EDUCATIONAL_EDUCATIONAL_WITH_STAY(), - EventCategory::CLUB_MEETING(), - EventCategory::CLUB_LECTURE(), - EventCategory::FOR_PUBLIC(), - EventCategory::ECO_TENT(), - EventCategory::EXHIBITION(), - EventCategory::INTERNAL_VOLUNTEER_MEETING(), - EventCategory::INTERNAL_GENERAL_MEETING(), - EventCategory::INTERNAL_SECTION_MEETING(), + Category::VOLUNTEERING(), + Category::EXPERIENCE(), + Category::EDUCATIONAL_LECTURE(), + Category::EDUCATIONAL_COURSE(), + Category::EDUCATIONAL_OHB(), + Category::EDUCATIONAL_EDUCATIONAL(), + Category::EDUCATIONAL_EDUCATIONAL_WITH_STAY(), + Category::CLUB_MEETING(), + Category::CLUB_LECTURE(), + Category::FOR_PUBLIC(), + Category::ECO_TENT(), + Category::EXHIBITION(), + Category::INTERNAL_VOLUNTEER_MEETING(), + Category::INTERNAL_GENERAL_MEETING(), + Category::INTERNAL_SECTION_MEETING(), ]); $params->setPrograms([ Program::NONE(), diff --git a/tests/opportunities.php b/tests/opportunities.php index 166f859..250d457 100644 --- a/tests/opportunities.php +++ b/tests/opportunities.php @@ -1,8 +1,8 @@ setCategories([ - OpportunityCategory::ORGANIZING(), - OpportunityCategory::COLLABORATION(), - OpportunityCategory::LOCATION_HELP(), + Category::ORGANIZING(), + Category::COLLABORATION(), + Category::LOCATION_HELP(), ]); $opportunities = $client->getOpportunities($params); foreach ($opportunities as $opportunity) {