diff --git a/README.md b/README.md index abd474e..39ecab4 100644 --- a/README.md +++ b/README.md @@ -23,11 +23,6 @@ $curl->post('http://www.example.com/login/', array( 'username' => 'myusername', 'password' => 'mypassword', )); -// Or for json APIs -$curl->post('http://www.example.com/login/', json_encode(array( - 'username' => 'myusername', - 'password' => 'mypassword', -))); ``` ```php @@ -63,11 +58,6 @@ $curl->put('http://api.example.com/user/', array( 'first_name' => 'Zach', 'last_name' => 'Borboa', )); -// Or for json APIs -$curl->put('http://api.example.com/user/', json_encode(array( - 'first_name' => 'Zach', - 'last_name' => 'Borboa', -))); ``` ```php @@ -75,10 +65,6 @@ $curl = new Curl\Curl(); $curl->patch('http://api.example.com/profile/', array( 'image' => '@path/to/file.jpg', )); -// Or for json APIs -$curl->patch('http://api.example.com/profile/', json_encode(array( - 'image' => '@path/to/file.jpg', -))); ``` ```php diff --git a/src/Curl/Curl.php b/src/Curl/Curl.php index a28a6b4..3db0379 100644 --- a/src/Curl/Curl.php +++ b/src/Curl/Curl.php @@ -47,7 +47,7 @@ public function __construct() { public function get($url, $data = array()) { if (count($data) > 0) - $this->setopt(CURLOPT_URL, $url . '?' g. http_build_query($data)); + $this->setopt(CURLOPT_URL, $url . '?' . http_build_query($data)); else $this->setopt(CURLOPT_URL, $url); $this->setopt(CURLOPT_HTTPGET, TRUE); @@ -57,40 +57,27 @@ public function get($url, $data = array()) { public function post($url, $data=array()) { $this->setopt(CURLOPT_URL, $url); $this->setopt(CURLOPT_POST, TRUE); - if(is_array($data)){ - $data = http_build_query($data); - } + $data = http_build_query($data); $this->setopt(CURLOPT_POSTFIELDS, $data); $this->_exec(); } public function put($url, $data=array()) { - $this->setopt(CURLOPT_URL, $url); + $this->setopt(CURLOPT_URL, $url . '?' . http_build_query($data)); $this->setopt(CURLOPT_CUSTOMREQUEST, 'PUT'); - if(is_array($data)){ - $data = http_build_query($data); - } - $this->setopt(CURLOPT_POSTFIELDS, $data); $this->_exec(); } public function patch($url, $data=array()) { $this->setopt(CURLOPT_URL, $url); $this->setopt(CURLOPT_CUSTOMREQUEST, 'PATCH'); - if(is_array($data)){ - $data = http_build_query($data); - } - $this->setopt(CURLOPT_POSTFIELDS, $data); + $this->setopt(CURLOPT_POSTFIELDS, $data); $this->_exec(); } public function delete($url, $data=array()) { - $this->setopt(CURLOPT_URL, $url); + $this->setopt(CURLOPT_URL, $url . '?' . http_build_query($data)); $this->setopt(CURLOPT_CUSTOMREQUEST, 'DELETE'); - if(is_array($data)){ - $data = http_build_query($data); - } - $this->setopt(CURLOPT_POSTFIELDS, $data); $this->_exec(); }