-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #16 from benrowe/releases/build-4
Releases/build 4
- Loading branch information
Showing
31 changed files
with
566 additions
and
53 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 |
---|---|---|
@@ -1,4 +1,5 @@ | ||
APP_ENV=dev | ||
|
||
LASTFM_KEY= | ||
LASTFM_SECRET= | ||
LASTFM_SECRET= | ||
LASTFM_PAGINATION_LIMIT=5 |
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 |
---|---|---|
@@ -1,3 +1,4 @@ | ||
/vendor/ | ||
.env | ||
.idea | ||
.idea | ||
/storage/views/ |
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,28 @@ | ||
<?php | ||
|
||
namespace App\Http\Controllers; | ||
|
||
use App\Exceptions\HttpException; | ||
use App\Services\LastFm\Response\Artist; | ||
|
||
class ArtistController extends AbstractController | ||
{ | ||
public function actionView($id) | ||
{ | ||
return $this->view('artist', ['artist' => $this->getModel($id)]); | ||
} | ||
|
||
/** | ||
* @param string $id | ||
* @return Artist | ||
* @throws HttpException | ||
*/ | ||
private function getModel($id) | ||
{ | ||
$model = \App\app()->get('lastfm')->artist->find($id); | ||
if (!$model) { | ||
throw new HttpException('Artist not found', 404); | ||
} | ||
return $model; | ||
} | ||
} |
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
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,52 @@ | ||
<?php | ||
|
||
namespace App\Models; | ||
|
||
use App\Exceptions\InvalidParamException; | ||
|
||
/** | ||
* | ||
* @package App\Models | ||
*/ | ||
abstract class AbstractModel | ||
{ | ||
protected $attributes = []; | ||
|
||
public function __construct($attributes = null) | ||
{ | ||
if (is_array($attributes)) { | ||
$this->attributes = $attributes; | ||
} | ||
} | ||
|
||
public function fill(array $attributes) | ||
{ | ||
$this->attributes = array_merge($this->attributes, $attributes); | ||
} | ||
|
||
/** | ||
* Access attributes as properties | ||
* | ||
* @param string $key | ||
* @return mixed | ||
* @throws InvalidParamException | ||
*/ | ||
public function __get($key) | ||
{ | ||
if (array_key_exists($key, $this->attributes)) { | ||
return $this->attributes[$key]; | ||
} | ||
throw new InvalidParamException(sprintf("Unknown property %s", $key)); | ||
} | ||
|
||
/** | ||
* Set the attribute | ||
* | ||
* @param string $key | ||
* @param mixed $value | ||
*/ | ||
public function __set($key, $value) | ||
{ | ||
$this->attributes[$key] = $value; | ||
} | ||
} |
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,70 @@ | ||
<?php | ||
|
||
namespace App\Models\Forms; | ||
|
||
use App\Models\AbstractModel; | ||
use App\Models\Country; | ||
use App\Services\LastFm\Client; | ||
|
||
/** | ||
* | ||
* @property Country country | ||
* @package App\Models | ||
*/ | ||
class SearchForm extends AbstractModel | ||
{ | ||
/** | ||
* Default attributes | ||
* | ||
* @var array | ||
*/ | ||
protected $attributes = ['country' => 'AU']; | ||
|
||
/** | ||
* Calculate the result set based on the current state of the object | ||
* | ||
* @return ResultSet | ||
*/ | ||
public function results() | ||
{ | ||
$client = $this->getLastFmApi(); | ||
|
||
return $client->geo->topArtists($this->country()->name); | ||
} | ||
|
||
/** | ||
* Check the state of the SearchForm model to determine if a search could | ||
* return possible results | ||
* | ||
* @return boolean [description] | ||
*/ | ||
public function isSearchable() | ||
{ | ||
return count(array_filter($this->attributes)) > 0; | ||
} | ||
|
||
/** | ||
* Get the country model | ||
* | ||
* @return Country|null | ||
*/ | ||
public function country() | ||
{ | ||
if ($this->country) { | ||
return Country::findById($this->country); | ||
} | ||
|
||
return null; | ||
} | ||
|
||
/** | ||
* Get the LastFm Api Client | ||
* | ||
* @return Client | ||
* @todo move this app container injection | ||
*/ | ||
public function getLastFmApi(): Client | ||
{ | ||
return \App\app()->get('lastfm'); | ||
} | ||
} |
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,39 @@ | ||
<?php | ||
|
||
namespace App\Services\LastFm\Api; | ||
|
||
use App\Services\LastFm\Client; | ||
use App\Services\LastFm\Response\AbstractResponse; | ||
use App\Services\LastFm\Response\Artist as ArtistResponse; | ||
|
||
/** | ||
* | ||
* @package App\Services\LastFm | ||
*/ | ||
class Geo | ||
{ | ||
/** | ||
* @var Client | ||
*/ | ||
private $client; | ||
|
||
public function __construct(Client $client) | ||
{ | ||
$this->client = $client; | ||
} | ||
|
||
/** | ||
* Get the top artists per country | ||
* | ||
* @param string $countryCode ISO 3166-1 country code | ||
* @param array $params additional params for the api request | ||
* @return ResultSet | ||
*/ | ||
public function topArtists($countryCode, array $params = []) | ||
{ | ||
$params = array_merge($params, ['country' => $countryCode]); | ||
$response = $this->client->request('geo.gettopartists', $params); | ||
|
||
return AbstractResponse::makeResultSet($this->client, $response, ArtistResponse::class, 'topartists.artist'); | ||
} | ||
} |
Oops, something went wrong.