Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

SMS refactoring #64

Merged
merged 3 commits into from
Feb 28, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -23,15 +23,15 @@

public class BatchesService implements com.sinch.sdk.domains.sms.BatchesService {

private final String uriPathID;
private final String uriUUID;
private final BatchesApi api;

public BatchesService(
String uriPathID,
String uriUUID,
SmsContext context,
HttpClient httpClient,
Map<String, AuthManager> authManagers) {
this.uriPathID = uriPathID;
this.uriUUID = uriUUID;
this.api = new BatchesApi(httpClient, context.getSmsServer(), authManagers, new HttpMapper());
}

Expand All @@ -40,17 +40,17 @@ protected BatchesApi getApi() {
}

public <T extends Batch<?>> T get(String batchId) throws ApiException {
return BatchDtoConverter.convert(getApi().getBatchMessage(uriPathID, batchId));
return BatchDtoConverter.convert(getApi().getBatchMessage(uriUUID, batchId));
}

public <T extends Batch<?>> T send(BaseBatch<?> batch) throws ApiException {
return BatchDtoConverter.convert(getApi().sendSMS(uriPathID, BatchDtoConverter.convert(batch)));
return BatchDtoConverter.convert(getApi().sendSMS(uriUUID, BatchDtoConverter.convert(batch)));
}

public DryRun dryRun(boolean perRecipient, int numberOfRecipient, BaseBatch<?> batch) {
return DryRunDtoConverter.convert(
getApi()
.dryRun(uriPathID, perRecipient, numberOfRecipient, BatchDtoConverter.convert(batch)));
.dryRun(uriUUID, perRecipient, numberOfRecipient, BatchDtoConverter.convert(batch)));
}

public BatchesListResponse list() throws ApiException {
Expand All @@ -65,7 +65,7 @@ public BatchesListResponse list(BatchesListRequestParameters parameters) throws
ApiBatchListDto response =
getApi()
.listBatches(
uriPathID,
uriUUID,
guardParameters.getPage().orElse(null),
guardParameters.getPageSize().orElse(null),
guardParameters.getFrom().orElse(null),
Expand All @@ -83,20 +83,20 @@ public BatchesListResponse list(BatchesListRequestParameters parameters) throws
public <T extends Batch<?>> T update(String batchId, UpdateBaseBatchRequest<?> batch)
throws ApiException {
return BatchDtoConverter.convert(
getApi().updateBatchMessage(uriPathID, batchId, BatchDtoConverter.convert(batch)));
getApi().updateBatchMessage(uriUUID, batchId, BatchDtoConverter.convert(batch)));
}

public <T extends Batch<?>> T replace(String batchId, BaseBatch<?> batch) throws ApiException {
return BatchDtoConverter.convert(
getApi().replaceBatch(uriPathID, batchId, BatchDtoConverter.convert(batch)));
getApi().replaceBatch(uriUUID, batchId, BatchDtoConverter.convert(batch)));
}

public <T extends Batch<?>> T cancel(String batchId) throws ApiException {
return BatchDtoConverter.convert(getApi().cancelBatchMessage(uriPathID, batchId));
return BatchDtoConverter.convert(getApi().cancelBatchMessage(uriUUID, batchId));
}

