Search in sources :

Example 21 with IamAuthenticator

use of com.ibm.cloud.sdk.core.security.IamAuthenticator in project java-sdk by watson-developer-cloud.

the class LanguageTranslatorExample method main.

public static void main(String[] args) {
    Authenticator authenticator = new IamAuthenticator("<iam_api_key>");
    LanguageTranslator service = new LanguageTranslator("2018-05-01", authenticator);
    TranslateOptions translateOptions = new TranslateOptions.Builder().addText("text").modelId("en-es").build();
    TranslationResult translationResult = service.translate(translateOptions).execute().getResult();
    System.out.println(translationResult);
}
Also used : IamAuthenticator(com.ibm.cloud.sdk.core.security.IamAuthenticator) TranslateOptions(com.ibm.watson.language_translator.v3.model.TranslateOptions) TranslationResult(com.ibm.watson.language_translator.v3.model.TranslationResult) Authenticator(com.ibm.cloud.sdk.core.security.Authenticator) IamAuthenticator(com.ibm.cloud.sdk.core.security.IamAuthenticator)

Example 22 with IamAuthenticator

use of com.ibm.cloud.sdk.core.security.IamAuthenticator in project java-sdk by watson-developer-cloud.

the class LanguageTranslatorIT method setUp.

/**
 * Sets up the tests.
 *
 * @throws Exception the exception
 */
/*
   * (non-Javadoc)
   * @see com.ibm.watson.developercloud.WatsonServiceTest#setUp()
   */
@Override
@Before
public void setUp() throws Exception {
    super.setUp();
    String iamApiKey = System.getenv("LANGUAGE_TRANSLATOR_APIKEY");
    String serviceUrl = System.getenv("LANGUAGE_TRANSLATOR_URL");
    if (iamApiKey == null) {
        iamApiKey = getProperty("language_translator.apikey");
        serviceUrl = getProperty("language_translator.url");
    }
    assertNotNull("LANGUAGE_TRANSLATOR_APIKEY is not defined and config.properties doesn't have valid credentials.", iamApiKey);
    Authenticator authenticator = new IamAuthenticator(iamApiKey);
    service = new LanguageTranslator("2018-05-01", authenticator);
    service.setServiceUrl(serviceUrl);
    // issue currently where document translation fails with learning opt-out
    Map<String, String> headers = new HashMap<>();
    headers.put(WatsonHttpHeaders.X_WATSON_TEST, "1");
    service.setDefaultHeaders(headers);
}
Also used : HashMap(java.util.HashMap) IamAuthenticator(com.ibm.cloud.sdk.core.security.IamAuthenticator) IamAuthenticator(com.ibm.cloud.sdk.core.security.IamAuthenticator) Authenticator(com.ibm.cloud.sdk.core.security.Authenticator) Before(org.junit.Before)

Example 23 with IamAuthenticator

use of com.ibm.cloud.sdk.core.security.IamAuthenticator in project java-sdk by watson-developer-cloud.

the class AssistantServiceTest method setUp.

/**
 * Sets up the tests.
 *
 * @throws Exception the exception
 */
/*
   * (non-Javadoc)
   * @see com.ibm.watson.common.WatsonServiceTest#setUp()
   */
@Override
@Before
public void setUp() throws Exception {
    super.setUp();
    String apiKey = System.getenv("ASSISTANT_APIKEY");
    workspaceId = System.getenv("ASSISTANT_WORKSPACE_ID");
    String serviceUrl = System.getenv("ASSISTANT_URL");
    if (apiKey == null) {
        apiKey = getProperty("assistant.apikey");
        workspaceId = getProperty("assistant.workspace_id");
        serviceUrl = getProperty("assistant.url");
    }
    Assume.assumeFalse("ASSISTANT_APIKEY is not defined and config.properties doesn't have valid credentials.", apiKey == null);
    Authenticator authenticator = new IamAuthenticator(apiKey);
    service = new Assistant("2019-02-28", authenticator);
    service.setServiceUrl(serviceUrl);
    service.setDefaultHeaders(getDefaultHeaders());
}
Also used : IamAuthenticator(com.ibm.cloud.sdk.core.security.IamAuthenticator) Authenticator(com.ibm.cloud.sdk.core.security.Authenticator) IamAuthenticator(com.ibm.cloud.sdk.core.security.IamAuthenticator) Before(org.junit.Before)

Example 24 with IamAuthenticator

use of com.ibm.cloud.sdk.core.security.IamAuthenticator in project java-sdk by watson-developer-cloud.

the class AssistantServiceTest method setUp.

/**
 * Sets up the tests.
 *
 * @throws Exception the exception
 */
