hoverbird-ny-times-congress 1.2.1 → 1.2.2

Sign up to get free protection for your applications and to get access to all the features.
data/TODO CHANGED
@@ -1,2 +1,3 @@
1
1
  * Auto-fill current session number based on the year.
2
- * Select congress members by state.
2
+ * Select congress members by state.
3
+ * A Position should fetch the RollCallVote on which it is based
@@ -1,4 +1,4 @@
1
1
  ---
2
2
  :major: 1
3
3
  :minor: 2
4
- :patch: 1
4
+ :patch: 2
@@ -13,37 +13,34 @@ module NYTimes
13
13
 
14
14
  def self.find(id)
15
15
  response = invoke("members/#{id}.json")
16
- require 'ruby-debug'
17
- debugger if response.inspect unless response.has_key?('results')
18
16
  new(response['results'].first)
19
17
  end
20
18
  attr_reader :attributes, :id
21
-
22
- def initialize(args={})
23
- @attributes = {}
24
- @id = args.delete('id') || args.delete('member_id')
25
- transformed = transform(args, ATTRIBUTE_MAP)
26
- transformed.each_pair do |attribute_name, attribute_value|
27
- attributes[attribute_name.to_sym] = attribute_value
28
- end
29
- @fully_loaded = false
30
- end
31
19
 
32
20
  def positions
33
- response = Base.invoke("members/#{id}/votes.json")
34
- response = response['results'].first['votes']
35
- positions_for(response)
21
+ @positions ||= fetch_positions
36
22
  end
23
+ alias votes positions
37
24
 
38
- def votes
39
- response = Base.invoke("members/#{id}/votes.json")
40
- response = response['results'].first['votes']
41
- votes_for(response)
42
- end
43
-
25
+ def initialize(args={})
26
+ prepare_arguments(args)
27
+ @attributes = {}
28
+ @transformed_arguments.each_pair do |name, value|
29
+ attributes[name.to_sym] = value
30
+ end
31
+ @fully_loaded = false
32
+ end
33
+
44
34
  private
45
35
  attr_reader :fully_loaded
46
36
 
37
+ def prepare_arguments(hash)
38
+ args = hash.dup
39
+ @id = args.delete('member_id') || args.delete('id')
40
+ raise ArgumentError, "could not assign ID" unless @id.is_a?(String)
41
+ @transformed_arguments = transform(args, ATTRIBUTE_MAP)
42
+ end
43
+
47
44
  def fully_loaded?
48
45
  fully_loaded
49
46
  end
@@ -53,7 +50,12 @@ module NYTimes
53
50
  attributes.merge!(full_legislator.attributes)
54
51
  @fully_loaded = true
55
52
  end
56
-
53
+
54
+ def fetch_positions
55
+ response = Base.invoke("members/#{id}/votes.json")
56
+ response = response['results'].first['votes']
57
+ positions_for(response)
58
+ end
57
59
  end
58
60
  end
59
61
  end
@@ -86,4 +86,52 @@ def role_response_fragment
86
86
  "end_date":"2009-01-20"
87
87
  }
88
88
  JSON
89
+ end
90
+
91
+ def member_positions_response
92
+ <<-JSON
93
+ {
94
+ "status":"OK",
95
+ "copyright":"Copyright (c) 2009 The New York Times Company. All Rights Reserved.",
96
+ "results":[
97
+ {
98
+ "member_id":"N000147",
99
+ "total_votes":"100",
100
+ "offset":"0",
101
+ "votes":[
102
+ {
103
+ "member_id":"N000147",
104
+ "chamber":"House",
105
+ "congress":"111",
106
+ "session":"1",
107
+ "roll_call":"23",
108
+ "date":"2009-01-21",
109
+ "time":"15:37:00",
110
+ "position":"Yes"
111
+ },
112
+ {
113
+ "member_id":"N000147",
114
+ "chamber":"House",
115
+ "congress":"111",
116
+ "session":"1",
117
+ "roll_call":"19",
118
+ "date":"2009-01-15",
119
+ "time":"13:37:00",
120
+ "position":"Yes"
121
+ },
122
+ {
123
+ "member_id":"N000147",
124
+ "chamber":"House",
125
+ "congress":"110",
126
+ "session":"1",
127
+ "roll_call":"1031",
128
+ "date":"2007-11-01",
129
+ "time":"14:21:00",
130
+ "position":"No"
131
+ }
132
+ ]
133
+ }
134
+ ]
135
+ }
136
+ JSON
89
137
  end
