项目作者: ma-residence

项目描述 :
The official ma-residence.fr's PHP SDK
高级语言: PHP
项目地址: git://github.com/ma-residence/php-sdk.git
创建时间: 2016-08-12T14:55:46Z
项目社区:https://github.com/ma-residence/php-sdk

开源协议:

下载


php-sdk

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 :

  1. {
  2. "require": {
  3. "ma-residence/php-sdk": "2.0.*"
  4. },
  5. "repositories": [
  6. {
  7. "type": "vcs",
  8. "url": "https://github.comma-residence/php-sdk.git",
  9. "no-api": true
  10. }
  11. ]
  12. }

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

  1. <?php
  2. use MR\SDK\Client;
  3. $host = 'https://api.ensembl.fr/';
  4. $clientId = 'CLIENT_ID';
  5. $clientSecret = 'CLIENT_SECRET';
  6. $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.

  1. <?php
  2. $storage = new MyTokenStorage();
  3. $mrClient = new Client($host, $clientId, $clientSecret, $storage);

After you have initialized the class, you can login with an email and password:

  1. $mrClient->auth()->loginWithCredentials('developpeur@ma-residence.fr', 'password');

Or with an external token:

  1. $mrClient->auth()->loginWithExternalToken('facebook', 'FACEBOOK_ACCESS_TOKEN');

And if to logout:

  1. $mrClient->auth()->logout();

Endpoints

  1. $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:

  1. // GET Request
  2. $mrClient->request()->get('/foo', [ 'id' => $id ]);
  3. // POST Request
  4. $mrClient->request()->post('/foo', [], [
  5. 'field_a' => 'A',
  6. 'field_b' => 'B',
  7. ]);
  8. // PUT Request
  9. $mrClient->request()->put('/foo', [], [
  10. 'field_a' => 'AA',
  11. 'field_b' => 'BB',
  12. ]);
  13. // PATCH Request
  14. $mrClient->request()->patch('/foo', [], [
  15. 'field_b' => 'C',
  16. ]);
  17. // DELETE Request
  18. $mrClient->request()->delete('/foo');

Each request returns a Response object.