opensecrets 0.0.4 → 0.0.5

Sign up to get free protection for your applications and to get access to all the features.
@@ -20,12 +20,20 @@ like to contribute please see : http://sunlightlabs.com/projects/opensecrets-rub
20
20
  require 'crack'
21
21
  require 'pp'
22
22
 
23
+ # Note, you can also provide your API key in an environment variable for security and convenience.
24
+ # export OPENSECRETS_API_KEY=YOUR_API_KEY
25
+ # If you provide your key this way you do not have to provide a key in the OpenSecrets::*.new constructors.
26
+ # A key provided to the constructor overrides any environment variable that is set.
27
+
23
28
  member = OpenSecrets::Member.new('YOUR OPEN SECRETS API KEY')
24
29
  pp member.pfd({:cid => 'N00007360', :year => '2008'})["response"]
25
30
 
26
31
  cand = OpenSecrets::Candidate.new('YOUR OPEN SECRETS API KEY')
27
32
  pp cand.summary({:cid => 'N00007360'})["response"]
28
33
 
34
+ com = OpenSecrets::Committee.new('YOUR OPEN SECRETS API KEY')
35
+ pp com.by_industry({:cmte => 'HARM', :congno => '110', :indus => 'F10'})["response"]
36
+
29
37
 
30
38
  == Project Websites
31
39
 
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.0.4
1
+ 0.0.5
@@ -7,12 +7,15 @@ require 'crack'
7
7
  require 'pp'
8
8
 
9
9
 
10
- # For convenience and security you can export an environment variable to hold your API key.
11
- API_KEY = ENV['OPENSECRETS_API_KEY'] ||= 'YOUR_API_KEY'
10
+ ########
11
+ # NOTE : You should 'export OPENSECRETS_API_KEY=YOUR_API_KEY' before running this script.
12
+ ########
13
+
14
+
12
15
  CID = 'N00007360' # Nancy Pelosi
13
16
 
14
17
 
15
- member = OpenSecrets::Member.new(API_KEY)
18
+ member = OpenSecrets::Member.new
16
19
 
17
20
  puts "\n\nMEMBER : PFD PROFILE\n\n"
18
21
  pp member.pfd({:cid => CID, :year => '2008'})["response"]
@@ -21,7 +24,7 @@ puts "\n\nMEMBER : TRAVEL & TRIPS\n\n"
21
24
  pp member.trips({:cid => CID, :year => '2008'})["response"]
22
25
 
23
26
 
24
- cand = OpenSecrets::Candidate.new(API_KEY)
27
+ cand = OpenSecrets::Candidate.new
25
28
 
26
29
  puts "\n\nCANDIDATE : SUMMARY\n\n"
27
30
  pp cand.summary({:cid => CID})["response"]
@@ -39,7 +42,7 @@ puts "\n\nCANDIDATE : SECTOR\n\n"
39
42
  pp cand.sector({:cid => CID})["response"]
40
43
 
41
44
 
42
- com = OpenSecrets::Committee.new(API_KEY)
45
+ com = OpenSecrets::Committee.new
43
46
 
44
47
  puts "\n\nCOMMITTEE\n\n"
45
48
  pp com.by_industry({:cmte => 'HARM', :congno => '110', :indus => 'F10'})["response"]
@@ -2,21 +2,30 @@ require 'httparty'
2
2
 
3
3
  module OpenSecrets
4
4
 
5
- class Member
5
+ class Base
6
+
6
7
  include HTTParty
7
8
  base_uri 'http://www.opensecrets.org/api'
8
9
  default_params :output => 'xml'
9
10
  format :xml
10
11
 
11
- # OpenSecrets information about a Member of Congress.
12
+ # OpenSecrets Base constructor. All OpenSecrets API classes inherit from this one which provides
13
+ # the common initialization function. For convenience you can skip providing an 'apikey' to the
14
+ # constructor if you instead export a OPENSECRETS_API_KEY environment variable which is set to the
15
+ # value of your API key.
12
16
  #
13
- # @option options [String] apikey ("") an OpenSecrets API Key
17
+ # @option options [String] apikey (nil) an OpenSecrets API Key, this can also be provided in an OPENSECRETS_API_KEY shell environment variable for security and convenience.
14
18
  #
15
- def initialize(apikey)
16
- raise ArgumentError, 'You must provide an API Key' if apikey.blank?
17
- self.class.default_params :apikey => apikey
19
+ def initialize(apikey = nil)
20
+ key = apikey ||= ENV['OPENSECRETS_API_KEY']
21
+ raise ArgumentError, 'You must provide an API Key' if key.blank?
22
+ self.class.default_params :apikey => key
18
23
  end
19
24
 
25
+ end
26
+
27
+ class Member < OpenSecrets::Base
28
+
20
29
  # Returns Personal Financial Disclosure (PFD) information for a member of Congress.
21
30
  #
22
31
  # See : http://www.opensecrets.org/api/?method=memPFDprofile&output=doc
@@ -47,20 +56,7 @@ module OpenSecrets
47
56
 
48
57
  end # member
49
58
 
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
59
+ class Candidate < OpenSecrets::Base
64
60
 
65
61
  # Provides summary fundraising information for specified politician.
66
62
  #
@@ -131,20 +127,7 @@ module OpenSecrets
131
127
 
132
128
  end # candidate
133
129
 
134
- class Committee
135
- include HTTParty
136
- base_uri 'http://www.opensecrets.org/api'
137
- default_params :output => 'xml'
138
- format :xml
139
-
140
- # OpenSecrets information about a specific committee.
141
- #
142
- # @option options [String] apikey ("") an OpenSecrets API Key
143
- #
144
- def initialize(apikey)
145
- raise ArgumentError, 'You must provide an API Key' if apikey.blank?
146
- self.class.default_params :apikey => apikey
147
- end
130
+ class Committee < OpenSecrets::Base
148
131
 
149
132
  # Provides summary fundraising information for a specific committee, industry and Congress number.
150
133
  #
@@ -5,7 +5,7 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{opensecrets}
8
- s.version = "0.0.4"
8
+ s.version = "0.0.5"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["Glenn Rempe"]
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: opensecrets
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.4
4
+ version: 0.0.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - Glenn Rempe