govkit 0.0.0.pre

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/.document ADDED
@@ -0,0 +1,5 @@
1
+ README.rdoc
2
+ lib/**/*.rb
3
+ bin/*
4
+ features/**/*.feature
5
+ LICENSE
data/.gitignore ADDED
@@ -0,0 +1,21 @@
1
+ ## MAC OS
2
+ .DS_Store
3
+
4
+ ## TEXTMATE
5
+ *.tmproj
6
+ tmtags
7
+
8
+ ## EMACS
9
+ *~
10
+ \#*
11
+ .\#*
12
+
13
+ ## VIM
14
+ *.swp
15
+
16
+ ## PROJECT::GENERAL
17
+ coverage
18
+ rdoc
19
+ pkg
20
+
21
+ ## PROJECT::SPECIFIC
data/LICENSE ADDED
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2009 Carl Tashian
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.markdown ADDED
@@ -0,0 +1,31 @@
1
+ Govkit
2
+ ======
3
+
4
+ Govkit is a Ruby gem that provides simple access to open government APIs around the web.
5
+
6
+ Setup
7
+ =====
8
+
9
+ Add govkit to your environment.rb or Gemfile
10
+
11
+ Run <code>./script/generate govkit</code> to copy a config file into <code>config/initializers/govkit.rb</code>. You will need to add your API keys to this config file.
12
+
13
+ Example
14
+ =======
15
+
16
+ [http://fiftystates-dev.sunlightlabs.com/](The Fifty States project) has a RESTful API for accessing data about state legislators, bills, votes, etc.
17
+
18
+ >> Govkit::FiftyStates::State.find_by_abbrev('CA')
19
+
20
+ (TODO: add usage examples...)
21
+
22
+ Bugs? Questions?
23
+ ================
24
+
25
+ Please join the [Govkit Google Group](http://groups.google.com/group/govkit), especially if you'd like to talk about a new feature and get announcements.
26
+
27
+ [Report a bug](https://participatorypolitics.lighthouseapp.com/projects/51485-govkit) on our Lighthouse page.
28
+
29
+ Govkit's main repo is on Github: [http://github.com/opengovernment/govkit](http://github.com/opengovernment/govkit), where your contributions, forks, and feedback are greatly welcomed.
30
+
31
+ Copyright (c) 2010 Participatory Politics Foundation, released under the MIT license
data/Rakefile ADDED
@@ -0,0 +1,80 @@
1
+ require 'rubygems'
2
+ require 'rake'
3
+ require 'rake/rdoctask'
4
+
5
+ begin
6
+ require 'spec/rake/spectask'
7
+ rescue LoadError
8
+ begin
9
+ gem 'rspec-rails', '>= 1.0.0'
10
+ require 'spec/rake/spectask'
11
+ rescue LoadError
12
+ puts "[govkit:] RSpec - or one of it's dependencies - is not available. Install it with: sudo gem install rspec-rails"
13
+ end
14
+ end
15
+
16
+ begin
17
+ require 'jeweler'
18
+ Jeweler::Tasks.new do |gem|
19
+ gem.name = "govkit"
20
+ gem.summary = %Q{Simple access to open government APIs around the web}
21
+ gem.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.}
22
+ gem.email = "carl@ppolitics.org"
23
+ gem.homepage = "http://github.com/opengovernment/govkit"
24
+ gem.authors = ["Participatory Politics Foundation", "Srinivas Aki", "Carl Tashian"]
25
+ gem.add_dependency('httparty', '>= 0.5.2')
26
+ gem.add_dependency('json', '>= 1.2.4')
27
+ # gem is a Gem::Specification... see http://www.rubygems.org/read/chapter/20 for additional settings
28
+ end
29
+ Jeweler::GemcutterTasks.new
30
+ rescue LoadError
31
+ puts "Jeweler (or a dependency) not available. Install it with: gem install jeweler"
32
+ end
33
+
34
+
35
+
36
+ begin
37
+ require 'rcov/rcovtask'
38
+ Rcov::RcovTask.new do |test|
39
+ test.libs << 'test'
40
+ test.pattern = 'test/**/test_*.rb'
41
+ test.verbose = true
42
+ end
43
+ rescue LoadError
44
+ task :rcov do
45
+ abort "RCov is not available. In order to run rcov, you must: sudo gem install spicycode-rcov"
46
+ end
47
+ end
48
+
49
+ task :default => :spec
50
+
51
+ Rake::RDocTask.new do |rdoc|
52
+ version = File.exist?('VERSION') ? File.read('VERSION') : ""
53
+
54
+ rdoc.rdoc_dir = 'rdoc'
55
+ rdoc.title = "govkit #{version}"
56
+ rdoc.rdoc_files.include('README*')
57
+ rdoc.rdoc_files.include('lib/**/*.rb')
58
+ end
59
+
60
+
61
+ if defined?(Spec)
62
+ desc 'Test the govkit plugin.'
63
+ Spec::Rake::SpecTask.new('spec') do |t|
64
+ t.spec_files = FileList['spec/**/*_spec.rb']
65
+ t.spec_opts = ["-c"]
66
+ end
67
+
68
+ desc 'Test the govkit plugin with specdoc formatting and colors'
69
+ Spec::Rake::SpecTask.new('specdoc') do |t|
70
+ t.spec_files = FileList['spec/**/*_spec.rb']
71
+ t.spec_opts = ["--format specdoc", "-c"]
72
+ end
73
+
74
+ desc "Run all examples with RCov"
75
+ Spec::Rake::SpecTask.new('examples_with_rcov') do |t|
76
+ t.spec_files = FileList['spec/**/*_spec.rb']
77
+ t.rcov = true
78
+ t.rcov_opts = ['--exclude', 'spec,Library']
79
+ end
80
+ end
data/USAGE ADDED
File without changes
data/VERSION ADDED
@@ -0,0 +1 @@
1
+ 0.0.0.pre
@@ -0,0 +1,20 @@
1
+ class GovkitGenerator < Rails::Generator::Base
2
+
3
+ def initialize(*runtime_args)
4
+ super
5
+ end
6
+
7
+ def manifest
8
+ record do |m|
9
+ m.directory File.join('config', 'initializers')
10
+ m.template 'govkit.rb', File.join('config', 'initializers', 'govkit.rb')
11
+ end
12
+ end
13
+
14
+ protected
15
+
16
+ def banner
17
+ %{Usage: #{$0} #{spec.name}\nCopies a config initializer to config/initializers/govkit.rb}
18
+ end
19
+
20
+ end
@@ -0,0 +1,12 @@
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
data/govkit.gemspec ADDED
@@ -0,0 +1,56 @@
1
+ # Generated by jeweler
2
+ # DO NOT EDIT THIS FILE DIRECTLY
3
+ # Instead, edit Jeweler::Tasks in Rakefile, and run the gemspec command
4
+ # -*- encoding: utf-8 -*-
5
+
6
+ Gem::Specification.new do |s|
7
+ s.name = %q{govkit}
8
+ s.version = "0.0.0.pre"
9
+
10
+ s.required_rubygems_version = Gem::Requirement.new("> 1.3.1") if s.respond_to? :required_rubygems_version=
11
+ s.authors = ["Participatory Politics Foundation", "Srinivas Aki", "Carl Tashian"]
12
+ s.date = %q{2010-04-28}
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
+ s.email = %q{carl@ppolitics.org}
15
+ s.extra_rdoc_files = [
16
+ "LICENSE",
17
+ "README.markdown"
18
+ ]
19
+ s.files = [
20
+ ".document",
21
+ ".gitignore",
22
+ "LICENSE",
23
+ "README.markdown",
24
+ "Rakefile",
25
+ "USAGE",
26
+ "VERSION",
27
+ "generators/govkit_generator.rb",
28
+ "generators/templates/govkit.rb",
29
+ "govkit.gemspec",
30
+ "lib/govkit.rb",
31
+ "lib/govkit/fifty_states.rb",
32
+ "rails/init.rb"
33
+ ]
34
+ s.homepage = %q{http://github.com/opengovernment/govkit}
35
+ s.rdoc_options = ["--charset=UTF-8"]
36
+ s.require_paths = ["lib"]
37
+ s.rubygems_version = %q{1.3.6}
38
+ s.summary = %q{Simple access to open government APIs around the web}
39
+
40
+ if s.respond_to? :specification_version then
41
+ current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
42
+ s.specification_version = 3
43
+
44
+ if Gem::Version.new(Gem::RubyGemsVersion) >= Gem::Version.new('1.2.0') then
45
+ s.add_runtime_dependency(%q<httparty>, [">= 0.5.2"])
46
+ s.add_runtime_dependency(%q<json>, [">= 1.2.4"])
47
+ else
48
+ s.add_dependency(%q<httparty>, [">= 0.5.2"])
49
+ s.add_dependency(%q<json>, [">= 1.2.4"])
50
+ end
51
+ else
52
+ s.add_dependency(%q<httparty>, [">= 0.5.2"])
53
+ s.add_dependency(%q<json>, [">= 1.2.4"])
54
+ end
55
+ end
56
+
@@ -0,0 +1,177 @@
1
+ require 'httparty'
2
+
3
+ module Govkit::FiftyStates
4
+
5
+ ROLE_MEMBER = "member"
6
+ ROLE_COMMITTEE_MEMBER = "committee member"
7
+ CHAMBER_UPPER = "upper"
8
+ CHAMBER_LOWER = "lower"
9
+
10
+ class FiftyStatesError < StandardError
11
+ attr_reader :response
12
+
13
+ def initialize(response, message = nil)
14
+ @response = response
15
+ @message = message
16
+ end
17
+
18
+ def to_s
19
+ "Failed with #{response.code} #{response.message if response.respond_to?(:message)}"
20
+ end
21
+ end
22
+
23
+ class NotauthorizedError < FiftyStatesError;
24
+ end
25
+
26
+ class InvalidRequestError < StandardError;
27
+ end
28
+
29
+ class NotFoundError < FiftyStatesError;
30
+ end
31
+
32
+ class NameError < FiftyStatesError;
33
+ end
34
+
35
+ class Base
36
+ include HTTParty
37
+ format :json
38
+ default_params :output => 'json'
39
+ base_uri 'fiftystates-dev.sunlightlabs.com/api'
40
+
41
+ attr_accessor :attributes
42
+
43
+ def initialize(attributes = {})
44
+ @attributes = {}
45
+ unload(attributes)
46
+ end
47
+
48
+ class << self
49
+ def instantiate_record(record)
50
+ new(record)
51
+ end
52
+
53
+ def instantiate_collection(collection)
54
+ collection.collect! { |record| instantiate_record(record) }
55
+ end
56
+ end
57
+
58
+ def unload(attributes)
59
+ raise ArgumentError, "expected an attributes Hash, got #{attributes.inspect}" unless attributes.is_a?(Hash)
60
+ attributes.each do |key, value|
61
+ @attributes[key.to_s] =
62
+ case value
63
+ when Array
64
+ resource = resource_for_collection(key)
65
+ value.map do |attrs|
66
+ if attrs.is_a?(String) || attrs.is_a?(Numeric)
67
+ attrs.duplicable? ? attrs.dup : attrs
68
+ else
69
+ resource.new(attrs)
70
+ end
71
+ end
72
+ when Hash
73
+ resource = find_or_create_resource_for(key)
74
+ resource.new(value)
75
+ else
76
+ value.dup rescue value
77
+ end
78
+ end
79
+ self
80
+ end
81
+
82
+ private
83
+ def resource_for_collection(name)
84
+ find_resource_for(name.to_s.singularize)
85
+ end
86
+
87
+ def find_resource_in_modules(resource_name, module_names)
88
+ receiver = Object
89
+ namespaces = module_names[0, module_names.size-1].map do |module_name|
90
+ receiver = receiver.const_get(module_name)
91
+ end
92
+ if namespace = namespaces.reverse.detect { |ns| ns.const_defined?(resource_name) }
93
+ return namespace.const_get(resource_name)
94
+ else
95
+ raise NameError, "Namespace for #{namespace} not found"
96
+ end
97
+ end
98
+
99
+ def find_resource_for(name)
100
+ resource_name = name.to_s.camelize
101
+ ancestors = self.class.name.split("::")
102
+ if ancestors.size > 1
103
+ find_resource_in_modules(resource_name, ancestors)
104
+ else
105
+ self.class.const_get(resource_name)
106
+ end
107
+ rescue NameError
108
+ #TODO: May be we should create new classes based on unknown records
109
+ end
110
+
111
+ def method_missing(method_symbol, *arguments) #:nodoc:
112
+ method_name = method_symbol.to_s
113
+
114
+ case method_name.last
115
+ when "="
116
+ attributes[method_name.first(-1)] = arguments.first
117
+ when "?"
118
+ attributes[method_name.first(-1)]
119
+ when "]"
120
+ attributes[arguments.first.to_s]
121
+ else
122
+ attributes.has_key?(method_name) ? attributes[method_name] : super
123
+ end
124
+ end
125
+ end
126
+
127
+ class State < Base
128
+ def self.find_by_abbreviation(abbreviation)
129
+ response = get("/#{abbreviation}")
130
+ instantiate_record(response)
131
+ end
132
+ end
133
+
134
+ class Bill < Base
135
+ # http://fiftystates-dev.sunlightlabs.com/api/ca/20092010/lower/bills/AB667/
136
+ def self.find(state_abbrev, session, chamber, bill_id)
137
+ response = get("/#{state_abbrev}/#{session}/#{chamber}/bills/#{bill_id}/")
138
+ instantiate_record(response)
139
+ end
140
+
141
+ def self.search(query, options = {})
142
+ response = get('/bills/search', :query => {:q => query}.merge(options))
143
+ instantiate_collection(response)
144
+ end
145
+
146
+ def self.latest(updated_since, state_abbrev)
147
+ response = get('/bills/latest/', :query => {:updated_since => updated_since, :state => state_abbrev})
148
+ instantiate_collection(response)
149
+ end
150
+ end
151
+
152
+ class Legislator < Base
153
+ def self.find(legislator_id)
154
+ response = get("/legislators/#{legislator_id}")
155
+ instantiate_record(response)
156
+ end
157
+
158
+ def self.search(options = {})
159
+ response = get('/legislators/search', :query => options)
160
+ instantiate_collection(response)
161
+ end
162
+ end
163
+
164
+ class Session < Base; end
165
+
166
+ class Role < Base; end
167
+
168
+ class Action < Base; end
169
+
170
+ class Vote < Base; end
171
+
172
+ class Sponsor < Base; end
173
+
174
+ class Version < Base; end
175
+
176
+ class Source < Base; end
177
+ end
data/lib/govkit.rb ADDED
@@ -0,0 +1,7 @@
1
+ $LOAD_PATH.unshift(File.expand_path(File.dirname(__FILE__))) unless $LOAD_PATH.include?(File.expand_path(File.dirname(__FILE__)))
2
+
3
+ require 'active_support'
4
+
5
+ module Govkit
6
+ autoload :FiftyStates, 'govkit/fifty_states'
7
+ end
data/rails/init.rb ADDED
@@ -0,0 +1,2 @@
1
+ # Include hook code here
2
+ require File.join(File.dirname(__FILE__), *%w[.. lib govkit])
metadata ADDED
@@ -0,0 +1,107 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: govkit
3
+ version: !ruby/object:Gem::Version
4
+ prerelease: true
5
+ segments:
6
+ - 0
7
+ - 0
8
+ - 0
9
+ - pre
10
+ version: 0.0.0.pre
11
+ platform: ruby
12
+ authors:
13
+ - Participatory Politics Foundation
14
+ - Srinivas Aki
15
+ - Carl Tashian
16
+ autorequire:
17
+ bindir: bin
18
+ cert_chain: []
19
+
20
+ date: 2010-04-28 00:00:00 -07:00
21
+ default_executable:
22
+ dependencies:
23
+ - !ruby/object:Gem::Dependency
24
+ name: httparty
25
+ prerelease: false
26
+ requirement: &id001 !ruby/object:Gem::Requirement
27
+ requirements:
28
+ - - ">="
29
+ - !ruby/object:Gem::Version
30
+ segments:
31
+ - 0
32
+ - 5
33
+ - 2
34
+ version: 0.5.2
35
+ type: :runtime
36
+ version_requirements: *id001
37
+ - !ruby/object:Gem::Dependency
38
+ name: json
39
+ prerelease: false
40
+ requirement: &id002 !ruby/object:Gem::Requirement
41
+ requirements:
42
+ - - ">="
43
+ - !ruby/object:Gem::Version
44
+ segments:
45
+ - 1
46
+ - 2
47
+ - 4
48
+ version: 1.2.4
49
+ type: :runtime
50
+ version_requirements: *id002
51
+ description: 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.
52
+ email: carl@ppolitics.org
53
+ executables: []
54
+
55
+ extensions: []
56
+
57
+ extra_rdoc_files:
58
+ - LICENSE
59
+ - README.markdown
60
+ files:
61
+ - .document
62
+ - .gitignore
63
+ - LICENSE
64
+ - README.markdown
65
+ - Rakefile
66
+ - USAGE
67
+ - VERSION
68
+ - generators/govkit_generator.rb
69
+ - generators/templates/govkit.rb
70
+ - govkit.gemspec
71
+ - lib/govkit.rb
72
+ - lib/govkit/fifty_states.rb
73
+ - rails/init.rb
74
+ has_rdoc: true
75
+ homepage: http://github.com/opengovernment/govkit
76
+ licenses: []
77
+
78
+ post_install_message:
79
+ rdoc_options:
80
+ - --charset=UTF-8
81
+ require_paths:
82
+ - lib
83
+ required_ruby_version: !ruby/object:Gem::Requirement
84
+ requirements:
85
+ - - ">="
86
+ - !ruby/object:Gem::Version
87
+ segments:
88
+ - 0
89
+ version: "0"
90
+ required_rubygems_version: !ruby/object:Gem::Requirement
91
+ requirements:
92
+ - - ">"
93
+ - !ruby/object:Gem::Version
94
+ segments:
95
+ - 1
96
+ - 3
97
+ - 1
98
+ version: 1.3.1
99
+ requirements: []
100
+
101
+ rubyforge_project:
102
+ rubygems_version: 1.3.6
103
+ signing_key:
104
+ specification_version: 3
105
+ summary: Simple access to open government APIs around the web
106
+ test_files: []
107
+