getClient()->post($url, $this->getPreparedOptions($options, $data)); } catch (BadResponseException $e) { return $e->getResponse(); } } /** * Returns guzzle client if set or creates a new instance and returns it * @return Client */ public function getClient(): Client { if ($this->client === null) { $this->client = new Client(); } return $this->client; } /** * @param Client $client */ public function setClient(Client $client) { $this->client = $client; } /** * @param $options * @param $data * @return array */ protected function getPreparedOptions($options, $data) { $options[RequestOptions::JSON] = $data; if (!isset($options['timeout'])) { $options['timeout'] = self::DEFAULT_REQUEST_TIMEOUT; } if (!isset($options['connect_timeout'])) { $options['connect_timeout'] = self::DEFAULT_REQUEST_TIMEOUT; } return $options; } }