Skip to content

Commit b3dd24a

Browse files
committed
SDK regeneration
1 parent 5b5fa43 commit b3dd24a

File tree

108 files changed

+20522
-12370
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

108 files changed

+20522
-12370
lines changed

.github/workflows/ci.yml

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,3 +36,26 @@ jobs:
3636

3737
- name: Test
3838
run: ./gradlew test
39+
publish:
40+
needs: [ compile, test ]
41+
if: github.event_name == 'push' && contains(github.ref, 'refs/tags/')
42+
runs-on: ubuntu-latest
43+
44+
steps:
45+
- name: Checkout repo
46+
uses: actions/checkout@v3
47+
48+
- name: Set up Java
49+
id: setup-jre
50+
uses: actions/setup-java@v1
51+
with:
52+
java-version: "11"
53+
architecture: x64
54+
55+
- name: Publish to maven
56+
run: |
57+
./gradlew publish
58+
env:
59+
MAVEN_USERNAME: ${{ secrets.MAVEN_USERNAME }}
60+
MAVEN_PASSWORD: ${{ secrets.MAVEN_PASSWORD }}
61+
MAVEN_PUBLISH_REGISTRY_URL: "https://s01.oss.sonatype.org/content/repositories/releases/"

README.md

Lines changed: 157 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,157 @@
1+
# Intercom Java Library
2+
3+
[![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)
4+
5+
The Intercom Java library provides convenient access to the Intercom API from Java.
6+
7+
## Usage
8+
9+
Instantiate and use the client with the following:
10+
11+
```java
12+
package com.example.usage;
13+
14+
import com.intercom.api.Intercom;
15+
import com.intercom.api.resources.articles.requests.CreateArticleRequest;
16+
import com.intercom.api.resources.articles.types.CreateArticleRequestState;
17+
18+
public class Example {
19+
public static void main(String[] args) {
20+
Intercom client = Intercom
21+
.builder()
22+
.token("<token>")
23+
.build();
24+
25+
client.articles().create(
26+
CreateArticleRequest
27+
.builder()
28+
.title("Thanks for everything")
29+
.authorId(1295)
30+
.description("Description of the Article")
31+
.body("Body of the Article")
32+
.state(CreateArticleRequestState.PUBLISHED)
33+
.build()
34+
);
35+
}
36+
}
37+
```
38+
39+
## Environments
40+
41+
This SDK allows you to configure different environments for API requests.
42+
43+
```java
44+
import com.intercom.api.Intercom;
45+
import com.intercom.api.core.Environment;
46+
47+
Intercom client = Intercom
48+
.builder()
49+
.environment(Environment.USProduction)
50+
.build();
51+
```
52+
53+
## Base Url
54+
55+
You can set a custom base URL when constructing the client.
56+
57+
```java
58+
import com.intercom.api.Intercom;
59+
60+
Intercom client = Intercom
61+
.builder()
62+
.url("https://example.com")
63+
.build();
64+
```
65+
66+
## Exception Handling
67+
68+
When the API returns a non-success status code (4xx or 5xx response), an API exception will be thrown.
69+
70+
```java
71+
import com.intercom.api.core.IntercomApiApiException;
72+
73+
try {
74+
client.articles().create(...);
75+
} catch (IntercomApiApiException e) {
76+
// Do something with the API exception...
77+
}
78+
```
79+
80+
## Advanced
81+
82+
### Custom Client
83+
84+
This SDK is built to work with any instance of `OkHttpClient`. By default, if no client is provided, the SDK will construct one.
85+
However, you can pass your own client like so:
86+
87+
```java
88+
import com.intercom.api.Intercom;
89+
import okhttp3.OkHttpClient;
90+
91+
OkHttpClient customClient = ...;
92+
93+
Intercom client = Intercom
94+
.builder()
95+
.httpClient(customClient)
96+
.build();
97+
```
98+
99+
### Retries
100+
101+
The SDK is instrumented with automatic retries with exponential backoff. A request will be retried as long
102+
as the request is deemed retriable and the number of retry attempts has not grown larger than the configured
103+
retry limit (default: 2).
104+
105+
A request is deemed retriable when any of the following HTTP status codes is returned:
106+
107+
- [408](https://developer.mozilla.org/en-US/docs/Web/HTTP/Status/408) (Timeout)
108+
- [429](https://developer.mozilla.org/en-US/docs/Web/HTTP/Status/429) (Too Many Requests)
109+
- [5XX](https://developer.mozilla.org/en-US/docs/Web/HTTP/Status/500) (Internal Server Errors)
110+
111+
Use the `maxRetries` request option to configure this behavior.
112+
113+
```java
114+
import com.intercom.api.core.RequestOptions;
115+
116+
client.articles().create(
117+
...,
118+
RequestOptions
119+
.builder()
120+
.maxRetries(1)
121+
.build()
122+
);
123+
```
124+
125+
### Timeouts
126+
127+
The SDK defaults to a 60 second timeout. You can configure this with a timeout option at the client or request level.
128+
129+
```java
130+
import com.intercom.api.Intercom;
131+
import com.intercom.api.core.RequestOptions;
132+
133+
// Client level
134+
Intercom client = Intercom
135+
.builder()
136+
.timeout(10)
137+
.build();
138+
139+
// Request level
140+
client.articles().create(
141+
...,
142+
RequestOptions
143+
.builder()
144+
.timeout(10)
145+
.build()
146+
);
147+
```
148+
149+
## Contributing
150+
151+
While we value open-source contributions to this SDK, this library is generated programmatically.
152+
Additions made directly to this library would have to be moved over to our generation code,
153+
otherwise they would be overwritten upon the next generated release. Feel free to open a PR as
154+
a proof of concept, but know that we will not be able to merge it as-is. We suggest opening
155+
an issue first to discuss with us!
156+
157+
On the other hand, contributions to the README are always very welcome!

build.gradle

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,10 +42,60 @@ java {
4242
}
4343

4444

45+
group = 'io.intercom'
46+
47+
version = '3.0.0-alpha0'
48+
49+
jar {
50+
dependsOn(":generatePomFileForMavenPublication")
51+
archiveBaseName = "intercom-java"
52+
}
53+
54+
sourcesJar {
55+
archiveBaseName = "intercom-java"
56+
}
57+
58+
javadocJar {
59+
archiveBaseName = "intercom-java"
60+
}
61+
4562
test {
4663
useJUnitPlatform()
4764
testLogging {
4865
showStandardStreams = true
4966
}
5067
}
5168

69+
publishing {
70+
publications {
71+
maven(MavenPublication) {
72+
groupId = 'io.intercom'
73+
artifactId = 'intercom-java'
74+
version = '3.0.0-alpha0'
75+
from components.java
76+
pom {
77+
licenses {
78+
license {
79+
name = 'The MIT License (MIT)'
80+
url = 'https://mit-license.org/'
81+
}
82+
}
83+
scm {
84+
connection = 'scm:git:git://github.com/intercom/intercom-java.git'
85+
developerConnection = 'scm:git:git://github.com/intercom/intercom-java.git'
86+
url = 'https://github.com/intercom/intercom-java'
87+
}
88+
}
89+
}
90+
}
91+
repositories {
92+
maven {
93+
url "$System.env.MAVEN_PUBLISH_REGISTRY_URL"
94+
credentials {
95+
username "$System.env.MAVEN_USERNAME"
96+
password "$System.env.MAVEN_PASSWORD"
97+
}
98+
}
99+
}
100+
}
101+

settings.gradle

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,3 @@
1+
rootProject.name = 'intercom-java'
2+
13
include 'sample-app'

src/main/java/com/intercom/api/AsyncIntercomBuilder.java

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,13 +34,21 @@ public AsyncIntercomBuilder url(String url) {
3434
}
3535

3636
/**
37-
* Sets the timeout (in seconds) for the client
37+
* Sets the timeout (in seconds) for the client. Defaults to 60 seconds.
3838
*/
3939
public AsyncIntercomBuilder timeout(int timeout) {
4040
this.clientOptionsBuilder.timeout(timeout);
4141
return this;
4242
}
4343

44+
/**
45+
* Sets the maximum number of retries for the client. Defaults to 2 retries.
46+
*/
47+
public AsyncIntercomBuilder maxRetries(int maxRetries) {
48+
this.clientOptionsBuilder.maxRetries(maxRetries);
49+
return this;
50+
}
51+
4452
/**
4553
* Sets the underlying OkHttp client
4654
*/

src/main/java/com/intercom/api/IntercomBuilder.java

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,13 +34,21 @@ public IntercomBuilder url(String url) {
3434
}
3535

3636
/**
37-
* Sets the timeout (in seconds) for the client
37+
* Sets the timeout (in seconds) for the client. Defaults to 60 seconds.
3838
*/
3939
public IntercomBuilder timeout(int timeout) {
4040
this.clientOptionsBuilder.timeout(timeout);
4141
return this;
4242
}
4343

44+
/**
45+
* Sets the maximum number of retries for the client. Defaults to 2 retries.
46+
*/
47+
public IntercomBuilder maxRetries(int maxRetries) {
48+
this.clientOptionsBuilder.maxRetries(maxRetries);
49+
return this;
50+
}
51+
4452
/**
4553
* Sets the underlying OkHttp client
4654
*/

src/main/java/com/intercom/api/core/ClientOptions.java

Lines changed: 44 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -64,9 +64,10 @@ private ClientOptions(
6464
this.headers.putAll(headers);
6565
this.headers.putAll(new HashMap<String, String>() {
6666
{
67+
put("User-Agent", "io.intercom:intercom-java/3.0.0-alpha0");
6768
put("X-Fern-Language", "JAVA");
6869
put("X-Fern-SDK-Name", "com.intercom.fern:api-sdk");
69-
put("X-Fern-SDK-Version", "0.0.155");
70+
put("X-Fern-SDK-Version", "3.0.0-alpha0");
7071
}
7172
});
7273
this.headerSuppliers = headerSuppliers;
@@ -133,12 +134,11 @@ public static final class Builder {
133134

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

136-
private int timeout = 60;
137+
private int maxRetries = 2;
137138

138-
private OkHttpClient httpClient = new OkHttpClient.Builder()
139-
.addInterceptor(new RetryInterceptor(3))
140-
.callTimeout(this.timeout, TimeUnit.SECONDS)
141-
.build();
139+
private Optional<Integer> timeout = Optional.empty();
140+
141+
private OkHttpClient httpClient = null;
142142

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

@@ -161,10 +161,26 @@ public Builder addHeader(String key, Supplier<String> value) {
161161
* Override the timeout in seconds. Defaults to 60 seconds.
162162
*/
163163
public Builder timeout(int timeout) {
164+
this.timeout = Optional.of(timeout);
165+
return this;
166+
}
167+
168+
/**
169+
* Override the timeout in seconds. Defaults to 60 seconds.
170+
*/
171+
public Builder timeout(Optional<Integer> timeout) {
164172
this.timeout = timeout;
165173
return this;
166174
}
167175

176+
/**
177+
* Override the maximum number of retries. Defaults to 2 retries.
178+
*/
179+
public Builder maxRetries(int maxRetries) {
180+
this.maxRetries = maxRetries;
181+
return this;
182+
}
183+
168184
public Builder httpClient(OkHttpClient httpClient) {
169185
this.httpClient = httpClient;
170186
return this;
@@ -179,7 +195,28 @@ public Builder version(ApiVersion version) {
179195
}
180196

181197
public ClientOptions build() {
182-
return new ClientOptions(environment, headers, headerSuppliers, httpClient, this.timeout, version);
198+
OkHttpClient.Builder httpClientBuilder =
199+
this.httpClient != null ? this.httpClient.newBuilder() : new OkHttpClient.Builder();
200+
201+
if (this.httpClient != null) {
202+
timeout.ifPresent(timeout -> httpClientBuilder
203+
.callTimeout(timeout, TimeUnit.SECONDS)
204+
.connectTimeout(0, TimeUnit.SECONDS)
205+
.writeTimeout(0, TimeUnit.SECONDS)
206+
.readTimeout(0, TimeUnit.SECONDS));
207+
} else {
208+
httpClientBuilder
209+
.callTimeout(this.timeout.orElse(60), TimeUnit.SECONDS)
210+
.connectTimeout(0, TimeUnit.SECONDS)
211+
.writeTimeout(0, TimeUnit.SECONDS)
212+
.readTimeout(0, TimeUnit.SECONDS)
213+
.addInterceptor(new RetryInterceptor(this.maxRetries));
214+
}
215+
216+
this.httpClient = httpClientBuilder.build();
217+
this.timeout = Optional.of(httpClient.callTimeoutMillis() / 1000);
218+
219+
return new ClientOptions(environment, headers, headerSuppliers, httpClient, this.timeout.get(), version);
183220
}
184221
}
185222
}

0 commit comments

Comments
 (0)