public void sendDeliveryFeedback(String batchId, Collection<String> recipients)
throws ApiException {
getApi().deliveryFeedback(uriPathID, batchId, BatchDtoConverter.convert(recipients));
getApi().deliveryFeedback(uriUUID, batchId, BatchDtoConverter.convert(recipients));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -36,19 +36,19 @@
*/
public class DeliveryReportsService implements com.sinch.sdk.domains.sms.DeliveryReportsService {

private final String uriPathID;
private final String uriUUID;
private final DeliveryReportsApi api;

protected DeliveryReportsApi getApi() {
return this.api;
}

public DeliveryReportsService(
String uriPathID,
String uriUUID,
SmsContext context,
HttpClient httpClient,
Map<String, AuthManager> authManagers) {
this.uriPathID = uriPathID;
this.uriUUID = uriUUID;
this.api =
new DeliveryReportsApi(httpClient, context.getSmsServer(), authManagers, new HttpMapper());
}
Expand All @@ -62,7 +62,7 @@ public DeliveryReportBatch get(String batchId, DeliveryReportBatchGetRequestPara
return DeliveryReportDtoConverter.convert(
getApi()
.getDeliveryReportByBatchId(
uriPathID,
uriUUID,
batchId,
guardParameters.getType().map(DeliveryReportType::value).orElse(null),
guardParameters
Expand All @@ -78,7 +78,7 @@ public DeliveryReportBatch get(String batchId, DeliveryReportBatchGetRequestPara
public DeliveryReportRecipient getForNumber(String batchId, String recipient)
throws ApiException {
return DeliveryReportDtoConverter.convert(
getApi().getDeliveryReportByPhoneNumber(uriPathID, batchId, recipient));
getApi().getDeliveryReportByPhoneNumber(uriUUID, batchId, recipient));
}

public DeliveryReportsListResponse list() throws ApiException {
Expand All @@ -93,7 +93,7 @@ public DeliveryReportsListResponse list(DeliveryReportListRequestParameters para
DeliveryReportListDto response =
getApi()
.getDeliveryReports(
uriPathID,
uriUUID,
guardParameters.getPage().orElse(null),
guardParameters.getPageSize().orElse(null),
guardParameters.getStartDate().map(Instant::toString).orElse(null),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,25 +22,25 @@

public class GroupsService implements com.sinch.sdk.domains.sms.GroupsService {

private final String uriPathID;
private final String uriUUID;
private final GroupsApi api;

protected GroupsApi getApi() {
return this.api;
}

public GroupsService(
String uriPathID,
String uriUUID,
SmsContext context,
HttpClient httpClient,
Map<String, AuthManager> authManagers) {
this.uriPathID = uriPathID;
this.uriUUID = uriUUID;
this.api = new GroupsApi(httpClient, context.getSmsServer(), authManagers, new HttpMapper());
}

public Group get(String groupId) throws ApiException {

CreateGroupResponseDto response = getApi().retrieveGroup(uriPathID, groupId);
CreateGroupResponseDto response = getApi().retrieveGroup(uriUUID, groupId);
return GroupsDtoConverter.convert(response);
}

Expand All @@ -53,7 +53,7 @@ public Group create(GroupCreateRequestParameters parameters) throws ApiException
null != parameters ? parameters : GroupCreateRequestParameters.builder().build();

CreateGroupResponseDto response =
getApi().createGroup(uriPathID, GroupsDtoConverter.convert(guardParameters));
getApi().createGroup(uriUUID, GroupsDtoConverter.convert(guardParameters));
return GroupsDtoConverter.convert(response);
}

Expand All @@ -68,7 +68,7 @@ public GroupsListResponse list(GroupsListRequestParameters parameters) throws Ap
ApiGroupListDto response =
getApi()
.listGroups(
uriPathID,
uriUUID,
guardParameters.getPage().orElse(null),
guardParameters.getPageSize().orElse(null));

Expand All @@ -85,7 +85,7 @@ public Group replace(String groupId, GroupReplaceRequestParameters parameters)
null != parameters ? parameters : GroupReplaceRequestParameters.builder().build();

CreateGroupResponseDto response =
getApi().replaceGroup(uriPathID, groupId, GroupsDtoConverter.convert(guardParameters));
getApi().replaceGroup(uriUUID, groupId, GroupsDtoConverter.convert(guardParameters));
return GroupsDtoConverter.convert(response);
}

Expand All @@ -94,15 +94,15 @@ public Group update(String groupId, GroupUpdateRequestParameters parameters) thr
null != parameters ? parameters : GroupUpdateRequestParameters.builder().build();

CreateGroupResponseDto response =
getApi().updateGroup(uriPathID, groupId, GroupsDtoConverter.convert(guardParameters));
getApi().updateGroup(uriUUID, groupId, GroupsDtoConverter.convert(guardParameters));
return GroupsDtoConverter.convert(response);
}

public void delete(String groupId) throws ApiException {
getApi().deleteGroup(uriPathID, groupId);
getApi().deleteGroup(uriUUID, groupId);
}

public Collection<String> listMembers(String groupId) throws ApiException {
return getApi().getMembers(uriPathID, groupId);
return getApi().getMembers(uriUUID, groupId);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,19 +20,19 @@

public class InboundsService implements com.sinch.sdk.domains.sms.InboundsService {

private final String uriPathID;
private final String uriUUID;
private final InboundsApi api;

protected InboundsApi getApi() {
return this.api;
}

public InboundsService(
String uriPathID,
String uriUUID,
SmsContext context,
HttpClient httpClient,
Map<String, AuthManager> authManagers) {
this.uriPathID = uriPathID;
this.uriUUID = uriUUID;
this.api = new InboundsApi(httpClient, context.getSmsServer(), authManagers, new HttpMapper());
}

Expand All @@ -47,7 +47,7 @@ public InboundsListResponse list(InboundsListRequestParameters parameters) throw
ApiInboundListDto response =
getApi()
.listInboundMessages(
uriPathID,
uriUUID,
guardParameters.getPage().orElse(null),
guardParameters.getPageSize().orElse(null),
guardParameters.getTo().map(f -> String.join(",", f)).orElse(null),
Expand All @@ -64,7 +64,7 @@ public InboundsListResponse list(InboundsListRequestParameters parameters) throw

public Inbound<?> get(String inboundId) throws ApiException {

InboundDto response = getApi().retrieveInboundMessage(uriPathID, inboundId);
InboundDto response = getApi().retrieveInboundMessage(uriUUID, inboundId);
return InboundsDtoConverter.convert(response);
}
}
4 changes: 2 additions & 2 deletions client/src/main/com/sinch/sdk/models/SmsContext.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ public class SmsContext {
private final SMSRegion smsRegion;
private final String smsUrl;

public SmsContext(SMSRegion smsRegion, String smsUrl) {
this.smsRegion = null == smsRegion ? SMSRegion.US : smsRegion;
private SmsContext(SMSRegion smsRegion, String smsUrl) {
this.smsRegion = smsRegion;
this.smsUrl = smsUrl;
}

Expand Down
16 changes: 16 additions & 0 deletions client/src/test/java/com/sinch/sdk/SinchClientTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

import com.sinch.sdk.core.utils.StringUtil;
import com.sinch.sdk.models.Configuration;
import com.sinch.sdk.models.SMSRegion;
import com.sinch.sdk.models.VoiceContext;
import com.sinch.sdk.models.VoiceRegion;
import org.junit.jupiter.api.Test;
Expand Down Expand Up @@ -34,6 +35,13 @@ void defaultSmsUrlAvailable() {
assertNotNull(client.getConfiguration().getSmsContext().get().getSmsUrl());
}

@Test
void defaultSmsRegion() {
Configuration configuration = Configuration.builder().build();
SinchClient client = new SinchClient(configuration);
assertEquals(SMSRegion.US, client.getConfiguration().getSmsContext().get().getSmsRegion());
}

@Test
void defaultVerificationUrlAvailable() {
Configuration configuration =
Expand All @@ -42,6 +50,14 @@ void defaultVerificationUrlAvailable() {
assertNotNull(client.getConfiguration().getVerificationContext().get().getVerificationUrl());
}

@Test
void defaultVoiceRegion() {
Configuration configuration = Configuration.builder().build();
SinchClient client = new SinchClient(configuration);
assertEquals(
VoiceRegion.GLOBAL, client.getConfiguration().getVoiceContext().get().getVoiceRegion());
}

@Test
void defaultVoiceUrl() {
Configuration configuration =
Expand Down
16 changes: 0 additions & 16 deletions client/src/test/java/com/sinch/sdk/models/SmsContextTest.java

This file was deleted.

Loading