govkit 0.7.2 → 0.7.3

Sign up to get free protection for your applications and to get access to all the features.
Files changed (37) hide show
  1. data/.travis.yml +2 -0
  2. data/Gemfile +11 -5
  3. data/README.md +1 -1
  4. data/Rakefile +29 -13
  5. data/VERSION +1 -1
  6. data/govkit.gemspec +25 -36
  7. data/lib/gov_kit.rb +16 -5
  8. data/lib/gov_kit/configuration.rb +5 -5
  9. data/lib/gov_kit/follow_the_money.rb +5 -2
  10. data/lib/gov_kit/open_congress.rb +3 -11
  11. data/lib/gov_kit/open_congress/bill.rb +32 -29
  12. data/lib/gov_kit/open_congress/person.rb +21 -20
  13. data/lib/gov_kit/open_states.rb +10 -15
  14. data/lib/gov_kit/railtie.rb +0 -2
  15. data/lib/gov_kit/resource.rb +0 -1
  16. data/lib/gov_kit/transparency_data.rb +1 -1
  17. data/lib/gov_kit/vote_smart.rb +81 -6
  18. data/{init.rb → rails/init.rb} +0 -0
  19. data/spec/fixtures/open_states/401.response +9 -9
  20. data/spec/fixtures/open_states/404.response +9 -9
  21. data/spec/fixtures/open_states/bill.response +9 -240
  22. data/spec/fixtures/open_states/bill_find.response +9 -0
  23. data/spec/fixtures/open_states/bill_query.response +9 -1990
  24. data/spec/fixtures/open_states/committee_find.response +9 -53
  25. data/spec/fixtures/open_states/committee_query.response +9 -190
  26. data/spec/fixtures/open_states/legislator_find.response +9 -0
  27. data/spec/fixtures/open_states/legislator_query.response +9 -144
  28. data/spec/fixtures/open_states/state.response +9 -60
  29. data/spec/follow_the_money_spec.rb +20 -16
  30. data/spec/open_congress_spec.rb +23 -35
  31. data/spec/open_states_spec.rb +63 -78
  32. data/spec/search_engines_spec.rb +10 -13
  33. data/spec/spec_helper.rb +16 -8
  34. data/spec/transparency_data_spec.rb +19 -35
  35. metadata +140 -145
  36. data/spec/fixtures/open_states/410.response +0 -6
  37. data/spec/fixtures/open_states/legislator.response +0 -34
@@ -1,25 +1,22 @@
1
1
  require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
2
2
 
3
- # Provides "String.singularize"
4
- # which is used by resource_for_collection, in resource.rb
5
- require 'active_support/inflector'
6
-
7
3
  module GovKit::FollowTheMoney
8
4
  describe GovKit::FollowTheMoney do
9
5
 
10
6
  before(:all) do
