ma-residence / php-sdk
Requires
- php: 8.*
- guzzlehttp/guzzle: 7.5.*
- symfony/cache: 5.4.*
Requires (Dev)
- phpunit/phpunit: 8.*
- symfony/browser-kit: 6.2.*
- symfony/dom-crawler: 6.2.*
- symfony/dotenv: ^6.2
- symfony/var-dumper: 6.2.*
- symfony/var-exporter: 6.2.*
README
Official PHP SDK for ma-residence's API.
Get started
To use ma-residence's API, you have to register your application. When registering your application, you will obtain a client_id and client_secret. The client_id and client_secret will be necessary to use the API.
Installation
Edit your composer.json
:
{ "require": { "ma-residence/php-sdk": "2.0.*" }, "repositories": [ { "type": "vcs", "url": "https://github.comma-residence/php-sdk.git", "no-api": true } ] }
Composer Update
docker run -it --name docker-php-sdk --rm -v "$PWD/php-sdk:/user/src/php-sdk" -w /user/src/php-sdk composer composer update
Usage
<?php use MR\SDK\Client; $host = 'https://api.ensembl.fr/'; $clientId = 'CLIENT_ID'; $clientSecret = 'CLIENT_SECRET'; $mrClient = new Client($host, $clientId, $clientSecret);
By default, the Client
will store the tokens in memory.
If you need to implement a custom token storage, you can use the TokenStorageInterface
and assigned it to the Client
.
<?php $storage = new MyTokenStorage(); $mrClient = new Client($host, $clientId, $clientSecret, $storage);
After you have initialized the class, you can login with an email and password:
$mrClient->auth()->loginWithCredentials('developpeur@ma-residence.fr', 'password');
Or with an external token:
$mrClient->auth()->loginWithExternalToken('facebook', 'FACEBOOK_ACCESS_TOKEN');
And if to logout:
$mrClient->auth()->logout();
Endpoints
$mrClient->myEndpoint()->foo();
Available endpoints:
- Me
- User
- Groups
- Associations
- CityHalls
- Categories
Request
If you have to call an url which has no endpoint, you can still do your own request:
// GET Request $mrClient->request()->get('/foo', [ 'id' => $id ]); // POST Request $mrClient->request()->post('/foo', [], [ 'field_a' => 'A', 'field_b' => 'B', ]); // PUT Request $mrClient->request()->put('/foo', [], [ 'field_a' => 'AA', 'field_b' => 'BB', ]); // PATCH Request $mrClient->request()->patch('/foo', [], [ 'field_b' => 'C', ]); // DELETE Request $mrClient->request()->delete('/foo');
Each request returns a Response
object.