All Downloads are FREE. Search and download functionalities are using the official Maven repository.

php.api.mustache Maven / Gradle / Ivy

There is a newer version: 3.0.0-rc1
Show newest version
getConfig()->setHost('{{basePath}}');
        }
  
        $this->apiClient = $apiClient;
    }
  
    /**
     * Get API client
     * @return \{{invokerPackage}}\ApiClient get the API client
     */
    public function getApiClient()
    {
        return $this->apiClient;
    }
  
    /**
     * Set the API client
     * @param \{{invokerPackage}}\ApiClient $apiClient set the API client
     * @return {{classname}}
     */
    public function setApiClient(ApiClient $apiClient)
    {
        $this->apiClient = $apiClient;
        return $this;
    }
  
    {{#operation}}
    /**
     * {{{nickname}}}
     *
     * {{{summary}}}
     *
  {{#allParams}}   * @param {{dataType}} ${{paramName}} {{description}} {{#required}}(required){{/required}}{{^required}}(optional){{/required}}
  {{/allParams}}   * @return {{#returnType}}{{{returnType}}}{{/returnType}}{{^returnType}}void{{/returnType}}
     * @throws \{{invokerPackage}}\ApiException on non-2xx response
     */
    public function {{nickname}}({{#allParams}}${{paramName}}{{^required}}=null{{/required}}{{#hasMore}}, {{/hasMore}}{{/allParams}})
    {
        {{#allParams}}{{#required}}
        // verify the required parameter '{{paramName}}' is set
        if (${{paramName}} === null) {
            throw new \InvalidArgumentException('Missing the required parameter ${{paramName}} when calling {{nickname}}');
        }{{/required}}{{/allParams}}
  
        // parse inputs
        $resourcePath = "{{path}}";
        $resourcePath = str_replace("{format}", "json", $resourcePath);
        $method = "{{httpMethod}}";
        $httpBody = '';
        $queryParams = array();
        $headerParams = array();
        $formParams = array();
        $_header_accept = ApiClient::selectHeaderAccept(array({{#produces}}'{{mediaType}}'{{#hasMore}}, {{/hasMore}}{{/produces}}));
        if (!is_null($_header_accept)) {
            $headerParams['Accept'] = $_header_accept;
        }
        $headerParams['Content-Type'] = ApiClient::selectHeaderContentType(array({{#consumes}}'{{mediaType}}'{{#hasMore}},{{/hasMore}}{{/consumes}}));
  
        {{#queryParams}}// query params
        if (${{paramName}} !== null) {
            $queryParams['{{baseName}}'] = $this->apiClient->getSerializer()->toQueryValue(${{paramName}});
        }{{/queryParams}}
        {{#headerParams}}// header params
        if (${{paramName}} !== null) {
            $headerParams['{{baseName}}'] = $this->apiClient->getSerializer()->toHeaderValue(${{paramName}});
        }{{/headerParams}}
        {{#pathParams}}// path params
        if (${{paramName}} !== null) {
            $resourcePath = str_replace(
                "{" . "{{baseName}}" . "}",
                $this->apiClient->getSerializer()->toPathValue(${{paramName}}),
                $resourcePath
            );
        }{{/pathParams}}
        {{#formParams}}// form params
        if (${{paramName}} !== null) {
            $formParams['{{baseName}}'] = {{#isFile}}'@' . {{/isFile}}$this->apiClient->getSerializer()->toFormValue(${{paramName}});
        }{{/formParams}}
        {{#bodyParams}}// body params
        $_tempBody = null;
        if (isset(${{paramName}})) {
            $_tempBody = ${{paramName}};
        }{{/bodyParams}}
  
        // for model (json/xml)
        if (isset($_tempBody)) {
            $httpBody = $_tempBody; // $_tempBody is the method argument, if present
        } else if (count($formParams) > 0) {
            $httpBody = $formParams; // for HTTP post (form)
        }
        {{#authMethods}}{{#isApiKey}}
        $apiKey = $this->apiClient->getApiKeyWithPrefix('{{keyParamName}}');
        if (isset($apiKey)) {
            {{#isKeyInHeader}}$headerParams['{{keyParamName}}'] = $apiKey;{{/isKeyInHeader}}{{#isKeyInQuery}}$queryParams['{{keyParamName}}'] = $apiKey;{{/isKeyInQuery}}
        }{{/isApiKey}}
        {{#isBasic}}$headerParams['Authorization'] = 'Basic '.base64_encode($this->apiClient->getConfig()->getUsername().":".$this->apiClient->getConfig()->getPassword());{{/isBasic}}
        {{#isOAuth}}//TODO support oauth{{/isOAuth}}
        {{/authMethods}}
        // make the API Call
        try
        {
            list($response, $httpHeader) = $this->apiClient->callApi(
                $resourcePath, $method,
                $queryParams, $httpBody,
                $headerParams{{#returnType}}, '{{returnType}}'{{/returnType}}
            );
        } catch (ApiException $e) {
            switch ($e->getCode()) { {{#responses}}{{#dataType}}
            case {{code}}:
                $data = $this->apiClient->getSerializer()->deserialize($e->getResponseBody(), '{{dataType}}', $httpHeader);
                $e->setResponseObject($data);
                break;{{/dataType}}{{/responses}}
            }
  
            throw $e;
        }
        {{#returnType}}
        if (!$response) {
            return null;
        }
  
        return $this->apiClient->getSerializer()->deserialize($response, '{{returnType}}');
        {{/returnType}}
    }
    {{/operation}}
}
{{/operations}}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy