anecka /retsrabbit
这是RetsRabbit的PHP SDK
Requires
- guzzlehttp/guzzle: ~4.0
Requires (Dev)
- phpunit/phpunit: 4.1.3
This package is not auto-updated.
Last update: 2024-09-28 16:15:25 UTC
README
Rets Rabbit客户端PHP SDK是一个库,它使您轻松与Rets Rabbit API协同工作。该API简化了处理房地产列表数据的工作。
项目的GitHub仓库在此处 https://github.com/patpohler/retsrabbit-php-sdk.git。
//New instance of the client
$client = new Anecka\retsrabbit\RetsRabbitClient($access_token);
//If using a custom API endpoint (ex. https://<domain>.retsrabbit.com/api)
//If your endpoint is https//api.retsrabbit.com you don't need to set this
$client->setEndpoint($endpoint_url);
//Get a listing from the MLS w/ an id of '5456655'
$listing = $client->getListing($server_id, '5456655');
//Run a search for listings on a price range
$listings = $client->getSearchListings($server_id, array('ListPrice' => '90000-100000'));
通过Composer安装
安装SDK的推荐方法是使用Composer。
# Install Composer
curl -sS https://getcomposer.org/installer | php
然后更新您的项目composer.json文件以包含SDK
"require": {
"anecka/retsrabbit": "dev-master"
}
运行composer install
安装库,安装后您需要要求Composer的自动加载器
require 'vendor/autoload.php';
身份验证
为了使用库,您需要有效的Rets Rabbit客户端凭证和API端点URL(通常形式为https://.retrabbit.com/api)。您需要这些凭证来创建访问令牌,以便向API发送请求。
$client = new Anecka\retsrabbit\RetsRabbitClient;
//If using a custom API endpoint (ex. https://<domain>.retsrabbit.com/api)
//If your endpoint is https//api.retsrabbit.com you don't need to set this
$client->setEndpoint($endpoint_url);
$client->getAccessCode($client_id, $client_secret);
//after you get the token you can save to a session variable for future requests, tokens are valid for 10 hours
echo $client->access_token
/* instantiating the client by passing an access_token */
$client = new Anecka\retsrabbit\RetsRabbitClient($_SESSION['access_token'], $endpoint_url);
获取服务器列表
要获取您账户注册的rets服务器列表,可以使用以下方法。
$servers = $client->getServers();
返回结果将是多维数组。以下是一个示例
[
[
"access_url": "http://rets.ranwrealtors.com:8080/wis/server/login",
"server_hash": "6cb1ab75588f1af22098f4df183cb988",
"listing_field": "MLSNumber",
"created_at": "2014-06-23 15:52:05",
"updated_at": "2014-06-23 15:52:05",
"listing_date_field": "ModificationTimeStamp",
"photo_class": "HQPhoto",
"last_run": null
],
...
]
server_hash
非常重要,因为您需要它来访问列表信息和运行MLS搜索。该散列永远不会更改,因此您可以将此值保存为环境变量或应用程序中的配置设置。
获取服务器的元数据
可以使用以下方法获取服务器的元数据。
$metadatas = $client->getServerMetadata($server_hash);
运行物业搜索
要搜索物业,只需调用getSearchListings
方法并传递服务器哈希和包含搜索参数的数组。由于字段因板而异,您需要参考您房地产板的元数据。
$params = array(
'ListPrice' => '90000-95000',
);
$listings = $client->getSearchListings($server_hash, $params);
返回结果将是stdClass对象的多维数组。您可以通过使用fields
和photos
属性来访问列表数据和照片。
foreach($listings as $listing) {
echo $listing->fields->MLSNumber;
echo $listing->fields->ListPrice;
foreach($listing->photos as $photo) {
echo $photo->url;
}
}
获取单个列表
要获取单个列表,请使用getListing
方法并传递服务器哈希和列表的唯一MLS ID。
$listing = $rets_client->getListing('6cb1ab75588f1af22098f4df183cb988', '50077235');
返回结果将是一个单独的stdClass对象。
©2016 Anecka, LLC 保留所有权利。