Skip to content

Commit

Permalink
atndのAPIを叩いて表示
Browse files Browse the repository at this point in the history
  • Loading branch information
chris4403 committed Oct 21, 2011
1 parent 43a524b commit d2172ca
Show file tree
Hide file tree
Showing 3 changed files with 67 additions and 0 deletions.
56 changes: 56 additions & 0 deletions app.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,5 +43,61 @@ app.post('/', function(req, res){
});
});

// atnd events api
app.get('/events', function(req, res){

var http = require('http');
var options = {
host : 'api.atnd.org',
port : 80,
path : '/events/?format=json',
};
var result = {};
http.get(options, function(response) {
response.setEncoding('utf8');
var json = "";
response.on('data',function(d) {
json += d;
}).on('end',function() {
result = JSON.parse(json);
res.render('events', {
title: 'atnd event results',
total_events : result.results_available,
events : result.events
});
});
}).on('error',function(e) {
console.log(e);
});

});

app.get('/event', function(req, res) {
var eventId = req.query.event_id;

var http = require('http');
var options = {
host : 'api.atnd.org',
port : 80,
path : '/events/?format=json&event_id=' + eventId,
};
var result = {};
http.get(options, function(response) {
response.setEncoding('utf8');
var json = "";
response.on('data',function(d) {
json += d;
}).on('end',function() {
result = JSON.parse(json);
res.render('event', {
title: 'atnd event',
event : result.events[0]
});
});
}).on('error',function(e) {
console.log(e);
});
});

app.listen(3000);
console.log("Express server listening on port %d in %s mode", app.address().port, app.settings.env);
5 changes: 5 additions & 0 deletions views/event.jade
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
h1= title
p #{title}
ul#event
each key in event
li #{key}
6 changes: 6 additions & 0 deletions views/events.jade
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
h1= title
p #{title}
ul#events
each event in events
li
a(href='/event?event_id=' + event.event_id, target='_blank') #{event.title}

0 comments on commit d2172ca

Please sign in to comment.