ru.dezhik.sms.sender.api.smsru.send.SMSRuBatchSendHandler Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of sms-sender Show documentation
Show all versions of sms-sender Show documentation
Library for sending SMS via sms.ru gateway
package ru.dezhik.sms.sender.api.smsru.send;
import java.util.Collection;
import java.util.List;
import org.apache.http.NameValuePair;
import org.apache.http.message.BasicNameValuePair;
import ru.dezhik.sms.sender.RequestValidationException;
import ru.dezhik.sms.sender.api.smsru.Pair;
/**
* @author ilya.dezhin
*/
public class SMSRuBatchSendHandler extends AbstractSMSRuSendHandler {
@Override
public void validate(SMSRuBatchSendRequest request) throws IllegalArgumentException {
super.validate(request);
final Collection> messages = request.getMessages();
if (messages == null || messages.isEmpty()) {
throw new RequestValidationException("No receiver/text pairs.");
}
for (Pair message : messages) {
if (message.getA() == null || message.getA().isEmpty()) {
throw new RequestValidationException("Receiver/text pairs contain null/empty receiver.");
}
if (message.getB() == null || message.getB().isEmpty()) {
throw new RequestValidationException("Receiver/text pairs contain null/empty text.");
}
}
}
@Override
public void appendParams(SMSRuBatchSendRequest request, List params) {
super.appendParams(request, params);
for (Pair message : request.getMessages()) {
params.add(new BasicNameValuePair("multi[" + message.getA() + "]", message.getB()));
}
}
}