Class: YouGotListed::Listings
Defined Under Namespace
Classes: SearchResponse
Instance Attribute Summary
Attributes inherited from Resource
#client
Instance Method Summary
collapse
Methods inherited from Resource
#initialize, #process_get, #process_post
Instance Method Details
#featured(params = {}, featured_tag = 'Featured Rentals') ⇒ Object
13
14
15
16
17
18
19
20
|
# File 'lib/you_got_listed/listings.rb', line 13
def featured(params = {}, featured_tag = 'Featured Rentals')
if params[:tags].blank?
params[:tags] = featured_tag
else
params[:tags] += (params[:tags].ends_with?(',') ? featured_tag : ",#{featured_tag}")
end
search(params)
end
|
#find_all(params = {}) ⇒ Object
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
|
# File 'lib/you_got_listed/listings.rb', line 29
def find_all(params = {})
params[:page_count] ||= 20
all_listings = []
response = search(params)
if response.success?
all_listings << response.properties
total_pages = (response.ygl_response.total.to_i/params[:page_count].to_f).ceil
if total_pages > 1
(2..total_pages).each do |page_num|
resp = search(params.merge(:page => page_num))
if resp.success?
all_listings << resp.properties
end
end
end
end
all_listings.flatten
end
|
#find_all_by_ids(listing_ids, include_off_market = true) ⇒ Object
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
|
# File 'lib/you_got_listed/listings.rb', line 48
def find_all_by_ids(listing_ids, include_off_market = true)
listing_ids = listing_ids.split(',') if listing_ids.is_a?(String)
all_listings = []
search_params = {}
search_params[:include_off_market] = 1 if include_off_market
if listing_ids.any?{|list_id| list_id !=~ /[A-Z]{3}-[0-9]{3}-[0-9]{3}/}
search_params[:include_mls] = 1
end
listing_ids.in_groups_of(20, false).each do |group|
group.delete_if{|x| x.nil?}
search_params[:listing_ids] = group.join(',')
all_listings << find_all(search_params)
end
all_listings.compact.flatten
end
|
#find_by_id(listing_id) ⇒ Object
22
23
24
25
26
27
|
# File 'lib/you_got_listed/listings.rb', line 22
def find_by_id(listing_id)
listing_id_key = listing_id.to_s.match(/7\d{7}/) ? :external_id : :listing_id
params = {listing_id_key => listing_id, :detail_level => 2}
response = SearchResponse.new(self.client.perform_request(:get, '/rentals/search.php', params), self.client, 20)
(response.success? && response.properties.size > 0) ? response.properties.first : nil
end
|
#search(params = {}) ⇒ Object
4
5
6
7
8
9
10
11
|
# File 'lib/you_got_listed/listings.rb', line 4
def search(params = {})
params[:page_count] ||= 20
params[:page_index] ||= 1
params[:sort_name] ||= "rent"
params[:sort_dir] ||= "asc"
params[:detail_level] ||= 2
SearchResponse.new(self.client.perform_request(:get, '/rentals/search.php', params), self.client, params[:page_count])
end
|