From 99eb7a75f445c0498941e305e14d766619c410dd Mon Sep 17 00:00:00 2001 From: Julien Ferrier Date: Sun, 27 Dec 2015 14:30:58 +0100 Subject: [PATCH] fix Improve README.md #3 --- README.md | 73 +++++++++++++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 71 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index dfb7c0f..03f2a33 100644 --- a/README.md +++ b/README.md @@ -1,5 +1,5 @@ -Sellsy Client Library -======================= +Sellsy API Client Library +========================= [![Build Status](https://travis-ci.org/ferjul17/Sellsy-api.svg?branch=master)](https://travis-ci.org/ferjul17/Sellsy-api) [![Coverage Status](https://coveralls.io/repos/ferjul17/Sellsy-api/badge.svg?branch=master&service=github)](https://coveralls.io/github/ferjul17/Sellsy-api?branch=master) @@ -18,3 +18,72 @@ $promise = $client->getService('Infos')->callAsync('getInfos', [])->then(functio }); $promise->wait(); ``` + +How to install +-------------- + +First of all you need [Composer](https://getcomposer.org/doc/00-intro.md "Introduction - Composer"): + + php -r "readfile('https://getcomposer.org/installer');" | php + +Then add Sellsy API as a dependency of your project: + + php composer.phar require ferjul17/sellsy-api + +How to use +---------- + +The library provide you a class called `Service` which represent a part of the Sellsy's API. +The service allows you to call api associated to this module. +For instance, the service `Accountdatas` allows to call all method which start with Accountdatas in Sellsy's API, like Accountdatas.getTaxe or Accountdatas.updateUnit + +The Services are created by a factory called `Client`. So you first need to create a `Client` before having a `Service`. +To create a client just call its constructor. Its first argument is an array which contains the configuration. +You must provide the credentials to call the API which include the user token and secret, and the consumer token and secret that you can find in Sellsy interface. + +```php +$client = new Client(['userToken' => 'xxx', 'userSecret' => 'xxx', + 'consumerToken' => 'xxx', 'consumerSecret' => 'xxx', + ]); +``` + +Once you have you client, you can retreive a `Service` by calling the method `getService($serviceName)`: + +```php +$service = $client->getService('Accountdatas'); +``` + +Finally, you can call an API with the method `call($methodName, $params)`: + +```php +$response = $service->call('createUnit', ['unit' => ['value' => 'Kg']); +``` + +There's another method `callAsync($methodName, $params)` which send an asynchronous request and return a `Promise`: + +```php +$promise = $service->callAsync('createUnit', ['unit' => ['value' => 'Kg']); +$response = $promise->wait(); +``` + +You can find more information about `Promise` [here](https://github.com/guzzle/promises "Github of Guzzle Promises"). + +How to run tests +---------------- + +If you want to test this library, you can run the test suite clone this repository: + + git clone https://github.com/ferjul17/Sellsy-api.git + +then install dependencies: + + composer update + +than run the tests: + + vendor/phpunit/phpunit/phpunit + +License +------- + +Sellsy API is an open-source project released under the MIT license. See the `LICENSE` file for more information.