antistatique / pricehubble-php-sdk
超简单、最小抽象的Pricehubble API v1.x包装器,用PHP编写
Requires
- php: >=8.0
- ext-curl: *
- ext-json: *
Requires (Dev)
- friendsofphp/php-cs-fixer: ^3.21
- php-coveralls/php-coveralls: ^2.1
- php-mock/php-mock-phpunit: ^2.6
- phpmd/phpmd: ^2.6
- phpunit/php-code-coverage: ^9
- phpunit/phpunit: ^9
- sebastian/phpcpd: ^6.0
- symfony/dotenv: ^5.4
- vimeo/psalm: ^4.10
README
超简单、最小抽象的Pricehubble API v1.x包装器,用PHP编写。
我讨厌复杂的包装器。这可以让您尽可能直接地从Pricehubble API文档到代码。
入门
您可以使用Composer安装 pricehubble-php-sdk
composer require antistatique/pricehubble-php-sdk
示例
查看 examples/
目录中的关键客户端功能示例。您可以通过运行php内置的Web服务器在浏览器中查看它们。
php -S localhost:8000 -t examples/
然后浏览到您指定的主机和端口(在上面的示例中,http://localhost:8000
)。
基本示例
首先通过 use
-ing 类并使用您的API密钥创建一个实例
use \Antistatique\Pricehubble\Pricehubble;
每个请求都应该包含一个有效的访问令牌。在发送任何请求之前使用 Pricehubble::authenticate
方法。所有操作请求都需要一个有效的身份验证。
估值
在指定的估值日期对指定的房地产进行估值。此端点可用于对一个单独的房地产进行估值、创建时间序列或执行批量估值。
每次调用中估值的数量不得超过50,即您可以为1个房地产在50个日期进行估值,或为50个房地产在1个日期进行估值,但不能为50个房地产在50个日期进行估值。
👉 https://docs.pricehubble.com/international/valuation/
$pricehubble = new Pricehubble(); $pricehubble->authenticate($username, $password) $response = $pricehubble->valuation()->full([ 'dealType' => 'sale', 'valuationInputs' => [ [ 'property' => [ 'location' => [ 'address' => [ 'postCode' => '8037', 'city' => 'Zürich', 'street' => 'Nordstrasse', 'houseNumber' => '391' ], ], 'buildingYear' => 1850, 'livingArea' => 800, 'propertyType' => [ 'code' => 'apartment' ], ], ], ], 'countryCode' => 'CH', ]); print_r($response);
估值轻量版
对指定的房地产进行简单的估值。
如果您想对多个房地产(在单个调用中)进行估值、创建时间序列或通过考虑更多参数来提高估值,请考虑使用完全功能的估值端点。
👉 https://docs.pricehubble.com/international/valuation_light/
$pricehubble = new Pricehubble(); $pricehubble->authenticate($username, $password) $response = $pricehubble->valuation()->light([ 'dealType' => 'sale', 'property' => [ 'location' => [ 'address' => [ 'postCode' => '8037', 'city' => 'Zürich', 'street' => 'Nordstrasse', 'houseNumber' => '391' ], ], 'buildingYear' => 1850, 'livingArea' => 800, 'propertyType' => [ 'code' => 'apartment' ], ], 'countryCode' => 'CH', ]); print_r($response);
兴趣点
返回与指定搜索标准匹配的兴趣点,如学校、商店等。
👉 https://docs.pricehubble.com/international/pois/
$pricehubble = new Pricehubble(); $pricehubble->authenticate($username, $password) $response = $pricehubble->pointsOfInterest()->gather([ 'coordinates' => [ 'latitude' => 47.3968601, 'longitude' => 8.5153549, ], 'radius' => 1000, 'category' => [ 'education', 'leisure', ], 'subcategory' => [ 'kindergarten', 'playground', ], 'offset' => 0, 'limit' => 10, 'countryCode' => 'CH', ]); print_r($response);
故障排除
要获取HTTP客户端或API返回的最后错误,请使用 getLastError()
echo $pricehubble->getLastError();
为进一步调试,您可以检查响应的标头和正文
print_r($pricehubble->getLastResponse());
如果您怀疑您发送的数据格式不正确,您可以查看包装器发送给Pricehubble的内容
print_r($pricehubble->getLastRequest());
如果您的服务器的CA根证书过时,您可能会发现SSL验证失败并且您没有收到响应。此错误的修正解决方案不是禁用SSL验证。解决方案是更新您的证书。如果您无法这样做,类文件顶部有一个选项。请不要不尝试更新您的证书就直接将其关闭——这是懒惰且危险的。你不是个懒惰、危险的开发者,对吧?