url = $url; if($params != null) { $this->url = $this->url."?"; foreach ($params as $key => $value) { $this->url = $this->url.$key."=".$value."&"; } $len = strlen($this->url); $this->url = substr($this->url, 0, $len-1); } $this->req =& new HTTP_Request($this->url); } public function __construct() { } public function setHeaders($headers = array("")) { $this->headers = $headers; } public function get() { $this->req->setMethod("GET"); return $this->connect(); } public function put($data) { $this->req->setMethod("PUT"); $this->req->setBody($data); return $this->connect(); } public function post($data) { if(is_array($data)) { $this->req->setMethod("POST"); $this->req->addHeader("Content-Type", "application/x-www-form-urlencoded"); foreach ($data as $key => $value) { $this->req->addPostData($key, $value); } } else { $this->req->setBody($data); } return $this->connect(); } public function delete() { $this->req->setMethod("DELETE"); return $this->connect(); } public function connect() { $this->response = $this->req->sendRequest(); if (PEAR::isError($this->response)) { echo $this->response->getMessage(); die(); } else { $this->responseBody = $this->req->getResponseBody(); } $response = new RestResponse(); $response->setResponseCode($this->req->getResponseCode()); $response->setResponseBody($this->req->getResponseBody()); return $response; } } ?>