Skip to content

Commit 2236ca9

Browse files
committed
fixed dependency
1 parent 631854d commit 2236ca9

File tree

4 files changed

+72
-96
lines changed

4 files changed

+72
-96
lines changed

composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
],
1414
"require": {
1515
"php": ">=5.5.0",
16-
"guzzlehttp/guzzle": "^6.0",
16+
"guzzlehttp/guzzle": "^5.0|^6.0",
1717
"symfony/serializer": "^2.0|^3.0"
1818
},
1919
"require-dev": {
Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
<?php
2+
3+
/*
4+
* This file is part of the Josser package.
5+
*
6+
* (C) Alan Gabriel Bem <alan.bem@gmail.com>
7+
*
8+
* For the full copyright and license information, please view the LICENSE
9+
* file that was distributed with this source code.
10+
*/
11+
12+
namespace Josser\Client\Transport;
13+
14+
use GuzzleHttp\Client;
15+
use Josser\Exception\TransportFailureException;
16+
17+
/**
18+
* JSON-RPC http transport with Guzzle 5.
19+
*
20+
* @author Alan Gabriel Bem <alan.bem@gmail.com>
21+
*/
22+
class Guzzle5Transport implements TransportInterface
23+
{
24+
/**
25+
* Guzzle http client.
26+
*
27+
* @var Client
28+
*/
29+
private $guzzle;
30+
31+
/**
32+
* @param Client $guzzle
33+
*/
34+
public function __construct(Client $guzzle)
35+
{
36+
$this->guzzle = $guzzle;
37+
}
38+
39+
/**
40+
* @return Client
41+
*/
42+
public function getGuzzle()
43+
{
44+
return $this->guzzle;
45+
}
46+
47+
/**
48+
* Send data to remote JSON-RPC service over HTTP.
49+
*
50+
* @throws \Josser\Exception\TransportFailureException
51+
* @param mixed $data
52+
* @return string
53+
*/
54+
public function send($data)
55+
{
56+
try {
57+
$response = $this->guzzle->post(null, [
58+
'body' => $data,
59+
'headers' => [
60+
'Content-Type' => 'application/json',
61+
]
62+
]);
63+
return $response->getBody()->getContents();
64+
} catch (\Exception $e) {
65+
$error = sprintf('JSON-RPC http connection failed. Remote service at "%s" is not responding.', $this->guzzle->getBaseUrl());
66+
throw new TransportFailureException($error, null, $e);
67+
}
68+
}
69+
}

src/Josser/Client/Transport/HttpTransport.php renamed to src/Josser/Client/Transport/Guzzle6Transport.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,11 +15,11 @@
1515
use Josser\Exception\TransportFailureException;
1616

1717
/**
18-
* JSON-RPC http transport.
18+
* JSON-RPC http transport with Guzzle 6.
1919
*
2020
* @author Alan Gabriel Bem <alan.bem@gmail.com>
2121
*/
22-
class HttpTransport implements TransportInterface
22+
class Guzzle6Transport implements TransportInterface
2323
{
2424
/**
2525
* Guzzle http client.

tests/Josser/Tests/Transport/HttpTransportTest.php

Lines changed: 0 additions & 93 deletions
This file was deleted.

0 commit comments

Comments
 (0)