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

com.rapidapi.p.wordsapiv1.controllers.APIsController Maven / Gradle / Ivy

/*
 * WordsAPILib
 *
 * This file was automatically generated by APIMATIC v3.0 ( https://www.apimatic.io ).
 */

package com.rapidapi.p.wordsapiv1.controllers;

import com.rapidapi.p.wordsapiv1.ApiHelper;
import com.rapidapi.p.wordsapiv1.Server;
import com.rapidapi.p.wordsapiv1.exceptions.ApiException;
import com.rapidapi.p.wordsapiv1.http.request.HttpMethod;
import com.rapidapi.p.wordsapiv1.models.DefinitionsResponse;
import com.rapidapi.p.wordsapiv1.models.ExamplesResponse;
import com.rapidapi.p.wordsapiv1.models.FrequencyResponse;
import com.rapidapi.p.wordsapiv1.models.PronunciationResponse;
import com.rapidapi.p.wordsapiv1.models.SynonymsResponse;
import com.rapidapi.p.wordsapiv1.models.WordResponse;
import io.apimatic.core.ApiCall;
import io.apimatic.core.GlobalConfiguration;
import java.io.IOException;
import java.util.concurrent.CompletableFuture;
import java.util.concurrent.CompletionException;

/**
 * This class lists all the endpoints of the groups.
 */
public final class APIsController extends BaseController {

    /**
     * Initializes the controller.
     * @param globalConfig    Configurations added in client.
     */
    public APIsController(GlobalConfiguration globalConfig) {
        super(globalConfig);
    }

    /**
     * Get synonyms of a word.
     * @param  word  Required parameter: The word to search synonyms for.
     * @return    Returns the SynonymsResponse response from the API call
     * @throws    ApiException    Represents error response from the server.
     * @throws    IOException    Signals that an I/O exception of some sort has occurred.
     */
    public SynonymsResponse synonyms(
            final String word) throws ApiException, IOException {
        return prepareSynonymsRequest(word).execute();
    }

    /**
     * Get synonyms of a word.
     * @param  word  Required parameter: The word to search synonyms for.
     * @return    Returns the SynonymsResponse response from the API call
     */
    public CompletableFuture synonymsAsync(
            final String word) {
        try { 
            return prepareSynonymsRequest(word).executeAsync(); 
        } catch (Exception e) {  
            throw new CompletionException(e); 
        }
    }

    /**
     * Builds the ApiCall object for synonyms.
     */
    private ApiCall prepareSynonymsRequest(
            final String word) throws IOException {
        return new ApiCall.Builder()
                .globalConfig(getGlobalConfiguration())
                .requestBuilder(requestBuilder -> requestBuilder
                        .server(Server.ENUM_DEFAULT.value())
                        .path("/words/{word}/synonyms")
                        .templateParam(param -> param.key("word").value(word)
                                .shouldEncode(true))
                        .headerParam(param -> param.key("accept").value("application/json"))
                        .authenticationKey(BaseController.AUTHENTICATION_KEY)
                        .httpMethod(HttpMethod.GET))
                .responseHandler(responseHandler -> responseHandler
                        .deserializer(
                                response -> ApiHelper.deserialize(response, SynonymsResponse.class))
                        .nullify404(false)
                        .globalErrorCase(GLOBAL_ERROR_CASES))
                .build();
    }

    /**
     * Get definitions of a word, including the part of speech.
     * @param  word  Required parameter: The word to search the definitions for.
     * @return    Returns the DefinitionsResponse response from the API call
     * @throws    ApiException    Represents error response from the server.
     * @throws    IOException    Signals that an I/O exception of some sort has occurred.
     */
    public DefinitionsResponse definitions(
            final String word) throws ApiException, IOException {
        return prepareDefinitionsRequest(word).execute();
    }

    /**
     * Get definitions of a word, including the part of speech.
     * @param  word  Required parameter: The word to search the definitions for.
     * @return    Returns the DefinitionsResponse response from the API call
     */
    public CompletableFuture definitionsAsync(
            final String word) {
        try { 
            return prepareDefinitionsRequest(word).executeAsync(); 
        } catch (Exception e) {  
            throw new CompletionException(e); 
        }
    }

