sunlightcongress 0.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (2) hide show
  1. data/lib/sunlight_congress.rb +95 -0
  2. metadata +46 -0
@@ -0,0 +1,95 @@
1
+ require "httparty"
2
+ require "json"
3
+
4
+ class SunlightCongress
5
+ def initialize(apikey)
6
+ @apikey = apikey
7
+ end
8
+
9
+ # Get legislator ID
10
+ def legislator_id(name)
11
+ options = {:query => {:apikey => @apikey} }
12
+ namearray = name.split(" ")
13
+ data = HTTParty.get("http://congress.api.sunlightfoundation.com/legislators?query="+namearray.last, options)["results"]
14
+
15
+ data.each do |l|
16
+ dhash = Hash[*l.flatten]
17
+ if data.length > 1
18
+ return dhash["bioguide_id"] if dhash["first_name"] == namearray.first
19
+ else return dhash["bioguide_id"]
20
+ end
21
+ end
22
+ end
23
+
24
+ # Get all votes by particular congressperson
25
+ def get_votes(id)
26
+ options = {:query => {:apikey => @apikey} }
27
+ data = HTTParty.get("http://congress.api.sunlightfoundation.com/votes?voter_ids." + id.to_s + "__exists=true", options)["results"]
28
+ return data.to_json
29
+ end
30
+
31
+ # Get all amendments sponsored by a congressperson
32
+ def get_amendments(id)
33
+ options = {:query => {:apikey => @apikey} }
34
+ data = HTTParty.get("http://congress.api.sunlightfoundation.com/amendments?sponsor_type=person&sponsor_id=" + id.to_s , options)["results"]
35
+ return data.to_json
36
+ end
37
+
38
+ # Get all bills sponsored by a congressperson
39
+ def get_bills(id)
40
+ options = {:query => {:apikey => @apikey} }
41
+ data = HTTParty.get("http://congress.api.sunlightfoundation.com/bills?sponsor_id=" + id.to_s , options)["results"]
42
+ return data.to_json
43
+ end
44
+
45
+ # Get all floor updates that mention a congressperson
46
+ def get_updates(id)
47
+ options = {:query => {:apikey => @apikey} }
48
+ data = HTTParty.get("http://congress.api.sunlightfoundation.com/floor_updates?legislator_ids=" + id.to_s , options)["results"]
49
+ return data.to_json
50
+ end
51
+
52
+ # Get all committees a congressperson is on
53
+ def get_committees(id)
54
+ options = {:query => {:apikey => @apikey} }
55
+ data = HTTParty.get("http://congress.api.sunlightfoundation.com/committees?member_ids=" + id.to_s , options)["results"]
56
+ return data.to_json
57
+ end
58
+
59
+ # Get all hearings for a committee
60
+ def get_hearings(cid)
61
+ options = {:query => {:apikey => @apikey} }
62
+ data = HTTParty.get("http://congress.api.sunlightfoundation.com/hearings?committee_id=" + cid.to_s , options)["results"]
63
+ return data.to_json
64
+ end
65
+
66
+ # Get hearings for a particular committee (JSON input)
67
+ def get_hearings_json(json_input)
68
+ jinput = JSON.parse(json_input)
69
+ savedata = Array.new
70
+
71
+ jinput.each do |l|
72
+ jhash = Hash[*l.flatten]
73
+ cid = jhash["committee_id"]
74
+ savedata = savedata + JSON.parse(get_hearings(cid))
75
+ end
76
+ return savedata.to_json
77
+ end
78
+
79
+ # Get all events (hearings, votes, bills, amendments, floor updates) for a congressperson and output JSON
80
+ def get_events(id)
81
+ votes = JSON.parse(get_votes(id))
82
+ amendments = JSON.parse(get_amendments(id))
83
+ bills = JSON.parse(get_bills(id))
84
+ updates = JSON.parse(get_updates(id))
85
+ hearings = JSON.parse(get_hearings_json(get_committees(id)))
86
+
87
+ combinedata = votes + amendments + bills + updates + hearings
88
+ combinedata.to_json
89
+ end
90
+ end
91
+
92
+ # Make gem
93
+ # Add to TT
94
+ # Make events work with TimelineGen
95
+ # Make all methods work with TimelineGen
metadata ADDED
@@ -0,0 +1,46 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: sunlightcongress
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - M. C. McGrath
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2013-12-16 00:00:00.000000000 Z
13
+ dependencies: []
14
+ description: Access to Sunlight Foundation's congress data.
15
+ email: shidash@shidash.com
16
+ executables: []
17
+ extensions: []
18
+ extra_rdoc_files: []
19
+ files:
20
+ - lib/sunlight_congress.rb
21
+ homepage:
22
+ licenses: []
23
+ post_install_message:
24
+ rdoc_options: []
25
+ require_paths:
26
+ - lib
27
+ required_ruby_version: !ruby/object:Gem::Requirement
28
+ none: false
29
+ requirements:
30
+ - - ! '>='
31
+ - !ruby/object:Gem::Version
32
+ version: '0'
33
+ required_rubygems_version: !ruby/object:Gem::Requirement
34
+ none: false
35
+ requirements:
36
+ - - ! '>='
37
+ - !ruby/object:Gem::Version
38
+ version: '0'
39
+ requirements: []
40
+ rubyforge_project:
41
+ rubygems_version: 1.8.23
42
+ signing_key:
43
+ specification_version: 3
44
+ summary: Wrapper for Sunlight Foundation's new congress API
45
+ test_files: []
46
+ has_rdoc: