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

.find_by_latlng(lat, lng) ⇒ Object

Find districts by latitude and longitude.

Raises:

  • (ArgumentError)


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

def self.find_by_latlng(lat, lng)
  # TODO use ArgumentError
  raise(ArgumentError, 'missing required parameter latitude') if lat.nil?

  query = {
    :latitude => lat,
    :longitude => lng,
    :apikey => Daywalker.api_key
  }
  response = get('/districts.getDistrictFromLatLong.xml', :query => query)
  handle_response(response) # TODO should only ever return one?
end

.find_by_zip(zip) ⇒ Object

Find districts by zip code

Raises:

  • (ArgumentError)


29
30
31
32
33
34
35
36
37
38
39
40
# File 'lib/daywalker/district.rb', line 29

def self.find_by_zip(zip)
  # TODO use ArgumentError
  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