Skip to content

Commit

Permalink
abstracts s3 and ordrin
Browse files Browse the repository at this point in the history
  • Loading branch information
MJefferson committed Jun 30, 2012
1 parent 351e24f commit 597ec53
Show file tree
Hide file tree
Showing 4 changed files with 136 additions and 12 deletions.
2 changes: 2 additions & 0 deletions worker/app.js
Expand Up @@ -7,6 +7,7 @@ var express = require('express')
, routes = require('./routes');

var app = module.exports = express.createServer();
var reqHandler = require('./scripts/request_handler.js');

// Configuration

Expand All @@ -33,4 +34,5 @@ app.get('/', routes.index);

app.listen(3000, function(){
console.log("Scrooge worker listening on port %d in %s mode", app.address().port, app.settings.env);
reqHandler.getQueue();
});
39 changes: 39 additions & 0 deletions worker/scripts/ordrin.js
@@ -0,0 +1,39 @@
var reqHandler = require('./request_handler.js');

module.exports = {
newRequest: function (queueObj){
generateResponse(queueObj);
}
}

function generateResponse(q){
var ordrinURL = "r-test.ordr.in"

var params;//build rest of path using queue's params
var options = {
host: ordrinURL,
path: '/dl/datetime,etc',
method: 'GET'
}

var req = https.request(option, function(result){
//pass this response to Fn that puts it to S3
var responseString = "";
response.on('data', function(chunk) {
responseString += chunk;
});

response.on('end', function() {
//at this point, the handler has the queue;
var responseObj = JSON.parse(responseString);
console.log(responseObj);
});

});

req.end();

req.on('error', function(e) {
console.error(e);
});
}
71 changes: 59 additions & 12 deletions worker/scripts/request_handler.js
@@ -1,24 +1,71 @@
var https = require('https');
var ordrin = require('./ordrin.js');
var s3 = require('./s3.js');

module.exports = {
getQueue: getQueue(),
handle: fn,
popQueue: fn
getQueue : function() {
getQueue();
},
handle : function() {

},
popQueue : function() {

},
config: function(){
return config;
}
}

//abstract the following config object; possibly put it in app.js

config = {

git : {
user : 'scrooge-demo'
},
s3 : {
s3_url : 'scrooge.leknarf.net',
s3_folder : 'results',
access_key_id : 'AKIAIWZWQG72NWWW7G3Q',
access_key : '8RlneaSOIjyiXWgWjf7lWoyTomHofiYSx5LLFcIi'
},
ordrn : {
access_key: 'LkAHD4QSAAAA6RoMAABJug'
}
}

function getQueue(){
options = {
host: 'api.github.com',
port: 80,
path: '/repos/:user/:repo/git/blobs/'
function getQueue() {

var options = {
host : 'api.github.com',
path : '/users/' + config.git.user + '/gists',
method : 'GET'
}

https.request(options, function(res){


var req = https.request(options, function(response) {
var queueString = "";
response.on('data', function(chunk) {
queueString += chunk;
});

response.on('end', function() {
//at this point, the handler has the queue;
var queue = JSON.parse(queueString);
console.log(queue);
});
});

req.end();

req.on('error', function(e) {
console.error(e);
});
}

function handleQueue(queue){
//loops over
//takes parameters from queue object
}



36 changes: 36 additions & 0 deletions worker/scripts/s3.js
@@ -0,0 +1,36 @@
var reqHandler = require('./request_handler.js');

module.exports = {
post: function(response){
postResponse(r);
}
}

function postResponse(r){

var params;//build params from passed in Ordrin response
var options = {
host: reqHandler.config.s3.url,
path: '',
method: 'POST'
}

var req = https.request(options, function(result){
var responseString = "";
response.on('data', function(chunk) {
responseString += chunk;
});

response.on('end', function() {
//s3's response
var responseObj = JSON.parse(responseString);
});

});

req.end();

req.on('error', function(e) {
console.error(e);
});
}

0 comments on commit 597ec53

Please sign in to comment.