This is a simple PHP SDK for interacting with the CFL API. All API documentation can be found at http://api.cfl.ca.
composer install christohill/cfl-api-php dev-master
Note: none of the API keys below are valid
You can request access to the API at api.cfl.ca/key-request
All endpoints in the API are mapped to their own methods in the wrapper. You can see all the method names below. There is also a folder full of examples to reference.
use CFLPHP\Teams\Teams;
$teams = new Teams();
$teams->setKey('edf59be9216e66eb17093574376d4c5f');
$data = $teams->getTeams();There are a few ways to set an API key.
- Set an .env variable (CFLPHP_Key):
CFLPHP_Key="edf59be9216e66eb17093574376d4c5f" - Set as an argument to the constructor:
$teams = new Teams('edf59be9216e66eb17093574376d4c5f') - Use
setKeysetter method after the class has been instantiated:
$teams = new Teams();
$teams->setKey('edf59be9216e66eb17093574376d4c5f');Most methods/endpoints accept some sort of configuration (include, sort, filter, pagination). Refer to method names below to see which accept these. These are set as a multidimensional array like this:
$config = array(
'include' => array(),
'sort' => array(),
'filter' => array(),
'pagination' => array()
);
$teams = new Games();
$data = $teams->getGames(2015, $config);There is some special formatting for each config type:
The API accepts comma separated values, so just a simple array will work for this:
$config = array(
'include' => array(
'boxscore',
'rosters'
)
);The API accepts comma separated values, so just a simple array will work for this:
$config = array(
'sort' => array(
'height',
'-weight'
)
);Note: Using - in front of the sort term will reverse the order
The API can accept multiple filters to try and narrow down the data you need. There is a slight change here from the original API to help keep these filters legible.
$config = array(
'filter' => array(
"team_2 == TOR",
"team_1 == HAM"
)
);Instead of using the [property][operator] format, the wrapper uses simple strings with PHP style operators. The operators are as follows:
'==' => 'eq'
'!=' => 'ne'
'>' => 'gt'
'<' => 'lt'
'>=' => 'ge'
'<=' => 'le'
'in' => 'in'See how the operators work here
Pagination is as simple as passing a page number and size to the config array.
$config = array(
'pagination' => array(
'number' => 2,
'size' => 15
)
);| Method | Description | Docs |
|---|---|---|
| getGames($season, $config) | Get a list of all games in a particular season | Read docs |
| getSingleGame($season, $gameID, $config) | Get data for a specific game | Read docs |
| getLeaders($season, $category, $config) | Get a list of leaders based on a statistical category | Read docs |
| getTeamLeaders($season, $category, $config) | Get a list of team leaders based on a statistical category | Read docs |
| getPlayers($config) | Get a list of all players | Read docs |
| getSinglePlayer($player_id, $config) | Get all data for a specific player | Read docs |
| getStandings($season) | Get the team standings for a given season | Read docs |
| getCrossoverStandings($season) | Get the crossover team standings for a given season | Read docs |
| getTeams | Get a list of all teams | Read docs |
| getTeamByID($team_id) | Get a CFL team by unique ID | N/A |
| getTeamByAbbr($abbreviation) | Get a CFL team by team abbreviation | N/A |
- Finish all examples
- Add a helper class for converting property ID to string. ie: Position ID > Position name
- Play-by-play