govkit 0.4.2 → 0.5.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/VERSION +1 -1
- data/govkit.gemspec +3 -3
- data/lib/gov_kit/{acts_as_citeable.rb → acts_as_noteworthy.rb} +13 -3
- data/lib/gov_kit/open_states.rb +25 -31
- data/lib/gov_kit/railtie.rb +1 -1
- data/lib/gov_kit/resource.rb +28 -31
- data/lib/gov_kit/search_engines/google_blog.rb +10 -10
- data/lib/gov_kit/search_engines/google_news.rb +9 -9
- data/lib/gov_kit/search_engines/technorati.rb +11 -11
- data/lib/gov_kit.rb +2 -2
- metadata +11 -5
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.
|
1
|
+
0.5.0
|
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.5.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{2010-
|
12
|
+
s.date = %q{2010-11-01}
|
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{carl@ppolitics.org}
|
15
15
|
s.extra_rdoc_files = [
|
@@ -31,7 +31,7 @@ Gem::Specification.new do |s|
|
|
31
31
|
"lib/generators/govkit/govkit_generator.rb",
|
32
32
|
"lib/generators/govkit/templates/govkit.rb",
|
33
33
|
"lib/gov_kit.rb",
|
34
|
-
"lib/gov_kit/
|
34
|
+
"lib/gov_kit/acts_as_noteworthy.rb",
|
35
35
|
"lib/gov_kit/configuration.rb",
|
36
36
|
"lib/gov_kit/follow_the_money.rb",
|
37
37
|
"lib/gov_kit/open_congress.rb",
|
@@ -1,17 +1,27 @@
|
|
1
|
-
module GovKit::
|
1
|
+
module GovKit::ActsAsNoteworthy
|
2
2
|
|
3
3
|
def self.included(base)
|
4
4
|
base.extend ActMethods
|
5
5
|
end
|
6
6
|
|
7
7
|
module ActMethods
|
8
|
-
def
|
8
|
+
def acts_as_noteworthy(options={})
|
9
9
|
options[:keywords] ||= []
|
10
10
|
|
11
11
|
class_inheritable_accessor :options
|
12
12
|
self.options = options
|
13
13
|
|
14
14
|
unless included_modules.include? InstanceMethods
|
15
|
+
instance_eval do
|
16
|
+
has_many :mentions, :as => :owner
|
17
|
+
|
18
|
+
with_options :as => :owner, :class_name => "Mention" do |c|
|
19
|
+
c.has_many :google_news_mentions, :conditions => {:search_source => "Google News"}
|
20
|
+
c.has_many :google_blog_mentions, :conditions => {:search_source => "Google Blogs"}
|
21
|
+
c.has_many :technorati_mentions, :conditions => {:search_source => "Technorati"}
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
15
25
|
extend ClassMethods
|
16
26
|
include InstanceMethods
|
17
27
|
end
|
@@ -23,7 +33,7 @@ module GovKit::ActsAsCiteable
|
|
23
33
|
|
24
34
|
module InstanceMethods
|
25
35
|
|
26
|
-
def
|
36
|
+
def raw_mentions
|
27
37
|
params = self.options[:keywords].clone
|
28
38
|
attributes = self.options[:with].clone
|
29
39
|
|
data/lib/gov_kit/open_states.rb
CHANGED
@@ -19,49 +19,43 @@ module GovKit
|
|
19
19
|
|
20
20
|
class Bill < OpenStatesResource
|
21
21
|
# http://openstates.sunlightlabs.com/api/v1/bills/ca/20092010/AB667/
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
end
|
22
|
+
def self.find(state_abbrev, session, bill_id, chamber = '')
|
23
|
+
response = get("/bills/#{state_abbrev}/#{session}/#{chamber.blank? ? '' : chamber + '/'}#{bill_id}/")
|
24
|
+
parse(response)
|
25
|
+
end
|
27
26
|
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
27
|
+
def self.search(query, options = {})
|
28
|
+
response = get('/bills/', :query => {:q => query}.merge(options))
|
29
|
+
parse(response)
|
30
|
+
end
|
32
31
|
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
end
|
32
|
+
def self.latest(updated_since, state_abbrev)
|
33
|
+
response = get('/bills/latest/', :query => {:updated_since => updated_since, :state => state_abbrev})
|
34
|
+
parse(response)
|
37
35
|
end
|
38
36
|
end
|
39
37
|
|
40
38
|
class Legislator < OpenStatesResource
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
end
|
39
|
+
def self.find(legislator_id)
|
40
|
+
response = get("/legislators/#{legislator_id}/")
|
41
|
+
parse(response)
|
42
|
+
end
|
46
43
|
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
end
|
44
|
+
def self.search(options = {})
|
45
|
+
response = get('/legislators/', :query => options)
|
46
|
+
parse(response)
|
51
47
|
end
|
52
48
|
end
|
53
49
|
|
54
50
|
class Committee < OpenStatesResource
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
end
|
51
|
+
def self.find(committee_id)
|
52
|
+
response = get("/committees/#{committee_id}/")
|
53
|
+
parse(response)
|
54
|
+
end
|
60
55
|
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
end
|
56
|
+
def self.search(options = {})
|
57
|
+
response = get('/committees/', :query => options)
|
58
|
+
parse(response)
|
65
59
|
end
|
66
60
|
end
|
67
61
|
|
data/lib/gov_kit/railtie.rb
CHANGED
data/lib/gov_kit/resource.rb
CHANGED
@@ -13,43 +13,40 @@ module GovKit
|
|
13
13
|
unload(attributes)
|
14
14
|
end
|
15
15
|
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
raise NotAuthorized, "401 Not Authorized; have you set up your API key?"
|
30
|
-
end
|
31
|
-
end
|
32
|
-
|
33
|
-
instantiate(response)
|
34
|
-
end
|
35
|
-
|
36
|
-
def instantiate(record)
|
37
|
-
case record
|
38
|
-
when Array
|
39
|
-
instantiate_collection(record)
|
40
|
-
else
|
41
|
-
instantiate_record(record)
|
16
|
+
def self.parse(response)
|
17
|
+
# This method handles the basic responses we might get back from
|
18
|
+
# Net::HTTP. But if a service returns something other than a 404 when an object is not found,
|
19
|
+
# you'll need to handle that in the subclass.
|
20
|
+
|
21
|
+
raise ResourceNotFound, "Resource not found" unless !response.blank?
|
22
|
+
|
23
|
+
if response.class == HTTParty::Response
|
24
|
+
case response.response
|
25
|
+
when Net::HTTPNotFound
|
26
|
+
raise ResourceNotFound, "404 Not Found"
|
27
|
+
when Net::HTTPUnauthorized
|
28
|
+
raise NotAuthorized, "401 Not Authorized; have you set up your API key?"
|
42
29
|
end
|
43
30
|
end
|
31
|
+
|
32
|
+
instantiate(response)
|
33
|
+
end
|
44
34
|
|
45
|
-
|
46
|
-
|
35
|
+
def self.instantiate(record)
|
36
|
+
case record
|
37
|
+
when Array
|
38
|
+
instantiate_collection(record)
|
39
|
+
else
|
40
|
+
instantiate_record(record)
|
47
41
|
end
|
42
|
+
end
|
48
43
|
|
49
|
-
|
50
|
-
|
51
|
-
|
44
|
+
def self.instantiate_record(record)
|
45
|
+
new(record)
|
46
|
+
end
|
52
47
|
|
48
|
+
def self.instantiate_collection(collection)
|
49
|
+
collection.collect! { |record| instantiate_record(record) }
|
53
50
|
end
|
54
51
|
|
55
52
|
def unload(attributes)
|
@@ -11,22 +11,22 @@ module GovKit
|
|
11
11
|
stories = doc.search("td.j")
|
12
12
|
titles = (doc/"a").select { |a| (a.attributes["id"] && a.attributes["id"].match(/p-(.*)/)) }
|
13
13
|
|
14
|
-
|
14
|
+
mentions = []
|
15
15
|
|
16
16
|
stories.each do |story|
|
17
|
-
|
17
|
+
mention = GovKit::Mention.new
|
18
18
|
t = titles.shift
|
19
19
|
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
20
|
+
mention.title = (t.inner_html) if t #.unpack("C*").pack("U*") if t
|
21
|
+
mention.url = t.attributes["href"] if t
|
22
|
+
mention.date = story.at("font:nth(0)").inner_html
|
23
|
+
mention.excerpt = (story.at("br + font").inner_html) #.unpack("C*").pack("U*")
|
24
|
+
mention.source = story.at("a.f1").inner_html
|
25
|
+
mention.url = story.at("a.f1").attributes["href"]
|
26
26
|
|
27
|
-
|
27
|
+
mentions << mention
|
28
28
|
end
|
29
|
-
|
29
|
+
mentions
|
30
30
|
end
|
31
31
|
|
32
32
|
def self.make_request(host, path)
|
@@ -13,20 +13,20 @@ module GovKit
|
|
13
13
|
doc = Hpricot(Iconv.conv('utf-8//IGNORE', 'gb2312',html))
|
14
14
|
stories = doc.search("div.search-results > div.story")
|
15
15
|
|
16
|
-
|
16
|
+
mentions = []
|
17
17
|
|
18
18
|
stories.each do |story|
|
19
|
-
|
19
|
+
mention = GovKit::Mention.new
|
20
20
|
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
21
|
+
mention.title = story.at("h2.title a").inner_text.html_safe
|
22
|
+
mention.url = story.at("h2.title a").attributes["href"]
|
23
|
+
mention.date = story.at("div.sub-title > span.date").inner_html.html_safe
|
24
|
+
mention.source = story.at("div.sub-title > span.source").inner_html.html_safe
|
25
|
+
mention.excerpt = story.at("div.body > div.snippet").inner_html.html_safe
|
26
26
|
|
27
|
-
|
27
|
+
mentions << mention
|
28
28
|
end
|
29
|
-
|
29
|
+
mentions
|
30
30
|
end
|
31
31
|
|
32
32
|
def self.make_request(host, path)
|
@@ -9,21 +9,21 @@ module GovKit
|
|
9
9
|
html = make_request(host, path)
|
10
10
|
doc = Hpricot(Iconv.conv('utf-8//IGNORE', 'gb2312',html))
|
11
11
|
|
12
|
-
|
12
|
+
mentions = []
|
13
13
|
# doc.search("tapi/document/item").each do |i|
|
14
|
-
#
|
14
|
+
# mention = GovKit::Mention.new
|
15
15
|
#
|
16
|
-
#
|
17
|
-
#
|
18
|
-
#
|
19
|
-
#
|
20
|
-
#
|
21
|
-
#
|
22
|
-
#
|
16
|
+
# mention.url = i.text("permalink")
|
17
|
+
# mention.title = i.text("title")
|
18
|
+
# mention.excerpt = i.text("excerpt")
|
19
|
+
# mention.date = i.text("created")
|
20
|
+
# mention.source = i.text("weblog/name")
|
21
|
+
# mention.url = i.text("weblog/url")
|
22
|
+
# mention.weight = i.text("weblog/inboundlinks")
|
23
23
|
#
|
24
|
-
#
|
24
|
+
# mentions << mention
|
25
25
|
# end
|
26
|
-
|
26
|
+
mentions
|
27
27
|
[]
|
28
28
|
end
|
29
29
|
|
data/lib/gov_kit.rb
CHANGED
@@ -11,12 +11,12 @@ module GovKit
|
|
11
11
|
autoload :Resource, 'gov_kit/resource'
|
12
12
|
autoload :OpenStates, 'gov_kit/open_states'
|
13
13
|
autoload :VoteSmart, 'gov_kit/vote_smart'
|
14
|
-
autoload :
|
14
|
+
autoload :ActsAsNoteworthy, 'gov_kit/acts_as_noteworthy'
|
15
15
|
autoload :FollowTheMoney, 'gov_kit/follow_the_money'
|
16
16
|
autoload :OpenCongress, 'gov_kit/open_congress'
|
17
17
|
autoload :SearchEngines, 'gov_kit/search_engines'
|
18
18
|
|
19
|
-
class
|
19
|
+
class Mention
|
20
20
|
attr_accessor :url, :excerpt, :title, :source, :date, :weight
|
21
21
|
end
|
22
22
|
|
metadata
CHANGED
@@ -1,12 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: govkit
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
+
hash: 11
|
4
5
|
prerelease: false
|
5
6
|
segments:
|
6
7
|
- 0
|
7
|
-
-
|
8
|
-
-
|
9
|
-
version: 0.
|
8
|
+
- 5
|
9
|
+
- 0
|
10
|
+
version: 0.5.0
|
10
11
|
platform: ruby
|
11
12
|
authors:
|
12
13
|
- Participatory Politics Foundation
|
@@ -16,7 +17,7 @@ autorequire:
|
|
16
17
|
bindir: bin
|
17
18
|
cert_chain: []
|
18
19
|
|
19
|
-
date: 2010-
|
20
|
+
date: 2010-11-01 00:00:00 -04:00
|
20
21
|
default_executable:
|
21
22
|
dependencies:
|
22
23
|
- !ruby/object:Gem::Dependency
|
@@ -27,6 +28,7 @@ dependencies:
|
|
27
28
|
requirements:
|
28
29
|
- - ">="
|
29
30
|
- !ruby/object:Gem::Version
|
31
|
+
hash: 15
|
30
32
|
segments:
|
31
33
|
- 0
|
32
34
|
- 5
|
@@ -42,6 +44,7 @@ dependencies:
|
|
42
44
|
requirements:
|
43
45
|
- - ">="
|
44
46
|
- !ruby/object:Gem::Version
|
47
|
+
hash: 1
|
45
48
|
segments:
|
46
49
|
- 1
|
47
50
|
- 4
|
@@ -57,6 +60,7 @@ dependencies:
|
|
57
60
|
requirements:
|
58
61
|
- - ">="
|
59
62
|
- !ruby/object:Gem::Version
|
63
|
+
hash: 59
|
60
64
|
segments:
|
61
65
|
- 0
|
62
66
|
- 8
|
@@ -88,7 +92,7 @@ files:
|
|
88
92
|
- lib/generators/govkit/govkit_generator.rb
|
89
93
|
- lib/generators/govkit/templates/govkit.rb
|
90
94
|
- lib/gov_kit.rb
|
91
|
-
- lib/gov_kit/
|
95
|
+
- lib/gov_kit/acts_as_noteworthy.rb
|
92
96
|
- lib/gov_kit/configuration.rb
|
93
97
|
- lib/gov_kit/follow_the_money.rb
|
94
98
|
- lib/gov_kit/open_congress.rb
|
@@ -139,6 +143,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
139
143
|
requirements:
|
140
144
|
- - ">="
|
141
145
|
- !ruby/object:Gem::Version
|
146
|
+
hash: 3
|
142
147
|
segments:
|
143
148
|
- 0
|
144
149
|
version: "0"
|
@@ -147,6 +152,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
147
152
|
requirements:
|
148
153
|
- - ">="
|
149
154
|
- !ruby/object:Gem::Version
|
155
|
+
hash: 3
|
150
156
|
segments:
|
151
157
|
- 0
|
152
158
|
version: "0"
|