RESTClient – Web Service Consumer

RESTClient is an application use to visit and test RESTful services.

REST (Representational State Transfer) is the model of the Web to consume web resources. The browser makes a request to a URL and receives a response.  The request may be a GET or POST (or a PUT, DELETE, or HEAD) and the response may be anything HTML, Image file, PDF, XML, JSON etc.

Some RESTful Web Services…

http://www.flickr.com/services/api/

http://code.google.com/p/a2zvideoapi/

RESTClient extension: https://addons.mozilla.org/en-US/firefox/addon/9780

a2zVideo API

Welcome to the a2zVideoAPI wiki!

This API supports video links to get video information like Embed Code, Video Thumb, Video Title, Video Description etc.

How to use a2zVideoAPI:

1. Download “api.php” from http://github.com/svnlabs/a2zVideoAPI

2. API require PHP with CURL extension.. Setup / Upload “api.php” to your web server

3. Modify “api.php” for API Video server
curl_setopt($ch, CURLOPT_URL, ‘https://www.svnlabs.com/a2zvideoapi/server.php’);

4. There are currently 3 formats for API response

a. HTML
b. XML
c. JSON

$post = array( ‘url’ => “http://www.flickr.com/photos/schwartzray/2483697739/”, ‘format’ => “html” );

5. You have to use valid video page url like “http://www.youtube.com/watch?v=mXMf9GOzzOA” with format “html”, “xml” and “json”

6. Enjoy with svnlabs.com

Follow me….

Facebook: http://www.facebook.com/svnlabs
Twitter: http://www.twitter.com/svnlabs

Subscribe me….
Youtube: http://www.youtube.com/user/svnlabs
Feeds: https://www.svnlabs.com/blogs/feed/

Download youtube videos using PEAR

PEAR have rich library to access web based resources easily…

<?php

$sv = new SVTube();
$sv->download(“D7cm-yu-CP0”, “svnlabs.flv”)

?>

Class: SVTube.php
——————————

<?php

require_once ‘HTTP/Client.php’;
require_once ‘HTTP/Request.php’;

class SVTube {

var $req;
var $debug = false;
var $auth = false;

function download ($video_id, $video_filename) {
$url = “http://www.youtube.com/watch?v=”.$video_id;
$this->req =& new HTTP_Request($url);
$response = $this->req->sendRequest();

if (PEAR::isError($response)) {
echo $response->getMessage().”\n”;
} else {
$page = $this->req->getResponseBody();

preg_match(‘/\&t=([^”]*)”/si’, $page, $match);

$html=html_entity_decode(urldecode(str_replace(‘\x’, ‘%’, $match[1])),ENT_QUOTES, “UTF-8”);

$echo = explode(“&”, $html);

$url = “http://www.youtube.com/get_video?el=detailpage&t=”.$echo[0].”&fmt=5&asv=3&video_id=”.$video_id;

if ($this->debug)
return $url.”\n”;

$req =& new HTTP_Request($url,array (“allowRedirects”=>true, “maxRedirects”=> 99));
$req->setMethod(HTTP_REQUEST_METHOD_GET);
$req->addHeader(“User-Agent”,”Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.0)”);
$response = $req->sendRequest();

$req->getResponseBody();

if (PEAR::isError($response)) {
//echo $response->getMessage().”\n”;
return “Error: Failed to open video file on YouTube\n”;
} else {
if ($o = fopen ($video_filename, “w”)) {
fwrite($o,$req->getResponseBody());
fclose ($o);
return “Download complete! File: “.$video_filename.”\n”;
} else {
return “Error: Failed to open video-file\n”;
}
}

}
}

}
?>