ferjul17/sellsy-api
最新稳定版本:1.0.1
Composer 安装命令:
composer require ferjul17/sellsy-api
包简介
PHP library which helps to call Sellsy's API
README 文档
README
PHP library which helps to call Sellsy's API
$client = new Client(['userToken' => 'xxx', 'userSecret' => 'xxx', 'consumerToken' => 'xxx', 'consumerSecret' => 'xxx', ]); var_dump($client->getService('Infos')->call('getInfos', [])); $promise = $client->getService('Infos')->callAsync('getInfos', [])->then(function($res) { var_dump($res); }); $promise->wait();
How to install
First of all you need 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
Setup the library
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.
require 'path/to/vendor/autoload.php'; use SellsyApi\Client; $client = new Client(['userToken' => 'xxx', 'userSecret' => 'xxx', 'consumerToken' => 'xxx', 'consumerSecret' => 'xxx', ]);
Call APIs
Once you have you client, you can retreive a Service by calling the method getService($serviceName):
$service = $client->getService('Accountdatas');
Finally, you can call an API with the method call($methodName, $params):
$response = $service->call('createUnit', ['unit' => ['value' => 'Kg']);
There's another method callAsync($methodName, $params) which send an asynchronous request and return a Promise:
$promise = $service->callAsync('createUnit', ['unit' => ['value' => 'Kg']); $response = $promise->wait();
You can find more information about Promise here.
Handle errors
In order to handle errors, you should use retryable version of the previous methodes: retryableCall($callable) and
retryableCallAsync($callable). In case of an error which is handle by the library, this one will try to send again the
requests by calling $callable.
$callable must be a function which return the parameters to give to the call() and callAsync() methods.
$callable takes 3 arguments:
- The instance of the
ServiceInterfaceused to send the call - The retry number. The first time this value is 0.
- The error received
var_dump($client->getService('Infos')->retryableCall(function (ServiceInterface $service, $retry, $e) { if ($retry > 3) { throw $e; } return ['getInfos', []]; })); $promise = $client->getService('Infos')->retryableCallAsync(function (ServiceInterface $service, $retry, $e) { if ($retry > 3) { throw $e; } return ['getInfos', []]; })->then(function ($res) { var_dump($res); }); $promise->wait();
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.
ferjul17/sellsy-api 适用场景与选型建议
ferjul17/sellsy-api 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 54.21k 次下载、GitHub Stars 达 14, 最近一次更新时间为 2015 年 12 月 20 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「api」 「library」 「sellsy」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 ferjul17/sellsy-api 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 ferjul17/sellsy-api 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 ferjul17/sellsy-api 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
PHP library to connect your applications to your Sellsy account account using the Sellsy API and build your websites and your platforms on the Sellsy technology.
PHP library to connect your applications to your Sellsy account account using the Sellsy API and build your websites and your platforms on the Sellsy technology.
A PSR-7 compatible library for making CRUD API endpoints
Inbox pattern process implementation for your Laravel Applications
Core library that defines common interfaces used by the rest of the intahwebz..
A cache strategy for Sellsy Api v1, build on top of Kevinrob Guzzle caceh middleware
统计信息
- 总下载量: 54.21k
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 15
- 点击次数: 18
- 依赖项目数: 1
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2015-12-20