java/src/main/java/com/konfigthis/newscatcherapi/client/api/SearchApi.java
<filename>java/src/main/java/com/konfigthis/newscatcherapi/client/api/SearchApi.java/*
 * NewsCatcher News API V2
 * NewsCatcher is a data-as-a-service startup that has one main goal: to build the largest database of structured news articles published online. In other words, we're like Google for the news part of the web, which you can access as a source of data.  Some useful links: - [How NewsCatcher Works](https://docs.newscatcherapi.com/knowledge-base/how-newscatcher-works) - [GitHub for the Python SDK](https://github.com/NewscatcherAPI/newscatcherapi-sdk-python) 
 *
 * The version of the OpenAPI document: 1.0.1
 * Contact: anpch@example.com
 *
 * NOTE: This class is auto generated by Konfig (https://konfigthis.com).
 * Do not edit the class manually.
 */


package com.konfigthis.newscatcherapi.client.api;

import com.konfigthis.newscatcherapi.client.ApiCallback;
import com.konfigthis.newscatcherapi.client.ApiClient;
import com.konfigthis.newscatcherapi.client.ApiException;
import com.konfigthis.newscatcherapi.client.ApiResponse;
import com.konfigthis.newscatcherapi.client.Configuration;
import com.konfigthis.newscatcherapi.client.Pair;
import com.konfigthis.newscatcherapi.client.ProgressRequestBody;
import com.konfigthis.newscatcherapi.client.ProgressResponseBody;

import com.google.gson.reflect.TypeToken;

import java.io.IOException;


import com.konfigthis.newscatcherapi.client.model.ErrorResponse;
import com.konfigthis.newscatcherapi.client.model.Model200Response;
import com.konfigthis.newscatcherapi.client.model.PublishDatePrecision;
import com.konfigthis.newscatcherapi.client.model.Search;
import com.konfigthis.newscatcherapi.client.model.SearchIn;
import com.konfigthis.newscatcherapi.client.model.SortBy;
import com.konfigthis.newscatcherapi.client.model.Topic;

import java.lang.reflect.Type;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import javax.ws.rs.core.GenericType;

public class SearchApi {
    private ApiClient localVarApiClient;
    private int localHostIndex;
    private String localCustomBaseUrl;

    public SearchApi() {
        this(Configuration.getDefaultApiClient());
    }

    public SearchApi(ApiClient apiClient) {
        this.localVarApiClient = apiClient;
    }

    public ApiClient getApiClient() {
        return localVarApiClient;
    }

    public void setApiClient(ApiClient apiClient) {
        this.localVarApiClient = apiClient;
    }

    public int getHostIndex() {
        return localHostIndex;
    }

    public void setHostIndex(int hostIndex) {
        this.localHostIndex = hostIndex;
    }

    public String getCustomBaseUrl() {
        return localCustomBaseUrl;
    }

    public void setCustomBaseUrl(String customBaseUrl) {
        this.localCustomBaseUrl = customBaseUrl;
    }