/*
   * (non-Javadoc)
   * @see com.ibm.watson.common.WatsonServiceTest#setUp()
   */
@Override
@Before
public void setUp() throws Exception {
    super.setUp();
    String apiKey = System.getenv("ASSISTANT_APIKEY");
    assistantId = System.getenv("ASSISTANT_ASSISTANT_ID");
    String serviceUrl = System.getenv("ASSISTANT_URL");
    if (apiKey == null) {
        apiKey = getProperty("assistant.apikey");
        assistantId = getProperty("assistant.assistant_id");
        serviceUrl = getProperty("assistant.url");
    }
    Assume.assumeFalse("ASSISTANT_APIKEY is not defined and config.properties doesn't have valid credentials.", apiKey == null);
    Authenticator authenticator = new IamAuthenticator(apiKey);
    service = new Assistant("2019-02-28", authenticator);
    service.setServiceUrl(serviceUrl);
    service.setDefaultHeaders(getDefaultHeaders());
}
Also used : IamAuthenticator(com.ibm.cloud.sdk.core.security.IamAuthenticator) Authenticator(com.ibm.cloud.sdk.core.security.Authenticator) IamAuthenticator(com.ibm.cloud.sdk.core.security.IamAuthenticator) Before(org.junit.Before)

Example 25 with IamAuthenticator

use of com.ibm.cloud.sdk.core.security.IamAuthenticator in project java-sdk by watson-developer-cloud.

the class DiscoveryIT method setUp.

/**
 * Sets up the tests.
 *
 * @throws Exception the exception
 */
/*
   * (non-Javadoc)
   *
   * @see com.ibm.watson.common.WatsonServiceTest#setUp()
   */
@Override
@Before
public void setUp() throws Exception {
    super.setUp();
    String apiKey = System.getenv("DISCOVERY_V2_APIKEY");
    String serviceUrl = System.getenv("DISCOVERY_V2_URL");
    if (apiKey == null) {
        apiKey = getProperty("discovery_v2.apikey");
        serviceUrl = getProperty("discovery_v2.url");
    }
    assertNotNull("DISCOVERY_V2_APIKEY is not defined and config.properties doesn't have valid credentials.", apiKey);
    Authenticator authenticator = new IamAuthenticator(apiKey);
    service = new Discovery(VERSION, authenticator);
    service.setDefaultHeaders(getDefaultHeaders());
    service.setServiceUrl(serviceUrl);
    HttpConfigOptions configOptions = new HttpConfigOptions.Builder().disableSslVerification(true).build();
    service.configureClient(configOptions);
}
Also used : HttpConfigOptions(com.ibm.cloud.sdk.core.http.HttpConfigOptions) IamAuthenticator(com.ibm.cloud.sdk.core.security.IamAuthenticator) IamAuthenticator(com.ibm.cloud.sdk.core.security.IamAuthenticator) Authenticator(com.ibm.cloud.sdk.core.security.Authenticator) Before(org.junit.Before)

Aggregations

IamAuthenticator (com.ibm.cloud.sdk.core.security.IamAuthenticator)32 Authenticator (com.ibm.cloud.sdk.core.security.Authenticator)30 Before (org.junit.Before)15 SpeechRecognitionResults (com.ibm.watson.speech_to_text.v1.model.SpeechRecognitionResults)5 File (java.io.File)4 Response (com.ibm.cloud.sdk.core.http.Response)2 MessageInput (com.ibm.watson.assistant.v1.model.MessageInput)2 MessageOptions (com.ibm.watson.assistant.v1.model.MessageOptions)2 MessageResponse (com.ibm.watson.assistant.v1.model.MessageResponse)2 TranslateOptions (com.ibm.watson.language_translator.v3.model.TranslateOptions)2 TranslationResult (com.ibm.watson.language_translator.v3.model.TranslationResult)2 RecognizeWithWebsocketsOptions (com.ibm.watson.speech_to_text.v1.model.RecognizeWithWebsocketsOptions)2 BaseRecognizeCallback (com.ibm.watson.speech_to_text.v1.websocket.BaseRecognizeCallback)2 ToneAnalysis (com.ibm.watson.tone_analyzer.v3.model.ToneAnalysis)2 ToneOptions (com.ibm.watson.tone_analyzer.v3.model.ToneOptions)2 ByteArrayInputStream (java.io.ByteArrayInputStream)2 InputStream (java.io.InputStream)2 JsonObject (com.google.gson.JsonObject)1 HttpConfigOptions (com.ibm.cloud.sdk.core.http.HttpConfigOptions)1 ServiceCallback (com.ibm.cloud.sdk.core.http.ServiceCallback)1