Class: Sunlight::Congress::CongressApi

Inherits:
Object
  • Object
show all
Defined in:
lib/sunlight/congress.rb

Direct Known Subclasses

District, Legislator

Class Method Summary collapse

Class Method Details

.create_from_response(response) ⇒ Object



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

def create_from_response(response)
  json = JSON.parse(response.body)

  if results = json['results']
    results.map do |attributes|
      self.new(attributes)
    end
  else
    json
  end
end

.encode_uri(location, options) ⇒ Object



9
10
11
12
13
14
# File 'lib/sunlight/congress.rb', line 9

def encode_uri(location, options)
  uri = URI("#{BASE_URI}/#{location}")
  uri.query = URI.encode_www_form(options.merge(apikey: '6d4acf5a753c40e1824857bb12679d89'))

  uri
end