    /**
     * Build call for get
     * @param q Keyword/keywords you&#39;re searching for. This is the most important part of your query. Please, refer to the **Advanced Query Parameter** section below of the docs for more examples and explanations  (required)
     * @param lang Specifies the languages of the search. For example: &#x60;en&#x60;. The only accepted format is [ISO 639-1 — 2](https://en.wikipedia.org/wiki/ISO_639-1) letter code.  (optional)
     * @param notLang Inverse to the &#x60;lang&#x60; parameter  (optional)
     * @param publishedDatePrecision There are 3 types of date precision we define: &#x60;full&#x60; — day and time of an article is correctly identified with the appropriate timezone &#x60;timezone unknown&#x60; — day and time of an article is correctly identified without timezone &#x60;date&#x60; — only the day is identified without an exact time  (optional)
     * @param from &#x60;YYYY/mm/dd&#x60; From which point in time to start the search. The default timezone is UTC. Defaults to the past week.  (optional)
     * @param to &#x60;YYYY/mm/dd&#x60; Until which point in time to search for. The default timezone is UTC.  (optional)
     * @param searchIn By default, we search what you specified in the &#x60;q&#x60; parameter in both &#x60;title&#x60; and &#x60;summary&#x60; of the article. However, you can limit this to either &#x60;title&#x60; or &#x60;summary&#x60;  (optional)
     * @param countries Countries where the news publisher is located. **Important**: This parameter is not responsible for the countries mentioned in the news article. One or multiple countries can be used in the search. The only acceptable format is [ISO 3166-1 alpha-2](https://en.wikipedia.org/wiki/ISO_3166-1_alpha-2) For example, &#x60;US,CA,MX&#x60; or just &#x60;US&#x60;  (optional)
     * @param notCountries The inverse of the &#x60;countries&#x60; parameter.  (optional)
     * @param topic Accepted values: &#x60;news&#x60;, &#x60;sport&#x60;, &#x60;tech&#x60;, &#x60;world&#x60;, &#x60;finance&#x60;, &#x60;politics&#x60;, &#x60;business&#x60;, &#x60;economics&#x60;, &#x60;entertainment&#x60;, &#x60;beauty&#x60;, &#x60;travel&#x60;, &#x60;music&#x60;, &#x60;food&#x60;, &#x60;science&#x60;, &#x60;gaming&#x60; The topic to which you want to restrict the articles of your choice. Not all news articles are assigned with a topic, therefore, we cannot guarantee that 100% of topics talking about technology will be assigned a tech label.  (optional)
     * @param sources One or more news resources to filter your search. It should be the normal form of the URL, For example: &#x60;nytimes.com,theguardian.com&#x60;  (optional)
     * @param notSources One or more sources to be excluded from the search. Comma-separated list. For example: &#x60;nytimes.com,cnn.com,wsj.com&#x60;  (optional)
     * @param rankedOnly Default: &#x60;True&#x60; Limit the search only for the sources which are in the top 1 million online websites. Unranked sources are assigned a rank that equals &#x60;999999&#x60;  (optional)
     * @param fromRank &#x60;[0:999999]&#x60; The lowest boundary of the rank of a news website to filter by. Important: lower rank means that a source is more popular  (optional)
     * @param toRank &#x60;[0:999999]&#x60; The upper boundary of the rank of a news website to filter by.  (optional)
     * @param sortBy &#x60;relevancy&#x60; (default value) — the most relevant results first &#x60;date&#x60; — the most recently published results first &#x60;rank&#x60; — the results from the highest-ranked sources first  (optional)
     * @param pageSize &#x60;[1:100]&#x60; How many articles to return per page.  (optional)
     * @param page The number of the page. Use it to scroll through the results. This parameter is used to paginate: scroll through results because one API response cannot return more than 100 articles.  (optional)
     * @param _callback Callback for upload/download progress
     * @return Call to execute
     * @throws ApiException If fail to serialize the request body object
     * @http.response.details
     <table summary="Response Details" border="1">
        <tr><td> Status Code </td><td> Description </td><td> Response Headers </td></tr>
        <tr><td> 200 </td><td> OK </td><td>  -  </td></tr>
        <tr><td> 400 </td><td> API is not put in headers </td><td>  -  </td></tr>
        <tr><td> 401 </td><td> API Key not found </td><td>  -  </td></tr>
        <tr><td> 406 </td><td> Wrong parameter has been used </td><td>  -  </td></tr>
        <tr><td> 408 </td><td> Request Timeout </td><td>  -  </td></tr>
        <tr><td> 429 </td><td> Concurrency violated </td><td>  -  </td></tr>
     </table>
     */
    public okhttp3.Call getCall(String q, String lang, String notLang, PublishDatePrecision publishedDatePrecision, String from, String to, SearchIn searchIn, String countries, String notCountries, Topic topic, String sources, String notSources, Boolean rankedOnly, Integer fromRank, Integer toRank, SortBy sortBy, Integer pageSize, Integer page, final ApiCallback _callback) throws ApiException {
        String basePath = null;
        // Operation Servers
        String[] localBasePaths = new String[] {  };

        // Determine Base Path to Use
        if (localCustomBaseUrl != null){
            basePath = localCustomBaseUrl;
        } else if ( localBasePaths.length > 0 ) {
            basePath = localBasePaths[localHostIndex];
        } else {
            basePath = null;
        }

        Object localVarPostBody = null;

        // create path and map variables
        String localVarPath = "/search";

        List<Pair> localVarQueryParams = new ArrayList<Pair>();
        List<Pair> localVarCollectionQueryParams = new ArrayList<Pair>();
        Map<String, String> localVarHeaderParams = new HashMap<String, String>();
        Map<String, String> localVarCookieParams = new HashMap<String, String>();
        Map<String, Object> localVarFormParams = new HashMap<String, Object>();

        if (q != null) {
            localVarQueryParams.addAll(localVarApiClient.parameterToPair("q", q));
        }

        if (lang != null) {
            localVarQueryParams.addAll(localVarApiClient.parameterToPair("lang", lang));
        }

        if (notLang != null) {
            localVarQueryParams.addAll(localVarApiClient.parameterToPair("not_lang", notLang));
        }

        if (publishedDatePrecision != null) {
            localVarQueryParams.addAll(localVarApiClient.parameterToPair("published_date_precision", publishedDatePrecision));
        }

        if (from != null) {
            localVarQueryParams.addAll(localVarApiClient.parameterToPair("from", from));
        }

        if (to != null) {
            localVarQueryParams.addAll(localVarApiClient.parameterToPair("to", to));
        }

        if (searchIn != null) {
            localVarQueryParams.addAll(localVarApiClient.parameterToPair("search_in", searchIn));
        }

        if (countries != null) {
            localVarQueryParams.addAll(localVarApiClient.parameterToPair("countries", countries));
        }

        if (notCountries != null) {
            localVarQueryParams.addAll(localVarApiClient.parameterToPair("not_countries", notCountries));
        }

        if (topic != null) {
            localVarQueryParams.addAll(localVarApiClient.parameterToPair("topic", topic));
        }

        if (sources != null) {
            localVarQueryParams.addAll(localVarApiClient.parameterToPair("sources", sources));
        }

        if (notSources != null) {
            localVarQueryParams.addAll(localVarApiClient.parameterToPair("not_sources", notSources));
        }

        if (rankedOnly != null) {
            localVarQueryParams.addAll(localVarApiClient.parameterToPair("ranked_only", rankedOnly));
        }

        if (fromRank != null) {
            localVarQueryParams.addAll(localVarApiClient.parameterToPair("from_rank", fromRank));
        }

        if (toRank != null) {
            localVarQueryParams.addAll(localVarApiClient.parameterToPair("to_rank", toRank));
        }

        if (sortBy != null) {
            localVarQueryParams.addAll(localVarApiClient.parameterToPair("sort_by", sortBy));
        }

        if (pageSize != null) {
            localVarQueryParams.addAll(localVarApiClient.parameterToPair("page_size", pageSize));
        }

        if (page != null) {
            localVarQueryParams.addAll(localVarApiClient.parameterToPair("page", page));
        }

        final String[] localVarAccepts = {
            "application/json"
        };
        final String localVarAccept = localVarApiClient.selectHeaderAccept(localVarAccepts);
        if (localVarAccept != null) {
            localVarHeaderParams.put("Accept", localVarAccept);
        }

        final String[] localVarContentTypes = {
        };
        final String localVarContentType = localVarApiClient.selectHeaderContentType(localVarContentTypes);
        if (localVarContentType != null) {
            localVarHeaderParams.put("Content-Type", localVarContentType);
        }

        String[] localVarAuthNames = new String[] { "api_key" };
        return localVarApiClient.buildCall(basePath, localVarPath, "GET", localVarQueryParams, localVarCollectionQueryParams, localVarPostBody, localVarHeaderParams, localVarCookieParams, localVarFormParams, localVarAuthNames, _callback);
    }

