-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit b94f3d2
Showing
9 changed files
with
351 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
vendor/ | ||
composer.lock |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
NatocTo/FootballData | ||
====== | ||
|
||
Nette basic integration of football-data.org's API. | ||
|
||
Installation | ||
------------ | ||
|
||
The best way to install NatocTo/FootballData is using the [Composer](http://getcomposer.org/) | ||
|
||
```sh | ||
$ composer require natocto/football-data | ||
``` | ||
|
||
and you can enable the extension using your neon config | ||
|
||
```yml | ||
extensions: | ||
footballData: NatocTo\FootballData\DI\FootballDataExtension | ||
``` | ||
|
||
if you want increase your rate limit from 50 requests per day to 50 requests per minute you can get your free token from [football-data.org](http://football-data.org/register) | ||
|
||
```yml | ||
footballData: | ||
authToken: 'YOUR-TOKEN' | ||
``` | ||
|
||
|
||
Documentation | ||
------------ | ||
|
||
There is no documentation. Just look to source code if you are interested. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
{ | ||
"name": "natocto/football-data", | ||
"description": "Nette integration of football-data.org's API.", | ||
"keywords": ["Football fixtures, Football data, Football results"], | ||
"license": "MIT", | ||
"authors": [ | ||
{ | ||
"name": "Jakub Kotek", | ||
"homepage": "http://jakubkotek.cz", | ||
"email": "info@jakubkotek.cz" | ||
} | ||
], | ||
"require": { | ||
"nette/di": "^2.3.0", | ||
"guzzlehttp/guzzle": "^6.2" | ||
}, | ||
"autoload": { | ||
"psr-4": { | ||
"NatocTo\\FootballData\\": "src/" | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
<?php | ||
|
||
namespace NatocTo\FootballData; | ||
|
||
use GuzzleHttp\Client; | ||
|
||
class Content { | ||
|
||
private $authToken; | ||
|
||
private $client; | ||
|
||
public function __construct($authToken) { | ||
|
||
$this->authToken = $authToken; | ||
|
||
$this->client = new Client(['base_uri' => 'http://api.football-data.org/v1/',]); | ||
} | ||
|
||
|
||
public function fetch($resource) | ||
{ | ||
$response = $this->client->get($resource, ['headers' => ['X-Auth-Token' => $this->authToken]]); | ||
|
||
return json_decode($response->getBody()); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
<?php | ||
|
||
namespace NatocTo\FootballData\DI; | ||
|
||
use Nette; | ||
use NatocTo; | ||
use Exception; | ||
|
||
class FootballDataExtension extends Nette\DI\CompilerExtension | ||
{ | ||
public $defaults = [ | ||
'authToken' => '' | ||
]; | ||
|
||
public function loadConfiguration() | ||
{ | ||
$config = $this->getConfig($this->defaults); | ||
|
||
$builder = $this->getContainerBuilder(); | ||
|
||
$builder->addDefinition($this->prefix('content')) | ||
->setClass(NatocTo\FootballData\Content::class, [$config['authToken']]); | ||
|
||
$builder->addDefinition($this->prefix('default')) | ||
->setClass(NatocTo\FootballData\FootballData::class, [$this->prefix('@content')]); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,104 @@ | ||
<?php | ||
|
||
namespace NatocTo\FootballData; | ||
|
||
use NatocTo\FootballData\Model; | ||
|
||
class FootballData { | ||
|
||
private $content; | ||
|
||
public function __construct(Content $content) | ||
{ | ||
$this->content = $content; | ||
} | ||
|
||
|
||
/** | ||
* Function returns a specific soccer season identified by an id. | ||
* | ||
* @param int $id | ||
* @return NatocTo\FootballData\Model\SoccerSeason | ||
*/ | ||
public function getSeason($id) { | ||
|
||
$resource = 'soccerseasons/' . $id; | ||
|
||
$response = $this->content->fetch($resource); | ||
|
||
return new Model\Soccerseason($this->content, $response); | ||
} | ||
|
||
|
||
/** | ||
* Function returns one unique team identified by a given id. | ||
* | ||
* @param int $id | ||
* @return NatocTo\FootballData\Model\Team | ||
*/ | ||
public function getTeam($id) { | ||
|
||
$resource = 'teams/' . $id; | ||
|
||
$response = $this->content->fetch($resource); | ||
|
||
return new Model\Team($this->content, $response); | ||
} | ||
|
||
|
||
/** | ||
* Function returns a specific soccer seasons identified by an year. | ||
* | ||
* @param int $id | ||
* @return NatocTo\FootballData\Model\SoccerSeason | ||
*/ | ||
public function getSeasonsByYear($year) { | ||
|
||
$resource = 'soccerseasons/?season=' . $year; | ||
|
||
return $this->content->fetch($resource); | ||
} | ||
|
||
|
||
/** | ||
* Function returns all available fixtures for a given date range. | ||
* | ||
* @param DateString 'Y-m-d' $start | ||
* @param DateString 'Y-m-d' $end | ||
* @return array - list of fixtures | ||
*/ | ||
public function getFixtures($start, $end) { | ||
|
||
$resource = 'fixtures/?timeFrameStart=' . $start . '&timeFrameEnd=' . $end; | ||
|
||
return $this->content->fetch($resource); | ||
} | ||
|
||
|
||
/** | ||
* Function returns one unique fixture identified by a given id. | ||
* | ||
* @param int $id | ||
* @return stdObject | ||
*/ | ||
public function getFixture($id) { | ||
|
||
$resource = 'fixtures/' . $id; | ||
|
||
return $this->content->fetch($resource); | ||
} | ||
|
||
|
||
/** | ||
* Function returns all teams matching a given keyword. | ||
* | ||
* @param string $keyword | ||
* @return array - list of teams | ||
*/ | ||
public function searchTeam($keyword) { | ||
|
||
$resource = 'teams/?name=' . urlencode($keyword); | ||
|
||
return $this->content->fetch($resource); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
<?php | ||
|
||
namespace NatocTo\FootballData\Model; | ||
|
||
use NatocTo\FootballData\Content; | ||
|
||
abstract class BaseModel { | ||
|
||
protected $content; | ||
|
||
public function __construct(Content $content) { | ||
|
||
$this->content = $content; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
<?php | ||
|
||
namespace NatocTo\FootballData\Model; | ||
|
||
use NatocTo\FootballData\Content; | ||
|
||
class Soccerseason extends BaseModel { | ||
|
||
private $payload; | ||
|
||
public function __construct(Content $content, $payload) | ||
{ | ||
parent::__construct($content); | ||
|
||
$this->payload = $payload; | ||
} | ||
|
||
|
||
/** | ||
* Function returns all fixtures for the instantiated soccerseason. | ||
* | ||
* @return array of fixture objects | ||
*/ | ||
public function getFixtures() { | ||
|
||
$uri = $this->payload->_links->fixtures->href; | ||
|
||
return $this->content->fetch($uri); | ||
} | ||
|
||
|
||
/** | ||
* Function returns all fixtures for a given matchday. | ||
* | ||
* @param type $matchday | ||
* @return array of fixture objects | ||
*/ | ||
public function getFixturesByMatchday($matchday = 1) { | ||
|
||
$uri = $this->payload->_links->fixtures->href . '/?matchday=' . $matchday; | ||
|
||
$response = $this->content->fetch($uri); | ||
|
||
return $response->fixtures; | ||
} | ||
|
||
|
||
/** | ||
* Function returns all teams participating in the instantiated soccerseason. | ||
* | ||
* @return array of team objects | ||
*/ | ||
public function getTeams() { | ||
|
||
$uri = $this->payload->_links->teams->href; | ||
|
||
$response = $this->content->fetch($uri); | ||
|
||
return $response->teams; | ||
} | ||
|
||
|
||
/** | ||
* Function returns the current league table for the instantiated soccerseason. | ||
* | ||
* @return object leagueTable | ||
*/ | ||
public function getTable() { | ||
|
||
$uri = $this->payload->_links->leagueTable->href; | ||
|
||
return $this->content->fetch($uri); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
<?php | ||
|
||
namespace NatocTo\FootballData\Model; | ||
|
||
use NatocTo\FootballData\Content; | ||
|
||
class Team extends BaseModel { | ||
|
||
private $payload; | ||
|
||
public function __construct(Content $content, $payload) | ||
{ | ||
parent::__construct($content); | ||
|
||
$this->payload = $payload; | ||
} | ||
|
||
|
||
/** | ||
* Function returns all fixtures for the team for this season. | ||
* | ||
* @param string $venue | ||
* @param string $timeFrame | ||
* @return array of stdObjects representing fixtures | ||
*/ | ||
public function getFixtures($venue = "", $timeFrame = "") { | ||
|
||
$uri = $this->payload->_links->fixtures->href . '/?venue=' . $venue . '&timeFrame=' . $timeFrame; | ||
|
||
return $this->content->fetch($uri); | ||
} | ||
|
||
|
||
/** | ||
* Function returns all players of the team | ||
* | ||
* @return array of fixture objects | ||
*/ | ||
public function getPlayers() { | ||
|
||
$uri = $this->payload->_links->players->href; | ||
|
||
$response = $this->content->fetch($uri); | ||
|
||
return $response->players; | ||
} | ||
} |