Code Monkey home page Code Monkey logo

rets-client's Introduction

rets-client

Node.js RETS client (Real Estate Transaction Standard)

Library was developed against a server running RETS v1.7.2.

RETS Specification

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

rets-client's People

Contributors

sbruno81 avatar zacronos avatar

Watchers

James Cloos avatar Geoff Weinhold avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.