opensecrets 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
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,22 @@
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
+ doc
19
+ pkg
20
+ .yardoc
21
+
22
+ ## PROJECT::SPECIFIC
data/LICENSE ADDED
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2009 Glenn Rempe
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.rdoc ADDED
@@ -0,0 +1,40 @@
1
+ = opensecrets
2
+
3
+ A Ruby wrapper around the OpenSecrets.org API.
4
+
5
+ You will need to have an OpenSecrets.org API key before you can use this library.
6
+
7
+ See the OpenSecrets API documentation at : http://www.opensecrets.org/action/api_doc.php
8
+
9
+ This project was inspired by a project suggestion on the SunlightLabs.com website. If you would
10
+ like to contribute please see : http://sunlightlabs.com/projects/opensecrets-ruby/
11
+
12
+ == Installation
13
+
14
+ [sudo] gem install opensecrets
15
+
16
+ == Usage
17
+
18
+ require 'rubygems'
19
+ require 'opensecrets'
20
+ require 'crack'
21
+ require 'pp'
22
+
23
+ member = OpenSecrets::Member.new('YOUR OPEN SECRETS API KEY')
24
+ pp member.pfd({:cid => 'N00007360', :year => '2008'})["response"]
25
+
26
+ cand = OpenSecrets::Candidate.new('YOUR OPEN SECRETS API KEY')
27
+ pp cand.summary({:cid => 'N00007360'})["response"]
28
+
29
+ == Note on Patches/Pull Requests
30
+
31
+ * Fork the project.
32
+ * Make your feature addition or bug fix.
33
+ * Add tests for it. This is important so I don't break it in a future version unintentionally.
34
+ * Commit, do not mess with rakefile, version, or history.
35
+ * Send me a pull request. Bonus points for topic branches.
36
+
37
+ == Copyright
38
+
39
+ Copyright (c) 2009 Glenn Rempe. See LICENSE for details.
40
+
data/Rakefile ADDED
@@ -0,0 +1,55 @@
1
+ require 'rubygems'
2
+ require 'rake'
3
+
4
+ begin
5
+ require 'jeweler'
6
+ Jeweler::Tasks.new do |gem|
7
+ gem.name = "opensecrets"
8
+ gem.summary = %Q{OpenSecrets.org API Ruby Wrapper}
9
+ gem.description = %Q{OpenSecrets are the best kind. Created as a community service as requested by the Sunlight Foundation.}
10
+ gem.email = "glenn@rempe.us"
11
+ gem.homepage = "http://github.com/grempe/opensecrets"
12
+ gem.authors = ["Glenn Rempe"]
13
+ gem.add_dependency "httparty", ">= 0.4.5"
14
+ gem.add_dependency "crack", ">= 0.1.4"
15
+ gem.add_development_dependency "shoulda", ">= 0"
16
+ gem.add_development_dependency "yard", ">= 0"
17
+ # gem is a Gem::Specification... see http://www.rubygems.org/read/chapter/20 for additional settings
18
+ end
19
+ Jeweler::GemcutterTasks.new
20
+ rescue LoadError
21
+ puts "Jeweler (or a dependency) not available. Install it with: sudo gem install jeweler"
22
+ end
23
+
24
+ require 'rake/testtask'
25
+ Rake::TestTask.new(:test) do |test|
26
+ test.libs << 'lib' << 'test'
27
+ test.pattern = 'test/**/test_*.rb'
28
+ test.verbose = true
29
+ end
30
+
31
+ begin
32
+ require 'rcov/rcovtask'
33
+ Rcov::RcovTask.new do |test|
34
+ test.libs << 'test'
35
+ test.pattern = 'test/**/test_*.rb'
36
+ test.verbose = true
37
+ end
38
+ rescue LoadError
39
+ task :rcov do
40
+ abort "RCov is not available. In order to run rcov, you must: sudo gem install rcov"
41
+ end
42
+ end
43
+
44
+ task :test => :check_dependencies
45
+
46
+ task :default => :test
47
+
48
+ begin
49
+ require 'yard'
50
+ YARD::Rake::YardocTask.new
51
+ rescue LoadError
52
+ task :yardoc do
53
+ abort "YARD is not available. In order to run yardoc, you must: sudo gem install yard"
54
+ end
55
+ end
data/VERSION ADDED
@@ -0,0 +1 @@
1
+ 0.0.1
@@ -0,0 +1,37 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'rubygems'
4
+ $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib')) # only when running from gem source dir
5
+ require 'opensecrets'
6
+ require 'crack'
7
+ require 'pp'
8
+
9
+ CID = 'N00007360' # Nancy Pelosi
10
+
11
+
12
+ member = OpenSecrets::Member.new('YOUR API KEY')
13
+
14
+ puts "\n\nMEMBER : PFD PROFILE\n\n"
15
+ pp member.pfd({:cid => CID, :year => '2008'})["response"]
16
+
17
+ puts "\n\nMEMBER : TRAVEL & TRIPS\n\n"
18
+ pp member.trips({:cid => CID, :year => '2008'})["response"]
19
+
20
+
21
+ cand = OpenSecrets::Candidate.new('YOUR API KEY')
22
+
23
+ puts "\n\nCANDIDATE : SUMMARY\n\n"
24
+ pp cand.summary({:cid => CID})["response"]
25
+
26
+ puts "\n\nCANDIDATE : CONTRIBUTORS\n\n"
27
+ pp cand.contributors({:cid => CID})["response"]
28
+
29
+ puts "\n\nCANDIDATE : INDUSTRIES\n\n"
30
+ pp cand.industries({:cid => CID})["response"]
31
+
32
+ puts "\n\nCANDIDATE : CONTRIBUTIONS BY SPECIFIC INDUSTRY\n\n"
33
+ pp cand.contributions_by_industry({:cid => CID, :indcode => 'K01'})["response"]
34
+
35
+ puts "\n\nCANDIDATE : SECTOR\n\n"
36
+ pp cand.sector({:cid => CID})["response"]
37
+
@@ -0,0 +1,135 @@
1
+ require 'httparty'
2
+
3
+ module OpenSecrets
4
+
5
+ class Member
6
+ include HTTParty
7
+ base_uri 'http://www.opensecrets.org/api'
8
+ default_params :output => 'xml'
9
+ format :xml
10
+
11
+ # OpenSecrets information about a Member of Congress.
12
+ #
13
+ # @option options [String] apikey ("") an OpenSecrets API Key
14
+ #
15
+ def initialize(apikey)
16
+ raise ArgumentError, 'You must provide an API Key' if apikey.blank?
17
+ self.class.default_params :apikey => apikey
18
+ end
19
+
20
+ # Returns Personal Financial Disclosure (PFD) information for a member of Congress.
21
+ #
22
+ # See : http://www.opensecrets.org/api/?method=memPFDprofile&output=doc
23
+ #
24
+ # @option options [String] :cid ("") a CRP CandidateID
25
+ # @option options [String] :year ("") Get data for specified year.
26
+ #
27
+ def pfd(options = {})
28
+ raise ArgumentError, 'You must provide a :cid option' if options[:cid].blank?
29
+ raise ArgumentError, 'You must provide a :year option' if options[:year].blank?
30
+ options.merge!({:method => 'memPFDprofile'})
31
+ self.class.get("/", :query => options)
32
+ end
33
+
34
+ # Provides a list of trips paid for by private organizations taken by a specified member or their staff.
35
+ #
36
+ # See : http://www.opensecrets.org/api/?method=memTravelTrips&output=doc
37
+ #
38
+ # @option options [String] :cid ("") a CRP CandidateID
39
+ # @option options [String] :year ("") Get data for specified year.
40
+ #
41
+ def trips(options = {})
42
+ raise ArgumentError, 'You must provide a :cid option' if options[:cid].blank?
43
+ raise ArgumentError, 'You must provide a :year option' if options[:year].blank?
44
+ options.merge!({:method => 'memTravelTrips'})
45
+ self.class.get("/", :query => options)
46
+ end
47
+
48
+ end
49
+
50
+ class Candidate
51
+ include HTTParty
52
+ base_uri 'http://www.opensecrets.org/api'
53
+ default_params :output => 'xml'
54
+ format :xml
55
+
56
+ # OpenSecrets information about a Candidate.
57
+ #
58
+ # @option options [String] apikey ("") an OpenSecrets API Key
59
+ #
60
+ def initialize(apikey)
61
+ raise ArgumentError, 'You must provide an API Key' if apikey.blank?
62
+ self.class.default_params :apikey => apikey
63
+ end
64
+
65
+ # Provides summary fundraising information for specified politician.
66
+ #
67
+ # See : http://www.opensecrets.org/api/?method=candSummary&output=doc
68
+ #
69
+ # @option options [String] :cid ("") a CRP CandidateID
70
+ # @option options [optional, String] :cycle ("") blank values returns current cycle.
71
+ #
72
+ def summary(options = {})
73
+ raise ArgumentError, 'You must provide a :cid option' if options[:cid].blank?
74
+ options.merge!({:method => 'candSummary'})
75
+ self.class.get("/", :query => options)
76
+ end
77
+
78
+ # Provides the top organizations contributing to specified politician.
79
+ #
80
+ # See : http://www.opensecrets.org/api/?method=candContrib&output=doc
81
+ #
82
+ # @option options [String] :cid ("") a CRP CandidateID
83
+ # @option options [optional, String] :cycle ("") 2008 or 2010.
84
+ #
85
+ def contributors(options = {})
86
+ raise ArgumentError, 'You must provide a :cid option' if options[:cid].blank?
87
+ options.merge!({:method => 'candContrib'})
88
+ self.class.get("/", :query => options)
89
+ end
90
+
91
+ # Provides the top industries contributing to a specified politician.
92
+ #
93
+ # See : http://www.opensecrets.org/api/?method=candIndustry&output=doc
94
+ #
95
+ # @option options [String] :cid ("") a CRP CandidateID
96
+ # @option options [optional, String] :cycle ("") blank values returns current cycle.
97
+ #
98
+ def industries(options = {})
99
+ raise ArgumentError, 'You must provide a :cid option' if options[:cid].blank?
100
+ options.merge!({:method => 'candIndustry'})
101
+ self.class.get("/", :query => options)
102
+ end
103
+
104
+ # Provides total contributed to specified candidate from specified industry for specified cycle.
105
+ #
106
+ # See : http://www.opensecrets.org/api/?method=candIndByInd&output=doc
107
+ #
108
+ # @option options [String] :cid ("") a CRP CandidateID
109
+ # @option options [String] :indcode ("") a a 3-character industry code
110
+ # @option options [optional, String] :cycle ("") 2010, 2008 allowed. leave blank for latest cycle.
111
+ #
112
+ def contributions_by_industry(options = {})
113
+ raise ArgumentError, 'You must provide a :cid option' if options[:cid].blank?
114
+ raise ArgumentError, 'You must provide a :indcode option' if options[:indcode].blank?
115
+ options.merge!({:method => 'candIndByInd'})
116
+ self.class.get("/", :query => options)
117
+ end
118
+
119
+ # Provides sector total of specified politician's receipts.
120
+ #
121
+ # See : http://www.opensecrets.org/api/?method=candSector&output=doc
122
+ #
123
+ # @option options [String] :cid ("") a CRP CandidateID
124
+ # @option options [optional, String] :cycle ("") blank values returns current cycle.
125
+ #
126
+ def sector(options = {})
127
+ raise ArgumentError, 'You must provide a :cid option' if options[:cid].blank?
128
+ options.merge!({:method => 'candSector'})
129
+ self.class.get("/", :query => options)
130
+ end
131
+
132
+ end
133
+
134
+ end
135
+
data/test/helper.rb ADDED
@@ -0,0 +1,10 @@
1
+ require 'rubygems'
2
+ require 'test/unit'
3
+ require 'shoulda'
4
+
5
+ $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
6
+ $LOAD_PATH.unshift(File.dirname(__FILE__))
7
+ require 'opensecrets'
8
+
9
+ class Test::Unit::TestCase
10
+ end
@@ -0,0 +1,7 @@
1
+ require 'helper'
2
+
3
+ class TestOpensecrets < Test::Unit::TestCase
4
+ should "probably rename this file and start testing for real" do
5
+ flunk "hey buddy, you should probably rename this file and start testing for real"
6
+ end
7
+ end
metadata ADDED
@@ -0,0 +1,106 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: opensecrets
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Glenn Rempe
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+
12
+ date: 2009-11-04 00:00:00 -08:00
13
+ default_executable:
14
+ dependencies:
15
+ - !ruby/object:Gem::Dependency
16
+ name: httparty
17
+ type: :runtime
18
+ version_requirement:
19
+ version_requirements: !ruby/object:Gem::Requirement
20
+ requirements:
21
+ - - ">="
22
+ - !ruby/object:Gem::Version
23
+ version: 0.4.5
24
+ version:
25
+ - !ruby/object:Gem::Dependency
26
+ name: crack
27
+ type: :runtime
28
+ version_requirement:
29
+ version_requirements: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: 0.1.4
34
+ version:
35
+ - !ruby/object:Gem::Dependency
36
+ name: shoulda
37
+ type: :development
38
+ version_requirement:
39
+ version_requirements: !ruby/object:Gem::Requirement
40
+ requirements:
41
+ - - ">="
42
+ - !ruby/object:Gem::Version
43
+ version: "0"
44
+ version:
45
+ - !ruby/object:Gem::Dependency
46
+ name: yard
47
+ type: :development
48
+ version_requirement:
49
+ version_requirements: !ruby/object:Gem::Requirement
50
+ requirements:
51
+ - - ">="
52
+ - !ruby/object:Gem::Version
53
+ version: "0"
54
+ version:
55
+ description: OpenSecrets are the best kind. Created as a community service as requested by the Sunlight Foundation.
56
+ email: glenn@rempe.us
57
+ executables: []
58
+
59
+ extensions: []
60
+
61
+ extra_rdoc_files:
62
+ - LICENSE
63
+ - README.rdoc
64
+ files:
65
+ - .document
66
+ - .gitignore
67
+ - LICENSE
68
+ - README.rdoc
69
+ - Rakefile
70
+ - VERSION
71
+ - examples/example.rb
72
+ - lib/opensecrets.rb
73
+ - test/helper.rb
74
+ - test/test_opensecrets.rb
75
+ has_rdoc: true
76
+ homepage: http://github.com/grempe/opensecrets
77
+ licenses: []
78
+
79
+ post_install_message:
80
+ rdoc_options:
81
+ - --charset=UTF-8
82
+ require_paths:
83
+ - lib
84
+ required_ruby_version: !ruby/object:Gem::Requirement
85
+ requirements:
86
+ - - ">="
87
+ - !ruby/object:Gem::Version
88
+ version: "0"
89
+ version:
90
+ required_rubygems_version: !ruby/object:Gem::Requirement
91
+ requirements:
92
+ - - ">="
93
+ - !ruby/object:Gem::Version
94
+ version: "0"
95
+ version:
96
+ requirements: []
97
+
98
+ rubyforge_project:
99
+ rubygems_version: 1.3.5
100
+ signing_key:
101
+ specification_version: 3
102
+ summary: OpenSecrets.org API Ruby Wrapper
103
+ test_files:
104
+ - test/helper.rb
105
+ - test/test_opensecrets.rb
106
+ - examples/example.rb