transparency_data 0.0.1 → 0.0.2
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/transparency_data/client.rb +188 -0
- metadata +5 -5
@@ -21,6 +21,125 @@ module TransparencyData
|
|
21
21
|
end
|
22
22
|
end
|
23
23
|
|
24
|
+
get(:entities) do |api_params|
|
25
|
+
uri TransparencyData.api_url("/entities")
|
26
|
+
params TransparencyData::Client.prepare_params(api_params)
|
27
|
+
handler do |response|
|
28
|
+
TransparencyData::Client.handle_response(response)
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
32
|
+
get(:id_lookup) do |api_params|
|
33
|
+
uri TransparencyData.api_url("/entities/id_lookup")
|
34
|
+
params TransparencyData::Client.prepare_params(api_params)
|
35
|
+
handler do |response|
|
36
|
+
TransparencyData::Client.handle_response(response)
|
37
|
+
end
|
38
|
+
end
|
39
|
+
|
40
|
+
get(:entity) do |id, api_params|
|
41
|
+
uri TransparencyData.api_url("/entities/#{id}")
|
42
|
+
params TransparencyData::Client.prepare_params(api_params) if api_params
|
43
|
+
handler do |response|
|
44
|
+
Hashie::Mash.new(JSON.parse(response.body))
|
45
|
+
end
|
46
|
+
end
|
47
|
+
|
48
|
+
get(:top_contributors) do |id, api_params|
|
49
|
+
uri TransparencyData.api_url("/aggregates/pol/#{id}/contributors")
|
50
|
+
params TransparencyData::Client.prepare_params(api_params) if api_params
|
51
|
+
handler do |response|
|
52
|
+
TransparencyData::Client.handle_response(response)
|
53
|
+
end
|
54
|
+
end
|
55
|
+
|
56
|
+
get(:top_sectors) do |id, api_params|
|
57
|
+
uri TransparencyData.api_url("/aggregates/pol/#{id}/contributors/sectors")
|
58
|
+
params TransparencyData::Client.prepare_params(api_params) if api_params
|
59
|
+
handler do |response|
|
60
|
+
sectors = TransparencyData::Client.handle_response(response)
|
61
|
+
TransparencyData::Client.process_sectors(sectors)
|
62
|
+
end
|
63
|
+
end
|
64
|
+
|
65
|
+
get(:top_industries) do |id, sector, api_params|
|
66
|
+
uri TransparencyData.api_url("/aggregates/pol/#{id}/contributors/sector/#{sector}/industries")
|
67
|
+
params TransparencyData::Client.prepare_params(api_params) if api_params
|
68
|
+
handler do |response|
|
69
|
+
TransparencyData::Client.handle_response(response)
|
70
|
+
end
|
71
|
+
end
|
72
|
+
|
73
|
+
|
74
|
+
get(:local_breakdown) do |id, api_params|
|
75
|
+
uri TransparencyData.api_url("/aggregates/pol/#{id}/contributors/local_breakdown")
|
76
|
+
params TransparencyData::Client.prepare_params(api_params) if api_params
|
77
|
+
handler do |response|
|
78
|
+
breakdown = Hashie::Mash.new(JSON.parse(response.body))
|
79
|
+
TransparencyData::Client.process_local_breakdown(breakdown)
|
80
|
+
end
|
81
|
+
end
|
82
|
+
|
83
|
+
get(:contributor_type_breakdown) do |id, api_params|
|
84
|
+
uri TransparencyData.api_url("/aggregates/pol/#{id}/contributors/type_breakdown")
|
85
|
+
params TransparencyData::Client.prepare_params(api_params) if api_params
|
86
|
+
handler do |response|
|
87
|
+
breakdown = Hashie::Mash.new(JSON.parse(response.body))
|
88
|
+
TransparencyData::Client.process_contributor_type_breakdown(breakdown)
|
89
|
+
end
|
90
|
+
end
|
91
|
+
|
92
|
+
get(:top_recipient_orgs) do |id, api_params|
|
93
|
+
uri TransparencyData.api_url("/aggregates/indiv/#{id}/recipient_orgs")
|
94
|
+
params TransparencyData::Client.prepare_params(api_params) if api_params
|
95
|
+
handler do |response|
|
96
|
+
TransparencyData::Client.handle_response(response)
|
97
|
+
end
|
98
|
+
end
|
99
|
+
|
100
|
+
get(:top_recipient_pols) do |id, api_params|
|
101
|
+
uri TransparencyData.api_url("/aggregates/indiv/#{id}/recipient_pols")
|
102
|
+
params TransparencyData::Client.prepare_params(api_params) if api_params
|
103
|
+
handler do |response|
|
104
|
+
TransparencyData::Client.handle_response(response)
|
105
|
+
end
|
106
|
+
end
|
107
|
+
|
108
|
+
get(:individual_party_breakdown) do |id, api_params|
|
109
|
+
uri TransparencyData.api_url("/aggregates/indiv/#{id}/recipients/party_breakdown")
|
110
|
+
params TransparencyData::Client.prepare_params(api_params) if api_params
|
111
|
+
handler do |response|
|
112
|
+
breakdown = Hashie::Mash.new(JSON.parse(response.body))
|
113
|
+
TransparencyData::Client.process_party_breakdown(breakdown)
|
114
|
+
end
|
115
|
+
end
|
116
|
+
|
117
|
+
get(:top_org_recipients) do |id, api_params|
|
118
|
+
uri TransparencyData.api_url("/aggregates/org/#{id}/recipients")
|
119
|
+
params TransparencyData::Client.prepare_params(api_params) if api_params
|
120
|
+
handler do |response|
|
121
|
+
TransparencyData::Client.handle_response(response)
|
122
|
+
end
|
123
|
+
end
|
124
|
+
|
125
|
+
get(:org_party_breakdown) do |id, api_params|
|
126
|
+
uri TransparencyData.api_url("/aggregates/org/#{id}/recipients/party_breakdown")
|
127
|
+
params TransparencyData::Client.prepare_params(api_params) if api_params
|
128
|
+
handler do |response|
|
129
|
+
breakdown = Hashie::Mash.new(JSON.parse(response.body))
|
130
|
+
TransparencyData::Client.process_org_party_breakdown(breakdown)
|
131
|
+
end
|
132
|
+
end
|
133
|
+
|
134
|
+
get(:org_level_breakdown) do |id, api_params|
|
135
|
+
uri TransparencyData.api_url("/aggregates/org/#{id}/recipients/level_breakdown")
|
136
|
+
params TransparencyData::Client.prepare_params(api_params) if api_params
|
137
|
+
handler do |response|
|
138
|
+
breakdown = Hashie::Mash.new(JSON.parse(response.body))
|
139
|
+
TransparencyData::Client.process_org_level_breakdown(breakdown)
|
140
|
+
end
|
141
|
+
end
|
142
|
+
|
24
143
|
def self.prepare_params(params)
|
25
144
|
params.each do |key, value|
|
26
145
|
if value.is_a?(Hash)
|
@@ -46,5 +165,74 @@ module TransparencyData
|
|
46
165
|
JSON.parse(response.body).map {|c| Hashie::Mash.new(c)}
|
47
166
|
end
|
48
167
|
|
168
|
+
def self.process_sectors(sectors)
|
169
|
+
sectors.each do |sector|
|
170
|
+
sector["name"] = case sector.sector
|
171
|
+
when "A" then "Agribusiness"
|
172
|
+
when "B" then "Communications/Electronics"
|
173
|
+
when "C" then "Construction"
|
174
|
+
when "D" then "Defense"
|
175
|
+
when "E" then "Energy/Natural Resources"
|
176
|
+
when "F" then "Finance/Insurance/Real Estate"
|
177
|
+
when "H" then "Health"
|
178
|
+
when "K" then "Lawyers/Lobbyists"
|
179
|
+
when "M" then "Transportation"
|
180
|
+
when "N" then "Misc. Business"
|
181
|
+
when "Q" then "Ideology/Single Issue"
|
182
|
+
when "P" then "Labor"
|
183
|
+
when "W" then "Other"
|
184
|
+
when "Y" then "Unknown"
|
185
|
+
when "Z" then "Administrative Use"
|
186
|
+
end
|
187
|
+
end
|
188
|
+
end
|
189
|
+
|
190
|
+
def self.process_local_breakdown(breakdown)
|
191
|
+
TransparencyData::Client.mashize_key(breakdown, "in-state", "in_state")
|
192
|
+
TransparencyData::Client.mashize_key(breakdown, "out-of-state", "out_of_state")
|
193
|
+
breakdown
|
194
|
+
end
|
195
|
+
|
196
|
+
def self.process_contributor_type_breakdown(breakdown)
|
197
|
+
TransparencyData::Client.mashize_key(breakdown, "Individuals", "individual")
|
198
|
+
TransparencyData::Client.mashize_key(breakdown, "PACs", "pac")
|
199
|
+
breakdown
|
200
|
+
end
|
201
|
+
|
202
|
+
def self.process_party_breakdown(breakdown)
|
203
|
+
TransparencyData::Client.mashize_key(breakdown, "D", "dem")
|
204
|
+
TransparencyData::Client.mashize_key(breakdown, "R", "rep")
|
205
|
+
TransparencyData::Client.mashize_key(breakdown, "L", "lib")
|
206
|
+
TransparencyData::Client.mashize_key(breakdown, "I", "ind")
|
207
|
+
TransparencyData::Client.mashize_key(breakdown, "U", "unknown")
|
208
|
+
TransparencyData::Client.mashize_key(breakdown, "U", "other")
|
209
|
+
TransparencyData::Client.mashize_key(breakdown, "3", "third")
|
210
|
+
breakdown
|
211
|
+
end
|
212
|
+
|
213
|
+
def self.process_org_party_breakdown(breakdown)
|
214
|
+
TransparencyData::Client.mashize_key(breakdown, "Democrats", "dem")
|
215
|
+
TransparencyData::Client.mashize_key(breakdown, "Republicans", "rep")
|
216
|
+
TransparencyData::Client.mashize_key(breakdown, "L", "lib")
|
217
|
+
TransparencyData::Client.mashize_key(breakdown, "I", "ind")
|
218
|
+
TransparencyData::Client.mashize_key(breakdown, "U", "unknown")
|
219
|
+
TransparencyData::Client.mashize_key(breakdown, "U", "other")
|
220
|
+
TransparencyData::Client.mashize_key(breakdown, "3", "third")
|
221
|
+
breakdown
|
222
|
+
end
|
223
|
+
|
224
|
+
def self.process_org_level_breakdown(breakdown)
|
225
|
+
TransparencyData::Client.mashize_key(breakdown, "State", "state")
|
226
|
+
TransparencyData::Client.mashize_key(breakdown, "Federal", "federal")
|
227
|
+
breakdown
|
228
|
+
end
|
229
|
+
|
230
|
+
def self.mashize_key(breakdown, api_key, mash_key)
|
231
|
+
if breakdown[api_key]
|
232
|
+
breakdown["#{mash_key}_count"] = breakdown[api_key][0].to_i
|
233
|
+
breakdown["#{mash_key}_amount"] = breakdown[api_key][1].to_f
|
234
|
+
end
|
235
|
+
end
|
236
|
+
|
49
237
|
end
|
50
238
|
end
|
metadata
CHANGED
@@ -5,8 +5,8 @@ version: !ruby/object:Gem::Version
|
|
5
5
|
segments:
|
6
6
|
- 0
|
7
7
|
- 0
|
8
|
-
-
|
9
|
-
version: 0.0.
|
8
|
+
- 2
|
9
|
+
version: 0.0.2
|
10
10
|
platform: ruby
|
11
11
|
authors:
|
12
12
|
- Wynn Netherland
|
@@ -16,7 +16,7 @@ autorequire:
|
|
16
16
|
bindir: bin
|
17
17
|
cert_chain: []
|
18
18
|
|
19
|
-
date: 2010-05-
|
19
|
+
date: 2010-05-20 00:00:00 -04:00
|
20
20
|
default_executable:
|
21
21
|
dependencies:
|
22
22
|
- !ruby/object:Gem::Dependency
|
@@ -170,8 +170,8 @@ files:
|
|
170
170
|
- README.md
|
171
171
|
- lib/transparency_data.rb
|
172
172
|
- lib/transparency_data/client.rb
|
173
|
-
has_rdoc:
|
174
|
-
homepage: http://github.com/pengwynn/
|
173
|
+
has_rdoc: true
|
174
|
+
homepage: http://github.com/pengwynn/transparency-data
|
175
175
|
licenses: []
|
176
176
|
|
177
177
|
post_install_message:
|