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

feature (Numbers): Use elegant functions #9

Merged
Show file tree
Hide file tree
Changes from 1 commit
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
5 changes: 1 addition & 4 deletions snippets/numbers/active_update/Snippet.java
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -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";
Expand All @@ -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));
}
Expand Down
10 changes: 2 additions & 8 deletions snippets/numbers/available_list/Snippet.java
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -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()
Expand Down
9 changes: 2 additions & 7 deletions snippets/numbers/rent/Snippet.java
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -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";
Expand All @@ -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));
}
Expand Down
9 changes: 2 additions & 7 deletions snippets/numbers/rent_any/Snippet.java
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -16,24 +15,20 @@ public class Snippet {

static void execute(NumbersService numbersService) {

AvailableNumberService availableNumbersService = numbersService.available();

String servicePlanId = "YOUR_service_plan_id";
String regionCode = "YOUR_region_code";

Capability capability = Capability.SMS;
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));
Expand Down
Loading