    @SuppressWarnings("rawtypes")
    private okhttp3.Call getValidateBeforeCall(String q, String lang, String notLang, PublishDatePrecision publishedDatePrecision, String from, String to, SearchIn searchIn, String countries, String notCountries, Topic topic, String sources, String notSources, Boolean rankedOnly, Integer fromRank, Integer toRank, SortBy sortBy, Integer pageSize, Integer page, final ApiCallback _callback) throws ApiException {
        // verify the required parameter 'q' is set
        if (q == null) {
            throw new ApiException("Missing the required parameter 'q' when calling get(Async)");
        }

        return getCall(q, lang, notLang, publishedDatePrecision, from, to, searchIn, countries, notCountries, topic, sources, notSources, rankedOnly, fromRank, toRank, sortBy, pageSize, page, _callback);

    }

    /**
     * Search for specific news articles
     * Main endpoint that allows you to find news article by keyword, date, language, country, etc.
     * @param q Keyword/keywords you&#39;re searching for. This is the most important part of your query. Please, refer to the **Advanced Query Parameter** section below of the docs for more examples and explanations  (required)
     * @param lang Specifies the languages of the search. For example: &#x60;en&#x60;. The only accepted format is [ISO 639-1 — 2](https://en.wikipedia.org/wiki/ISO_639-1) letter code.  (optional)
     * @param notLang Inverse to the &#x60;lang&#x60; parameter  (optional)
     * @param publishedDatePrecision There are 3 types of date precision we define: &#x60;full&#x60; — day and time of an article is correctly identified with the appropriate timezone &#x60;timezone unknown&#x60; — day and time of an article is correctly identified without timezone &#x60;date&#x60; — only the day is identified without an exact time  (optional)
     * @param from &#x60;YYYY/mm/dd&#x60; From which point in time to start the search. The default timezone is UTC. Defaults to the past week.  (optional)
     * @param to &#x60;YYYY/mm/dd&#x60; Until which point in time to search for. The default timezone is UTC.  (optional)
     * @param searchIn By default, we search what you specified in the &#x60;q&#x60; parameter in both &#x60;title&#x60; and &#x60;summary&#x60; of the article. However, you can limit this to either &#x60;title&#x60; or &#x60;summary&#x60;  (optional)
     * @param countries Countries where the news publisher is located. **Important**: This parameter is not responsible for the countries mentioned in the news article. One or multiple countries can be used in the search. The only acceptable format is [ISO 3166-1 alpha-2](https://en.wikipedia.org/wiki/ISO_3166-1_alpha-2) For example, &#x60;US,CA,MX&#x60; or just &#x60;US&#x60;  (optional)
     * @param notCountries The inverse of the &#x60;countries&#x60; parameter.  (optional)
     * @param topic Accepted values: &#x60;news&#x60;, &#x60;sport&#x60;, &#x60;tech&#x60;, &#x60;world&#x60;, &#x60;finance&#x60;, &#x60;politics&#x60;, &#x60;business&#x60;, &#x60;economics&#x60;, &#x60;entertainment&#x60;, &#x60;beauty&#x60;, &#x60;travel&#x60;, &#x60;music&#x60;, &#x60;food&#x60;, &#x60;science&#x60;, &#x60;gaming&#x60; The topic to which you want to restrict the articles of your choice. Not all news articles are assigned with a topic, therefore, we cannot guarantee that 100% of topics talking about technology will be assigned a tech label.  (optional)
     * @param sources One or more news resources to filter your search. It should be the normal form of the URL, For example: &#x60;nytimes.com,theguardian.com&#x60;  (optional)
     * @param notSources One or more sources to be excluded from the search. Comma-separated list. For example: &#x60;nytimes.com,cnn.com,wsj.com&#x60;  (optional)
     * @param rankedOnly Default: &#x60;True&#x60; Limit the search only for the sources which are in the top 1 million online websites. Unranked sources are assigned a rank that equals &#x60;999999&#x60;  (optional)
     * @param fromRank &#x60;[0:999999]&#x60; The lowest boundary of the rank of a news website to filter by. Important: lower rank means that a source is more popular  (optional)
     * @param toRank &#x60;[0:999999]&#x60; The upper boundary of the rank of a news website to filter by.  (optional)
     * @param sortBy &#x60;relevancy&#x60; (default value) — the most relevant results first &#x60;date&#x60; — the most recently published results first &#x60;rank&#x60; — the results from the highest-ranked sources first  (optional)
     * @param pageSize &#x60;[1:100]&#x60; How many articles to return per page.  (optional)
     * @param page The number of the page. Use it to scroll through the results. This parameter is used to paginate: scroll through results because one API response cannot return more than 100 articles.  (optional)
     * @return Model200Response
     * @throws ApiException If fail to call the API, e.g. server error or cannot deserialize the response body
     * @http.response.details
     <table summary="Response Details" border="1">
        <tr><td> Status Code </td><td> Description </td><td> Response Headers </td></tr>
        <tr><td> 200 </td><td> OK </td><td>  -  </td></tr>
        <tr><td> 400 </td><td> API is not put in headers </td><td>  -  </td></tr>
        <tr><td> 401 </td><td> API Key not found </td><td>  -  </td></tr>
        <tr><td> 406 </td><td> Wrong parameter has been used </td><td>  -  </td></tr>
        <tr><td> 408 </td><td> Request Timeout </td><td>  -  </td></tr>
        <tr><td> 429 </td><td> Concurrency violated </td><td>  -  </td></tr>
     </table>
     */
    public Model200Response get(String q, String lang, String notLang, PublishDatePrecision publishedDatePrecision, String from, String to, SearchIn searchIn, String countries, String notCountries, Topic topic, String sources, String notSources, Boolean rankedOnly, Integer fromRank, Integer toRank, SortBy sortBy, Integer pageSize, Integer page) throws ApiException {
        ApiResponse<Model200Response> localVarResp = getWithHttpInfo(q, lang, notLang, publishedDatePrecision, from, to, searchIn, countries, notCountries, topic, sources, notSources, rankedOnly, fromRank, toRank, sortBy, pageSize, page);
        return localVarResp.getData();
    }

