client = $client ?: new Client(); $this->config = $config ?: new Configuration(); $this->headerSelector = $selector ?: new HeaderSelector(); } /** * @return Configuration */ public function getConfig() { return $this->config; } /** * Operation getById * * Obtener modelos de cablemodem por id. * * @param string $id Id de modelo de cablemodem que quiere obtener. (required) * * @throws \Swagger\Client\ApiException on non-2xx response * @throws \InvalidArgumentException * @return \Swagger\Client\Cablemodem\Model\CablemodemModel */ public function getById($id) { list($response) = $this->getByIdWithHttpInfo($id); return $response; } /** * Operation getByIdWithHttpInfo * * Obtener modelos de cablemodem por id. * * @param string $id Id de modelo de cablemodem que quiere obtener. (required) * * @throws \Swagger\Client\ApiException on non-2xx response * @throws \InvalidArgumentException * @return array of \Swagger\Client\Cablemodem\Model\CablemodemModel, HTTP status code, HTTP response headers (array of strings) */ public function getByIdWithHttpInfo($id) { $returnType = '\Swagger\Client\Cablemodem\Model\CablemodemModel'; $request = $this->getByIdRequest($id); try { $options = $this->createHttpClientOption(); try { $response = $this->client->send($request, $options); } catch (RequestException $e) { throw new ApiException( "[{$e->getCode()}] {$e->getMessage()}", $e->getCode(), $e->getResponse() ? $e->getResponse()->getHeaders() : null, $e->getResponse() ? $e->getResponse()->getBody()->getContents() : null ); } $statusCode = $response->getStatusCode(); if ($statusCode < 200 || $statusCode > 299) { throw new ApiException( sprintf( '[%d] Error connecting to the API (%s)', $statusCode, $request->getUri() ), $statusCode, $response->getHeaders(), $response->getBody() ); } $responseBody = $response->getBody(); if ($returnType === '\SplFileObject') { $content = $responseBody; //stream goes to serializer } else { $content = $responseBody->getContents(); if ($returnType !== 'string') { $content = json_decode($content); } } return [ ObjectSerializer::deserialize( $this->getConfig()->getTempFolderPath(), $content, $returnType, []), $response->getStatusCode(), $response->getHeaders() ]; } catch (ApiException $e) { switch ($e->getCode()) { case 200: $data = ObjectSerializer::deserialize( $this->getConfig()->getTempFolderPath(), $e->getResponseBody(), '\Swagger\Client\Cablemodem\Model\CablemodemModel', $e->getResponseHeaders() ); $e->setResponseObject($data); break; } throw $e; } } /** * Operation getByIdAsync * * Obtener modelos de cablemodem por id. * * @param string $id Id de modelo de cablemodem que quiere obtener. (required) * * @throws \InvalidArgumentException * @return \GuzzleHttp\Promise\PromiseInterface */ public function getByIdAsync($id) { return $this->getByIdAsyncWithHttpInfo($id) ->then( function ($response) { return $response[0]; } ); } /** * Operation getByIdAsyncWithHttpInfo * * Obtener modelos de cablemodem por id. * * @param string $id Id de modelo de cablemodem que quiere obtener. (required) * * @throws \InvalidArgumentException * @return \GuzzleHttp\Promise\PromiseInterface */ public function getByIdAsyncWithHttpInfo($id) { $returnType = '\Swagger\Client\Cablemodem\Model\CablemodemModel'; $request = $this->getByIdRequest($id); return $this->client ->sendAsync($request, $this->createHttpClientOption()) ->then( function ($response) use ($returnType) { $responseBody = $response->getBody(); if ($returnType === '\SplFileObject') { $content = $responseBody; //stream goes to serializer } else { $content = $responseBody->getContents(); if ($returnType !== 'string') { $content = json_decode($content); } } return [ ObjectSerializer::deserialize( $this->getConfig()->getTempFolderPath(), $content, $returnType, []), $response->getStatusCode(), $response->getHeaders() ]; }, function ($exception) { $response = $exception->getResponse(); $statusCode = $response->getStatusCode(); throw new ApiException( sprintf( '[%d] Error connecting to the API (%s)', $statusCode, $exception->getRequest()->getUri() ), $statusCode, $response->getHeaders(), $response->getBody() ); } ); } /** * Create request for operation 'getById' * * @param string $id Id de modelo de cablemodem que quiere obtener. (required) * * @throws \InvalidArgumentException * @return \GuzzleHttp\Psr7\Request */ protected function getByIdRequest($id) { // verify the required parameter 'id' is set if ($id === null || (is_array($id) && count($id) === 0)) { throw new \InvalidArgumentException( 'Missing the required parameter $id when calling getById' ); } $resourcePath = '/cablemodemmodels/{id}.json'; $formParams = []; $queryParams = []; $headerParams = []; $httpBody = ''; $multipart = false; // path params if ($id !== null) { $resourcePath = str_replace( '{' . 'id' . '}', ObjectSerializer::toPathValue($id), $resourcePath ); } // body params $_tempBody = null; if ($multipart) { $headers = $this->headerSelector->selectHeadersForMultipart( ['application/json'] ); } else { $headers = $this->headerSelector->selectHeaders( ['application/json'], [] ); } // for model (json/xml) if (isset($_tempBody)) { // $_tempBody is the method argument, if present $httpBody = $_tempBody; // \stdClass has no __toString(), so we should encode it manually if ($httpBody instanceof \stdClass && $headers['Content-Type'] === 'application/json') { $httpBody = \GuzzleHttp\json_encode($httpBody); } } elseif (count($formParams) > 0) { if ($multipart) { $multipartContents = []; foreach ($formParams as $formParamName => $formParamValue) { $multipartContents[] = [ 'name' => $formParamName, 'contents' => $formParamValue ]; } // for HTTP post (form) $httpBody = new MultipartStream($multipartContents); } elseif ($headers['Content-Type'] === 'application/json') { $httpBody = \GuzzleHttp\json_encode($formParams); } else { // for HTTP post (form) $httpBody = \GuzzleHttp\Psr7\build_query($formParams); } } // this endpoint requires HTTP basic authentication if ($this->config->getUsername() !== null || $this->config->getPassword() !== null) { $headers['Authorization'] = 'Basic ' . base64_encode($this->config->getUsername() . ":" . $this->config->getPassword()); } $defaultHeaders = []; if ($this->config->getUserAgent()) { $defaultHeaders['User-Agent'] = $this->config->getUserAgent(); } $headers = array_merge( $defaultHeaders, $headerParams, $headers ); $query = \GuzzleHttp\Psr7\build_query($queryParams); return new Request( 'GET', $this->config->getHost() . $resourcePath . ($query ? "?{$query}" : ''), $headers, $httpBody ); } /** * Operation getList * * Obtener modelos de cablemodem por id o nombre. * * @param int $filters_id Id del modelo de cablemodem que quiere obtener. (optional) * @param string $filters_name Nombre del modelo de cablemodem que quiere obtener. (optional) * @param int $filters_qb_criteria Criteria true. (optional, default to 1) * @param int $limit Cantidad de registros por página. (optional, default to 20) * @param int $page Número de página a buscar. (optional, default to 0) * * @throws \Swagger\Client\ApiException on non-2xx response * @throws \InvalidArgumentException * @return \Swagger\Client\Cablemodem\Model\CablemodemModel[] */ public function getList($filters_id = null, $filters_name = null, $filters_qb_criteria = '1', $limit = '20', $page = '0') { list($response) = $this->getListWithHttpInfo($filters_id, $filters_name, $filters_qb_criteria, $limit, $page); return $response; } /** * Operation getListWithHttpInfo * * Obtener modelos de cablemodem por id o nombre. * * @param int $filters_id Id del modelo de cablemodem que quiere obtener. (optional) * @param string $filters_name Nombre del modelo de cablemodem que quiere obtener. (optional) * @param int $filters_qb_criteria Criteria true. (optional, default to 1) * @param int $limit Cantidad de registros por página. (optional, default to 20) * @param int $page Número de página a buscar. (optional, default to 0) * * @throws \Swagger\Client\ApiException on non-2xx response * @throws \InvalidArgumentException * @return array of \Swagger\Client\Cablemodem\Model\CablemodemModel[], HTTP status code, HTTP response headers (array of strings) */ public function getListWithHttpInfo($filters_id = null, $filters_name = null, $filters_qb_criteria = '1', $limit = '20', $page = '0') { $returnType = '\Swagger\Client\Cablemodem\Model\CablemodemModel[]'; $request = $this->getListRequest($filters_id, $filters_name, $filters_qb_criteria, $limit, $page); try { $options = $this->createHttpClientOption(); try { $response = $this->client->send($request, $options); } catch (RequestException $e) { throw new ApiException( "[{$e->getCode()}] {$e->getMessage()}", $e->getCode(), $e->getResponse() ? $e->getResponse()->getHeaders() : null, $e->getResponse() ? $e->getResponse()->getBody()->getContents() : null ); } $statusCode = $response->getStatusCode(); if ($statusCode < 200 || $statusCode > 299) { throw new ApiException( sprintf( '[%d] Error connecting to the API (%s)', $statusCode, $request->getUri() ), $statusCode, $response->getHeaders(), $response->getBody() ); } $responseBody = $response->getBody(); if ($returnType === '\SplFileObject') { $content = $responseBody; //stream goes to serializer } else { $content = $responseBody->getContents(); if ($returnType !== 'string') { $content = json_decode($content); } } return [ ObjectSerializer::deserialize( $this->getConfig()->getTempFolderPath(), $content, $returnType, []), $response->getStatusCode(), $response->getHeaders() ]; } catch (ApiException $e) { switch ($e->getCode()) { case 200: $data = ObjectSerializer::deserialize( $this->getConfig()->getTempFolderPath(), $e->getResponseBody(), '\Swagger\Client\Cablemodem\Model\CablemodemModel[]', $e->getResponseHeaders() ); $e->setResponseObject($data); break; } throw $e; } } /** * Operation getListAsync * * Obtener modelos de cablemodem por id o nombre. * * @param int $filters_id Id del modelo de cablemodem que quiere obtener. (optional) * @param string $filters_name Nombre del modelo de cablemodem que quiere obtener. (optional) * @param int $filters_qb_criteria Criteria true. (optional, default to 1) * @param int $limit Cantidad de registros por página. (optional, default to 20) * @param int $page Número de página a buscar. (optional, default to 0) * * @throws \InvalidArgumentException * @return \GuzzleHttp\Promise\PromiseInterface */ public function getListAsync($filters_id = null, $filters_name = null, $filters_qb_criteria = '1', $limit = '20', $page = '0') { return $this->getListAsyncWithHttpInfo($filters_id, $filters_name, $filters_qb_criteria, $limit, $page) ->then( function ($response) { return $response[0]; } ); } /** * Operation getListAsyncWithHttpInfo * * Obtener modelos de cablemodem por id o nombre. * * @param int $filters_id Id del modelo de cablemodem que quiere obtener. (optional) * @param string $filters_name Nombre del modelo de cablemodem que quiere obtener. (optional) * @param int $filters_qb_criteria Criteria true. (optional, default to 1) * @param int $limit Cantidad de registros por página. (optional, default to 20) * @param int $page Número de página a buscar. (optional, default to 0) * * @throws \InvalidArgumentException * @return \GuzzleHttp\Promise\PromiseInterface */ public function getListAsyncWithHttpInfo($filters_id = null, $filters_name = null, $filters_qb_criteria = '1', $limit = '20', $page = '0') { $returnType = '\Swagger\Client\Cablemodem\Model\CablemodemModel[]'; $request = $this->getListRequest($filters_id, $filters_name, $filters_qb_criteria, $limit, $page); return $this->client ->sendAsync($request, $this->createHttpClientOption()) ->then( function ($response) use ($returnType) { $responseBody = $response->getBody(); if ($returnType === '\SplFileObject') { $content = $responseBody; //stream goes to serializer } else { $content = $responseBody->getContents(); if ($returnType !== 'string') { $content = json_decode($content); } } return [ ObjectSerializer::deserialize( $this->getConfig()->getTempFolderPath(), $content, $returnType, []), $response->getStatusCode(), $response->getHeaders() ]; }, function ($exception) { $response = $exception->getResponse(); $statusCode = $response->getStatusCode(); throw new ApiException( sprintf( '[%d] Error connecting to the API (%s)', $statusCode, $exception->getRequest()->getUri() ), $statusCode, $response->getHeaders(), $response->getBody() ); } ); } /** * Create request for operation 'getList' * * @param int $filters_id Id del modelo de cablemodem que quiere obtener. (optional) * @param string $filters_name Nombre del modelo de cablemodem que quiere obtener. (optional) * @param int $filters_qb_criteria Criteria true. (optional, default to 1) * @param int $limit Cantidad de registros por página. (optional, default to 20) * @param int $page Número de página a buscar. (optional, default to 0) * * @throws \InvalidArgumentException * @return \GuzzleHttp\Psr7\Request */ protected function getListRequest($filters_id = null, $filters_name = null, $filters_qb_criteria = '1', $limit = '20', $page = '0') { $resourcePath = '/cablemodemmodels.json'; $formParams = []; $queryParams = []; $headerParams = []; $httpBody = ''; $multipart = false; // query params if ($filters_id !== null) { $queryParams['filters[id]'] = ObjectSerializer::toQueryValue($filters_id); } // query params if ($filters_name !== null) { $queryParams['filters[name]'] = ObjectSerializer::toQueryValue($filters_name); } // query params if ($filters_qb_criteria !== null) { $queryParams['filters[qb-criteria]'] = ObjectSerializer::toQueryValue($filters_qb_criteria); } // query params if ($limit !== null) { $queryParams['limit'] = ObjectSerializer::toQueryValue($limit); } // query params if ($page !== null) { $queryParams['page'] = ObjectSerializer::toQueryValue($page) * ObjectSerializer::toQueryValue($limit); } // body params $_tempBody = null; if ($multipart) { $headers = $this->headerSelector->selectHeadersForMultipart( ['application/json'] ); } else { $headers = $this->headerSelector->selectHeaders( ['application/json'], [] ); } // for model (json/xml) if (isset($_tempBody)) { // $_tempBody is the method argument, if present $httpBody = $_tempBody; // \stdClass has no __toString(), so we should encode it manually if ($httpBody instanceof \stdClass && $headers['Content-Type'] === 'application/json') { $httpBody = \GuzzleHttp\json_encode($httpBody); } } elseif (count($formParams) > 0) { if ($multipart) { $multipartContents = []; foreach ($formParams as $formParamName => $formParamValue) { $multipartContents[] = [ 'name' => $formParamName, 'contents' => $formParamValue ]; } // for HTTP post (form) $httpBody = new MultipartStream($multipartContents); } elseif ($headers['Content-Type'] === 'application/json') { $httpBody = \GuzzleHttp\json_encode($formParams); } else { // for HTTP post (form) $httpBody = \GuzzleHttp\Psr7\build_query($formParams); } } // this endpoint requires HTTP basic authentication if ($this->config->getUsername() !== null || $this->config->getPassword() !== null) { $headers['Authorization'] = 'Basic ' . base64_encode($this->config->getUsername() . ":" . $this->config->getPassword()); } $defaultHeaders = []; if ($this->config->getUserAgent()) { $defaultHeaders['User-Agent'] = $this->config->getUserAgent(); } $headers = array_merge( $defaultHeaders, $headerParams, $headers ); $query = \GuzzleHttp\Psr7\build_query($queryParams); return new Request( 'GET', $this->config->getHost() . $resourcePath . ($query ? "?{$query}" : ''), $headers, $httpBody ); } /** * Create http client option * * @throws \RuntimeException on file opening failure * @return array of http client options */ protected function createHttpClientOption() { $options = []; if ($this->config->getDebug()) { $options[RequestOptions::DEBUG] = fopen($this->config->getDebugFile(), 'a'); if (!$options[RequestOptions::DEBUG]) { throw new \RuntimeException('Failed to open the debug file: ' . $this->config->getDebugFile()); } } return $options; } }