-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSms.java
More file actions
47 lines (38 loc) · 1.51 KB
/
Sms.java
File metadata and controls
47 lines (38 loc) · 1.51 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
package dev.resms.services.sms;
import dev.resms.core.exception.ReSMSException;
import dev.resms.core.net.AbstractHttpResponse;
import dev.resms.core.net.HttpMethod;
import dev.resms.core.service.BaseService;
import dev.resms.services.sms.model.SendSmsOptions;
import dev.resms.services.sms.model.SendSmsResponse;
import dev.resms.services.sms.validator.SendSmsOptionsValidator;
public class Sms extends BaseService {
private static final String SEND_SMS_PATH = "/sms";
/**
* Constructs an instance of the {@code Sms} class.
*
* @param apiKey The apiKey used for authentication.
*/
public Sms(final String apiKey) {
super(apiKey);
}
/**
* Sends an SMS based on the provided SMS request.
*
* @param sendSmsOptions The request containing SMS details.
* @return The response indicating the status of the sms sending.
* @throws ReSMSException If an error occurs while sending the SMS.
*/
public SendSmsResponse send(SendSmsOptions sendSmsOptions) throws ReSMSException {
SendSmsOptionsValidator.validate(sendSmsOptions);
String payload = super.reSMSMapper.toJson(sendSmsOptions);
AbstractHttpResponse<String> response =
super.httpClient.perform(SEND_SMS_PATH, apiKey, HttpMethod.POST, payload);
if (!response.isSuccessful()) {
throw new ReSMSException(
"Failed to send sms: " + response.getCode() + " " + response.getBody());
}
String responseBody = response.getBody();
return reSMSMapper.fromJson(responseBody, SendSmsResponse.class);
}
}