@@ -1,8 +1,6 @@
1
1
  require File.dirname(__FILE__) + '/spec_helper.rb'
2
2
 
3
- describe Legislator do
4
- attr_reader :legislator, :role, :parsed_data
5
-
3
+ describe Legislator do
6
4
  describe ".find" do
7
5
  attr_reader :joe
8
6
 
@@ -28,13 +26,15 @@ describe Legislator do
28
26
 
29
27
  describe "#initialize" do
30
28
  context "with limited params hash" do
29
+ attr_reader :legislator, :role, :parsed_data
30
+
31
31
  def example_data
32
32
  limited_legislator_attributes
33
33
  end
34
34
 
35
35
  before do
36
- @parsed_data = JSON.parse(example_data)
37
- @legislator = Legislator.new(parsed_data)
36
+ @parsed_data = JSON.parse(example_data)
37
+ @legislator = Legislator.new(parsed_data)
38
38
  end
39
39
 
40
40
  it "assigns attributes as expected" do
@@ -63,7 +63,8 @@ describe Legislator do
63
63
  end
64
64
  end
65
65
 
66
- describe "with full bio and roles hash" do
66
+ context "with full bio and roles hash" do
67
+ attr_reader :legislator, :role, :parsed_data
67
68
 
68
69
  def example_data
69
70
  full_legislator_attributes
@@ -87,26 +88,51 @@ describe Legislator do
87
88
  legislator.roles.size.should == 2
88
89
  legislator.roles.each {|role| role.should be_kind_of(Role)}
89
90
  end
91
+
92
+ it "raises an error if it's unable to assign an id" do
93
+ data = @parsed_data.dup.delete('member_id')
94
+ lambda {Legislator.new(dat)}.should raise_error
95
+ end
96
+
90
97
  end
91
98
  end
92
99
 
93
100
  describe "#positions" do
94
- it "needs specs"
95
- end
96
-
97
- describe "#roles" do
101
+ attr_reader :legislator, :legislator_id, :role, :positions, :parsed_data
102
+
98
103
  def example_data
99
- limited_legislator_attributes
100
- end
104
+ full_legislator_attributes
105
+ end
101
106
 
102
107
  before do
103
- @parsed_data = JSON.parse(example_data)
104
- @legislator = Legislator.new(parsed_data)
108
+ @legislator_id = 'L000304'
109
+ FakeWeb.clean_registry
110
+ FakeWeb.register_uri(api_url_for("members/#{legislator_id}/votes.json"), :string => member_positions_response)
111
+ FakeWeb.register_uri(api_url_for("members/#{legislator_id}.json"), :string => member_response)
112
+ @legislator = Legislator.find(legislator_id)
105
113
  end
106
114
 
115
+ it "returns an Array of Positions for the given Legislator" do
116
+ legislator.positions.should_not be_nil
117
+ legislator.positions.size.should == 3
118
+ end
119
+
120
+ end
121
+
122
+
123
+ describe "#roles" do
124
+
107
125
  context "when bio and roles haven't been populated" do
108
-
126
+ attr_reader :legislator, :role, :parsed_data
127
+ def example_data
128
+ limited_legislator_attributes
129
+ end
130
+
109
131
  before do
132
+ @parsed_data = JSON.parse(example_data)
133
+ @parsed_data['id'].should_not be_nil
134
+ @legislator = Legislator.new(parsed_data)
135
+
110
136
  legislator.attributes[:roles].should be_nil
111
137
  legislator.attributes[:url].should be_nil
112
138
  legislator.attributes[:birthdate].should be_nil
@@ -124,6 +150,8 @@ describe Legislator do
124
150
  end
125
151
 
126
152
  context "when bio and roles have already been loaded" do
153
+ attr_reader :legislator, :role, :parsed_data
154
+
127
155
  def example_data
128
156
  full_legislator_attributes
129
157
  end
@@ -139,7 +167,6 @@ describe Legislator do
139
167
  legislator.date_of_birth.should_not be_nil
140
168
  end
141
169
  end
142
-
143
170
  end
144
171
 
145
172
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: hoverbird-ny-times-congress
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.2.1
4
+ version: 1.2.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Patrick Ewing
@@ -9,7 +9,7 @@ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
 
12
- date: 2009-02-20 00:00:00 -08:00
12
+ date: 2009-03-10 00:00:00 -07:00
13
13
  default_executable: congresh
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency