Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

added front and back end

  • Loading branch information...
commit 7f3da6b0c820244476951ea0d082c8c046f55caf 1 parent 27241d0
@JustinBeckwith authored
View
1  .gitignore
@@ -1,3 +1,4 @@
node_modules
keys.json
iisnode
+instagram-subscriptions.json
View
4 backend/.gitignore
@@ -0,0 +1,4 @@
+node_modules
+keys.json
+iisnode
+instagram-subscriptions.json
View
0  README.md → backend/README.md
File renamed without changes
View
18 backend/cities.json
@@ -0,0 +1,18 @@
+{
+ "cities": [
+ { "name": "seattle", "lat":"47.606308", "long":"-122.332072" },
+ { "name": "new-york", "lat":"40.714379", "long":"-74.005989"},
+ { "name": "los-angeles", "lat":"34.052304", "long":"-118.243686"},
+ { "name": "pittsburgh", "lat":"40.440709", "long":"-79.995879" },
+ { "name": "san-francisco", "lat":"37.774963", "long":"-122.419433"},
+ { "name": "washington-dc", "lat":"38.895125", "long":"-77.03637"},
+ { "name": "london", "lat":"51.508235", "long":"-0.128023"},
+ { "name": "rome", "lat":"41.901534", "long":"12.460781"}
+ ],
+
+}
+
+
+
+
+
View
4 backend/keys.example.json
@@ -0,0 +1,4 @@
+{
+ "instagramClientId": "INSTAGRAM CLIENT ID HERE",
+ "instagramClientSecret": "INSTAGRAM CLIENT SECRET HERE"
+}
View
4 package.json → backend/package.json
@@ -8,6 +8,8 @@
"dependencies": {
"express": "3.0.0rc4",
"jade": "*",
- "nconf": "~0.6.4"
+ "nconf": "~0.6.4",
+ "request": "~2.11.4",
+ "azure": "~0.6.4"
}
}
View
0  public/stylesheets/style.css → backend/public/stylesheets/style.css
File renamed without changes
View
9 backend/response.txt
@@ -0,0 +1,9 @@
+
+{"meta":{"code":200},"data":{"object":"geography","object_id":"1465543","aspect":"media","callback_url":"http:\/\/wazstagram.azurewebsites.net\/newimage\/san-francisco","type":"subscription","id":"2365423"}}
+{"meta":{"code":200},"data":{"object":"geography","object_id":"1465542","aspect":"media","callback_url":"http:\/\/wazstagram.azurewebsites.net\/newimage\/new-york","type":"subscription","id":"2365424"}}
+{"meta":{"code":200},"data":{"object":"geography","object_id":"1465544","aspect":"media","callback_url":"http:\/\/wazstagram.azurewebsites.net\/newimage\/seattle","type":"subscription","id":"2365425"}}
+{"meta":{"code":200},"data":{"object":"geography","object_id":"1465541","aspect":"media","callback_url":"http:\/\/wazstagram.azurewebsites.net\/newimage\/pittsburgh","type":"subscription","id":"2365426"}}
+{"meta":{"code":200},"data":{"object":"geography","object_id":"1465540","aspect":"media","callback_url":"http:\/\/wazstagram.azurewebsites.net\/newimage\/los-angeles","type":"subscription","id":"2365427"}}
+{"meta":{"code":200},"data":{"object":"geography","object_id":"1465537","aspect":"media","callback_url":"http:\/\/wazstagram.azurewebsites.net\/newimage\/washington-dc","type":"subscription","id":"2365419"}}
+{"meta":{"code":200},"data":{"object":"geography","object_id":"1465536","aspect":"media","callback_url":"http:\/\/wazstagram.azurewebsites.net\/newimage\/london","type":"subscription","id":"2365420"}}
+{"meta":{"code":200},"data":{"object":"geography","object_id":"1465538","aspect":"media","callback_url":"http:\/\/wazstagram.azurewebsites.net\/newimage\/rome","type":"subscription","id":"2365421"}}
View
0  robots.txt → backend/robots.txt
File renamed without changes
View
45 backend/routes/home.js
@@ -0,0 +1,45 @@
+var request = require('request');
+
+module.exports = function (app, nconf, serviceBusService) {
+
+ // home page
+ app.get('/', function (req, res) {
+
+
+
+ res.render('index', { title: 'Home Page. ' })
+ });
+
+ // instagram get
+ app.get('/newimage/:city', function (req, res) {
+ // http://your-callback.com/url/?hub.mode=subscribe&hub.challenge=15f7d1a91c1f40f8a748fd134752feb3&hub.verify_token=myVerifyToken
+
+ console.log(req.params.city);
+ console.log(req.query['hub.challenge']);
+ console.log(req.query['hub.mode']);
+ console.log(req.query['hub.verify_token']);
+
+ res.send(req.query['hub.challenge']);
+ });
+
+
+ app.post('/newimage/:city', function (req, res) {
+ var data = req.body;
+ data.forEach(function (img) {
+ var url = "https://api.instagram.com/v1/media/" + img.object_id + "?client_id=" + nconf.get('instagramClientId');
+ console.log(url);
+ request(url, function (e, r, b) {
+ console.log(b);
+ var message = { body: b };
+ serviceBusService.sendTopicMessage('wazages', message, function (error) {
+ if (error) {
+ console.log('error sending message to topic - ' + error);
+ } else {
+ console.log('message sent!');
+ }
+ })
+ });
+ })
+ res.end();
+ });
+}
View
47 backend/server.js
@@ -0,0 +1,47 @@
+
+/**
+ * Module dependencies.
+ */
+
+var express = require('express')
+ , http = require('http')
+ , path = require('path')
+ , nconf = require('nconf')
+ , azure = require('azure');
+
+nconf.argv().env().file('keys.json');
+
+var sbNamespace = nconf.get('AZURE_SERVICEBUS_NAMESPACE');
+var sbKey = nconf.get('AZURE_SERVICEBUS_ACCESS_KEY');
+var serviceBusService = azure.createServiceBusService(sbNamespace, sbKey);
+serviceBusService.createTopicIfNotExists('wazages', function (error) {
+ if (!error) {
+ console.log('topic wazages created or exists');
+ } else {
+ console.log('error creating service topic wazages');
+ }
+});
+
+var app = express();
+
+app.configure(function () {
+ app.set('port', process.env.PORT || 3000);
+ app.set('views', __dirname + '/views');
+ app.set('view engine', 'jade');
+ app.use(express.favicon());
+ app.use(express.logger('dev'));
+ app.use(express.bodyParser());
+ app.use(express.methodOverride());
+ app.use(app.router);
+ app.use(express.static(path.join(__dirname, 'public')));
+});
+
+app.configure('development', function(){
+ app.use(express.errorHandler());
+});
+
+require('./routes/home')(app, nconf, serviceBusService);
+
+http.createServer(app).listen(app.get('port'), function(){
+ console.log("Express server listening on port " + app.get('port'));
+});
View
36 backend/tests/register.js
@@ -0,0 +1,36 @@
+var cities = require("./cities").cities,
+ http = require("http"),
+ request = require('request'),
+ nconf = require('nconf'),
+ util = require('util');
+
+nconf.argv().env().file('keys.json');
+
+cities.forEach(function (city) {
+
+ var options = {
+ "client_id": nconf.get("instagramClientId"),
+ "client_secret": nconf.get("instagramClientSecret"),
+ "object": "geography",
+ "aspect": "media",
+ "lat": city.lat,
+ "lng": city.long,
+ "radius": 5000,
+ "callback_url": util.format(nconf.get("subscriptionCallbackUrl"), city.name)
+ }
+
+ request('https://api.instagram.com/v1/subscriptions/',
+ {
+ "form": options,
+ "method": "post"
+ }, function (err, response, body) {
+
+ if (err) {
+ console.log('ERROR! ' + err);
+ }
+ console.log(body);
+ });
+
+});
+
+
View
33 backend/tests/simpost.js
@@ -0,0 +1,33 @@
+var request = require('request');
+
+var testData = [
+ {
+ "subscription_id": "1",
+ "object": "user",
+ "object_id": "1234",
+ "changed_aspect": "media",
+ "time": 1297286541
+ },
+ {
+ "subscription_id": "2",
+ "object": "tag",
+ "object_id": "nofilter",
+ "changed_aspect": "media",
+ "time": 1297286541
+ }];
+
+ console.log(JSON.stringify(testData));
+
+request('http://localhost:16378/newimage/seattle',
+ {
+ "json": testData,
+ "method": "post"
+ }, function (err, response, body) {
+
+ if (err) {
+ console.log('ERROR! ' + err);
+ }
+ console.log(body);
+});
+
+
View
0  views/index.jade → backend/views/index.jade
File renamed without changes
View
0  views/layout.jade → backend/views/layout.jade
File renamed without changes
View
0  web.config → backend/web.config
File renamed without changes
View
16 cities.json
@@ -1,16 +0,0 @@
-{
- "name": "NodeSite",
- "version": "0.0.1",
- "author": "",
- "description": "",
- "contributors": [],
- "main": "./server.js",
- "keywords": [],
- "dependencies": {},
- "noAnalyze": true,
- "engines": {
- "node": ">=0.6"
- },
- "devDependencies": {},
- "optionalDependencies": {}
-}
View
14 server.js → frontend/app.js
@@ -3,14 +3,11 @@
* Module dependencies.
*/
-var express = require('express')
+var express = require('express')
+ , routes = require('./routes')
+ , user = require('./routes/user')
, http = require('http')
- , path = require('path')
- , nconf = require('nconf');
-
-nconf.argv().env().file('keys.json');
-
-//console.log(nconf.get('instagramClientId'));
+ , path = require('path');
var app = express();
@@ -30,7 +27,8 @@ app.configure('development', function(){
app.use(express.errorHandler());
});
-require('./routes/home')(app);
+app.get('/', routes.index);
+app.get('/users', user.list);
http.createServer(app).listen(app.get('port'), function(){
console.log("Express server listening on port " + app.get('port'));
View
12 frontend/package.json
@@ -0,0 +1,12 @@
+{
+ "name": "application-name",
+ "version": "0.0.1",
+ "private": true,
+ "scripts": {
+ "start": "node app"
+ },
+ "dependencies": {
+ "express": "3.0.0rc4",
+ "jade": "*"
+ }
+}
View
8 frontend/public/stylesheets/style.css
@@ -0,0 +1,8 @@
+body {
+ padding: 50px;
+ font: 14px "Lucida Grande", Helvetica, Arial, sans-serif;
+}
+
+a {
+ color: #00B7FF;
+}
View
8 frontend/routes/index.js
@@ -0,0 +1,8 @@
+
+/*
+ * GET home page.
+ */
+
+exports.index = function(req, res){
+ res.render('index', { title: 'Express' });
+};
View
8 frontend/routes/user.js
@@ -0,0 +1,8 @@
+
+/*
+ * GET users listing.
+ */
+
+exports.list = function(req, res){
+ res.send("respond with a resource");
+};
View
5 frontend/views/index.jade
@@ -0,0 +1,5 @@
+extends layout
+
+block content
+ h1= title
+ p Welcome to #{title}
View
7 frontend/views/layout.jade
@@ -0,0 +1,7 @@
+doctype 5
+html
+ head
+ title= title
+ link(rel='stylesheet', href='/stylesheets/style.css')
+ body
+ block content
View
19 routes/home.js
@@ -1,19 +0,0 @@
-module.exports = function (app) {
-
- // home page
- app.get('/', function (req, res) {
- res.render('index', { title: 'Home Page. ' })
- });
-
- // instagram get
- app.get('/newimage/:city', function (req, res) {
- // http://your-callback.com/url/?hub.mode=subscribe&hub.challenge=15f7d1a91c1f40f8a748fd134752feb3&hub.verify_token=myVerifyToken
-
- console.log(req.params.city);
- console.log(req.query['hub.challenge']);
- console.log(req.query['hub.mode']);
- console.log(req.query['hub.verify_token']);
-
- res.send(req.query['hub.challenge']);
- });
-}
Please sign in to comment.
Something went wrong with that request. Please try again.