|
1
|
|
|
<?php |
|
2
|
|
|
/** |
|
3
|
|
|
* Created by PhpStorm. |
|
4
|
|
|
* User: thiago |
|
5
|
|
|
* Date: 31/03/18 |
|
6
|
|
|
* Time: 10:05 |
|
7
|
|
|
*/ |
|
8
|
|
|
|
|
9
|
|
|
namespace MyWonderland\Service; |
|
10
|
|
|
|
|
11
|
|
|
use MyWonderland\Domain\Model\Event; |
|
12
|
|
|
|
|
13
|
|
|
class SongkickService |
|
14
|
|
|
{ |
|
15
|
|
|
const BASE_URI = 'http://api.songkick.com/api/3.0'; |
|
16
|
|
|
|
|
17
|
|
|
|
|
18
|
|
|
/** |
|
19
|
|
|
* @var RequestService |
|
20
|
|
|
*/ |
|
21
|
|
|
protected $requestService; |
|
22
|
|
|
|
|
23
|
|
|
/** |
|
24
|
|
|
* SongkickService constructor. |
|
25
|
|
|
* @param RequestService $requestService |
|
26
|
|
|
*/ |
|
27
|
|
|
public function __construct(RequestService $requestService) |
|
28
|
|
|
{ |
|
29
|
|
|
$this->requestService = $requestService; |
|
30
|
|
|
} |
|
31
|
|
|
|
|
32
|
|
|
|
|
33
|
|
|
/** |
|
34
|
|
|
* @param $songkickApiKey |
|
35
|
|
|
* @param $name |
|
36
|
|
|
* @return mixed |
|
37
|
|
|
*/ |
|
38
|
|
|
public function getArtistIdByName($songkickApiKey, $name) |
|
39
|
|
|
{ |
|
40
|
|
|
$queryStringWOKey = '/search/artists.json' . |
|
41
|
|
|
'?per_page=1' . |
|
42
|
|
|
'&query=' . rawurlencode($name); |
|
43
|
|
|
$queryString = "$queryStringWOKey&apikey=$songkickApiKey"; |
|
44
|
|
|
$res = $this->requestService->requestContent('GET', |
|
45
|
|
|
self::BASE_URI . $queryString, [], $queryStringWOKey); |
|
46
|
|
|
|
|
47
|
|
|
// @todo check if resultsPage -> status is ok |
|
48
|
|
|
if ($res['resultsPage']['totalEntries'] === 0) { |
|
49
|
|
|
return null; |
|
50
|
|
|
} |
|
51
|
|
|
|
|
52
|
|
|
return $res['resultsPage']['results']['artist'][0]['id']; |
|
53
|
|
|
} |
|
54
|
|
|
|
|
55
|
|
|
|
|
56
|
|
|
/** |
|
57
|
|
|
* @param $songkickApiKey |
|
58
|
|
|
* @param $artistId |
|
59
|
|
|
* @return array |
|
60
|
|
|
*/ |
|
61
|
|
|
public function getArtistUpcomingEvents($songkickApiKey, $artistId) |
|
62
|
|
|
{ |
|
63
|
|
|
$queryStringWOKey = '/artists/' . $artistId . '/calendar.json'; |
|
64
|
|
|
$queryString = "$queryStringWOKey?apikey=$songkickApiKey"; |
|
65
|
|
|
$res = $this->requestService->requestContent('GET', |
|
66
|
|
|
self::BASE_URI . $queryString, [], $queryStringWOKey); |
|
67
|
|
|
|
|
68
|
|
|
// @todo check if resultsPage -> status is ok |
|
69
|
|
|
|
|
70
|
|
|
if (!isset($res['resultsPage']['results']['event'])) { |
|
71
|
|
|
return []; |
|
72
|
|
|
} |
|
73
|
|
|
|
|
74
|
|
|
$upcomingEvents = []; |
|
75
|
|
|
foreach ($res['resultsPage']['results']['event'] as $event) { |
|
76
|
|
|
$upcomingEvents[] = new Event( |
|
77
|
|
|
$event['venue']['metroArea']['displayName'], |
|
78
|
|
|
$event['venue']['metroArea']['country']['displayName'], |
|
79
|
|
|
isset($event['venue']['metroArea']['state']) ? $event['venue']['metroArea']['state']['displayName'] : null |
|
80
|
|
|
); |
|
81
|
|
|
} |
|
82
|
|
|
return $upcomingEvents; |
|
83
|
|
|
} |
|
84
|
|
|
} |