Permalink
Please sign in to comment.
Showing
with
1,021 additions
and 0 deletions.
- +1 −0 .gitignore
- +13 −0 LICENSE
- +34 −0 README.md
- +62 −0 app.js
- +27 −0 lib/broadcast.js
- +94 −0 npm-shrinkwrap.json
- +15 −0 package.json
- +10 −0 public/javascripts/jquery.masonry.min.js
- +4 −0 public/javascripts/jquery.min.js
- +18 −0 public/javascripts/livestream.js
- +27 −0 public/javascripts/sockjs-0.3.4.min.js
- +11 −0 public/javascripts/thanksgiving.js
- +9 −0 public/stylesheets/bootstrap.min.css
- +504 −0 public/stylesheets/normalize.css
- +124 −0 public/stylesheets/style.css
- +68 −0 views/layout.ejs
@@ -0,0 +1 @@ | ||
+node_modules |
13
LICENSE
@@ -0,0 +1,13 @@ | ||
+Copyright 2012 Alvaro Videla <avidela@vmware.com> | ||
+ | ||
+Licensed under the Apache License, Version 2.0 (the "License"); | ||
+you may not use this file except in compliance with the License. | ||
+You may obtain a copy of the License at | ||
+ | ||
+ http://www.apache.org/licenses/LICENSE-2.0 | ||
+ | ||
+Unless required by applicable law or agreed to in writing, software | ||
+distributed under the License is distributed on an "AS IS" BASIS, | ||
+WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
+See the License for the specific language governing permissions and | ||
+limitations under the License. |
34
README.md
@@ -0,0 +1,34 @@ | ||
+# Thanksgiving App # | ||
+ | ||
+This app shows a real time feed of Instagram images for that have the `#thanksgiving` tag. | ||
+ | ||
+The feed is refreshewd in realtime using [https://github.com/sockjs/sockjs-client](sock.js) and consumers the Instagram Api. | ||
+ | ||
+See it live here: [http://thanksgiving.cloudfoundry.com/](http://thanksgiving.cloudfoundry.com/). | ||
+ | ||
+__NOTE__ This application is not affiliated with Instagram. This is just a demo. | ||
+ | ||
+# Deploying the App to Cloud Foundry # | ||
+ | ||
+```bash | ||
+git clone | ||
+cd thanksgiving | ||
+vmc push --runtime node08 | ||
+``` | ||
+ | ||
+Then you will need to set the following env variables for your app: | ||
+ | ||
+```bash | ||
+vmc env-add thanksgiving CLIENT_ID=$CLIENT_ID | ||
+vmc env-add thanksgiving CLIENT_SECRET=$CLIENT_SECRET | ||
+``` | ||
+ | ||
+Use the values from your Instagram developer account. | ||
+ | ||
+# License # | ||
+ | ||
+See the LICENSE file. | ||
+ | ||
+# Credits # | ||
+ | ||
+[https://twitter.com/old_sound](@old_sound). |
62
app.js
@@ -0,0 +1,62 @@ | ||
+var express = require('express') | ||
+ , http = require('http') | ||
+ , path = require('path') | ||
+ , Instagram = require('instagram-node-lib') | ||
+ , broadcast = require('./lib/broadcast.js')(); | ||
+ | ||
+Instagram.set('client_id', process.env.CLIENT_ID); | ||
+Instagram.set('client_secret', process.env.CLIENT_SECRET); | ||
+ | ||
+var app = express(); | ||
+ | ||
+app.configure(function(){ | ||
+ app.set('port', process.env.VCAP_APP_PORT || 3000); | ||
+ app.set('views', __dirname + '/views'); | ||
+ app.set('view engine', 'ejs'); | ||
+ app.use(express.favicon()); | ||
+ app.use(express.logger('dev')); | ||
+ app.use(app.router); | ||
+ app.use(express.static(path.join(__dirname, 'public'))); | ||
+}); | ||
+ | ||
+app.configure('development', function(){ | ||
+ app.use(express.errorHandler()); | ||
+}); | ||
+ | ||
+var max_tag_id = null; | ||
+ | ||
+app.get('/', function(req, res) { | ||
+ Instagram.tags.recent({ | ||
+ name: 'thanksgiving', | ||
+ max_tag_id: max_tag_id, | ||
+ complete: function(data, pagination){ | ||
+ max_tag_id = pagination.next_max_tag_id; | ||
+ res.render('layout', { | ||
+ data: data | ||
+ }); | ||
+ } | ||
+ }); | ||
+}); | ||
+ | ||
+var server = http.createServer(app); | ||
+ | ||
+broadcast.installHandlers(server, { | ||
+ prefix: '/broadcast', | ||
+ sockjs_url: '/javascripts/sockjs-0.3.js' | ||
+}); | ||
+ | ||
+server.listen(app.get('port'), function(){ | ||
+ console.log("Express server listening on port " + app.get('port')); | ||
+}); | ||
+ | ||
+var interval = setInterval(function () { | ||
+ Instagram.tags.recent({ | ||
+ name: 'thanksgiving', | ||
+ max_tag_id: max_tag_id, | ||
+ complete: function(data, pagination){ | ||
+ max_tag_id = pagination.next_max_tag_id; | ||
+ var images = data.slice(0, 2); | ||
+ broadcast.send(JSON.stringify(images)); | ||
+ } | ||
+ }); | ||
+}, 5000); |
@@ -0,0 +1,27 @@ | ||
+// taken from https://github.com/igorw/websockets-talk/tree/master/broadcast | ||
+ | ||
+var sockjs = require('sockjs'); | ||
+ | ||
+module.exports = function () { | ||
+ var broadcast = sockjs.createServer(); | ||
+ | ||
+ broadcast.on('connection', function (conn) { | ||
+ broadcast.clients.push(conn); | ||
+ | ||
+ conn.on('close', function () { | ||
+ var index = broadcast.clients.indexOf(conn); | ||
+ if (-1 !== index) { | ||
+ broadcast.clients.splice(index, 1); | ||
+ } | ||
+ }); | ||
+ }); | ||
+ | ||
+ broadcast.clients = []; | ||
+ broadcast.send = function (message) { | ||
+ this.clients.forEach(function (conn) { | ||
+ conn.write(message); | ||
+ }); | ||
+ }; | ||
+ | ||
+ return broadcast; | ||
+}; |
15
package.json
@@ -0,0 +1,15 @@ | ||
+{ | ||
+ "name": "thanksgiving", | ||
+ "version": "0.0.1", | ||
+ "private": true, | ||
+ "scripts": { | ||
+ "start": "node app" | ||
+ }, | ||
+ "dependencies": { | ||
+ "express": "3.0.3", | ||
+ "ejs": "*", | ||
+ "instagram-node-lib": "*", | ||
+ "sockjs": "0.3.4", | ||
+ "jade": "*" | ||
+ } | ||
+} |
@@ -0,0 +1,18 @@ | ||
+var sockUrl = 'http://' + window.location.host +'/broadcast'; | ||
+console.log('sockUrl: ', sockUrl); | ||
+var sock = new SockJS(sockUrl); | ||
+sock.onopen = function (event) { | ||
+ console.log('sockjs connection ready'); | ||
+}; | ||
+sock.onmessage = function (event) { | ||
+ var images = JSON.parse(event.data); | ||
+ console.log("data: ", event.data); | ||
+ jQuery.each(images, function(index, image) { | ||
+ console.log(index, image); | ||
+ var html = '<div id="box-' + image.id + '" class="imagebox">' + | ||
+ '<div><a href="' + image.link + '" target="_new"><img class="userimage" src="' + image.images.thumbnail.url + '"></a>' + | ||
+ '</div></div>'; | ||
+ console.log(html); | ||
+ jQuery('#image-list').prepend(html).masonry('reload'); | ||
+ }); | ||
+}; |
@@ -0,0 +1,11 @@ | ||
+function initMasonry() { | ||
+ $('#image-list').masonry({ | ||
+ itemSelector : '.imagebox', | ||
+ columnWidth : 160, | ||
+ isAnimated: true | ||
+ }); | ||
+} | ||
+ | ||
+jQuery(document).ready(function() { | ||
+ initMasonry(); | ||
+}); |

Oops, something went wrong.
0 comments on commit
ac8fbea