Rets-Rabbit-Javascript-SDK
Vanilla javascript sdk for the Rets Rabbit (RR) API.
Install the library
$ npm install rets-rabbit-js
$ bower install rets-rabbit-js
Configure a new client
There are several configuration options which you can use when instantiating
a new Rets Rabbit client.
var rrClient = new RetsRabbit({
clientId: 'YOUR_CLIENT_ID',
clientSecret: 'YOUR_CLIENT_SECRET',
host: 'https',
url: 'stage.retsrabbit.com/api',
storageKey: 'token'
});
If you do not supply your own clientId or clientSecret, the test Rets Rabbit
credentials will be used which will give you access to our test data store.
You may configure your RR credentials after instantiating your client with
the following methods:
var rrClient = new RetsRabbit({});
rrClient.clientId('YOUR_NEW_CLIENT_ID');
rrClient.clientSecret('YOUR_NEW_CLIENT_SECRET');
rrClient.host('YOUR_NEW_HOST');
rrClient.url('YOUR_NEW_URL');
rrClient.storageKey('NEW_KEY_NAME');
Loading
Make sure you wrap any of your logic inside of a .ready()
callback to
ensure the library is fully loaded.
RetsRabbit.ready(function () {
});
Authentication
The RR library exposes a method auth()
which hits the OAUTH 2.0 endpoint
to receive a new access token. By default this method stores the access_token
in a localStorage key called 'access_token', but this can be configured.
var rrClient = new RetsRabbit({});
RetsRabbit.ready(function () {
rrClient.auth(function (err, res){
if(err){
} else {
var token = res.access_token;
}
});
});
Querying
There are currently two version of the RR API: v1 & v2. This package supports
querying against both endpoints, by simply changing the url your GET
request is pointed at.
V1
rrClient.get('/v1/rest-of-path', ...)
To learn more about querying the v1 endpoint go check out our [v1 docs]
(https://retsrabbit.com/docs) .
V2
rrClient.get('/v2/rest-of-path', ...)
The latest version (v2) of RR is ODATA v4 compliant which means we offer
support for these types of query expressions:
$filter=ListPrice gt 75000 and geo.distance(location, POINT(-127.89734578345 45.234534534)) lt 50
$select=ListPrice, ListingId, OriginaListPrice
$orderby=ListPrice desc
$skip=10
$top=10
See the RR v2 docs for more details
on how to interact with our data. If reading through documentation isn't
your kind of thing we have an API explorer
which allows you to interactively play with v2 of the API in an intuitive
and fun way!
###Get Request
In order to perform queries against with the RR API, this module exposes
a get()
request method which accepts a request parameter.
var rrClient = new RetsRabbit();
RetsRabbit.ready(function () {
var q = {
'$top': 10,
'$select': 'ListingId, ListPrice'
};
rrClient.get('/v2/property', q, null, function (err, res){
if(err){
} else {
var listings = res.value;
}
});
});