Skip to content

Commit ab7dbe4

Browse files
committed
- code refactoring
1 parent 0ef99e6 commit ab7dbe4

2 files changed

Lines changed: 5 additions & 15 deletions

File tree

dHttp/Client.php

Lines changed: 3 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -116,11 +116,7 @@ public function addOptions(array $params)
116116
*/
117117
public function post($fields = array(), array $options = array())
118118
{
119-
$fields = is_array($fields) ? http_build_query($fields) : $fields;
120-
121-
$this->addOptions($options);
122-
$this->addOptions(array(CURLOPT_POST => true, CURLOPT_POSTFIELDS => $fields));
123-
return $this->_exec();
119+
return $this->get($options + array(CURLOPT_POST => true, CURLOPT_POSTFIELDS => is_array($fields) ? http_build_query($fields) : $fields));
124120
}
125121

126122
/**
@@ -132,11 +128,7 @@ public function post($fields = array(), array $options = array())
132128
*/
133129
public function put($fields = array(), array $options = array())
134130
{
135-
$fields = is_array($fields) ? http_build_query($fields) : $fields;
136-
137-
$this->addOptions($options);
138-
$this->addOptions(array(CURLOPT_CUSTOMREQUEST => 'PUT', CURLOPT_POSTFIELDS => $fields));
139-
return $this->_exec();
131+
return $this->get($options + array(CURLOPT_CUSTOMREQUEST => 'PUT', CURLOPT_POSTFIELDS => is_array($fields) ? http_build_query($fields) : $fields));
140132
}
141133

142134
/**
@@ -159,9 +151,7 @@ public function get(array $options = array())
159151
*/
160152
public function delete(array $options = array())
161153
{
162-
$this->addOptions($options);
163-
$this->addOptions(array(CURLOPT_CUSTOMREQUEST => 'DELETE'));
164-
return $this->_exec();
154+
return $this->get($options + array(CURLOPT_CUSTOMREQUEST => 'DELETE'));
165155
}
166156

167157
/**

tests/dHttpTest.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,8 @@ public function testGetRequest()
3030
public function testPostRequest()
3131
{
3232
$http = new dHttp\Client('http://php.net');
33-
$resp = $http->post();
34-
33+
$resp = $http->post([], [CURLOPT_HEADER => true]);
34+
3535
$this->assertInstanceOf('dHttp\Response', $resp);
3636
$this->assertEquals($resp->getCode(), 200);
3737
}

0 commit comments

Comments
 (0)