Class: Daywalker::District

Inherits:
Base
  • Object
show all
Includes:
HappyMapper
Defined in:
lib/daywalker/district.rb

Overview

Represents a Congressional district.

They have the following attributes:

  • number

  • state (as a two-letter abbreviation)

Class Method Summary collapse

Class Method Details

.all_by_zipcode(zip) ⇒ Object

Finds all districts for a specific zip code.

Returns an Array of Districts. Raises ArgumentError if you omit the zip.

Raises:

  • (ArgumentError)


33
34
35
36
37
38
39
40
41
42
43
# File 'lib/daywalker/district.rb', line 33

def self.all_by_zipcode(zip)
  raise(ArgumentError, 'missing required parameter zip') if zip.nil?

  query = {
    :zip => zip,
    :apikey => Daywalker.api_key
  }
  response = get('/districts.getDistrictsFromZip.xml', :query => query)

  handle_response(response)
end

.unique_by_address(address) ⇒ Object

Find the district for a specific address.

Returns a District.

Raises Daywalker::AddressError if the address can’t be geocoded.

Raises:

  • (ArgumentError)


50
51
52
53
54
55
# File 'lib/daywalker/district.rb', line 50

def self.unique_by_address(address)
  raise(ArgumentError, 'missing required parameter address') if address.nil?
  location = Daywalker.geocoder.locate(address)

  unique_by_latitude_and_longitude(location[:latitude], location[:longitude])
end

.unique_by_latitude_and_longitude(latitude, longitude) ⇒ Object

Find the district for a specific latitude and longitude.

Returns a District. Raises ArgumentError if you omit latitude or longitude.

Raises:

  • (ArgumentError)


17
18
19
20
21
22
23
24
25
26
27
28
# File 'lib/daywalker/district.rb', line 17

def self.unique_by_latitude_and_longitude(latitude, longitude)
  raise(ArgumentError, 'missing required parameter latitude') if latitude.nil?
  raise(ArgumentError, 'missing required parameter longitude') if longitude.nil?

  query = {
    :latitude => latitude,
    :longitude => longitude,
    :apikey => Daywalker.api_key
  }
  response = get('/districts.getDistrictFromLatLong.xml', :query => query)
  handle_response(response).first
end