Module: Zoopla::Listings::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.
-
#reset! ⇒ Rentals, Sales
Resets all parameters except the API key.
-
#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
28 29 30 |
# File 'lib/zoopla/listings/listing.rb', line 28 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 |
# 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) 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
79 80 81 82 |
# File 'lib/zoopla/listings/listing.rb', line 79 def flats @request[:property_type] = 'flats' self end |
#houses ⇒ Sales, Rentals
Search only for houses
72 73 74 75 |
# File 'lib/zoopla/listings/listing.rb', line 72 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/
11 12 13 14 |
# File 'lib/zoopla/listings/listing.rb', line 11 def in(location) @request.merge! location self end |
#keywords(keywords) ⇒ Sales, Rentals
Keywords to search for within the listing description.
87 88 89 90 91 92 |
# File 'lib/zoopla/listings/listing.rb', line 87 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
126 127 128 129 130 131 |
# File 'lib/zoopla/listings/listing.rb', line 126 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
118 119 120 |
# File 'lib/zoopla/listings/listing.rb', line 118 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
104 105 106 |
# File 'lib/zoopla/listings/listing.rb', line 104 def maximum_price(price) set_limiting_value(:maximum, :price, price) end |
#minimum_beds(beds) ⇒ Sales, Rentals
Sets the minimum number of bedrooms
111 112 113 |
# File 'lib/zoopla/listings/listing.rb', line 111 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
97 98 99 |
# File 'lib/zoopla/listings/listing.rb', line 97 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.
46 47 48 49 50 |
# File 'lib/zoopla/listings/listing.rb', line 46 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
55 56 57 58 59 |
# File 'lib/zoopla/listings/listing.rb', line 55 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
19 20 21 |
# File 'lib/zoopla/listings/listing.rb', line 19 def price(price_range) set_range_parameter(:price, price_range) end |
#property_type(type) ⇒ Sales, Rentals
Property type. Either :houses or :flats
64 65 66 67 68 |
# File 'lib/zoopla/listings/listing.rb', line 64 def property_type(type) ensure_valid_parameter('property type', type, %w(houses flats)) @request[:property_type] = type.to_s self end |
#reset! ⇒ Rentals, Sales
Resets all parameters except the API key
150 151 152 153 |
# File 'lib/zoopla/listings/listing.rb', line 150 def reset! @request = default_parameters 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
35 36 37 38 39 |
# File 'lib/zoopla/listings/listing.rb', line 35 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 |