hulse 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,15 @@
1
+ ---
2
+ !binary "U0hBMQ==":
3
+ metadata.gz: !binary |-
4
+ NjllNjg3OGYwNTNkMjdlYzRhY2Y4ZjQ1Yjg4ZWJiNDA0ODQxZGY1Mg==
5
+ data.tar.gz: !binary |-
6
+ ZWZiMzliODMzM2Y2NDM5MDA3MDJhNGEyMmZlYmI3YjIyMjUwOWUzOA==
7
+ SHA512:
8
+ metadata.gz: !binary |-
9
+ OGNiMjkxOGVmOTA1NGJmMzMzNWM2NGM1YmE3ZTA1NTcyNTcwZWNmNTdhNTRi
10
+ MjMyODc0OWZhY2M0YTc1ODdmZjllNWIwZDZmOGU3MzQ5YWVmN2E1YzNlOWI0
11
+ ZDFjNjQ2NWQwZmYzNzc0MTk0OTM3ZjhmYmE3NWM1YzZhOGExYTg=
12
+ data.tar.gz: !binary |-
13
+ MGNkN2Y2NTcyNThhZTFlZGYzZDQ3OTRmY2MyYjVhZTU0OTE2MjVhYWVlN2Q0
14
+ YWMxMjEyNGU1Mjk1NzNjMmE0NjRiZmNiMmJjOTdjZTY0ZTNhNWIzNzJiYjIw
15
+ NDFmM2RlYzY2ZTEzZTllZDdhZDAyOGJlODRkYWRiNDg2NDljZTI=
data/.gitignore ADDED
@@ -0,0 +1,18 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ Gemfile.lock
7
+ InstalledFiles
8
+ _yardoc
9
+ coverage
10
+ doc/
11
+ lib/bundler/man
12
+ pkg
13
+ rdoc
14
+ spec/reports
15
+ test/tmp
16
+ test/version_tmp
17
+ tmp
18
+ .DS_Store
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in hulse.gemspec
4
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2013 Derek Willis
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,51 @@
1
+ # Hulse
2
+
3
+ Hulse is a Ruby gem for accessing House and Senate roll call votes from the official sources on [house.gov](http://clerk.house.gov/evs/2013/index.asp) and [senate.gov](http://www.senate.gov/pagelayout/legislative/a_three_sections_with_teasers/votes.htm). It is developed under Ruby 1.9.3.
4
+
5
+ Hulse has two classes, `HouseVote` and `SenateVote` which create Ruby objects using the XML attributes available from roll call vote data (voice votes are not covered by Hulse or available as data from official sources). Hulse makes a few changes, renaming some attributes for clarity and consistency, and collapsing each House vote's date and time into a single datetime attribute. Otherwise it does not alter the original data.
6
+
7
+ `HouseVote` and `SenateVote` have different attributes due to parliamentary conventions and the presence or absence of data in one chamber or the other. Senators are uniquely identified by a `lis_member_id`; House members are uniquely identified by a `bioguide_id` beginning in 2003. Prior to 2003, there is no unique ID for House members, but using a combination of name, state and political party one can be manfactured. House member attributes also include an `unaccented_name` and an `name` attribute that may contain accent characters.
8
+
9
+ Hulse is named for Carl Hulse, a longtime congressional correspondent for The New York Times.
10
+
11
+ ## Installation
12
+
13
+ Add this line to your application's Gemfile:
14
+
15
+ gem 'hulse'
16
+
17
+ And then execute:
18
+
19
+ $ bundle
20
+
21
+ Or install it yourself as:
22
+
23
+ $ gem install hulse
24
+
25
+ ## Usage
26
+
27
+ For both House and Senate votes, pass the year and roll call number into the `find` class method:
28
+
29
+ ```ruby
30
+ 1.9.3-p484> require 'hulse'
31
+ 1.9.3-p484> include Hulse
32
+ 1.9.3-p484> hv = HouseVote.find(2013, 628)
33
+ 1.9.3-p484> hv.question
34
+ => "On Agreeing to the Amendment"
35
+ 1.9.3-p484> hv.vote_count
36
+ => {:yea_total=>157, :nay_total=>258, :present_total=>0, :not_voting_total=>16}
37
+ ```
38
+
39
+ Be aware that in 2012, there were 5 House votes that occurred on Jan. 1, 2013. These are considered "2012" votes by [the Clerk of the House](http://clerk.house.gov/evs/2012/index.asp), so use 2012 as the year for these.
40
+
41
+ ## Authors
42
+
43
+ * [Derek Willis](https://github.com/dwillis)
44
+
45
+ ## Contributing
46
+
47
+ 1. Fork it ( http://github.com/dwillis/hulse/fork )
48
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
49
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
50
+ 4. Push to the branch (`git push origin my-new-feature`)
51
+ 5. Create new Pull Request
data/Rakefile ADDED
@@ -0,0 +1 @@
1
+ require "bundler/gem_tasks"
data/hulse.gemspec ADDED
@@ -0,0 +1,24 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'hulse/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "hulse"
8
+ spec.version = Hulse::VERSION
9
+ spec.authors = ["Derek Willis"]
10
+ spec.email = ["dwillis@gmail.com"]
11
+ spec.summary = %q{Hulse is a Ruby gem for accessing House and Senate roll call votes from the official sources on house.gov and senate.gov}
12
+ spec.description = %q{Turns House and Senate votes into Ruby objects for your legislative pleasure.}
13
+ spec.homepage = ""
14
+ spec.license = "MIT"
15
+
16
+ spec.files = `git ls-files`.split($/)
17
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
18
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
19
+ spec.require_paths = ["lib"]
20
+
21
+ spec.add_development_dependency "bundler", "~> 1.5"
22
+ spec.add_development_dependency "rake"
23
+ spec.add_dependency "httparty"
24
+ end
@@ -0,0 +1,50 @@
1
+ module Hulse
2
+ class HouseVote
3
+
4
+ attr_reader :majority, :congress, :session, :chamber, :vote_number, :bill_number, :question, :vote_type, :vote_result, :vote_timestamp, :description,
5
+ :party_summary, :vote_count, :members, :amendment_number, :amendment_author
6
+
7
+ def initialize(params={})
8
+ params.each_pair do |k,v|
9
+ instance_variable_set("@#{k}", v)
10
+ end
11
+ end
12
+
13
+ def self.find(year, vote)
14
+ url = "http://clerk.house.gov/evs/#{year.to_s}/roll#{vote}.xml"
15
+ response = HTTParty.get(url)
16
+ self.create_from_vote(response.parsed_response['rollcall_vote'])
17
+ end
18
+
19
+ def self.create_from_vote(response)
20
+ party_totals = []
21
+ response['vote_metadata']['vote_totals']['totals_by_party'].each do |p|
22
+ party_totals << p.inject({}){|memo,(k,v)| memo[k.to_sym] = v; memo}
23
+ end
24
+ members = []
25
+ mappings = {"__content__" => "name"}
26
+ response['vote_data']['recorded_vote'].each do |m|
27
+ m['legislator']['name'] = m['legislator'].delete('__content__')
28
+ m['legislator']['bioguide_id'] = m['legislator'].delete('name_id') # prior to 2003, bioguide IDs were not used in the XML
29
+ m['legislator']['vote'] = m['vote']
30
+ members << m['legislator'].inject({}){|memo,(k,v)| memo[k.to_sym] = v; memo}
31
+ end
32
+ self.new(:majority => response['vote_metadata']['majority'],
33
+ :congress => response['vote_metadata']['congress'].to_i,
34
+ :session => response['vote_metadata']['session'],
35
+ :chamber => response['vote_metadata']['chamber'],
36
+ :vote_number => response['vote_metadata']['rollcall_num'].to_i,
37
+ :bill_number => response['vote_metadata']['legis_num'],
38
+ :question => response['vote_metadata']['vote_question'],
39
+ :amendment_number => response['vote_metadata']['amendment_num'],
40
+ :amendment_author => response['vote_metadata']['amendment_author'],
41
+ :vote_type => response['vote_metadata']['vote_type'],
42
+ :vote_result => response['vote_metadata']['vote_result'],
43
+ :vote_timestamp => DateTime.parse(response['vote_metadata']['action_date'] + ' ' + response['vote_metadata']['action_time']['time_etz']),
44
+ :description => response['vote_metadata']['vote_desc'],
45
+ :party_summary => party_totals,
46
+ :vote_count => response['vote_metadata']['vote_totals']['totals_by_vote'].reject{|k,v| k == 'total_stub'}.inject({}){|memo,(k,v)| memo[k.to_sym] = v.to_i; memo},
47
+ :members => members)
48
+ end
49
+ end
50
+ end
@@ -0,0 +1,49 @@
1
+ module Hulse
2
+ class SenateVote
3
+
4
+ attr_reader :congress, :session, :year, :vote_number, :vote_timestamp, :updated_at, :vote_question_text, :vote_document_text,
5
+ :vote_result_text, :question, :vote_title, :majority_requirement, :vote_result, :document, :amendment, :vote_count, :tie_breaker, :members
6
+
7
+ def initialize(params={})
8
+ params.each_pair do |k,v|
9
+ instance_variable_set("@#{k}", v)
10
+ end
11
+ end
12
+
13
+ def self.find(year, vote)
14
+ # TODO: need to special-case 2013 votes from 112th congress, 2nd session
15
+ congress, session = Hulse::Utils.convert_year_to_congress_and_session(year)
16
+ url = "http://www.senate.gov/legislative/LIS/roll_call_votes/vote#{congress.to_s}#{session.to_s}/vote_#{congress.to_s}_#{session.to_s}_#{vote.to_s.rjust(5,"0")}.xml"
17
+ response = HTTParty.get(url)
18
+ self.create_from_vote(response.parsed_response['roll_call_vote'])
19
+ end
20
+
21
+ def self.create_from_vote(response)
22
+ members = []
23
+ response['members']['member'].each do |m|
24
+ members << m.inject({}){|memo,(k,v)| memo[k.to_sym] = v; memo}
25
+ end
26
+ self.new(:congress => response['congress'].to_i,
27
+ :session => response['session'].to_i,
28
+ :year => response['congress_year'].to_i,
29
+ :vote_number => response['vote_number'].to_i,
30
+ :vote_timestamp => DateTime.parse(response['vote_date']),
31
+ :updated_at => DateTime.parse(response['modify_date']),
32
+ :vote_question_text => response['vote_question_text'],
33
+ :vote_document_text => response['vote_document_text'],
34
+ :vote_result_text => response['vote_result_text'],
35
+ :question => response['question'],
36
+ :vote_title => response['vote_title'],
37
+ :majority_requirement => response['majority_requirement'],
38
+ :vote_result => response['vote_result'],
39
+ :document => response['document'].inject({}){|memo,(k,v)| memo[k.to_sym] = v; memo},
40
+ :amendment => response['amendment'].inject({}){|memo,(k,v)| memo[k.to_sym] = v; memo},
41
+ :vote_count => response['count'].inject({}){|memo,(k,v)| memo[k.to_sym] = v; memo},
42
+ :tie_breaker => response['tie_breaker'].inject({}){|memo,(k,v)| memo[k.to_sym] = v; memo},
43
+ :members => members
44
+ )
45
+ end
46
+
47
+
48
+ end
49
+ end
@@ -0,0 +1,3 @@
1
+ module Hulse
2
+ VERSION = "0.0.1"
3
+ end
data/lib/hulse.rb ADDED
@@ -0,0 +1,47 @@
1
+ require "hulse/version"
2
+ require "hulse/house_vote"
3
+ require "hulse/senate_vote"
4
+ require 'httparty'
5
+ require 'oj'
6
+
7
+ module Hulse
8
+ class Utils
9
+
10
+ CONGRESSES = {
11
+ 2014 => 113,
12
+ 2013 => 113,
13
+ 2012 => 112,
14
+ 2011 => 112,
15
+ 2010 => 111,
16
+ 2009 => 111,
17
+ 2008 => 110,
18
+ 2007 => 110,
19
+ 2006 => 109,
20
+ 2005 => 109,
21
+ 2004 => 108,
22
+ 2003 => 108,
23
+ 2002 => 107,
24
+ 2001 => 107,
25
+ 2000 => 106,
26
+ 1999 => 106,
27
+ 1998 => 106,
28
+ 1997 => 105,
29
+ 1996 => 105,
30
+ 1995 => 104,
31
+ 1994 => 104,
32
+ 1993 => 103,
33
+ 1992 => 103,
34
+ 1991 => 102,
35
+ 1990 => 102,
36
+ 1989 => 101
37
+ }
38
+
39
+ def self.convert_year_to_congress_and_session(year)
40
+ congress = CONGRESSES[year]
41
+ session = year.odd? ? 1 : 2
42
+ return [congress, session]
43
+ end
44
+
45
+
46
+ end
47
+ end
metadata ADDED
@@ -0,0 +1,97 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: hulse
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Derek Willis
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2013-12-31 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ~>
18
+ - !ruby/object:Gem::Version
19
+ version: '1.5'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ~>
25
+ - !ruby/object:Gem::Version
26
+ version: '1.5'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ! '>='
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ! '>='
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: httparty
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ! '>='
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :runtime
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ! '>='
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ description: Turns House and Senate votes into Ruby objects for your legislative pleasure.
56
+ email:
57
+ - dwillis@gmail.com
58
+ executables: []
59
+ extensions: []
60
+ extra_rdoc_files: []
61
+ files:
62
+ - .gitignore
63
+ - Gemfile
64
+ - LICENSE.txt
65
+ - README.md
66
+ - Rakefile
67
+ - hulse.gemspec
68
+ - lib/hulse.rb
69
+ - lib/hulse/house_vote.rb
70
+ - lib/hulse/senate_vote.rb
71
+ - lib/hulse/version.rb
72
+ homepage: ''
73
+ licenses:
74
+ - MIT
75
+ metadata: {}
76
+ post_install_message:
77
+ rdoc_options: []
78
+ require_paths:
79
+ - lib
80
+ required_ruby_version: !ruby/object:Gem::Requirement
81
+ requirements:
82
+ - - ! '>='
83
+ - !ruby/object:Gem::Version
84
+ version: '0'
85
+ required_rubygems_version: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - ! '>='
88
+ - !ruby/object:Gem::Version
89
+ version: '0'
90
+ requirements: []
91
+ rubyforge_project:
92
+ rubygems_version: 2.1.11
93
+ signing_key:
94
+ specification_version: 4
95
+ summary: Hulse is a Ruby gem for accessing House and Senate roll call votes from the
96
+ official sources on house.gov and senate.gov
97
+ test_files: []