YES API PHP Wrapper
» » 16 Comments
I had some time and so I whipped up a quick PHP wrapper for the YES.com 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 = "http://api.yes.com";
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;
}
}
?>

F1X85o hi nice site thanx http://peace.com
Do you have any examples/demos of this wrapper in use?
Can you please provide an example of this class in use… Thanks.
It’s good, it’s useful (as usual), actionable and concise. Love it.
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!
Spodobała mi się ta strona i będę tutaj wracał częściej. Zapraszam również na swoją stronę.
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.
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..
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.
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!!
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.
I do not even know how I ended up here, but I thought
Cheers!
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
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.
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
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!
Hello, I check your blog regularly. Your writing style is awesome, keep it up!