Module: FindReps
- Extended by:
- FindReps
- Included in:
- FindReps
- Defined in:
- lib/find_reps.rb,
lib/find_reps/version.rb
Defined Under Namespace
Classes: Error, Representative
Constant Summary
collapse
- VERSION =
"0.1.2"
Instance Method Summary
collapse
Instance Method Details
#by_zipcode(zipcode) ⇒ Object
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
|
# File 'lib/find_reps.rb', line 20
def by_zipcode(zipcode)
if zipcode.nil? || zipcode.to_s.empty?
raise Error, "must provide a zipcode"
end
if endpoint.nil?
raise Error, "must assign an endpoint"
end
url = "#{endpoint}/api/representatives.json?zipcode=#{zipcode}"
response = Faraday.get(url)
if response.status == 200
JSON.parse(response.body).map { |rep_data| Representative.new(rep_data) }
else
raise Error, "status: #{response.status}, body: #{response.body}"
end
end
|
#endpoint ⇒ Object
16
17
18
|
# File 'lib/find_reps.rb', line 16
def endpoint
@endpoint
end
|
#endpoint=(value) ⇒ Object
12
13
14
|
# File 'lib/find_reps.rb', line 12
def endpoint=(value)
@endpoint = value
end
|