Skip to content

Commit 0c8857c

Browse files
authored
Merge pull request #6 from KOBASSoftware/curl-info-fix
Update to enable extracting curl info for debugging
2 parents 4192830 + 75b6054 commit 0c8857c

File tree

5 files changed

+47
-14
lines changed

5 files changed

+47
-14
lines changed

README.md

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -33,19 +33,25 @@ echo json_encode($response, JSON_PRETTY_PRINT);
3333
## Client Functions
3434

3535
## get($route, $params = array(), $headers = array())
36-
cURL Get Request
36+
Sends a HTTP GET Request to the route provided.
3737

3838
## post($route, $params = array(), $headers = array())
39-
cURL Post Request
39+
Sends a HTTP POST Request to the route provided.
4040

4141
## put($route, $params = array(), $headers = array())
42-
cURL Put Request
42+
Sends a HTTP PUT Request to the route provided.
4343

4444
## delete($route, $params = array(), $headers = array())
45-
cURL Delete Request
45+
Sends a HTTP DELETE Request to the route provided.
46+
47+
## getRequestInfo()
48+
Returns the result of `curl_getinfo()`on the last request made as an array.
4649

4750
## setAPIBaseURL($url)
4851
Allows over-riding the base URL (only really needed for development)
4952

5053
## setAPIVersion($version)
5154
Allows over-riding of the API version. Might be useful in future?
55+
56+
57+

src/Kobas/APIClient/Auth/Provider.php

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
use Kobas\APIClient\Exception\CurlException;
88
use League\OAuth2\Client\Provider\Exception\IdentityProviderException;
99
use League\OAuth2\Client\Token\AccessToken;
10+
use Kobas\OAuth2\Client\Provider\Kobas as OAuthProvider;
1011

1112
/**
1213
* Class OAuthSigner
@@ -110,11 +111,11 @@ public function getAccessToken()
110111
}
111112

112113
/**
113-
* @return \Kobas\OAuth2\Client\Provider\Kobas
114+
* @return OAuthProvider
114115
*/
115116
public function getProvider()
116117
{
117-
$provider = new \Kobas\OAuth2\Client\Provider\Kobas([
118+
$provider = new OAuthProvider([
118119
'clientId' => $this->clientId,
119120
'clientSecret' => $this->clientSecret,
120121
'companyId' => $this->companyId,

src/Kobas/APIClient/Client.php

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,9 @@ class Client
4646
protected $curl_options;
4747

4848

49+
protected $request_info;
50+
51+
4952
/**
5053
* Client constructor.
5154
*
@@ -185,6 +188,7 @@ protected function call($http_method, $route, array $params = array(), array $he
185188
throw new CurlException($this->request->getErrorMessage(), $this->request->getErrorNumber());
186189
}
187190

191+
$this->request_info = $this->request->getAllInfo();
188192
$last_response = $this->request->getInfo(CURLINFO_HTTP_CODE);
189193

190194
$this->request->close();
@@ -240,4 +244,12 @@ public function delete($route, array $params = array(), array $headers = array()
240244
{
241245
return $this->call('DELETE', $route, $params, $headers);
242246
}
247+
248+
/**
249+
* @return array|false
250+
*/
251+
public function getRequestInfo()
252+
{
253+
return $this->request_info;
254+
}
243255
}

src/Kobas/APIClient/Request/Curl.php

Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
class Curl implements HttpRequest
1111
{
1212
/**
13-
* @var null
13+
* @var null|resource
1414
*/
1515
private $handle = null;
1616

@@ -28,7 +28,7 @@ public function init()
2828

2929
/**
3030
* @param $url
31-
* @return $this|Curl
31+
* @return Curl
3232
*/
3333
public function setUrl($url)
3434
{
@@ -38,7 +38,7 @@ public function setUrl($url)
3838
/**
3939
* @param $name
4040
* @param $value
41-
* @return $this
41+
* @return Curl
4242
*/
4343
public function setOption($name, $value)
4444
{
@@ -48,15 +48,15 @@ public function setOption($name, $value)
4848

4949

5050
/**
51-
* @return null
51+
* @return null|resource
5252
*/
5353
public function getHandle()
5454
{
5555
return $this->handle;
5656
}
5757

5858
/**
59-
* @return mixed
59+
* @return bool|string
6060
*/
6161
public function execute()
6262
{
@@ -73,23 +73,31 @@ public function getInfo($name)
7373
}
7474

7575
/**
76-
* @return int|mixed
76+
* @return array|false
77+
*/
78+
public function getAllInfo()
79+
{
80+
return curl_getinfo($this->handle);
81+
}
82+
83+
/**
84+
* @return int
7785
*/
7886
public function getErrorNumber()
7987
{
8088
return curl_errno($this->handle);
8189
}
8290

8391
/**
84-
* @return mixed|string
92+
* @return string
8593
*/
8694
public function getErrorMessage()
8795
{
8896
return curl_error($this->handle);
8997
}
9098

9199
/**
92-
* @return $this
100+
* @return Curl
93101
*/
94102
public function close()
95103
{

src/Kobas/APIClient/Request/HttpRequest.php

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,12 @@ public function execute();
3838
public function getInfo($name);
3939

4040

41+
/**
42+
* @return array|false
43+
*/
44+
public function getAllInfo();
45+
46+
4147
/**
4248
* @return mixed
4349
*/

0 commit comments

Comments
 (0)