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 CHANGED
@@ -1 +1 @@
1
- 0.4.2
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.4.2"
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-09-29}
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/acts_as_citeable.rb",
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::ActsAsCiteable
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 acts_as_citeable(options={})
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 raw_citations
36
+ def raw_mentions
27
37
  params = self.options[:keywords].clone
28
38
  attributes = self.options[:with].clone
29
39
 
@@ -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
- class << self
23
- def find(state_abbrev, session, bill_id, chamber = '')
24
- response = get("/bills/#{state_abbrev}/#{session}/#{chamber.blank? ? '' : chamber + '/'}#{bill_id}/")
25
- parse(response)
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
- def search(query, options = {})
29
- response = get('/bills/', :query => {:q => query}.merge(options))
30
- parse(response)
31
- end
27
+ def self.search(query, options = {})
28
+ response = get('/bills/', :query => {:q => query}.merge(options))
29
+ parse(response)
30
+ end
32
31
 
33
- def latest(updated_since, state_abbrev)
34
- response = get('/bills/latest/', :query => {:updated_since => updated_since, :state => state_abbrev})
35
- parse(response)
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
- class << self
42
- def find(legislator_id)
43
- response = get("/legislators/#{legislator_id}/")
44
- parse(response)
45
- end
39
+ def self.find(legislator_id)
40
+ response = get("/legislators/#{legislator_id}/")
41
+ parse(response)
42
+ end
46
43
 
47
- def search(options = {})
48
- response = get('/legislators/', :query => options)
49
- parse(response)
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
- class << self
56
- def find(committee_id)
57
- response = get("/committees/#{committee_id}/")
58
- parse(response)
59
- end
51
+ def self.find(committee_id)
52
+ response = get("/committees/#{committee_id}/")
53
+ parse(response)
54
+ end
60
55
 
61
- def search(options = {})
62
- response = get('/committees/', :query => options)
63
- parse(response)
64
- end
56
+ def self.search(options = {})
57
+ response = get('/committees/', :query => options)
58
+ parse(response)
65
59
  end
66
60
  end
67
61
 
@@ -14,7 +14,7 @@ module GovKit
14
14
 
15
15
  class Railtie
16
16
  def self.insert
17
- ActiveRecord::Base.send(:include, GovKit::ActsAsCiteable)
17
+ ActiveRecord::Base.send(:include, GovKit::ActsAsNoteworthy)
18
18
  end
19
19
  end
20
20
  end
@@ -13,43 +13,40 @@ module GovKit
13
13
  unload(attributes)
14
14
  end
15
15
 
16
- class << self
17
- def parse(response)
18
- # This method handles the basic responses we might get back from
19
- # Net::HTTP. But if a service returns something other than a 404 when an object is not found,
20
- # you'll need to handle that in the subclass.
21
-
22
- raise ResourceNotFound, "Resource not found" unless !response.blank?
23
-
24
- if response.class == HTTParty::Response
25
- case response.response
26
- when Net::HTTPNotFound
27
- raise ResourceNotFound, "404 Not Found"
28
- when Net::HTTPUnauthorized
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
- def instantiate_record(record)
46
- new(record)
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
- def instantiate_collection(collection)
50
- collection.collect! { |record| instantiate_record(record) }
51
- end
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
- citations = []
14
+ mentions = []
15
15
 
16
16
  stories.each do |story|
17
- citation = GovKit::Citation.new
17
+ mention = GovKit::Mention.new
18
18
  t = titles.shift
19
19
 
20
- citation.title = (t.inner_html) if t #.unpack("C*").pack("U*") if t
21
- citation.url = t.attributes["href"] if t
22
- citation.date = story.at("font:nth(0)").inner_html
23
- citation.excerpt = (story.at("br + font").inner_html) #.unpack("C*").pack("U*")
24
- citation.source = story.at("a.f1").inner_html
25
- citation.url = story.at("a.f1").attributes["href"]
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
- citations << citation
27
+ mentions << mention
28
28
  end
29
- citations
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
- citations = []
16
+ mentions = []
17
17
 
18
18
  stories.each do |story|
19
- citation = GovKit::Citation.new
19
+ mention = GovKit::Mention.new
20
20
 
21
- citation.title = story.at("h2.title a").inner_text.html_safe
22
- citation.url = story.at("h2.title a").attributes["href"]
23
- citation.date = story.at("div.sub-title > span.date").inner_html.html_safe
24
- citation.source = story.at("div.sub-title > span.source").inner_html.html_safe
25
- citation.excerpt = story.at("div.body > div.snippet").inner_html.html_safe
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
- citations << citation
27
+ mentions << mention
28
28
  end
29
- citations
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
- citations = []
12
+ mentions = []
13
13
  # doc.search("tapi/document/item").each do |i|
14
- # citation = GovKit::Citation.new
14
+ # mention = GovKit::Mention.new
15
15
  #
16
- # citation.url = i.text("permalink")
17
- # citation.title = i.text("title")
18
- # citation.excerpt = i.text("excerpt")
19
- # citation.date = i.text("created")
20
- # citation.source = i.text("weblog/name")
21
- # citation.url = i.text("weblog/url")
22
- # citation.weight = i.text("weblog/inboundlinks")
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
- # citations << citation
24
+ # mentions << mention
25
25
  # end
26
- citations
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 :ActsAsCiteable, 'gov_kit/acts_as_citeable'
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 Citation
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
- - 4
8
- - 2
9
- version: 0.4.2
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-09-29 00:00:00 -07:00
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/acts_as_citeable.rb
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"