|
| 1 | +/** |
| 2 | + * This file was auto-generated by Fern from our API Definition. |
| 3 | + */ |
| 4 | +package com.intercom.api.resources.customchannelevents; |
| 5 | + |
| 6 | +import com.intercom.api.core.ClientOptions; |
| 7 | +import com.intercom.api.core.IntercomApiException; |
| 8 | +import com.intercom.api.core.IntercomException; |
| 9 | +import com.intercom.api.core.IntercomHttpResponse; |
| 10 | +import com.intercom.api.core.ObjectMappers; |
| 11 | +import com.intercom.api.core.RequestOptions; |
| 12 | +import java.io.IOException; |
| 13 | +import java.util.concurrent.CompletableFuture; |
| 14 | +import okhttp3.Call; |
| 15 | +import okhttp3.Callback; |
| 16 | +import okhttp3.Headers; |
| 17 | +import okhttp3.HttpUrl; |
| 18 | +import okhttp3.OkHttpClient; |
| 19 | +import okhttp3.Request; |
| 20 | +import okhttp3.RequestBody; |
| 21 | +import okhttp3.Response; |
| 22 | +import okhttp3.ResponseBody; |
| 23 | +import org.jetbrains.annotations.NotNull; |
| 24 | + |
| 25 | +public class AsyncRawCustomChannelEventsClient { |
| 26 | + protected final ClientOptions clientOptions; |
| 27 | + |
| 28 | + public AsyncRawCustomChannelEventsClient(ClientOptions clientOptions) { |
| 29 | + this.clientOptions = clientOptions; |
| 30 | + } |
| 31 | + |
| 32 | + public CompletableFuture<IntercomHttpResponse<Void>> notifyAttributeCollected() { |
| 33 | + return notifyAttributeCollected(null); |
| 34 | + } |
| 35 | + |
| 36 | + public CompletableFuture<IntercomHttpResponse<Void>> notifyAttributeCollected(RequestOptions requestOptions) { |
| 37 | + HttpUrl httpUrl = HttpUrl.parse(this.clientOptions.environment().getUrl()) |
| 38 | + .newBuilder() |
| 39 | + .addPathSegments("custom_channel_events/notify_attribute_collected") |
| 40 | + .build(); |
| 41 | + Request okhttpRequest = new Request.Builder() |
| 42 | + .url(httpUrl) |
| 43 | + .method("POST", RequestBody.create("", null)) |
| 44 | + .headers(Headers.of(clientOptions.headers(requestOptions))) |
| 45 | + .build(); |
| 46 | + OkHttpClient client = clientOptions.httpClient(); |
| 47 | + if (requestOptions != null && requestOptions.getTimeout().isPresent()) { |
| 48 | + client = clientOptions.httpClientWithTimeout(requestOptions); |
| 49 | + } |
| 50 | + CompletableFuture<IntercomHttpResponse<Void>> future = new CompletableFuture<>(); |
| 51 | + client.newCall(okhttpRequest).enqueue(new Callback() { |
| 52 | + @Override |
| 53 | + public void onResponse(@NotNull Call call, @NotNull Response response) throws IOException { |
| 54 | + try (ResponseBody responseBody = response.body()) { |
| 55 | + if (response.isSuccessful()) { |
| 56 | + future.complete(new IntercomHttpResponse<>(null, response)); |
| 57 | + return; |
| 58 | + } |
| 59 | + String responseBodyString = responseBody != null ? responseBody.string() : "{}"; |
| 60 | + future.completeExceptionally(new IntercomApiException( |
| 61 | + "Error with status code " + response.code(), |
| 62 | + response.code(), |
| 63 | + ObjectMappers.JSON_MAPPER.readValue(responseBodyString, Object.class), |
| 64 | + response)); |
| 65 | + return; |
| 66 | + } catch (IOException e) { |
| 67 | + future.completeExceptionally(new IntercomException("Network error executing HTTP request", e)); |
| 68 | + } |
| 69 | + } |
| 70 | + |
| 71 | + @Override |
| 72 | + public void onFailure(@NotNull Call call, @NotNull IOException e) { |
| 73 | + future.completeExceptionally(new IntercomException("Network error executing HTTP request", e)); |
| 74 | + } |
| 75 | + }); |
| 76 | + return future; |
| 77 | + } |
| 78 | + |
| 79 | + public CompletableFuture<IntercomHttpResponse<Void>> notifyNewMessage() { |
| 80 | + return notifyNewMessage(null); |
| 81 | + } |
| 82 | + |
| 83 | + public CompletableFuture<IntercomHttpResponse<Void>> notifyNewMessage(RequestOptions requestOptions) { |
| 84 | + HttpUrl httpUrl = HttpUrl.parse(this.clientOptions.environment().getUrl()) |
| 85 | + .newBuilder() |
| 86 | + .addPathSegments("custom_channel_events/notify_new_message") |
| 87 | + .build(); |
| 88 | + Request okhttpRequest = new Request.Builder() |
| 89 | + .url(httpUrl) |
| 90 | + .method("POST", RequestBody.create("", null)) |
| 91 | + .headers(Headers.of(clientOptions.headers(requestOptions))) |
| 92 | + .build(); |
| 93 | + OkHttpClient client = clientOptions.httpClient(); |
| 94 | + if (requestOptions != null && requestOptions.getTimeout().isPresent()) { |
| 95 | + client = clientOptions.httpClientWithTimeout(requestOptions); |
| 96 | + } |
| 97 | + CompletableFuture<IntercomHttpResponse<Void>> future = new CompletableFuture<>(); |
| 98 | + client.newCall(okhttpRequest).enqueue(new Callback() { |
| 99 | + @Override |
| 100 | + public void onResponse(@NotNull Call call, @NotNull Response response) throws IOException { |
| 101 | + try (ResponseBody responseBody = response.body()) { |
| 102 | + if (response.isSuccessful()) { |
| 103 | + future.complete(new IntercomHttpResponse<>(null, response)); |
| 104 | + return; |
| 105 | + } |
| 106 | + String responseBodyString = responseBody != null ? responseBody.string() : "{}"; |
| 107 | + future.completeExceptionally(new IntercomApiException( |
| 108 | + "Error with status code " + response.code(), |
| 109 | + response.code(), |
| 110 | + ObjectMappers.JSON_MAPPER.readValue(responseBodyString, Object.class), |
| 111 | + response)); |
| 112 | + return; |
| 113 | + } catch (IOException e) { |
| 114 | + future.completeExceptionally(new IntercomException("Network error executing HTTP request", e)); |
| 115 | + } |
| 116 | + } |
| 117 | + |
| 118 | + @Override |
| 119 | + public void onFailure(@NotNull Call call, @NotNull IOException e) { |
| 120 | + future.completeExceptionally(new IntercomException("Network error executing HTTP request", e)); |
| 121 | + } |
| 122 | + }); |
| 123 | + return future; |
| 124 | + } |
| 125 | + |
| 126 | + public CompletableFuture<IntercomHttpResponse<Void>> notifyNewConversation() { |
| 127 | + return notifyNewConversation(null); |
| 128 | + } |
| 129 | + |
| 130 | + public CompletableFuture<IntercomHttpResponse<Void>> notifyNewConversation(RequestOptions requestOptions) { |
| 131 | + HttpUrl httpUrl = HttpUrl.parse(this.clientOptions.environment().getUrl()) |
| 132 | + .newBuilder() |
| 133 | + .addPathSegments("custom_channel_events/notify_new_conversation") |
| 134 | + .build(); |
| 135 | + Request okhttpRequest = new Request.Builder() |
| 136 | + .url(httpUrl) |
| 137 | + .method("POST", RequestBody.create("", null)) |
| 138 | + .headers(Headers.of(clientOptions.headers(requestOptions))) |
| 139 | + .build(); |
| 140 | + OkHttpClient client = clientOptions.httpClient(); |
| 141 | + if (requestOptions != null && requestOptions.getTimeout().isPresent()) { |
| 142 | + client = clientOptions.httpClientWithTimeout(requestOptions); |
| 143 | + } |
| 144 | + CompletableFuture<IntercomHttpResponse<Void>> future = new CompletableFuture<>(); |
| 145 | + client.newCall(okhttpRequest).enqueue(new Callback() { |
| 146 | + @Override |
| 147 | + public void onResponse(@NotNull Call call, @NotNull Response response) throws IOException { |
| 148 | + try (ResponseBody responseBody = response.body()) { |
| 149 | + if (response.isSuccessful()) { |
| 150 | + future.complete(new IntercomHttpResponse<>(null, response)); |
| 151 | + return; |
| 152 | + } |
| 153 | + String responseBodyString = responseBody != null ? responseBody.string() : "{}"; |
| 154 | + future.completeExceptionally(new IntercomApiException( |
| 155 | + "Error with status code " + response.code(), |
| 156 | + response.code(), |
| 157 | + ObjectMappers.JSON_MAPPER.readValue(responseBodyString, Object.class), |
| 158 | + response)); |
| 159 | + return; |
| 160 | + } catch (IOException e) { |
| 161 | + future.completeExceptionally(new IntercomException("Network error executing HTTP request", e)); |
| 162 | + } |
| 163 | + } |
| 164 | + |
| 165 | + @Override |
| 166 | + public void onFailure(@NotNull Call call, @NotNull IOException e) { |
| 167 | + future.completeExceptionally(new IntercomException("Network error executing HTTP request", e)); |
| 168 | + } |
| 169 | + }); |
| 170 | + return future; |
| 171 | + } |
| 172 | + |
| 173 | + public CompletableFuture<IntercomHttpResponse<Void>> notifyQuickReplySelected() { |
| 174 | + return notifyQuickReplySelected(null); |
| 175 | + } |
| 176 | + |
| 177 | + public CompletableFuture<IntercomHttpResponse<Void>> notifyQuickReplySelected(RequestOptions requestOptions) { |
| 178 | + HttpUrl httpUrl = HttpUrl.parse(this.clientOptions.environment().getUrl()) |
| 179 | + .newBuilder() |
| 180 | + .addPathSegments("custom_channel_events/notify_quick_reply_selected") |
| 181 | + .build(); |
| 182 | + Request okhttpRequest = new Request.Builder() |
| 183 | + .url(httpUrl) |
| 184 | + .method("POST", RequestBody.create("", null)) |
| 185 | + .headers(Headers.of(clientOptions.headers(requestOptions))) |
| 186 | + .build(); |
| 187 | + OkHttpClient client = clientOptions.httpClient(); |
| 188 | + if (requestOptions != null && requestOptions.getTimeout().isPresent()) { |
| 189 | + client = clientOptions.httpClientWithTimeout(requestOptions); |
| 190 | + } |
| 191 | + CompletableFuture<IntercomHttpResponse<Void>> future = new CompletableFuture<>(); |
| 192 | + client.newCall(okhttpRequest).enqueue(new Callback() { |
| 193 | + @Override |
| 194 | + public void onResponse(@NotNull Call call, @NotNull Response response) throws IOException { |
| 195 | + try (ResponseBody responseBody = response.body()) { |
| 196 | + if (response.isSuccessful()) { |
| 197 | + future.complete(new IntercomHttpResponse<>(null, response)); |
| 198 | + return; |
| 199 | + } |
| 200 | + String responseBodyString = responseBody != null ? responseBody.string() : "{}"; |
| 201 | + future.completeExceptionally(new IntercomApiException( |
| 202 | + "Error with status code " + response.code(), |
| 203 | + response.code(), |
| 204 | + ObjectMappers.JSON_MAPPER.readValue(responseBodyString, Object.class), |
| 205 | + response)); |
| 206 | + return; |
| 207 | + } catch (IOException e) { |
| 208 | + future.completeExceptionally(new IntercomException("Network error executing HTTP request", e)); |
| 209 | + } |
| 210 | + } |
| 211 | + |
| 212 | + @Override |
| 213 | + public void onFailure(@NotNull Call call, @NotNull IOException e) { |
| 214 | + future.completeExceptionally(new IntercomException("Network error executing HTTP request", e)); |
| 215 | + } |
| 216 | + }); |
| 217 | + return future; |
| 218 | + } |
| 219 | +} |
0 commit comments