Skip to content

Commit 422418a

Browse files
committed
Refactor Client
1 parent 9bc1669 commit 422418a

File tree

1 file changed

+36
-23
lines changed

1 file changed

+36
-23
lines changed

lib/ApiClient/Http/Client.php

Lines changed: 36 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -58,29 +58,14 @@ private function execute(
5858
array $formData = []
5959
): Response {
6060
try {
61-
if ($formData) {
62-
/** @var GuzzleResponse $response */
63-
$guzzleResponse = $this->guzzle->request(
64-
$method,
65-
$url,
66-
[
67-
'headers' => $headers,
68-
'form_params' => $formData,
69-
'timeout' => 30
70-
]
71-
);
72-
} else {
73-
/** @var GuzzleResponse $response */
74-
$guzzleResponse = $this->guzzle->request(
75-
$method,
76-
$url,
77-
[
78-
'headers' => $headers,
79-
'body' => $content,
80-
'timeout' => 30
81-
]
82-
);
83-
}
61+
$guzzleResponse = $this->doExecute(
62+
$method,
63+
$url,
64+
$headers,
65+
$content,
66+
$formData
67+
);
68+
8469
} catch (ConnectException $e) {
8570
if (str_contains($e->getMessage(), 'cURL error 28')) {
8671
throw new HttpTimeOutException();
@@ -100,4 +85,32 @@ private function execute(
10085
$guzzleResponse->getHeaders()
10186
);
10287
}
88+
89+
private function doExecute(
90+
string $method,
91+
string $url,
92+
array $headers,
93+
?string $content,
94+
array $formData
95+
): GuzzleResponse {
96+
$requestData = [
97+
'headers' => $headers,
98+
'timeout' => 30
99+
];
100+
101+
if ($formData) {
102+
$requestData['form_params'] = $formData;
103+
} else {
104+
$requestData['body'] = $content;
105+
}
106+
107+
/** @var GuzzleResponse $response */
108+
$guzzleResponse = $this->guzzle->request(
109+
$method,
110+
$url,
111+
$requestData
112+
);
113+
114+
return $guzzleResponse;
115+
}
103116
}

0 commit comments

Comments
 (0)