Skip to content

Commit

Permalink
增加批量设置群成员自定义属性功能
Browse files Browse the repository at this point in the history
  • Loading branch information
FuDongHai committed Nov 20, 2024
1 parent 000b001 commit 0a3ddba
Show file tree
Hide file tree
Showing 4 changed files with 594 additions and 0 deletions.
113 changes: 113 additions & 0 deletions src/main/java/com/easemob/im/api/MetadataApi.java
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,119 @@ public void setCustomBaseUrl(String customBaseUrl) {
this.localCustomBaseUrl = customBaseUrl;
}

/**
* Build call for batchCustomGroupMemberAttribute
* @param groupId (required)
* @param emBatchCustomGroupMemberAttribute (optional)
* @param _callback Callback for upload/download progress
* @return Call to execute
* @throws ApiException If fail to serialize the request body object
* http.response.details
*/
public okhttp3.Call batchCustomGroupMemberAttributeCall(String groupId, List<EMBatchCustomGroupMemberAttribute> emBatchCustomGroupMemberAttribute, final ApiCallback _callback) throws ApiException {
String basePath = null;
// Operation Servers
String[] localBasePaths = new String[] { };

// Determine Base Path to Use
if (localCustomBaseUrl != null){
basePath = localCustomBaseUrl;
} else if ( localBasePaths.length > 0 ) {
basePath = localBasePaths[localHostIndex];
} else {
basePath = null;
}

Object localVarPostBody = emBatchCustomGroupMemberAttribute;

// create path and map variables
String localVarPath = "/metadata/chatgroup/{group_id}/users/batch"
.replace("{" + "group_id" + "}", localVarApiClient.escapeString(groupId.toString()));

List<Pair> localVarQueryParams = new ArrayList<Pair>();
List<Pair> localVarCollectionQueryParams = new ArrayList<Pair>();
Map<String, String> localVarHeaderParams = new HashMap<String, String>();
Map<String, String> localVarCookieParams = new HashMap<String, String>();
Map<String, Object> localVarFormParams = new HashMap<String, Object>();

final String[] localVarAccepts = {
"application/json"
};
final String localVarAccept = localVarApiClient.selectHeaderAccept(localVarAccepts);
if (localVarAccept != null) {
localVarHeaderParams.put("Accept", localVarAccept);
}

final String[] localVarContentTypes = {
"application/json"
};
final String localVarContentType = localVarApiClient.selectHeaderContentType(localVarContentTypes);
if (localVarContentType != null) {
localVarHeaderParams.put("Content-Type", localVarContentType);
}

String[] localVarAuthNames = new String[] { };
return localVarApiClient.buildCall(basePath, localVarPath, "PUT", localVarQueryParams, localVarCollectionQueryParams, localVarPostBody, localVarHeaderParams, localVarCookieParams, localVarFormParams, localVarAuthNames, _callback);
}

@SuppressWarnings("rawtypes")
private okhttp3.Call batchCustomGroupMemberAttributeValidateBeforeCall(String groupId, List<EMBatchCustomGroupMemberAttribute> emBatchCustomGroupMemberAttribute, final ApiCallback _callback) throws ApiException {
// verify the required parameter 'groupId' is set
if (groupId == null) {
throw new ApiException("Missing the required parameter 'groupId' when calling batchCustomGroupMemberAttribute(Async)");
}

return batchCustomGroupMemberAttributeCall(groupId, emBatchCustomGroupMemberAttribute, _callback);

}

/**
* 批量设置群成员自定义属性
* 批量设置群成员的自定义属性(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
* @param groupId (required)
* @param emBatchCustomGroupMemberAttribute (optional)
* @return EMBatchCustomGroupMemberAttributeResult
* @throws ApiException If fail to call the API, e.g. server error or cannot deserialize the response body
* http.response.details
*/
public EMBatchCustomGroupMemberAttributeResult batchCustomGroupMemberAttribute(String groupId, List<EMBatchCustomGroupMemberAttribute> emBatchCustomGroupMemberAttribute) throws ApiException {
ApiResponse<EMBatchCustomGroupMemberAttributeResult> localVarResp = batchCustomGroupMemberAttributeWithHttpInfo(groupId, emBatchCustomGroupMemberAttribute);
return localVarResp.getData();
}

