robsonsanches/stays-php-client
Composer 安装命令:
composer require robsonsanches/stays-php-client
包简介
PHP client for server-side integration with Stays API v1 (unofficial library)
README 文档
README
PHP client for server-side integration with Stays API v1 (unofficial library)
Table of contents:
- Requirements
- Installation
- Getting started
- Setup
- Making Requests
- Using Responses
- Docs
- License
- Release History
Requirements
- PHP >= 7.3
- Composer
Installation
composer require robsonsanches/stays-php-client
Getting started
To obtain API credentials please read the Stays API Docs https://stays.net/external-api/#introduction.
Setup
Setup for the Stays API integration:
require '/vendor/autoload.php'; use RobsonSanches\Stays\Client\Client; $stays = new Client($domain, $clientId, $clientSecret, $options);
Client Parameters
| Parameter | Type | Required | Description |
|---|---|---|---|
$domain |
string |
yes | System's domain, example: https://play.stays.net/ |
$clientId |
string |
yes | API Client ID |
$clientSecret |
string |
yes | API Client Secret |
$options |
array |
no | Additional options (see additional options table) |
Additional options
| Option | Type | Required | Description |
|---|---|---|---|
type |
string |
no | API type, default is external |
version |
string |
no | API version, default is v1 |
timeout |
number |
no | Request timeout, default is 2.0 |
response_format |
string |
no | Response format (array, object or string), default is array |
http_errors |
bool |
no | Set to false to disable throwing exceptions, default is true |
http_client_options |
array |
no | Guzzle HTTP client options |
Making Requests
You may use the get, post, patch, and delete methods to make requests to Stays API.
Request Methods
$stays->get($endpoint, $query = [], $headers = []) $stays->post($endpoint, $data = [], $headers = []) $stays->patch($endpoint, $data = [], $headers = []) $stays->delete($endpoint, $query = [], $headers = [])
Arguments
| Parameter | Type | Description |
|---|---|---|
$endpoint |
string |
Stays API endpoint, example: content/groups |
$data |
array |
Only for POST and PATCH, data that will be converted to JSON |
$query |
array |
Only for GET and DELETE, request query string |
$headers |
array |
Additional http headers |
Using Responses
All the request methods will return a response that can be a multidimensional array, array of objects or JSON string on success. If is present the argument http_errors = true, will throwing ClientException error on failure.
use RobsonSanches\Stays\Client\ClientException; try { $results = $stays->get('content/groups'); print_r( $results, true ); // array or JSON string } catch (ClientException $e) { echo $e->getMessage(); // Exception message. }
To get the response data from Http Client:
$response = $stays->http()->getResponse(); echo $response->getReasonPhrase(); // Reason phrase (string). echo $response->getStatusCode(); // Response code (int). echo $response->getBody()->getContents(); // Response body (JSON). print_r( $response->getHeaders() ); // Response headers (array). print_r( $response->getBody() ); // PSR-7 StreamInterface (object).
If you need to get the last requested data:
$request = $stays->http()->getRequest(); echo $request->getUri(); // Requested URI (string). echo $request->getMethod(); // Request method (string). echo $request->getBody()->getContents(); // Request body content (JSON). print_r( $request->getHeaders() ); // Request headers (array). print_r( $request->getUri() ); // PSR-7 UriInterface (object). print_r( $request->getBody() ); // PSR-7 StreamInterface (object).
Docs
Licence
Release History
- 2022-02-20 - 1.0.0 - Initial release.
robsonsanches/stays-php-client 适用场景与选型建议
robsonsanches/stays-php-client 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 4 次下载、GitHub Stars 达 1, 最近一次更新时间为 2022 年 02 月 20 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「php」 「api」 「client」 「stays」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 robsonsanches/stays-php-client 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 robsonsanches/stays-php-client 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 robsonsanches/stays-php-client 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
A PSR-7 compatible library for making CRUD API endpoints
Mock PSR-18 HTTP client
Asynchronous MQTT client built on React
Client for Google Directions API to add interpolated points to a route consisting of given coordinates.
Alfabank REST API integration
A Flickr wrapper to allow you to call the Flickr api with Guzzle as the backend.Goal is to have 100% Flickr api coverage rather than just upload/display photos (currently at 23%).
统计信息
- 总下载量: 4
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 1
- 点击次数: 2
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2022-02-20