Muschamp Rd

albumCollection.php is starting to come together

October 6th, 2010
CD covers

I never set out to write this much PHP code. But after seeing what passes for a PHP API to access Amazon Product Information, well I vowed to do a good job on my PHP class, even though it was intended for my own personal use. I had modest goals at the beginning I just wanted to take a list of CDs I own and produce a gallery of album covers.

Update: I ended up writing even more PHP code and creating a series of web mashups, the code for which is detailed online.

After I finally got to work I wrote code that did that, but it ran slow, especially when you gave it more data. So I set out to write a proper class to represent a collection of albums in PHP. I also integrated it with Amazon for cover images and for artist info. This was more than sufficient for my original needs, but while writing various methods on my class, I decided to go all in and integrate in support for other APIs and web services.

Look at all the pretty icons and buttons

The third one I got working was Facebook, although it too had buggy PHP code online claiming to solve all my needs. I ended up not using much of that code or the Facebook API, but I made a little button so you can like an artist following various official guidelines and my own trial and error. I got pretty good at string manipulation and using CURL and JSON.

I was always going to integrate with iLike but their developer site was always down or the documentation was down, basically they were just holding me up and it’s not like I need them. So I went on to the iTunes Music Store. The iTunes Music Store does have an API of sorts, you can search it and fetch back various links. They even have an affiliate program but it isn’t available in Canada. The only affiliate program I’ve implemented is the only one I’ve ever signed up for, Amazon Associate. I don’t really use my ID though, so for this project I put in support for that.

I really don’t use very much of any one API. I don’t even fetch that much data. Mainly I link out to more information, rather than pull it into my application. This is partially done for speed, but also because that was closer to my original design. Now that I’ve written so much PHP code I’ll probably make a couple uses of it.

Tweet this functionality in action

I added caching to my iTunes Music Store queries. I don’t query it that much and it’s not like the URL to an artist’s page is going to change very often. With basic iTunes functionality working today, I added in support for Twitter. Some people seem to love Twitter, so I implemented the Tweet This button. You can now Tweet your favourite albums from my collection, or at least this subset of my collection that I’m using to make these test web applications.

I had trouble sleeping so although I stopped working on this project at 7pm I decided to get up and have a snack and update my blog. Tomorrow I hope to work on the front end or front ends of the application, then I’ll likely need to do more research into how PHP interacts with webpages. I plan to add a few more convenience methods and improve the constructor, Facebook integration, and probably take a look at what Google and a few others have to offer in the way of APIs. I also plan to try and get sample tracks, first from as I think that will be easiest, but iTunes and Amazon have more tracks I believe, I might end up searching them all, it is playing them on a webpage that worries me, I might need a widget or rely on people’s browsers to just handle it…

Now back to bed.

Posts on Muskblog © Andrew "Muskie" McKay comments not necessarily so...
CFA Institute does not endorse, promote or warrant the accuracy or quality of Muskblog. CFA® and Chartered Financial Analyst® are registered trademarks owned by CFA Institute.