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

DEVEXP-631: rename auto subscribe to user consent #23

Draft
wants to merge 2 commits into
base: main
Choose a base branch
from
Draft
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
2 changes: 1 addition & 1 deletion tutorials/compile.sh
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#!/bin/sh

(cd sms/auto-subscribe-app && mvn clean package)
(cd sms/user-consent-app && mvn clean package)
(cd voice/capture-leads-app && mvn clean package)
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# auto-subscribe application sample
# user-consent application sample

This directory contains sample related to Java SDK tutorials: [auto-subscribe](https://developers.sinch.com/docs/sms/tutorials/sms/tutorials/java-sdk/auto-subscribe)
This directory contains sample related to Java SDK tutorials: [user-consent](https://developers.sinch.com/docs/sms/tutorials/sms/tutorials/java-sdk/user-consent)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@Alexander-Mair
Please confirm which path will be used for tutorials.
Currently, python is sms-tutorials/docs/sms/tutorials/python-sdk/user-consent/

## Requirements

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,10 @@
</parent>

<groupId>my.company.com</groupId>
<artifactId>sinch-sdk-java-tuturial-auto-subscribe</artifactId>
<artifactId>sinch-sdk-java-tuturial-user-consent</artifactId>
<version>0.0.1-SNAPSHOT</version>
<name>Sinch Java SDK auto-subscribe Sample Application</name>
<description>Demo Project for auto-subscribe</description>
<name>Sinch Java SDK user consent Sample Application</name>
<description>Demo Project for user consent</description>

<properties>
<sinch.sdk.java.version>[1.0.0,)</sinch.sdk.java.version>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,17 +19,18 @@ public class Config {
@Value("${credentials.key-secret}")
String keySecret;

@Value("${sms.region}")
String smsRegion;

@Bean
public SMSService smsService() {

var configuration =
Configuration.builder()
.setProjectId(projectId)
.setKeyId(keyId)
.setKeySecret(keySecret)
.setSmsRegion(SMSRegion.US)
.build();
var builder =
Configuration.builder().setProjectId(projectId).setKeyId(keyId).setKeySecret(keySecret);

return new SinchClient(configuration).sms();
if (!smsRegion.isEmpty()) {
builder.setSmsRegion(SMSRegion.from(smsRegion));
}
return new SinchClient(builder.build()).sms();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,13 @@
import org.springframework.web.bind.annotation.RestController;

@RestController
public class AutoSubscribeController {
public class UserConsentController {

private final SMSService smsService;
private final AutoSubscribeService service;
private final UserConsentService service;

@Autowired
public AutoSubscribeController(SMSService smsService, AutoSubscribeService service) {
public UserConsentController(SMSService smsService, UserConsentService service) {
this.smsService = smsService;
this.service = service;
}
Expand All @@ -30,8 +30,6 @@ public void smsDeliveryEvent(@RequestBody String body) {
// let business layer process the request
if (Objects.requireNonNull(event) instanceof InboundText e) {
service.processInboundEvent(e);
} else {
throw new IllegalStateException("Unexpected value: " + event);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,9 @@
import org.springframework.stereotype.Service;

@Service
public class AutoSubscribeService {
public class UserConsentService {

private static final Logger LOGGER = Logger.getLogger(AutoSubscribeService.class.getName());
private static final Logger LOGGER = Logger.getLogger(UserConsentService.class.getName());

static final String SUBSCRIBE_ACTION = "SUBSCRIBE";
static final String STOP_ACTION = "STOP";
Expand All @@ -23,7 +23,7 @@ public class AutoSubscribeService {
private final Group group;

@Autowired
public AutoSubscribeService(SMSService smsService, GroupManager groupManager) {
public UserConsentService(SMSService smsService, GroupManager groupManager) {
this.smsService = smsService;
this.group = groupManager.getGroup();
}
Expand All @@ -39,7 +39,7 @@ public void processInboundEvent(InboundText event) {
var membersList = getMembersList(group);
var isMemberInGroup = isMemberInGroup(membersList, from);

String response = processAction(from, to, action, membersList, isMemberInGroup);
String response = processAction(from, to, action, isMemberInGroup);

sendResponse(to, from, response);
}
Expand All @@ -52,20 +52,15 @@ private boolean isMemberInGroup(Collection<String> membersList, String member) {
return membersList.contains(member);
}

private String processAction(
String from,
String to,
String action,
Collection<String> membersList,
boolean isMemberInGroup) {
private String processAction(String from, String to, String action, boolean isMemberInGroup) {

if (SUBSCRIBE_ACTION.equals(action)) {
return subscribe(group, isMemberInGroup, to, from);
} else if (STOP_ACTION.equals(action)) {
return unsubscribe(group, isMemberInGroup, to, from);
}

return unknwownAction(isMemberInGroup, to);
return unknownAction(isMemberInGroup, to);
}

private String subscribe(
Expand Down Expand Up @@ -100,7 +95,7 @@ private String unsubscribe(
.formatted(group.getName(), SUBSCRIBE_ACTION, groupPhoneNumber);
}

private String unknwownAction(boolean isMemberInGroup, String to) {
private String unknownAction(boolean isMemberInGroup, String to) {

String message =
isMemberInGroup
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,8 @@ server:
credentials:
project-id:
key-id:
key-secret:
key-secret:

# Set a value if not using the default "us" region
sms:
region:
Loading