Skip to content

Commit

Permalink
Теперь конфигурация guzzle-клиента производится через соответствующий…
Browse files Browse the repository at this point in the history
… метод setClient класса Zelenin\SmsRu\Api
  • Loading branch information
S.E.M committed Mar 26, 2018
1 parent 6454cbb commit 19599c3
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 29 deletions.
11 changes: 2 additions & 9 deletions Api.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,20 +33,13 @@ class Api
*/
private $client;

/**
* @var array
*/
private $config = [];

/**
* @param AuthInterface $auth
* @param array $config additional config setting for client service
*/
public function __construct(AuthInterface $auth, $config = [])
public function __construct(AuthInterface $auth)
{
$this->auth = $auth;
$this->auth->setContext($this);
$this->config = $config;
}

/**
Expand Down Expand Up @@ -287,7 +280,7 @@ public function request($method, $params = [])
public function getClient()
{
if ($this->client === null) {
$this->client = new Client($this->config);
$this->client = new Client();
}

return $this->client;
Expand Down
21 changes: 7 additions & 14 deletions Client/Client.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,23 +7,21 @@
class Client implements ClientInterface
{
/**
* Additional configuration for Guzzle Client.
* For example @link http://docs.guzzlephp.org/en/stable/request-options.html#verify
* @var array
* @var string
*/
protected $config = [];
private $baseUrl = 'https://sms.ru/{method}';

/**
* @var string
* @var Client
*/
private $baseUrl = 'https://sms.ru/{method}';
private $client;

/**
* @param array $config
* @param array $config Additional configuration for Guzzle Client
*/
public function __construct($config = [])
{
$this->config = $config;
$this->client = new \GuzzleHttp\Client($config);
}

/**
Expand All @@ -36,12 +34,7 @@ public function __construct($config = [])
*/
public function request($method, $params = [])
{
$client = new \GuzzleHttp\Client();

// Merge with specific config
$params = array_merge($this->config, ['query' => $params]);

$response = $client->post($this->getUrl($method), $params);
$response = $this->client->post($this->getUrl($method), ['query' => $params]);

if ($response->getStatusCode() === 200) {
return (string)$response->getBody();
Expand Down
6 changes: 0 additions & 6 deletions Client/ClientInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,6 @@
interface ClientInterface
{

/**
* Provides an additional configs for client service
* @param array $config
*/
public function __construct($config = []);

/**
* @param string $method
* @param array $params
Expand Down

0 comments on commit 19599c3

Please sign in to comment.