Package Exports
- rets-client
This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (rets-client) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.
Readme
rets-client
Node.js RETS client (Real Estate Transaction Standard)
Library was developed against a server running RETS v1.7.2.
Future work
This is the rets-client 1.x branch -- development has begun on a 2.x branch, which will NOT be backward compatible. This new branch will use a Promise and stream-based API, rather than the current events and callback API. If you are interested, please take a look at the 2.x branch, and feel free to open issue tickets or PRs against it. Note however that the 2.x branch is considered unstable; this means we might make additional breaking changes to the API. Eventually, the 2.x branch will be merged to master, and at that time it will be considered stable.
Example RETS Session
Create a Client Instance (Login)
//create rets-client
var client = require('rets-client').getClient(retsLoginUrl, retsUser, retsPassword);
//connection success event
client.once('connection.success', function() {
console.log("RETS Server connection success!");
console.log("RETS version: " + client.retsVersion);
console.log("Member name: " + client.memberName);
});
//connection failure event
client.once('connection.failure', function(error) {
console.log("connection to RETS server failed ~ %s", error);
});
Custom Client Configuration
//create rets-client
var client = require('rets-client').getClientFromSettings({
loginUrl:retsLoginUrl,
username:retsUser,
password:retsPassword,
version:'RETS/1.7.2',
userAgent:'RETS node-client/1.0'
});
...
Client configuration with UA Authorization
//create rets-client
var client = require('rets-client').getClientFromSettings({
version:'RETS/1.7.2',
userAgent:userAgent,
userAgentPassword:userAgentPassword,
sessionId:sessionId
});
...
Get Resources Metadata
//get resources metadata
var client = require('rets-client').getClient(retsLoginUrl, retsUser, retsPassword);
client.once('connection.success', function() {
client.getResources();
client.once('metadata.resources.success', function(data) {
console.log(data.Version);
console.log(data.Date);
for(var dataItem = 0; dataItem < data.Resources.length; dataItem++) {
console.log(data.Resources[dataItem].ResourceID);
console.log(data.Resources[dataItem].StandardName);
console.log(data.Resources[dataItem].VisibleName);
console.log(data.Resources[dataItem].ObjectVersion);
}
});
});
Get Class Metadata
//get class metadata
var client = require('rets-client').getClient(retsLoginUrl, retsUser, retsPassword);
client.once('connection.success', function() {
client.getClass("Property");
client.once('metadata.class.success', function(data) {
console.log(data.Version);
console.log(data.Date);
console.log(data.Resource);
for(var classItem = 0; classItem < data.Classes.length; classItem++) {
console.log(data.Classes[classItem].ClassName);
console.log(data.Classes[classItem].StandardName);
console.log(data.Classes[classItem].VisibleName);
console.log(data.Classes[classItem].TableVersion);
}
});
});
Get Field Metadata
//get field data
var client = require('rets-client').getClient(retsLoginUrl, retsUser, retsPassword);
client.once('connection.success', function() {
client.getTable("Property", "RESI");
client.once('metadata.table.success', function(data) {
console.log(data.Version);
console.log(data.Date);
console.log(data.Resource);
console.log(data.Class);
for(var tableItem = 0; tableItem < data.Fields.length; tableItem++) {
console.log(data.Fields[tableItem].MetadataEntryID);
console.log(data.Fields[tableItem].SystemName);
console.log(data.Fields[tableItem].ShortName);
console.log(data.Fields[tableItem].LongName);
console.log(data.Fields[tableItem].DataType);
}
});
});
Perform a Query
//perform a query using DQML
var client = require('rets-client').getClient(retsLoginUrl, retsUser, retsPassword);
client.once('connection.success', function() {
//get open house fields
client.getTable("OpenHouse", "OPENHOUSE");
var fields;
client.once('metadata.table.success', function(table) {
fields = table.Fields;
//pass resource, class, and DQML2 query
client.queryWithOpts("OpenHouse", "OPENHOUSE",
"(OpenHouseType=PUBLIC),(ActiveYN=1)", {limit:100, offset:1}, function(error, data) {
if (error) {
console.log(error);
return;
}
//iterate through search results
for(var dataItem = 0; dataItem < data.length; dataItem++) {
console.log("-------- Open House --------")
for(var fieldItem = 0; fieldItem < fields.length; fieldItem++) {
var systemStr = fields[fieldItem].SystemName;
console.log(systemStr + " : " + data[dataItem][systemStr]);
}
console.log("\n");
}
});
});
});
Retrieve Large Photos of a Property
//get photos
var client = require('rets-client').getClient(retsLoginUrl, retsUser, retsPassword);
client.once('connection.success', function() {
client.getPhotos("Property", "LargePhoto", "123456789", function(error, dataList) {
if (error) {
console.log(error);
return;
}
for(var i = 0; i < dataList.length; i++) {
console.log("Photo " + (i+1) + " MIME type: " + dataList[i].mime);
require('fs').writeFile(
"imgs/photo"+(i+1)+"."+dataList[i].mime.match(/image\/(\w+)/i)[1],
dataList[i].buffer
);
}
});
});