Class: SunlightApi
- Inherits:
-
GenericApi
- Object
- GenericApi
- SunlightApi
- Includes:
- HTTParty
- Defined in:
- lib/apis/sunlight_api.rb
Overview
Control Access to Sunlight API.
Instance Method Summary collapse
-
#key=(key) ⇒ Object
Simply declare and remember the API Key.
-
#legislators_get(params) ⇒ Object
Call Sunlight queries returning a single legislator matching a query.
-
#legislators_getlist(params) ⇒ Object
Sunlight query returning an array of matching legislators.
- #legislators_search(params) ⇒ Object
Methods inherited from GenericApi
Instance Method Details
#key=(key) ⇒ Object
Simply declare and remember the API Key
42 43 44 45 |
# File 'lib/apis/sunlight_api.rb', line 42 def key=(key) @api_key = key SunlightApi.default_params :apikey => key end |
#legislators_get(params) ⇒ Object
Call Sunlight queries returning a single legislator matching a query
48 49 50 51 52 53 54 55 56 |
# File 'lib/apis/sunlight_api.rb', line 48 def legislators_get(params) begin result = SunlightApi.get("/api/legislators.get", :query => params) result = result["response"]["legislator"] rescue Net::HTTPServerException => exception puts "EXCEPTION: from Sunlight - legislators.get: #{exception.response.body}" return nil end end |
#legislators_getlist(params) ⇒ Object
Sunlight query returning an array of matching legislators
59 60 61 62 63 64 65 66 67 |
# File 'lib/apis/sunlight_api.rb', line 59 def legislators_getlist(params) begin result = SunlightApi.get("/api/legislators.getList", :query => params) result = result["response"]["legislators"] rescue Net::HTTPServerException => exception puts "EXCEPTION: from Sunlight - legislators.getList: #{exception.response.body}" return nil end end |
#legislators_search(params) ⇒ Object
36 37 38 39 |
# File 'lib/apis/sunlight_api.rb', line 36 def legislators_search(params) result = SunlightApi.get("/api/legislators.search", :query => {:name => params}) result["response"]["results"] end |