-
Notifications
You must be signed in to change notification settings - Fork 0
/
handler.js
73 lines (56 loc) · 1.68 KB
/
handler.js
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
var model = require('./model.js');
var twitterApi = require('./twitterapi.js');
var guardian = require('./guardian.js');
var home = function(request, reply){
console.log('request handler for "/"');
reply.file('views/index.html');
}
var view = function(request, reply){
console.log('request handler for "/view"');
reply.file('views/view.html');
}
var confirmation = function(request, reply){
console.log('request handler for "/confirmation"');
reply.file('views/confirmation.html');
}
var postForm = function (request, reply){
console.log('request handler for "postForm"');
console.log('payload: ', request.payload);
model.saveForm(request.payload);
reply('postForm received');
}
var getData = function(request, reply){
console.log('request handler for "getData"');
model.getData(reply);
}
var sendId = function (request, reply){
console.log('request handler for "sendId"');
console.log('ID of clicked button is...', request.query.id);
model.getRecord(request.query.id, buildHeadlinesArray);
}
//TWITTER FUNCTIONS
function twitterRequestHeadlines (record) {
console.log('twitterRequestHeadlines, ', record);
var tag1 = record[0].tag1,
tag2 = record[0].tag2,
tag3 = record[0].tag3
twitterApi.getTweets(tag1, tag2, tag3);
}
//GUARDIAN FUNCTIONS
function buildHeadlinesArray (record) {
console.log('guardian api called: ', record);
var tag1 = record[0].tag1,
tag2 = record[0].tag2,
tag3 = record[0].tag3
tagArray = [tag1, tag2, tag3]
var emailAddress = record[0].email;
guardian.getHeadlines(tagArray, emailAddress);
}
module.exports = {
home: home,
postForm: postForm,
view: view,
confirmation: confirmation,
getData: getData,
sendId: sendId
}