mcrock/allegroapi
Composer 安装命令:
composer require mcrock/allegroapi
包简介
library making allegro rest and soap api using easier
README 文档
README
Library that makes allegro rest and soap api using easier
Installation
This lib should be installed with composer
composer require mcrock/allegroapi
Requirements
- PHP >= 7.1 (please forgive me, i think it's time to say goodbye to PHP5)
REST Api usage
Usage of allegro rest api is very simple with this library.
Prepare credentials
First, you should create object Credentials, or implement CredentialsInterface in your own class.
$credentials = new Credentials([ 'restClientId' => 'yourClientId', 'restClientSecret' => 'yourClientSecret', 'restApiKey' => 'yourApiKey', 'restRedirectUri' => 'yourRedirectUri', 'soapApiKey' => 'yourSoapApiKey', ]);
Get your token
Every operation in REST Api needs OAuth token. You can easily get it with this library.
$client = new RestClient($credentials); $authService = $client->getAuthService(); //now redirect to URL generated from this method: header('Location: '.$authService->getAuthUrl());
After logging in Allegro.pl you will be redirected to your RedirectUrl with auth code in query string. What next?
$code = $_GET['code']; $token = $authService->getNewToken($code);
You can store Token serializing it, or storing it's values. You can also implement TokenInterface to create a solution that suits your needs.
If your token has expired, just generate new one with this method:
$newToken = $authService->refreshToken($token);
Usage of API methods
The best explanation how to use it will be some example, so here it is:
$request = new Request('GET', 'pricing/offer-quotes', null, ['offer.id' => '123123123']); $response = $client->sendRequest($token, $request); var_dump(json_decode((string) $response->getBody()));
With that simple way you can use all api methods. Alternative method is use prepared request classes.
Ready-to-use request classes location: here I already covered almost all rest api methods. I'll try to create all to cover 100%.
Of course you can create your own, just implement RequestInterface. It's very simple.
Example:
$request = new PutChangePriceCommandRequest('123123123', '123.45'); $response = $client->sendRequest($token, $request); var_dump(json_decode((string) $response->getBody()));
Exceptions
I've created two Exception classes: InvalidRequestMethodException - just means that you used wrong HTTP method name in your request. UnauthorizedClientException - you should catch it just to know when refreshing token is necessary.
SOAP API
There is a class AllegroApiSoapClient inside this lib, and you can use it, by so far I got no time to finish it. It should work ok, but I need some time to document it.
Sandbox
Allegro Api Sandbox is problematic. It almost never works properly, so if you want to test your app, just use production API. Trust me, there is no good reason to implement Sandbox endpoints :)
Few ending words
If you have any suggestions, or noticed any issues, feel free to report it, or contact me.
mcrock/allegroapi 适用场景与选型建议
mcrock/allegroapi 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 151 次下载、GitHub Stars 达 0, 最近一次更新时间为 2018 年 09 月 13 日, 在 PHP 生态内属于活跃度较高的组件。
我们在过去多个企业项目中使用过 mcrock/allegroapi 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 mcrock/allegroapi 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
统计信息
- 总下载量: 151
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 3
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2018-09-13