fw4 / organimmo-rental-api
用于实现 Organimmo 租赁 API 的 PHP 库
v1.3.0
2024-08-13 13:54 UTC
Requires
- php: ^7.4|^8.0|^8.1
- caseyamcl/guzzle_retry_middleware: ^2.10
- guzzlehttp/guzzle: ~6.3|~7.0
- league/oauth2-client: ^2.6
- ocramius/package-versions: ^2.1
Requires (Dev)
- phpunit/phpunit: ^9.0
This package is auto-updated.
Last update: 2024-09-13 14:03:06 UTC
README
Organimmo 租赁 API 的 PHP 客户端。有关使用条款和 API 凭据,请参阅官方文档。
安装
composer require fw4/organimmo-rental-api
用法
use Organimmo\Rental\Organimmo; $client = new Organimmo('customer-id'); // Retrieve existing access token from storage (getAccessTokenFromDataStore to be implemented) $accessToken = getAccessTokenFromDataStore(); if (empty($accessToken) || $accessToken->hasExpired()) { // Request and store new access token (saveAccessTokenToDataStore to be implemented) $accessToken = $client->requestAccessToken('client-id', 'client-secret', 'username', 'password'); saveAccessTokenToDataStore($accessToken); } else { $client->setAccessToken($accessToken); }
所有端点都作为 Organimmo 类的方法可用。有关可用端点和响应格式的更多信息,请参阅官方 API 文档。
通过 ID 获取对象
在端点上调用 get($id)
以通过 ID 获取特定对象。如果没有存在具有提供 ID 的对象,则返回 null。
$country = $client->countries()->get(1); if (is_null($country)) echo 'Country does not exist' . PHP_EOL; else echo $country->name . PHP_EOL;
列出对象
在端点上调用 get()
以获取对象的遍历列表。所需的分页操作将自动执行。
$countries = $client->countries()->get(); foreach ($countries as $country) { echo $country->name . PHP_EOL; }
端点中的相关对象
$rental_unit_id = 1; $photos = $client->rentalUnits()->photos($rental_unit_id)->get();
响应可能包含对相关对象的引用。这些对象的实际数据默认不在响应中,但可以通过在指针对象上调用 get()
来轻松检索。
预取相关对象
$city = $client->cities()->get(1); $country = $city->country->get(); echo $country->name . PHP_EOL;
可以使用 depth
方法预取相关对象。传递从 1 到 5 的整数以确定预取的级别。
$city = $client->cities()->depth(1)->get(1); echo $city->country->name . PHP_EOL;
排序结果
使用 sort('fieldname')
方法按特定属性排序结果。
$countries = $client->countries()->sort('name')->get();
按日期过滤结果
使用 from($date)
和 to($date)
方法按修改或创建日期过滤结果。这些方法接受 DateTime 对象。
$countries = $client->countries()->from(date_create('2020-01-01'))->to(date_create('2020-06-01'))->get();
许可证
fw4/organimmo-rental-api
在 MIT 许可证 (MIT) 下授权。有关更多信息,请参阅LICENSE。