-
Notifications
You must be signed in to change notification settings - Fork 28
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
danijoo
committed
Jan 30, 2015
1 parent
c7162af
commit 462d6c4
Showing
11 changed files
with
1,146 additions
and
3 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
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
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 LeagueWrap\Api; | ||
use \LeagueWrap\Dto\CurrentGame as CurrentGameDto; | ||
|
||
/** | ||
* Spectator service endpoint | ||
*/ | ||
class CurrentGame extends AbstractApi | ||
{ | ||
|
||
/** | ||
* Valid version for this api call. | ||
* | ||
* @var array | ||
*/ | ||
protected $versions = ['v1.0']; | ||
|
||
/** | ||
* A list of all permitted regions for the league api call. | ||
* | ||
* @param array | ||
*/ | ||
protected $permittedRegions = [ | ||
'br', | ||
'eune', | ||
'euw', | ||
'lan', | ||
'las', | ||
'na', | ||
'oce', | ||
'ru', | ||
'tr', | ||
'kr', | ||
]; | ||
|
||
/** | ||
* @param platform ids for regions | ||
*/ | ||
protected $platformIds = [ | ||
'na' => 'NA1', | ||
'euw' => 'EUW1', | ||
'br' => 'BR1', | ||
'las' => 'LA1', | ||
'lan' => 'LA2', | ||
'oce' => 'OC1', | ||
'eune' => 'EUN1', | ||
'tr' => 'TR1', | ||
'ru' => 'RU', | ||
'kr' => 'KR' | ||
]; | ||
|
||
public function currentGame($identity) | ||
{ | ||
$summonerId = $this->extractId($identity); | ||
$info = $this->request('consumer/getSpectatorGameInfo/' . '%1$s' . '/' . $summonerId, [], false, true); | ||
$game = new CurrentGameDto($info); | ||
$game = $this->attachStaticDataToDto($game); | ||
|
||
$this->attachResponse($identity, $game, 'game'); | ||
|
||
return $game; | ||
} | ||
|
||
/** | ||
* Intercept client request to patch platform id into url (ugly hack!) | ||
*/ | ||
protected function clientRequest($static, $uri, $params) | ||
{ | ||
$uri = sprintf($uri, $this->platformIds[$this->region->getRegion()]); | ||
return parent::clientRequest($static, $uri, $params); | ||
} | ||
} |
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,10 @@ | ||
<?php | ||
|
||
|
||
namespace LeagueWrap\Dto; | ||
|
||
|
||
class CurrentGame extends AbstractDto | ||
{ | ||
// TODO implement subclasses | ||
} |
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
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,37 @@ | ||
<?php | ||
|
||
|
||
use LeagueWrap\Api; | ||
use Mockery as m; | ||
|
||
class CurrentGameTest extends PHPUnit_Framework_TestCase | ||
{ | ||
protected $client; | ||
|
||
public function setUp() | ||
{ | ||
$client = m::mock('LeagueWrap\Client'); | ||
$this->client = $client; | ||
} | ||
|
||
public function tearDown() | ||
{ | ||
m::close(); | ||
} | ||
|
||
public function testCurrentGame() | ||
{ | ||
$this->client->shouldReceive('baseUrl') | ||
->once(); | ||
$this->client->shouldReceive('request') | ||
->with('consumer/getSpectatorGameInfo/EUW1/30447079', [ | ||
'api_key' => 'key', | ||
])->once() | ||
->andReturn(file_get_contents('tests/Json/currentgame.30447079.json')); | ||
|
||
$api = new Api('key', $this->client); | ||
$api->setRegion('euw'); | ||
$game = $api->currentGame()->currentGame(30447079); | ||
$this->assertTrue($game instanceof LeagueWrap\Dto\CurrentGame); | ||
} | ||
} |
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
Oops, something went wrong.