diff --git a/src/Http/Client/ClientInterface.php b/src/Http/Client/ClientInterface.php index 8150142..792e96d 100644 --- a/src/Http/Client/ClientInterface.php +++ b/src/Http/Client/ClientInterface.php @@ -11,5 +11,5 @@ interface ClientInterface { - public function makeRequest($url, array $parameters = array(), $method = Client::GET); + public function request($url, array $parameters = array(), $method = Client::GET); } diff --git a/src/Http/Client/Guzzle.php b/src/Http/Client/Guzzle.php index f406c22..feb1294 100644 --- a/src/Http/Client/Guzzle.php +++ b/src/Http/Client/Guzzle.php @@ -7,6 +7,7 @@ namespace SocialConnect\Common\Http\Client; use \GuzzleHttp\Client as GuzzleClient; +use \SocialConnect\Common\Http\Response; class Guzzle extends Client { @@ -23,8 +24,10 @@ public function __construct(GuzzleClient $client = null) $this->client = is_null($client) ? new GuzzleClient() : $client; } - public function makeRequest($url, array $parameters = array(), $method = Client::GET) + public function request($url, array $parameters = array(), $method = Client::GET) { - $request = $this->client->createRequest($method, $url, $parameters); + $response = $this->client->send($this->client->createRequest($method, $url, $parameters)); + + return new Response($response->getStatusCode(), (string) $response->getBody()); } } diff --git a/src/Http/Request.php b/src/Http/Request.php new file mode 100644 index 0000000..55cb43c --- /dev/null +++ b/src/Http/Request.php @@ -0,0 +1,12 @@ + + */ + +namespace SocialConnect\Common\Http; + +class Request +{ + +} diff --git a/src/Http/Response.php b/src/Http/Response.php new file mode 100644 index 0000000..1342c9d --- /dev/null +++ b/src/Http/Response.php @@ -0,0 +1,40 @@ + + */ + +namespace SocialConnect\Common\Http; + +class Response +{ + protected $statusCode; + + protected $body; + + /** + * @param $statusCode + * @param $body + */ + public function __construct($statusCode, $body) + { + $this->statusCode = $statusCode; + $this->body = $body; + } + + /** + * @return mixed + */ + public function getBody() + { + return $this->body; + } + + /** + * @return mixed + */ + public function getStatusCode() + { + return $this->statusCode; + } +} diff --git a/tests/Test/Http/Client/GuzzleTest.php b/tests/Test/Http/Client/GuzzleTest.php index bc36f56..6518ea7 100755 --- a/tests/Test/Http/Client/GuzzleTest.php +++ b/tests/Test/Http/Client/GuzzleTest.php @@ -19,4 +19,10 @@ public function testConstructSuccess() $client = new Guzzle(new Client()); $this->assertInstanceOf('SocialConnect\Common\Http\Client\Client', $client); } + + public function testRequest() + { + $client = new Guzzle(new Client()); + $client->request('http://phalcon-module.dmtry.me/api/users/get/1/'); + } }