Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit bf1be4d
Showing
5 changed files
with
117 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
node_modules | ||
.DS_Store | ||
*.db |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
var express = require('express'); | ||
var http = require('http'); | ||
var routes = require('./lib/routes'); | ||
var app = express(); | ||
|
||
|
||
app.get('/', routes.getAuthURL); | ||
app.get('/user/authorize', routes.getAuthURL); | ||
app.get('/auth_callback', routes.authCallback); | ||
app.get('/api/:method', routes.makeFlickrRequest); | ||
|
||
|
||
http.createServer(app).listen(3000, function(){ | ||
console.log('Express server listening on port 3000'); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
var dirty = require('dirty'); | ||
var Flapi = require('flapi'); | ||
|
||
|
||
exports.createClient = function(next){ | ||
|
||
var settings = dirty('./db/settings.db'); | ||
settings.on('load', function(){ | ||
|
||
var opts = { | ||
oauth_consumer_key : process.env.FLICKR_KEY, | ||
oauth_consumer_secret : process.env.FLICKR_SECRET, | ||
perms : 'delete' | ||
}; | ||
|
||
var oauthOpts = settings.get('oauth'); | ||
if(oauthOpts){ | ||
opts.oauth_token = oauthOpts.oauth_token; | ||
opts.oauth_token_secret = oauthOpts.oauth_token_secret; | ||
} | ||
|
||
makeNewCient(opts); | ||
}); | ||
|
||
|
||
var makeNewCient = function(opts){ | ||
var client = new Flapi(opts); | ||
if(!opts.oauth_token){ | ||
client.authApp('http://localhost:3000/auth_callback', function(oauthResults){ | ||
console.log('Flickr Initialized'); | ||
settings.set('oauth', oauthResults); | ||
next(client); | ||
}); | ||
} else{ | ||
console.log('Flickr Initialized'); | ||
next(client); | ||
} | ||
}; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
var dirty = require('dirty'); | ||
var users = dirty('./db/users.db'); | ||
|
||
var flickrClient; | ||
require('./flickrConnect').createClient(function(client){ | ||
flickrClient = client; | ||
}); | ||
|
||
|
||
exports.getAuthURL = function(req, res){ | ||
res.redirect(flickrClient.getUserAuthURL()); | ||
}; | ||
|
||
|
||
// If there's an oauth_token, we know this is a user auth. | ||
// otherwise, it's just the app trying to auth, let it pass | ||
exports.authCallback = function(req, res){ | ||
if(req.query.oauth_token){ | ||
flickrClient.getUserAccessToken(req.query.oauth_verifier, function(accessToken){ | ||
users.set(accessToken.user_nsid, accessToken); | ||
res.send('Succesfully Authorized.'); | ||
}); | ||
} else { | ||
res.writeHead(200, {'Content-Type': 'text/plain'}); | ||
res.end(); | ||
} | ||
}; | ||
|
||
|
||
exports.makeFlickrRequest = function(req, res){ | ||
var accessToken = users.get(req.query.user_id); | ||
var apiMethod = 'flickr.' + req.params.method; | ||
var params = {}; | ||
|
||
for(var key in req.query){ | ||
params[key] = req.query[key]; | ||
} | ||
|
||
flickrClient.api({ | ||
method : apiMethod, | ||
params : params, | ||
accessToken : accessToken, | ||
next : function(data){ | ||
res.send(data); | ||
} | ||
}); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
{ | ||
"name": "flickr-app-server", | ||
"version": "0.0.0", | ||
"description": "", | ||
"main": "index.js", | ||
"repository": "", | ||
"author": "Joe Longstreet", | ||
"license": "BSD", | ||
"dependencies": { | ||
"dirty": "~0.9.7", | ||
"express": "~3.4.8" | ||
} | ||
} |