@@ -23,7 +23,7 @@ class Guzzle implements AdapterInterface
2323
2424 /** @var string Base URI for requests */
2525 private $ baseURI ;
26-
26+
2727 /** @var bool SSL verification flag */
2828 protected $ ssl = true ;
2929
@@ -39,7 +39,7 @@ public function __construct(AuthInterface $auth, ?string $baseURI = null)
3939 $ this ->headers = array_merge ($ auth ->getHeaders (), [
4040 'Accept ' => 'application/x-www-form-urlencoded ' ,
4141 ]);
42-
42+
4343 $ this ->initClient ();
4444 }
4545
@@ -55,6 +55,17 @@ private function initClient(): void
5555 ]);
5656 }
5757
58+ /**
59+ * Set base URL.
60+ *
61+ * @param string $baseURI https://...........
62+ */
63+ public function setBaseUri (string $ baseURI ): void
64+ {
65+ $ this ->baseURI = $ baseURI ;
66+ $ this ->initClient ();
67+ }
68+
5869 /**
5970 * Set SSL verification status.
6071 *
@@ -97,52 +108,51 @@ public function delete(string $uri, array $data = [], array $headers = []): Resp
97108 }
98109
99110 /**
100- * Sends an HTTP request.
101- *
102- * @param string $method The HTTP request method (GET, POST, PUT, PATCH, DELETE).
103- * @param string $uri The API endpoint URI.
104- * @param array $data The request payload.
105- * @param array $headers Additional headers for the request.
106- * @throws InvalidArgumentException If an invalid HTTP method is specified.
107- * @throws RequestException If an error occurs while sending the request.
108- * @return ResponseInterface The response from the API.
109- */
110- public function request (string $ method , string $ uri , array $ data = [], array $ headers = []): ResponseInterface
111- {
112- $ method = strtolower ($ method );
111+ * Sends an HTTP request.
112+ *
113+ * @param string $method The HTTP request method (GET, POST, PUT, PATCH, DELETE).
114+ * @param string $uri The API endpoint URI.
115+ * @param array $data The request payload.
116+ * @param array $headers Additional headers for the request.
117+ * @throws InvalidArgumentException If an invalid HTTP method is specified.
118+ * @throws RequestException If an error occurs while sending the request.
119+ * @return ResponseInterface The response from the API.
120+ */
121+ public function request (string $ method , string $ uri , array $ data = [], array $ headers = []): ResponseInterface
122+ {
123+ $ method = strtolower ($ method );
113124
114- if (!in_array ($ method , ['get ' , 'post ' , 'put ' , 'patch ' , 'delete ' ], true )) {
115- throw new InvalidArgumentException ('Invalid HTTP method: ' . $ method );
116- }
125+ if (!in_array ($ method , ['get ' , 'post ' , 'put ' , 'patch ' , 'delete ' ], true )) {
126+ throw new InvalidArgumentException ('Invalid HTTP method: ' . $ method );
127+ }
117128
118- $ headers = array_merge ($ this ->headers , $ headers );
129+ $ headers = array_merge ($ this ->headers , $ headers );
119130
120- // Ensure Content-Type is set if JSON payload is provided
121- if (isset ($ data ['json ' ]) && !isset ($ headers ['Content-Type ' ])) {
122- $ headers ['Content-Type ' ] = 'application/json ' ;
123- }
131+ // Ensure Content-Type is set if JSON payload is provided
132+ if (isset ($ data ['json ' ]) && !isset ($ headers ['Content-Type ' ])) {
133+ $ headers ['Content-Type ' ] = 'application/json ' ;
134+ }
124135
125- $ options = ['headers ' => $ headers ];
126-
127- if ($ method === 'get ' ) {
128- $ options ['query ' ] = isset ($ data ['json ' ]) ? $ data ['json ' ] : $ data ;
129- } else {
130- if (isset ($ data ['json ' ])) {
131- $ options ['json ' ] = $ data ['json ' ];
132- } elseif (isset ($ data ['multipart ' ])) {
133- $ options ['multipart ' ] = [];
134- foreach ($ data ['multipart ' ] as $ name => $ content ) {
135- $ options ['multipart ' ][] = [
136- 'name ' => $ name ,
137- 'contents ' => $ content ,
138- ];
139- }
136+ $ options = ['headers ' => $ headers ];
137+
138+ if ($ method === 'get ' ) {
139+ $ options ['query ' ] = isset ($ data ['json ' ]) ? $ data ['json ' ] : $ data ;
140140 } else {
141- $ options ['form_params ' ] = $ data ;
141+ if (isset ($ data ['json ' ])) {
142+ $ options ['json ' ] = $ data ['json ' ];
143+ } elseif (isset ($ data ['multipart ' ])) {
144+ $ options ['multipart ' ] = [];
145+ foreach ($ data ['multipart ' ] as $ name => $ content ) {
146+ $ options ['multipart ' ][] = [
147+ 'name ' => $ name ,
148+ 'contents ' => $ content ,
149+ ];
150+ }
151+ } else {
152+ $ options ['form_params ' ] = $ data ;
153+ }
142154 }
143- }
144-
145- return $ this ->client ->request ($ method , $ uri , $ options );
146- }
147155
156+ return $ this ->client ->request ($ method , $ uri , $ options );
157+ }
148158}
0 commit comments