Skip to content

Commit 0a3ddba

Browse files
committed
增加批量设置群成员自定义属性功能
1 parent 000b001 commit 0a3ddba

File tree

4 files changed

+594
-0
lines changed

4 files changed

+594
-0
lines changed

src/main/java/com/easemob/im/api/MetadataApi.java

Lines changed: 113 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,119 @@ public void setCustomBaseUrl(String customBaseUrl) {
6666
this.localCustomBaseUrl = customBaseUrl;
6767
}
6868

69+
/**
70+
* Build call for batchCustomGroupMemberAttribute
71+
* @param groupId (required)
72+
* @param emBatchCustomGroupMemberAttribute (optional)
73+
* @param _callback Callback for upload/download progress
74+
* @return Call to execute
75+
* @throws ApiException If fail to serialize the request body object
76+
* http.response.details
77+
*/
78+
public okhttp3.Call batchCustomGroupMemberAttributeCall(String groupId, List<EMBatchCustomGroupMemberAttribute> emBatchCustomGroupMemberAttribute, final ApiCallback _callback) throws ApiException {
79+
String basePath = null;
80+
// Operation Servers
81+
String[] localBasePaths = new String[] { };
82+
83+
// Determine Base Path to Use
84+
if (localCustomBaseUrl != null){
85+
basePath = localCustomBaseUrl;
86+
} else if ( localBasePaths.length > 0 ) {
87+
basePath = localBasePaths[localHostIndex];
88+
} else {
89+
basePath = null;
90+
}
91+
92+
Object localVarPostBody = emBatchCustomGroupMemberAttribute;
93+
94+
// create path and map variables
95+
String localVarPath = "/metadata/chatgroup/{group_id}/users/batch"
96+
.replace("{" + "group_id" + "}", localVarApiClient.escapeString(groupId.toString()));
97+
98+
List<Pair> localVarQueryParams = new ArrayList<Pair>();
99+
List<Pair> localVarCollectionQueryParams = new ArrayList<Pair>();
100+
Map<String, String> localVarHeaderParams = new HashMap<String, String>();
101+
Map<String, String> localVarCookieParams = new HashMap<String, String>();
102+
Map<String, Object> localVarFormParams = new HashMap<String, Object>();
103+
104+
final String[] localVarAccepts = {
105+
"application/json"
106+
};
107+
final String localVarAccept = localVarApiClient.selectHeaderAccept(localVarAccepts);
108+
if (localVarAccept != null) {
109+
localVarHeaderParams.put("Accept", localVarAccept);
110+
}
111+
112+
final String[] localVarContentTypes = {
113+
"application/json"
114+
};
115+
final String localVarContentType = localVarApiClient.selectHeaderContentType(localVarContentTypes);
116+
if (localVarContentType != null) {
117+
localVarHeaderParams.put("Content-Type", localVarContentType);
118+
}
119+
120+
String[] localVarAuthNames = new String[] { };
121+
return localVarApiClient.buildCall(basePath, localVarPath, "PUT", localVarQueryParams, localVarCollectionQueryParams, localVarPostBody, localVarHeaderParams, localVarCookieParams, localVarFormParams, localVarAuthNames, _callback);
122+
}
123+
124+
@SuppressWarnings("rawtypes")
125+
private okhttp3.Call batchCustomGroupMemberAttributeValidateBeforeCall(String groupId, List<EMBatchCustomGroupMemberAttribute> emBatchCustomGroupMemberAttribute, final ApiCallback _callback) throws ApiException {
126+
// verify the required parameter 'groupId' is set
127+
if (groupId == null) {
128+
throw new ApiException("Missing the required parameter 'groupId' when calling batchCustomGroupMemberAttribute(Async)");
129+
}
130+
131+
return batchCustomGroupMemberAttributeCall(groupId, emBatchCustomGroupMemberAttribute, _callback);
132+
133+
}
134+
135+
/**
136+
* 批量设置群成员自定义属性
137+
* 批量设置群成员的自定义属性(key-value),例如,在群组中的昵称和头像等。每次请求最多可为 20 个群成员设置多个属性,而且可对不同群成员设置不同属性。传入相同用户 ID 时,若其属性名称不同,则添加,相同则更新。文档介绍:https://doc.easemob.com/document/server-side/group_member.html#%E6%89%B9%E9%87%8F%E8%AE%BE%E7%BD%AE%E7%BE%A4%E6%88%90%E5%91%98%E8%87%AA%E5%AE%9A%E4%B9%89%E5%B1%9E%E6%80%A7
138+
* @param groupId (required)
139+
* @param emBatchCustomGroupMemberAttribute (optional)
140+
* @return EMBatchCustomGroupMemberAttributeResult
141+
* @throws ApiException If fail to call the API, e.g. server error or cannot deserialize the response body
142+
* http.response.details
143+
*/
144+
public EMBatchCustomGroupMemberAttributeResult batchCustomGroupMemberAttribute(String groupId, List<EMBatchCustomGroupMemberAttribute> emBatchCustomGroupMemberAttribute) throws ApiException {
145+
ApiResponse<EMBatchCustomGroupMemberAttributeResult> localVarResp = batchCustomGroupMemberAttributeWithHttpInfo(groupId, emBatchCustomGroupMemberAttribute);
146+
return localVarResp.getData();
147+
}
148+
149+
/**
150+
* 批量设置群成员自定义属性
151+
* 批量设置群成员的自定义属性(key-value),例如,在群组中的昵称和头像等。每次请求最多可为 20 个群成员设置多个属性,而且可对不同群成员设置不同属性。传入相同用户 ID 时,若其属性名称不同,则添加,相同则更新。文档介绍:https://doc.easemob.com/document/server-side/group_member.html#%E6%89%B9%E9%87%8F%E8%AE%BE%E7%BD%AE%E7%BE%A4%E6%88%90%E5%91%98%E8%87%AA%E5%AE%9A%E4%B9%89%E5%B1%9E%E6%80%A7
152+
* @param groupId (required)
153+
* @param emBatchCustomGroupMemberAttribute (optional)
154+
* @return ApiResponse&lt;EMBatchCustomGroupMemberAttributeResult&gt;
155+
* @throws ApiException If fail to call the API, e.g. server error or cannot deserialize the response body
156+
* http.response.details
157+
*/
158+
public ApiResponse<EMBatchCustomGroupMemberAttributeResult> batchCustomGroupMemberAttributeWithHttpInfo(String groupId, List<EMBatchCustomGroupMemberAttribute> emBatchCustomGroupMemberAttribute) throws ApiException {
159+
okhttp3.Call localVarCall = batchCustomGroupMemberAttributeValidateBeforeCall(groupId, emBatchCustomGroupMemberAttribute, null);
160+
Type localVarReturnType = new TypeToken<EMBatchCustomGroupMemberAttributeResult>(){}.getType();
161+
return localVarApiClient.execute(localVarCall, localVarReturnType);
162+
}
163+
164+
/**
165+
* 批量设置群成员自定义属性 (asynchronously)
166+
* 批量设置群成员的自定义属性(key-value),例如,在群组中的昵称和头像等。每次请求最多可为 20 个群成员设置多个属性,而且可对不同群成员设置不同属性。传入相同用户 ID 时,若其属性名称不同,则添加,相同则更新。文档介绍:https://doc.easemob.com/document/server-side/group_member.html#%E6%89%B9%E9%87%8F%E8%AE%BE%E7%BD%AE%E7%BE%A4%E6%88%90%E5%91%98%E8%87%AA%E5%AE%9A%E4%B9%89%E5%B1%9E%E6%80%A7
167+
* @param groupId (required)
168+
* @param emBatchCustomGroupMemberAttribute (optional)
169+
* @param _callback The callback to be executed when the API call finishes
170+
* @return The request call
171+
* @throws ApiException If fail to process the API call, e.g. serializing the request body object
172+
* http.response.details
173+
*/
174+
public okhttp3.Call batchCustomGroupMemberAttributeAsync(String groupId, List<EMBatchCustomGroupMemberAttribute> emBatchCustomGroupMemberAttribute, final ApiCallback<EMBatchCustomGroupMemberAttributeResult> _callback) throws ApiException {
175+
176+
okhttp3.Call localVarCall = batchCustomGroupMemberAttributeValidateBeforeCall(groupId, emBatchCustomGroupMemberAttribute, _callback);
177+
Type localVarReturnType = new TypeToken<EMBatchCustomGroupMemberAttributeResult>(){}.getType();
178+
localVarApiClient.executeAsync(localVarCall, localVarReturnType, _callback);
179+
return localVarCall;
180+
}
181+
69182
/**
70183
* Build call for customGroupMemberAttribute
71184
* @param groupId (required)
Lines changed: 216 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,216 @@
1+
/*
2+
* EMService
3+
* Easemob Rest API
4+
*
5+
* The version of the OpenAPI document: 1.0.0
6+
*
7+
*
8+
* NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech).
9+
* https://openapi-generator.tech
10+
* Do not edit the class manually.
11+
*/
12+
13+
14+
package com.easemob.im.api.model;
15+
16+
import com.easemob.im.JSON;
17+
import com.google.gson.*;
18+
import com.google.gson.annotations.SerializedName;
19+
import com.google.gson.reflect.TypeToken;
20+
import com.google.gson.stream.JsonReader;
21+
import com.google.gson.stream.JsonWriter;
22+
23+
import java.io.IOException;
24+
import java.util.HashSet;
25+
import java.util.Map;
26+
import java.util.Objects;
27+
import java.util.Set;
28+
29+
/**
30+
* EMBatchCustomGroupMemberAttribute
31+
*/
32+
@javax.annotation.Generated(value = "org.openapitools.codegen.languages.JavaClientCodegen", date = "2024-11-20T11:16:55.650302+08:00[Asia/Shanghai]")
33+
public class EMBatchCustomGroupMemberAttribute {
34+
public static final String SERIALIZED_NAME_USERNAME = "username";
35+
@SerializedName(SERIALIZED_NAME_USERNAME)
36+
private String username;
37+
38+
public static final String SERIALIZED_NAME_METADATA = "metadata";
39+
@SerializedName(SERIALIZED_NAME_METADATA)
40+
private Object metadata;
41+
42+
public EMBatchCustomGroupMemberAttribute() {
43+
}
44+
45+
public EMBatchCustomGroupMemberAttribute username(String username) {
46+
47+
this.username = username;
48+
return this;
49+
}
50+
51+
/**
52+
* 用户 ID,长度不可超过 64 字节
53+
* @return username
54+
**/
55+
@javax.annotation.Nullable
56+
public String getUsername() {
57+
return username;
58+
}
59+
60+
61+
public void setUsername(String username) {
62+
this.username = username;
63+
}
64+
65+
66+
public EMBatchCustomGroupMemberAttribute metadata(Object metadata) {
67+
68+
this.metadata = metadata;
69+
return this;
70+
}
71+
72+
/**
73+
* 要设置的群成员自定义属性,为 key-value 键值对。对于单个键值对: - key 表示属性名称,不能超过 16 字节。 - value 表示属性值,不能超过 512 个字节。若 value 设置为空字符串即删除该自定义属性。 单个群成员的自定义属性总长度不能超过 4 KB
74+
* @return metadata
75+
**/
76+
@javax.annotation.Nullable
77+
public Object getMetadata() {
78+
return metadata;
79+
}
80+
81+
82+
public void setMetadata(Object metadata) {
83+
this.metadata = metadata;
84+
}
85+
86+
87+
88+
@Override
89+
public boolean equals(Object o) {
90+
if (this == o) {
91+
return true;
92+
}
93+
if (o == null || getClass() != o.getClass()) {
94+
return false;
95+
}
96+
EMBatchCustomGroupMemberAttribute batchCustomGroupMemberAttribute = (EMBatchCustomGroupMemberAttribute) o;
97+
return Objects.equals(this.username, batchCustomGroupMemberAttribute.username) &&
98+
Objects.equals(this.metadata, batchCustomGroupMemberAttribute.metadata);
99+
}
100+
101+
@Override
102+
public int hashCode() {
103+
return Objects.hash(username, metadata);
104+
}
105+
106+
@Override
107+
public String toString() {
108+
StringBuilder sb = new StringBuilder();
109+
sb.append("class EMBatchCustomGroupMemberAttribute {\n");
110+
sb.append(" username: ").append(toIndentedString(username)).append("\n");
111+
sb.append(" metadata: ").append(toIndentedString(metadata)).append("\n");
112+
sb.append("}");
113+
return sb.toString();
114+
}
115+
116+
/**
117+
* Convert the given object to string with each line indented by 4 spaces
118+
* (except the first line).
119+
*/
120+
private String toIndentedString(Object o) {
121+
if (o == null) {
122+
return "null";
123+
}
124+
return o.toString().replace("\n", "\n ");
125+
}
126+
127+
128+
public static HashSet<String> openapiFields;
129+
public static HashSet<String> openapiRequiredFields;
130+
131+
static {
132+
// a set of all properties/fields (JSON key names)
133+
openapiFields = new HashSet<String>();
134+
openapiFields.add("username");
135+
openapiFields.add("metadata");
136+
137+
// a set of required properties/fields (JSON key names)
138+
openapiRequiredFields = new HashSet<String>();
139+
}
140+
141+
/**
142+
* Validates the JSON Element and throws an exception if issues found
143+
*
144+
* @param jsonElement JSON Element
145+
* @throws IOException if the JSON Element is invalid with respect to EMBatchCustomGroupMemberAttribute
146+
*/
147+
public static void validateJsonElement(JsonElement jsonElement) throws IOException {
148+
if (jsonElement == null) {
149+
if (!EMBatchCustomGroupMemberAttribute.openapiRequiredFields.isEmpty()) { // has required fields but JSON element is null
150+
throw new IllegalArgumentException(String.format("The required field(s) %s in EMBatchCustomGroupMemberAttribute is not found in the empty JSON string", EMBatchCustomGroupMemberAttribute.openapiRequiredFields.toString()));
151+
}
152+
}
153+
154+
Set<Map.Entry<String, JsonElement>> entries = jsonElement.getAsJsonObject().entrySet();
155+
// check to see if the JSON string contains additional fields
156+
for (Map.Entry<String, JsonElement> entry : entries) {
157+
if (!EMBatchCustomGroupMemberAttribute.openapiFields.contains(entry.getKey())) {
158+
throw new IllegalArgumentException(String.format("The field `%s` in the JSON string is not defined in the `EMBatchCustomGroupMemberAttribute` properties. JSON: %s", entry.getKey(), jsonElement.toString()));
159+
}
160+
}
161+
JsonObject jsonObj = jsonElement.getAsJsonObject();
162+
if ((jsonObj.get("username") != null && !jsonObj.get("username").isJsonNull()) && !jsonObj.get("username").isJsonPrimitive()) {
163+
throw new IllegalArgumentException(String.format("Expected the field `username` to be a primitive type in the JSON string but got `%s`", jsonObj.get("username").toString()));
164+
}
165+
}
166+
167+
public static class CustomTypeAdapterFactory implements TypeAdapterFactory {
168+
@SuppressWarnings("unchecked")
169+
@Override
170+
public <T> TypeAdapter<T> create(Gson gson, TypeToken<T> type) {
171+
if (!EMBatchCustomGroupMemberAttribute.class.isAssignableFrom(type.getRawType())) {
172+
return null; // this class only serializes 'EMBatchCustomGroupMemberAttribute' and its subtypes
173+
}
174+
final TypeAdapter<JsonElement> elementAdapter = gson.getAdapter(JsonElement.class);
175+
final TypeAdapter<EMBatchCustomGroupMemberAttribute> thisAdapter
176+
= gson.getDelegateAdapter(this, TypeToken.get(EMBatchCustomGroupMemberAttribute.class));
177+
178+
return (TypeAdapter<T>) new TypeAdapter<EMBatchCustomGroupMemberAttribute>() {
179+
@Override
180+
public void write(JsonWriter out, EMBatchCustomGroupMemberAttribute value) throws IOException {
181+
JsonObject obj = thisAdapter.toJsonTree(value).getAsJsonObject();
182+
elementAdapter.write(out, obj);
183+
}
184+
185+
@Override
186+
public EMBatchCustomGroupMemberAttribute read(JsonReader in) throws IOException {
187+
JsonElement jsonElement = elementAdapter.read(in);
188+
validateJsonElement(jsonElement);
189+
return thisAdapter.fromJsonTree(jsonElement);
190+
}
191+
192+
}.nullSafe();
193+
}
194+
}
195+
196+
/**
197+
* Create an instance of EMBatchCustomGroupMemberAttribute given an JSON string
198+
*
199+
* @param jsonString JSON string
200+
* @return An instance of EMBatchCustomGroupMemberAttribute
201+
* @throws IOException if the JSON string is invalid with respect to EMBatchCustomGroupMemberAttribute
202+
*/
203+
public static EMBatchCustomGroupMemberAttribute fromJson(String jsonString) throws IOException {
204+
return JSON.getGson().fromJson(jsonString, EMBatchCustomGroupMemberAttribute.class);
205+
}
206+
207+
/**
208+
* Convert an instance of EMBatchCustomGroupMemberAttribute to an JSON string
209+
*
210+
* @return JSON string
211+
*/
212+
public String toJson() {
213+
return JSON.getGson().toJson(this);
214+
}
215+
}
216+

0 commit comments

Comments
 (0)