|
1
|
|
|
<?php |
|
2
|
|
|
namespace Sourceout\LastFm\Providers\LastFm\Resources; |
|
3
|
|
|
|
|
4
|
|
|
use Sourceout\LastFm\Http\Response; |
|
5
|
|
|
use Sourceout\LastFm\Http\HttpInterface; |
|
6
|
|
|
use Sourceout\LastFm\Providers\GeoInterface; |
|
7
|
|
|
use Sourceout\LastFm\Providers\ProviderInterface; |
|
8
|
|
|
use Sourceout\LastFm\Providers\LastFm\Exception\LastFmException; |
|
9
|
|
|
|
|
10
|
|
|
class Geo implements GeoInterface |
|
11
|
|
|
{ |
|
12
|
|
|
const TOP_ARTISTS_URI = "http://ws.audioscrobbler.com/2.0/"; |
|
13
|
|
|
const TOP_TRACKS_URI = "http://ws.audioscrobbler.com/2.0/"; |
|
14
|
|
|
|
|
15
|
|
|
/** @var HttpInterface */ |
|
16
|
|
|
private $http; |
|
17
|
|
|
|
|
18
|
|
|
/** @var ProviderInterface */ |
|
19
|
|
|
private $provider; |
|
20
|
|
|
|
|
21
|
|
|
/** @var string */ |
|
22
|
|
|
private $format; |
|
23
|
|
|
|
|
24
|
|
|
/** |
|
25
|
|
|
* Constructor for Geo Class |
|
26
|
|
|
* |
|
27
|
|
|
* @param ProviderInterface $provider |
|
28
|
|
|
* @param HttpInterface $http |
|
29
|
|
|
* @param string $format |
|
30
|
|
|
* @todo Support for $format is yet not enabled, add that in future |
|
31
|
|
|
*/ |
|
32
|
5 |
|
public function __construct( |
|
33
|
|
|
ProviderInterface $provider, |
|
34
|
|
|
HttpInterface $http, |
|
35
|
|
|
$format = 'json' |
|
36
|
|
|
) { |
|
37
|
5 |
|
$this->http = $http; |
|
38
|
5 |
|
$this->provider = $provider; |
|
39
|
5 |
|
$this->format = $format; |
|
40
|
5 |
|
} |
|
41
|
|
|
|
|
42
|
|
|
/** @inheritDoc */ |
|
43
|
2 |
|
public function getTopArtists( |
|
44
|
|
|
string $country, |
|
45
|
|
|
int $page = 1, |
|
46
|
|
|
int $limit = 50 |
|
47
|
|
|
) { |
|
48
|
|
|
try { |
|
49
|
2 |
|
$query = http_build_query( |
|
50
|
|
|
[ |
|
51
|
2 |
|
'method' => 'geo.gettopartists', |
|
52
|
2 |
|
'api_key' => $this->provider->getConfig()['api_key'], |
|
53
|
2 |
|
'country' => $country, |
|
54
|
2 |
|
'limit' => $limit, |
|
55
|
2 |
|
'page' => $page, |
|
56
|
2 |
|
'format' => 'json' |
|
57
|
|
|
] |
|
58
|
|
|
); |
|
59
|
2 |
|
$response = $this->http->sendRequest('GET', Geo::TOP_ARTISTS_URI, $query); |
|
|
|
|
|
|
60
|
1 |
|
return Response::send($response); |
|
61
|
1 |
|
} catch (\Exception $e) { |
|
62
|
1 |
|
throw new LastFmException($e->getMessage(), $e->getCode(), $e); |
|
63
|
|
|
} |
|
64
|
|
|
} |
|
65
|
|
|
|
|
66
|
|
|
/** @inheritDoc */ |
|
67
|
2 |
|
public function getTopTracks( |
|
68
|
|
|
string $country, |
|
69
|
|
|
string $location = null, |
|
70
|
|
|
int $limit = 50, |
|
71
|
|
|
int $page = 1 |
|
72
|
|
|
) { |
|
73
|
|
|
try { |
|
74
|
2 |
|
$query = http_build_query( |
|
75
|
|
|
[ |
|
76
|
2 |
|
'method' => 'geo.gettoptracks', |
|
77
|
2 |
|
'api_key' => $this->provider->getConfig()['api_key'], |
|
78
|
2 |
|
'country' => $country, |
|
79
|
2 |
|
'location' => $location, |
|
80
|
2 |
|
'limit' => $limit, |
|
81
|
2 |
|
'page' => $page, |
|
82
|
2 |
|
'format' => 'json' |
|
83
|
|
|
] |
|
84
|
|
|
); |
|
85
|
2 |
|
$response = $this->http->sendRequest('GET', Geo::TOP_TRACKS_URI, $query); |
|
|
|
|
|
|
86
|
1 |
|
return Response::send($response); |
|
87
|
1 |
|
} catch (\Exception $e) { |
|
88
|
1 |
|
throw new LastFmException($e->getMessage(), $e->getCode(), $e); |
|
89
|
|
|
} |
|
90
|
|
|
} |
|
91
|
|
|
} |