@@ 21-73 (lines=53) @@ | ||
18 | use Core23\SetlistFm\Model\Artist; |
|
19 | use Core23\SetlistFm\Model\ArtistSearchResult; |
|
20 | ||
21 | final class ArtistService |
|
22 | { |
|
23 | /** |
|
24 | * @var ConnectionInterface |
|
25 | */ |
|
26 | private $connection; |
|
27 | ||
28 | public function __construct(ConnectionInterface $connection) |
|
29 | { |
|
30 | $this->connection = $connection; |
|
31 | } |
|
32 | ||
33 | /** |
|
34 | * Get the metadata for an artist. |
|
35 | * |
|
36 | * @throws ApiException |
|
37 | * @throws NotFoundException |
|
38 | */ |
|
39 | public function getArtist(string $mbid): Artist |
|
40 | { |
|
41 | return Artist::fromApi( |
|
42 | $this->connection->call('artist/'.$mbid) |
|
43 | ); |
|
44 | } |
|
45 | ||
46 | /** |
|
47 | * Search for artists. |
|
48 | * |
|
49 | * @throws ApiException |
|
50 | * @throws NotFoundException |
|
51 | */ |
|
52 | public function search(ArtistSearchBuilder $builder): ArtistSearchResult |
|
53 | { |
|
54 | $response = $this->connection->call('search/artists', $builder->getQuery()); |
|
55 | ||
56 | if (!\array_key_exists('artist', $response)) { |
|
57 | return ArtistSearchResult::createEmpty(); |
|
58 | } |
|
59 | ||
60 | return ArtistSearchResult::fromApi($response); |
|
61 | } |
|
62 | } |
|
63 |
@@ 21-73 (lines=53) @@ | ||
18 | use Core23\SetlistFm\Model\City; |
|
19 | use Core23\SetlistFm\Model\CitySearchResult; |
|
20 | ||
21 | final class CityService |
|
22 | { |
|
23 | /** |
|
24 | * @var ConnectionInterface |
|
25 | */ |
|
26 | private $connection; |
|
27 | ||
28 | public function __construct(ConnectionInterface $connection) |
|
29 | { |
|
30 | $this->connection = $connection; |
|
31 | } |
|
32 | ||
33 | /** |
|
34 | * Get the city data for an id. |
|
35 | * |
|
36 | * @throws ApiException |
|
37 | * @throws NotFoundException |
|
38 | */ |
|
39 | public function getCity(int $cityId): City |
|
40 | { |
|
41 | return City::fromApi( |
|
42 | $this->connection->call('city/'.$cityId) |
|
43 | ); |
|
44 | } |
|
45 | ||
46 | /** |
|
47 | * Search for cities. |
|
48 | * |
|
49 | * @throws ApiException |
|
50 | * @throws NotFoundException |
|
51 | */ |
|
52 | public function search(CitySearchBuilder $builder): CitySearchResult |
|
53 | { |
|
54 | $response = $this->connection->call('search/cities', $builder->getQuery()); |
|
55 | ||
56 | if (!\array_key_exists('cities', $response)) { |
|
57 | return CitySearchResult::createEmpty(); |
|
58 | } |
|
59 | ||
60 | return CitySearchResult::fromApi($response); |
|
61 | } |
|
62 | } |
|
63 |
@@ 21-73 (lines=53) @@ | ||
18 | use Core23\SetlistFm\Model\Venue; |
|
19 | use Core23\SetlistFm\Model\VenueSearchResult; |
|
20 | ||
21 | final class VenueService |
|
22 | { |
|
23 | /** |
|
24 | * @var ConnectionInterface |
|
25 | */ |
|
26 | private $connection; |
|
27 | ||
28 | public function __construct(ConnectionInterface $connection) |
|
29 | { |
|
30 | $this->connection = $connection; |
|
31 | } |
|
32 | ||
33 | /** |
|
34 | * Get the metadata for an artist. |
|
35 | * |
|
36 | * @throws ApiException |
|
37 | * @throws NotFoundException |
|
38 | */ |
|
39 | public function getVenue(string $venueId): Venue |
|
40 | { |
|
41 | return Venue::fromApi( |
|
42 | $this->connection->call('venue/'.$venueId) |
|
43 | ); |
|
44 | } |
|
45 | ||
46 | /** |
|
47 | * Search for venues. |
|
48 | * |
|
49 | * @throws ApiException |
|
50 | * @throws NotFoundException |
|
51 | */ |
|
52 | public function search(VenueSearchBuilder $builder): VenueSearchResult |
|
53 | { |
|
54 | $response = $this->connection->call('search/venues', $builder->getQuery()); |
|
55 | ||
56 | if (!\array_key_exists('venue', $response)) { |
|
57 | return VenueSearchResult::createEmpty(); |
|
58 | } |
|
59 | ||
60 | return VenueSearchResult::fromApi($response); |
|
61 | } |
|
62 | } |
|
63 |