Skip to content

Commit

Permalink
Merge pull request #5 from JBZoo/develop
Browse files Browse the repository at this point in the history
New syntax for multiRequest
  • Loading branch information
SmetDenis committed Aug 1, 2016
2 parents e1c3748 + 74f9ffe commit 9c1f875
Show file tree
Hide file tree
Showing 6 changed files with 26 additions and 3 deletions.
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ $httpClient = new HttpClient([
],
'driver' => 'auto', // (Auto|Guzzle5|Guzzle6|Rmccue)
'timeout' => 10, // Wait in seconds
'verify' => false, // check cert for SSL
'verify' => false, // Check cert for SSL
'exceptions' => false, // Show exceptions for statuses 4xx and 5xx
'allow_redirects' => true, // Show real 3xx-header or result?
'max_redirects' => 10, // How much to reirect?
Expand Down Expand Up @@ -76,8 +76,8 @@ $value = $json->find('key.nested', 'default', 'trim');
```php
$httpClient = new HttpClient();

$results = $httpClient->multiRequest([
'request_0' => ['http://mockbin.org/request'],
$results = $httpClient->multiRequest(array(
'request_0' => 'http://mockbin.org/request',
'request_1' => ['http://mockbin.org/request', [
'args' => ['key' => 'value']
]],
Expand Down
5 changes: 5 additions & 0 deletions src/Driver/Guzzle5.php
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,11 @@ public function multiRequest(array $urls)

$requests = array();
foreach ($urls as $urlName => $urlData) {

if (is_string($urlData)) {
$urlData = array($urlData, array());
}

$urlOptions = new Options($urlData[1]);

$method = $urlOptions->get('method', 'GET', 'up');
Expand Down
5 changes: 5 additions & 0 deletions src/Driver/Guzzle6.php
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,11 @@ public function multiRequest(array $urls)

$promises = array();
foreach ($urls as $urlName => $urlData) {

if (is_string($urlData)) {
$urlData = array($urlData, array());
}

$urlOptions = new Options($urlData[1]);

$method = $urlOptions->get('method', 'GET', 'up');
Expand Down
5 changes: 5 additions & 0 deletions src/Driver/Rmccue.php
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,11 @@ public function multiRequest(array $urls)
{
$requests = array();
foreach ($urls as $urlName => $urlData) {

if (is_string($urlData)) {
$urlData = array($urlData, array());
}

$urlOptions = new Options($urlData[1]);

$method = $urlOptions->get('method', 'GET', 'up');
Expand Down
2 changes: 2 additions & 0 deletions tests/DriverAutoTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@ protected function setUp()
{
parent::setUp();

sleep(1); // for mockservers

if ($this->_isPHP53()) {
$this->_methods = array('GET', 'POST', 'PATCH', 'PUT'); // TODO add 'DELETE'
}
Expand Down
6 changes: 6 additions & 0 deletions tests/DriverTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -315,6 +315,7 @@ public function testSSL()
public function testMultiRequest()
{
$results = $this->_getClient()->multiRequest(array(
'request_0' => 'http://mockbin.org/request?qwerty=123456',
'request_1' => array('http://mockbin.org/request', array(
'args' => array('key' => 'value')
)),
Expand All @@ -324,6 +325,11 @@ public function testMultiRequest()
))
));

/** @var Response $body1 */
$body1 = $results['request_0']->getJSON();
isSame('GET', $body1->find('method'));
isSame('123456', $body1->find('queryString.qwerty'));

/** @var Response $body1 */
$body1 = $results['request_1']->getJSON();
isSame('GET', $body1->find('method'));
Expand Down

0 comments on commit 9c1f875

Please sign in to comment.