Skip to content

Commit

Permalink
Latest changes to support v2.0 feed requests.
Browse files Browse the repository at this point in the history
  • Loading branch information
bradbarkhouse committed Aug 22, 2018
1 parent 04cad46 commit 9f958c9
Show file tree
Hide file tree
Showing 9 changed files with 341 additions and 60 deletions.
44 changes: 38 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ Free for Non-Commercial Use.
Using composer, simply add it to the "require" section of your composer.json:

"require": {
"mysportsfeeds\mysportsfeeds-php": ">=1.0.0"
"mysportsfeeds\mysportsfeeds-php": ">=2.0.0"
}

If you haven't signed up for API access, do so here [https://www.mysportsfeeds.com/index.php/register/](https://www.mysportsfeeds.com/index.php/register/)
Expand All @@ -20,32 +20,64 @@ If you haven't signed up for API access, do so here [https://www.mysportsfeeds.c

Create main MySportsFeeds object with API version as input parameter

For v1.x feed requests (free non-commercial access available):

use MySportsFeeds\MySportsFeeds;

$msf = new MySportsFeeds("1.2");

Authenticate (v1.x uses your MySportsFeeds account credentials)
For v2.0 feed requests (donation required for non-commercial access):

use MySportsFeeds\MySportsFeeds;

$msf = new MySportsFeeds("2.0");


Authenticate for v1.x (uses your MySportsFeeds account password)

$msf->authenticate("<YOUR_API_KEY>", "<YOUR_ACCOUNT_PASSWORD>");

Authenticate for v2.0 (simply uses "MYSPORTSFEEDS" as password)

$msf->authenticate("<YOUR_API_KEY>", "MYSPORTSFEEDS");

$msf->authenticate("YOUR_USERNAME", "YOUR_PASSWORD");

Start making requests, specifying in this order: $league, $season, $feed, $format, and any other applicable params for the feed. See example.php for sample usage.

Get all NBA 2016-2017 regular season gamelogs for Stephen Curry, in JSON format
Example (v1.x): Get all NBA 2016-2017 regular season gamelogs for Stephen Curry, in JSON format

```
$data = $msf->getData('nba', '2016-2017-regular', 'player_gamelogs', 'json', 'player=stephen-curry');
```

Get all NFL 2015-2016 regular season seasonal stats totals for all Dallas Cowboys players, in XML format
Example (v1.x): Get all NFL 2015-2016 regular season seasonal stats totals for all Dallas Cowboys players, in XML format

```
$data = $msf->getData('nfl', '2015-2016-regular', 'cumulative_player_stats', 'xml', 'team=dallas-cowboys');
```

Get full game schedule for the MLB 2016 playoff season, in CSV format
Example (v1.x): Get full game schedule for the MLB 2016 playoff season, in CSV format

```
$data = $msf->getData('mlb', '2016-playoff', 'full_game_schedule', 'csv');
```

Example (v2.0): Get all NBA 2016-2017 regular season gamelogs for Stephen Curry, in JSON format

```
$data = $msf->getData('nba', '2016-2017-regular', 'seasonal_player_gamelogs', 'json', 'player=stephen-curry');
```

Example (v2.0): Get all NFL 2015 regular season stats totals for all Dallas Cowboys players, in XML format

```
$data = $msf->getData('nfl', '2015-regular', 'seasonal_player_stats', 'xml', 'team=dallas-cowboys');
```

Example (v2.0): Get full game schedule and scores for the MLB 2016 playoff season, in CSV format

```
$data = $msf->getData('mlb', '2016-playoff', 'seasonal_games', 'csv');
```

That's it! Returned data is also stored locally under "results/" by default, in appropriately named files.
19 changes: 18 additions & 1 deletion example.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
use MySportsFeeds\MySportsFeeds;

$data_query = new MySportsFeeds('1.2', true);
$data_query->authenticate('YOUR_USERNAME', 'YOUR_PASSWORD');
$data_query->authenticate('<YOUR_API_KEY>', '<YOUR_ACCOUNT_PASSWORD>');
$data = $data_query->getData(
'nba', // league

Expand All @@ -20,3 +20,20 @@
);

var_dump($data);

$data_query = new MySportsFeeds('2.0', true);
$data_query->authenticate('<YOUR_API_KEY>', 'MYSPORTSFEEDS');
$data = $data_query->getData(
'nba', // league

'2016-2017-regular', // season identifier

'seasonal_player_gamelogs', // feed name

'json', // format (must be one of: "csv", "json", or "xml")

// add any number of additional valid parameters, with "name=value" format
'player=stephen-curry'
);

var_dump($data);
39 changes: 37 additions & 2 deletions src/API_v1_0.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,43 @@
namespace MySportsFeeds;

class API_v1_0 extends BaseApi {
protected function getBaseUrlForVersion($version)

# Constructor
public function __construct($version, $verbose, $storeType = null, $storeLocation = null) {
$this->validFeeds = [
'seasonal_games',
'daily_games',
'weekly_games',
'seasonal_dfs',
'daily_dfs',
'weekly_dfs',
'seasonal_player_gamelogs',
'daily_player_gamelogs',
'weekly_player_gamelogs',
'seasonal_team_gamelogs',
'daily_team_gamelogs',
'weekly_team_gamelogs',
'game_boxscore',
'game_playbyplay',
'game_lineup',
'current_season',
'player_injuries',
'latest_updates',
'seasonal_team_stats',
'seasonal_player_stats',
'seasonal_venues',
'players',
'seasonal_standings'
];
}

protected function __determineUrl($league, $season, $feed, $output, $params)
{
return "https://api.mysportsfeeds.com/v1.0/pull";
if ( $feed == 'current_season' ) {
return $this->baseUrl . "/" . $league . "/" . $feed . "." . $outputFormat;
} else {
return $this->baseUrl . "/" . $league . "/" . $season . "/" . $feed . "." . $outputFormat;
}
}

}
6 changes: 1 addition & 5 deletions src/API_v1_1.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,5 @@

namespace MySportsFeeds;

class API_v1_1 extends BaseApi {
protected function getBaseUrlForVersion($version)
{
return "https://api.mysportsfeeds.com/v1.1/pull";
}
class API_v1_1 extends API_v1_0 {
}
6 changes: 1 addition & 5 deletions src/API_v1_2.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,5 @@

namespace MySportsFeeds;

class API_v1_2 extends BaseApi {
protected function getBaseUrlForVersion($version)
{
return "https://api.mysportsfeeds.com/v1.2/pull";
}
class API_v1_2 extends API_v1_1 {
}
Loading

0 comments on commit 9f958c9

Please sign in to comment.