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
|
# File 'lib/sinatra/cf_light_api.rb', line 11
def self.registered(app)
app.get '/v1/apps/?:org?' do
content_type :json
all_apps = JSON.parse(REDIS.get("#{ENV['REDIS_KEY_PREFIX']}:apps"))
if params[:org]
return all_apps.select{|an_app| an_app['org'] == params[:org]}.to_json
end
return all_apps.to_json
end
app.get '/v2/apps/?:org?' do
content_type :json
all_apps = JSON.parse(REDIS.get("#{ENV['REDIS_KEY_PREFIX']}:apps:v2"))
if params[:org]
return all_apps.select{|an_app| an_app['org'] == params[:org]}.to_json
end
return all_apps.to_json
end
app.get '/v1/orgs/?:guid?' do
content_type :json
all_orgs = JSON.parse(REDIS.get("#{ENV['REDIS_KEY_PREFIX']}:orgs"))
if params[:guid]
return all_orgs.select{|an_org| an_org['guid'] == params[:guid]}.to_json
end
return all_orgs.to_json
end
app.get '/v1/last_updated' do
content_type :json
updated_json = REDIS.get("#{ENV['REDIS_KEY_PREFIX']}:last_updated")
last_updated = DateTime.parse JSON.parse(updated_json)["last_updated"]
seconds_since_update = ((DateTime.now - last_updated) * 24 * 60 * 60).to_i
status 503 if seconds_since_update >= (ENV['DATA_AGE_VALIDITY'] || '600'.to_i)
return updated_json
end
app.get '/v1/info' do
content_type :json
return REDIS.get("#{ENV['REDIS_KEY_PREFIX']}:info")
end
end
|