govkit 0.0.0.pre → 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- data/VERSION +1 -1
- data/generators/{govkit_generator.rb → govkit/govkit_generator.rb} +1 -1
- data/generators/govkit/templates/govkit.rb +9 -0
- data/govkit.gemspec +14 -6
- data/lib/govkit/configuration.rb +25 -0
- data/lib/govkit/fifty_states.rb +14 -3
- data/lib/govkit.rb +1 -0
- data/spec/fifty_states_spec.rb +90 -0
- data/spec/spec.opts +6 -0
- data/spec/spec_helper.rb +25 -0
- metadata +16 -14
- data/generators/templates/govkit.rb +0 -12
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.0.
|
1
|
+
0.0.1
|
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.0.
|
8
|
+
s.version = "0.0.1"
|
9
9
|
|
10
|
-
s.required_rubygems_version = Gem::Requirement.new("
|
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-05-10}
|
13
13
|
s.description = %q{Govkit lets you quickly get encapsulated Ruby objects for common open government APIs. We're starting with Sunlight's Fifty States API and the Project Vote Smart API.}
|
14
14
|
s.email = %q{carl@ppolitics.org}
|
15
15
|
s.extra_rdoc_files = [
|
@@ -24,18 +24,26 @@ Gem::Specification.new do |s|
|
|
24
24
|
"Rakefile",
|
25
25
|
"USAGE",
|
26
26
|
"VERSION",
|
27
|
-
"generators/govkit_generator.rb",
|
28
|
-
"generators/templates/govkit.rb",
|
27
|
+
"generators/govkit/govkit_generator.rb",
|
28
|
+
"generators/govkit/templates/govkit.rb",
|
29
29
|
"govkit.gemspec",
|
30
30
|
"lib/govkit.rb",
|
31
|
+
"lib/govkit/configuration.rb",
|
31
32
|
"lib/govkit/fifty_states.rb",
|
32
|
-
"rails/init.rb"
|
33
|
+
"rails/init.rb",
|
34
|
+
"spec/fifty_states_spec.rb",
|
35
|
+
"spec/spec.opts",
|
36
|
+
"spec/spec_helper.rb"
|
33
37
|
]
|
34
38
|
s.homepage = %q{http://github.com/opengovernment/govkit}
|
35
39
|
s.rdoc_options = ["--charset=UTF-8"]
|
36
40
|
s.require_paths = ["lib"]
|
37
41
|
s.rubygems_version = %q{1.3.6}
|
38
42
|
s.summary = %q{Simple access to open government APIs around the web}
|
43
|
+
s.test_files = [
|
44
|
+
"spec/fifty_states_spec.rb",
|
45
|
+
"spec/spec_helper.rb"
|
46
|
+
]
|
39
47
|
|
40
48
|
if s.respond_to? :specification_version then
|
41
49
|
current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
|
@@ -0,0 +1,25 @@
|
|
1
|
+
module Govkit
|
2
|
+
class Configuration
|
3
|
+
attr_accessor :fiftystates_apikey, :fiftystates_base_url
|
4
|
+
|
5
|
+
def initialize
|
6
|
+
@fiftystates_apikey = ''
|
7
|
+
@fiftystates_base_url = 'fiftystates-dev.sunlightlabs.com/api'
|
8
|
+
end
|
9
|
+
end
|
10
|
+
|
11
|
+
class << self
|
12
|
+
attr_accessor :configuration
|
13
|
+
end
|
14
|
+
|
15
|
+
# Configure Govkit in config/initializers/govkit.rb
|
16
|
+
#
|
17
|
+
# @example
|
18
|
+
# Govkit.configure do |config|
|
19
|
+
# config.fiftystates_apikey = ''
|
20
|
+
# end
|
21
|
+
def self.configure
|
22
|
+
self.configuration ||= Configuration.new
|
23
|
+
yield(configuration)
|
24
|
+
end
|
25
|
+
end
|
data/lib/govkit/fifty_states.rb
CHANGED
@@ -35,8 +35,8 @@ module Govkit::FiftyStates
|
|
35
35
|
class Base
|
36
36
|
include HTTParty
|
37
37
|
format :json
|
38
|
-
default_params :output => 'json'
|
39
|
-
base_uri
|
38
|
+
default_params :output => 'json', :apikey => Govkit::configuration.fiftystates_apikey
|
39
|
+
base_uri Govkit::configuration.fiftystates_base_url
|
40
40
|
|
41
41
|
attr_accessor :attributes
|
42
42
|
|
@@ -53,6 +53,10 @@ module Govkit::FiftyStates
|
|
53
53
|
def instantiate_collection(collection)
|
54
54
|
collection.collect! { |record| instantiate_record(record) }
|
55
55
|
end
|
56
|
+
|
57
|
+
def parse(json)
|
58
|
+
instantiate_record(json)
|
59
|
+
end
|
56
60
|
end
|
57
61
|
|
58
62
|
def unload(attributes)
|
@@ -167,7 +171,14 @@ module Govkit::FiftyStates
|
|
167
171
|
|
168
172
|
class Action < Base; end
|
169
173
|
|
170
|
-
class Vote < Base
|
174
|
+
class Vote < Base
|
175
|
+
def self.find(vote_id)
|
176
|
+
response = get("/votes/#{vote_id}")
|
177
|
+
instantiate_record(response)
|
178
|
+
end
|
179
|
+
end
|
180
|
+
|
181
|
+
class Roll < Base; end
|
171
182
|
|
172
183
|
class Sponsor < Base; end
|
173
184
|
|
data/lib/govkit.rb
CHANGED
@@ -0,0 +1,90 @@
|
|
1
|
+
require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
|
2
|
+
|
3
|
+
#TODO: Mock http requests, rather than making an actual call to the api
|
4
|
+
|
5
|
+
module Govkit::FiftyStates
|
6
|
+
describe Govkit::FiftyStates do
|
7
|
+
it "should have the base uri set properly" do
|
8
|
+
[State, Bill, Legislator].each do |klass|
|
9
|
+
klass.base_uri.should == "http://fiftystates-dev.sunlightlabs.com/api"
|
10
|
+
end
|
11
|
+
end
|
12
|
+
end
|
13
|
+
|
14
|
+
describe State do
|
15
|
+
context "#find_by_abbreviation" do
|
16
|
+
before do
|
17
|
+
#TODO: Mock request for State
|
18
|
+
end
|
19
|
+
it "should find a state by abbreviation" do
|
20
|
+
lambda do
|
21
|
+
@state = State.find_by_abbreviation('ca')
|
22
|
+
end.should_not raise_error
|
23
|
+
|
24
|
+
@state.should_not be_nil
|
25
|
+
@state.name.should == "California"
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
describe Bill do
|
31
|
+
context "#find" do
|
32
|
+
before do
|
33
|
+
#TODO: Mock request for Bill
|
34
|
+
end
|
35
|
+
|
36
|
+
it "should find a bill by stat abbreviation, session, chamber, bill_id" do
|
37
|
+
lambda do
|
38
|
+
@bill = Bill.find('ca', 20092010, 'lower', 'AB667')
|
39
|
+
end.should_not raise_error
|
40
|
+
|
41
|
+
@bill.should_not be_nil
|
42
|
+
@bill.title.should include("An act to amend Section 1750.1 of the Business and Professions Code, and to amend Section 104830 of")
|
43
|
+
end
|
44
|
+
end
|
45
|
+
|
46
|
+
context "#search" do
|
47
|
+
it "should find bills by given criteria" do
|
48
|
+
@bills = Bill.search('agriculture')
|
49
|
+
|
50
|
+
@bills.should_not be_nil
|
51
|
+
@bills.collect(&:bill_id).should include("S 0438")
|
52
|
+
end
|
53
|
+
end
|
54
|
+
|
55
|
+
context "#latest" do
|
56
|
+
it "should get the latest bills by given criteria" do
|
57
|
+
lambda do
|
58
|
+
@latest = Bill.latest('2010-01-01','sd')
|
59
|
+
end.should_not raise_error
|
60
|
+
|
61
|
+
@latest.collect(&:bill_id).should include("SB 7")
|
62
|
+
end
|
63
|
+
end
|
64
|
+
end
|
65
|
+
|
66
|
+
describe Legislator do
|
67
|
+
before do
|
68
|
+
#TODO: Mock request for legislator
|
69
|
+
end
|
70
|
+
context "#find" do
|
71
|
+
it "should get the latest bill" do
|
72
|
+
lambda do
|
73
|
+
@legislator = Legislator.find(2462)
|
74
|
+
end.should_not raise_error
|
75
|
+
|
76
|
+
@legislator.first_name.should == "Dave"
|
77
|
+
@legislator.last_name.should == "Cox"
|
78
|
+
end
|
79
|
+
end
|
80
|
+
context "#search" do
|
81
|
+
it "should get legislators by given criteria" do
|
82
|
+
lambda do
|
83
|
+
@legislators = Legislator.search(:state => 'ca')
|
84
|
+
end.should_not raise_error
|
85
|
+
|
86
|
+
@legislators.should_not be_nil
|
87
|
+
end
|
88
|
+
end
|
89
|
+
end
|
90
|
+
end
|
data/spec/spec.opts
ADDED
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,25 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
require 'spec'
|
3
|
+
require File.dirname(__FILE__) + '/../lib/govkit'
|
4
|
+
|
5
|
+
# prevent the use of `` in tests
|
6
|
+
Spec::Runner.configure do |configuration|
|
7
|
+
end
|
8
|
+
|
9
|
+
# When running specs in TextMate, provide an rputs method to cleanly print objects into HTML display
|
10
|
+
# From http://talklikeaduck.denhaven2.com/2009/09/23/rspec-textmate-pro-tip
|
11
|
+
module Kernel
|
12
|
+
if ENV.keys.find {|env_var| env_var.index("TM_")}
|
13
|
+
def rputs(*args)
|
14
|
+
require 'cgi'
|
15
|
+
puts( *["<pre>", args.collect {|a| CGI.escapeHTML(a.to_s)}, "</pre>"])
|
16
|
+
end
|
17
|
+
def rp(*args)
|
18
|
+
require 'cgi'
|
19
|
+
puts( *["<pre>", args.collect {|a| CGI.escapeHTML(a.inspect)}, "</pre>"])
|
20
|
+
end
|
21
|
+
else
|
22
|
+
alias_method :rputs, :puts
|
23
|
+
alias_method :rp, :p
|
24
|
+
end
|
25
|
+
end
|
metadata
CHANGED
@@ -1,13 +1,12 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: govkit
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
prerelease:
|
4
|
+
prerelease: false
|
5
5
|
segments:
|
6
6
|
- 0
|
7
7
|
- 0
|
8
|
-
-
|
9
|
-
|
10
|
-
version: 0.0.0.pre
|
8
|
+
- 1
|
9
|
+
version: 0.0.1
|
11
10
|
platform: ruby
|
12
11
|
authors:
|
13
12
|
- Participatory Politics Foundation
|
@@ -17,7 +16,7 @@ autorequire:
|
|
17
16
|
bindir: bin
|
18
17
|
cert_chain: []
|
19
18
|
|
20
|
-
date: 2010-
|
19
|
+
date: 2010-05-10 00:00:00 -07:00
|
21
20
|
default_executable:
|
22
21
|
dependencies:
|
23
22
|
- !ruby/object:Gem::Dependency
|
@@ -65,12 +64,16 @@ files:
|
|
65
64
|
- Rakefile
|
66
65
|
- USAGE
|
67
66
|
- VERSION
|
68
|
-
- generators/govkit_generator.rb
|
69
|
-
- generators/templates/govkit.rb
|
67
|
+
- generators/govkit/govkit_generator.rb
|
68
|
+
- generators/govkit/templates/govkit.rb
|
70
69
|
- govkit.gemspec
|
71
70
|
- lib/govkit.rb
|
71
|
+
- lib/govkit/configuration.rb
|
72
72
|
- lib/govkit/fifty_states.rb
|
73
73
|
- rails/init.rb
|
74
|
+
- spec/fifty_states_spec.rb
|
75
|
+
- spec/spec.opts
|
76
|
+
- spec/spec_helper.rb
|
74
77
|
has_rdoc: true
|
75
78
|
homepage: http://github.com/opengovernment/govkit
|
76
79
|
licenses: []
|
@@ -89,13 +92,11 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
89
92
|
version: "0"
|
90
93
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
91
94
|
requirements:
|
92
|
-
- - "
|
95
|
+
- - ">="
|
93
96
|
- !ruby/object:Gem::Version
|
94
97
|
segments:
|
95
|
-
-
|
96
|
-
|
97
|
-
- 1
|
98
|
-
version: 1.3.1
|
98
|
+
- 0
|
99
|
+
version: "0"
|
99
100
|
requirements: []
|
100
101
|
|
101
102
|
rubyforge_project:
|
@@ -103,5 +104,6 @@ rubygems_version: 1.3.6
|
|
103
104
|
signing_key:
|
104
105
|
specification_version: 3
|
105
106
|
summary: Simple access to open government APIs around the web
|
106
|
-
test_files:
|
107
|
-
|
107
|
+
test_files:
|
108
|
+
- spec/fifty_states_spec.rb
|
109
|
+
- spec/spec_helper.rb
|
@@ -1,12 +0,0 @@
|
|
1
|
-
if defined? Govkit
|
2
|
-
|
3
|
-
# Get an API key for Sunlight's Fifty States project here:
|
4
|
-
# http://services.sunlightlabs.com/accounts/register/
|
5
|
-
Govkit::FiftyStates::apikey = 'YOUR_FIFTYSTATES_API_KEY'
|
6
|
-
|
7
|
-
# Get a key for the VoteSmart API here:
|
8
|
-
# http://votesmart.org/services_api.php
|
9
|
-
Govkit::Votesmart::apikey = 'YOUR_VOTESMART_API_KEY'
|
10
|
-
|
11
|
-
|
12
|
-
end
|