Module: Zoopla::Listing
Overview
Common methods for Sales and Rentals classes
Instance Method Summary collapse
-
#beds(beds_range) ⇒ Sales, Rentals
Sets the number of bedrooms range.
-
#each {|Hashie::Mash| ... } ⇒ Object
Iterates over the results.
-
#flats ⇒ Sales, Rentals
Search only for flats.
-
#houses ⇒ Sales, Rentals
Search only for houses.
-
#in(location) ⇒ Sales, Rentals
Defines the search area.
-
#keywords(keywords) ⇒ Sales, Rentals
Keywords to search for within the listing description.
-
#listing_id(listing_id) ⇒ Sales, Rentals
Adds another listing id to the query.
-
#maximum_beds(beds) ⇒ Sales, Rentals
Sets the maximum number of bedrooms.
-
#maximum_price(price) ⇒ Sales, Rentals
Sets the maximum price.
-
#minimum_beds(beds) ⇒ Sales, Rentals
Sets the minimum number of bedrooms.
-
#minimum_price(price) ⇒ Sales, Rentals
Sets the minimum price.
-
#order_by(field) ⇒ Sales, Rentals
The field by which the results should be ordered, either :price or :age of listing.
-
#ordering(order) ⇒ Sales, Rentals
Sort order for the listings returned.
-
#price(price_range) ⇒ Sales, Rentals
(also: #for)
Sets the price range.
-
#property_type(type) ⇒ Sales, Rentals
Property type.
-
#within(miles) ⇒ Sales, Rentals
(also: #radius)
Defines the size of the search area in miles.
Instance Method Details
#beds(beds_range) ⇒ Sales, Rentals
Sets the number of bedrooms range
27 28 29 |
# File 'lib/zoopla/listings/listing.rb', line 27 def beds(beds_range) set_range_parameter(:beds, beds_range) end |
#each {|Hashie::Mash| ... } ⇒ Object
Iterates over the results. Possible fields are described at developer.zoopla.com/docs/read/Property_listings
135 136 137 138 139 140 141 142 143 144 145 146 147 |
# File 'lib/zoopla/listings/listing.rb', line 135 def each fetched_so_far, number_of_results = 0, 0 @request[:page_number] = 1 begin number_of_results, listings = fetch_data(@request) number_of_results = 0 if listings.size == 0 fetched_so_far += listings.size @request[:page_number] += 1 listings.each do |listing| yield listing end end while fetched_so_far < number_of_results end |
#flats ⇒ Sales, Rentals
Search only for flats
78 79 80 81 |
# File 'lib/zoopla/listings/listing.rb', line 78 def flats @request[:property_type] = 'flats' self end |
#houses ⇒ Sales, Rentals
Search only for houses
71 72 73 74 |
# File 'lib/zoopla/listings/listing.rb', line 71 def houses @request[:property_type] = 'houses' self end |
#in(location) ⇒ Sales, Rentals
Defines the search area. All possible params are described at developer.zoopla.com/docs/
9 10 11 12 13 |
# File 'lib/zoopla/listings/listing.rb', line 9 def in(location) check_output_type location @request.merge! location self end |
#keywords(keywords) ⇒ Sales, Rentals
Keywords to search for within the listing description.
86 87 88 89 90 91 |
# File 'lib/zoopla/listings/listing.rb', line 86 def keywords(keywords) ensure_valid_parameter('keywords', keywords, lambda {|k| k.is_a? Array or k.is_a? String}) keywords = keywords.join(' ') if keywords.is_a? Array @request[:keywords] = keywords self end |
#listing_id(listing_id) ⇒ Sales, Rentals
Adds another listing id to the query. Calling this function multiple times will add multiple ids. Please note that other provided arguments will still be taken into account when filtering listings
125 126 127 128 129 130 |
# File 'lib/zoopla/listings/listing.rb', line 125 def listing_id(listing_id) ensure_valid_parameter('listing id', listing_id, lambda {|k| k.is_a? Fixnum and k >= 0}) @request[:listing_id] ||= [] @request[:listing_id] << listing_id self end |
#maximum_beds(beds) ⇒ Sales, Rentals
Sets the maximum number of bedrooms
117 118 119 |
# File 'lib/zoopla/listings/listing.rb', line 117 def maximum_beds(beds) set_limiting_value(:maximum, :beds, beds) end |
#maximum_price(price) ⇒ Sales, Rentals
Sets the maximum price. Weekly prices in case of rentals
103 104 105 |
# File 'lib/zoopla/listings/listing.rb', line 103 def maximum_price(price) set_limiting_value(:maximum, :price, price) end |
#minimum_beds(beds) ⇒ Sales, Rentals
Sets the minimum number of bedrooms
110 111 112 |
# File 'lib/zoopla/listings/listing.rb', line 110 def minimum_beds(beds) set_limiting_value(:minimum, :beds, beds) end |
#minimum_price(price) ⇒ Sales, Rentals
Sets the minimum price. Weekly prices in case of rentals
96 97 98 |
# File 'lib/zoopla/listings/listing.rb', line 96 def minimum_price(price) set_limiting_value(:minimum, :price, price) end |
#order_by(field) ⇒ Sales, Rentals
The field by which the results should be ordered, either :price or :age of listing.
45 46 47 48 49 |
# File 'lib/zoopla/listings/listing.rb', line 45 def order_by(field) ensure_valid_parameter('sorting order', field, %w(price age)) @request[:order_by] = field.to_s self end |
#ordering(order) ⇒ Sales, Rentals
Sort order for the listings returned. Either :descending or :ascending
54 55 56 57 58 |
# File 'lib/zoopla/listings/listing.rb', line 54 def ordering(order) ensure_valid_parameter('ordering', order, %w(ascending descending)) @request[:ordering] = order.to_s self end |
#price(price_range) ⇒ Sales, Rentals Also known as: for
Sets the price range
18 19 20 |
# File 'lib/zoopla/listings/listing.rb', line 18 def price(price_range) set_range_parameter(:price, price_range) end |
#property_type(type) ⇒ Sales, Rentals
Property type. Either :houses or :flats
63 64 65 66 67 |
# File 'lib/zoopla/listings/listing.rb', line 63 def property_type(type) ensure_valid_parameter('property type', type, %w(houses flats)) @request[:property_type] = type.to_s self end |
#within(miles) ⇒ Sales, Rentals Also known as: radius
Defines the size of the search area in miles. E.g. 2 miles around a location
34 35 36 37 38 |
# File 'lib/zoopla/listings/listing.rb', line 34 def within(miles) ensure_valid_parameter('radius', miles, lambda {|p| (p.is_a? Float or p.is_a? Fixnum) and p >= 0}) @request[:radius] = miles self end |