From 3ef0b5ebfcec6af7161c8e679239e3f6c96ed7e3 Mon Sep 17 00:00:00 2001 From: Jean-Pierre Portier Date: Thu, 4 Jul 2024 14:28:42 +0200 Subject: [PATCH 1/4] refactor (Numbers): Use Numbers v1() --- snippets/numbers/active_update/Snippet.java | 18 +++++++++--------- snippets/numbers/available_list/Snippet.java | 13 +++++++------ snippets/numbers/rent/Snippet.java | 18 +++++++++--------- snippets/numbers/rent_any/Snippet.java | 18 +++++++++--------- 4 files changed, 34 insertions(+), 33 deletions(-) diff --git a/snippets/numbers/active_update/Snippet.java b/snippets/numbers/active_update/Snippet.java index 78e94d9..00dd79e 100644 --- a/snippets/numbers/active_update/Snippet.java +++ b/snippets/numbers/active_update/Snippet.java @@ -1,10 +1,11 @@ package numbers; -import com.sinch.sdk.domains.numbers.ActiveNumberService; -import com.sinch.sdk.domains.numbers.NumbersService; -import com.sinch.sdk.domains.numbers.models.ActiveNumber; -import com.sinch.sdk.domains.numbers.models.requests.ActiveNumberUpdateRequestParameters; -import com.sinch.sdk.domains.numbers.models.requests.ActiveNumberUpdateVoiceConfigurationRequestParameters; +import com.sinch.sdk.domains.numbers.api.v1.ActiveNumberService; +import com.sinch.sdk.domains.numbers.api.v1.NumbersService; +import com.sinch.sdk.domains.numbers.models.v1.ActiveNumber; +import com.sinch.sdk.domains.numbers.models.v1.VoiceConfiguration; +import com.sinch.sdk.domains.numbers.models.v1.VoiceConfigurationRTC; +import com.sinch.sdk.domains.numbers.models.v1.active.request.ActiveNumberUpdateRequest; import java.util.logging.Logger; public class Snippet { @@ -19,11 +20,10 @@ static void execute(NumbersService numbersService) { String appId = "YOUR_app_id"; String displayName = "Updated from Sinch Java SDK"; - ActiveNumberUpdateVoiceConfigurationRequestParameters voiceConfiguration = - ActiveNumberUpdateVoiceConfigurationRequestParameters.builder().setAppId(appId).build(); + VoiceConfiguration voiceConfiguration = VoiceConfigurationRTC.builder().setAppId(appId).build(); - ActiveNumberUpdateRequestParameters updateRequest = - ActiveNumberUpdateRequestParameters.builder() + ActiveNumberUpdateRequest updateRequest = + ActiveNumberUpdateRequest.builder() .setDisplayName(displayName) .setVoiceConfiguration(voiceConfiguration) .build(); diff --git a/snippets/numbers/available_list/Snippet.java b/snippets/numbers/available_list/Snippet.java index d164b1c..358cc58 100644 --- a/snippets/numbers/available_list/Snippet.java +++ b/snippets/numbers/available_list/Snippet.java @@ -1,9 +1,10 @@ package numbers; -import com.sinch.sdk.domains.numbers.*; -import com.sinch.sdk.domains.numbers.models.*; -import com.sinch.sdk.domains.numbers.models.requests.*; -import com.sinch.sdk.domains.numbers.models.responses.AvailableNumberListResponse; +import com.sinch.sdk.domains.numbers.api.v1.AvailableNumberService; +import com.sinch.sdk.domains.numbers.api.v1.NumbersService; +import com.sinch.sdk.domains.numbers.models.v1.NumberType; +import com.sinch.sdk.domains.numbers.models.v1.available.request.AvailableNumberListRequest; +import com.sinch.sdk.domains.numbers.models.v1.available.response.AvailableNumberListResponse; import java.util.logging.Logger; public class Snippet { @@ -17,8 +18,8 @@ static void execute(NumbersService numbersService) { String regionCode = "US"; NumberType type = NumberType.LOCAL; - AvailableNumberListAllRequestParameters parameters = - AvailableNumberListAllRequestParameters.builder() + AvailableNumberListRequest parameters = + AvailableNumberListRequest.builder() .setRegionCode(regionCode) .setType(type) .build(); diff --git a/snippets/numbers/rent/Snippet.java b/snippets/numbers/rent/Snippet.java index bbb7da5..21f3fdb 100644 --- a/snippets/numbers/rent/Snippet.java +++ b/snippets/numbers/rent/Snippet.java @@ -1,10 +1,10 @@ package numbers; -import com.sinch.sdk.domains.numbers.AvailableNumberService; -import com.sinch.sdk.domains.numbers.NumbersService; -import com.sinch.sdk.domains.numbers.models.ActiveNumber; -import com.sinch.sdk.domains.numbers.models.requests.AvailableNumberRentRequestParameters; -import com.sinch.sdk.domains.numbers.models.requests.RentSMSConfigurationRequestParameters; +import com.sinch.sdk.domains.numbers.api.v1.AvailableNumberService; +import com.sinch.sdk.domains.numbers.api.v1.NumbersService; +import com.sinch.sdk.domains.numbers.models.v1.ActiveNumber; +import com.sinch.sdk.domains.numbers.models.v1.SmsConfiguration; +import com.sinch.sdk.domains.numbers.models.v1.available.request.AvailableNumberRentRequest; import java.util.logging.Logger; public class Snippet { @@ -20,11 +20,11 @@ static void execute(NumbersService numbersService) { String phoneNumber = "available_phone_number_to_be_rented"; String servicePlanId = "YOUR_service_plan_id"; - RentSMSConfigurationRequestParameters smsConfiguration = - RentSMSConfigurationRequestParameters.builder().setServicePlanId(servicePlanId).build(); + SmsConfiguration smsConfiguration = + SmsConfiguration.builder().setServicePlanId(servicePlanId).build(); - AvailableNumberRentRequestParameters rentRequest = - AvailableNumberRentRequestParameters.builder() + AvailableNumberRentRequest rentRequest = + AvailableNumberRentRequest.builder() .setSmsConfiguration(smsConfiguration) .build(); diff --git a/snippets/numbers/rent_any/Snippet.java b/snippets/numbers/rent_any/Snippet.java index a4e28b3..668d557 100644 --- a/snippets/numbers/rent_any/Snippet.java +++ b/snippets/numbers/rent_any/Snippet.java @@ -1,12 +1,12 @@ package numbers; -import com.sinch.sdk.domains.numbers.AvailableNumberService; -import com.sinch.sdk.domains.numbers.NumbersService; -import com.sinch.sdk.domains.numbers.models.ActiveNumber; -import com.sinch.sdk.domains.numbers.models.Capability; -import com.sinch.sdk.domains.numbers.models.NumberType; -import com.sinch.sdk.domains.numbers.models.requests.AvailableNumberRentAnyRequestParameters; -import com.sinch.sdk.domains.numbers.models.requests.RentSMSConfigurationRequestParameters; +import com.sinch.sdk.domains.numbers.api.v1.AvailableNumberService; +import com.sinch.sdk.domains.numbers.api.v1.NumbersService; +import com.sinch.sdk.domains.numbers.models.v1.ActiveNumber; +import com.sinch.sdk.domains.numbers.models.v1.Capability; +import com.sinch.sdk.domains.numbers.models.v1.NumberType; +import com.sinch.sdk.domains.numbers.models.v1.SmsConfiguration; +import com.sinch.sdk.domains.numbers.models.v1.available.request.AvailableNumberRentAnyRequest; import java.util.Collections; import java.util.logging.Logger; @@ -26,12 +26,12 @@ static void execute(NumbersService numbersService) { ActiveNumber response = availableNumbersService.rentAny( - AvailableNumberRentAnyRequestParameters.builder() + AvailableNumberRentAnyRequest.builder() .setCapabilities(Collections.singletonList(capability)) .setType(numberType) .setRegionCode(regionCode) .setSmsConfiguration( - RentSMSConfigurationRequestParameters.builder() + SmsConfiguration.builder() .setServicePlanId(servicePlanId) .build()) .build()); From 61b158fe4361bd47258007b1f4c013da5797f273 Mon Sep 17 00:00:00 2001 From: Jean-Pierre Portier Date: Thu, 4 Jul 2024 14:29:01 +0200 Subject: [PATCH 2/4] ci: Stop script onto compilation error --- compile.sh | 4 ++-- snippets/compile.sh | 6 +----- 2 files changed, 3 insertions(+), 7 deletions(-) diff --git a/compile.sh b/compile.sh index 507ee01..81b44f0 100755 --- a/compile.sh +++ b/compile.sh @@ -1,5 +1,5 @@ #!/bin/sh -(cd snippets && mvn clean spotless:apply) -(cd snippets && ./compile.sh) +(cd snippets && mvn clean spotless:apply) || exit 1 +(cd snippets && ./compile.sh) ||exit 1 diff --git a/snippets/compile.sh b/snippets/compile.sh index eb921f1..167484f 100755 --- a/snippets/compile.sh +++ b/snippets/compile.sh @@ -6,9 +6,5 @@ echo "Compiling snippets:" for snippet in $SNIPPETS do echo " - Snippet: $snippet" - mvn compile -Dsnippet="$(dirname $snippet)" - if [ $? -ne 0 ] - then - exit $? - fi + mvn compile -Dsnippet="$(dirname $snippet)" || exit 1 done From f8aab60cf842525739d1cbd12999e4c4cb1d65df Mon Sep 17 00:00:00 2001 From: Jean-Pierre Portier Date: Tue, 9 Jul 2024 18:30:31 +0200 Subject: [PATCH 3/4] feature (Numbers): Use elegant functions --- snippets/numbers/active_update/Snippet.java | 5 +---- snippets/numbers/available_list/Snippet.java | 10 ++-------- snippets/numbers/rent/Snippet.java | 9 ++------- snippets/numbers/rent_any/Snippet.java | 9 ++------- 4 files changed, 7 insertions(+), 26 deletions(-) diff --git a/snippets/numbers/active_update/Snippet.java b/snippets/numbers/active_update/Snippet.java index 00dd79e..cb09b9a 100644 --- a/snippets/numbers/active_update/Snippet.java +++ b/snippets/numbers/active_update/Snippet.java @@ -1,6 +1,5 @@ package numbers; -import com.sinch.sdk.domains.numbers.api.v1.ActiveNumberService; import com.sinch.sdk.domains.numbers.api.v1.NumbersService; import com.sinch.sdk.domains.numbers.models.v1.ActiveNumber; import com.sinch.sdk.domains.numbers.models.v1.VoiceConfiguration; @@ -14,8 +13,6 @@ public class Snippet { static void execute(NumbersService numbersService) { - ActiveNumberService activeNumbersService = numbersService.active(); - String phoneNumber = "YOUR_phone_number_to_be_updated"; String appId = "YOUR_app_id"; String displayName = "Updated from Sinch Java SDK"; @@ -28,7 +25,7 @@ static void execute(NumbersService numbersService) { .setVoiceConfiguration(voiceConfiguration) .build(); - ActiveNumber response = activeNumbersService.update(phoneNumber, updateRequest); + ActiveNumber response = numbersService.update(phoneNumber, updateRequest); LOGGER.info(String.format("Updated number: %s", response)); } diff --git a/snippets/numbers/available_list/Snippet.java b/snippets/numbers/available_list/Snippet.java index 358cc58..7ba34a3 100644 --- a/snippets/numbers/available_list/Snippet.java +++ b/snippets/numbers/available_list/Snippet.java @@ -1,6 +1,5 @@ package numbers; -import com.sinch.sdk.domains.numbers.api.v1.AvailableNumberService; import com.sinch.sdk.domains.numbers.api.v1.NumbersService; import com.sinch.sdk.domains.numbers.models.v1.NumberType; import com.sinch.sdk.domains.numbers.models.v1.available.request.AvailableNumberListRequest; @@ -13,18 +12,13 @@ public class Snippet { static void execute(NumbersService numbersService) { - AvailableNumberService availableNumbersService = numbersService.available(); - String regionCode = "US"; NumberType type = NumberType.LOCAL; AvailableNumberListRequest parameters = - AvailableNumberListRequest.builder() - .setRegionCode(regionCode) - .setType(type) - .build(); + AvailableNumberListRequest.builder().setRegionCode(regionCode).setType(type).build(); - AvailableNumberListResponse response = availableNumbersService.list(parameters); + AvailableNumberListResponse response = numbersService.searchForAvailableNumbers(parameters); response .iterator() diff --git a/snippets/numbers/rent/Snippet.java b/snippets/numbers/rent/Snippet.java index 21f3fdb..4675944 100644 --- a/snippets/numbers/rent/Snippet.java +++ b/snippets/numbers/rent/Snippet.java @@ -1,6 +1,5 @@ package numbers; -import com.sinch.sdk.domains.numbers.api.v1.AvailableNumberService; import com.sinch.sdk.domains.numbers.api.v1.NumbersService; import com.sinch.sdk.domains.numbers.models.v1.ActiveNumber; import com.sinch.sdk.domains.numbers.models.v1.SmsConfiguration; @@ -13,8 +12,6 @@ public class Snippet { static void execute(NumbersService numbersService) { - AvailableNumberService availableNumbersService = numbersService.available(); - // Available numbers list can be retrieved by using list() function from available service, see: // https://developers.sinch.com/quickstart-getting-started-poc/docs/numbers/getting-started/java-sdk/searchavailable String phoneNumber = "available_phone_number_to_be_rented"; @@ -24,11 +21,9 @@ static void execute(NumbersService numbersService) { SmsConfiguration.builder().setServicePlanId(servicePlanId).build(); AvailableNumberRentRequest rentRequest = - AvailableNumberRentRequest.builder() - .setSmsConfiguration(smsConfiguration) - .build(); + AvailableNumberRentRequest.builder().setSmsConfiguration(smsConfiguration).build(); - ActiveNumber response = availableNumbersService.rent(phoneNumber, rentRequest); + ActiveNumber response = numbersService.rent(phoneNumber, rentRequest); LOGGER.info(String.format("Rented number: %s", response)); } diff --git a/snippets/numbers/rent_any/Snippet.java b/snippets/numbers/rent_any/Snippet.java index 668d557..a1e82bd 100644 --- a/snippets/numbers/rent_any/Snippet.java +++ b/snippets/numbers/rent_any/Snippet.java @@ -1,6 +1,5 @@ package numbers; -import com.sinch.sdk.domains.numbers.api.v1.AvailableNumberService; import com.sinch.sdk.domains.numbers.api.v1.NumbersService; import com.sinch.sdk.domains.numbers.models.v1.ActiveNumber; import com.sinch.sdk.domains.numbers.models.v1.Capability; @@ -16,8 +15,6 @@ public class Snippet { static void execute(NumbersService numbersService) { - AvailableNumberService availableNumbersService = numbersService.available(); - String servicePlanId = "YOUR_service_plan_id"; String regionCode = "YOUR_region_code"; @@ -25,15 +22,13 @@ static void execute(NumbersService numbersService) { NumberType numberType = NumberType.LOCAL; ActiveNumber response = - availableNumbersService.rentAny( + numbersService.rentAny( AvailableNumberRentAnyRequest.builder() .setCapabilities(Collections.singletonList(capability)) .setType(numberType) .setRegionCode(regionCode) .setSmsConfiguration( - SmsConfiguration.builder() - .setServicePlanId(servicePlanId) - .build()) + SmsConfiguration.builder().setServicePlanId(servicePlanId).build()) .build()); LOGGER.info(String.format("Rented number: %s", response)); From 9ce72e40194b73f66808fde8ce45508f49ee131a Mon Sep 17 00:00:00 2001 From: Jean-Pierre Portier Date: Wed, 10 Jul 2024 08:38:36 +0200 Subject: [PATCH 4/4] refactor: available/active classes moved to request/response package at numbers's package level --- snippets/numbers/active_update/Snippet.java | 2 +- snippets/numbers/available_list/Snippet.java | 4 ++-- snippets/numbers/rent/Snippet.java | 2 +- snippets/numbers/rent_any/Snippet.java | 2 +- 4 files changed, 5 insertions(+), 5 deletions(-) diff --git a/snippets/numbers/active_update/Snippet.java b/snippets/numbers/active_update/Snippet.java index cb09b9a..a7965d3 100644 --- a/snippets/numbers/active_update/Snippet.java +++ b/snippets/numbers/active_update/Snippet.java @@ -4,7 +4,7 @@ import com.sinch.sdk.domains.numbers.models.v1.ActiveNumber; import com.sinch.sdk.domains.numbers.models.v1.VoiceConfiguration; import com.sinch.sdk.domains.numbers.models.v1.VoiceConfigurationRTC; -import com.sinch.sdk.domains.numbers.models.v1.active.request.ActiveNumberUpdateRequest; +import com.sinch.sdk.domains.numbers.models.v1.request.ActiveNumberUpdateRequest; import java.util.logging.Logger; public class Snippet { diff --git a/snippets/numbers/available_list/Snippet.java b/snippets/numbers/available_list/Snippet.java index 7ba34a3..56efc89 100644 --- a/snippets/numbers/available_list/Snippet.java +++ b/snippets/numbers/available_list/Snippet.java @@ -2,8 +2,8 @@ import com.sinch.sdk.domains.numbers.api.v1.NumbersService; import com.sinch.sdk.domains.numbers.models.v1.NumberType; -import com.sinch.sdk.domains.numbers.models.v1.available.request.AvailableNumberListRequest; -import com.sinch.sdk.domains.numbers.models.v1.available.response.AvailableNumberListResponse; +import com.sinch.sdk.domains.numbers.models.v1.request.AvailableNumberListRequest; +import com.sinch.sdk.domains.numbers.models.v1.response.AvailableNumberListResponse; import java.util.logging.Logger; public class Snippet { diff --git a/snippets/numbers/rent/Snippet.java b/snippets/numbers/rent/Snippet.java index 4675944..f0a967c 100644 --- a/snippets/numbers/rent/Snippet.java +++ b/snippets/numbers/rent/Snippet.java @@ -3,7 +3,7 @@ import com.sinch.sdk.domains.numbers.api.v1.NumbersService; import com.sinch.sdk.domains.numbers.models.v1.ActiveNumber; import com.sinch.sdk.domains.numbers.models.v1.SmsConfiguration; -import com.sinch.sdk.domains.numbers.models.v1.available.request.AvailableNumberRentRequest; +import com.sinch.sdk.domains.numbers.models.v1.request.AvailableNumberRentRequest; import java.util.logging.Logger; public class Snippet { diff --git a/snippets/numbers/rent_any/Snippet.java b/snippets/numbers/rent_any/Snippet.java index a1e82bd..abf1411 100644 --- a/snippets/numbers/rent_any/Snippet.java +++ b/snippets/numbers/rent_any/Snippet.java @@ -5,7 +5,7 @@ import com.sinch.sdk.domains.numbers.models.v1.Capability; import com.sinch.sdk.domains.numbers.models.v1.NumberType; import com.sinch.sdk.domains.numbers.models.v1.SmsConfiguration; -import com.sinch.sdk.domains.numbers.models.v1.available.request.AvailableNumberRentAnyRequest; +import com.sinch.sdk.domains.numbers.models.v1.request.AvailableNumberRentAnyRequest; import java.util.Collections; import java.util.logging.Logger;