cn.jiguang.common.ServiceHelper Java Examples

The following examples show how to use cn.jiguang.common.ServiceHelper. 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: SMSClient.java    From jsms-api-java-client with MIT License 6 votes vote down vote up
public SMSClient(String masterSecret, String appkey, HttpProxy proxy, JSMSConfig conf) {
    ServiceHelper.checkBasic(appkey, masterSecret);

    _baseUrl = (String) conf.get(JSMSConfig.API_HOST_NAME);
    _smsCodePath = (String) conf.get(JSMSConfig.CODE_PATH);
    _validPath = (String) conf.get(JSMSConfig.VALID_PATH);
    _voiceCodePath = (String) conf.get(JSMSConfig.VOICE_CODE_PATH);
    _shortMsgPath = (String) conf.get(JSMSConfig.SHORT_MESSAGE_PATH);
    _tempMsgPath = (String) conf.get(JSMSConfig.TEMPlATE_MESSAGE_PATH);
    _signPath = (String) conf.get(JSMSConfig.SIGN_PATH);
    _signDefaultPath = (String) conf.get(JSMSConfig.SIGN_DEFAULT_PATH);
    _schedulePath = (String) conf.get(JSMSConfig.SCHEDULE_PATH);
    _accountPath = (String) conf.get(JSMSConfig.ACCOUNT_PATH);
    String authCode = ServiceHelper.getBasicAuthorization(appkey, masterSecret);
    _authCode = authCode;
    this._httpClient = new NativeHttpClient(authCode, proxy, conf.getClientConfig());
}
 
Example #2
Source File: StringUtils.java    From jmessage-api-java-client with MIT License 6 votes vote down vote up
public static void checkUsername(String username) {
	if ( null == username || username.trim().length() == 0) {
		throw new IllegalArgumentException("username must not be empty");
	}
	if (username.contains("\n") || username.contains("\r") || username.contains("\t")) {
		throw new IllegalArgumentException("username must not contain line feed character");
	}
	byte[] usernameByte = username.getBytes();
	if (usernameByte.length < 4 || usernameByte.length > 128) {
		throw new IllegalArgumentException("The length of username must between 4 and 128 bytes. Input is " + username);
	}
	if (!ServiceHelper.checkUsername(username)) {
		throw new IllegalArgumentException("The parameter username contains illegal character," +
				" a-zA-Z_0-9.、-,@。 is legally, and start with alphabet or number. Input is " + username);
	}
}
 
Example #3
Source File: UserPayload.java    From jmessage-api-java-client with MIT License 5 votes vote down vote up
public UserPayload build() {

            if ( null != nickname ) {
                Preconditions.checkArgument(nickname.getBytes().length <= 64,
                        "The length of nickname must less than 64 bytes.");
                Preconditions.checkArgument(!StringUtils.isLineBroken(nickname),
                        "The nickname must not contain line feed character.");
            }

            if ( null != birthday) {
                Preconditions.checkArgument( ServiceHelper.isValidBirthday(birthday),
                        "Invalid birthday.");
            }

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

            Preconditions.checkArgument( gender >= -1 && gender <= 2,
                    "Invalid gender. 0 for unknown , 1 for male and 2 for female." );

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

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

            return new UserPayload(nickname, birthday, signature, gender, region, address, avatar, 
            		extrasBuilder, numberExtrasBuilder, booleanExtrasBuilder,jsonExtrasBuilder);
        }
 
Example #4
Source File: HttpProxy.java    From jiguang-java-client-common with MIT License 4 votes vote down vote up
public String getProxyAuthorization() {
    return ServiceHelper.getBasicAuthorization(username, password);
}
 
Example #5
Source File: BaseClient.java    From jmessage-api-java-client with MIT License 3 votes vote down vote up
/**
 * Create a JMessage Base Client
 *
 * @param appKey The KEY of one application on JPush.
 * @param masterSecret API access secret of the appKey.
 * @param proxy The proxy, if there is no proxy, should be null.
 * @param config The client configuration. Can use JMessageConfig.getInstance() as default.
 */
public BaseClient(String appKey, String masterSecret, HttpProxy proxy, JMessageConfig config) {
    ServiceHelper.checkBasic(appKey, masterSecret);
    String authCode = ServiceHelper.getBasicAuthorization(appKey, masterSecret);
    this._baseUrl = (String) config.get(JMessageConfig.API_HOST_NAME);
    this._httpClient = new NativeHttpClient(authCode, proxy, config.getClientConfig());
}
 
Example #6
Source File: ResourceClient.java    From jmessage-api-java-client with MIT License 2 votes vote down vote up
/**
 * Create a JMessage Base Client
 *
 * @param appkey       The KEY of one application on JPush.
 * @param masterSecret API access secret of the appKey.
 * @param proxy        The proxy, if there is no proxy, should be null.
 * @param config       The client configuration. Can use JMessageConfig.getInstance() as default.
 */
public ResourceClient(String appkey, String masterSecret, HttpProxy proxy, JMessageConfig config) {
    super(appkey, masterSecret, proxy, config);
    this.resourcePath = (String) config.get(JMessageConfig.RESOURCE_PATH);
    this.authCode = ServiceHelper.getBasicAuthorization(appkey, masterSecret);
}