Java Code Examples for cn.jiguang.common.utils.Preconditions#checkArgument()

The following examples show how to use cn.jiguang.common.utils.Preconditions#checkArgument() . 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: GroupPayload.java    From jmessage-api-java-client with MIT License 6 votes vote down vote up
public GroupPayload build() {

            Preconditions.checkArgument(StringUtils.isNotEmpty(owner), "The owner must not be empty.");
            Preconditions.checkArgument(StringUtils.isNotEmpty(name), "The group name must not be empty.");
            Preconditions.checkArgument(!StringUtils.isLineBroken(owner), 
            		"The owner name must not contain line feed character.");
            Preconditions.checkArgument(name.getBytes().length <= 64,
                    "The length of group name must not more than 64 bytes.");
            Preconditions.checkArgument( !StringUtils.isLineBroken(name),
                    "The group name must not contain line feed character.");

            if ( null != desc ) {
                Preconditions.checkArgument( desc.getBytes().length <= 250,
                        "The length of group description must not more than 250 bytes.");
            }

            return new GroupPayload(owner, name, members, desc, avatar, flag);
        }
 
Example 2
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 3
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 4
Source File: FriendNote.java    From jmessage-api-java-client with MIT License 5 votes vote down vote up
public FriendNote builder() {
    StringUtils.checkUsername(username);
    try {
        Preconditions.checkArgument(note_name.trim().getBytes("UTF-8").length <= 250, "length of note name should less than 250");
        Preconditions.checkArgument(others.getBytes("UTF-8").length <= 250, "length of others should not larger than 250");
    } catch (UnsupportedEncodingException e) {
        e.printStackTrace();
    }

    return new FriendNote(note_name, others, username);
}
 
Example 5
Source File: RecipientPayload.java    From jsms-api-java-client with MIT License 5 votes vote down vote up
public Builder setTempPara(Map<String, String> temp_para) {
    Preconditions.checkArgument(! (null == temp_para), "temp_para should not be null.");
    if (null == tempPara) {
        tempPara = new HashMap<String, String>();
    }
    for (String key : temp_para.keySet()) {
        tempPara.put(key, temp_para.get(key));
    }
    return this;
}
 
Example 6
Source File: HttpProxy.java    From jiguang-java-client-common with MIT License 5 votes vote down vote up
public HttpProxy(String host, int port, String username, String password) {
    this(host, port);
    
    Preconditions.checkArgument(! (null == username), "username should not be null");
    Preconditions.checkArgument(! (null == password), "password should not be null");
    
    this.username = username;
    this.password = password;
    authenticationNeeded = true;
    
    LOG.info("Http Proxy - host:" + host + ", port:" + port
            + ", username:" + username + ", password:" + password);
}
 
Example 7
Source File: ResourceClient.java    From jmessage-api-java-client with MIT License 5 votes vote down vote up
/**
 * Download file with mediaId, will return DownloadResult which include url.
 * @param mediaId Necessary
 * @return DownloadResult
 * @throws APIConnectionException connect exception
 * @throws APIRequestException request exception
 */
public DownloadResult downloadFile(String mediaId)
        throws APIConnectionException, APIRequestException {
    Preconditions.checkArgument(null != mediaId, "mediaId is necessary");

    ResponseWrapper response = _httpClient.sendGet(_baseUrl + resourcePath + "?mediaId=" + mediaId);
    return DownloadResult.fromResponse(response, DownloadResult.class);
}
 
Example 8
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 9
Source File: RegisterInfo.java    From jmessage-api-java-client with MIT License 5 votes vote down vote up
public Builder addExtra(String key, Boolean value) {
    Preconditions.checkArgument(! (null == key || null == value), "Key/Value should not be null.");
    if (null == booleanExtrasBuilder) {
        booleanExtrasBuilder = new HashMap<String, Boolean>();
    }
    booleanExtrasBuilder.put(key, value);
    return this;
}
 
Example 10
Source File: RegisterInfo.java    From jmessage-api-java-client with MIT License 5 votes vote down vote up
public Builder addExtras(Map<String, String> extras) {
    Preconditions.checkArgument(! (null == extras), "extras should not be null.");
    if (null == extrasBuilder) {
        extrasBuilder = new HashMap<String, String>();
    }
    for (String key : extras.keySet()) {
        extrasBuilder.put(key, extras.get(key));
    }
    return this;
}
 
Example 11
Source File: RegisterInfo.java    From jmessage-api-java-client with MIT License 5 votes vote down vote up
public Builder addExtra(String key, JsonObject value) {
	Preconditions.checkArgument(! (null == key || null == value), "Key/Value should not be null.");
    if (null == jsonExtrasBuilder) {
    	jsonExtrasBuilder = new HashMap<String, JsonObject>();
    }
    jsonExtrasBuilder.put(key, value);
    return this;
}
 
Example 12
Source File: ChatRoomClient.java    From jmessage-api-java-client with MIT License 5 votes vote down vote up
/**
 * Update chat room info
 *
 * @param roomId        room id
 * @param ownerUsername owner username
 * @param name          new chat room name
 * @param desc          chat room description
 * @return No content
 * @throws APIConnectionException connect exception
 * @throws APIRequestException    request exception
 */
