|
8 | 8 | import com.polytomic.api.core.MediaTypes; |
9 | 9 | import com.polytomic.api.core.ObjectMappers; |
10 | 10 | import com.polytomic.api.core.RequestOptions; |
| 11 | +import com.polytomic.api.resources.connections.requests.ApiRequest; |
11 | 12 | import com.polytomic.api.resources.connections.requests.ConnectCardRequest; |
12 | 13 | import com.polytomic.api.resources.connections.requests.ConnectionsRemoveRequest; |
13 | 14 | import com.polytomic.api.resources.connections.requests.CreateConnectionRequestSchema; |
| 15 | +import com.polytomic.api.resources.connections.requests.GetConnectionTypeParameterValuesRequestSchema; |
14 | 16 | import com.polytomic.api.resources.connections.requests.TestConnectionRequest; |
15 | 17 | import com.polytomic.api.resources.connections.requests.UpdateConnectionRequestSchema; |
16 | 18 | import com.polytomic.api.types.ConnectCardResponseEnvelope; |
|
20 | 22 | import com.polytomic.api.types.ConnectionTypeResponseEnvelope; |
21 | 23 | import com.polytomic.api.types.CreateConnectionResponseEnvelope; |
22 | 24 | import com.polytomic.api.types.JsonschemaSchema; |
| 25 | +import com.polytomic.api.types.V2CreateSharedConnectionResponseEnvelope; |
23 | 26 | import java.io.IOException; |
24 | 27 | import okhttp3.Headers; |
25 | 28 | import okhttp3.HttpUrl; |
@@ -105,6 +108,52 @@ public JsonschemaSchema getConnectionTypeSchema(String id, RequestOptions reques |
105 | 108 | } |
106 | 109 | } |
107 | 110 |
|
| 111 | + public ConnectionParameterValuesResponseEnvelope getTypeParameterValues( |
| 112 | + String type, GetConnectionTypeParameterValuesRequestSchema request) { |
| 113 | + return getTypeParameterValues(type, request, null); |
| 114 | + } |
| 115 | + |
| 116 | + public ConnectionParameterValuesResponseEnvelope getTypeParameterValues( |
| 117 | + String type, GetConnectionTypeParameterValuesRequestSchema request, RequestOptions requestOptions) { |
| 118 | + HttpUrl httpUrl = HttpUrl.parse(this.clientOptions.environment().getUrl()) |
| 119 | + .newBuilder() |
| 120 | + .addPathSegments("api/connection_types") |
| 121 | + .addPathSegment(type) |
| 122 | + .addPathSegments("parameter_values") |
| 123 | + .build(); |
| 124 | + RequestBody body; |
| 125 | + try { |
| 126 | + body = RequestBody.create( |
| 127 | + ObjectMappers.JSON_MAPPER.writeValueAsBytes(request), MediaTypes.APPLICATION_JSON); |
| 128 | + } catch (Exception e) { |
| 129 | + throw new RuntimeException(e); |
| 130 | + } |
| 131 | + Request okhttpRequest = new Request.Builder() |
| 132 | + .url(httpUrl) |
| 133 | + .method("POST", body) |
| 134 | + .headers(Headers.of(clientOptions.headers(requestOptions))) |
| 135 | + .addHeader("Content-Type", "application/json") |
| 136 | + .build(); |
| 137 | + try { |
| 138 | + OkHttpClient client = clientOptions.httpClient(); |
| 139 | + if (requestOptions != null && requestOptions.getTimeout().isPresent()) { |
| 140 | + client = clientOptions.httpClientWithTimeout(requestOptions); |
| 141 | + } |
| 142 | + Response response = client.newCall(okhttpRequest).execute(); |
| 143 | + ResponseBody responseBody = response.body(); |
| 144 | + if (response.isSuccessful()) { |
| 145 | + return ObjectMappers.JSON_MAPPER.readValue( |
| 146 | + responseBody.string(), ConnectionParameterValuesResponseEnvelope.class); |
| 147 | + } |
| 148 | + throw new ApiError( |
| 149 | + response.code(), |
| 150 | + ObjectMappers.JSON_MAPPER.readValue( |
| 151 | + responseBody != null ? responseBody.string() : "{}", Object.class)); |
| 152 | + } catch (IOException e) { |
| 153 | + throw new RuntimeException(e); |
| 154 | + } |
| 155 | + } |
| 156 | + |
108 | 157 | public ConnectionListResponseEnvelope list() { |
109 | 158 | return list(null); |
110 | 159 | } |
@@ -445,4 +494,49 @@ public ConnectionParameterValuesResponseEnvelope getParameterValues(String id, R |
445 | 494 | throw new RuntimeException(e); |
446 | 495 | } |
447 | 496 | } |
| 497 | + |
| 498 | + public V2CreateSharedConnectionResponseEnvelope apiV2CreateSharedConnection(String id, ApiRequest request) { |
| 499 | + return apiV2CreateSharedConnection(id, request, null); |
| 500 | + } |
| 501 | + |
| 502 | + public V2CreateSharedConnectionResponseEnvelope apiV2CreateSharedConnection( |
| 503 | + String id, ApiRequest request, RequestOptions requestOptions) { |
| 504 | + HttpUrl httpUrl = HttpUrl.parse(this.clientOptions.environment().getUrl()) |
| 505 | + .newBuilder() |
| 506 | + .addPathSegments("api/connections") |
| 507 | + .addPathSegment(id) |
| 508 | + .addPathSegments("share") |
| 509 | + .build(); |
| 510 | + RequestBody body; |
| 511 | + try { |
| 512 | + body = RequestBody.create( |
| 513 | + ObjectMappers.JSON_MAPPER.writeValueAsBytes(request), MediaTypes.APPLICATION_JSON); |
| 514 | + } catch (Exception e) { |
| 515 | + throw new RuntimeException(e); |
| 516 | + } |
| 517 | + Request okhttpRequest = new Request.Builder() |
| 518 | + .url(httpUrl) |
| 519 | + .method("POST", body) |
| 520 | + .headers(Headers.of(clientOptions.headers(requestOptions))) |
| 521 | + .addHeader("Content-Type", "application/json") |
| 522 | + .build(); |
| 523 | + try { |
| 524 | + OkHttpClient client = clientOptions.httpClient(); |
| 525 | + if (requestOptions != null && requestOptions.getTimeout().isPresent()) { |
| 526 | + client = clientOptions.httpClientWithTimeout(requestOptions); |
| 527 | + } |
| 528 | + Response response = client.newCall(okhttpRequest).execute(); |
| 529 | + ResponseBody responseBody = response.body(); |
| 530 | + if (response.isSuccessful()) { |
| 531 | + return ObjectMappers.JSON_MAPPER.readValue( |
| 532 | + responseBody.string(), V2CreateSharedConnectionResponseEnvelope.class); |
| 533 | + } |
| 534 | + throw new ApiError( |
| 535 | + response.code(), |
| 536 | + ObjectMappers.JSON_MAPPER.readValue( |
| 537 | + responseBody != null ? responseBody.string() : "{}", Object.class)); |
| 538 | + } catch (IOException e) { |
| 539 | + throw new RuntimeException(e); |
| 540 | + } |
| 541 | + } |
448 | 542 | } |
0 commit comments