Skip to content

Commit

Permalink
Moved CosmoService code from generic mashups module to cosmoservice m…
Browse files Browse the repository at this point in the history
…odule

git-svn-id: http://svn.silverstripe.com/open/modules/cosmoservice/trunk@43821 467b73ca-7a2a-4603-9d3b-597d59a354a9
  • Loading branch information
mpeel committed Oct 24, 2007
1 parent 9d7144b commit 5f57568
Showing 1 changed file with 89 additions and 0 deletions.
89 changes: 89 additions & 0 deletions YoutubeService.php
@@ -0,0 +1,89 @@
<?php

/**
* Used to connect to YouTube API via REST interface.
*/
class YoutubeService extends RestfulService {
private static $api_key;

function __construct(){
$this->baseURL = 'http://www.youtube.com/api2_rest';
$this->checkErrors = true;
}

/*
This will return API specific error messages.
*/
function errorCatch($response){
$err_msg = $this->getValue($response, "error", "description");
if($err_msg)
//user_error("YouTube Service Error : $err_msg", E_USER_ERROR);
throw new Exception("YouTube Service Error : $err_msg");
else
return $response;
}
/*
Sets the Developer ID for YouTube. Method name remains same as setAPIKey but it implies the dev_id
*/
static function setAPIKey($key){
self::$api_key = $key;
}

function getAPIKey(){
return self::$api_key;
}

function getVideosByTag($tag=NULL, $per_page=20, $page=1){
$params = array(
'method' => 'youtube.videos.list_by_tag',
'tag' => $tag,
'per_page' => $per_page,
'page' => $page,
'dev_id' => $this->getAPIKey()
);

$this->setQueryString($params);
$conn = $this->connect();

$results = $this->getValues($conn, 'video_list', 'video');
Debug::show($results);
return $results;
}

function getVideosByUser($user=NULL, $per_page=20, $page=1){
$params = array(
'method' => 'youtube.videos.list_by_user',
'user' => $user,
'per_page' => $per_page,
'page' => $page,
'dev_id' => $this->getAPIKey()
);

$this->setQueryString($params);
$conn = $this->connect();

$results = $this->getValues($conn, 'video_list', 'video');
Debug::show($results);
return $results;
}

function getVideosByPlaylist($playlist=NULL, $per_page=20, $page=1){
$params = array(
'method' => 'youtube.videos.list_by_playlist',
'id' => $playlist,
'per_page' => $per_page,
'page' => $page,
'dev_id' => $this->getAPIKey()
);

$this->setQueryString($params);
$conn = $this->connect();

$results = $this->getValues($conn, 'video_list', 'video');
Debug::show($results);
return $results;
}


}
?>

0 comments on commit 5f57568

Please sign in to comment.