cn.jiguang.common.resp.ResponseWrapper Java Examples

The following examples show how to use cn.jiguang.common.resp.ResponseWrapper. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: ChatRoomMemberList.java    From jmessage-api-java-client with MIT License 5 votes vote down vote up
public static ChatRoomMemberList fromResponse(ResponseWrapper responseWrapper) {
    ChatRoomMemberList  result = new ChatRoomMemberList();
    if (responseWrapper.isServerResponse()) {
        result.users = _gson.fromJson(responseWrapper.responseContent, ChatRoomMember[].class);
    } else {
        // nothing
    }
    result.setResponseWrapper(responseWrapper);
    return result;
}
 
Example #2
Source File: ReportClient.java    From jmessage-api-java-client with MIT License 5 votes vote down vote up
/**
 * Get group statistic, time unit only supports DAY now.
 * @param start Format: yyyy-MM-dd
 * @param duration duration must between 0 and 60
 * @return {@link GroupStatListResult}
 * @throws APIConnectionException connect exception
 * @throws APIRequestException request exception
 */
public GroupStatListResult getGroupStatistic(String start, int duration)
        throws APIConnectionException, APIRequestException {
    Preconditions.checkArgument(verifyDateFormat("DAY", start), "Illegal date format");
    Preconditions.checkArgument(0 <= duration && duration <= 60, " 0 <= duration <= 60");
    String url = mBaseReportPath + mV2StatisticPath + "/groups?time_unit=DAY&start=" + start + "&duration=" + duration;
    ResponseWrapper responseWrapper = _httpClient.sendGet(url);
    return GroupStatListResult.fromResponse(responseWrapper);
}
 
Example #3
Source File: UserClient.java    From jmessage-api-java-client with MIT License 5 votes vote down vote up
/**
 * Add friends to username
 *
 * @param username Necessary
 * @param users    username to be add
 * @return No content
 * @throws APIConnectionException connect exception
 * @throws APIRequestException    request exception
 */
public ResponseWrapper addFriends(String username, String... users)
        throws APIConnectionException, APIRequestException {
    StringUtils.checkUsername(username);
    Preconditions.checkArgument(null != users && users.length > 0, "friend list should not be empty");

    JsonArray array = new JsonArray();
    for (String user : users) {
        array.add(new JsonPrimitive(user));
    }

    return _httpClient.sendPost(_baseUrl + userPath + "/" + username + "/friends", array.toString());
}
 
Example #4
Source File: MessageClient.java    From jmessage-api-java-client with MIT License 5 votes vote down vote up
public SendMessageResult sendMessage(MessagePayload payload)
        throws APIConnectionException, APIRequestException {
    Preconditions.checkArgument(!(null == payload), "Message payload should not be null");

    ResponseWrapper response = _httpClient.sendPost(_baseUrl + messagePath, payload.toString());
    return SendMessageResult.fromResponse(response, SendMessageResult.class);
}
 
Example #5
Source File: UserClient.java    From jmessage-api-java-client with MIT License 5 votes vote down vote up
public ResponseWrapper removeBlackList(String username, String... users)
        throws APIConnectionException, APIRequestException {
    StringUtils.checkUsername(username);
    Preconditions.checkArgument(null != users && users.length > 0, "black list should not be empty");
    JsonArray array = new JsonArray();
    for (String user : users) {
        array.add(new JsonPrimitive(user));
    }

    return _httpClient.sendDelete(_baseUrl + userPath + "/" + username + "/blacklist", array.toString());
}
 
Example #6
Source File: SMSClient.java    From jsms-api-java-client with MIT License 5 votes vote down vote up
/**
 * Modify SMS with schedule
 *
 * @param payload    ScheduleSMSPayload
 * @param scheduleId id
 * @return ScheduleResult which includes schedule_id
 * @throws APIConnectionException connect exception
 * @throws APIRequestException    request exception
 */