    /**
     * Search for specific news articles
     * Main endpoint that allows you to find news article by keyword, date, language, country, etc.
     * @param q Keyword/keywords you&#39;re searching for. This is the most important part of your query. Please, refer to the **Advanced Query Parameter** section below of the docs for more examples and explanations  (required)
     * @param lang Specifies the languages of the search. For example: &#x60;en&#x60;. The only accepted format is [ISO 639-1 — 2](https://en.wikipedia.org/wiki/ISO_639-1) letter code.  (optional)
     * @param notLang Inverse to the &#x60;lang&#x60; parameter  (optional)
     * @param publishedDatePrecision There are 3 types of date precision we define: &#x60;full&#x60; — day and time of an article is correctly identified with the appropriate timezone &#x60;timezone unknown&#x60; — day and time of an article is correctly identified without timezone &#x60;date&#x60; — only the day is identified without an exact time  (optional)
     * @param from &#x60;YYYY/mm/dd&#x60; From which point in time to start the search. The default timezone is UTC. Defaults to the past week.  (optional)
     * @param to &#x60;YYYY/mm/dd&#x60; Until which point in time to search for. The default timezone is UTC.  (optional)
     * @param searchIn By default, we search what you specified in the &#x60;q&#x60; parameter in both &#x60;title&#x60; and &#x60;summary&#x60; of the article. However, you can limit this to either &#x60;title&#x60; or &#x60;summary&#x60;  (optional)
     * @param countries Countries where the news publisher is located. **Important**: This parameter is not responsible for the countries mentioned in the news article. One or multiple countries can be used in the search. The only acceptable format is [ISO 3166-1 alpha-2](https://en.wikipedia.org/wiki/ISO_3166-1_alpha-2) For example, &#x60;US,CA,MX&#x60; or just &#x60;US&#x60;  (optional)
     * @param notCountries The inverse of the &#x60;countries&#x60; parameter.  (optional)
     * @param topic Accepted values: &#x60;news&#x60;, &#x60;sport&#x60;, &#x60;tech&#x60;, &#x60;world&#x60;, &#x60;finance&#x60;, &#x60;politics&#x60;, &#x60;business&#x60;, &#x60;economics&#x60;, &#x60;entertainment&#x60;, &#x60;beauty&#x60;, &#x60;travel&#x60;, &#x60;music&#x60;, &#x60;food&#x60;, &#x60;science&#x60;, &#x60;gaming&#x60; The topic to which you want to restrict the articles of your choice. Not all news articles are assigned with a topic, therefore, we cannot guarantee that 100% of topics talking about technology will be assigned a tech label.  (optional)
     * @param sources One or more news resources to filter your search. It should be the normal form of the URL, For example: &#x60;nytimes.com,theguardian.com&#x60;  (optional)
     * @param notSources One or more sources to be excluded from the search. Comma-separated list. For example: &#x60;nytimes.com,cnn.com,wsj.com&#x60;  (optional)
     * @param rankedOnly Default: &#x60;True&#x60; Limit the search only for the sources which are in the top 1 million online websites. Unranked sources are assigned a rank that equals &#x60;999999&#x60;  (optional)
     * @param fromRank &#x60;[0:999999]&#x60; The lowest boundary of the rank of a news website to filter by. Important: lower rank means that a source is more popular  (optional)
     * @param toRank &#x60;[0:999999]&#x60; The upper boundary of the rank of a news website to filter by.  (optional)
     * @param sortBy &#x60;relevancy&#x60; (default value) — the most relevant results first &#x60;date&#x60; — the most recently published results first &#x60;rank&#x60; — the results from the highest-ranked sources first  (optional)
     * @param pageSize &#x60;[1:100]&#x60; How many articles to return per page.  (optional)
     * @param page The number of the page. Use it to scroll through the results. This parameter is used to paginate: scroll through results because one API response cannot return more than 100 articles.  (optional)
     * @return ApiResponse&lt;Model200Response&gt;
     * @throws ApiException If fail to call the API, e.g. server error or cannot deserialize the response body
     * @http.response.details
     <table summary="Response Details" border="1">
        <tr><td> Status Code </td><td> Description </td><td> Response Headers </td></tr>
        <tr><td> 200 </td><td> OK </td><td>  -  </td></tr>
        <tr><td> 400 </td><td> API is not put in headers </td><td>  -  </td></tr>
        <tr><td> 401 </td><td> API Key not found </td><td>  -  </td></tr>
        <tr><td> 406 </td><td> Wrong parameter has been used </td><td>  -  </td></tr>
        <tr><td> 408 </td><td> Request Timeout </td><td>  -  </td></tr>
        <tr><td> 429 </td><td> Concurrency violated </td><td>  -  </td></tr>
     </table>
     */
    public ApiResponse<Model200Response> getWithHttpInfo(String q, String lang, String notLang, PublishDatePrecision publishedDatePrecision, String from, String to, SearchIn searchIn, String countries, String notCountries, Topic topic, String sources, String notSources, Boolean rankedOnly, Integer fromRank, Integer toRank, SortBy sortBy, Integer pageSize, Integer page) throws ApiException {
        okhttp3.Call localVarCall = getValidateBeforeCall(q, lang, notLang, publishedDatePrecision, from, to, searchIn, countries, notCountries, topic, sources, notSources, rankedOnly, fromRank, toRank, sortBy, pageSize, page, null);
        Type localVarReturnType = new TypeToken<Model200Response>(){}.getType();
        return localVarApiClient.execute(localVarCall, localVarReturnType);
    }

