nytimes-congress 1.4.0 → 1.4.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -20,20 +20,20 @@ You get a Congress object either by calling Congress.new with a number and chamb
20
20
 
21
21
  Through a Congress object, you can get a hash of Legislators, keyed by congressional Bio ID.
22
22
 
23
- senators = Senate.members
23
+ >> senators = Senate.members
24
24
 
25
25
  Legislator
26
26
  ---------------------
27
27
  You could crawl the Hash values to find the bio ID in question, as this is a useful key to use across other open government APIs (notably Sunlight).
28
28
 
29
- $ hrc = senators.values.find {|legislator| legislator.name == "Hillary Clinton"}
30
- $ bio_id = hrc.bio_id
29
+ >> coburn = senators.values.find {|legislator| legislator.last_name == "Coburn"}
30
+ >> bio_id = coburn.id
31
31
 
32
32
  Legislators come down the wire with a lot of interesting info, such as how often they vote along party lines, what roles they serve in Congress and more. Check out the full set of attributes in the Legislator class.
33
33
 
34
34
  You can also grab a Legislator directly by their Bio ID. This call includes full details on the congressperson's roles, biographical info and more:
35
35
 
36
- $ Legislator.find('C001041')
36
+ >> Legislator.find('C001041')
37
37
 
38
38
  When accessing a Legislator from a collection of congress members, they include only a limited set of attributes. However, the library will make a second API call and lazy-load full attributes if you ask for them specifically. So even though a Legislator object returned through Congress.members don't have the #gender attribute, if you call for a specific Legislators gender, that data will be fetched and populated just in time.
39
39
 
@@ -41,10 +41,17 @@ Current Member
41
41
  ---------------------
42
42
  If you need to check the current representative for a House district or senators from a state, each chamber exposes a method for that. Note that the senate call does not need a district and returns a list of two senators.
43
43
 
44
- $ pa19 = House.current_member_for_state_district("PA", 19)
45
- $ pa19.name
46
- "Todd R. Platts"
44
+ >> pa19 = House.current_member_for_state_district("PA", 19)
45
+ >> pa19.values.each do |member| puts member.name end
46
+ Todd R. Platts
47
47
 
48
+ Members by Vote Type
49
+ ---------------------
50
+ These responses are returned as an array of hashes rather than a single hash (like the Legislator methods), because the order matters. These methods return members ordered according to rank for missed votes percentage, voting with party percentage, the number of "Lone No" votes and perfect voting attendance. Missed votes ranks in descending order (most votes missed first), while voting with party ranks in ascending order (lowest party agreement percentage first).
51
+
52
+ >> party = House.votes('party')
53
+ >> party.first
54
+ => {"party_votes_pct"=>"70.49", "name"=>"Walt Minnick", "notes"=>"", "total_votes"=>"1326", "district"=>"1", "rank"=>"1", "votes_with_party"=>"18", "id"=>"M001175", "party"=>"D", "state"=>"ID"}
48
55
 
49
56
  Roll Call Votes
50
57
  ---------------------
@@ -1,5 +1,5 @@
1
1
  ---
2
+ :patch: 1
2
3
  :build:
3
- :patch: 0
4
4
  :major: 1
5
5
  :minor: 4
@@ -7,11 +7,13 @@ require 'JSON'
7
7
  require 'congress/base'
8
8
  require 'congress/attribute_transformation'
9
9
  require 'congress/congress'
10
+ require 'congress/current_member'
10
11
  require 'congress/legislator'
11
12
  require 'congress/legislator_vote_comparison'
13
+ require 'congress/member_vote_type'
12
14
  require 'congress/role'
13
15
  require 'congress/roll_call_vote'
14
16
  require 'congress/position'
15
17
  require 'congress/nomination'
16
18
  require 'congress/floor'
17
- require 'congress/current_member'
19
+
@@ -12,7 +12,7 @@ module NYTimes
12
12
  end
13
13
 
14
14
  def members(params = {})