    /**
     * Builds the ApiCall object for definitions.
     */
    private ApiCall prepareDefinitionsRequest(
            final String word) throws IOException {
        return new ApiCall.Builder()
                .globalConfig(getGlobalConfiguration())
                .requestBuilder(requestBuilder -> requestBuilder
                        .server(Server.ENUM_DEFAULT.value())
                        .path("/words/{word}/definitions")
                        .templateParam(param -> param.key("word").value(word)
                                .shouldEncode(true))
                        .headerParam(param -> param.key("accept").value("application/json"))
                        .authenticationKey(BaseController.AUTHENTICATION_KEY)
                        .httpMethod(HttpMethod.GET))
                .responseHandler(responseHandler -> responseHandler
                        .deserializer(
                                response -> ApiHelper.deserialize(response, DefinitionsResponse.class))
                        .nullify404(false)
                        .globalErrorCase(GLOBAL_ERROR_CASES))
                .build();
    }

    /**
     * How to pronounce a word, according to the International Phonetic Alphabet. May include
     * multiple results if the word is pronounced differently depending on its part of speech.
     * @param  word  Required parameter: The word to search pronunciation for.
     * @return    Returns the PronunciationResponse response from the API call
     * @throws    ApiException    Represents error response from the server.
     * @throws    IOException    Signals that an I/O exception of some sort has occurred.
     */
    public PronunciationResponse pronunciation(
            final String word) throws ApiException, IOException {
        return preparePronunciationRequest(word).execute();
    }

    /**
     * How to pronounce a word, according to the International Phonetic Alphabet. May include
     * multiple results if the word is pronounced differently depending on its part of speech.
     * @param  word  Required parameter: The word to search pronunciation for.
     * @return    Returns the PronunciationResponse response from the API call
     */
    public CompletableFuture pronunciationAsync(
            final String word) {
        try { 
            return preparePronunciationRequest(word).executeAsync(); 
        } catch (Exception e) {  
            throw new CompletionException(e); 
        }
    }

    /**
     * Builds the ApiCall object for pronunciation.
     */
    private ApiCall preparePronunciationRequest(
            final String word) throws IOException {
        return new ApiCall.Builder()
                .globalConfig(getGlobalConfiguration())
                .requestBuilder(requestBuilder -> requestBuilder
                        .server(Server.ENUM_DEFAULT.value())
                        .path("/words/{word}/pronunciation")
                        .templateParam(param -> param.key("word").value(word)
                                .shouldEncode(true))
                        .headerParam(param -> param.key("accept").value("application/json"))
                        .authenticationKey(BaseController.AUTHENTICATION_KEY)
                        .httpMethod(HttpMethod.GET))
                .responseHandler(responseHandler -> responseHandler
                        .deserializer(
                                response -> ApiHelper.deserialize(response, PronunciationResponse.class))
                        .nullify404(false)
                        .globalErrorCase(GLOBAL_ERROR_CASES))
                .build();
    }

    /**
     * Retrieve information about a word. Results can include definitions, part of speech, synonyms,
     * related words, syllables, and pronunciation. This method is useful to see which relationships
     * are attached to which definition and part of speech of a word.
     * @param  word  Required parameter: This is a template parameter that is used to provide the
     *         word, about which the information is being fetched.
     * @return    Returns the WordResponse response from the API call
     * @throws    ApiException    Represents error response from the server.
     * @throws    IOException    Signals that an I/O exception of some sort has occurred.
     */
    public WordResponse word(
            final String word) throws ApiException, IOException {
        return prepareWordRequest(word).execute();
    }

    /**
     * Retrieve information about a word. Results can include definitions, part of speech, synonyms,
     * related words, syllables, and pronunciation. This method is useful to see which relationships
     * are attached to which definition and part of speech of a word.
     * @param  word  Required parameter: This is a template parameter that is used to provide the
     *         word, about which the information is being fetched.
     * @return    Returns the WordResponse response from the API call
     */
    public CompletableFuture wordAsync(
            final String word) {
        try { 
            return prepareWordRequest(word).executeAsync(); 
        } catch (Exception e) {  
            throw new CompletionException(e); 
        }
    }

    /**
     * Builds the ApiCall object for word.
     */
    private ApiCall prepareWordRequest(
            final String word) throws IOException {
        return new ApiCall.Builder()
                .globalConfig(getGlobalConfiguration())
                .requestBuilder(requestBuilder -> requestBuilder
                        .server(Server.ENUM_DEFAULT.value())
                        .path("/words/{word}")
                        .templateParam(param -> param.key("word").value(word)
                                .shouldEncode(true))
                        .headerParam(param -> param.key("accept").value("application/json"))
                        .authenticationKey(BaseController.AUTHENTICATION_KEY)
                        .httpMethod(HttpMethod.GET))
                .responseHandler(responseHandler -> responseHandler
                        .deserializer(
                                response -> ApiHelper.deserialize(response, WordResponse.class))
                        .nullify404(false)
                        .globalErrorCase(GLOBAL_ERROR_CASES))
                .build();
    }