    /**
     * Search for specific news articles (asynchronously)
     * Main endpoint that allows you to find news article by keyword, date, language, country, etc.
     * @param q Keyword/keywords you&#39;re searching for. This is the most important part of your query. Please, refer to the **Advanced Query Parameter** section below of the docs for more examples and explanations  (required)
     * @param lang Specifies the languages of the search. For example: &#x60;en&#x60;. The only accepted format is [ISO 639-1 — 2](https://en.wikipedia.org/wiki/ISO_639-1) letter code.  (optional)
     * @param notLang Inverse to the &#x60;lang&#x60; parameter  (optional)
     * @param publishedDatePrecision There are 3 types of date precision we define: &#x60;full&#x60; — day and time of an article is correctly identified with the appropriate timezone &#x60;timezone unknown&#x60; — day and time of an article is correctly identified without timezone &#x60;date&#x60; — only the day is identified without an exact time  (optional)
     * @param from &#x60;YYYY/mm/dd&#x60; From which point in time to start the search. The default timezone is UTC. Defaults to the past week.  (optional)
     * @param to &#x60;YYYY/mm/dd&#x60; Until which point in time to search for. The default timezone is UTC.  (optional)
     * @param searchIn By default, we search what you specified in the &#x60;q&#x60; parameter in both &#x60;title&#x60; and &#x60;summary&#x60; of the article. However, you can limit this to either &#x60;title&#x60; or &#x60;summary&#x60;  (optional)
     * @param countries Countries where the news publisher is located. **Important**: This parameter is not responsible for the countries mentioned in the news article. One or multiple countries can be used in the search. The only acceptable format is [ISO 3166-1 alpha-2](https://en.wikipedia.org/wiki/ISO_3166-1_alpha-2) For example, &#x60;US,CA,MX&#x60; or just &#x60;US&#x60;  (optional)
     * @param notCountries The inverse of the &#x60;countries&#x60; parameter.  (optional)
     * @param topic Accepted values: &#x60;news&#x60;, &#x60;sport&#x60;, &#x60;tech&#x60;, &#x60;world&#x60;, &#x60;finance&#x60;, &#x60;politics&#x60;, &#x60;business&#x60;, &#x60;economics&#x60;, &#x60;entertainment&#x60;, &#x60;beauty&#x60;, &#x60;travel&#x60;, &#x60;music&#x60;, &#x60;food&#x60;, &#x60;science&#x60;, &#x60;gaming&#x60; The topic to which you want to restrict the articles of your choice. Not all news articles are assigned with a topic, therefore, we cannot guarantee that 100% of topics talking about technology will be assigned a tech label.  (optional)
     * @param sources One or more news resources to filter your search. It should be the normal form of the URL, For example: &#x60;nytimes.com,theguardian.com&#x60;  (optional)
     * @param notSources One or more sources to be excluded from the search. Comma-separated list. For example: &#x60;nytimes.com,cnn.com,wsj.com&#x60;  (optional)
     * @param rankedOnly Default: &#x60;True&#x60; Limit the search only for the sources which are in the top 1 million online websites. Unranked sources are assigned a rank that equals &#x60;999999&#x60;  (optional)
     * @param fromRank &#x60;[0:999999]&#x60; The lowest boundary of the rank of a news website to filter by. Important: lower rank means that a source is more popular  (optional)
     * @param toRank &#x60;[0:999999]&#x60; The upper boundary of the rank of a news website to filter by.  (optional)
     * @param sortBy &#x60;relevancy&#x60; (default value) — the most relevant results first &#x60;date&#x60; — the most recently published results first &#x60;rank&#x60; — the results from the highest-ranked sources first  (optional)
     * @param pageSize &#x60;[1:100]&#x60; How many articles to return per page.  (optional)
     * @param page The number of the page. Use it to scroll through the results. This parameter is used to paginate: scroll through results because one API response cannot return more than 100 articles.  (optional)
     * @param _callback The callback to be executed when the API call finishes
     * @return The request call
     * @throws ApiException If fail to process the API call, e.g. serializing the request body object
     * @http.response.details
     <table summary="Response Details" border="1">
        <tr><td> Status Code </td><td> Description </td><td> Response Headers </td></tr>
        <tr><td> 200 </td><td> OK </td><td>  -  </td></tr>
        <tr><td> 400 </td><td> API is not put in headers </td><td>  -  </td></tr>
        <tr><td> 401 </td><td> API Key not found </td><td>  -  </td></tr>
        <tr><td> 406 </td><td> Wrong parameter has been used </td><td>  -  </td></tr>
        <tr><td> 408 </td><td> Request Timeout </td><td>  -  </td></tr>
        <tr><td> 429 </td><td> Concurrency violated </td><td>  -  </td></tr>
     </table>
     */
    public okhttp3.Call getAsync(String q, String lang, String notLang, PublishDatePrecision publishedDatePrecision, String from, String to, SearchIn searchIn, String countries, String notCountries, Topic topic, String sources, String notSources, Boolean rankedOnly, Integer fromRank, Integer toRank, SortBy sortBy, Integer pageSize, Integer page, final ApiCallback<Model200Response> _callback) throws ApiException {

        okhttp3.Call localVarCall = getValidateBeforeCall(q, lang, notLang, publishedDatePrecision, from, to, searchIn, countries, notCountries, topic, sources, notSources, rankedOnly, fromRank, toRank, sortBy, pageSize, page, _callback);
        Type localVarReturnType = new TypeToken<Model200Response>(){}.getType();
        localVarApiClient.executeAsync(localVarCall, localVarReturnType, _callback);
        return localVarCall;
    }
    /**
     * Build call for post
     * @param search  (optional)
     * @param _callback Callback for upload/download progress
     * @return Call to execute
     * @throws ApiException If fail to serialize the request body object
     * @http.response.details
     <table summary="Response Details" border="1">
        <tr><td> Status Code </td><td> Description </td><td> Response Headers </td></tr>
        <tr><td> 200 </td><td> OK </td><td>  -  </td></tr>
        <tr><td> 400 </td><td> API is not put in headers </td><td>  -  </td></tr>
        <tr><td> 401 </td><td> API Key not found </td><td>  -  </td></tr>
        <tr><td> 406 </td><td> Wrong parameter has been used </td><td>  -  </td></tr>
        <tr><td> 408 </td><td> Request Timeout </td><td>  -  </td></tr>
        <tr><td> 429 </td><td> Concurrency violated </td><td>  -  </td></tr>
     </table>
     */
    public okhttp3.Call postCall(Search search, final ApiCallback _callback) throws ApiException {
        String basePath = null;
        // Operation Servers
        String[] localBasePaths = new String[] {  };

        // Determine Base Path to Use
        if (localCustomBaseUrl != null){
            basePath = localCustomBaseUrl;
        } else if ( localBasePaths.length > 0 ) {
            basePath = localBasePaths[localHostIndex];
        } else {
            basePath = null;
        }

        Object localVarPostBody = search;

        // create path and map variables
        String localVarPath = "/search";

        List<Pair> localVarQueryParams = new ArrayList<Pair>();
        List<Pair> localVarCollectionQueryParams = new ArrayList<Pair>();
        Map<String, String> localVarHeaderParams = new HashMap<String, String>();
        Map<String, String> localVarCookieParams = new HashMap<String, String>();
        Map<String, Object> localVarFormParams = new HashMap<String, Object>();

        final String[] localVarAccepts = {
            "application/json"
        };
        final String localVarAccept = localVarApiClient.selectHeaderAccept(localVarAccepts);
        if (localVarAccept != null) {
            localVarHeaderParams.put("Accept", localVarAccept);
        }

        final String[] localVarContentTypes = {
            "application/json"
        };
        final String localVarContentType = localVarApiClient.selectHeaderContentType(localVarContentTypes);
        if (localVarContentType != null) {
            localVarHeaderParams.put("Content-Type", localVarContentType);
        }

        String[] localVarAuthNames = new String[] { "api_key" };
        return localVarApiClient.buildCall(basePath, localVarPath, "POST", localVarQueryParams, localVarCollectionQueryParams, localVarPostBody, localVarHeaderParams, localVarCookieParams, localVarFormParams, localVarAuthNames, _callback);
    }

