Skip to content

Commit

Permalink
Add modify user push nicknames and send message example
Browse files Browse the repository at this point in the history
  • Loading branch information
FuDongHai committed Jun 25, 2024
1 parent 25f642c commit 5626f61
Show file tree
Hide file tree
Showing 12 changed files with 2,506 additions and 128 deletions.
126 changes: 101 additions & 25 deletions src/main/java/com/easemob/im/api/UserApi.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,34 +19,10 @@
import com.easemob.im.ApiResponse;
import com.easemob.im.Configuration;
import com.easemob.im.Pair;
import com.easemob.im.ProgressRequestBody;
import com.easemob.im.ProgressResponseBody;

import com.easemob.im.api.model.*;
import com.google.gson.reflect.TypeToken;

import java.io.IOException;


import com.easemob.im.api.model.EMCreateUser;
import com.easemob.im.api.model.EMCreateUsersResult;
import com.easemob.im.api.model.EMDeleteUserResult;
import com.easemob.im.api.model.EMDeleteUsersResult;
import com.easemob.im.api.model.EMForceUserLogoutResult;
import com.easemob.im.api.model.EMGetAllGloballyMutedUsersResult;
import com.easemob.im.api.model.EMGetOfflineMessageStatusResult;
import com.easemob.im.api.model.EMGetUserGlobalMuteResult;
import com.easemob.im.api.model.EMGetUserOfflineMessageCountResult;
import com.easemob.im.api.model.EMGetUserOnlineLoginDeviceListResult;
import com.easemob.im.api.model.EMGetUserOnlineStateResult;
import com.easemob.im.api.model.EMGetUserResult;
import com.easemob.im.api.model.EMGetUsersOnlineState;
import com.easemob.im.api.model.EMGetUsersOnlineStateResult;
import com.easemob.im.api.model.EMGetUsersResult;
import com.easemob.im.api.model.EMModifyUserPassword;
import com.easemob.im.api.model.EMSetUserGlobalMute;
import com.easemob.im.api.model.EMSetUserGlobalMuteResult;
import com.easemob.im.api.model.EMUserDeactivateResult;

import java.lang.reflect.Type;
import java.util.ArrayList;
import java.util.HashMap;
Expand Down Expand Up @@ -1917,4 +1893,104 @@ public okhttp3.Call userDeactivateAsync(String username, final ApiCallback<EMUse
localVarApiClient.executeAsync(localVarCall, localVarReturnType, _callback);
return localVarCall;
}

/**
* Build call for modifyPushNicknames
* @param emModifyPushNickname (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 modifyPushNicknamesCall(List<EMModifyPushNickname> emModifyPushNickname, 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 = emModifyPushNickname;

// create path and map variables
String localVarPath = "/push/nickname";

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 modifyPushNicknamesValidateBeforeCall(List<EMModifyPushNickname> emModifyPushNickname, final ApiCallback _callback) throws ApiException {
return modifyPushNicknamesCall(emModifyPushNickname, _callback);

}

/**
* 批量修改用户推送昵称
* @param emModifyPushNickname (optional)
* @return EMModifyPushNicknamesResult
* @throws ApiException If fail to call the API, e.g. server error or cannot deserialize the response body
* http.response.details
*/
public EMModifyPushNicknamesResult modifyPushNicknames(List<EMModifyPushNickname> emModifyPushNickname) throws ApiException {
ApiResponse<EMModifyPushNicknamesResult> localVarResp = modifyPushNicknamesWithHttpInfo(emModifyPushNickname);
return localVarResp.getData();
}

/**
* 批量修改用户推送昵称
* @param emModifyPushNickname (optional)
* @return ApiResponse&lt;EMModifyPushNicknamesResult&gt;
* @throws ApiException If fail to call the API, e.g. server error or cannot deserialize the response body
* http.response.details
*/
public ApiResponse<EMModifyPushNicknamesResult> modifyPushNicknamesWithHttpInfo(List<EMModifyPushNickname> emModifyPushNickname) throws ApiException {
okhttp3.Call localVarCall = modifyPushNicknamesValidateBeforeCall(emModifyPushNickname, null);
Type localVarReturnType = new TypeToken<EMModifyPushNicknamesResult>(){}.getType();
return localVarApiClient.execute(localVarCall, localVarReturnType);
}

/**
* 批量修改用户推送昵称 (asynchronously)
* @param emModifyPushNickname (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 modifyPushNicknamesAsync(List<EMModifyPushNickname> emModifyPushNickname, final ApiCallback<EMModifyPushNicknamesResult> _callback) throws ApiException {

okhttp3.Call localVarCall = modifyPushNicknamesValidateBeforeCall(emModifyPushNickname, _callback);
Type localVarReturnType = new TypeToken<EMModifyPushNicknamesResult>(){}.getType();
localVarApiClient.executeAsync(localVarCall, localVarReturnType, _callback);
return localVarCall;
}
}
219 changes: 219 additions & 0 deletions src/main/java/com/easemob/im/api/model/EMModifyPushNickname.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,219 @@
/*
* 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;

/**
* EMModifyPushNickname
*/
@javax.annotation.Generated(value = "org.openapitools.codegen.languages.JavaClientCodegen", date = "2024-06-24T17:32:21.382715+08:00[Asia/Shanghai]")
public class EMModifyPushNickname {
public static final String SERIALIZED_NAME_USERNAME = "username";
@SerializedName(SERIALIZED_NAME_USERNAME)
private String username;

public static final String SERIALIZED_NAME_PUSH_NICKNAME = "push_nickname";
@SerializedName(SERIALIZED_NAME_PUSH_NICKNAME)
private String pushNickname;

public EMModifyPushNickname() {
}

public EMModifyPushNickname 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 EMModifyPushNickname pushNickname(String pushNickname) {

this.pushNickname = pushNickname;
return this;
}

/**
* 离线推送时在接收方的客户端推送通知栏中显示的发送方的昵称。你可以自定义该昵称,长度不能超过 100 个字符。
* @return pushNickname
**/
@javax.annotation.Nullable
public String getPushNickname() {
return pushNickname;
}


public void setPushNickname(String pushNickname) {
this.pushNickname = pushNickname;
}



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

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

@Override
public String toString() {
StringBuilder sb = new StringBuilder();
sb.append("class EMModifyPushNickname {\n");
sb.append(" username: ").append(toIndentedString(username)).append("\n");
sb.append(" pushNickname: ").append(toIndentedString(pushNickname)).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("push_nickname");

// 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 EMModifyPushNickname
*/
public static void validateJsonElement(JsonElement jsonElement) throws IOException {
if (jsonElement == null) {
if (!EMModifyPushNickname.openapiRequiredFields.isEmpty()) { // has required fields but JSON element is null
throw new IllegalArgumentException(String.format("The required field(s) %s in EMModifyPushNickname is not found in the empty JSON string", EMModifyPushNickname.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 (!EMModifyPushNickname.openapiFields.contains(entry.getKey())) {
throw new IllegalArgumentException(String.format("The field `%s` in the JSON string is not defined in the `EMModifyPushNickname` 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()));
}
if ((jsonObj.get("push_nickname") != null && !jsonObj.get("push_nickname").isJsonNull()) && !jsonObj.get("push_nickname").isJsonPrimitive()) {
throw new IllegalArgumentException(String.format("Expected the field `push_nickname` to be a primitive type in the JSON string but got `%s`", jsonObj.get("push_nickname").toString()));
}
}

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

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

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

}.nullSafe();
}
}

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

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

Loading

0 comments on commit 5626f61

Please sign in to comment.