Class: GovKit::OpenStatesResource

Inherits:
Resource
  • Object
show all
Defined in:
lib/gov_kit/open_states.rb

Overview

Parent class for OpenStates resources See openstates.sunlightlabs.com/api/

Instance Attribute Summary

Attributes inherited from Resource

#attributes, #raw_response

Class Method Summary collapse

Methods inherited from Resource

#initialize, instantiate, instantiate_collection, parse, #to_md5, #unload

Constructor Details

This class inherits a constructor from GovKit::Resource

Dynamic Method Handling

This class handles dynamic methods through the method_missing method in the class GovKit::Resource

Class Method Details

.get_uri(uri, options = {}) ⇒ Object

Do a GET query, with optional parameters.

OpenStates returns a 404 error when a query returns nothing.

So, if a query result is a resource not found error, we return an empty set.



15
16
17
18
19
20
21
22
23
24
# File 'lib/gov_kit/open_states.rb', line 15

def self.get_uri(uri, options={})
  options[:query] ||= {}
  options[:query][:apikey] = GovKit::configuration.sunlight_apikey

  begin
    parse(get(URI.encode(uri), options))
  rescue ResourceNotFound
    []
  end
end