public ScheduleResult updateScheduleSMS(ScheduleSMSPayload payload, String scheduleId)
        throws APIConnectionException, APIRequestException {
    Preconditions.checkArgument(null != payload, "Schedule SMS payload should not be null");
    Preconditions.checkArgument(null != scheduleId, "Schedule id should not be null");
    Preconditions.checkArgument(null != payload.getMobile(), "Mobile should not be null");
    Preconditions.checkArgument(StringUtils.isMobileNumber(payload.getMobile()), "Invalid mobile number");
    ResponseWrapper responseWrapper = _httpClient.sendPut(_baseUrl + _schedulePath + "/" + scheduleId, payload.toString());
    return ScheduleResult.fromResponse(responseWrapper, ScheduleResult.class);
}
 
Example #7
Source File: ReportClient.java    From jmessage-api-java-client with MIT License 5 votes vote down vote up
/**
 * Get user statistic, now time unit only supports DAY
 * @param startTime start time, format: yyyy-MM-dd
 * @param duration 0-60
 * @return {@link UserStatListResult}
 * @throws APIConnectionException connect exception
 * @throws APIRequestException request exception
 */
public UserStatListResult getUserStatistic(String startTime, int duration)
        throws APIConnectionException, APIRequestException {
    Preconditions.checkArgument(verifyDateFormat("DAY", startTime), "Illegal date format");
    Preconditions.checkArgument(0 <= duration && duration <= 60, " 0 <= duration <= 60");
    String url = mBaseReportPath + mV2StatisticPath + "/users?time_unit=DAY&start=" + startTime + "&duration=" + duration;
    ResponseWrapper responseWrapper = _httpClient.sendGet(url);
    return UserStatListResult.fromResponse(responseWrapper);
}
 
Example #8
Source File: GroupClient.java    From jmessage-api-java-client with MIT License 5 votes vote down vote up
public GroupListResult getGroupListByAppkey(int start, int count)
        throws APIConnectionException, APIRequestException {
    if (start < 0 || count <= 0 || count > 500) {
        throw new IllegalArgumentException("negative index or count must more than 0 and less than 501");
    }
    ResponseWrapper response = _httpClient.sendGet(_baseUrl + groupPath + "?start=" + start + "&count=" + count);
    return GroupListResult.fromResponse(response, GroupListResult.class);
}
 
Example #9
Source File: GroupClient.java    From jmessage-api-java-client with MIT License 5 votes vote down vote up
public GroupInfoResult getGroupInfo(long gid)
        throws APIConnectionException, APIRequestException {
    Preconditions.checkArgument(gid > 0, "gid should more than 0.");

    ResponseWrapper response = _httpClient.sendGet(_baseUrl + groupPath + "/" + gid);

    return GroupInfoResult.fromResponse(response, GroupInfoResult.class);
}
 
Example #10
Source File: UserClient.java    From jmessage-api-java-client with MIT License 5 votes vote down vote up
/**
 * Delete friends
 *
 * @param username Friends you want to delete to
 * @param users    username to be delete
 * @return No content
 * @throws APIConnectionException connect exception
 * @throws APIRequestException    request exception
 */
public ResponseWrapper deleteFriends(String username, String... users)
        throws APIConnectionException, APIRequestException {
    StringUtils.checkUsername(username);
    Preconditions.checkArgument(null != users && users.length > 0, "friend list should not be empty");

    JsonArray array = new JsonArray();
    for (String user : users) {
        array.add(new JsonPrimitive(user));
    }
    return _httpClient.sendDelete(_baseUrl + userPath + "/" + username + "/friends", array.toString());
}
 
Example #11
Source File: SensitiveWordClient.java    From jmessage-api-java-client with MIT License 5 votes vote down vote up
/**
 * Update sensitive word
 * @param newWord new word
 * @param oldWord old word
 * @return No content
 * @throws APIConnectionException connect exception
 * @throws APIRequestException request exception
 */
public ResponseWrapper updateSensitiveWord(String newWord, String oldWord)
        throws APIConnectionException, APIRequestException {
    Preconditions.checkArgument(newWord.length() <= 10, "one word's max length is 10");
    Preconditions.checkArgument(oldWord.length() <= 10, "one word's max length is 10");
    JsonObject jsonObject = new JsonObject();
    jsonObject.addProperty("new_word", newWord);
    jsonObject.addProperty("old_word", oldWord);
    return _httpClient.sendPut(_baseUrl + sensitiveWordPath, jsonObject.toString());
}
 
