Skip to content

🌿 Fern Regeneration -- April 8, 2025 #326

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Apr 8, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 23 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -36,3 +36,26 @@ jobs:

- name: Test
run: ./gradlew test
publish:
needs: [ compile, test ]
if: github.event_name == 'push' && contains(github.ref, 'refs/tags/')
runs-on: ubuntu-latest

steps:
- name: Checkout repo
uses: actions/checkout@v3

- name: Set up Java
id: setup-jre
uses: actions/setup-java@v1
with:
java-version: "11"
architecture: x64

- name: Publish to maven
run: |
./gradlew publish
env:
MAVEN_USERNAME: ${{ secrets.MAVEN_USERNAME }}
MAVEN_PASSWORD: ${{ secrets.MAVEN_PASSWORD }}
MAVEN_PUBLISH_REGISTRY_URL: "https://s01.oss.sonatype.org/content/repositories/releases/"
157 changes: 157 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,157 @@
# Intercom Java Library

[![fern shield](https://img.shields.io/badge/%F0%9F%8C%BF-Built%20with%20Fern-brightgreen)](https://buildwithfern.com?utm_source=github&utm_medium=github&utm_campaign=readme&utm_source=https%3A%2F%2Fgithub.com%2Fintercom%2Fintercom-java)

The Intercom Java library provides convenient access to the Intercom API from Java.

## Usage

Instantiate and use the client with the following:

```java
package com.example.usage;

import com.intercom.api.Intercom;
import com.intercom.api.resources.articles.requests.CreateArticleRequest;
import com.intercom.api.resources.articles.types.CreateArticleRequestState;

public class Example {
public static void main(String[] args) {
Intercom client = Intercom
.builder()
.token("<token>")
.build();

client.articles().create(
CreateArticleRequest
.builder()
.title("Thanks for everything")
.authorId(1295)
.description("Description of the Article")
.body("Body of the Article")
.state(CreateArticleRequestState.PUBLISHED)
.build()
);
}
}
```

## Environments

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

```java
import com.intercom.api.Intercom;
import com.intercom.api.core.Environment;

Intercom client = Intercom
.builder()
.environment(Environment.USProduction)
.build();
```

## Base Url

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

```java
import com.intercom.api.Intercom;

Intercom client = Intercom
.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.

```java
import com.intercom.api.core.IntercomApiApiException;

try {
client.articles().create(...);
} catch (IntercomApiApiException e) {
// 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:

```java
import com.intercom.api.Intercom;
import okhttp3.OkHttpClient;

OkHttpClient customClient = ...;

Intercom client = Intercom
.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 retriable and the number of retry attempts has not grown larger than the configured
retry limit (default: 2).

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

- [408](https://developer.mozilla.org/en-US/docs/Web/HTTP/Status/408) (Timeout)
- [429](https://developer.mozilla.org/en-US/docs/Web/HTTP/Status/429) (Too Many Requests)
- [5XX](https://developer.mozilla.org/en-US/docs/Web/HTTP/Status/500) (Internal Server Errors)

Use the `maxRetries` request option to configure this behavior.

```java
import com.intercom.api.core.RequestOptions;

client.articles().create(
...,
RequestOptions
.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.

```java
import com.intercom.api.Intercom;
import com.intercom.api.core.RequestOptions;

// Client level
Intercom client = Intercom
.builder()
.timeout(10)
.build();

// Request level
client.articles().create(
...,
RequestOptions
.builder()
.timeout(10)
.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!
50 changes: 50 additions & 0 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -42,10 +42,60 @@ java {
}


group = 'io.intercom'

version = '3.0.0-alpha0'

jar {
dependsOn(":generatePomFileForMavenPublication")
archiveBaseName = "intercom-java"
}

sourcesJar {
archiveBaseName = "intercom-java"
}

javadocJar {
archiveBaseName = "intercom-java"
}

test {
useJUnitPlatform()
testLogging {
showStandardStreams = true
}
}

publishing {
publications {
maven(MavenPublication) {
groupId = 'io.intercom'
artifactId = 'intercom-java'
version = '3.0.0-alpha0'
from components.java
pom {
licenses {
license {
name = 'The MIT License (MIT)'
url = 'https://mit-license.org/'
}
}
scm {
connection = 'scm:git:git://github.com/intercom/intercom-java.git'
developerConnection = 'scm:git:git://github.com/intercom/intercom-java.git'
url = 'https://github.com/intercom/intercom-java'
}
}
}
}
repositories {
maven {
url "$System.env.MAVEN_PUBLISH_REGISTRY_URL"
credentials {
username "$System.env.MAVEN_USERNAME"
password "$System.env.MAVEN_PASSWORD"
}
}
}
}

2 changes: 2 additions & 0 deletions settings.gradle
Original file line number Diff line number Diff line change
@@ -1 +1,3 @@
rootProject.name = 'intercom-java'

include 'sample-app'
10 changes: 9 additions & 1 deletion src/main/java/com/intercom/api/AsyncIntercomBuilder.java
Original file line number Diff line number Diff line change
Expand Up @@ -34,13 +34,21 @@ public AsyncIntercomBuilder url(String url) {
}

/**
* Sets the timeout (in seconds) for the client
* Sets the timeout (in seconds) for the client. Defaults to 60 seconds.
*/
public AsyncIntercomBuilder timeout(int timeout) {
this.clientOptionsBuilder.timeout(timeout);
return this;
}

/**
* Sets the maximum number of retries for the client. Defaults to 2 retries.
*/
public AsyncIntercomBuilder maxRetries(int maxRetries) {
this.clientOptionsBuilder.maxRetries(maxRetries);
return this;
}

/**
* Sets the underlying OkHttp client
*/
Expand Down
10 changes: 9 additions & 1 deletion src/main/java/com/intercom/api/IntercomBuilder.java
Original file line number Diff line number Diff line change
Expand Up @@ -34,13 +34,21 @@ public IntercomBuilder url(String url) {
}

/**
* Sets the timeout (in seconds) for the client
* Sets the timeout (in seconds) for the client. Defaults to 60 seconds.
*/
public IntercomBuilder timeout(int timeout) {
this.clientOptionsBuilder.timeout(timeout);
return this;
}

/**
* Sets the maximum number of retries for the client. Defaults to 2 retries.
*/
public IntercomBuilder maxRetries(int maxRetries) {
this.clientOptionsBuilder.maxRetries(maxRetries);
return this;
}

/**
* Sets the underlying OkHttp client
*/
Expand Down
51 changes: 44 additions & 7 deletions src/main/java/com/intercom/api/core/ClientOptions.java
Original file line number Diff line number Diff line change
Expand Up @@ -64,9 +64,10 @@ private ClientOptions(
this.headers.putAll(headers);
this.headers.putAll(new HashMap<String, String>() {
{
put("User-Agent", "io.intercom:intercom-java/3.0.0-alpha0");
put("X-Fern-Language", "JAVA");
put("X-Fern-SDK-Name", "com.intercom.fern:api-sdk");
put("X-Fern-SDK-Version", "0.0.155");
put("X-Fern-SDK-Version", "3.0.0-alpha0");
}
});
this.headerSuppliers = headerSuppliers;
Expand Down Expand Up @@ -133,12 +134,11 @@ public static final class Builder {

private final Map<String, Supplier<String>> headerSuppliers = new HashMap<>();

private int timeout = 60;
private int maxRetries = 2;

private OkHttpClient httpClient = new OkHttpClient.Builder()
.addInterceptor(new RetryInterceptor(3))
.callTimeout(this.timeout, TimeUnit.SECONDS)
.build();
private Optional<Integer> timeout = Optional.empty();

private OkHttpClient httpClient = null;

private Optional<ApiVersion> version = Optional.empty();

Expand All @@ -161,10 +161,26 @@ public Builder addHeader(String key, Supplier<String> value) {
* Override the timeout in seconds. Defaults to 60 seconds.
*/
public Builder timeout(int timeout) {
this.timeout = Optional.of(timeout);
return this;
}

/**
* Override the timeout in seconds. Defaults to 60 seconds.
*/
public Builder timeout(Optional<Integer> timeout) {
this.timeout = timeout;
return this;
}

/**
* Override the maximum number of retries. Defaults to 2 retries.
*/
public Builder maxRetries(int maxRetries) {
this.maxRetries = maxRetries;
return this;
}

public Builder httpClient(OkHttpClient httpClient) {
this.httpClient = httpClient;
return this;
Expand All @@ -179,7 +195,28 @@ public Builder version(ApiVersion version) {
}

public ClientOptions build() {
return new ClientOptions(environment, headers, headerSuppliers, httpClient, this.timeout, version);
OkHttpClient.Builder httpClientBuilder =
this.httpClient != null ? this.httpClient.newBuilder() : new OkHttpClient.Builder();

if (this.httpClient != null) {
timeout.ifPresent(timeout -> httpClientBuilder
.callTimeout(timeout, TimeUnit.SECONDS)
.connectTimeout(0, TimeUnit.SECONDS)
.writeTimeout(0, TimeUnit.SECONDS)
.readTimeout(0, TimeUnit.SECONDS));
} else {
httpClientBuilder
.callTimeout(this.timeout.orElse(60), TimeUnit.SECONDS)
.connectTimeout(0, TimeUnit.SECONDS)
.writeTimeout(0, TimeUnit.SECONDS)
.readTimeout(0, TimeUnit.SECONDS)
.addInterceptor(new RetryInterceptor(this.maxRetries));
}

this.httpClient = httpClientBuilder.build();
this.timeout = Optional.of(httpClient.callTimeoutMillis() / 1000);

return new ClientOptions(environment, headers, headerSuppliers, httpClient, this.timeout.get(), version);
}
}
}
Loading
Loading