Skip to content

Commit

Permalink
Adding NCAAF to the module
Browse files Browse the repository at this point in the history
  • Loading branch information
rgerard committed May 29, 2013
1 parent 8fdcda8 commit 0e7fae5
Show file tree
Hide file tree
Showing 7 changed files with 11,576 additions and 2 deletions.
7 changes: 7 additions & 0 deletions config.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,4 +21,11 @@ config.mlb.version = '3';
config.mlb.apikey = '';
config.mlb.year = '2013';

config.ncaaf = {};
config.ncaaf.access_level = 't';
config.ncaaf.version = '1';
config.ncaaf.season = 'REG';
config.ncaaf.apikey = '';
config.ncaaf.year = '2013';

module.exports = config;
10 changes: 8 additions & 2 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@

var sportsdata_nfl = require('./index_nfl'),
sportsdata_nba = require('./index_nba'),
sportsdata_mlb = require('./index_mlb');
sportsdata_mlb = require('./index_mlb'),
sportsdata_ncaaf = require('./index_ncaaf');

function createNfl() {
return sportsdata_nfl;
Expand All @@ -28,6 +29,11 @@ function createMlb() {
return sportsdata_mlb;
}

function createNcaaf() {
return sportsdata_ncaaf;
}

module.exports.NFL = createNfl();
module.exports.NBA = createNba();
module.exports.MLB = createMlb();
module.exports.MLB = createMlb();
module.exports.NCAAF = createNcaaf();
107 changes: 107 additions & 0 deletions index_ncaaf.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,107 @@
// Copyright 2010-2012 Ryan Gerard
//
// 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.

var config = require('./config'),
request = require('request'),
xml2js = require('xml2js'),
parser = new xml2js.Parser(),
urlHelper = require('./util/url_helper_ncaaf');

function init(access_level, version, year, season, apikey) {
config.ncaaf.access_level = access_level;
config.ncaaf.version = version;
config.ncaaf.year = year;
config.ncaaf.season = season;
config.ncaaf.apikey = apikey;
}

function getSeasonSchedule(callback) {
var url = urlHelper.getSeasonScheduleUrl();
createRequest(url, callback);
}

function getWeeklySchedule(week, callback) {
var url = urlHelper.getWeeklyScheduleUrl(week);
createRequest(url, callback);
}

function getGameStatistics(week, awayteam, hometeam, callback) {
var url = urlHelper.getGameStatisticsUrl(week, awayteam, hometeam);
createRequest(url, callback);
}

function getBoxscore(week, awayteam, hometeam, callback) {
var url = urlHelper.getBoxscoreUrl(week, awayteam, hometeam);
createRequest(url, callback);
}

function getExtendedBoxscore(week, awayteam, hometeam, callback) {
var url = urlHelper.getExtendedBoxscoreUrl(week, awayteam, hometeam);
createRequest(url, callback);
}

function getStandings(division, callback) {
var url = urlHelper.getStandingsUrl(division);
createRequest(url, callback);
}

function createRequest(url, callback) {
request(url, function (error, response, body) {

if (response.statusCode == 200) {

// Parse the XML to JSON
parser.parseString(body, function (err, result) {
callback(err, result);
});
} else {
callback(error, body);
}
});
}

module.exports = {

init: function(access_level, version, year, season, apikey) {
return init(access_level, version, year, season, apikey);
},

setRequest: function(reqObj) {
request = reqObj;
},

getSeasonSchedule: function(callback) {
return getSeasonSchedule(callback);
},

getWeeklySchedule: function(week, callback) {
return getWeeklySchedule(week, callback);
},

getGameStatistics: function(week, awayteam, hometeam, callback) {
return getGameStatistics(week, awayteam, hometeam, callback);
},

getBoxscore: function(week, awayteam, hometeam, callback) {
return getBoxscore(week, awayteam, hometeam, callback);
},

getExtendedBoxscore: function(week, awayteam, hometeam, callback) {
return getExtendedBoxscore(week, awayteam, hometeam, callback);
},

getStandings: function(division, callback) {
return getStandings(division, callback);
}
};
Loading

0 comments on commit 0e7fae5

Please sign in to comment.