Example #12
Source File: UserGroupsResult.java    From jmessage-api-java-client with MIT License 5 votes vote down vote up
public static UserGroupsResult fromResponse(ResponseWrapper responseWrapper) {
    UserGroupsResult  result = new UserGroupsResult();
    if (responseWrapper.isServerResponse()) {
        result.groups = _gson.fromJson(responseWrapper.responseContent, GroupInfoResult[].class);
    } else {
        // nothing
    }
    result.setResponseWrapper(responseWrapper);
    return result;
}
 
Example #13
Source File: UserClient.java    From jmessage-api-java-client with MIT License 5 votes vote down vote up
/**
 * Add Users to black list
 *
 * @param username The owner of the black list
 * @param users    The users that will add to black list
 * @return add users to black list
 * @throws APIConnectionException connect exception
 * @throws APIRequestException    request exception
 */
public ResponseWrapper addBlackList(String username, String... users)
        throws APIConnectionException, APIRequestException {
    StringUtils.checkUsername(username);
    Preconditions.checkArgument(null != users && users.length > 0, "black list should not be empty");

    JsonArray array = new JsonArray();
    for (String user : users) {
        array.add(new JsonPrimitive(user));
    }
    return _httpClient.sendPut(_baseUrl + userPath + "/" + username + "/blacklist", array.toString());
}
 
Example #14
Source File: ReportClient.java    From jmessage-api-java-client with MIT License 5 votes vote down vote up
/**
 * Get message statistic. Detail instructions please refer to https://docs.jiguang.cn/jmessage/server/rest_api_im_report_v2/#_6
 * @param timeUnit MUST be one of HOUR, DAY, MONTH
 * @param start start time, when timeUnit is HOUR, format: yyyy-MM-dd HH,
 * @param duration depends on timeUnit, the duration has limit
 * @return {@link MessageStatListResult}
 * @throws APIConnectionException connect exception
 * @throws APIRequestException request exception
 */
public MessageStatListResult getMessageStatistic(String timeUnit, String start, int duration)
        throws APIConnectionException, APIRequestException {
    Preconditions.checkArgument(verifyDateFormat(timeUnit, start), "Time format error, please check your argument");
    if (timeUnit.equals("HOUR")) {
        Preconditions.checkArgument(0 <= duration && duration <= 24, "time unit is HOUR, duration must between 0 and 24 ");
    } else if (timeUnit.equals("DAY")) {
        Preconditions.checkArgument(0 <= duration && duration <= 60, "time unit is DAY, duration must between 0 and 60");
    } else if (timeUnit.equals("MONTH")) {
        Preconditions.checkArgument(0 <= duration && duration <= 2, "time unit is MONTH, duration must between 0 and 2");
    } else throw new IllegalArgumentException("Time unit error");
    String url = mBaseReportPath + mV2StatisticPath + "/messages?time_unit=" + timeUnit + "&start=" + start + "&duration=" + duration;
    ResponseWrapper responseWrapper = _httpClient.sendGet(url);
    return MessageStatListResult.fromResponse(responseWrapper, MessageStatListResult.class);
}
 
Example #15
Source File: SensitiveWordClient.java    From jmessage-api-java-client with MIT License 5 votes vote down vote up
/**
 * Add sensitive words
 * @param words String Set
 * @return No content
 * @throws APIConnectionException connect exception
 * @throws APIRequestException request exception
 */
public ResponseWrapper addSensitiveWords(Set<String> words) throws APIConnectionException, APIRequestException {
    JsonArray array = new JsonArray();
    for (String word : words) {
        Preconditions.checkArgument(word.length() <= 10, "one word's max length is 10");
        array.add(new JsonPrimitive(word));
    }
    return _httpClient.sendPost(_baseUrl + sensitiveWordPath, array.toString());
}
 
