Official PHP SDK for ma-residence's API.
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.
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
}
]
}
docker run -it --name docker-php-sdk --rm -v "$PWD/php-sdk:/user/src/php-sdk" -w /user/src/php-sdk composer composer update
<?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('[email protected]', 'password');
Or with an external token:
$mrClient->auth()->loginWithExternalToken('facebook', 'FACEBOOK_ACCESS_TOKEN');
And if to logout:
$mrClient->auth()->logout();
$mrClient->myEndpoint()->foo();
Available endpoints:
- Me
- User
- Groups
- Associations
- CityHalls
- Categories
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.