    @SuppressWarnings("rawtypes")
    private okhttp3.Call postValidateBeforeCall(Search search, final ApiCallback _callback) throws ApiException {
        return postCall(search, _callback);

    }

    /**
     * Search for specific news articles
     * Main endpoint that allows you to find news article by keyword, date, language, country, etc.
     * @param search  (optional)
     * @return Model200Response
     * @throws ApiException If fail to call the API, e.g. server error or cannot deserialize the response body
     * @http.response.details
     <table summary="Response Details" border="1">
        <tr><td> Status Code </td><td> Description </td><td> Response Headers </td></tr>
        <tr><td> 200 </td><td> OK </td><td>  -  </td></tr>
        <tr><td> 400 </td><td> API is not put in headers </td><td>  -  </td></tr>
        <tr><td> 401 </td><td> API Key not found </td><td>  -  </td></tr>
        <tr><td> 406 </td><td> Wrong parameter has been used </td><td>  -  </td></tr>
        <tr><td> 408 </td><td> Request Timeout </td><td>  -  </td></tr>
        <tr><td> 429 </td><td> Concurrency violated </td><td>  -  </td></tr>
     </table>
     */
    public Model200Response post(Search search) throws ApiException {
        ApiResponse<Model200Response> localVarResp = postWithHttpInfo(search);
        return localVarResp.getData();
    }

