Class: Sunlight::Congress::District

Inherits:
CongressApi show all
Defined in:
lib/sunlight/congress/district.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from CongressApi

create_from_response, encode_uri

Constructor Details

#initialize(options = {}) ⇒ District

Returns a new instance of District.



7
8
9
10
11
# File 'lib/sunlight/congress/district.rb', line 7

def initialize(options = {})
  options.each do |attribute, value|
    instance_variable_set("@#{attribute}", value)
  end
end

Instance Attribute Details

#districtObject

Returns the value of attribute district.



5
6
7
# File 'lib/sunlight/congress/district.rb', line 5

def district
  @district
end

#stateObject

Returns the value of attribute state.



5
6
7
# File 'lib/sunlight/congress/district.rb', line 5

def state
  @state
end

Class Method Details

.locate(options) ⇒ Object



14
15
16
17
18
19
20
21
22
23
# File 'lib/sunlight/congress/district.rb', line 14

def locate(options)
  if options.is_a?(String) || options[:address]
    coords = Geocoder.coordinates(options)
    response = Net::HTTP.get_response(locate_uri(latitude: coords[0], longitude: coords[1]))
  else
    response = Net::HTTP.get_response(locate_uri(options))
  end

  create_from_response(response)
end

.locate_uri(options = {}) ⇒ Object



25
26
27
# File 'lib/sunlight/congress/district.rb', line 25

def locate_uri(options = {})
  encode_uri('legislators/locate', options)
end