Permalink
Browse files

first commit

  • Loading branch information...
videlalvaro committed Nov 23, 2012
0 parents commit ac8fbea485f461d97ca29294c66ff43f9aca8315
@@ -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.
@@ -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;
+};

Some generated files are not rendered by default. Learn more.

Oops, something went wrong.
@@ -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": "*"
+ }
+}

Some generated files are not rendered by default. Learn more.

Oops, something went wrong.

Large diffs are not rendered by default.

Oops, something went wrong.
@@ -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');
+ });
+};

Large diffs are not rendered by default.

Oops, something went wrong.
@@ -0,0 +1,11 @@
+function initMasonry() {
+ $('#image-list').masonry({
+ itemSelector : '.imagebox',
+ columnWidth : 160,
+ isAnimated: true
+ });
+}
+
+jQuery(document).ready(function() {
+ initMasonry();
+});

Large diffs are not rendered by default.

Oops, something went wrong.
Oops, something went wrong.

0 comments on commit ac8fbea

Please sign in to comment.