Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

add :api_key in #get_uri, as GovKit may not be configured when the Op…

…enStatesResource class is initialized
  • Loading branch information...
commit 2721384468d32f6cbadb3e7b60238a5b7a99b222 1 parent 4ec637c
James McKinney jpmckinney authored
Showing with 7 additions and 11 deletions.
  1. +7 −11 lib/gov_kit/open_states.rb
18 lib/gov_kit/open_states.rb
View
@@ -3,11 +3,6 @@ module GovKit
# Parent class for OpenStates resources
# See http://openstates.sunlightlabs.com/api/
class OpenStatesResource < Resource
-
- # Uses default_params from the HTTParty gem.
- # See HTTParty::ClassMethods:
- # http://rubydoc.info/gems/httparty/0.7.4/HTTParty/ClassMethods#default_params-instance_method
- default_params :output => 'json', :apikey => GovKit::configuration.sunlight_apikey
base_uri GovKit::configuration.openstates_base_url
# Do a GET query, with optional parameters.
@@ -18,13 +13,14 @@ class OpenStatesResource < Resource
# So, if a query result is a resource not found error,
# we return an empty set.
def self.get_uri(uri, options={})
+ options[:query] ||= {}
+ options[:query][:apikey] = GovKit::configuration.sunlight_apikey
+
begin
- response = get(URI.encode(uri), options)
- result = parse(response)
+ parse(get(URI.encode(uri), options))
rescue ResourceNotFound
- return []
+ []
end
- result
end
end
@@ -76,8 +72,8 @@ def self.search(query, options = {})
end
def self.latest(updated_since, ops = {})
- response = get('/bills/', :query => {:updated_since => updated_since.to_s}.merge(ops))
- parse(response)
+ result = get_uri('/bills/', :query => {:updated_since => updated_since.to_s}.merge(ops))
+ return Array(result)
end
end
Please sign in to comment.
Something went wrong with that request. Please try again.