govkit 0.6.1 → 0.7.0
Sign up to get free protection for your applications and to get access to all the features.
- data/.rspec +3 -0
- data/Gemfile +13 -0
- data/README.md +0 -5
- data/Rakefile +1 -1
- data/VERSION +1 -1
- data/generators/govkit/templates/govkit.rb +3 -0
- data/govkit.gemspec +41 -13
- data/lib/gov_kit/acts_as_noteworthy.rb +15 -9
- data/lib/gov_kit/configuration.rb +3 -1
- data/lib/gov_kit/open_congress/bill.rb +3 -5
- data/lib/gov_kit/open_congress/blog_post.rb +3 -7
- data/lib/gov_kit/open_congress/news_post.rb +3 -7
- data/lib/gov_kit/open_congress/person.rb +2 -4
- data/lib/gov_kit/open_congress/person_stat.rb +2 -7
- data/lib/gov_kit/open_congress/roll_call.rb +4 -6
- data/lib/gov_kit/open_congress/roll_call_comparison.rb +1 -4
- data/lib/gov_kit/open_congress/voting_comparison.rb +1 -3
- data/lib/gov_kit/open_congress.rb +8 -0
- data/lib/gov_kit/open_states.rb +63 -14
- data/lib/gov_kit/railtie.rb +4 -0
- data/lib/gov_kit/resource.rb +62 -12
- data/lib/gov_kit/search_engines/bing.rb +38 -0
- data/lib/gov_kit/search_engines/google_blog.rb +3 -2
- data/lib/gov_kit/search_engines/google_news.rb +26 -16
- data/lib/gov_kit/search_engines/technorati.rb +1 -0
- data/lib/gov_kit/search_engines/wikipedia.rb +1 -1
- data/lib/gov_kit/search_engines.rb +1 -0
- data/lib/gov_kit/transparency_data.rb +98 -0
- data/lib/gov_kit/vote_smart.rb +9 -2
- data/lib/gov_kit.rb +4 -2
- data/spec/fixtures/bing/news_search.response +1 -0
- data/spec/fixtures/bing/no_results.response +1 -0
- data/spec/fixtures/open_congress/person.response +8 -0
- data/spec/fixtures/open_states/401.response +8 -4
- data/spec/fixtures/open_states/404.response +9 -0
- data/spec/fixtures/open_states/committee_find.response +53 -0
- data/spec/fixtures/open_states/committee_query.response +190 -0
- data/spec/fixtures/search_engines/google_news.response +8 -0
- data/spec/fixtures/transparency_data/contributions.response +18 -0
- data/spec/fixtures/transparency_data/entities_search.response +7 -0
- data/spec/fixtures/transparency_data/entities_search_limit_0.response +7 -0
- data/spec/fixtures/transparency_data/entities_search_limit_1.response +7 -0
- data/spec/fixtures/transparency_data/grants_find_all.response +7 -0
- data/spec/fixtures/transparency_data/lobbyists_find_all.response +7 -0
- data/spec/follow_the_money_spec.rb +7 -3
- data/spec/open_congress_spec.rb +36 -0
- data/spec/open_states_spec.rb +98 -16
- data/spec/search_engines_spec.rb +44 -0
- data/spec/spec_helper.rb +2 -3
- data/spec/transparency_data_spec.rb +106 -0
- metadata +118 -32
- data/spec/spec.opts +0 -6
data/.rspec
ADDED
data/Gemfile
ADDED
data/README.md
CHANGED
@@ -59,9 +59,4 @@ For Canadian open government data, our friends up north have created a [govkit-c
|
|
59
59
|
|
60
60
|
Let us know if you'd like to build a govkit for your region! We'd love to link to you. Your gem should be called, for example, govkit-uk (ISO 3166 country code), and your methods should live in the GovKit::GB namespace (for example).
|
61
61
|
|
62
|
-
# TODOs
|
63
|
-
|
64
|
-
* Guaranteed Eachability: If an API call is expected to return zero or more records, then GovKit should always return an array or nil to the caller, not a single object, even if there's only one record returned in this particular API call.
|
65
|
-
* Migration & documentation for acts_as_noteworthy
|
66
|
-
|
67
62
|
Copyright (c) 2010 Participatory Politics Foundation, released under the MIT license
|
data/Rakefile
CHANGED
@@ -22,7 +22,7 @@ begin
|
|
22
22
|
gem.email = "develop@opencongress.org"
|
23
23
|
gem.homepage = "http://github.com/opengovernment/govkit"
|
24
24
|
gem.authors = ["Participatory Politics Foundation", "Srinivas Aki", "Carl Tashian"]
|
25
|
-
gem.add_dependency('httparty', '>= 0.
|
25
|
+
gem.add_dependency('httparty', '>= 0.7.4')
|
26
26
|
gem.add_dependency('json', '>= 1.4.3')
|
27
27
|
gem.add_dependency('nokogiri', '>= 1.4.4')
|
28
28
|
gem.add_dependency('fastercsv', '>= 1.5.3')
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.
|
1
|
+
0.7.0
|
@@ -19,6 +19,9 @@ if defined? GovKit
|
|
19
19
|
# Technorati API key
|
20
20
|
config.technorati_apikey = 'YOUR_TECHNORATI_APIKEY'
|
21
21
|
|
22
|
+
# Bing App ID
|
23
|
+
config.bing_appid = 'YOUR_BING_APPID'
|
24
|
+
|
22
25
|
# Other things you could set here include alternate URLs for
|
23
26
|
# the APIs. See GovKit::Configuration for available attributes.
|
24
27
|
end
|
data/govkit.gemspec
CHANGED
@@ -5,11 +5,11 @@
|
|
5
5
|
|
6
6
|
Gem::Specification.new do |s|
|
7
7
|
s.name = %q{govkit}
|
8
|
-
s.version = "0.
|
8
|
+
s.version = "0.7.0"
|
9
9
|
|
10
10
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
11
|
s.authors = ["Participatory Politics Foundation", "Srinivas Aki", "Carl Tashian"]
|
12
|
-
s.date = %q{2011-
|
12
|
+
s.date = %q{2011-06-29}
|
13
13
|
s.description = %q{Govkit lets you quickly get encapsulated Ruby objects for common open government APIs. We're starting with Sunlight's Open States API and the Project Vote Smart API.}
|
14
14
|
s.email = %q{develop@opencongress.org}
|
15
15
|
s.extra_rdoc_files = [
|
@@ -18,6 +18,8 @@ Gem::Specification.new do |s|
|
|
18
18
|
]
|
19
19
|
s.files = [
|
20
20
|
".document",
|
21
|
+
".rspec",
|
22
|
+
"Gemfile",
|
21
23
|
"LICENSE",
|
22
24
|
"README.md",
|
23
25
|
"Rakefile",
|
@@ -46,6 +48,7 @@ Gem::Specification.new do |s|
|
|
46
48
|
"lib/gov_kit/railtie.rb",
|
47
49
|
"lib/gov_kit/resource.rb",
|
48
50
|
"lib/gov_kit/search_engines.rb",
|
51
|
+
"lib/gov_kit/search_engines/bing.rb",
|
49
52
|
"lib/gov_kit/search_engines/google_blog.rb",
|
50
53
|
"lib/gov_kit/search_engines/google_news.rb",
|
51
54
|
"lib/gov_kit/search_engines/technorati.rb",
|
@@ -53,48 +56,73 @@ Gem::Specification.new do |s|
|
|
53
56
|
"lib/gov_kit/transparency_data.rb",
|
54
57
|
"lib/gov_kit/vote_smart.rb",
|
55
58
|
"lib/govkit.rb",
|
59
|
+
"spec/fixtures/bing/news_search.response",
|
60
|
+
"spec/fixtures/bing/no_results.response",
|
56
61
|
"spec/fixtures/follow_the_money/business-page0.response",
|
57
62
|
"spec/fixtures/follow_the_money/business-page1.response",
|
58
63
|
"spec/fixtures/follow_the_money/contribution.response",
|
59
64
|
"spec/fixtures/follow_the_money/unauthorized.response",
|
65
|
+
"spec/fixtures/open_congress/person.response",
|
60
66
|
"spec/fixtures/open_states/401.response",
|
67
|
+
"spec/fixtures/open_states/404.response",
|
61
68
|
"spec/fixtures/open_states/410.response",
|
62
69
|
"spec/fixtures/open_states/bill.response",
|
63
70
|
"spec/fixtures/open_states/bill_query.response",
|
71
|
+
"spec/fixtures/open_states/committee_find.response",
|
72
|
+
"spec/fixtures/open_states/committee_query.response",
|
64
73
|
"spec/fixtures/open_states/legislator.response",
|
65
74
|
"spec/fixtures/open_states/legislator_query.response",
|
66
75
|
"spec/fixtures/open_states/state.response",
|
76
|
+
"spec/fixtures/search_engines/google_news.response",
|
77
|
+
"spec/fixtures/transparency_data/contributions.response",
|
78
|
+
"spec/fixtures/transparency_data/entities_search.response",
|
79
|
+
"spec/fixtures/transparency_data/entities_search_limit_0.response",
|
80
|
+
"spec/fixtures/transparency_data/entities_search_limit_1.response",
|
81
|
+
"spec/fixtures/transparency_data/grants_find_all.response",
|
82
|
+
"spec/fixtures/transparency_data/lobbyists_find_all.response",
|
67
83
|
"spec/follow_the_money_spec.rb",
|
84
|
+
"spec/open_congress_spec.rb",
|
68
85
|
"spec/open_states_spec.rb",
|
69
|
-
"spec/
|
70
|
-
"spec/spec_helper.rb"
|
86
|
+
"spec/search_engines_spec.rb",
|
87
|
+
"spec/spec_helper.rb",
|
88
|
+
"spec/transparency_data_spec.rb"
|
71
89
|
]
|
72
90
|
s.homepage = %q{http://github.com/opengovernment/govkit}
|
73
91
|
s.require_paths = ["lib"]
|
74
|
-
s.rubygems_version = %q{1.
|
92
|
+
s.rubygems_version = %q{1.6.2}
|
75
93
|
s.summary = %q{Simple access to open government APIs around the web}
|
76
|
-
s.test_files = [
|
77
|
-
"spec/follow_the_money_spec.rb",
|
78
|
-
"spec/open_states_spec.rb",
|
79
|
-
"spec/spec_helper.rb"
|
80
|
-
]
|
81
94
|
|
82
95
|
if s.respond_to? :specification_version then
|
83
96
|
s.specification_version = 3
|
84
97
|
|
85
98
|
if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
|
86
|
-
s.add_runtime_dependency(%q<
|
99
|
+
s.add_runtime_dependency(%q<govkit>, [">= 0"])
|
100
|
+
s.add_runtime_dependency(%q<active_support>, [">= 0"])
|
101
|
+
s.add_runtime_dependency(%q<nokogiri>, [">= 0"])
|
102
|
+
s.add_runtime_dependency(%q<httparty>, [">= 0"])
|
103
|
+
s.add_runtime_dependency(%q<i18n>, [">= 0"])
|
104
|
+
s.add_runtime_dependency(%q<httparty>, [">= 0.7.4"])
|
87
105
|
s.add_runtime_dependency(%q<json>, [">= 1.4.3"])
|
88
106
|
s.add_runtime_dependency(%q<nokogiri>, [">= 1.4.4"])
|
89
107
|
s.add_runtime_dependency(%q<fastercsv>, [">= 1.5.3"])
|
90
108
|
else
|
91
|
-
s.add_dependency(%q<
|
109
|
+
s.add_dependency(%q<govkit>, [">= 0"])
|
110
|
+
s.add_dependency(%q<active_support>, [">= 0"])
|
111
|
+
s.add_dependency(%q<nokogiri>, [">= 0"])
|
112
|
+
s.add_dependency(%q<httparty>, [">= 0"])
|
113
|
+
s.add_dependency(%q<i18n>, [">= 0"])
|
114
|
+
s.add_dependency(%q<httparty>, [">= 0.7.4"])
|
92
115
|
s.add_dependency(%q<json>, [">= 1.4.3"])
|
93
116
|
s.add_dependency(%q<nokogiri>, [">= 1.4.4"])
|
94
117
|
s.add_dependency(%q<fastercsv>, [">= 1.5.3"])
|
95
118
|
end
|
96
119
|
else
|
97
|
-
s.add_dependency(%q<
|
120
|
+
s.add_dependency(%q<govkit>, [">= 0"])
|
121
|
+
s.add_dependency(%q<active_support>, [">= 0"])
|
122
|
+
s.add_dependency(%q<nokogiri>, [">= 0"])
|
123
|
+
s.add_dependency(%q<httparty>, [">= 0"])
|
124
|
+
s.add_dependency(%q<i18n>, [">= 0"])
|
125
|
+
s.add_dependency(%q<httparty>, [">= 0.7.4"])
|
98
126
|
s.add_dependency(%q<json>, [">= 1.4.3"])
|
99
127
|
s.add_dependency(%q<nokogiri>, [">= 1.4.4"])
|
100
128
|
s.add_dependency(%q<fastercsv>, [">= 1.5.3"])
|
@@ -6,19 +6,18 @@ module GovKit::ActsAsNoteworthy
|
|
6
6
|
|
7
7
|
module ActMethods
|
8
8
|
def acts_as_noteworthy(options={})
|
9
|
-
options[:keywords] ||= []
|
10
|
-
|
11
9
|
class_inheritable_accessor :options
|
12
10
|
self.options = options
|
13
11
|
|
14
12
|
unless included_modules.include? InstanceMethods
|
15
13
|
instance_eval do
|
16
|
-
has_many :mentions, :as => :owner
|
14
|
+
has_many :mentions, :as => :owner, :order => 'date desc'
|
17
15
|
|
18
16
|
with_options :as => :owner, :class_name => "Mention" do |c|
|
19
17
|
c.has_many :google_news_mentions, :conditions => {:search_source => "Google News"}, :order => 'date desc'
|
20
18
|
c.has_many :google_blog_mentions, :conditions => {:search_source => "Google Blogs"}, :order => 'date desc'
|
21
19
|
c.has_many :technorati_mentions, :conditions => {:search_source => "Technorati"}, :order => 'date desc'
|
20
|
+
c.has_many :bing_mentions, :conditions => {:search_source => "Bing"}, :order => 'date desc'
|
22
21
|
end
|
23
22
|
end
|
24
23
|
|
@@ -34,16 +33,23 @@ module GovKit::ActsAsNoteworthy
|
|
34
33
|
module InstanceMethods
|
35
34
|
|
36
35
|
def raw_mentions
|
37
|
-
|
38
|
-
attributes =
|
36
|
+
opts = self.options.clone
|
37
|
+
attributes = opts.delete(:with)
|
38
|
+
|
39
|
+
if opts[:geo]
|
40
|
+
opts[:geo] = self.instance_eval("#{opts[:geo]}")
|
41
|
+
end
|
39
42
|
|
43
|
+
query = []
|
40
44
|
attributes.each do |attr|
|
41
|
-
|
45
|
+
query << self.instance_eval("#{attr}")
|
42
46
|
end
|
47
|
+
|
43
48
|
{
|
44
|
-
:google_news => GovKit::SearchEngines::GoogleNews.search(
|
45
|
-
:google_blogs => GovKit::SearchEngines::GoogleBlog.search(
|
46
|
-
:technorati => GovKit::SearchEngines::Technorati.search(
|
49
|
+
:google_news => GovKit::SearchEngines::GoogleNews.search(query, opts),
|
50
|
+
:google_blogs => GovKit::SearchEngines::GoogleBlog.search(query, opts),
|
51
|
+
# :technorati => GovKit::SearchEngines::Technorati.search(query),
|
52
|
+
:bing => GovKit::SearchEngines::Bing.search(query, opts)
|
47
53
|
}
|
48
54
|
end
|
49
55
|
end
|
@@ -2,11 +2,12 @@ module GovKit
|
|
2
2
|
class Configuration
|
3
3
|
attr_accessor :sunlight_apikey, :openstates_base_url, :transparency_data_base_url, :transparency_data_categories_url
|
4
4
|
attr_accessor :votesmart_apikey, :votesmart_base_url
|
5
|
-
attr_accessor :ftm_apikey, :ftm_base_url
|
5
|
+
attr_accessor :openstates_apikey, :ftm_apikey, :ftm_base_url
|
6
6
|
attr_accessor :opencongress_apikey, :opencongress_base_url
|
7
7
|
attr_accessor :technorati_apikey, :technorati_base_url
|
8
8
|
attr_accessor :google_blog_base_url, :google_news_base_url
|
9
9
|
attr_accessor :wikipedia_base_url
|
10
|
+
attr_accessor :bing_appid, :bing_base_url
|
10
11
|
|
11
12
|
def initialize
|
12
13
|
@openstates_apikey = @votesmart_apikey = @ftm_apikey = ''
|
@@ -16,6 +17,7 @@ module GovKit
|
|
16
17
|
@ftm_base_url = 'api.followthemoney.org/'
|
17
18
|
@opencongress_base_url = 'www.opencongress.org/'
|
18
19
|
@technorati_base_url = 'api.technorati.com'
|
20
|
+
@bing_base_url = 'api.search.live.net'
|
19
21
|
@google_blog_base_url = 'blogsearch.google.com'
|
20
22
|
@google_news_base_url = 'news.google.com'
|
21
23
|
@wikipedia_base_url = 'en.wikipedia.org'
|
@@ -2,13 +2,11 @@ module GovKit
|
|
2
2
|
module OpenCongress
|
3
3
|
class Bill < OpenCongressObject
|
4
4
|
attr_accessor :bill_type, :id, :introduced, :last_speech, :last_vote_date, :last_vote_roll, :last_vote_where, :last_action, :number, :plain_language_summary, :session, :sponsor, :co_sponsors, :title_full_common, :status, :most_recent_actions, :bill_titles, :recent_blogs, :recent_news, :ident
|
5
|
-
|
5
|
+
|
6
6
|
def initialize(params)
|
7
|
-
|
8
|
-
instance_variable_set("@#{key}", value) if Bill.instance_methods.include? key
|
9
|
-
end
|
7
|
+
super Bill, params
|
10
8
|
end
|
11
|
-
|
9
|
+
|
12
10
|
def ident
|
13
11
|
"#{session}-#{bill_type}#{number}"
|
14
12
|
end
|
@@ -4,14 +4,10 @@ module GovKit
|
|
4
4
|
class BlogPost < OpenCongressObject
|
5
5
|
|
6
6
|
attr_accessor :title, :date, :url, :source_url, :excerpt, :source, :average_rating
|
7
|
-
|
8
|
-
|
9
|
-
def initialize(params)
|
10
|
-
params.each do |key, value|
|
11
|
-
instance_variable_set("@#{key}", value) if BlogPost.instance_methods.include? key
|
12
|
-
end
|
13
|
-
end
|
14
7
|
|
8
|
+
def initialize(params)
|
9
|
+
super BlogPost, params
|
10
|
+
end
|
15
11
|
|
16
12
|
end
|
17
13
|
|
@@ -4,14 +4,10 @@ module GovKit
|
|
4
4
|
class NewsPost < OpenCongressObject
|
5
5
|
|
6
6
|
attr_accessor :title, :date, :url, :source_url, :excerpt, :source, :average_rating
|
7
|
-
|
8
|
-
|
9
|
-
def initialize(params)
|
10
|
-
params.each do |key, value|
|
11
|
-
instance_variable_set("@#{key}", value) if NewsPost.instance_methods.include? key
|
12
|
-
end
|
13
|
-
end
|
14
7
|
|
8
|
+
def initialize(params)
|
9
|
+
super NewsPost, params
|
10
|
+
end
|
15
11
|
|
16
12
|
end
|
17
13
|
|
@@ -7,11 +7,9 @@ module GovKit
|
|
7
7
|
:name, :nickname, :osid, :party, :religion, :state, :title, :unaccented_name, :url, :user_approval,
|
8
8
|
:youtube_id, :oc_user_comments, :oc_users_tracking, :abstains_percentage, :with_party_percentage, :recent_news,
|
9
9
|
:recent_blogs, :person_stats
|
10
|
-
|
10
|
+
|
11
11
|
def initialize(params)
|
12
|
-
|
13
|
-
instance_variable_set("@#{key}", value) if Person.instance_methods.include? key
|
14
|
-
end
|
12
|
+
super Person, params
|
15
13
|
end
|
16
14
|
|
17
15
|
def self.find(params)
|
@@ -4,14 +4,9 @@ module GovKit
|
|
4
4
|
|
5
5
|
attr_accessor :votes_most_often_with_id, :opposing_party_votes_most_often_with_id, :votes_least_often_with_id, :same_party_votes_least_often_with_id, :party_votes_percentage, :abstains_percentage, :abstains_percentage_rank, :party_votes_percentage_rank, :sponsored_bills, :cosponsored_bills, :abstains, :sponsored_bills_passed_rank, :cosponsored_bills_passed_rank, :sponsored_bills_passed, :cosponsored_bills_passed, :sponsored_bills_rank, :cosponsored_bills_rank
|
6
6
|
|
7
|
-
|
8
7
|
def initialize(params)
|
9
|
-
|
10
|
-
|
11
|
-
end
|
12
|
-
end
|
13
|
-
|
14
|
-
|
8
|
+
super PersonStat, params
|
9
|
+
end
|
15
10
|
end
|
16
11
|
|
17
12
|
end
|
@@ -4,13 +4,11 @@ module GovKit
|
|
4
4
|
|
5
5
|
attr_accessor :abstains, :presents, :roll_type, :title, :question, :republican_position, :democratic_position,
|
6
6
|
:amendment_id, :ayes, :nays, :bill, :date, :number, :id, :required, :where
|
7
|
-
|
7
|
+
|
8
8
|
def initialize(params)
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
end
|
13
|
-
|
9
|
+
super RollCall, params
|
10
|
+
end
|
11
|
+
|
14
12
|
end
|
15
13
|
end
|
16
14
|
end
|
@@ -5,10 +5,7 @@ module GovKit
|
|
5
5
|
attr_accessor :roll_call, :person1, :person2
|
6
6
|
|
7
7
|
def initialize(params)
|
8
|
-
|
9
|
-
instance_variable_set("@#{key}", value) if RollCallComparison.instance_methods.include? key
|
10
|
-
end
|
11
|
-
|
8
|
+
super RollCallComparison, params
|
12
9
|
|
13
10
|
set_people
|
14
11
|
set_roll_call
|
@@ -1,6 +1,7 @@
|
|
1
1
|
require 'nokogiri'
|
2
2
|
require 'open-uri'
|
3
3
|
require 'json'
|
4
|
+
require 'CGI'
|
4
5
|
|
5
6
|
module GovKit::OpenCongress
|
6
7
|
autoload :Bill, 'gov_kit/open_congress/bill'
|
@@ -12,6 +13,13 @@ module GovKit::OpenCongress
|
|
12
13
|
autoload :PersonStat, 'gov_kit/open_congress/person_stat'
|
13
14
|
|
14
15
|
class OpenCongressObject
|
16
|
+
|
17
|
+
def initialize(obj, params)
|
18
|
+
params.each do |key, value|
|
19
|
+
key = key.to_sym if RUBY_VERSION[0,3] == "1.9"
|
20
|
+
instance_variable_set("@#{key}", value) if obj.instance_methods.include? key
|
21
|
+
end
|
22
|
+
end
|
15
23
|
|
16
24
|
def self.construct_url(api_method, params)
|
17
25
|
url = nil
|
data/lib/gov_kit/open_states.rb
CHANGED
@@ -1,34 +1,76 @@
|
|
1
1
|
module GovKit
|
2
|
+
|
3
|
+
# Parent class for OpenStates resources
|
4
|
+
# See http://openstates.sunlightlabs.com/api/
|
2
5
|
class OpenStatesResource < Resource
|
6
|
+
|
7
|
+
# Uses default_params from the HTTParty gem.
|
8
|
+
# See HTTParty::ClassMethods:
|
9
|
+
# http://rubydoc.info/gems/httparty/0.7.4/HTTParty/ClassMethods#default_params-instance_method
|
3
10
|
default_params :output => 'json', :apikey => GovKit::configuration.sunlight_apikey
|
4
11
|
base_uri GovKit::configuration.openstates_base_url
|
12
|
+
|
13
|
+
# Do a GET query, with optional parameters.
|
14
|
+
#
|
15
|
+
# OpenStates returns a 404 error when a query
|
16
|
+
# returns nothing.
|
17
|
+
#
|
18
|
+
# So, if a query result is a resource not found error,
|
19
|
+
# we return an empty set.
|
20
|
+
def self.get_uri(uri, options={})
|
21
|
+
begin
|
22
|
+
response = get(uri, options)
|
23
|
+
result = parse(response)
|
24
|
+
rescue ResourceNotFound
|
25
|
+
return []
|
26
|
+
end
|
27
|
+
result
|
28
|
+
end
|
29
|
+
|
5
30
|
end
|
6
31
|
|
32
|
+
# Ruby module for interacting with the Open States Project API
|
33
|
+
# See http://openstates.sunlightlabs.com/api/
|
34
|
+
# Most +find+ and +search+ methods:
|
35
|
+
# * call HTTParty::ClassMethods#get
|
36
|
+
# * which returns an HTTParty::Response object
|
37
|
+
# * which is passed to GovKit::Resource#parse
|
38
|
+
# * which uses the response to populate a Resource
|
39
|
+
#
|
7
40
|
module OpenStates
|
8
41
|
ROLE_MEMBER = "member"
|
9
42
|
ROLE_COMMITTEE_MEMBER = "committee member"
|
10
43
|
CHAMBER_UPPER = "upper"
|
11
44
|
CHAMBER_LOWER = "lower"
|
12
45
|
|
46
|
+
# The State class represents the state data returned from Open States.
|
47
|
+
#
|
48
|
+
# For details about fields returned, see the Open States documentation, at
|
49
|
+
# http://openstates.sunlightlabs.com/api/metadata/,
|
50
|
+
#
|
13
51
|
class State < OpenStatesResource
|
14
52
|
def self.find_by_abbreviation(abbreviation)
|
15
|
-
|
16
|
-
parse(response)
|
53
|
+
get_uri("/metadata/#{abbreviation}/")
|
17
54
|
end
|
18
55
|
end
|
19
56
|
|
57
|
+
# The Bill class represents the bill data returned from Open States.
|
58
|
+
#
|
59
|
+
# For details about fields returned, see the Open States documentation, at
|
60
|
+
# http://openstates.sunlightlabs.com/api/bills/,
|
61
|
+
#
|
20
62
|
class Bill < OpenStatesResource
|
21
63
|
# http://openstates.sunlightlabs.com/api/v1/bills/ca/20092010/AB 667/
|
22
64
|
def self.find(state_abbrev, session, bill_id, chamber = '')
|
23
65
|
escaped_bill_id = bill_id.gsub(/ /, '%20')
|
24
66
|
escaped_session = session.gsub(/ /, '%20')
|
25
|
-
|
26
|
-
|
67
|
+
|
68
|
+
get_uri("/bills/#{state_abbrev.downcase}/#{escaped_session}/#{chamber.blank? ? '' : chamber + '/'}#{escaped_bill_id}/")
|
27
69
|
end
|
28
70
|
|
29
71
|
def self.search(query, options = {})
|
30
|
-
|
31
|
-
|
72
|
+
result = get_uri('/bills/', :query => {:q => query}.merge(options))
|
73
|
+
return Array(result)
|
32
74
|
end
|
33
75
|
|
34
76
|
def self.latest(updated_since, ops = {})
|
@@ -37,27 +79,34 @@ module GovKit
|
|
37
79
|
end
|
38
80
|
end
|
39
81
|
|
82
|
+
# The Legislator class represents the legislator data returned from Open States.
|
83
|
+
#
|
84
|
+
# For details about fields returned, see the Open States documentation, at
|
85
|
+
# http://openstates.sunlightlabs.com/api/legislators/,
|
86
|
+
#
|
40
87
|
class Legislator < OpenStatesResource
|
41
88
|
def self.find(legislator_id)
|
42
|
-
|
43
|
-
parse(response)
|
89
|
+
get_uri("/legislators/#{legislator_id}/")
|
44
90
|
end
|
45
91
|
|
46
92
|
def self.search(options = {})
|
47
|
-
|
48
|
-
|
93
|
+
result = get_uri('/legislators/', :query => options)
|
94
|
+
return Array(result)
|
49
95
|
end
|
50
96
|
end
|
51
97
|
|
98
|
+
# The Committee class represents the committee data returned from Open States.
|
99
|
+
#
|
100
|
+
# For details about fields returned, see the Open States documentation, at
|
101
|
+
# http://openstates.sunlightlabs.com/api/committees/,
|
102
|
+
#
|
52
103
|
class Committee < OpenStatesResource
|
53
104
|
def self.find(committee_id)
|
54
|
-
|
55
|
-
parse(response)
|
105
|
+
get_uri("/committees/#{committee_id}/")
|
56
106
|
end
|
57
107
|
|
58
108
|
def self.search(options = {})
|
59
|
-
|
60
|
-
parse(response)
|
109
|
+
get_uri('/committees/', :query => options)
|
61
110
|
end
|
62
111
|
end
|
63
112
|
|
data/lib/gov_kit/railtie.rb
CHANGED
@@ -12,6 +12,10 @@ module GovKit
|
|
12
12
|
end
|
13
13
|
end
|
14
14
|
|
15
|
+
# This class exists in order to run its insert method while
|
16
|
+
# Rails is loading.
|
17
|
+
# This then adds GovKit::ActsAsNoteworthy to ActiveRecord::Base.
|
18
|
+
# See http://api.rubyonrails.org/classes/Rails/Railtie.html
|
15
19
|
class Railtie
|
16
20
|
def self.insert
|
17
21
|
ActiveRecord::Base.send(:include, GovKit::ActsAsNoteworthy)
|