Example #16
Source File: UserClient.java    From jmessage-api-java-client with MIT License 5 votes vote down vote up
/**
 * Get admins by appkey
 *
 * @param start The start index of the list
 * @param count The number that how many you want to get from list
 * @return admin user info list
 * @throws APIConnectionException connect exception
 * @throws APIRequestException    request exception
 */
public UserListResult getAdminListByAppkey(int start, int count)
        throws APIConnectionException, APIRequestException {
    if (start < 0 || count <= 0 || count > 500) {
        throw new IllegalArgumentException("negative index or count must more than 0 and less than 501");
    }
    ResponseWrapper response = _httpClient.sendGet(_baseUrl + adminPath + "?start=" + start + "&count=" + count);
    return UserListResult.fromResponse(response, UserListResult.class);

}
 
Example #17
Source File: ReportClient.java    From jmessage-api-java-client with MIT License 5 votes vote down vote up
/**
 * Get message list with cursor, the cursor will effective in 120 seconds. And will
 * return same count of messages as first request.
 * @param cursor First request will return cursor
 * @return MessageListResult
 * @throws APIConnectionException connect exception
 * @throws APIRequestException request exception
 */
public MessageListResult v2GetMessageListByCursor(String cursor)
        throws APIConnectionException, APIRequestException {
    if (null != cursor) {
        String requestUrl = mBaseReportPath + mV2MessagePath + "?cursor=" + cursor;
        ResponseWrapper response = _httpClient.sendGet(requestUrl);
        return MessageListResult.fromResponse(response, MessageListResult.class);
    } else {
        throw new IllegalArgumentException("the cursor parameter should not be null");
    }
}
 
Example #18
Source File: ChatRoomListResult.java    From jmessage-api-java-client with MIT License 5 votes vote down vote up
public static ChatRoomListResult fromResponse(ResponseWrapper responseWrapper) {
    ChatRoomListResult result = new ChatRoomListResult();
    if (responseWrapper.isServerResponse()) {
        result.roomsArray = _gson.fromJson(responseWrapper.responseContent, ChatRoomResult[].class);
    }
    result.setResponseWrapper(responseWrapper);
    return result;
}
 
Example #19
Source File: SMSClient.java    From jsms-api-java-client with MIT License 5 votes vote down vote up
/**
 * create sign
 * 其实两个接口可以合并 但没时间搞
 *
 * @param payload {@link SignPayload }
 * @return SignResult
 * @throws APIConnectionException connect exception
 * @throws APIRequestException    request exception
 */
public SignResult createSign(SignPayload payload) throws APIConnectionException, APIRequestException {
    Preconditions.checkArgument(null != payload, "sign payload should not be null");
    Preconditions.checkArgument(payload.getType() > 0 && payload.getType() <= 7,
            "type should be between 1 and 7");
    Map<String, Object> params = new HashMap<String, Object>();
    params.put(SignPayload.getSIGN(), payload.getSign());
    if (!StringUtils.isEmpty(payload.getRemark())) {
        Preconditions.checkArgument(payload.getRemark().length() <= 100,
                "remark too long");
        params.put(SignPayload.getREMARK(), payload.getRemark());
    }
    params.put(SignPayload.getTYPE(), payload.getType());
    Map<String, byte[]> fileParams = new HashMap<String, byte[]>();
    File[] images = payload.getImages();
    if (images != null && images.length > 0) {
        for (File file : payload.getImages()) {
            fileParams.put(file.getName(), getBytes(file));
        }
    }
    String url = _baseUrl + _signPath;
    try {
        ResponseWrapper wrapper = doPostSign(url, params, fileParams, SignPayload.getIMAGES());
        if (wrapper.responseCode != 200) {
            throw new APIRequestException(wrapper);
        }
        return SignResult.fromResponse(wrapper, SignResult.class);
    } catch (IOException e) {
        e.printStackTrace();
        throw new IllegalArgumentException("fail to creat sign");
    }
}
 