    /**
     * Search for specific news articles
     * Main endpoint that allows you to find news article by keyword, date, language, country, etc.
     * @param search  (optional)
     * @return ApiResponse&lt;Model200Response&gt;
     * @throws ApiException If fail to call the API, e.g. server error or cannot deserialize the response body
     * @http.response.details
     <table summary="Response Details" border="1">
        <tr><td> Status Code </td><td> Description </td><td> Response Headers </td></tr>
        <tr><td> 200 </td><td> OK </td><td>  -  </td></tr>
        <tr><td> 400 </td><td> API is not put in headers </td><td>  -  </td></tr>
        <tr><td> 401 </td><td> API Key not found </td><td>  -  </td></tr>
        <tr><td> 406 </td><td> Wrong parameter has been used </td><td>  -  </td></tr>
        <tr><td> 408 </td><td> Request Timeout </td><td>  -  </td></tr>
        <tr><td> 429 </td><td> Concurrency violated </td><td>  -  </td></tr>
     </table>
     */
    public ApiResponse<Model200Response> postWithHttpInfo(Search search) throws ApiException {
        okhttp3.Call localVarCall = postValidateBeforeCall(search, null);
        Type localVarReturnType = new TypeToken<Model200Response>(){}.getType();
        return localVarApiClient.execute(localVarCall, localVarReturnType);
    }

