/** * Constructor. Sets the configuration for this Omeda API client instance. * * @param Configuration $config The config options. */ public function __construct(Configuration $config) { $this->config = $config; if (false === $this->hasValidConfig()) { throw ApiClientException::invalidConfiguration($this->requiredConfigOptions); } $this->initClient(); }
/** * Creates a new request object based on API method parameters. * * @param string $endpoint The API endpoint. * @param mixed $content The request body content to use. * @param string $method The request method. * @param bool $clientCall Whether this is an API that applies to the entire customer/client. * @return \GuzzleHttp\Message\Request * @throws ApiClientException If a non-supported request method is passed. */ protected function createRequest($endpoint, $content = null, $method = 'GET', $clientCall = false) { $method = strtoupper($method); if (!in_array($method, $this->supportedMethods)) { // Request method not allowed by the API throw ApiClientException::invalidRequestMethod($method, $this->supportedMethods); } $options = []; if (in_array($method, ['POST', 'PUT'])) { // Handle the request body content if (is_scalar($content)) { $content = (string) $content; } elseif (is_array($content)) { $content = @json_encode($content); } $options['body'] = $content; $options['headers'] = ['X-Omeda-Inputid' => $this->getInputId(), 'Content-Type' => 'application/json']; } return $this->client->createRequest($method, $this->getEndpoint($endpoint, $clientCall), $options); }