govkit 0.5.1 → 0.6.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 +2 -2
- data/lib/gov_kit/configuration.rb +1 -1
- data/lib/gov_kit/open_states.rb +4 -2
- data/lib/gov_kit/resource.rb +5 -1
- data/lib/gov_kit/transparency_data.rb +10 -7
- data/lib/gov_kit.rb +9 -0
- metadata +5 -5
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.
|
1
|
+
0.6.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.6.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{
|
12
|
+
s.date = %q{2011-02-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{develop@opencongress.org}
|
15
15
|
s.extra_rdoc_files = [
|
@@ -21,7 +21,7 @@ module GovKit
|
|
21
21
|
@wikipedia_base_url = 'en.wikipedia.org'
|
22
22
|
|
23
23
|
# Permant home for contribution category mappings
|
24
|
-
@transparency_data_categories_url = 'assets.transparencydata.org.s3.amazonaws.com/docs/catcodes.csv'
|
24
|
+
@transparency_data_categories_url = 'http://assets.transparencydata.org.s3.amazonaws.com/docs/catcodes.csv'
|
25
25
|
end
|
26
26
|
end
|
27
27
|
|
data/lib/gov_kit/open_states.rb
CHANGED
@@ -18,9 +18,11 @@ module GovKit
|
|
18
18
|
end
|
19
19
|
|
20
20
|
class Bill < OpenStatesResource
|
21
|
-
# http://openstates.sunlightlabs.com/api/v1/bills/ca/20092010/
|
21
|
+
# http://openstates.sunlightlabs.com/api/v1/bills/ca/20092010/AB 667/
|
22
22
|
def self.find(state_abbrev, session, bill_id, chamber = '')
|
23
|
-
|
23
|
+
escaped_bill_id = bill_id.gsub(/ /, '%20')
|
24
|
+
escaped_session = session.gsub(/ /, '%20')
|
25
|
+
response = get("/bills/#{state_abbrev.downcase}/#{escaped_session}/#{chamber.blank? ? '' : chamber + '/'}#{escaped_bill_id}/")
|
24
26
|
parse(response)
|
25
27
|
end
|
26
28
|
|
data/lib/gov_kit/resource.rb
CHANGED
@@ -25,6 +25,10 @@ module GovKit
|
|
25
25
|
raise ResourceNotFound, "404 Not Found"
|
26
26
|
when Net::HTTPUnauthorized
|
27
27
|
raise NotAuthorized, "401 Not Authorized; have you set up your API key?"
|
28
|
+
when Net::HTTPServerError
|
29
|
+
raise ServerError, '5xx server error'
|
30
|
+
when Net::HTTPClientError
|
31
|
+
raise ClientError, '4xx client error'
|
28
32
|
end
|
29
33
|
end
|
30
34
|
|
@@ -86,7 +90,7 @@ module GovKit
|
|
86
90
|
end
|
87
91
|
|
88
92
|
def find_or_create_resource_for(name)
|
89
|
-
resource_name = name.to_s.gsub(/^[_
|
93
|
+
resource_name = name.to_s.gsub(/^[_\-+]/,'').gsub(/^(\-?\d)/, "n#{$1}").gsub(/(\s|-)/, '').camelize
|
90
94
|
if self.class.parents.size > 1
|
91
95
|
find_resource_in_modules(resource_name, self.class.parents)
|
92
96
|
else
|
@@ -1,5 +1,3 @@
|
|
1
|
-
require 'fastercsv'
|
2
|
-
|
3
1
|
module GovKit
|
4
2
|
class TransparencyDataResource < Resource
|
5
3
|
default_params :apikey => GovKit::configuration.sunlight_apikey
|
@@ -25,14 +23,19 @@ module GovKit
|
|
25
23
|
|
26
24
|
class Categories
|
27
25
|
# Contribution category code mapping table, in CSV format
|
28
|
-
# Returns an array of hashes
|
26
|
+
# Returns an array of hashes, each with the following keys:
|
27
|
+
# :source, :code, :name, :industry, :order
|
29
28
|
def self.all
|
29
|
+
# This provides Ruby 1.8 & 1.9 CSV compatibility
|
30
|
+
if CSV.const_defined? :Reader
|
31
|
+
csv = FasterCSV
|
32
|
+
else
|
33
|
+
csv = CSV
|
34
|
+
end
|
30
35
|
categories = []
|
31
36
|
open(GovKit::configuration.transparency_data_categories_url) do |f|
|
32
|
-
f.
|
33
|
-
|
34
|
-
categories << row.fields
|
35
|
-
end
|
37
|
+
csv.parse(f.read, :headers => true, :header_converters => :symbol) do |row|
|
38
|
+
categories << row.to_hash
|
36
39
|
end
|
37
40
|
end
|
38
41
|
categories
|
data/lib/gov_kit.rb
CHANGED
@@ -7,6 +7,11 @@ require 'httparty'
|
|
7
7
|
require 'open-uri'
|
8
8
|
require 'json'
|
9
9
|
require 'gov_kit/configuration'
|
10
|
+
require 'csv'
|
11
|
+
|
12
|
+
if VERSION[0,3] == "1.8"
|
13
|
+
require 'fastercsv'
|
14
|
+
end
|
10
15
|
|
11
16
|
module GovKit
|
12
17
|
autoload :Resource, 'gov_kit/resource'
|
@@ -30,4 +35,8 @@ module GovKit
|
|
30
35
|
class InvalidRequest < GovKitError; end
|
31
36
|
|
32
37
|
class ResourceNotFound < GovKitError; end
|
38
|
+
|
39
|
+
class ServerError < GovKitError; end
|
40
|
+
|
41
|
+
class ClientError < GovKitError; end
|
33
42
|
end
|
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: govkit
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
4
|
+
hash: 7
|
5
5
|
prerelease: false
|
6
6
|
segments:
|
7
7
|
- 0
|
8
|
-
-
|
9
|
-
-
|
10
|
-
version: 0.
|
8
|
+
- 6
|
9
|
+
- 0
|
10
|
+
version: 0.6.0
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- Participatory Politics Foundation
|
@@ -17,7 +17,7 @@ autorequire:
|
|
17
17
|
bindir: bin
|
18
18
|
cert_chain: []
|
19
19
|
|
20
|
-
date:
|
20
|
+
date: 2011-02-01 00:00:00 -08:00
|
21
21
|
default_executable:
|
22
22
|
dependencies:
|
23
23
|
- !ruby/object:Gem::Dependency
|