Module: Zoopla::Listing

Included in:
Rentals, Sales
Defined in:
lib/zoopla/listings/listing.rb

Overview

Common methods for Sales and Rentals classes

Instance Method Summary collapse

Instance Method Details

#beds(beds_range) ⇒ Sales, Rentals

Sets the number of bedrooms range

Parameters:

  • bedrooms (Range)

    range, e.g. 2..3

Returns:



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

Yields:

  • (Hashie::Mash)

    a listing with data, e.g. sales.each{|listing| puts listing.price }

Raises:

  • Zoopla::DisambiguationError if an ambiguous area is specified. Always expect this exception



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

#flatsSales, Rentals

Search only for flats

Returns:



78
79
80
81
# File 'lib/zoopla/listings/listing.rb', line 78

def flats
  @request[:property_type] = 'flats'
  self
end

#housesSales, Rentals

Search only for houses

Returns:



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/

Parameters:

  • Location (Hash)

    hash

Returns:



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.

Parameters:

  • keywords (Array, String)

Returns:



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

Parameters:

  • listing (Fixnum)

    id

Returns:



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

Parameters:

  • number (Fixnum)

    of bedrooms

Returns:



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

Parameters:

  • price (Fixnum)

Returns:



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

Parameters:

  • number (Fixnum)

    of bedrooms

Returns:



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

Parameters:

  • price (Fixnum)

Returns:



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.

Parameters:

  • sorting (Symbol, String)

    field

Returns:



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

Parameters:

  • sorting (Symbol, String)

    order

Returns:



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

Parameters:

  • price (Range)

    range (weekly in case of rentals), e.g. 200..300

Returns:



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

Parameters:

  • property (Symbol, String)

    type

Returns:



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

Parameters:

  • radius (Fixum)

    in miles

Returns:



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