Skip to content

Commit

Permalink
Added Http\Response and rewrite Guzzle wrapper for it
Browse files Browse the repository at this point in the history
  • Loading branch information
ovr committed Sep 10, 2014
1 parent f2849fb commit cc033dc
Show file tree
Hide file tree
Showing 5 changed files with 64 additions and 3 deletions.
2 changes: 1 addition & 1 deletion src/Http/Client/ClientInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
7 changes: 5 additions & 2 deletions src/Http/Client/Guzzle.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
namespace SocialConnect\Common\Http\Client;

use \GuzzleHttp\Client as GuzzleClient;
use \SocialConnect\Common\Http\Response;

class Guzzle extends Client
{
Expand All @@ -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());
}
}
12 changes: 12 additions & 0 deletions src/Http/Request.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<?php
/**
* SocialConnect project
* @author: Patsura Dmitry @ovr <[email protected]>
*/

namespace SocialConnect\Common\Http;

class Request
{

}
40 changes: 40 additions & 0 deletions src/Http/Response.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
<?php
/**
* SocialConnect project
* @author: Patsura Dmitry @ovr <[email protected]>
*/

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;
}
}
6 changes: 6 additions & 0 deletions tests/Test/Http/Client/GuzzleTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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/');
}
}

0 comments on commit cc033dc

Please sign in to comment.