openclassrooms / front-desk
Front Desk Library
Installs: 3 913
Dependents: 1
Suggesters: 0
Security: 0
Stars: 1
Watchers: 28
Forks: 0
Open Issues: 0
Requires
- php: >=5.6
- guzzlehttp/guzzle: ~6.0
- nesbot/carbon: ~1.8
Requires (Dev)
- phpunit/phpunit: ~5.5
- satooshi/php-coveralls: dev-master
README
FrontDesk
This is a PHP5 library that provides FrontDesk Core API functionality in your application.
Install
The easiest way to install FrontDesk Library is via composer.
Create the following composer.json
file and run the php composer.phar install
command to install it.
{ "require": { "openclassrooms/front-desk": "*" } }
<?php require 'vendor/autoload.php'; use OpenClassrooms\FrontDesk\Services\PackService; use OpenClassrooms\FrontDesk\Services\PersonService; //do things
USAGE
Instanciation
If you plan to use FrontDesk in a Symfony2 project, check out the FrontDeskBundle. The bundle provides an easy configuration option for this library.
Factory
The library provides a factory to create a client
use OpenClassrooms\FrontDesk\Client\Impl\ClientFactoryImpl; $factory = new ClientFactoryImpl(); $client = $factory->createCoreApi('your_front_desk_server_name', 'your_token'); \\ $client = $factory->createReportingApi('your_front_desk_server_name', 'your_token');
ENDPOINTS
ENROLLMENT
Gateway
use OpenClassrooms\FrontDesk\Repository\PackRepository; $enrollmentGateway = new EnrollmentRepository(); $enrollmentGateway->setReportingApiClient($client);
Services
Services Instanciation
use OpenClassrooms\FrontDesk\Services\Impl\EnrollmentServiceImpl; $service = new EnrollmentServiceImpl(); $service->setEnrollmentGateway($enrollmentGateway);
Create Query
... $service->query($field, $filter, $limit);
PACK
Gateway
use OpenClassrooms\FrontDesk\Repository\PackRepository; $packGateway = new PackRepository(); $packGateway->setCoreApiClient($client);
Builder
use OpenClassrooms\FrontDesk\Models\PersonBuilder; $pack = $packBuilder ->create() ->withCount(5) ->withEndDate(new \DateTime()) ->withPersonIds([21987]) ->withStartDate(new \DateTime()) ->build();
Services
Services Instanciation
use OpenClassrooms\FrontDesk\Services\Impl\PackServiceImpl; $service = new PackServiceImpl(); $service->setPackGateway($packGateway);
Create Pack
... $service->create($pack, $packProductId);
Delete Pack by id
... $service->deletePack($packId);
PERSON
Gateway
use OpenClassrooms\FrontDesk\Repository\PersonRepository; $personGateway = new PersonRepository(); $personGateway->setCoreApiClient($client); $personGateway->setPersonBuilder(new PersonBuilderImpl());
Builder
The library provides a builder to create a Person:
use OpenClassrooms\FrontDesk\Models\PersonBuilder; $person = $personBuilder->create() ->withAddress('address') ->withEmail('email') ->withFirstName('first_name') ->withJoinedAt(new \DateTime()) ->withLastName('last_name') ... ->build();
Services
Services Instanciation
use OpenClassrooms\FrontDesk\Services\Impl\PersonServiceImpl; $service = new PersonServiceImpl(); $service->setPersonGateway($personGateway);
Post a person
$service->create($person);
Put a person
$service->update($person);
Get person by id
$service->find($personId);
Get all the people
$service->findAll($page);
Search person by query
$service->search($query);
PLAN
Gateway
Gateway
The library provides Gateway for a person, a pack, a plan and a visit:
$planGateway = new PlanRepository(); $planGateway->setCoreApiClient($client); $planGateway->setPlanBuilder(new PlanBuilderImpl());
Services
Services Instanciation
$service = new PlanServiceImpl(); $service->setPlanGateway($planGateway);
Get Plans by person id
$service->getPlans($personId);
VISIT
Gateway
use OpenClassrooms\FrontDesk\Repository\VisitRepository; $visitGateway = new VisitRepository(); $visitGateway->setCoreApiClient($client); $visitGateway->setVisitBuilder(new VisitBuilderImpl());
Services
Services Instanciation
$service = new VisitServiceImpl(); $service->setVisitGateway($visitGateway);
Get Visit by person id
$service->getVisits($personId, $from, $to);
Delete Visit by id
$service->deleteVisit($visitId);