Skip to content

Repository files navigation

Mavenagi Java Library

fern shieldMaven Central

The Mavenagi Java library provides convenient access to the Mavenagi APIs from Java.

Table of Contents

Reference

A full reference for this library is available here.

Usage

Instantiate and use the client with the following:

packagecom.example.usage;
importcom.mavenagi.MavenAGI;
importcom.mavenagi.resources.actions.types.ActionsSearchRequest;
publicclassExample {
publicstaticvoidmain(String[] args) {
MavenAGIclient = MavenAGI
.builder()
.credentials("<username>", "<password>")
.build();
client.actions().search(
ActionsSearchRequest
.builder()
.build()
);
}
}

Environments

This SDK allows you to configure different environments for API requests.

importcom.mavenagi.MavenAGI;
importcom.mavenagi.core.Environment;
MavenAGIclient = MavenAGI
.builder()
.environment(Environment.Production)
.build();

Base Url

You can set a custom base URL when constructing the client.

importcom.mavenagi.MavenAGI;
MavenAGIclient = MavenAGI
.builder()
.url("https://example.com")
.build();

Exception Handling

When the API returns a non-success status code (4xx or 5xx response), an API exception will be thrown.

importcom.mavenagi.core.MavenagiApiApiException;
try {
client.actions().search(...);
} catch (MavenagiApiApiExceptione) {
// Do something with the API exception...
}

Advanced

Custom Client

This SDK is built to work with any instance of OkHttpClient. By default, if no client is provided, the SDK will construct one. However, you can pass your own client like so:

importcom.mavenagi.MavenAGI;
importokhttp3.OkHttpClient;
OkHttpClientcustomClient = ...;
MavenAGIclient = MavenAGI
.builder()
.httpClient(customClient)
.build();

Retries

The SDK is instrumented with automatic retries with exponential backoff. A request will be retried as long as the request is deemed retryable and the number of retry attempts has not grown larger than the configured retry limit (default: 2).

A request is deemed retryable when any of the following HTTP status codes is returned:

  • 408 (Timeout)
  • 429 (Too Many Requests)
  • 5XX (Internal Server Errors)

Use the maxRetries client option to configure this behavior.

importcom.mavenagi.MavenAGI;
MavenAGIclient = MavenAGI
.builder()
.maxRetries(1)
.build();

Timeouts

The SDK defaults to a 60 second timeout. You can configure this with a timeout option at the client or request level.

importcom.mavenagi.MavenAGI;
importcom.mavenagi.core.RequestOptions;
// Client levelMavenAGIclient = MavenAGI
.builder()
.timeout(10)
.build();
// Request levelclient.actions().search(
...,
RequestOptions
.builder()
.timeout(10)
.build()
);

Custom Headers

The SDK allows you to add custom headers to requests. You can configure headers at the client level or at the request level.

importcom.mavenagi.MavenAGI;
importcom.mavenagi.core.RequestOptions;
// Client levelMavenAGIclient = MavenAGI
.builder()
.addHeader("X-Custom-Header", "custom-value")
.addHeader("X-Request-Id", "abc-123")
.build();
;
// Request levelclient.actions().search(
...,
RequestOptions
.builder()
.addHeader("X-Request-Header", "request-value")
.build()
);

Contributing

While we value open-source contributions to this SDK, this library is generated programmatically. Additions made directly to this library would have to be moved over to our generation code, otherwise they would be overwritten upon the next generated release. Feel free to open a PR as a proof of concept, but know that we will not be able to merge it as-is. We suggest opening an issue first to discuss with us!

On the other hand, contributions to the README are always very welcome!

Installation

Gradle

Add the dependency in your build.gradle file:

dependencies {
implementation 'com.mavenagi:mavenagi-java:1.2.57'
}

Maven

Add the dependency in your pom.xml file:

<dependency>
<groupId>com.mavenagi</groupId>
<artifactId>mavenagi-java</artifactId>
<version>1.2.57</version>
</dependency>

About

Maven AGI Java SDK

Resources

Stars

0 stars

Watchers

2 watching

Forks

Releases

Packages

Used by

Contributors

Languages