» December 6th, 2008 » 29 Comments

I had some time and so I whipped up a quick PHP wrapper for the API. This is a pretty cool api if you haven’t seen it, check it out! Anyways, you can get the wrapper from the download link below or just copy/paste it.

< ?php

//  YES API Wrapper version 1.0
//  (c) 2008 Kevin Miller
//  This script is freely distributable under the terms of an MIT-style license.

class YESAPIWrapper
	const API_URL = "";
	const API_VERSION = "1";
	public function __construct() 
	public function execute($method = null, $options = array())
		if ($this->allowed_method($method))
			return $this->fetch(self::API_URL . "/" . self::API_VERSION . "/" . $this->method . "?" . $this->options_string($options));
	protected $method;
	protected $allowed_paramaters = array(
		"station" => array(
			"name" => true,
			"callback" => false
		"stations" => array(
			"match" => false,
			"freq" => false,
			"media" => false,
			"genre" => false,
			"loc" => false,
			"max" => false,
			"callback" => false
		"log" => array(
			"name" => true,
			"ago" => false,
			"callback" => false
		"recent" => array(
			"name" => false,
			"max" => false,
			"callback" => false
		"chart" => array(
			"name" => false,
			"date" => false,
			"genre" => false,
			"hot" => false,
			"max" => false,
			"callback" => false
		"media" => array(
			"q" => false,
			"mid" => false,
			"callback" => false
		"related" => array(
			"mid" => true,
			"max" => false,
			"callback" => false
		"artist" => array(
			"artist" => true,
			"callback" => false

	private function allowed_method($method)
		foreach ($this->allowed_paramaters as $key => $value)
			if ($key == $method)
				$this->method = $method;
				return true;
		throw new Exception($key . " is a required parameter for the method (" . $this->method . ")!");
	private function validate_options($options)
		foreach ($this->allowed_paramaters[$this->method] as $key => $value)
			if ($value && !array_key_exists($key, $options))
				throw new Exception($key . " is a required parameter for the method (" . $this->method . ")!");

		foreach ($options as $key => $value)
			if (!array_key_exists($key, $this->allowed_paramaters[$this->method]))
				throw new Exception($key . " is not an valid parameter for the method (" . $this->method . ")!");

		return true;
	private function options_string($options = array())
		if ($this->validate_options($options))
			return http_build_query($options);		
	private function fetch($url = "")
		return ($contents = file_get_contents($url)) ? json_decode($contents) : null;

Be Sociable, Share!



29 Responses to “YES API PHP Wrapper”

  1. F1X85o hi nice site thanx

  2. bob on January 3rd, 2009 at 2:17 am
  3. Do you have any examples/demos of this wrapper in use?

  4. Nick on January 22nd, 2009 at 5:40 am
  5. Can you please provide an example of this class in use… Thanks. :-)

  6. Jon on June 22nd, 2009 at 11:43 pm
  7. It’s good, it’s useful (as usual), actionable and concise. Love it.

  8. Coupon Builder on March 12th, 2010 at 2:56 am
  9. After studying this posting, I contemplated the exact same point that I invariably wonder about when scanning new blogs and forums. Just what do I think about this? Exactly how ought to it effect me? This and extra posts in your weblog right here actually give some stuff to look at. I basically ended up here by the use of Yahoo when I was very first doing some internet research for some course perform that I have. Always excellent instances browsing by the use of and I’m hopeful that you’ll keep on writing new posts. Cheers!

  10. Collin Banek on May 20th, 2011 at 2:24 pm
  11. Spodobała mi się ta strona i będę tutaj wracał częściej. Zapraszam również na swoją stronę.

  12. Hubert on June 30th, 2011 at 1:00 am
  13. Thanks for all your labor on this blog. Betty delights in setting aside time for research and it’s easy to understand why. We notice all about the lively means you render good suggestions by means of this blog and in addition cause contribution from other individuals on this area so our girl is in fact being taught a lot. Enjoy the remaining portion of the year. You’re carrying out a brilliant job.

  14. massage tips on November 10th, 2011 at 6:32 pm
  15. I’d like to be able to tag blogs I like and have them show on my website. Any suggestions on the best route to take on this. Any input would be helpful..

  16. impetigo symptoms on November 17th, 2011 at 4:00 am
  17. I’ve just launched some blog, typically the information most people provide on that website seems to have made it easier everybody tremendously. Thank you for the purpose of your personal instance & give good results.

  18. keratin express on December 3rd, 2011 at 8:53 am
  19. A motivаtіng disсusѕion is definitelу wοrth
    comment. I do believe thаt you should write more about this issue,
    іt mіght not be a taboo subject but generally fοlκs ԁon’t speak about these topics. To the next! Kind regards!!

  20. on April 8th, 2013 at 2:26 pm
  21. I think what you posted was actually very logical. But, consider
    this, suppose you were to create a killer headline?
    I mean, I don’t wish to tell you how to run your website, but suppose you added a headline that grabbed a person’s
    attention? I mean YES API PHP Wrapper : p51 Labs is kinda plain.

    You ought to peek at Yahoo’s home page and see how they create news headlines to grab viewers to open the links. You might add a video or a related pic or two to get people interested about everything’ve written.
    In my opinion, it would bring your posts a little bit more interesting.

  22. diabetes health pack on April 9th, 2013 at 4:05 am
  23. I do not even know how I ended up here, but I thought
    this post was good. I don’t know who you are but certainly you’re going
    to a famous blogger if you are not already ;) Cheers!

  24. online bingo no deposit on April 12th, 2013 at 2:20 pm
  25. Just desire to say your article is as surprising.

    The clearness in your put up is just great and i can assume you are an expert in this subject.
    Well with your permission allow me to seize your feed to stay
    updated with coming near near post. Thanks a million and please continue the rewarding work.

  26. on April 13th, 2013 at 6:44 am
  27. Interesting blog! Is your theme custom made or did you download it from somewhere?
    A design like yours with a few simple adjustements would really make my
    blog stand out. Please let me know where you got your theme.
    Appreciate it

  28. on April 19th, 2013 at 7:42 am
  29. What i do not understood is in reality how you
    are not actually much more smartly-liked than you may be now.
    You’re very intelligent. You understand thus significantly relating to this matter, made me personally imagine it from so many various angles. Its like men and women are not interested unless it is something to do with Lady gaga! Your individual stuffs great. Always handle it up!

  30. Kattie on May 6th, 2013 at 11:35 pm
  31. Hello, I check your blog regularly. Your writing style is awesome, keep it up!

  32. free microsoft points generator no survey no password on May 19th, 2013 at 7:42 pm
  33. It’s going to be ending of mine day, but before finish I am reading this impressive paragraph to improve my experience.

  34. Bankrupt Millionaire on May 27th, 2013 at 1:23 am
  35. We stumbled over here different website and thought I
    should check things out. I like what I see so now i’m following you. Look forward to finding out about your web page yet again.

  36. limo service on June 4th, 2013 at 5:16 pm
  37. Aw, this was an incredibly good post. Spending some time and actual effort
    to make a really good article… but what can I say… I procrastinate
    a whole lot and never manage to get anything done.

  38. フルラ アウトレット on June 5th, 2013 at 9:19 pm
  39. Oh my goodness! Amazing article dude! Thank you, However I am having troubles
    with your RSS. I don’t know the reason why I am unable to subscribe to it. Is there anybody else having the same RSS issues? Anybody who knows the solution will you kindly respond? Thanks!!

  40. コーチ 財布 新作 on June 11th, 2013 at 8:26 am
  41. Nice blog here! Also your site loads up fast!

    What web host are you using? Can I get your affiliate link
    to your host? I wish my web site loaded up as quickly as yours lol

  42. Keeley on June 11th, 2013 at 12:30 pm
  43. For latest news you have to pay a visit internet and on internet I found this web site as
    a best site for hottest updates.

  44. how to trade stocks on August 5th, 2013 at 8:31 pm
  45. “Wow, incredible blog layout! How long have you been blogging for? you made blogging look easy. The overall look of your website is fantastic, let alone the content!. Thanks For Your article about Quen Somos ? | grupo de consumo responsable .”

  46. europe seo hosting on August 16th, 2013 at 7:44 am
  47. When I originally left a comment I seem to have clicked
    on the -Notify me when new comments are added- checkbox and
    from now on each time a comment is added I receive four
    emails with the same comment. There has to be a means you are able to remove me
    from that service? Appreciate it!

  48. good colon cleanse on October 18th, 2013 at 2:10 pm
  49. “YES API PHP Wrapper : p51 Labs” was a terrific article.
    In case it owned a lot more photos it would most likely
    be quite possibly more effective. Thank u ,Lisette

    Also visit my site Audra

  50. Audra on January 22nd, 2014 at 2:06 pm
  51. My Partner And I just want to share it with you the fact that I’m really inexperienced to online blogging and genuinely cherished your information. Quite possibly I am most likely to bookmark your post post . You seriously have fantastic article writing. Acknowledge it for share-out with us your url report.

  52. Charles S. Parks on May 8th, 2014 at 4:21 pm
  53. I’ve bedn browsing online more than three hours these
    days, but I by no means discovered any attention-grabbing article like yours.
    It’s lovely worth enough for me. In my opinion, iff all web owners and bloggers made just right content
    material aas you did, the nternet shall be a lot more useful than ever before.

  54. on May 9th, 2014 at 11:45 am
  55. Some genuinely great blog posts on this site, regards for contribution.
    “Once, power was considered a masculine attribute. In fact, power has no sex.” by Katharine Graham.

  56. on May 15th, 2014 at 1:38 pm
  57. If a painting company is bonded and insured by workers’ compensation, and reliability.
    Please be aware provide of the correct grade of his home country, pool lifts and stair lifts, you need to ask them.

    To ensure you re and your contractor.

    Review my homepage webpage (Harriett)

  58. Harriett on September 22nd, 2014 at 1:56 pm

Leave a Reply