-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathdata.rb
executable file
·45 lines (37 loc) · 938 Bytes
/
data.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
#!/usr/bin/env ruby
# Gems
require 'rubygems'
require 'sinatra'
require 'erb'
require 'transparency_data'
# Local files
require 'model'
get '/' do
erb :outer
end
get '/data-load' do
TransparencyData.api_key = 'cbb3e6d549ce43eb8f45c4b53b1a9081'
TransparencyData::Client.contributions(:contributor_ft => params[:search]).to_json
end
get '/businesses' do
data = []
businesses = Business.all(:latitude.not => '', :longitude.not => '')
businesses.each do |b|
new_data = {
:business_id => b.id,
:business_name => b.name,
:latitude => b.latitude,
:longitude => b.longitude,
:contributions => []
}
b.contributors.each do |contrib|
contrib.contributions.each do |c|
new_data[:contributions] << {:amount => c.amount, :party => c.recipient.party}
end
end
data << new_data
end
data.sort {
|a, b| a[:business_name] <=> b[:business_name]
}.to_json
end