    /**
     * Get examples of how the word is used.
     * @param  word  Required parameter: The word to search the examples for.
     * @return    Returns the ExamplesResponse response from the API call
     * @throws    ApiException    Represents error response from the server.
     * @throws    IOException    Signals that an I/O exception of some sort has occurred.
     */
    public ExamplesResponse examples(
            final String word) throws ApiException, IOException {
        return prepareExamplesRequest(word).execute();
    }

    /**
     * Get examples of how the word is used.
     * @param  word  Required parameter: The word to search the examples for.
     * @return    Returns the ExamplesResponse response from the API call
     */
    public CompletableFuture examplesAsync(
            final String word) {
        try { 
            return prepareExamplesRequest(word).executeAsync(); 
        } catch (Exception e) {  
            throw new CompletionException(e); 
        }
    }

    /**
     * Builds the ApiCall object for examples.
     */
    private ApiCall prepareExamplesRequest(
            final String word) throws IOException {
        return new ApiCall.Builder()
                .globalConfig(getGlobalConfiguration())
                .requestBuilder(requestBuilder -> requestBuilder
                        .server(Server.ENUM_DEFAULT.value())
                        .path("/words/{word}/examples")
                        .templateParam(param -> param.key("word").value(word)
                                .shouldEncode(true))
                        .headerParam(param -> param.key("accept").value("application/json"))
                        .authenticationKey(BaseController.AUTHENTICATION_KEY)
                        .httpMethod(HttpMethod.GET))
                .responseHandler(responseHandler -> responseHandler
                        .deserializer(
                                response -> ApiHelper.deserialize(response, ExamplesResponse.class))
                        .nullify404(false)
                        .globalErrorCase(GLOBAL_ERROR_CASES))
                .build();
    }

    /**
     * Expands upon the frequency score returned by the main /words/{word} endpoint. Returns zipf, a
     * score indicating how common the word is in the English language, with a range of 1 to 7; per
     * Million, the number of times the word is likely to appear in a corpus of one million English
     * words; and diversity, a 0-1 scale the shows the likelihood of the word appearing in an
     * English document that is part of a corpus.
     * @param  word  Required parameter: The word to search frequency for.
     * @return    Returns the FrequencyResponse response from the API call
     * @throws    ApiException    Represents error response from the server.
     * @throws    IOException    Signals that an I/O exception of some sort has occurred.
     */
    public FrequencyResponse frequency(
            final String word) throws ApiException, IOException {
        return prepareFrequencyRequest(word).execute();
    }

    /**
     * Expands upon the frequency score returned by the main /words/{word} endpoint. Returns zipf, a
     * score indicating how common the word is in the English language, with a range of 1 to 7; per
     * Million, the number of times the word is likely to appear in a corpus of one million English
     * words; and diversity, a 0-1 scale the shows the likelihood of the word appearing in an
     * English document that is part of a corpus.
     * @param  word  Required parameter: The word to search frequency for.
     * @return    Returns the FrequencyResponse response from the API call
     */
    public CompletableFuture frequencyAsync(
            final String word) {
        try { 
            return prepareFrequencyRequest(word).executeAsync(); 
        } catch (Exception e) {  
            throw new CompletionException(e); 
        }
    }

    /**
     * Builds the ApiCall object for frequency.
     */
    private ApiCall prepareFrequencyRequest(
            final String word) throws IOException {
        return new ApiCall.Builder()
                .globalConfig(getGlobalConfiguration())
                .requestBuilder(requestBuilder -> requestBuilder
                        .server(Server.ENUM_DEFAULT.value())
                        .path("/words/{word}/frequency")
                        .templateParam(param -> param.key("word").value(word)
                                .shouldEncode(true))
                        .headerParam(param -> param.key("accept").value("application/json"))
                        .authenticationKey(BaseController.AUTHENTICATION_KEY)
                        .httpMethod(HttpMethod.GET))
                .responseHandler(responseHandler -> responseHandler
                        .deserializer(
                                response -> ApiHelper.deserialize(response, FrequencyResponse.class))
                        .nullify404(false)
                        .globalErrorCase(GLOBAL_ERROR_CASES))
                .build();
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy