Skip to content

Commit 4118b03

Browse files
committed
Change client facotry
1 parent 5d65382 commit 4118b03

File tree

3 files changed

+9
-23
lines changed

3 files changed

+9
-23
lines changed

src/Chatwork.php

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
use Polidog\Chatwork\Api\Me;
99
use Polidog\Chatwork\Api\My;
1010
use Polidog\Chatwork\Api\Rooms;
11+
use Polidog\Chatwork\Client\Client;
1112
use Polidog\Chatwork\Client\ClientFactory;
1213
use Polidog\Chatwork\Client\ClientInterface;
1314
use Polidog\Chatwork\Entity\Factory\RoomFactory;
@@ -50,8 +51,8 @@ public function rooms(): Rooms
5051
return new Api\Rooms($this->client, new RoomFactory());
5152
}
5253

53-
public static function create(string $token, string $version = 'v2', array $httpOptions = []): self
54+
public static function create(string $token, string $version = 'v2'): self
5455
{
55-
return new self(ClientFactory::create($token, $version, $httpOptions));
56+
return new self(new Client($token, $version, null));
5657
}
5758
}

src/Client/Client.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@
88
use GuzzleHttp\Exception\GuzzleException;
99
use GuzzleHttp\Middleware;
1010
use Polidog\Chatwork\Exception\ClientException;
11-
use Psr\Http\Message\RequestInterface;
1211

1312
final class Client implements ClientInterface
1413
{
@@ -29,10 +28,11 @@ final class Client implements ClientInterface
2928
public function __construct(
3029
string $chatworkToken,
3130
string $apiVersion,
32-
?HttpClientInterface $httpClient = null
31+
?HttpClientInterface $httpClient = null,
32+
array $httpOptions = []
3333
) {
3434
if ($httpClient === null) {
35-
$httpClient = ClientFactory::createHttpClient($chatworkToken);
35+
$httpClient = ClientFactory::createHttpClient($chatworkToken, [], $httpOptions);
3636
}
3737
$this->apiVersion = $apiVersion;
3838
$this->httpClient = $httpClient;

src/Client/ClientFactory.php

Lines changed: 3 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
namespace Polidog\Chatwork\Client;
66

7+
use GuzzleHttp\Handler\CurlHandler;
78
use GuzzleHttp\HandlerStack;
89
use GuzzleHttp\Middleware;
910
use Psr\Http\Message\RequestInterface;
@@ -27,32 +28,16 @@ final class ClientFactory
2728
],
2829
];
2930

30-
/**
31-
* @deprecated
32-
*
33-
* @param string $token
34-
* @param string $version
35-
* @param array $httpOptions
36-
* @return ClientInterface
37-
*/
38-
public static function create(string $token, string $version, array $httpOptions = []): ClientInterface
39-
{
40-
$httpOptions = array_merge(self::$httpOptions, $httpOptions);
41-
42-
return new Client($token, $version, new \GuzzleHttp\Client($httpOptions));
43-
}
44-
4531
public static function createHttpClient(string $chatworkToken, array $middlewares = []): \GuzzleHttp\Client
4632
{
4733
$stack = new HandlerStack();
34+
$stack->setHandler(new CurlHandler());
4835
$stack->push(Middleware::mapRequest(static fn (RequestInterface $request) => $request->withHeader('X-ChatWorkToken', $chatworkToken)));
4936
foreach ($middlewares as $middleware) {
5037
$stack->push($middleware);
5138
}
5239

53-
$options = array_merge(self::$httpOptions, [
54-
'handler' => $stack,
55-
]);
40+
$options = array_merge(self::$httpOptions, ['handler' => $stack]);
5641
return new \GuzzleHttp\Client($options);
5742
}
5843
}

0 commit comments

Comments
 (0)