Skip to content
This repository has been archived by the owner on Jan 2, 2018. It is now read-only.

Commit

Permalink
Add yo functionality
Browse files Browse the repository at this point in the history
  • Loading branch information
shuwen committed Feb 24, 2015
1 parent dc86a09 commit 3e20932
Show file tree
Hide file tree
Showing 4 changed files with 44 additions and 13 deletions.
31 changes: 26 additions & 5 deletions public/javascripts/client.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,19 +39,40 @@

// Get the server to emit a test event back to us
$('#test').click(function() {
socket.emit('test', {});
var user = $('#handle').val();
yo(user);
});

// Server will respond when there is a bus
socket.on('bus', function() {
alert('it works, there is a bus');
flashTitle();
var user = $('#handle').val();
yo(user);
});

// Implement this later
// Flash the page title
function flashTitle() {
var oldTitle = document.title;
var newTitle = 'Yo!';
var title = $('title');

var oldTitle = title.text();
var newTitle = 'Get ready for the bus!';

setInterval(function() {
if(title.text() == oldTitle)
title.text(newTitle);
else
title.text(oldTitle);
}, 900);
}

function yo(user) {
$.ajax({
type: 'POST',
url: 'http://api.justyo.co/yo/',
data: {
'api_token': '',
'username': user
}
});
}
})();
12 changes: 9 additions & 3 deletions public/stylesheets/style.css
Original file line number Diff line number Diff line change
Expand Up @@ -52,20 +52,23 @@ input[disabled]:active {
margin: 0 auto 2em;
}

#timer {
#timer,
#yo {
color: #fff;
display: block;
margin: auto;
text-align: center;
}

#timer span {
#timer span,
#yo span {
display: block;
line-height: 37px;
vertical-align: middle;
}

#time {
#time,
#handle {
background-color: #004B8D;
border: none;
border-radius: 5px;
Expand All @@ -74,5 +77,8 @@ input[disabled]:active {
margin: 0 .5em;
padding: .25em;
text-align: center;
}

#time {
width: 2em;
}
8 changes: 4 additions & 4 deletions sockets/base.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,22 +5,22 @@ var unirest = require('unirest'),
module.exports = function(io) {
io.on('connection', function(socket) {

// For testing only
socket.on('test', function() {
console.log('test: it works');
socket.emit('bus', {});
});

socket.on('watch', function(d) {
var f = false;
// Pass the bus id, time, and socket
findBus(d.bus, d.t, socket);
});

});
}

/**
* Helper function that queries API until true
*/
// Helper function that queries API until true
function findBus(id, t, soc) {
var busFound = false;
var reqPath = "https://transloc-api-1-2.p.mashape.com/arrival-estimates.json?agencies=100&stops="+id;
Expand All @@ -31,8 +31,8 @@ function findBus(id, t, soc) {
.end(function (res) {
if ( (Date.parse(res.body.data[0].arrivals[0].arrival_at) - Date.now() ) < t*60000 ) {
soc.emit('bus', {});
return busFound;
} else {
// Wait 1 minute and run this function again
sleep.sleep(60);
findBus(id);
}
Expand Down
6 changes: 5 additions & 1 deletion views/index.jade
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,13 @@ block content

div#timer
span= "Alert me in"
input#time(type='text')
input#time(type='text',value='5')
span= "minutes"

div#yo
span= "Yo handle"
input#handle(type='text')

input#submit(type='submit',value="Submit",disabled)

input#test(type='button',value='Test Event')

0 comments on commit 3e20932

Please sign in to comment.