Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 0 additions & 14 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -63,22 +58,13 @@ $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
$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
Expand Down
23 changes: 5 additions & 18 deletions src/Curl/Curl.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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();
}

Expand Down