Example #20
Source File: SMSClient.java    From jsms-api-java-client with MIT License 5 votes vote down vote up
/**
 * update sign
 *
 * @param payload {@link SignPayload }
 * @param signId necessary
 * @return SignResult
 * @throws APIConnectionException connect exception
 * @throws APIRequestException    request exception
 */
public SignResult updateSign(SignPayload payload, int signId) throws APIConnectionException, APIRequestException {
    Preconditions.checkArgument(null != payload, "sign payload should not be null");
    Preconditions.checkArgument(payload.getType() > 0 && payload.getType() <= 7,
            "type should be between 1 and 7");

    Map<String, Object> params = new HashMap<String, Object>();
    params.put(SignPayload.getSIGN(), payload.getSign());
    if (!StringUtils.isEmpty(payload.getRemark())) {
        Preconditions.checkArgument(payload.getRemark().length() <= 100,
                "remark too long");
        params.put(SignPayload.getREMARK(), payload.getRemark());
    }
    params.put(SignPayload.getTYPE(), payload.getType());
    Map<String, byte[]> fileParams = new HashMap<String, byte[]>();
    File[] images = payload.getImages();
    if (images != null && images.length > 0) {
        for (File file : payload.getImages()) {
            fileParams.put(file.getName(), getBytes(file));
        }
    }
    String url = _baseUrl + _signPath + "/" + signId;
    try {
        ResponseWrapper wrapper = doPostSign(url, params, fileParams, SignPayload.getIMAGES());
        if (wrapper.responseCode != 200) {
            throw new APIRequestException(wrapper);
        }
        return SignResult.fromResponse(wrapper, SignResult.class);
    } catch (IOException e) {
        e.printStackTrace();
        throw new IllegalArgumentException("fail to update sign");
    }
}
 
Example #21
Source File: ChatRoomClient.java    From jmessage-api-java-client with MIT License 5 votes vote down vote up
/**
 * Add members to chat room
 *
 * @param roomId  chat room id
 * @param members username array
 * @return No content
 * @throws APIConnectionException connect exception
 * @throws APIRequestException    request exception
 */
public ResponseWrapper addChatRoomMember(long roomId, String... members)
        throws APIConnectionException, APIRequestException {
    Preconditions.checkArgument(roomId > 0, "room id is invalid");
    Preconditions.checkArgument(members != null && members.length > 0, "member should not be empty");
    JsonArray array = new JsonArray();
    for (String username : members) {
        array.add(new JsonPrimitive(username));
    }
    return _httpClient.sendPut(_baseUrl + mChatRoomPath + "/" + roomId + "/members", array.toString());
}
 
Example #22
Source File: GroupClient.java    From jmessage-api-java-client with MIT License 5 votes vote down vote up
public CreateGroupResult createGroup(GroupPayload payload)
        throws APIConnectionException, APIRequestException {
    Preconditions.checkArgument(!(null == payload), "group payload should not be null");

    ResponseWrapper response = _httpClient.sendPost(_baseUrl + groupPath, payload.toString());
    return CreateGroupResult.fromResponse(response, CreateGroupResult.class);
}
 
Example #23
Source File: CrossAppClient.java    From jmessage-api-java-client with MIT License 5 votes vote down vote up
/**
 * Add blacklist whose users belong to another app to a given user.
 * @param username The owner of the blacklist
 * @param blacklists CrossBlacklist array
 * @return No Content
 * @throws APIConnectionException connect exception
 * @throws APIRequestException request exception
 */
public ResponseWrapper addCrossBlacklist(String username, CrossBlacklist[] blacklists)
        throws APIConnectionException, APIRequestException {
    StringUtils.checkUsername(username);
    CrossBlacklistPayload payload = new CrossBlacklistPayload.Builder()
            .setCrossBlacklists(blacklists)
            .build();
    return _httpClient.sendPut(_baseUrl + crossUserPath + "/" + username +"/blacklist", payload.toString());
}
 
