Getting Started with Java
Safe API Key Storage
In a production setup, do not store API Keys in the host's environment variables or in the source code.
Requirements
To be able to use the Opportify SDK requires:
- Java 1.8+
- Maven (3.8.3+)/Gradle (7.2+)
Install the Opportify SDK
Maven
Add this dependency to your project's POM:
<dependency>
<groupId>ai.opportify</groupId>
<artifactId>opportify-sdk-client</artifactId>
<version>1.0.0</version>
<scope>compile</scope>
</dependency>
Gradle
Add this dependency to your project's build file:
repositories {
mavenCentral()
}
dependencies {
implementation "ai.opportify:opportify-sdk-client:1.0.0"
}
Install Using Maven as package manager
To install the SDK to your local Maven repository, simply execute:
mvn clean install
Usage
Client
After you installed the library, you can create a client
instance and interface with it.
// Import classes:
import ai.opportify.client.ApiClient;
import ai.opportify.client.ApiException;
import ai.opportify.client.Configuration;
import ai.opportify.client.auth.*;
import ai.opportify.client.model.*;
import ai.opportify.client.api.EmailInsightsApi;
public class Example {
public static void main(String[] args) {
ApiClient defaultClient = Configuration.getDefaultApiClient();
// Configure API key authorization: apiKeyAuth
ApiKeyAuth apiKeyAuth = (ApiKeyAuth) defaultClient.getAuthentication("apiKeyAuth");
apiKeyAuth.setApiKey("YOUR API KEY");
EmailInsightsApi apiInstance = new EmailInsightsApi(defaultClient);
AnalyzeRequest analyzeRequest = new AnalyzeRequest();
analyzeEmailRequest.email("email_to_validate@domain.com");
analyzeEmailRequest.enableAutoCorrection(true);
analyzeEmailRequest.enableAI(true); // only available for paid plans.
try {
Analyze200Response result = apiInstance.analyze(analyzeRequest);
System.out.println(result);
} catch (ApiException e) {
System.err.println("Exception when calling EmailInsightsApi#analyze");
System.err.println("Status code: " + e.getCode());
System.err.println("Reason: " + e.getResponseBody());
System.err.println("Response headers: " + e.getResponseHeaders());
e.printStackTrace();
}
}
}
What's next?
How-To Guides
Once you have installed the Opportify SDK, you can start building your application. You can find usage examples in this Wiki's how-to guides.