-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathserver.rb
152 lines (131 loc) · 4.52 KB
/
server.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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
require 'rubygems'
require 'sinatra'
require 'json'
require 'rack-cache'
require 'net/http'
require 'net/https'
#require 'active_support/core_ext/hash'
#require 'active_support/core_ext/object'
use Rack::Cache
set :public_folder, 'public'
set :bind, '0.0.0.0'
get '/' do
File.read(File.join('public', 'index.html'))
end
#===========
# Historic visitors
get '/govuk-historic-visitors' do
cache_control :public, :max_age => 20
http = Net::HTTP.new('www.performance.service.gov.uk', 443)
http.use_ssl = true
req = Net::HTTP::Get.new("/data/govuk/visitors?collect=visitors%3Asum&period=month&duration=1")
response = http.request(req)
response.body
end
#===========
# Devices last week
get '/govuk-devices' do
cache_control :public, :max_age => 20
http = Net::HTTP.new('www.performance.service.gov.uk', 443)
http.use_ssl = true
req = Net::HTTP::Get.new("/data/govuk/devices?collect=visitors%3Asum&group_by=deviceCategory&duration=1&period=week")
response = http.request(req)
response.body
end
#===========
# tax disc realtime visitors
get '/tax-disc-users' do
cache_control :public, :max_age => 20
http = Net::HTTP.new('www.performance.service.gov.uk', 443)
http.use_ssl = true
req = Net::HTTP::Get.new("/data/tax-disc/realtime?sort_by=_timestamp%3Adescending&limit=5")
response = http.request(req)
response.body
end
# tax disc satisfaction
get '/tax-disc-satisfaction' do
cache_control :public, :max_age => 20
http = Net::HTTP.new('www.performance.service.gov.uk', 443)
http.use_ssl = true
req = Net::HTTP::Get.new("/data/vehicle-licensing/customer-satisfaction?")
response = http.request(req)
response.body
end
#===========
# SORN realtime visitors
get '/sorn-users' do
cache_control :public, :max_age => 20
http = Net::HTTP.new('www.performance.service.gov.uk', 443)
http.use_ssl = true
req = Net::HTTP::Get.new("/data/sorn/realtime?sort_by=_timestamp%3Adescending&limit=5")
response = http.request(req)
response.body
end
# SORN satisfaction
get '/sorn-satisfaction' do
cache_control :public, :max_age => 20
http = Net::HTTP.new('www.performance.service.gov.uk', 443)
http.use_ssl = true
req = Net::HTTP::Get.new("/data/vehicle-licensing/customer-satisfaction?")
response = http.request(req)
response.body
end
#===========
# LPA live data
get '/lpa' do
cache_control :public, :max_age => 20
http = Net::HTTP.new('www.performance.service.gov.uk', 443)
http.use_ssl = true
req = Net::HTTP::Get.new("/data/lasting-power-of-attorney/volumes?")
response = http.request(req)
response.body
end
#===========
# Carer's allowance live data (returns ALL claims by channel) in a nice format!
get '/carers' do
cache_control :public, :max_age => 20
http = Net::HTTP.new('www.performance.service.gov.uk', 443)
http.use_ssl = true
req = Net::HTTP::Get.new("/data/carers-allowance/weekly-claims?collect=value%3Asum&period=month&group_by=key&duration=12")
response = http.request(req)
response.body
end
#===========
# Prison visits over the last 12 months
get '/prison-visits' do
cache_control :public, :max_age => 20
http = Net::HTTP.new('www.performance.service.gov.uk', 443)
http.use_ssl = true
req = Net::HTTP::Get.new("/data/prison-visits/digital-volumes?period=month&group_by=is_digital&collect=count%3Asum&duration=12")
response = http.request(req)
response.body
end
#===========
# Civil claims over the last 12 months
get '/civil-claims' do
cache_control :public, :max_age => 20
http = Net::HTTP.new('www.performance.service.gov.uk', 443)
http.use_ssl = true
req = Net::HTTP::Get.new("/data/accelerated-possession-eviction/transactions-by-channel?period=month&group_by=channel&collect=count%3Asum&duration=12")
response = http.request(req)
response.body
end
#===========
# Register to vote realtime visitors
get '/register-to-vote-users' do
cache_control :public, :max_age => 20
http = Net::HTTP.new('www.performance.service.gov.uk', 443)
http.use_ssl = true
req = Net::HTTP::Get.new("/data/register-to-vote/realtime?sort_by=_timestamp%3Adescending&limit=5")
response = http.request(req)
response.body
end
# Register to vote satisfaction
get '/register-to-vote-satisfaction' do
cache_control :public, :max_age => 20
http = Net::HTTP.new('www.performance.service.gov.uk', 443)
http.use_ssl = true
req = Net::HTTP::Get.new("/data/register-to-vote/customer-satisfaction?period=day&duration=1&collect=rating_1%3Asum&collect=rating_2%3Asum&collect=rating_3%3Asum&collect=rating_4%3Asum&collect=rating_5%3Asum&collect=total%3Asum")
response = http.request(req)
response.body
end