    /**
     * Search for specific news articles (asynchronously)
     * Main endpoint that allows you to find news article by keyword, date, language, country, etc.
     * @param search  (optional)
     * @param _callback The callback to be executed when the API call finishes
     * @return The request call
     * @throws ApiException If fail to process the API call, e.g. serializing the request body object
     * @http.response.details
     <table summary="Response Details" border="1">
        <tr><td> Status Code </td><td> Description </td><td> Response Headers </td></tr>
        <tr><td> 200 </td><td> OK </td><td>  -  </td></tr>
        <tr><td> 400 </td><td> API is not put in headers </td><td>  -  </td></tr>
        <tr><td> 401 </td><td> API Key not found </td><td>  -  </td></tr>
        <tr><td> 406 </td><td> Wrong parameter has been used </td><td>  -  </td></tr>
        <tr><td> 408 </td><td> Request Timeout </td><td>  -  </td></tr>
        <tr><td> 429 </td><td> Concurrency violated </td><td>  -  </td></tr>
     </table>
     */
    public okhttp3.Call postAsync(Search search, final ApiCallback<Model200Response> _callback) throws ApiException {

        okhttp3.Call localVarCall = postValidateBeforeCall(search, _callback);
        Type localVarReturnType = new TypeToken<Model200Response>(){}.getType();
        localVarApiClient.executeAsync(localVarCall, localVarReturnType, _callback);
        return localVarCall;
    }
}
