fw4/organimmo-rental-api 问题修复 & 功能扩展

解决BUG、新增功能、兼容多环境部署,快速响应你的开发需求

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

fw4/organimmo-rental-api

最新稳定版本:v1.3.1

Composer 安装命令:

composer require fw4/organimmo-rental-api

包简介

PHP library for implementing the Organimmo rental API

README 文档

README

PHP client for the Organimmo rental API. For terms of use and API credentials, refer to the official documentation.

Installation

composer require fw4/organimmo-rental-api

Usage

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);
}

All endpoints are available as methods of the Organimmo class. For more information about available endpoints and response format, refer to the official API documentation.

Retrieving objects by ID

Call get($id) on an endpoint to retrieve a specific object by ID. If no object exists with the provided ID, null is returned.

$country = $client->countries()->get(1);

if (is_null($country)) echo 'Country does not exist' . PHP_EOL;
else echo $country->name . PHP_EOL;

Listing objects

Call get() on an endpoint to retrieve a traversable list of objects. Any pagination that's required happens automatically.

$countries = $client->countries()->get();

foreach ($countries as $country) {
	echo $country->name . PHP_EOL;
}

Some endpoints may themselves provide additional methods for retrieving related objects. These methods usually accept the ID of the relevant parent object. Like with other endpoints, chain get() on these methods to retrieve a traversable list of objects.

$rental_unit_id = 1;
$photos = $client->rentalUnits()->photos($rental_unit_id)->get();

Related objects in responses

Responses may contain references to related objects. The actual data of these objects is not present in the response by default, but can easily be retrieved by calling get() on the pointer object.

$city = $client->cities()->get(1);
$country = $city->country->get();
echo $country->name . PHP_EOL;

Alternatively, it is possible to use the depth method to pre-fetch related objects. Pass an integer from 1 to 5 to determine how many levels to pre-fetch.

$city = $client->cities()->depth(1)->get(1);
echo $city->country->name . PHP_EOL;

Sorting results

Use the sort('fieldname') method to order results by a specific property.

$countries = $client->countries()->sort('name')->get();

Filtering results by date

Use the from($date) and to($date) methods to filter results by modification or creation date. These methods accept DateTime objects.

$countries = $client->countries()->from(date_create('2020-01-01'))->to(date_create('2020-06-01'))->get();

License

fw4/organimmo-rental-api is licensed under the MIT License (MIT). Please see LICENSE for more information.

统计信息

  • 总下载量: 1.06k
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 1
  • 点击次数: 0
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 1
  • Watchers: 3
  • Forks: 1
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2020-04-09