Example #24
Source File: GroupClient.java    From jmessage-api-java-client with MIT License 5 votes vote down vote up
public ResponseWrapper updateGroupInfo(long gid, String groupName, String groupDesc, String avatar)
        throws APIConnectionException, APIRequestException {
    Preconditions.checkArgument(gid > 0, "gid should more than 0.");

    if (StringUtils.isTrimedEmpty(groupName) && StringUtils.isTrimedEmpty(groupDesc)
            && StringUtils.isTrimedEmpty(avatar)) {
        Preconditions.checkArgument(false, "group name, group description and group avatar should not be null at the same time.");
    }

    JsonObject json = new JsonObject();
    if (StringUtils.isNotEmpty(groupName)) {
        groupName = groupName.trim();
        Preconditions.checkArgument(groupName.getBytes().length <= 64,
                "The length of group name must not more than 64 bytes.");
        Preconditions.checkArgument(!StringUtils.isLineBroken(groupName),
                "The group name must not contain line feed character.");
        json.addProperty(GroupPayload.GROUP_NAME, groupName);
    }

    if (StringUtils.isNotEmpty(groupDesc)) {
        groupDesc = groupDesc.trim();
        Preconditions.checkArgument(groupDesc.getBytes().length <= 250,
                "The length of group description must not more than 250 bytes.");
        json.addProperty(GroupPayload.DESC, groupDesc);
    }

    if (StringUtils.isNotEmpty(avatar)) {
        avatar = avatar.trim();
        json.addProperty(GroupPayload.AVATAR, avatar);
    }

    return _httpClient.sendPut(_baseUrl + groupPath + "/" + gid, json.toString());
}
 
Example #25
Source File: UserListResult.java    From jmessage-api-java-client with MIT License 5 votes vote down vote up
public static UserListResult fromResponse(ResponseWrapper responseWrapper) {
    UserListResult result = new UserListResult();
    if (responseWrapper.isServerResponse()) {
        result.users = _gson.fromJson(responseWrapper.responseContent, UserInfoResult[].class);
    }
    result.setResponseWrapper(responseWrapper);
    return result;
}
 
Example #26
Source File: UserClient.java    From jmessage-api-java-client with MIT License 5 votes vote down vote up
/**
 * Get user list
 *
 * @param start The start index of the list
 * @param count The number that how many you want to get from list
 * @return User info list
 * @throws APIConnectionException connect exception
 * @throws APIRequestException    request exception
 */
public UserListResult getUserList(int start, int count)
        throws APIConnectionException, APIRequestException {

    if (start < 0 || count <= 0 || count > 500) {
        throw new IllegalArgumentException("negative index or count must more than 0 and less than 501");
    }
    ResponseWrapper response = _httpClient.sendGet(_baseUrl + userPath + "?start=" + start + "&count=" + count);
    return UserListResult.fromResponse(response, UserListResult.class);

}
 
Example #27
Source File: MemberListResult.java    From jmessage-api-java-client with MIT License 5 votes vote down vote up
public static MemberListResult fromResponse(ResponseWrapper responseWrapper) {
    MemberListResult  result = new MemberListResult();
    if (responseWrapper.isServerResponse()) {
        result.members = _gson.fromJson(responseWrapper.responseContent, MemberResult[].class);
    } else {
        // nothing
    }
    result.setResponseWrapper(responseWrapper);
    return result;
}
 
Example #28
Source File: NettyHttpClient.java    From jiguang-java-client-common with MIT License 4 votes vote down vote up
@Override
public ResponseWrapper sendPut(String url, String content) throws APIConnectionException, APIRequestException {
    return sendHttpRequest(HttpMethod.PUT, url, content);
}
 
Example #29
Source File: NettyHttpClient.java    From jiguang-java-client-common with MIT License 4 votes vote down vote up
@Override
public ResponseWrapper sendDelete(String url) throws APIConnectionException, APIRequestException {
    return sendDelete(url, null);
}
 
Example #30
Source File: NativeHttpClient.java    From jiguang-java-client-common with MIT License 4 votes vote down vote up
public ResponseWrapper sendPost(String url, String content) 
           throws APIConnectionException, APIRequestException {
	return doRequest(url, content, RequestMethod.POST);
}