Class: SunlightPartyTime
- Inherits:
-
Object
- Object
- SunlightPartyTime
- Defined in:
- lib/sunlightpartytime.rb
Instance Method Summary collapse
-
#crp_id(name) ⇒ Object
Get legislator ID.
-
#initialize(apikey) ⇒ SunlightPartyTime
constructor
A new instance of SunlightPartyTime.
-
#parties(name) ⇒ Object
Get all events a legislator is a beneficiary of.
-
#parties_clean(name) ⇒ Object
Get a cleaner JSON of party events.
Constructor Details
#initialize(apikey) ⇒ SunlightPartyTime
Returns a new instance of SunlightPartyTime.
5 6 7 |
# File 'lib/sunlightpartytime.rb', line 5 def initialize(apikey) @apikey = apikey end |
Instance Method Details
#crp_id(name) ⇒ Object
Get legislator ID
10 11 12 13 14 15 16 17 18 19 20 21 22 |
# File 'lib/sunlightpartytime.rb', line 10 def crp_id(name) = {:query => {:apikey => @apikey} } namearray = name.split(" ") data = HTTParty.get("http://congress.api.sunlightfoundation.com/legislators?query="+namearray.last, )["results"] data.each do |l| dhash = Hash[*l.flatten] if data.length > 1 return dhash["crp_id"] if dhash["first_name"] == namearray.first else return dhash["crp_id"] end end end |
#parties(name) ⇒ Object
Get all events a legislator is a beneficiary of
25 26 27 28 29 30 |
# File 'lib/sunlightpartytime.rb', line 25 def parties(name) cid = crp_id(name) = {:query => {:apikey => @apikey} } data = HTTParty.get("http://politicalpartytime.org/api/v1/event/?beneficiaries__crp_id=" + cid.to_s + "&format=json", )["objects"] return data.to_json end |
#parties_clean(name) ⇒ Object
Get a cleaner JSON of party events
33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 |
# File 'lib/sunlightpartytime.rb', line 33 def parties_clean(name) cid = crp_id(name) parties = JSON.parse(parties(cid)) partyarray = Array.new parties.each do |p| savehash = Hash.new phash = Hash[*p.flatten] savehash["start time"] = phash["start_date"].to_s savehash["end time"] = phash["end_date"].to_s savehash["headline"] = "Party: " + phash["entertainment"].to_s savehash["text"] = "contributions_info: " + phash["contributions_info"].to_s + " venue: " + phash["venue"]["venue_name"].to_s + " " + phash["venue"]["city"].to_s + ", " + phash["venue"]["state"].to_s partyarray.push(savehash) end partyarray.to_json end |