-
Notifications
You must be signed in to change notification settings - Fork 2
Design
Before i start explaining how to install and use the source i better start explaining the design first.
Once we have a model using this source all API sections1 kinda emulate the interface of associated models. So the way you talk to the source is similar to how you talk to models. $this->Model->AssocModel. The difference is that the AssocModel is actually a method related to specific part of the API. That way we don’t have to worry which method exists and avoid conflicts.
If we want something that is a Album we call the source like so:
$this->Model->Album('search', array('album' => 'Dark Side of the Moon'));
If we want something from a Track we change it to this:
$this→Model→Track(‘getInfo’, array(‘track’ => ‘The Wall’));
This schema is kept throughout the implementation. All API methods work the same. It is easy to adapt. The first paramter is the method and the second is a array with optional paramters as required/allowed by the API. To make it more clear have a look at this:
$this→Model→Artist(‘search’, array(‘artist’ => ‘Pink Floyd’, ‘limit’ => 10))
| | |
| | |_ query params: “&artist=Pink%20Floyd&limit=10”
| |
| |_method: search (= artist.search)
|
|_ class: LastFmArtist (‘Artist’ section)
1 Sections as in: Album, Artist, Tag, etc. as layed out on the api homepage.
The source is intelligent enough to handle this on it’s own. So you don’t need to worry about if the method needs post or get or what special params you need to add if auth is required. The Interface is always the same, regardless.
There are other methods that have nothing to do with calling the API (ie. make a request). You could, for example, read all available methods for a single Section using apiMethods($section), or you could read the last request URI using getLastCall() etc. But that’s nearly all there is. All other method focus on getting this thing going. The source is well documented and should tell you everything you need to know.