filipovi / php-sdk-1

The official ma-residence.fr's PHP SDK

Home Page:https://api.ma-residence.fr

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

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 :

{
    "require": {
        "ma-residence/php-sdk": "dev-master"
    },
    "repositories": [
        {
            "type": "vcs",
            "url":  "git@github.com:ma-residence/php-sdk.git",
            "no-api": true
        }
    ]
}

And don't forget to run:

$ composer update

Usage

To user the client, you need to instantiate a Client with your clientId, clientSecret of your application and host of the API.

<?php

use MR\SDK\Client;

$host = 'https://api.ma-residence.fr/';
$clientId = 'CLIENT_ID';
$clientSecret = 'CLIENT_SECRET';

$mrClient = new Client($host, $clientId, $clientSecret);

By default, the Client will store tokens in the memory. But if you need to implement a custom token storage, you can use 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 (after login with facebook for example) :

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

And if you want to logout to do some requests anonymously, do the following :

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

About

The official ma-residence.fr's PHP SDK

https://api.ma-residence.fr


Languages

Language:PHP 100.0%