Skip to content

Commit d605410

Browse files
committed
feat (Conversation/Consents): API contract
1 parent d45c01b commit d605410

14 files changed

Lines changed: 1591 additions & 0 deletions
Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
/*
2+
* Conversation API | Sinch
3+
*
4+
* OpenAPI document version: 1.0
5+
* Contact: support@sinch.com
6+
*
7+
* NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech).
8+
* Do not edit the class manually.
9+
*/
10+
11+
package com.sinch.sdk.domains.conversation.api.v1;
12+
13+
import com.sinch.sdk.core.exceptions.ApiException;
14+
import com.sinch.sdk.domains.conversation.models.v1.consents.ConsentsListType;
15+
import com.sinch.sdk.domains.conversation.models.v1.consents.request.ConsentsListQueryParameters;
16+
import com.sinch.sdk.domains.conversation.models.v1.consents.response.AuditRecordsResponse;
17+
import com.sinch.sdk.domains.conversation.models.v1.consents.response.ConsentsListResponse;
18+
19+
/** Consents Service */
20+
public interface ConsentsService {
21+
22+
/**
23+
* Get audit records from consent lists
24+
*
25+
* <p>Get all audit records associated with the given identity from the consent lists within the
26+
* specified project and app.
27+
*
28+
* @param appId The unique ID of the app. You can find this on the [Sinch
29+
* Dashboard](https://dashboard.sinch.com/convapi/apps). (required)
30+
* @param identity An identity to use on Consent audit records queries. (required)
31+
* @return AuditRecordsResponse
32+
* @throws ApiException if fails to make API call
33+
*/
34+
AuditRecordsResponse listAuditRecords(String appId, String identity) throws ApiException;
35+
36+
/**
37+
* Get identities from consent list (using default parameters)
38+
*
39+
* <p>Get all identities contained within a consent list for a given project id, app id, and list
40+
* type.
41+
*
42+
* @param appId The unique ID of the app. You can find this on the [Sinch
43+
* Dashboard](https://dashboard.sinch.com/convapi/apps). (required)
44+
* @param listType The consent list type. One of &#x60;OPT_OUT_ALL&#x60;,
45+
* &#x60;OPT_OUT_MARKETING&#x60;, and or &#x60;OPT_OUT_NOTIFICATION&#x60;. (required)
46+
* @return ConsentsListResponse
47+
* @throws ApiException if fails to make API call
48+
*/
49+
ConsentsListResponse listIdentities(String appId, ConsentsListType listType) throws ApiException;
50+
51+
/**
52+
* Get identities from consent list
53+
*
54+
* <p>Get all identities contained within a consent list for a given project id, app id, and list
55+
* type.
56+
*
57+
* @param appId The unique ID of the app. You can find this on the [Sinch
58+
* Dashboard](https://dashboard.sinch.com/convapi/apps). (required)
59+
* @param listType The consent list type. One of &#x60;OPT_OUT_ALL&#x60;,
60+
* &#x60;OPT_OUT_MARKETING&#x60;, and or &#x60;OPT_OUT_NOTIFICATION&#x60;. (required)
61+
* @param queryParameter (optional)
62+
* @return ConsentsListResponse
63+
* @throws ApiException if fails to make API call
64+
*/
65+
ConsentsListResponse listIdentities(
66+
String appId, ConsentsListType listType, ConsentsListQueryParameters queryParameter)
67+
throws ApiException;
68+
}
Lines changed: 271 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,271 @@
1+
/*
2+
* Conversation API | Sinch
3+
*
4+
* OpenAPI document version: 1.0
5+
* Contact: support@sinch.com
6+
*
7+
* NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech).
8+
* Do not edit the class manually.
9+
*/
10+
11+
package com.sinch.sdk.domains.conversation.api.v1.adapters;
12+
13+
import com.fasterxml.jackson.core.type.TypeReference;
14+
import com.sinch.sdk.core.exceptions.ApiException;
15+
import com.sinch.sdk.core.exceptions.ApiExceptionBuilder;
16+
import com.sinch.sdk.core.http.AuthManager;
17+
import com.sinch.sdk.core.http.HttpClient;
18+
import com.sinch.sdk.core.http.HttpMapper;
19+
import com.sinch.sdk.core.http.HttpMethod;
20+
import com.sinch.sdk.core.http.HttpRequest;
21+
import com.sinch.sdk.core.http.HttpResponse;
22+
import com.sinch.sdk.core.http.HttpStatus;
23+
import com.sinch.sdk.core.http.URLParameter;
24+
import com.sinch.sdk.core.http.URLParameterUtils;
25+
import com.sinch.sdk.core.http.URLPathUtils;
26+
import com.sinch.sdk.core.models.ServerConfiguration;
27+
import com.sinch.sdk.core.models.pagination.Page;
28+
import com.sinch.sdk.core.models.pagination.PageNavigator;
29+
import com.sinch.sdk.core.utils.StringUtil;
30+
import com.sinch.sdk.domains.conversation.models.v1.consents.ConsentsListType;
31+
import com.sinch.sdk.domains.conversation.models.v1.consents.internal.ConsentsListResponseInternal;
32+
import com.sinch.sdk.domains.conversation.models.v1.consents.request.ConsentsListQueryParameters;
33+
import com.sinch.sdk.domains.conversation.models.v1.consents.response.AuditRecordsResponse;
34+
import com.sinch.sdk.domains.conversation.models.v1.consents.response.ConsentsListResponse;
35+
import java.util.ArrayList;
36+
import java.util.Arrays;
37+
import java.util.Collection;
38+
import java.util.HashMap;
39+
import java.util.List;
40+
import java.util.Map;
41+
import java.util.function.Function;
42+
import java.util.logging.Logger;
43+
44+
public class ConsentsServiceImpl
45+
implements com.sinch.sdk.domains.conversation.api.v1.ConsentsService {
46+
47+
private static final Logger LOGGER = Logger.getLogger(ConsentsServiceImpl.class.getName());
48+
private final HttpClient httpClient;
49+
private final ServerConfiguration serverConfiguration;
50+
private final Map<String, AuthManager> authManagersByOasSecuritySchemes;
51+
private final HttpMapper mapper;
52+
53+
private final String projectId;
54+
55+
public ConsentsServiceImpl(
56+
HttpClient httpClient,
57+
ServerConfiguration serverConfiguration,
58+
Map<String, AuthManager> authManagersByOasSecuritySchemes,
59+
HttpMapper mapper,
60+
String projectId) {
61+
this.httpClient = httpClient;
62+
this.serverConfiguration = serverConfiguration;
63+
this.authManagersByOasSecuritySchemes = authManagersByOasSecuritySchemes;
64+
this.mapper = mapper;
65+
this.projectId = projectId;
66+
}
67+
68+
@Override
69+
public AuditRecordsResponse listAuditRecords(String appId, String identity) throws ApiException {
70+
71+
LOGGER.finest("[listAuditRecords]" + " " + "appId: " + appId + ", " + "identity: " + identity);
72+
73+
HttpRequest httpRequest = listAuditRecordsRequestBuilder(appId, identity);
74+
HttpResponse response =
75+
httpClient.invokeAPI(
76+
this.serverConfiguration, this.authManagersByOasSecuritySchemes, httpRequest);
77+
78+
if (HttpStatus.isSuccessfulStatus(response.getCode())) {
79+
return mapper.deserialize(response, new TypeReference<AuditRecordsResponse>() {});
80+
}
81+
// fallback to default errors handling:
82+
// all error cases definition are not required from specs: will try some "hardcoded" content
83+
// parsing
84+
throw ApiExceptionBuilder.build(
85+
response.getMessage(),
86+
response.getCode(),
87+
mapper.deserialize(response, new TypeReference<HashMap<String, ?>>() {}));
88+
}
89+
90+
private HttpRequest listAuditRecordsRequestBuilder(String appId, String identity)
91+
throws ApiException {
92+
// verify the required parameter 'this.projectId' is set
93+
if (this.projectId == null) {
94+
throw new ApiException(
95+
400, "Missing the required parameter 'this.projectId' when calling listAuditRecords");
96+
}
97+
// verify the required parameter 'appId' is set
98+
if (appId == null) {
99+
throw new ApiException(
100+
400, "Missing the required parameter 'appId' when calling listAuditRecords");
101+
}
102+
// verify the required parameter 'identity' is set
103+
if (identity == null) {
104+
throw new ApiException(
105+
400, "Missing the required parameter 'identity' when calling listAuditRecords");
106+
}
107+
108+
String localVarPath =
109+
"/v1/projects/{project_id}/apps/{app_id}/consents/identities/{identity}"
110+
.replaceAll(
111+
"\\{" + "project_id" + "\\}",
112+
URLPathUtils.encodePathSegment(this.projectId.toString()))
113+
.replaceAll("\\{" + "app_id" + "\\}", URLPathUtils.encodePathSegment(appId.toString()))
114+
.replaceAll(
115+
"\\{" + "identity" + "\\}", URLPathUtils.encodePathSegment(identity.toString()));
116+
117+
List<URLParameter> localVarQueryParams = new ArrayList<>();
118+
119+
Map<String, String> localVarHeaderParams = new HashMap<>();
120+
121+
final Collection<String> localVarAccepts = Arrays.asList("application/json");
122+
123+
final Collection<String> localVarContentTypes = Arrays.asList();
124+
125+
final Collection<String> localVarAuthNames = Arrays.asList("Basic", "oAuth2");
126+
final String serializedBody = null;
127+
128+
return new HttpRequest(
129+
localVarPath,
130+
HttpMethod.GET,
131+
localVarQueryParams,
132+
serializedBody,
133+
localVarHeaderParams,
134+
localVarAccepts,
135+
localVarContentTypes,
136+
localVarAuthNames);
137+
}
138+
139+
@Override
140+
public ConsentsListResponse listIdentities(String appId, ConsentsListType listType)
141+
throws ApiException {
142+
return listIdentities(appId, listType, (ConsentsListQueryParameters) null);
143+
}
144+
145+
@Override
146+
public ConsentsListResponse listIdentities(
147+
String appId, ConsentsListType listType, ConsentsListQueryParameters queryParameter)
148+
throws ApiException {
149+
150+
LOGGER.finest(
151+
"[listIdentities]"
152+
+ " "
153+
+ "appId: "
154+
+ appId
155+
+ ", "
156+
+ "listType: "
157+
+ listType
158+
+ ", "
159+
+ "queryParameter: "
160+
+ queryParameter);
161+
162+
HttpRequest httpRequest = listIdentitiesRequestBuilder(appId, listType, queryParameter);
163+
return _fetchListIdentitiesPage(
164+
(queryParameters) -> listIdentitiesRequestBuilder(appId, listType, queryParameters),
165+
queryParameter,
166+
httpRequest);
167+
}
168+
169+
private ConsentsListResponse _fetchListIdentitiesPage(
170+
Function<ConsentsListQueryParameters, HttpRequest> requestBuilder,
171+
ConsentsListQueryParameters queryParameter,
172+
HttpRequest httpRequest)
173+
throws ApiException {
174+
HttpResponse response =
175+
httpClient.invokeAPI(
176+
this.serverConfiguration, this.authManagersByOasSecuritySchemes, httpRequest);
177+
178+
if (HttpStatus.isSuccessfulStatus(response.getCode())) {
179+
180+
ConsentsListResponseInternal deserialized =
181+
mapper.deserialize(response, new TypeReference<ConsentsListResponseInternal>() {});
182+
183+
String nextToken = deserialized.getNextPageToken();
184+
185+
ConsentsListQueryParameters nextParameters =
186+
ConsentsListQueryParameters.builder(queryParameter).setPageToken(nextToken).build();
187+
188+
final HttpRequest nextHttpRequest =
189+
!StringUtil.isEmpty(nextToken) ? requestBuilder.apply(nextParameters) : null;
190+
191+
return new ConsentsListResponse(
192+
() -> _fetchListIdentitiesPage(requestBuilder, nextParameters, nextHttpRequest),
193+
new Page<>(deserialized.getIdentities(), new PageNavigator<>(nextHttpRequest)));
194+
}
195+
// fallback to default errors handling:
196+
// all error cases definition are not required from specs: will try some "hardcoded" content
197+
// parsing
198+
throw ApiExceptionBuilder.build(
199+
response.getMessage(),
200+
response.getCode(),
201+
mapper.deserialize(response, new TypeReference<HashMap<String, ?>>() {}));
202+
}
203+
204+
private HttpRequest listIdentitiesRequestBuilder(
205+
String appId, ConsentsListType listType, ConsentsListQueryParameters queryParameter)
206+
throws ApiException {
207+
// verify the required parameter 'this.projectId' is set
208+
if (this.projectId == null) {
209+
throw new ApiException(
210+
400, "Missing the required parameter 'this.projectId' when calling listIdentities");
211+
}
212+
// verify the required parameter 'appId' is set
213+
if (appId == null) {
214+
throw new ApiException(
215+
400, "Missing the required parameter 'appId' when calling listIdentities");
216+
}
217+
// verify the required parameter 'listType' is set
218+
if (listType == null) {
219+
throw new ApiException(
220+
400, "Missing the required parameter 'listType' when calling listIdentities");
221+
}
222+
223+
String localVarPath =
224+
"/v1/projects/{project_id}/apps/{app_id}/consents/{list_type}"
225+
.replaceAll(
226+
"\\{" + "project_id" + "\\}",
227+
URLPathUtils.encodePathSegment(this.projectId.toString()))
228+
.replaceAll("\\{" + "app_id" + "\\}", URLPathUtils.encodePathSegment(appId.toString()))
229+
.replaceAll(
230+
"\\{" + "list_type" + "\\}", URLPathUtils.encodePathSegment(listType.toString()));
231+
232+
List<URLParameter> localVarQueryParams = new ArrayList<>();
233+
if (null != queryParameter) {
234+
235+
URLParameterUtils.addQueryParam(
236+
queryParameter.getPageSize(),
237+
"page_size",
238+
URLParameter.form,
239+
null,
240+
localVarQueryParams,
241+
true);
242+
243+
URLParameterUtils.addQueryParam(
244+
queryParameter.getPageToken(),
245+
"page_token",
246+
URLParameter.form,
247+
null,
248+
localVarQueryParams,
249+
true);
250+
}
251+
252+
Map<String, String> localVarHeaderParams = new HashMap<>();
253+
254+
final Collection<String> localVarAccepts = Arrays.asList("application/json");
255+
256+
final Collection<String> localVarContentTypes = Arrays.asList();
257+
258+
final Collection<String> localVarAuthNames = Arrays.asList("Basic", "oAuth2");
259+
final String serializedBody = null;
260+
261+
return new HttpRequest(
262+
localVarPath,
263+
HttpMethod.GET,
264+
localVarQueryParams,
265+
serializedBody,
266+
localVarHeaderParams,
267+
localVarAccepts,
268+
localVarContentTypes,
269+
localVarAuthNames);
270+
}
271+
}
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
package com.sinch.sdk.domains.conversation.models.v1.consents;
2+
3+
import com.sinch.sdk.core.utils.EnumDynamic;
4+
import com.sinch.sdk.core.utils.EnumSupportDynamic;
5+
import java.util.Arrays;
6+
import java.util.stream.Stream;
7+
8+
/**
9+
* The consent list type. See <a
10+
* href="https://developers.sinch.com/docs/conversation/consent-management">consent management</a>
11+
* page for more information.
12+
*/
13+
public class ConsentsListType extends EnumDynamic<String, ConsentsListType> {
14+
15+
/** List type that blocks all kinds of messages */
16+
public static final ConsentsListType OPT_OUT_ALL = new ConsentsListType("OPT_OUT_ALL");
17+
18+
/** List type that blocks only marketing messages */
19+
public static final ConsentsListType OPT_OUT_MARKETING =
20+
new ConsentsListType("OPT_OUT_MARKETING");
21+
22+
/** List type that blocks only notification messages */
23+
public static final ConsentsListType OPT_OUT_NOTIFICATION =
24+
new ConsentsListType("OPT_OUT_NOTIFICATION");
25+
26+
private static final EnumSupportDynamic<String, ConsentsListType> ENUM_SUPPORT =
27+
new EnumSupportDynamic<>(
28+
ConsentsListType.class,
29+
ConsentsListType::new,
30+
Arrays.asList(OPT_OUT_ALL, OPT_OUT_MARKETING, OPT_OUT_NOTIFICATION));
31+
32+
private ConsentsListType(String value) {
33+
super(value);
34+
}
35+
36+
public static Stream<ConsentsListType> values() {
37+
return ENUM_SUPPORT.values();
38+
}
39+
40+
public static ConsentsListType from(String value) {
41+
return ENUM_SUPPORT.from(value);
42+
}
43+
44+
public static String valueOf(ConsentsListType e) {
45+
return ENUM_SUPPORT.valueOf(e);
46+
}
47+
}

0 commit comments

Comments
 (0)