forked from DFID/devtracker-from-api
-
Notifications
You must be signed in to change notification settings - Fork 0
/
devtracker.rb
158 lines (128 loc) · 4.36 KB
/
devtracker.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
152
153
154
155
156
# devtracker.rb
#require 'rubygems'
#require 'bundler'
#Bundler.setup
require 'sinatra'
require 'json'
require 'rest-client'
require 'active_support'
#helpers path
require_relative 'helpers/formatters.rb'
require_relative 'helpers/oipa_helpers.rb'
require_relative 'helpers/codelists.rb'
require_relative 'helpers/lookups.rb'
require_relative 'helpers/project_helpers.rb'
require_relative 'helpers/sector_helpers.rb'
#helpers modules
include SectorHelpers
# set global settings
set :oipa_api_url, 'http://dfid-oipa.zz-clients.net/api/'
#ensures that we can use the extension html.erb rather than just .erb
Tilt.register Tilt::ERBTemplate, 'html.erb'
#####################################################################
# HOME PAGE
#####################################################################
get '/' do #homepage
#read static data from JSON files for the front page
# top5countries = JSON.parse(File.read('data/top5countries.json'))
top5sectors = JSON.parse(File.read('data/top5sectors.json'))
top5results = JSON.parse(File.read('data/top5results.json'))
countriesJSON = RestClient.get settings.oipa_api_url + "activities/aggregations?reporting_organisation=GB-1&group_by=recipient_country&aggregations=budget&budget_period_start=2015-04-01&budget_period_end=2016-03-31&order_by=-budget&page_size=5"
top5countries = JSON.parse(countriesJSON)
erb :index,
:layout => :'layouts/layout',
:locals => {
top_5_countries: top5countries,
what_we_do: high_level_sector_list,
what_we_achieve: top5results
}
end
#####################################################################
# PROJECTS PAGES
#####################################################################
# examples:
#http://devtracker.dfid.gov.uk/projects/GB-1-204024/
# http://149.210.176.175/api/activities/GB-1-204024?format=json
# Project summary page
get '/projects/:proj_id/?' do |n|
# get the project data from the API
oipa = RestClient.get settings.oipa_api_url + "activities/#{n}?format=json"
project = JSON.parse(oipa)
erb :'projects/summary',
:layout => :'layouts/layout',
:locals => {
project: project
}
end
#Project test page
get '/projects/:proj_id/test/?' do |n|
# get the project data from the API
oipa = RestClient.get settings.oipa_api_url + "activities/#{n}?format=json"
project = JSON.parse(oipa)
erb :'projects/test',
:layout => :'layouts/layout',
:locals => {
project: project
}
end
#Project documents page
get '/projects/:proj_id/documents/?' do |n|
# get the project data from the API
oipa = RestClient.get settings.oipa_api_url + "activities/#{n}?format=json"
project = JSON.parse(oipa)
erb :'projects/documents',
:layout => :'layouts/layout',
:locals => {
project: project
}
end
#Project transactions page
get '/projects/:proj_id/transactions/?' do |n|
# get the project data from the API
oipa = RestClient.get settings.oipa_api_url + "activities/#{n}?format=json"
project = JSON.parse(oipa)
# get the transactions from the API
oipa_tx = RestClient.get settings.oipa_api_url + "activities/#{n}/transactions?format=json" #TEST: for Partner Project
tx = JSON.parse(oipa_tx)
transactions = tx['results']
erb :'projects/transactions',
:layout => :'layouts/layout',
:locals => {
project: project,
transactions: transactions
}
end
#Project transactions page (test)
get '/projects/:proj_id/txtest/?' do |n|
# get the project data from the API
oipa = RestClient.get settings.oipa_api_url + "activities/#{n}?format=json"
project = JSON.parse(oipa)
# get the transactions from the API
oipa_tx = RestClient.get settings.oipa_api_url + "activities/#{n}-101/transactions?format=json" #TEST: hard-coding -101
tx = JSON.parse(oipa_tx)
transactions = tx['results']
erb :'projects/testtx',
:layout => :'layouts/layout',
:locals => {
project: project,
transactions: transactions
}
end
#####################################################################
# STATIC PAGES
#####################################################################
get '/about/?' do
erb :'about/index', :layout => :'layouts/layout'
end
get '/cookies/?' do
erb :'cookies/index', :layout => :'layouts/layout'
end
get '/faq/?' do
erb :'faq/index', :layout => :'layouts/layout'
end
get '/feedback/?' do
erb :'feedback/index', :layout => :'layouts/layout'
end
get '/fraud/?' do
erb :'fraud/index', :layout => :'layouts/layout'
end