15
- @members ||= fetch_members(Base.invoke("#{api_path}/members.json")['results'].first)
15
+ @members ||= fetch_members(Base.invoke("#{api_path}/members.json")['results'].first['members'])
16
16
  end
17
17
 
18
18
  def self.new_members(params = {})
@@ -45,25 +45,33 @@ module NYTimes
45
45
  end
46
46
  end
47
47
 
48
+ def votes(type)
49
+ members = fetch_members_by_type(Base.invoke("#{number}/#{chamber}/votes/#{type}.json")['results'].first['members'])
50
+ end
51
+
48
52
  protected
49
53
 
50
54
  def fetch_members(results)
51
55
  results.inject({}) do |hash, member|
52
56
  hash[member['id']] = Legislator.new(member)
53
- hash.delete_if {|k,v| k.nil? }
54
57
  hash
55
58
  end
56
59
  end
57
60
 
58
61
  def fetch_current_members(results)
59
- if results.length > 1
60
- results.collect do |member|
61
- CurrentMember.new(member)
62
- end
63
- else
64
- CurrentMember.new(results.first)
62
+ results.inject({}) do |hash, member|
63
+ hash[member['id']] = CurrentMember.new(member)
64
+ hash
65
65
  end
66
66
  end
67
+
68
+ def fetch_members_by_type(results)
69
+ h = Hash.new
70
+ results.each do |member|
71
+ h[member['id']] = MemberVoteType.new(member)
72
+ h
73
+ end
74
+ end
67
75
 
68
76
  def self.fetch_new_members
69
77
  results = Base.invoke("/members/new.json")['results'].first
@@ -0,0 +1,37 @@
1
+ module NYTimes
2
+ module Congress
3
+ class MemberVoteType < Base
4
+ include AttributeTransformation
5
+ attr_reader :attributes, :id
6
+
7
+ ATTRIBUTE_MAP = {
8
+ :integer_for => [:total_votes, :missed_votes, :rank, :district, :votes_with_party, :loneno],
9
+ :float_for => [:missed_votes_pct, :party_votes_pct],
10
+ :string_for => [:id, :name, :party, :state, :notes]
11
+ }
12
+
13
+ ATTRIBUTES = ATTRIBUTE_MAP.values.flatten
14
+ ATTRIBUTES.each {|attribute| define_lazy_reader_for_attribute_named(attribute) }
15
+
16
+ def initialize(args={})
17
+ prepare_arguments(args)
18
+ @attributes = {}
19
+ @transformed_arguments.each_pair {|name, value| attributes[name.to_sym] = value }
20
+ end
21
+
22
+ def to_s
23
+ id
24
+ end
25
+
26
+ private
27
+
28
+ def prepare_arguments(hash)
29
+ args = hash.dup
30
+ @id = args.delete('member_id') || args.delete('id')
31
+ raise ArgumentError, "could not assign ID" unless @id.is_a?(String)
32
+ @transformed_arguments = transform(args, ATTRIBUTE_MAP)
33
+ end
34
+
35
+ end
36
+ end
37
+ end
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: nytimes-congress
3
3
  version: !ruby/object:Gem::Version
4
- hash: 7
4
+ hash: 5
5
5
  prerelease: false
6
6
  segments:
7
7
  - 1
8
8
  - 4
9
- - 0
10
- version: 1.4.0
9
+ - 1
10
+ version: 1.4.1
11
11
  platform: ruby
12
12
  authors:
13
13
  - Patrick Ewing
@@ -61,6 +61,7 @@ files:
61
61
  - lib/ny-times/congress/floor.rb
62
62
  - lib/ny-times/congress/legislator.rb
63
63
  - lib/ny-times/congress/legislator_vote_comparison.rb
64
+ - lib/ny-times/congress/member_vote_type.rb
64
65
  - lib/ny-times/congress/nomination.rb
65
66
  - lib/ny-times/congress/position.rb
66
67
  - lib/ny-times/congress/role.rb