Skip to content

Commit

Permalink
fixed dependency
Browse files Browse the repository at this point in the history
  • Loading branch information
alanbem committed Apr 12, 2016
1 parent 631854d commit 2236ca9
Show file tree
Hide file tree
Showing 4 changed files with 72 additions and 96 deletions.
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
],
"require": {
"php": ">=5.5.0",
"guzzlehttp/guzzle": "^6.0",
"guzzlehttp/guzzle": "^5.0|^6.0",
"symfony/serializer": "^2.0|^3.0"
},
"require-dev": {
Expand Down
69 changes: 69 additions & 0 deletions src/Josser/Client/Transport/Guzzle5Transport.php
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 <alan.bem@gmail.com>
*
* 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 <alan.bem@gmail.com>
*/
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);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,11 @@
use Josser\Exception\TransportFailureException;

/**
* JSON-RPC http transport.
* JSON-RPC http transport with Guzzle 6.
*
* @author Alan Gabriel Bem <alan.bem@gmail.com>
*/
class HttpTransport implements TransportInterface
class Guzzle6Transport implements TransportInterface
{
/**
* Guzzle http client.
Expand Down
93 changes: 0 additions & 93 deletions tests/Josser/Tests/Transport/HttpTransportTest.php

This file was deleted.

0 comments on commit 2236ca9

Please sign in to comment.