transparency_data 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- data/README.md +71 -0
- data/lib/transparency_data.rb +52 -0
- data/lib/transparency_data/client.rb +50 -0
- metadata +204 -0
data/README.md
ADDED
@@ -0,0 +1,71 @@
|
|
1
|
+
# TransparencyData.com Ruby Wrapper
|
2
|
+
|
3
|
+
By Wynn Netherland, Jeremy Hinegardner, and Luigi Montanez
|
4
|
+
|
5
|
+
Before using this library, please read the official [TransparencyData.com API documentation](http://transparencydata.com/api/). Query parameters and return formats are described there.
|
6
|
+
|
7
|
+
## Setup
|
8
|
+
|
9
|
+
Get an API key from [Sunlight Labs](http://services.sunlightlabs.com/).
|
10
|
+
|
11
|
+
Required gems:
|
12
|
+
|
13
|
+
* monster_mash
|
14
|
+
* hashie
|
15
|
+
|
16
|
+
After a `gem install transparency_data`, you can do:
|
17
|
+
|
18
|
+
require 'transparency_data'
|
19
|
+
TransparencyData.api_key = 'YOUR_KEY_HERE'
|
20
|
+
|
21
|
+
Within a Rails app, create a `config/initializers/transparency_data.rb` and stick this in:
|
22
|
+
|
23
|
+
TransparencyData.configure do |config|
|
24
|
+
config.api_key = 'YOUR_KEY_HERE'
|
25
|
+
end
|
26
|
+
|
27
|
+
## Usage
|
28
|
+
|
29
|
+
See the official [API docs](http://transparencydata.com/api/) for all parameters you can send in, and the [schema docs](http://transparencydata.com/docs/) for what you get back:
|
30
|
+
|
31
|
+
contributions = TransparencyData::Client.contributions(:contributor_ft => 'steve jobs')
|
32
|
+
contributions.each do |contribution|
|
33
|
+
puts "Amount: #{contribution.amount}"
|
34
|
+
puts "Date: #{contribution.date}"
|
35
|
+
end
|
36
|
+
|
37
|
+
lobbyings = TransparencyData::Client.lobbying(:client_ft => "apple inc")
|
38
|
+
lobbyings.each do |lobbying|
|
39
|
+
puts "Amount: #{lobbying.amount}"
|
40
|
+
puts "Year: #{lobbying.year}"
|
41
|
+
end
|
42
|
+
|
43
|
+
As described in the API docs, the TransparencyData.com API supports a special syntax as the parameter value for specifying ranges and sets on amount, cycle, year, and date. You can either pass in strings, or use a more Rubyish approach:
|
44
|
+
|
45
|
+
# contributions with an amount greater than or equal to $1000
|
46
|
+
TransparencyData::Client.contributions(:contributor_ft => 'steve jobs', :amount => {:gte => 1000})
|
47
|
+
|
48
|
+
# contributions with an amount less than or equal to $500
|
49
|
+
TransparencyData::Client.contributions(:contributor_ft => 'bill gates', :amount => {:lte => 500})
|
50
|
+
|
51
|
+
# contributions in the 2006 or 2008 cycle
|
52
|
+
TransparencyData::Client.contributions(:contributor_ft => 'eric schmidt', :cycle => [2006,2008]})
|
53
|
+
|
54
|
+
# contributions to Obama made between in Q1 2008
|
55
|
+
TransparencyData::Client.contributions(:recipient_ft => 'barack obama',
|
56
|
+
:date => {:between => ['2008-01-01','2008-03-31']})
|
57
|
+
|
58
|
+
## Contributing
|
59
|
+
|
60
|
+
Required gems for running tests:
|
61
|
+
|
62
|
+
* mg
|
63
|
+
* shoulda
|
64
|
+
* jnunemaker-matchy
|
65
|
+
* mocha
|
66
|
+
* fakeweb
|
67
|
+
* vcr
|
68
|
+
|
69
|
+
Run the test suite:
|
70
|
+
|
71
|
+
rake test
|
@@ -0,0 +1,52 @@
|
|
1
|
+
require 'hashie'
|
2
|
+
require 'json'
|
3
|
+
require 'monster_mash'
|
4
|
+
|
5
|
+
Hash.send :include, Hashie::HashExtensions
|
6
|
+
|
7
|
+
|
8
|
+
|
9
|
+
module TransparencyData
|
10
|
+
|
11
|
+
VERSION = "0.0.1".freeze
|
12
|
+
|
13
|
+
# config/initializers/transparency_data.rb (for instance)
|
14
|
+
#
|
15
|
+
# TransparencyData.configure do |config|
|
16
|
+
# config.api_key = 'api_key'
|
17
|
+
# end
|
18
|
+
#
|
19
|
+
def self.configure
|
20
|
+
yield self
|
21
|
+
true
|
22
|
+
end
|
23
|
+
|
24
|
+
def self.api_url(endpoint, version = self.api_version)
|
25
|
+
"http://transparencydata.com/api/#{version}#{endpoint}.json"
|
26
|
+
end
|
27
|
+
|
28
|
+
# class << self
|
29
|
+
# attr_accessor :api_key
|
30
|
+
# attr_accessor :api_version
|
31
|
+
# end
|
32
|
+
|
33
|
+
def self.api_version
|
34
|
+
@api_version || "1.0"
|
35
|
+
end
|
36
|
+
|
37
|
+
def self.api_version=(value)
|
38
|
+
@api_version = value
|
39
|
+
end
|
40
|
+
|
41
|
+
def self.api_key
|
42
|
+
@api_key
|
43
|
+
end
|
44
|
+
|
45
|
+
def self.api_key=(value)
|
46
|
+
@api_key = value
|
47
|
+
end
|
48
|
+
|
49
|
+
|
50
|
+
end
|
51
|
+
|
52
|
+
require 'lib/transparency_data/client'
|
@@ -0,0 +1,50 @@
|
|
1
|
+
module TransparencyData
|
2
|
+
class Client < MonsterMash::Base
|
3
|
+
|
4
|
+
defaults do
|
5
|
+
params :apikey => TransparencyData.api_key
|
6
|
+
end
|
7
|
+
|
8
|
+
get(:contributions) do |api_params|
|
9
|
+
uri TransparencyData.api_url("/contributions")
|
10
|
+
params TransparencyData::Client.prepare_params(api_params)
|
11
|
+
handler do |response|
|
12
|
+
TransparencyData::Client.handle_response(response)
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
16
|
+
get(:lobbying) do |api_params|
|
17
|
+
uri TransparencyData.api_url("/lobbying")
|
18
|
+
params TransparencyData::Client.prepare_params(api_params)
|
19
|
+
handler do |response|
|
20
|
+
TransparencyData::Client.handle_response(response)
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
def self.prepare_params(params)
|
25
|
+
params.each do |key, value|
|
26
|
+
if value.is_a?(Hash)
|
27
|
+
|
28
|
+
case value.keys.first
|
29
|
+
when :gte
|
30
|
+
params[key] = ">|#{value.values.first}"
|
31
|
+
when :lte
|
32
|
+
params[key] = "<|#{value.values.first}"
|
33
|
+
when :between
|
34
|
+
params[key] = "><|#{value.values.first.join('|')}"
|
35
|
+
end
|
36
|
+
|
37
|
+
elsif value.is_a?(Array)
|
38
|
+
params[key] = value.join("|")
|
39
|
+
end
|
40
|
+
end
|
41
|
+
params
|
42
|
+
end
|
43
|
+
|
44
|
+
def self.handle_response(response)
|
45
|
+
# TODO: raise_errors
|
46
|
+
JSON.parse(response.body).map {|c| Hashie::Mash.new(c)}
|
47
|
+
end
|
48
|
+
|
49
|
+
end
|
50
|
+
end
|
metadata
ADDED
@@ -0,0 +1,204 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: transparency_data
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
prerelease: false
|
5
|
+
segments:
|
6
|
+
- 0
|
7
|
+
- 0
|
8
|
+
- 1
|
9
|
+
version: 0.0.1
|
10
|
+
platform: ruby
|
11
|
+
authors:
|
12
|
+
- Wynn Netherland
|
13
|
+
- Jeremy Hinegardner
|
14
|
+
- Luigi Montanez
|
15
|
+
autorequire:
|
16
|
+
bindir: bin
|
17
|
+
cert_chain: []
|
18
|
+
|
19
|
+
date: 2010-05-06 00:00:00 -05:00
|
20
|
+
default_executable:
|
21
|
+
dependencies:
|
22
|
+
- !ruby/object:Gem::Dependency
|
23
|
+
name: rake
|
24
|
+
prerelease: false
|
25
|
+
requirement: &id001 !ruby/object:Gem::Requirement
|
26
|
+
requirements:
|
27
|
+
- - ">="
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
segments:
|
30
|
+
- 0
|
31
|
+
version: "0"
|
32
|
+
type: :runtime
|
33
|
+
version_requirements: *id001
|
34
|
+
- !ruby/object:Gem::Dependency
|
35
|
+
name: monster_mash
|
36
|
+
prerelease: false
|
37
|
+
requirement: &id002 !ruby/object:Gem::Requirement
|
38
|
+
requirements:
|
39
|
+
- - ~>
|
40
|
+
- !ruby/object:Gem::Version
|
41
|
+
segments:
|
42
|
+
- 0
|
43
|
+
- 1
|
44
|
+
- 0
|
45
|
+
version: 0.1.0
|
46
|
+
type: :runtime
|
47
|
+
version_requirements: *id002
|
48
|
+
- !ruby/object:Gem::Dependency
|
49
|
+
name: hashie
|
50
|
+
prerelease: false
|
51
|
+
requirement: &id003 !ruby/object:Gem::Requirement
|
52
|
+
requirements:
|
53
|
+
- - ~>
|
54
|
+
- !ruby/object:Gem::Version
|
55
|
+
segments:
|
56
|
+
- 0
|
57
|
+
- 2
|
58
|
+
- 0
|
59
|
+
version: 0.2.0
|
60
|
+
type: :runtime
|
61
|
+
version_requirements: *id003
|
62
|
+
- !ruby/object:Gem::Dependency
|
63
|
+
name: yard
|
64
|
+
prerelease: false
|
65
|
+
requirement: &id004 !ruby/object:Gem::Requirement
|
66
|
+
requirements:
|
67
|
+
- - ">="
|
68
|
+
- !ruby/object:Gem::Version
|
69
|
+
segments:
|
70
|
+
- 0
|
71
|
+
version: "0"
|
72
|
+
type: :development
|
73
|
+
version_requirements: *id004
|
74
|
+
- !ruby/object:Gem::Dependency
|
75
|
+
name: shoulda
|
76
|
+
prerelease: false
|
77
|
+
requirement: &id005 !ruby/object:Gem::Requirement
|
78
|
+
requirements:
|
79
|
+
- - ">="
|
80
|
+
- !ruby/object:Gem::Version
|
81
|
+
segments:
|
82
|
+
- 2
|
83
|
+
- 10
|
84
|
+
- 1
|
85
|
+
version: 2.10.1
|
86
|
+
type: :development
|
87
|
+
version_requirements: *id005
|
88
|
+
- !ruby/object:Gem::Dependency
|
89
|
+
name: jnunemaker-matchy
|
90
|
+
prerelease: false
|
91
|
+
requirement: &id006 !ruby/object:Gem::Requirement
|
92
|
+
requirements:
|
93
|
+
- - "="
|
94
|
+
- !ruby/object:Gem::Version
|
95
|
+
segments:
|
96
|
+
- 0
|
97
|
+
- 4
|
98
|
+
- 0
|
99
|
+
version: 0.4.0
|
100
|
+
type: :development
|
101
|
+
version_requirements: *id006
|
102
|
+
- !ruby/object:Gem::Dependency
|
103
|
+
name: fakeweb
|
104
|
+
prerelease: false
|
105
|
+
requirement: &id007 !ruby/object:Gem::Requirement
|
106
|
+
requirements:
|
107
|
+
- - ">="
|
108
|
+
- !ruby/object:Gem::Version
|
109
|
+
segments:
|
110
|
+
- 1
|
111
|
+
- 2
|
112
|
+
- 5
|
113
|
+
version: 1.2.5
|
114
|
+
type: :development
|
115
|
+
version_requirements: *id007
|
116
|
+
- !ruby/object:Gem::Dependency
|
117
|
+
name: vcr
|
118
|
+
prerelease: false
|
119
|
+
requirement: &id008 !ruby/object:Gem::Requirement
|
120
|
+
requirements:
|
121
|
+
- - ">="
|
122
|
+
- !ruby/object:Gem::Version
|
123
|
+
segments:
|
124
|
+
- 0
|
125
|
+
- 4
|
126
|
+
- 1
|
127
|
+
version: 0.4.1
|
128
|
+
type: :development
|
129
|
+
version_requirements: *id008
|
130
|
+
- !ruby/object:Gem::Dependency
|
131
|
+
name: mg
|
132
|
+
prerelease: false
|
133
|
+
requirement: &id009 !ruby/object:Gem::Requirement
|
134
|
+
requirements:
|
135
|
+
- - ">="
|
136
|
+
- !ruby/object:Gem::Version
|
137
|
+
segments:
|
138
|
+
- 0
|
139
|
+
- 0
|
140
|
+
- 8
|
141
|
+
version: 0.0.8
|
142
|
+
type: :development
|
143
|
+
version_requirements: *id009
|
144
|
+
- !ruby/object:Gem::Dependency
|
145
|
+
name: mocha
|
146
|
+
prerelease: false
|
147
|
+
requirement: &id010 !ruby/object:Gem::Requirement
|
148
|
+
requirements:
|
149
|
+
- - ">="
|
150
|
+
- !ruby/object:Gem::Version
|
151
|
+
segments:
|
152
|
+
- 0
|
153
|
+
- 9
|
154
|
+
- 8
|
155
|
+
version: 0.9.8
|
156
|
+
type: :development
|
157
|
+
version_requirements: *id010
|
158
|
+
description: Wrapper for the Sunlight Transparency data API
|
159
|
+
email:
|
160
|
+
- wynn.netherland@gmail.com
|
161
|
+
- jeremy@hinegardner.org
|
162
|
+
- luigi.montanez@gmail.com
|
163
|
+
executables: []
|
164
|
+
|
165
|
+
extensions: []
|
166
|
+
|
167
|
+
extra_rdoc_files: []
|
168
|
+
|
169
|
+
files:
|
170
|
+
- README.md
|
171
|
+
- lib/transparency_data.rb
|
172
|
+
- lib/transparency_data/client.rb
|
173
|
+
has_rdoc: false
|
174
|
+
homepage: http://github.com/pengwynn/transparency_data
|
175
|
+
licenses: []
|
176
|
+
|
177
|
+
post_install_message:
|
178
|
+
rdoc_options: []
|
179
|
+
|
180
|
+
require_paths:
|
181
|
+
- lib
|
182
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
183
|
+
requirements:
|
184
|
+
- - ">="
|
185
|
+
- !ruby/object:Gem::Version
|
186
|
+
segments:
|
187
|
+
- 0
|
188
|
+
version: "0"
|
189
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
190
|
+
requirements:
|
191
|
+
- - ">="
|
192
|
+
- !ruby/object:Gem::Version
|
193
|
+
segments:
|
194
|
+
- 0
|
195
|
+
version: "0"
|
196
|
+
requirements: []
|
197
|
+
|
198
|
+
rubyforge_project:
|
199
|
+
rubygems_version: 1.3.6
|
200
|
+
signing_key:
|
201
|
+
specification_version: 3
|
202
|
+
summary: Wrapper for the Sunlight Transparency data API
|
203
|
+
test_files: []
|
204
|
+
|