Reputation: 685
I'm working on a Real Estate project with Ruby on Rails based on Florida, there are no more details about matrixrets.swflamls
API but I need fetch data from there database save to my own database this regular basis for data update and create.
I have following configuration for fetching data
client = Rets::Client.new({
login_url: 'http://matrixrets.swflamls.com/rets/Login.ashx',
username: 'XXXXXXXXXXXXXX',
password: 'XXXXXXXXXXXXXX'
})
Query for fetching data, this query copied from this tutorial, this tutorial is related but not exact for my API
properties = client.find (:all), {
search_type: 'Property',
class: 'RES',
querytype: 'DMQL2',
Format: 'COMPACT',
query: "(YearBuilt=1900+), (Status=A)",
}
<% properties.each do |data| %>
<%= data['Bedrooms'] %>
<% end %>
I have some keys for properties like active, pending etc... the below
'A', 'AC', 'AP', 'AS', 'I', 'P', 'PC', 'R', 'T', 'W'
I have two questions:
How to fetch data from there database
If I got data then how to all data fetch like Status equal all keys.
Currently not any error also not fetching any data
Much appriciated
Upvotes: 0
Views: 240
Reputation: 7777
Ok, I think you have missed something in you your configuration section if you got the RETSMD for looking details on your API you found the version
I think you missed the version see the below.
client = Rets::Client.new({
login_url: 'http://matrixrets.swflamls.com/rets/Login.ashx',
username: 'XXXXXXXXXX',
password: 'XXXXXXXXXX',
version: 'RETS/1.7.2' #=> Or which compatible yours like 1.5 or something
})
Then update your query using no_records_not_an_error
method for if not find data then not showing any error else will show a nil error, see the below
properties = client.find (:all), {
no_records_not_an_error: true,
search_type: 'Property',
class: 'RES',
querytype: 'DMQL2',
Format: 'COMPACT',
query: "(YearBuilt=1900+), (Status=A})",
}
That your problem 1
Hope that is work
Now problem 2
You can declare an array and keep all keys inside array like below
arr = ['A', 'AC', 'AP', 'AS', 'I', 'P', 'PC', 'R', 'T', 'W']
And then update your query
for i in 0...arr.count
properties = client.find (:all), {
no_records_not_an_error: true,
search_type: 'Property',
class: 'RES',
querytype: 'DMQL2',
Format: 'COMPACT',
query: "(YearBuilt=1900+), (Status=#{arr[i]})",
}
puts properties.count #=> count for every status
end
See the console have counted any number if yes then working and then move forward.
Hope it helps
Upvotes: 1