Skip to content

Commit 402a20e

Browse files
author
Martin Brecht-Precht
committed
Updated dependencies.
1 parent eb0244c commit 402a20e

File tree

4 files changed

+27
-29
lines changed

4 files changed

+27
-29
lines changed

README.md

+9-10
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ A JSON HTTP client library. This project also is the reference implementation fo
1515
```{json}
1616
{
1717
"require": {
18-
"markenwerk/json-http-client": "~1.0"
18+
"markenwerk/json-http-client": "~2.0"
1919
}
2020
}
2121
```
@@ -190,25 +190,24 @@ $message->addHeader(new Header('Custom-Header', array('CustomHeaderValue')));
190190
$message->addAdditionalHeader(new Header('Custom-Header', array('AnotherCustomHeaderValue')));
191191
```
192192

193-
#### Configuring a Request instance and perform the HTTP request
193+
#### Configuring an endpoints URL, build the Request instance and perform the HTTP request
194+
195+
For more information about the usage of the URL object please take a look at the [PHP URL Util](https://github.com/markenwerk/php-url-util) project.
194196

195197
```{php}
196198
use BasicHttpClient\Request\Authentication\BasicAuthentication;
197199
use JsonHttpClient\Request\JsonRequest;
200+
use Url\Url;
201+
202+
// Setting up the endpoints URL
203+
$url = new Url('https://john:[email protected]:443/path/to/resource?arg1=123#fragment');
198204
199205
// Configuring and performing a Request
200206
$request = new JsonRequest();
201207
$request
202208
->setUserAgent('PHP JSON HTTP Client Test 1.0')
203-
->setEndpoint('https://yourapihere-com-98yq3775xff0.runscope.net/')
204-
->setPort(443)
209+
->setUrl($url)
205210
->addAuthentication(new BasicAuthentication('username', 'password'))
206-
->setQueryParameters(
207-
array(
208-
'paramName1' => 'paramValue1',
209-
'paramName2' => 'paramValue2'
210-
)
211-
)
212211
->setMethod(JsonRequest::REQUEST_METHOD_POST)
213212
->setTransport($transport)
214213
->setMessage($message)

composer.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626
},
2727
"require": {
2828
"php": ">=5.3",
29-
"markenwerk/basic-http-client": "~1.0"
29+
"markenwerk/basic-http-client": "~2.0"
3030
},
3131
"require-dev": {
3232
"phpunit/phpunit": "~4.8",

detaild.php

+4-8
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
use BasicHttpClient\Request\Transport\HttpsTransport;
1111
use JsonHttpClient\Request\Message\Body\JsonBody;
1212
use JsonHttpClient\Request\JsonRequest;
13+
use Url\Url;
1314

1415
require_once('vendor/autoload.php');
1516

@@ -40,18 +41,13 @@
4041
->addCookie(new Cookie('PHPSESSID', '<MY_SESSION_ID>'))
4142
->setBody($messageBody);
4243

44+
$url = new Url('https://yourapihere-com-98yq3775xff0.runscope.net/');
45+
4346
$request = new JsonRequest();
4447
$response = $request
4548
->setUserAgent('PHP JSON HTTP Client Test 1.0')
46-
->setEndpoint('https://yourapihere-com-98yq3775xff0.runscope.net/')
47-
->setPort(443)
49+
->setUrl($url)
4850
->addAuthentication(new BasicAuthentication('username', 'password'))
49-
->setQueryParameters(
50-
array(
51-
'paramName1' => 'paramValue1',
52-
'paramName2' => 'paramValue2'
53-
)
54-
)
5551
->setMethod(JsonRequest::REQUEST_METHOD_POST)
5652
->setTransport($transport)
5753
->setMessage($message)

src/JsonHttpClient.php

+13-10
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,9 @@
99
use BasicHttpClient\Request\Transport\HttpsTransport;
1010
use BasicHttpClient\Request\Transport\HttpTransport;
1111
use BasicHttpClient\Response\ResponseInterface;
12-
use BasicHttpClient\Util\UrlUtil;
1312
use JsonHttpClient\Request\JsonRequest;
1413
use JsonHttpClient\Request\Message\Body\JsonBody;
14+
use Url\Url;
1515

1616
/**
1717
* Class JsonHttpClient
@@ -33,9 +33,9 @@ class JsonHttpClient implements HttpClientInterface
3333
*/
3434
public function __construct($endpoint)
3535
{
36-
$urlUtil = new UrlUtil();
36+
$url = new Url($endpoint);
3737
$transport = new HttpTransport();
38-
if ($urlUtil->getScheme($endpoint) == 'HTTPS') {
38+
if (mb_strtoupper($url->getScheme()) == 'HTTPS') {
3939
$transport = new HttpsTransport();
4040
}
4141
$message = new Message();
@@ -46,7 +46,7 @@ public function __construct($endpoint)
4646
$this->request
4747
->setTransport($transport)
4848
->setMessage($message)
49-
->setEndpoint($endpoint);
49+
->setUrl($url);
5050
}
5151

5252
/**
@@ -67,8 +67,9 @@ public function get(array $queryParameters = null)
6767
{
6868
$this->request
6969
->setMethod(RequestInterface::REQUEST_METHOD_GET)
70-
->setQueryParameters($queryParameters)
71-
->perform();
70+
->getUrl()
71+
->setQueryParametersFromArray($queryParameters);
72+
$this->request->perform();
7273
return $this->request->getResponse();
7374
}
7475

@@ -82,8 +83,9 @@ public function head(array $queryParameters = null)
8283
{
8384
$this->request
8485
->setMethod(RequestInterface::REQUEST_METHOD_HEAD)
85-
->setQueryParameters($queryParameters)
86-
->perform();
86+
->getUrl()
87+
->setQueryParametersFromArray($queryParameters);
88+
$this->request->perform();
8789
return $this->request->getResponse();
8890
}
8991

@@ -148,8 +150,9 @@ public function delete(array $queryParameters = null)
148150
{
149151
$this->request
150152
->setMethod(RequestInterface::REQUEST_METHOD_DELETE)
151-
->setQueryParameters($queryParameters)
152-
->perform();
153+
->getUrl()
154+
->setQueryParametersFromArray($queryParameters);
155+
$this->request->perform();
153156
return $this->request->getResponse();
154157
}
155158

0 commit comments

Comments
 (0)