Class: TransparencyData::Client
- Inherits:
-
MonsterMash::Base
- Object
- MonsterMash::Base
- TransparencyData::Client
- Defined in:
- lib/transparency_data/client.rb
Class Method Summary collapse
- .handle_response(response) ⇒ Object
- .mashize_key(breakdown, api_key, mash_key) ⇒ Object
- .prepare_params(params) ⇒ Object
- .process_contributor_type_breakdown(breakdown) ⇒ Object
- .process_local_breakdown(breakdown) ⇒ Object
- .process_org_level_breakdown(breakdown) ⇒ Object
- .process_org_party_breakdown(breakdown) ⇒ Object
- .process_party_breakdown(breakdown) ⇒ Object
- .process_sectors(sectors) ⇒ Object
Class Method Details
.handle_response(response) ⇒ Object
163 164 165 166 |
# File 'lib/transparency_data/client.rb', line 163 def self.handle_response(response) # TODO: raise_errors JSON.parse(response.body).map {|c| Hashie::Mash.new(c)} end |
.mashize_key(breakdown, api_key, mash_key) ⇒ Object
230 231 232 233 234 235 |
# File 'lib/transparency_data/client.rb', line 230 def self.mashize_key(breakdown, api_key, mash_key) if breakdown[api_key] breakdown["#{mash_key}_count"] = breakdown[api_key][0].to_i breakdown["#{mash_key}_amount"] = breakdown[api_key][1].to_f end end |
.prepare_params(params) ⇒ Object
143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 |
# File 'lib/transparency_data/client.rb', line 143 def self.prepare_params(params) params.each do |key, value| if value.is_a?(Hash) case value.keys.first when :gte params[key] = ">|#{value.values.first}" when :lte params[key] = "<|#{value.values.first}" when :between params[key] = "><|#{value.values.first.join('|')}" end elsif value.is_a?(Array) params[key] = value.join("|") end end params end |
.process_contributor_type_breakdown(breakdown) ⇒ Object
196 197 198 199 200 |
# File 'lib/transparency_data/client.rb', line 196 def self.process_contributor_type_breakdown(breakdown) TransparencyData::Client.mashize_key(breakdown, "Individuals", "individual") TransparencyData::Client.mashize_key(breakdown, "PACs", "pac") breakdown end |
.process_local_breakdown(breakdown) ⇒ Object
190 191 192 193 194 |
# File 'lib/transparency_data/client.rb', line 190 def self.process_local_breakdown(breakdown) TransparencyData::Client.mashize_key(breakdown, "in-state", "in_state") TransparencyData::Client.mashize_key(breakdown, "out-of-state", "out_of_state") breakdown end |
.process_org_level_breakdown(breakdown) ⇒ Object
224 225 226 227 228 |
# File 'lib/transparency_data/client.rb', line 224 def self.process_org_level_breakdown(breakdown) TransparencyData::Client.mashize_key(breakdown, "State", "state") TransparencyData::Client.mashize_key(breakdown, "Federal", "federal") breakdown end |
.process_org_party_breakdown(breakdown) ⇒ Object
213 214 215 216 217 218 219 220 221 222 |
# File 'lib/transparency_data/client.rb', line 213 def self.process_org_party_breakdown(breakdown) TransparencyData::Client.mashize_key(breakdown, "Democrats", "dem") TransparencyData::Client.mashize_key(breakdown, "Republicans", "rep") TransparencyData::Client.mashize_key(breakdown, "L", "lib") TransparencyData::Client.mashize_key(breakdown, "I", "ind") TransparencyData::Client.mashize_key(breakdown, "U", "unknown") TransparencyData::Client.mashize_key(breakdown, "Other", "other") TransparencyData::Client.mashize_key(breakdown, "3", "third") breakdown end |
.process_party_breakdown(breakdown) ⇒ Object
202 203 204 205 206 207 208 209 210 211 |
# File 'lib/transparency_data/client.rb', line 202 def self.process_party_breakdown(breakdown) TransparencyData::Client.mashize_key(breakdown, "Democrats", "dem") TransparencyData::Client.mashize_key(breakdown, "Republicans", "rep") TransparencyData::Client.mashize_key(breakdown, "L", "lib") TransparencyData::Client.mashize_key(breakdown, "I", "ind") TransparencyData::Client.mashize_key(breakdown, "U", "unknown") TransparencyData::Client.mashize_key(breakdown, "Other", "other") TransparencyData::Client.mashize_key(breakdown, "3", "third") breakdown end |
.process_sectors(sectors) ⇒ Object
168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 |
# File 'lib/transparency_data/client.rb', line 168 def self.process_sectors(sectors) sectors.each do |sector| sector["name"] = case sector.sector when "A" then "Agribusiness" when "B" then "Communications/Electronics" when "C" then "Construction" when "D" then "Defense" when "E" then "Energy/Natural Resources" when "F" then "Finance/Insurance/Real Estate" when "H" then "Health" when "K" then "Lawyers/Lobbyists" when "M" then "Transportation" when "N" then "Misc. Business" when "Q" then "Ideology/Single Issue" when "P" then "Labor" when "W" then "Other" when "Y" then "Unknown" when "Z" then "Administrative Use" end end end |