-
-
Notifications
You must be signed in to change notification settings - Fork 9
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
Showing
17 changed files
with
404 additions
and
451 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,16 @@ | ||
<?php | ||
|
||
namespace App\Apis; | ||
|
||
use Illuminate\Support\Collection; | ||
|
||
class BasketballApi extends LiveScoresApi | ||
{ | ||
public function makeRequest(): Collection | ||
{ | ||
return $this->client() | ||
->get('/basketball/1.00?MD=1') | ||
->throw() | ||
->collect(); | ||
} | ||
} |
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,16 @@ | ||
<?php | ||
|
||
namespace App\Apis; | ||
|
||
use Illuminate\Support\Collection; | ||
|
||
class FootballApi extends LiveScoresApi | ||
{ | ||
public function makeRequest(): Collection | ||
{ | ||
return $this->client() | ||
->get('/soccer/1.00?MD=1') | ||
->throw() | ||
->collect(); | ||
} | ||
} |
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,53 @@ | ||
<?php | ||
|
||
namespace App\Apis; | ||
|
||
use App\Contracts\ScoresApi; | ||
use Illuminate\Http\Client\Factory; | ||
use Illuminate\Http\Client\PendingRequest; | ||
use Illuminate\Support\Collection; | ||
|
||
abstract class LiveScoresApi implements ScoresApi | ||
{ | ||
public function __construct( | ||
private Factory $client = new Factory(), | ||
private string $baseUrl = 'https://prod-public-api.livescore.com/v1/api/app/live', | ||
) { | ||
// .. | ||
} | ||
|
||
public function fetch(): Collection | ||
{ | ||
return collect($this->makeRequest()->get('Stages'))->map(fn ($league) => [ | ||
'category' => $league['Cnm'], | ||
'stage' => $league['Snm'], | ||
'games' => collect($league['Events'])->map(fn ($event) => [ | ||
'time' => $event['Eps'], | ||
'team_1' => [ | ||
'name' => $event['T1']['0']['Nm'], | ||
'score' => $event['Tr1'] ?? '0', | ||
], | ||
'team_2' => [ | ||
'name' => $event['T2']['0']['Nm'], | ||
'score' => $event['Tr2'] ?? '0', | ||
], | ||
]), | ||
]); | ||
} | ||
|
||
public function makeRequest(): Collection | ||
{ | ||
return $this->client() | ||
->get('/soccer/1.00?MD=1') | ||
->throw() | ||
->collect(); | ||
} | ||
|
||
protected function client(): PendingRequest | ||
{ | ||
return $this->client | ||
->baseUrl($this->baseUrl) | ||
->asJson() | ||
->acceptJson(); | ||
} | ||
} |
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,10 @@ | ||
<?php | ||
|
||
namespace App\Contracts; | ||
|
||
use Illuminate\Support\Collection; | ||
|
||
interface ScoresApi | ||
{ | ||
public function fetch(): Collection; | ||
} |
This file was deleted.
Oops, something went wrong.
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.