Skip to content

Commit

Permalink
Merge pull request #61 from programmatordev/SPA-69-create-timezone-en…
Browse files Browse the repository at this point in the history
…dpoint

Create Timezone endpoint
  • Loading branch information
andrepimpao authored Nov 20, 2023
2 parents 2c95911 + a3e7a61 commit 64badad
Show file tree
Hide file tree
Showing 41 changed files with 213 additions and 341 deletions.
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"name": "programmatordev/sportmonksfootball-php-api",
"description": "SportMonksFootball PHP library that provides convenient access to the SportMonks Football API",
"type": "library",
"keywords": ["SportMonksFootball", "SportMonks", "Football", "API", "PHP", "PHP8", "SDK", "PSR-18", "PSR-17", "PSR-6", "PSR-3"],
"keywords": ["sportmonks", "football", "api", "sportmonks-football-api", "football-api", "php", "php8", "psr-18", "psr-17", "psr-6", "psr-3"],
"license": "MIT",
"authors": [
{
Expand Down
22 changes: 22 additions & 0 deletions docs/03-supported-endpoints.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
- [Countries](#countries)
- [Filters](#filters)
- [Regions](#regions)
- [Timezones](#timezones)
- [Types](#types)
- [Select, Include and Filters](#select-include-and-filters)
- [withSelect](#withselect)
Expand Down Expand Up @@ -2139,6 +2140,27 @@ foreach ($regions->getData() as $region) {
}
```

### Timezones

- [Official documentation](https://docs.sportmonks.com/football/v/core-api/endpoints/timezones)
- Cache default max age: `1 day`

#### `getAll`

```php
getAll(): TimezoneCollection
```

Get all timezones:

```php
$timezones = $sportMonksFootball->timezones()->getAll();

foreach ($timezones->getData() as $timezone) {
echo $timezone;
}
```

### Types

- [Official documentation](https://docs.sportmonks.com/football/v/core-api/endpoints/types)
Expand Down
26 changes: 26 additions & 0 deletions src/Endpoint/TimezoneEndpoint.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
<?php

namespace ProgrammatorDev\SportMonksFootball\Endpoint;

use Http\Client\Exception;
use ProgrammatorDev\SportMonksFootball\Entity\Response\TimezoneCollection;
use ProgrammatorDev\SportMonksFootball\Exception\ApiErrorException;

class TimezoneEndpoint extends AbstractEndpoint
{
protected int $cacheTtl = 3600 * 24; // 1 day

/**
* @throws Exception
* @throws ApiErrorException
*/
public function getAll(): TimezoneCollection
{
$response = $this->sendRequest(
method: 'GET',
path: '/v3/core/timezones'
);

return new TimezoneCollection($response);
}
}
1 change: 0 additions & 1 deletion src/Endpoint/Util/TimezoneTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
use ProgrammatorDev\YetAnotherPhpValidator\Exception\ValidationException;
use ProgrammatorDev\YetAnotherPhpValidator\Validator;

// TODO create tests for trait upon implementation of an endpoint that makes use of it
trait TimezoneTrait
{
/**
Expand Down
21 changes: 21 additions & 0 deletions src/Entity/Response/TimezoneCollection.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
<?php

namespace ProgrammatorDev\SportMonksFootball\Entity\Response;

class TimezoneCollection extends AbstractCollectionResponse
{
/** @var string[] */
private array $data;

public function __construct(array $response)
{
parent::__construct($response);

$this->data = $response['data'];
}

public function getData(): array
{
return $this->data;
}
}
6 changes: 6 additions & 0 deletions src/SportMonksFootball.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
use ProgrammatorDev\SportMonksFootball\Endpoint\StatisticEndpoint;
use ProgrammatorDev\SportMonksFootball\Endpoint\TeamEndpoint;
use ProgrammatorDev\SportMonksFootball\Endpoint\TeamSquadEndpoint;
use ProgrammatorDev\SportMonksFootball\Endpoint\TimezoneEndpoint;
use ProgrammatorDev\SportMonksFootball\Endpoint\TopscorerEndpoint;
use ProgrammatorDev\SportMonksFootball\Endpoint\TransferEndpoint;
use ProgrammatorDev\SportMonksFootball\Endpoint\TvStationEndpoint;
Expand Down Expand Up @@ -167,6 +168,11 @@ public function teamSquads(): TeamSquadEndpoint
return new TeamSquadEndpoint($this);
}

public function timezones(): TimezoneEndpoint
{
return new TimezoneEndpoint($this);
}

public function topscorers(): TopscorerEndpoint
{
return new TopscorerEndpoint($this);
Expand Down
2 changes: 2 additions & 0 deletions src/Test/MockResponse.php
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,8 @@ class MockResponse

public const TEAM_SQUAD_COLLECTION_DATA = '[{"id":741301,"transfer_id":233006,"player_id":8056287,"team_id":53,"position_id":25,"detailed_position_id":148,"start":"2023-07-26","end":"2028-05-31","captain":false,"jersey_number":17},{"id":762227,"transfer_id":234932,"player_id":3533334,"team_id":53,"position_id":25,"detailed_position_id":148,"start":"2023-08-16","end":"2028-05-31","captain":false,"jersey_number":4}]';

public const TIMEZONE_COLLECTION_DATA = '["Africa\/Abidjan","Africa\/Accra","Africa\/Addis_Ababa"]';

public const TOPSCORER_COLLECTION_DATA = '[{"id":1540882,"season_id":19735,"player_id":37305554,"type_id":83,"position":1,"total":3,"participant_id":246},{"id":1540879,"season_id":19735,"player_id":1494374,"type_id":83,"position":2,"total":3,"participant_id":314}]';

public const TRANSFER_ITEM_DATA = '{"id":1,"sport_id":1,"player_id":35659846,"type_id":219,"from_team_id":148048,"to_team_id":3736,"position_id":25,"detailed_position_id":154,"date":"2021-12-27","career_ended":false,"completed":true,"amount":909000}';
Expand Down
16 changes: 4 additions & 12 deletions tests/BookmakerEndpointTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,7 @@ public static function provideEndpointItemResponseData(): \Generator
MockResponse::BOOKMAKER_ITEM_DATA,
'bookmakers',
'getById',
[1],
Bookmaker::class,
'assertResponse'
[1]
];
}

Expand All @@ -33,25 +31,19 @@ public static function provideEndpointCollectionResponseData(): \Generator
MockResponse::BOOKMAKER_COLLECTION_DATA,
'bookmakers',
'getAll',
[],
Bookmaker::class,
'assertResponse'
[]
];
yield 'get all by fixture id' => [
MockResponse::BOOKMAKER_COLLECTION_DATA,
'bookmakers',
'getAllByFixtureId',
[1],
Bookmaker::class,
'assertResponse'
[1]
];
yield 'get all by search query' => [
MockResponse::BOOKMAKER_COLLECTION_DATA,
'bookmakers',
'getAllBySearchQuery',
['test'],
Bookmaker::class,
'assertResponse'
['test']
];
}

Expand Down
12 changes: 3 additions & 9 deletions tests/CityEndpointTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,7 @@ public static function provideEndpointItemResponseData(): \Generator
MockResponse::CITY_ITEM_DATA,
'cities',
'getById',
[1],
City::class,
'assertResponse'
[1]
];
}

Expand All @@ -33,17 +31,13 @@ public static function provideEndpointCollectionResponseData(): \Generator
MockResponse::CITY_COLLECTION_DATA,
'cities',
'getAll',
[],
City::class,
'assertResponse'
[]
];
yield 'get all by search query' => [
MockResponse::CITY_COLLECTION_DATA,
'cities',
'getAllBySearchQuery',
['test'],
City::class,
'assertResponse'
['test']
];
}

Expand Down
20 changes: 5 additions & 15 deletions tests/CoachEndpointTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,7 @@ public static function provideEndpointItemResponseData(): \Generator
MockResponse::COACH_ITEM_DATA,
'coaches',
'getById',
[1],
Coach::class,
'assertResponse'
[1]
];
}

Expand All @@ -33,33 +31,25 @@ public static function provideEndpointCollectionResponseData(): \Generator
MockResponse::COACH_COLLECTION_DATA,
'coaches',
'getAll',
[],
Coach::class,
'assertResponse'
[]
];
yield 'get all by country id' => [
MockResponse::COACH_COLLECTION_DATA,
'coaches',
'getAllByCountryId',
[1],
Coach::class,
'assertResponse'
[1]
];
yield 'get all by search query' => [
MockResponse::COACH_COLLECTION_DATA,
'coaches',
'getAllBySearchQuery',
['test'],
Coach::class,
'assertResponse'
['test']
];
yield 'get all last updated' => [
MockResponse::COACH_COLLECTION_DATA,
'coaches',
'getAllLastUpdated',
[],
Coach::class,
'assertResponse'
[]
];
}

Expand Down
8 changes: 2 additions & 6 deletions tests/CommentaryEndpointTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,17 +17,13 @@ public static function provideEndpointCollectionResponseData(): \Generator
MockResponse::COMMENTARY_COLLECTION_DATA,
'commentaries',
'getAll',
[],
Commentary::class,
'assertResponse'
[]
];
yield 'get all by fixture id' => [
MockResponse::COMMENTARY_COLLECTION_DATA,
'commentaries',
'getAllByFixtureId',
[1],
Commentary::class,
'assertResponse'
[1]
];
}

Expand Down
8 changes: 2 additions & 6 deletions tests/ContinentEndpointTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,7 @@ public static function provideEndpointItemResponseData(): \Generator
MockResponse::CONTINENT_ITEM_DATA,
'continents',
'getById',
[1],
Continent::class,
'assertResponse'
[1]
];
}

Expand All @@ -31,9 +29,7 @@ public static function provideEndpointCollectionResponseData(): \Generator
MockResponse::CONTINENT_COLLECTION_DATA,
'continents',
'getAll',
[],
Continent::class,
'assertResponse'
[]
];
}

Expand Down
12 changes: 3 additions & 9 deletions tests/CountryEndpointTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,7 @@ public static function provideEndpointItemResponseData(): \Generator
MockResponse::COUNTRY_ITEM_DATA,
'countries',
'getById',
[1],
Country::class,
'assertResponse'
[1]
];
}

Expand All @@ -33,17 +31,13 @@ public static function provideEndpointCollectionResponseData(): \Generator
MockResponse::COUNTRY_COLLECTION_DATA,
'countries',
'getAll',
[],
Country::class,
'assertResponse'
[]
];
yield 'get all by search query' => [
MockResponse::COUNTRY_COLLECTION_DATA,
'countries',
'getAllBySearchQuery',
['test'],
Country::class,
'assertResponse'
['test']
];
}

Expand Down
4 changes: 1 addition & 3 deletions tests/FilterEndpointTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,7 @@ public static function provideEndpointCollectionResponseData(): \Generator
MockResponse::FILTER_ENTITY_COLLECTION_DATA,
'filters',
'getAllByEntity',
[],
FilterEntity::class,
'assertResponse'
[]
];
}

Expand Down
Loading

0 comments on commit 64badad

Please sign in to comment.