11
- base_uri = GovKit::FollowTheMoneyResource.base_uri.gsub(/\./, '\.')
12
-
13
- urls = [
14
- ['/base_level\.industries\.list\.php\?.*page=0', 'business-page0.response'],
15
- ['/base_level\.industries\.list\.php\?.*page=1', 'business-page1.response'],
16
- ['/candidates\.contributions\.php\?imsp_candidate_id=111933', 'contribution.response'],
17
- ['/candidates\.contributions\.php\?imsp_candidate_id=0', 'unauthorized.response'],
18
- ]
19
-
20
- urls.each do |u|
21
- FakeWeb.register_uri(:get, %r|#{base_uri}#{u[0]}|, :response => File.join(FIXTURES_DIR, 'follow_the_money', u[1]))
22
- # puts "registered #{base_uri}#{u[0]}"
7
+ unless FakeWeb.allow_net_connect?
8
+ base_uri = GovKit::FollowTheMoneyResource.base_uri.gsub(/\./, '\.')
9
+
10
+ urls = [
11
+ ['/base_level\.industries\.list\.php\?.*page=0', 'business-page0.response'],
12
+ ['/base_level\.industries\.list\.php\?.*page=1', 'business-page1.response'],
13
+ ['/candidates\.contributions\.php\?imsp_candidate_id=111933', 'contribution.response'],
14
+ ['/candidates\.contributions\.php\?imsp_candidate_id=0', 'unauthorized.response'],
15
+ ]
16
+
17
+ urls.each do |u|
18
+ FakeWeb.register_uri(:get, %r|#{base_uri}#{u[0]}|, :response => File.join(FIXTURES_DIR, 'follow_the_money', u[1]))
19
+ end
23
20
  end
24
21
  end
25
22
 
@@ -30,11 +27,17 @@ module GovKit::FollowTheMoney
30
27
  end
31
28
 
32
29
  it "should raise NotAuthorized if the api key is not valid" do
30
+ api_key = GovKit.configuration.ftm_apikey
31
+
32
+ GovKit.configuration.ftm_apikey = nil
33
+
33
34
  lambda do
34
35
  @contribution = Contribution.find(0)
35
36
  end.should raise_error(GovKit::NotAuthorized)
36
37
 
37
38
  @contribution.should be_nil
39
+
40
+ GovKit.configuration.ftm_apikey = api_key
38
41
  end
39
42
 
40
43
  describe Business do
@@ -49,6 +52,7 @@ module GovKit::FollowTheMoney
49
52
 
50
53
  describe Contribution do
51
54
  it "should get a list of campaign contributions for a given person" do
55
+ pending 'This API call is restricted'
52
56
  @contributions = Contribution.find(111933)
53
57
  @contributions.should be_an_instance_of(Array)
54
58
  @contributions.each do |c|
@@ -4,30 +4,28 @@ module GovKit::OpenCongress
4
4
  describe GovKit::OpenCongress do
5
5
  before(:all) do
6
6
  @oc_objs = [Bill, Person]
7
- base_uri = "http://www.opencongress.org/api/"
8
-
9
- # An array of uris and filenames
10
- # Use FakeWeb to intercept net requests;
11
- # if a requested uri matches one of the following,
12
- # then return the contents of the corresponding file
13
- # as the result.
14
- urls = [
15
- [ "people?format=json&district=1&state=FL", "fl01.response" ],
16
- [ "people?format=json&district=0&state=ZZ", "empty.response" ],
17
- [ "most_blogged_representatives_this_week?format=json", "person.response" ],
18
- [ "bills?format=json&number=0", "empty.response" ],
19
- [ "bills?format=json&number=501", "501.response" ],
20
- [ "most_blogged_bills_this_week?format=json", "bill.response" ]
21
- ]
22
-
23
- urls.each do |u|
24
- FakeWeb.register_uri(:get, "#{base_uri}#{u[0]}", :response => File.join(FIXTURES_DIR, 'open_congress', u[1]))
7
+
8
+ unless FakeWeb.allow_net_connect?
9
+ base_uri = "http://api.opencongress.org/"
10
+
11
+ urls = [
12
+ [ "people?format=json&district=1&state=FL", "fl01.response" ],
13
+ [ "people?format=json&district=0&state=ZZ", "empty.response" ],
14
+ [ "most_blogged_representatives_this_week?format=json", "person.response" ],
15
+ [ "bills?format=json&number=0", "empty.response" ],
16
+ [ "bills?format=json&number=501", "501.response" ],
17
+ [ "most_blogged_bills_this_week?format=json", "bill.response" ]
18
+ ]
19
+
20
+ urls.each do |u|
21
+ FakeWeb.register_uri(:get, "#{base_uri}#{u[0]}", :response => File.join(FIXTURES_DIR, 'open_congress', u[1]))
22
+ end
25
23
  end
26
24
  end
27
25
 
28
26
  it "should construct a url properly" do
29
27
  @oc_objs.each do |klass|
30
- klass.construct_url(klass.to_s.split("::").last, {}).should == "http://www.opencongress.org/api/#{klass.to_s.split("::").last}?format=json"
28
+ klass.construct_url(klass.to_s.split("::").last, {}).should == "http://api.opencongress.org/#{klass.to_s.split("::").last}?format=json"
31
29
  end
32
30
  end
33
31
 
@@ -40,9 +38,7 @@ module GovKit::OpenCongress
40
38
  describe Person do
41
39
  context "#find" do
42
40
  it "should find a specific person" do
43
- lambda do
44
- @person = Person.find(:district => 1, :state => "FL").first
45
- end.should_not raise_error
41
+ @person = Person.find(:district => 1, :state => "FL").first
46
42
 
47
43
  @person.should be_an_instance_of(Person)
48
44
  @person.firstname.should == "Jeff"
@@ -50,9 +46,7 @@ module GovKit::OpenCongress
50
46
  end
51
47
 
52
48
  it "should return an empty array when no person fits the criteria" do
53
- lambda do
54
- @person = Person.find(:district => 0, :state => "ZZ")
55
- end.should_not raise_error
49
+ @person = Person.find(:district => 0, :state => "ZZ")
56
50
 
57
51
  @person.should be_an_instance_of(Array)
58
52
  @person.empty?.should be_true
@@ -61,9 +55,7 @@ module GovKit::OpenCongress
61
55
 
62
56
  context "#most blogged representatives this week" do
63
57
  it "should find reps" do
64
- lambda do
65
- @person = Person.most_blogged_representatives_this_week.first
66
- end.should_not raise_error
58
+ @person = Person.most_blogged_representatives_this_week.first
67
59
 
68
60
  @person.should be_an_instance_of(Person)
69
61
  @person.firstname.should == "Jeff"
@@ -75,13 +67,11 @@ module GovKit::OpenCongress
75
67
  describe Bill do
76
68
  context "#find" do
77
69
  it "should find a specific bill" do
78
- lambda do
79
- @bill = Bill.find(:number => 501).first
80
- end.should_not raise_error
70
+ @bill = Bill.find(:number => 501).first
81
71
 
82
72
  @bill.should be_an_instance_of(Bill)
83
73
  @bill.number.should == 501
84
- @bill.bill_type.should == "h"
74
+ @bill.bill_type.should == (FakeWeb.allow_net_connect? ? "hr" : "h")
85
75
  end
86
76
 
87
77
  it "should return an empty array when no bill fits the criteria" do
@@ -94,9 +84,7 @@ module GovKit::OpenCongress
94
84
 
95
85
  context "#most blogged bills this week" do
96
86
  it "should find specific bills" do
97
- lambda do
98
- @bill = Bill.most_blogged_bills_this_week.first
99
- end.should_not raise_error
87
+ @bill = Bill.most_blogged_bills_this_week.first
100
88
 
101
89
  @bill.should be_an_instance_of(Bill)
102
90
  @bill.number.should == 2678
@@ -1,80 +1,73 @@
1
1
  require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
2
2
 
3
- # Provides "String.singularize"
4
- # which is used by resource_for_collection, in resource.rb
5
- require 'active_support/inflector'
6
-
7
- # Provides string.last()
8
- # which is used by method_missing in resource.rb
9
- require 'active_support/core_ext/string'
10
-
11
3
  module GovKit::OpenStates
12
4
  describe GovKit::OpenStates do
13
5
  before(:all) do
14
- base_uri = GovKit::OpenStatesResource.base_uri.gsub(/\./, '\.')
15
-
16
- # An array of uris and filenames
17
- # Use FakeWeb to intercept net requests;
18
- # if a requested uri matches one of the following,
19
- # then return the contents of the corresponding file
20
- # as the result.
21
- urls = [
22
- ['/bills/ca/20092010/AB667/', 'bill.response'],
23
- ['/bills/\?.*q=cooperatives.*', 'bill_query.response'],
24
- ['/bills/\?.*state=tx.*', 'bill_query.response'],
25
- ['/bills/\?.*q=professions.*', 'bill.response'],
26
- ['/bills/latest/\?', 'bill_query.response'],
27
- ['/legislators/2462/\?', 'legislator.response'],
28
- ['/legislators/410/\?', '410.response'],
29
- ['/legislators/401/\?', '401.response'],
30
- ['/legislators/404/\?', '404.response'],
31
- ['/legislators/\?.*state=zz.*', '404.response'],
32
- ['/legislators/\?.*state=ca.*', 'legislator.response'],
33
- ['/committees/MDC000012/', 'committee_find.response'],
34
- ['/committees/\?.*state=md', 'committee_query.response'],
35
- ['/metadata/ca/\?', 'state.response']
36
- ]
37
-
38
- # First convert each of the uri strings above into regexp's before
39
- # passing them on to register_uri.
40
- #
41
- # Internally, before checking if a new uri string matches one of the registered uri's,
42
- # FakeWeb normalizes it by parsing it with URI.parse(string), and then
43
- # calling URI.normalize on the resulting URI. This appears to reorder any
44
- # query parameters alphabetically by key.
45
- #
46
- # So the uri
47
- # http://openstates.sunlightlabs.com/api/v1/legislators/?state=zz&output=json&apikey=
48
- # would actually not match a registered uri of
49
- # ['/legislators/\?state=zz', '404.response'],
50
- # or
51
- # ['/legislators/\?state=zz*', '404.response'],
52
- # or even
53
- # ['/legislators/\?state=zz&output=json&apikey=', '404.response'],
54
- #
55
- # But it would match a registered uri of
56
- # ['/legislators/\?apikey=&output=json&state=zz', '404.response'],
57
- # or
58
- # ['/legislators/\?(.*)state=zz(.*)', '404.response'],
59
-
60
-
61
- urls.each do |u|
62
- FakeWeb.register_uri(:get, %r|#{base_uri}#{u[0]}|, :response => File.join(FIXTURES_DIR, 'open_states', u[1]))
6
+ unless FakeWeb.allow_net_connect?
7
+ base_uri = GovKit::OpenStatesResource.base_uri.gsub(/\./, '\.')
8
+
9
+ # @todo The fixtures are out-of-date.
10
+ urls = [
11
+ ['/bills/ca/20092010/lower/AB%20667/', 'bill.response'],
12
+ ['/bills/\?.*q=cooperatives.*', 'bill_find.response'],
13
+ ['/bills/\?.*state=tx.*', 'bill_query.response'],
14
+ ['/legislators/CAL000088/\?', 'legislator_find.response'],
15
+ ['/legislators/XXL123456/\?', '401.response'],
16
+ ['/legislators/CAL999999/\?', '404.response'],
17
+ ['/legislators/\?.*state=zz.*', '404.response'],
18
+ ['/legislators/\?.*state=ca.*', 'legislator_query.response'],
19
+ ['/committees/MDC000012/', 'committee_find.response'],
20
+ ['/committees/\?.*state=md', 'committee_query.response'],
21
+ ['/metadata/ca/\?', 'state.response']
22
+ ]
23
+
24
+ # First convert each of the uri strings above into regexp's before
25
+ # passing them on to register_uri.
26
+ #
27
+ # Internally, before checking if a new uri string matches one of the registered uri's,
28
+ # FakeWeb normalizes it by parsing it with URI.parse(string), and then
29
+ # calling URI.normalize on the resulting URI. This appears to reorder any
30
+ # query parameters alphabetically by key.
31
+ #
32
+ # So the uri
33
+ # http://openstates.sunlightlabs.com/api/v1/legislators/?state=zz&output=json&apikey=
34
+ # would actually not match a registered uri of
35
+ # ['/legislators/\?state=zz', '404.response'],
36
+ # or
37
+ # ['/legislators/\?state=zz*', '404.response'],
38
+ # or even
39
+ # ['/legislators/\?state=zz&output=json&apikey=', '404.response'],
40
+ #
41
+ # But it would match a registered uri of
42
+ # ['/legislators/\?apikey=&output=json&state=zz', '404.response'],
43
+ # or
44
+ # ['/legislators/\?(.*)state=zz(.*)', '404.response'],
45
+
46
+
47
+ urls.each do |u|
48
+ FakeWeb.register_uri(:get, %r|#{base_uri}#{u[0]}|, :response => File.join(FIXTURES_DIR, 'open_states', u[1]))
49
+ end
63
50
  end
64
51
  end
65
52
 
66
53
  it "should have the base uri set properly" do
67
54
  [State, Bill, Legislator].each do |klass|
68
- klass.base_uri.should == "http://openstates.sunlightlabs.com/api/v1"
55
+ klass.base_uri.should == "http://openstates.org/api/v1"
69
56
  end
70
57
  end
71
58
 
72
59
  it "should raise NotAuthorized if the api key is not valid" do
60
+ api_key = GovKit.configuration.sunlight_apikey
61
+
62
+ GovKit.configuration.sunlight_apikey = nil
63
+
73
64
  lambda do
74
- @legislator = Legislator.find(401)
65
+ @legislator = Legislator.find 'XXL123456'
75
66
  end.should raise_error(GovKit::NotAuthorized)
76
67
 
77
68
  @legislator.should be_nil
69
+
70
+ GovKit.configuration.sunlight_apikey = api_key
78
71
  end
79
72
 
80
73
  describe State do
@@ -89,7 +82,7 @@ module GovKit::OpenStates
89
82
 
90
83
  @state.should be_an_instance_of(State)
91
84
  @state.name.should == "California"
92
- @state.sessions.size.should == 8
85
+ @state.terms.first.sessions.size.should == 9
93
86
  end
94
87
  end
95
88
  end
@@ -98,7 +91,7 @@ module GovKit::OpenStates
98
91
  context "#find" do
99
92
  it "should find a bill by state abbreviation, session, chamber, bill_id" do
100
93
  lambda do
101
- @bill = Bill.find('ca', '20092010', 'lower', 'AB667')
94
+ @bill = Bill.find('ca', '20092010', 'AB 667', 'lower')
102
95
  end.should_not raise_error
103
96
 
104
97
  @bill.should be_an_instance_of(Bill)
@@ -114,29 +107,21 @@ module GovKit::OpenStates
114
107
  @bills.each do |b|
115
108
  b.should be_an_instance_of(Bill)
116
109
  end
117
- @bills.collect(&:bill_id).should include("SB 921")
118
- end
119
-
120
- it "should return a single bill result as an array" do
121
- @bills = Bill.search('professions')
122
-
123
- @bills.should be_an_instance_of(Array)
124
- @bills.collect(&:bill_id).should include("AB667")
110
+ @bills.collect(&:bill_id).should include("SB 207")
125
111
  end
126
-
127
112
  end
128
113
 
129
114
  context "#latest" do
130
115
  it "should get the latest bills by given criteria" do
131
116
  lambda do
132
- @latest = Bill.latest('2010-01-01', :state => 'tx')
117
+ @latest = Bill.latest('2012-11-01', :state => 'tx')
133
118
  end.should_not raise_error
134
119
 
135
120
  @latest.should be_an_instance_of(Array)
136
121
  @latest.each do |b|
137
122
  b.should be_an_instance_of(Bill)
138
123
  end
139
- @latest.collect(&:bill_id).should include("SB 2236")
124
+ @latest.collect(&:bill_id).should include("HB 41")
140
125
  end
141
126
  end
142
127
  end
@@ -145,16 +130,16 @@ module GovKit::OpenStates
145
130
  context "#find" do
146
131
  it "should find a specific legislator" do
147
132
  lambda do
148
- @legislator = Legislator.find(2462)
133
+ @legislator = Legislator.find('CAL000088')
149
134
  end.should_not raise_error
150
135
 
151
136
  @legislator.should be_an_instance_of(Legislator)
152
- @legislator.first_name.should == "Dave"
153
- @legislator.last_name.should == "Cox"
137
+ @legislator.first_name.should == "Bob"
138
+ @legislator.last_name.should == "Blumenfield"
154
139
  end
155
140
 
156
141
  it "should return an empty array if the legislator is not found" do
157
- @legislator = Legislator.find(404)
142
+ @legislator = Legislator.find('CAL999999')
158
143
 
159
144
  @legislator.should eql([])
160
145
  end
@@ -202,10 +187,10 @@ module GovKit::OpenStates
202
187
  end.should_not raise_error
203
188
 
204
189
  @committees.should be_an_instance_of(Array)
205
- @committees.length.should eql(20)
190
+ @committees.length.should eql(21)
206
191
  com = @committees[0]
207
192
  com.should be_an_instance_of(Committee)
208
- com['id'].should eql('MDC000009')
193
+ com['id'].should eql('MDC000001')
209
194
  end
210
195
  end
211
196
  end
@@ -3,19 +3,16 @@ require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
3
3
  module GovKit::SearchEngines
4
4
  describe GovKit::SearchEngines do
5
5
  before(:all) do
6
- google_news_uri = "http://news.google.com/"
7
-
8
- # An array of uris and filenames
9
- # Use FakeWeb to intercept net requests;
10
- # if a requested uri matches one of the following,
11
- # then return the contents of the corresponding file
12
- # as the result.
13
- urls = [
14
- [ "news?q=congress&output=rss&num=50", "google_news.response" ]
15
- ]
16
-
17
- urls.each do |u|
18
- FakeWeb.register_uri(:get, "#{google_news_uri}#{u[0]}", :response => File.join(FIXTURES_DIR, 'search_engines', u[1]))
6
+ unless FakeWeb.allow_net_connect?
7
+ google_news_uri = "http://news.google.com/"
8
+
9
+ urls = [
10
+ [ "news?q=congress&output=rss&num=50", "google_news.response" ]
11
+ ]
12
+
13
+ urls.each do |u|
14
+ FakeWeb.register_uri(:get, "#{google_news_uri}#{u[0]}", :response => File.join(FIXTURES_DIR, 'search_engines', u[1]))
15
+ end
19
16
  end
20
17
  end
21
18
 
data/spec/spec_helper.rb CHANGED
@@ -3,6 +3,22 @@ require 'rspec'
3
3
  require 'fakeweb'
4
4
  require File.dirname(__FILE__) + '/../lib/govkit'
5
5
 
6
+ # Set to true to run tests against the live URLs, and add the following to
7
+ # spec/support/api_keys.rb:
8
+ #
9
+ # unless FakeWeb.allow_net_connect?
10
+ # GovKit.configure do |config|
11
+ # config.sunlight_apikey = 'YOUR_SUNLIGHT_API_KEY'
12
+ # config.votesmart_apikey = 'YOUR_VOTESMART_API_KEY'
13
+ # config.ftm_apikey = 'YOUR_FTM_API_KEY'
14
+ # end
15
+ # end
16
+ FakeWeb.allow_net_connect = false
17
+
18
+ # Requires supporting ruby files with custom matchers and macros, etc,
19
+ # in spec/support/ and its subdirectories.
20
+ Dir[File.join(File.dirname(__FILE__), 'support', '**', '*.rb')].each {|f| require f}
21
+
6
22
  # prevent the use of `` in tests
7
23
  RSpec.configure do |c|
8
24
  end
@@ -25,12 +41,4 @@ module Kernel
25
41
  end
26
42
  end
27
43
 
28
- FakeWeb.allow_net_connect = false
29
-
30
44
  FIXTURES_DIR = File.join(File.dirname(__FILE__), 'fixtures')
31
-
32
- GovKit.configure do |config|
33
- config.openstates_apikey = 'YOUR_OPENSTATES_API_KEY'
34
- config.votesmart_apikey = 'YOUR_VOTESMART_API_KEY'
35
- config.ftm_apikey = 'YOUR_FTM_API_KEY'
36
- end