/**
* 批量设置群成员自定义属性
* 批量设置群成员的自定义属性(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
* @param groupId (required)
* @param emBatchCustomGroupMemberAttribute (optional)
* @return ApiResponse&lt;EMBatchCustomGroupMemberAttributeResult&gt;
* @throws ApiException If fail to call the API, e.g. server error or cannot deserialize the response body
* http.response.details
*/
public ApiResponse<EMBatchCustomGroupMemberAttributeResult> batchCustomGroupMemberAttributeWithHttpInfo(String groupId, List<EMBatchCustomGroupMemberAttribute> emBatchCustomGroupMemberAttribute) throws ApiException {
okhttp3.Call localVarCall = batchCustomGroupMemberAttributeValidateBeforeCall(groupId, emBatchCustomGroupMemberAttribute, null);
Type localVarReturnType = new TypeToken<EMBatchCustomGroupMemberAttributeResult>(){}.getType();
return localVarApiClient.execute(localVarCall, localVarReturnType);
}

/**
* 批量设置群成员自定义属性 (asynchronously)
* 批量设置群成员的自定义属性(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
* @param groupId (required)
* @param emBatchCustomGroupMemberAttribute (optional)
* @param _callback The callback to be executed when the API call finishes
* @return The request call
* @throws ApiException If fail to process the API call, e.g. serializing the request body object
* http.response.details
*/
public okhttp3.Call batchCustomGroupMemberAttributeAsync(String groupId, List<EMBatchCustomGroupMemberAttribute> emBatchCustomGroupMemberAttribute, final ApiCallback<EMBatchCustomGroupMemberAttributeResult> _callback) throws ApiException {

okhttp3.Call localVarCall = batchCustomGroupMemberAttributeValidateBeforeCall(groupId, emBatchCustomGroupMemberAttribute, _callback);
Type localVarReturnType = new TypeToken<EMBatchCustomGroupMemberAttributeResult>(){}.getType();
localVarApiClient.executeAsync(localVarCall, localVarReturnType, _callback);
return localVarCall;
}

/**
* Build call for customGroupMemberAttribute
* @param groupId (required)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,216 @@
/*
* EMService
* Easemob Rest API
*
* The version of the OpenAPI document: 1.0.0
*
*
* NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech).
* https://openapi-generator.tech
* Do not edit the class manually.
*/


package com.easemob.im.api.model;

import com.easemob.im.JSON;
import com.google.gson.*;
import com.google.gson.annotations.SerializedName;
import com.google.gson.reflect.TypeToken;
import com.google.gson.stream.JsonReader;
import com.google.gson.stream.JsonWriter;

import java.io.IOException;
import java.util.HashSet;
import java.util.Map;
import java.util.Objects;
import java.util.Set;

