Sha256: fda24402357c5ecc97d0f549bf19433e256d88ac6e5a2ee2e02f743c69bc8f29

Contents?: true

Size: 1.11 KB

Versions: 3

Compression:

Stored size: 1.11 KB

Contents

module Daywalker
  # Represents a Congressional district.
  #
  # They have the following attributes:
  # * number
  # * state (as a two-letter abbreviation)
  class District < Base
    include HappyMapper

    tag     'district'
    element 'number', Integer
    element 'state', String

    # Find districts by latitude and longitude.
    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 districts by zip code
    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

  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
technicalpickles-daywalker-0.1.0 lib/daywalker/district.rb
technicalpickles-daywalker-0.1.1 lib/daywalker/district.rb
technicalpickles-daywalker-0.1.2 lib/daywalker/district.rb