Skip to content

Commit

Permalink
add :api_key in #get_uri, as GovKit may not be configured when the Op…
Browse files Browse the repository at this point in the history
…enStatesResource class is initialized
  • Loading branch information
James McKinney committed Nov 7, 2012
1 parent 4ec637c commit 2721384
Showing 1 changed file with 7 additions and 11 deletions.
18 changes: 7 additions & 11 deletions lib/gov_kit/open_states.rb
Expand Up @@ -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.
Expand All @@ -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
Expand Down Expand Up @@ -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

Expand Down

0 comments on commit 2721384

Please sign in to comment.