/**
* EMBatchCustomGroupMemberAttribute
*/
@javax.annotation.Generated(value = "org.openapitools.codegen.languages.JavaClientCodegen", date = "2024-11-20T11:16:55.650302+08:00[Asia/Shanghai]")
public class EMBatchCustomGroupMemberAttribute {
public static final String SERIALIZED_NAME_USERNAME = "username";
@SerializedName(SERIALIZED_NAME_USERNAME)
private String username;

public static final String SERIALIZED_NAME_METADATA = "metadata";
@SerializedName(SERIALIZED_NAME_METADATA)
private Object metadata;

public EMBatchCustomGroupMemberAttribute() {
}

public EMBatchCustomGroupMemberAttribute username(String username) {

this.username = username;
return this;
}

/**
* 用户 ID,长度不可超过 64 字节
* @return username
**/
@javax.annotation.Nullable
public String getUsername() {
return username;
}


public void setUsername(String username) {
this.username = username;
}


public EMBatchCustomGroupMemberAttribute metadata(Object metadata) {

this.metadata = metadata;
return this;
}

/**
* 要设置的群成员自定义属性,为 key-value 键值对。对于单个键值对: - key 表示属性名称,不能超过 16 字节。 - value 表示属性值,不能超过 512 个字节。若 value 设置为空字符串即删除该自定义属性。 单个群成员的自定义属性总长度不能超过 4 KB
* @return metadata
**/
@javax.annotation.Nullable
public Object getMetadata() {
return metadata;
}


public void setMetadata(Object metadata) {
this.metadata = metadata;
}



@Override
public boolean equals(Object o) {
if (this == o) {
return true;
}
if (o == null || getClass() != o.getClass()) {
return false;
}
EMBatchCustomGroupMemberAttribute batchCustomGroupMemberAttribute = (EMBatchCustomGroupMemberAttribute) o;
return Objects.equals(this.username, batchCustomGroupMemberAttribute.username) &&
Objects.equals(this.metadata, batchCustomGroupMemberAttribute.metadata);
}

@Override
public int hashCode() {
return Objects.hash(username, metadata);
}

@Override
public String toString() {
StringBuilder sb = new StringBuilder();
sb.append("class EMBatchCustomGroupMemberAttribute {\n");
sb.append(" username: ").append(toIndentedString(username)).append("\n");
sb.append(" metadata: ").append(toIndentedString(metadata)).append("\n");
sb.append("}");
return sb.toString();
}

/**
* Convert the given object to string with each line indented by 4 spaces
* (except the first line).
*/
private String toIndentedString(Object o) {
if (o == null) {
return "null";
}
return o.toString().replace("\n", "\n ");
}


public static HashSet<String> openapiFields;
public static HashSet<String> openapiRequiredFields;

static {
// a set of all properties/fields (JSON key names)
openapiFields = new HashSet<String>();
openapiFields.add("username");
openapiFields.add("metadata");

// a set of required properties/fields (JSON key names)
openapiRequiredFields = new HashSet<String>();
}

/**
* Validates the JSON Element and throws an exception if issues found
*
* @param jsonElement JSON Element
* @throws IOException if the JSON Element is invalid with respect to EMBatchCustomGroupMemberAttribute
*/
public static void validateJsonElement(JsonElement jsonElement) throws IOException {
if (jsonElement == null) {
if (!EMBatchCustomGroupMemberAttribute.openapiRequiredFields.isEmpty()) { // has required fields but JSON element is null
throw new IllegalArgumentException(String.format("The required field(s) %s in EMBatchCustomGroupMemberAttribute is not found in the empty JSON string", EMBatchCustomGroupMemberAttribute.openapiRequiredFields.toString()));
}
}

Set<Map.Entry<String, JsonElement>> entries = jsonElement.getAsJsonObject().entrySet();
// check to see if the JSON string contains additional fields
for (Map.Entry<String, JsonElement> entry : entries) {
if (!EMBatchCustomGroupMemberAttribute.openapiFields.contains(entry.getKey())) {
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()));
}
}
JsonObject jsonObj = jsonElement.getAsJsonObject();
if ((jsonObj.get("username") != null && !jsonObj.get("username").isJsonNull()) && !jsonObj.get("username").isJsonPrimitive()) {
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()));
}
}

public static class CustomTypeAdapterFactory implements TypeAdapterFactory {
@SuppressWarnings("unchecked")
@Override
public <T> TypeAdapter<T> create(Gson gson, TypeToken<T> type) {
if (!EMBatchCustomGroupMemberAttribute.class.isAssignableFrom(type.getRawType())) {
return null; // this class only serializes 'EMBatchCustomGroupMemberAttribute' and its subtypes
}
final TypeAdapter<JsonElement> elementAdapter = gson.getAdapter(JsonElement.class);
final TypeAdapter<EMBatchCustomGroupMemberAttribute> thisAdapter
= gson.getDelegateAdapter(this, TypeToken.get(EMBatchCustomGroupMemberAttribute.class));

return (TypeAdapter<T>) new TypeAdapter<EMBatchCustomGroupMemberAttribute>() {
@Override
public void write(JsonWriter out, EMBatchCustomGroupMemberAttribute value) throws IOException {
JsonObject obj = thisAdapter.toJsonTree(value).getAsJsonObject();
elementAdapter.write(out, obj);
}

@Override
public EMBatchCustomGroupMemberAttribute read(JsonReader in) throws IOException {
JsonElement jsonElement = elementAdapter.read(in);
validateJsonElement(jsonElement);
return thisAdapter.fromJsonTree(jsonElement);
}

}.nullSafe();
}
}

/**
* Create an instance of EMBatchCustomGroupMemberAttribute given an JSON string
*
* @param jsonString JSON string
* @return An instance of EMBatchCustomGroupMemberAttribute
* @throws IOException if the JSON string is invalid with respect to EMBatchCustomGroupMemberAttribute
*/
public static EMBatchCustomGroupMemberAttribute fromJson(String jsonString) throws IOException {
return JSON.getGson().fromJson(jsonString, EMBatchCustomGroupMemberAttribute.class);
}

/**
* Convert an instance of EMBatchCustomGroupMemberAttribute to an JSON string
*
* @return JSON string
*/
public String toJson() {
return JSON.getGson().toJson(this);
}
}

Loading

0 comments on commit 0a3ddba

Please sign in to comment.