-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathindex.php
201 lines (157 loc) · 4.13 KB
/
index.php
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
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
<?php
require_once __DIR__.'/silex.phar';
$app = new Silex\Application();
$app['debug'] = true;
$app->register(new Silex\Extension\DoctrineExtension(), array(
'db.options' => array(
'driver' => 'pdo_mysql',
'dbname' => 'hackday',
'user' => 'root',
'password' => '',
'host' => 'localhost'
),
'db.dbal.class_path' => __DIR__.'/vendor/doctrine-dbal/lib',
'db.common.class_path' => __DIR__.'/vendor/doctrine-common/lib',
));
$app->get('/twitter', function() use ($app) {
header('application/json');
require 'lib/Twitter.php';
$resource = new Twitter();
echo json_encode($resource->getQuestion());
});
$app->get('/craigslist', function() use ($app) {
header('application/json');
require 'lib/Craigslist.php';
$resource = new Craigslist();
echo json_encode($resource->getQuestion());
});
$app->get('/rottentomato', function() use ($app) {
header('application/json');
require 'lib/RottenTomato.php';
$resource = new RottenTomato();
echo json_encode($resource->getQuestion());
});
$app->get('/musixmatch', function() use ($app) {
header('application/json');
require 'lib/MusixMatch.php';
$resource = new MusixMatch();
echo json_encode($resource->getQuestion());
});
$app->get('/question', function() use ($app) {
$feeds = array('MusixMatch','RottenTomato','Craigslist');
$source = $feeds[array_rand($feeds)];
header('application/json');
require "lib/{$source}.php";
$resource = new $source();
echo json_encode($resource->getQuestion());
});
$app->get('/leaderboard', function() use ($app) {
header('application/json');
$return = array(
23525 => array(
'score' => 62351351,
'name' => 'Jake Smith'
),
231413 => array(
'score' => 2342355,
'name' => 'Geoff Tran'
),
123 => array(
'score' => 21242,
'name' => 'Ben Gatzke'
)
);
echo json_encode($return);
});
$app->get('/submissions', function() use ($app) {
header('application/json');
$return = array(
23525 => array(
'correct' => true,
'name' => 'Jake Smith'
),
231413 => array(
'score' => true,
'name' => 'Geoff Tran'
),
123 => array(
'score' => false,
'name' => 'Ben Gatzke'
)
);
echo json_encode($return);
});
$app->post('/user', function() use ($app) {
// Add User;
$answerId = $app['db']->insert('users', array(
'name' => 'Jake Smith',
'email' => '[email protected]'
));
header('application/json');
$return = array(
12515 => array(
'name' => 'Jake Smith',
'email' => '[email protected]'
)
);
echo json_encode($return);
});
$app->post('/submit', function() use ($app) {
// Submit User Score
$answerId = $app['db']->insert('answers', array(
'answer' => 'Yes',
'question_id' => 1,
'correct' => true,
'quiz_id' => 1,
'user_id' => 1
));
header('application/json');
$return = array(
1245133 => true
);
echo json_encode($return);
});
$app->run();
/*
require 'lib/RottenTomato.php';
$resource = new RottenTomato('php');
$question = $resource->getQuestion();
echo "<h2>{$question['question']}</h2>";
echo "<ul>";
foreach ($question['answers'] as $answer) {
echo "<li>{$answer}</li>";
}
echo "</ul>";
echo "<p>Correct Answer: {$question['correctAnswer']}</p>";
require 'lib/Craigslist.php';
$clist = new Craigslist();
$cquestion = $clist->getQuestion();
echo "<h2>{$cquestion['question']}</h2>";
echo "<img src='{$cquestion['photo']}' alt=''><br>";
echo "<ul>";
foreach ($cquestion['answers'] as $answer) {
echo "<li>{$answer}</li>";
}
echo "</ul>";
echo "<p>Correct Answer: {$cquestion['correctAnswer']}</p>";
require 'lib/MusixMatch.php';
$music = new MusixMatch();
$mquestion = $music->getQuestion();
echo "<h2>{$mquestion['question']}</h2>";
echo "<ul>";
foreach ($mquestion['answers'] as $answer) {
echo "<li>{$answer}</li>";
}
echo "</ul>";
echo "<p>Correct Answer: {$mquestion['correctAnswer']}</p>";
require 'lib/Twitter.php';
$twitter = new Twitter();
$tquestion = $twitter->getQuestion();
echo "<h2>{$tquestion['question']}</h2>";
echo "<ul>";
foreach ($tquestion['answers'] as $answer) {
echo "<li>{$answer}</li>";
}
echo "</ul>";
echo "<p>Correct Answer: {$tquestion['correctAnswer']}</p>";
*/