Skip to content
Browse files

Adding an init function

  • Loading branch information...
1 parent 61da835 commit 19cf67e498cc6c6bab5cb98ae56235f6d1bbbe11 @rgerard committed Nov 20, 2012
Showing with 84 additions and 5 deletions.
  1. +59 −5 README.md
  2. +13 −0 index_nba.js
  3. +12 −0 index_nfl.js
View
64 README.md
@@ -19,22 +19,28 @@ Or from source:
</pre>
-## Configure
-
-Modify config.js and input your own API key and API access level for whatever sports you have a key for.
-
-
## Simple Examples
```javascript
var sportsdata_nfl = require('index_nfl');
+
+// Init the object with the access level, version, apikey, year, and season you care about
+sportsdata_nfl.init('t', 1, apikey, '2012', 'REG');
+
+// Get the season schedule
sportsdata_nfl.getSeasonSchedule(function(error, schedule) {
if (!error) {
console.log(schedule) // Print the season schedule for the NFL season
}
});
+
var sportsdata_nba = require('index_nba');
+
+// Init the object with the access level, version, apikey, seasonID, and season you care about
+sportsdata_nba.init('t', 2, apikey, '2012', 'REG');
+
+// Get the season schedule
sportsdata_nba.getSeasonSchedule(function(error, schedule) {
if (!error) {
console.log(schedule) // Print the season schedule for the NBA season
@@ -60,6 +66,7 @@ nodeunit test/
### NFL
+* [init](#init)
* [getWeeklySchedule](#getWeeklySchedule)
* [getSeasonSchedule](#getSeasonSchedule)
* [getGameStats](#getGameStats)
@@ -81,6 +88,7 @@ nodeunit test/
### NBA
+* [init](#initNba)
* [getSeasonSchedule](#getSeasonScheduleNba)
* [get3DaySchedule](#get3DaySchedule)
* [getStandings](#getStandingsNba)
@@ -93,6 +101,29 @@ nodeunit test/
## NFL API
+<a name="init" />
+### init(access_level, version, apikey, year, season)
+
+Inits the object with your API data, including your API key.
+
+__Arguments__
+
+* access_level - Your API access level
+* version - The version of the API
+* apikey - Your API key
+* year - The year
+* season - The season type
+
+__Example__
+
+```js
+// Fetch the schedule for Week 1 of the NFL season
+
+sportsdata_nfl.init('t', 1, apikey, '2012', 'REG');
+```
+
+---------------------------------------
+
<a name="getWeeklySchedule" />
### getWeeklySchedule(week, callback)
@@ -542,6 +573,29 @@ sportsdata.getSeasonalStats('DAL', function(error, data) {
## NBA API
+<a name="initNba" />
+### init(access_level, version, apikey, seasonID, season)
+
+Inits the object with your API data, including your API key.
+
+__Arguments__
+
+* access_level - Your API access level
+* version - The version of the API to use
+* apikey - Your API key
+* seasonID - The year
+* season - The season type
+
+__Example__
+
+```js
+// Init the object with the access level, version, apikey, seasonID, and season you care about
+
+sportsdata_nba.init('t', 2, apikey, '2012', 'REG');
+```
+
+---------------------------------------
+
<a name="getSeasonScheduleNba" />
### getSeasonSchedule(callback)
View
13 index_nba.js
@@ -18,6 +18,14 @@ var config = require('./config'),
parser = new xml2js.Parser(),
urlHelper = require('./util/url_helper_nba');
+function init(access_level, version, apikey, seasonID, season) {
+ config.nba.access_level = access_level;
+ config.nba.version = version;
+ config.nba.apikey = apikey;
+ config.nba.seasonID = seasonID;
+ config.nba.season = season;
+}
+
function getSeasonSchedule(callback) {
var url = urlHelper.getSeasonScheduleUrl();
createRequest(url, callback);
@@ -80,6 +88,11 @@ function createRequest(url, callback) {
}
module.exports = {
+
+ init: function(access_level, version, apikey, seasonID, season) {
+ return init(access_level, version, apikey, seasonID, season);
+ },
+
setRequest: function(reqObj) {
request = reqObj;
},
View
12 index_nfl.js
@@ -18,6 +18,14 @@ var config = require('./config'),
parser = new xml2js.Parser(),
urlHelper = require('./util/url_helper_nfl');
+function init(access_level, version, apikey, year, season) {
+ config.nfl.access_level = access_level;
+ config.nfl.version = version;
+ config.nfl.apikey = apikey;
+ config.nfl.year = year;
+ config.nfl.season = season;
+}
+
function getWeeklySchedule(week, callback) {
var url = urlHelper.getWeeklyScheduleUrl(week);
createRequest(url, callback);
@@ -124,6 +132,10 @@ function createRequest(url, callback) {
}
module.exports = {
+ init: function(access_level, version, apikey, year, season) {
+ return init(access_level, version, apikey, year, season);
+ },
+
setRequest: function(reqObj) {
request = reqObj;
},

0 comments on commit 19cf67e

Please sign in to comment.
Something went wrong with that request. Please try again.