4800-v-004-002
[previously]
- [2015-06-09] NEW task IN PAGE rankings
- x] # # - UPDATE rankings - use REQUEST to pull data from api - i] revisiting pulling the drivers data FROM src=sospep.people using api call, ] see TRY 1, TRY 2, TRY 3 and TRY 4 ] SUCCESS with TRY 4 using the 'request' package, see example code in homes.js-v-001
- [2015-06-10] NEW task IN PAGE
- ] # # - CREATE-module - getEntrants - put code for pulling entrants data, then processing it, into a seperate module(VS in index 'controller)
[currently]
- [2015-06-10] NEW task IN
- ] # # - request api - lets get that request working properly, http.get request
- *] TRY 1 - SRC = SO ? http://stackoverflow.com/questions/9577611/http-get-request-in-node-js-express response # 2
- *] uses = http
- ] SUCCESS - try# 4
- [00:00] NEW task IN
- ] # # - data
- ] var url = 'http://sospep.com/qry/Select-IndividualsInMemberGroup-a/25'; //returns nascar drivers list
- ] { race: '2015-13', id: 107, nameDriver: 'Ricky Stenhouse Jr', teamID: '17', points: 0, top10s: 'one', description: 'ricky is awesome' },
- * [00:00] NEW task IN
- ] # # - use existing 'drivers' to create an 'entrants list'
- ] person - HAS id, name
- ] request json - all
- ] iterate 'records' and add desired properties to each driver record NEED ADD - ] race, ] teamID, ] points ] top10(CALC)
- ] PRB teamID - create/use lookupDriver function
- ] save as file
- ] pull data for view from file
- ] admin command to /get-entrants
- [00:00] NEW task IN sospep/membergroup/ {nations/nascar/drivers}
- x] # # - data - drivers
- x] changed person.status of non active drivers(7) to 'asked' from default of ask, USE this param to pull just the drivers entered in a given race
- [00:00] NEW task IN sospep app
- x] # # - app sospep - make new dir x] api
- [00:00] NEW task IN sospep app pages
- x] # # - sospep - NEW endpoint - raceEntrants
- x] = ( copy SelectIndividualsInMemberGroup-a /{membergroup id} /{status}
- ] COMPARE MemberGroup-a - concats first and last to return fullname
- ] VS MemberGroup - returns first and last name
- ]
- ] ?? == current session
- *] this gets me a 'pseudo list' of entrants for the current race *, still NEED the actual list of entrants ..
- > [00:00] NEW task IN
- ] # # - actual entrants - COMPARE
- > [00:00] NEW task IN PASS - rankings
- x] # # - get entrants (aka drivers) for current race - x] call new api,
- > [00:00] NEW task IN PASS - rankings
- ] # # - TRY CREATE module for 'getEntrants' code
- ] var entrants = [
- ];
- module.exports(getEntrants)
- ] iterate the list of drivers to ADD additional properties
- [00:00] NEW task IN
- ] # # - CREATE module - take logic for building entrants list, move into module
- ] using module.exports = function(){} then ADD route VS
- ] using var myModule = { properties:'values'} module.exports(myModule) then ADD route
- [00:00] NEW task IN NOTE
- ] entrants.js - v-001 = first example, see 10.3, 500 error
- ] entrants.js -v-002 = simple example of passing data
- *] PAGE (ex index) requires var entrants = requries entrants.js, CANT invoke
- [00:00] NEW task IN NOTE its WORKING (it may NOT be right, but it is working)
- ] filename.js - using module.exports, ex entrants.js
- ] include pseudo path to .js file in app.js routes section, example = require('./routes/entrants')(app);
- ] define var in file using - ex index - var drivers = require('./filename')
- ] call var function where you need entrants()
- CC] # # - understanding expressjs - ]
- [2015-06-11] DONE
- ] teams table, manually loaded data
- ] lookup function, lookup teamID by driverID,
- ] fails on loop,
- ] seems to work on invidual
- ] sospep data - add prop 'priority' to race entrants, USE for teamID
- ] adjust getEntrants api endpoint to return property
- ] DO
- ] driver (description w/{}, )
- ] rankRace15
- ]- avgfinish-last10 races
- >] ]
- ]
[next]
- ]
TRY 1
var http = require('http');
var options = {
host: 'sospep.com',
path: '/qry/Select-IndividualsInMemberGroup-a/25'
};
var reqDrivers = http.get(url, function (res1) {
console.log('STATUS: ' + res1.statusCode);
console.log('HEADERS: ' + JSON.stringify(res1.headers));
// Buffer the body entirely for processing as a whole.
var bodyChunks = [];
res1.on('data', function (chunk) {
// You can process streamed parts here...
bodyChunks.push(chunk);
}).on('end', function () {
var body = Buffer.concat(bodyChunks);
// console.log('BODY: ' + body);
// ...and/or process the entire body here.
// body = JSON.parse(body);
})
});
reqDrivers.on('error', function (e) {
console.log('ERROR: ' + e.message);
});
TRY 2 https://docs.nodejitsu.com/articles/HTTP/clients/how-to-create-a-HTTP-request
var scoot = '';
var http = require('http');
callback = function (response) {
var str = '';
//another chunk of data has been recieved, so append it to `str`
response.on('data', function (chunk) {
str += chunk;
});
//the whole response has been recieved, so we just print it out here
response.on('end', function () {
console.log(str);
// return JSON.stringify(str);
});
}
http.request(url, callback).end();
// var str = '';
TRY 3 - use previous example code in home.js page,
successfully pulled data from api and piped that data to a file on the server
using request package, try get vs fs
TRY 4 - use tutorial in art# 4566
KEY - moving the http request outside of the app.get(){ } function