-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
72 additions
and
96 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
<?php | ||
|
||
/* | ||
* This file is part of the Josser package. | ||
* | ||
* (C) Alan Gabriel Bem <[email protected]> | ||
* | ||
* For the full copyright and license information, please view the LICENSE | ||
* file that was distributed with this source code. | ||
*/ | ||
|
||
namespace Josser\Client\Transport; | ||
|
||
use GuzzleHttp\Client; | ||
use Josser\Exception\TransportFailureException; | ||
|
||
/** | ||
* JSON-RPC http transport with Guzzle 5. | ||
* | ||
* @author Alan Gabriel Bem <[email protected]> | ||
*/ | ||
class Guzzle5Transport implements TransportInterface | ||
{ | ||
/** | ||
* Guzzle http client. | ||
* | ||
* @var Client | ||
*/ | ||
private $guzzle; | ||
|
||
/** | ||
* @param Client $guzzle | ||
*/ | ||
public function __construct(Client $guzzle) | ||
{ | ||
$this->guzzle = $guzzle; | ||
} | ||
|
||
/** | ||
* @return Client | ||
*/ | ||
public function getGuzzle() | ||
{ | ||
return $this->guzzle; | ||
} | ||
|
||
/** | ||
* Send data to remote JSON-RPC service over HTTP. | ||
* | ||
* @throws \Josser\Exception\TransportFailureException | ||
* @param mixed $data | ||
* @return string | ||
*/ | ||
public function send($data) | ||
{ | ||
try { | ||
$response = $this->guzzle->post(null, [ | ||
'body' => $data, | ||
'headers' => [ | ||
'Content-Type' => 'application/json', | ||
] | ||
]); | ||
return $response->getBody()->getContents(); | ||
} catch (\Exception $e) { | ||
$error = sprintf('JSON-RPC http connection failed. Remote service at "%s" is not responding.', $this->guzzle->getBaseUrl()); | ||
throw new TransportFailureException($error, null, $e); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -15,11 +15,11 @@ | |
use Josser\Exception\TransportFailureException; | ||
|
||
/** | ||
* JSON-RPC http transport. | ||
* JSON-RPC http transport with Guzzle 6. | ||
* | ||
* @author Alan Gabriel Bem <[email protected]> | ||
*/ | ||
class HttpTransport implements TransportInterface | ||
class Guzzle6Transport implements TransportInterface | ||
{ | ||
/** | ||
* Guzzle http client. | ||
|
This file was deleted.
Oops, something went wrong.