public ResponseWrapper updateChatRoomInfo(long roomId, String ownerUsername, String name, String desc)
        throws APIConnectionException, APIRequestException {
    Preconditions.checkArgument(roomId > 0, "room id is invalid");
    StringUtils.checkUsername(ownerUsername);
    Preconditions.checkArgument(null != name, "Chat room name is null");
    Preconditions.checkArgument(null != desc, "Description is null");
    JsonObject jsonObject = new JsonObject();
    jsonObject.addProperty(ChatRoomPayload.OWNER, ownerUsername);
    jsonObject.addProperty(ChatRoomPayload.NAME, name);
    jsonObject.addProperty(ChatRoomPayload.DESC, desc);
    return _httpClient.sendPut(_baseUrl + mChatRoomPath + "/" + roomId, _gson.toJson(jsonObject));
}
 
Example 13
Source File: CrossFriendPayload.java    From jmessage-api-java-client with MIT License 4 votes vote down vote up
public CrossFriendPayload build() {
    Preconditions.checkArgument(null != appKey, "AppKey should not be null!");
    Preconditions.checkArgument(null != users, "Users should not be null");
    return new CrossFriendPayload(appKey, users);
}
 
Example 14
Source File: GroupClient.java    From jmessage-api-java-client with MIT License 4 votes vote down vote up
public ResponseWrapper setGroupMemberSilence(long gid, boolean status, String[] usernames)
    throws APIConnectionException, APIRequestException {
    Preconditions.checkArgument(gid > 0, "gid should more than 0.");
    Preconditions.checkArgument(usernames != null && usernames.length > 0, "username array is invalid");
    return _httpClient.sendPut(_baseUrl + groupPath + "/messages/" + gid + "/silence?status=" + (status ? "true" : "false"), new Gson().toJson(usernames));
}
 
Example 15
Source File: TemplatePayload.java    From jsms-api-java-client with MIT License 4 votes vote down vote up
public TemplatePayload build() {
    Preconditions.checkArgument(ttl >= 0, "ttl should not less 0");
    Preconditions.checkArgument(type > 0, "type should be 1, or 2 or 3");

    return new TemplatePayload(tempId, template, type, ttl, remark);
}
 
Example 16
Source File: ScheduleSMSPayload.java    From jsms-api-java-client with MIT License 4 votes vote down vote up
public Builder addRecipient(RecipientPayload recipientPayload) {
    Preconditions.checkArgument(null != recipientPayload, "RecipientPayload should not be null");
    this.recipients.add(recipientPayload.toJSON());
    return this;
}
 
Example 17
Source File: UserClient.java    From jmessage-api-java-client with MIT License 3 votes vote down vote up
/**
 * Set user's group message blocking
 *
 * @param payload  GroupShieldPayload
 * @param username Necessary
 * @return No content
 * @throws APIConnectionException connect exception
 * @throws APIRequestException    request exception
 */
public ResponseWrapper setGroupShield(GroupShieldPayload payload, String username)
        throws APIConnectionException, APIRequestException {
    Preconditions.checkArgument(null != payload, "GroupShieldPayload should not be null");
    StringUtils.checkUsername(username);
    return _httpClient.sendPost(_baseUrl + userPath + "/" + username + "/groupsShield", payload.toString());
}
 
Example 18
Source File: CrossBlacklistPayload.java    From jmessage-api-java-client with MIT License 3 votes vote down vote up
public CrossBlacklistPayload build() {

            Preconditions.checkArgument(0 != array.size(), "The array must not be empty.");
            Preconditions.checkArgument(array.size() <= 500, "The array size must not over 500");

            return new CrossBlacklistPayload(array);
        }
 
Example 19
Source File: SensitiveWordClient.java    From jmessage-api-java-client with MIT License 3 votes vote down vote up
/**
 * Delete sensitive word
 * @param word word to be deleted
 * @return No content
 * @throws APIConnectionException connect exception
 * @throws APIRequestException request exception
 */
public ResponseWrapper deleteSensitiveWord(String word) throws APIConnectionException, APIRequestException {
    Preconditions.checkArgument(word.length() <= 10, "one word's max length is 10");
    JsonObject jsonObject = new JsonObject();
    jsonObject.addProperty("word", word);
    return _httpClient.sendDelete(_baseUrl + sensitiveWordPath, jsonObject.toString());
}
 
Example 20
Source File: SMSClient.java    From jsms-api-java-client with MIT License 2 votes vote down vote up
/**
 * Create template sms.
 *
 * @param payload {@link TemplatePayload }
 * @return {@link SendTempSMSResult }, include temp_id
 * @throws APIConnectionException connect exception
 * @throws APIRequestException    request exception
 */
public SendTempSMSResult createTemplate(TemplatePayload payload) throws APIConnectionException, APIRequestException {
    Preconditions.checkArgument(null != payload, "Template payload should not be null");
    ResponseWrapper responseWrapper = _httpClient.sendPost(_baseUrl + _tempMsgPath, payload.toString());
    return SendTempSMSResult.fromResponse(responseWrapper, SendTempSMSResult.class);
}