Skip to content

Commit

Permalink
Refactor private methods and added readme
Browse files Browse the repository at this point in the history
  • Loading branch information
jorge-beauregard committed Oct 26, 2020
1 parent db34882 commit 5ec46e1
Show file tree
Hide file tree
Showing 4 changed files with 49 additions and 49 deletions.
16 changes: 16 additions & 0 deletions sdk/communication/azure-communication-administration/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -303,6 +303,22 @@ SyncPoller<Void, Void> res =
res.waitForCompletion();
```

### Release Phone Numbers
<!-- embedme ./src/samples/java/com/azure/communication/administration/ReadmeSamples.java#L399-L409 -->
```java
PhoneNumber phoneNumber = new PhoneNumber("PHONE_NUMBER_TO_RELEASE");
List<PhoneNumber> phoneNumbers = new ArrayList<>();
phoneNumbers.add(phoneNumber);
PhoneNumberClient phoneNumberClient = createPhoneNumberClient();

SyncPoller<PhoneNumberRelease, PhoneNumberRelease> res =
phoneNumberClient.beginReleasePhoneNumbers(phoneNumbers, duration);
res.waitForCompletion();
PhoneNumberRelease result = res.getFinalResult();
System.out.println("Phone number status: " + result.getStatus());
}
```

## Contributing

This project welcomes contributions and suggestions. Most contributions require you to agree to a [Contributor License Agreement (CLA)][cla] declaring that you have the right to, and actually do, grant us the rights to use your contribution.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -367,30 +367,6 @@ public Response<PhoneNumberRelease> getReleaseByIdWithResponse(String releaseId,
return phoneNumberAsyncClient.getReleaseByIdWithResponse(releaseId, context).block();
}

/**
* Creates a release for the given phone numbers.
*
* @param phoneNumbers {@link List} of {@link PhoneNumber} objects with the phone numbers.
* @return A {@link ReleaseResponse} representing the release.
*/
@ServiceMethod(returns = ReturnType.SINGLE)
public ReleaseResponse releasePhoneNumbers(List<PhoneNumber> phoneNumbers) {
return phoneNumberAsyncClient.releasePhoneNumbers(phoneNumbers).block();
}

/**
* Creates a release for the given phone numbers.
*
* @param phoneNumbers {@link List} of {@link PhoneNumber} objects with the phone numbers.
* @param context A {@link Context} representing the request context.
* @return A {@link Response} whose {@link Response#getValue()} value returns
* a {@link ReleaseResponse} representing the release.
*/
@ServiceMethod(returns = ReturnType.SINGLE)
public Response<ReleaseResponse> releasePhoneNumbersWithResponse(List<PhoneNumber> phoneNumbers, Context context) {
return phoneNumberAsyncClient.releasePhoneNumbersWithResponse(phoneNumbers, context).block();
}

/**
* Gets the list of all releases
*
Expand Down Expand Up @@ -554,4 +530,19 @@ public SyncPoller<Void, Void> beginPurchaseSearch(
String searchId, Duration pollInterval) {
return phoneNumberAsyncClient.beginPurchaseSearch(searchId, pollInterval).getSyncPoller();
}

/**
* Releases the given phone numbers.
* This function returns a Long Running Operation poller
*
* @param phoneNumbers A list of {@link PhoneNumber} with the desired numbers to release
* @param pollInterval The time our long running operation will keep on polling
* until it gets a result from the server
* @return A {@link SyncPoller} object with the search result
*/
@ServiceMethod(returns = ReturnType.COLLECTION)
public SyncPoller<PhoneNumberRelease, PhoneNumberRelease> beginReleasePhoneNumbers(
List<PhoneNumber> phoneNumbers, Duration pollInterval) {
return phoneNumberAsyncClient.beginReleasePhoneNumbers(phoneNumbers, pollInterval).getSyncPoller();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
import com.azure.communication.administration.models.LocationOptionsDetails;
import com.azure.communication.administration.models.LocationOptionsQuery;
import com.azure.communication.administration.models.PhoneNumberCountry;
import com.azure.communication.administration.models.PhoneNumberRelease;
import com.azure.communication.administration.models.PhoneNumberSearch;
import com.azure.communication.administration.models.PhonePlan;
import com.azure.communication.administration.models.PhonePlanGroup;
Expand All @@ -27,7 +28,6 @@
import com.azure.core.util.polling.SyncPoller;

public class ReadmeSamples {

/**
* Sample code for creating a sync Communication Identity Client.
*
Expand Down Expand Up @@ -390,4 +390,21 @@ public void beginPurchaseSearch() {
phoneNumberClient.beginPurchaseSearch(phoneNumberSearchId, duration);
res.waitForCompletion();
}

/**
* Sample code to release a phone number as a long running operation
*/
public void beginReleasePhoneNumbers() {
Duration duration = Duration.ofSeconds(1);
PhoneNumber phoneNumber = new PhoneNumber("PHONE_NUMBER_TO_RELEASE");
List<PhoneNumber> phoneNumbers = new ArrayList<>();
phoneNumbers.add(phoneNumber);
PhoneNumberClient phoneNumberClient = createPhoneNumberClient();

SyncPoller<PhoneNumberRelease, PhoneNumberRelease> res =
phoneNumberClient.beginReleasePhoneNumbers(phoneNumbers, duration);
res.waitForCompletion();
PhoneNumberRelease result = res.getFinalResult();
System.out.println("Phone number status: " + result.getStatus());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -345,30 +345,6 @@ public void unconfigureNumberWithResponse(HttpClient httpClient) {
assertEquals(200, response.getStatusCode());
}

@ParameterizedTest
@MethodSource("com.azure.core.test.TestBase#getHttpClients")
public void releasePhoneNumbers(HttpClient httpClient) {
List<PhoneNumber> phoneNumbers = new ArrayList<>();
phoneNumbers.add(new PhoneNumber(PHONENUMBER_TO_RELEASE));

ReleaseResponse releaseResponse = this.getClient(httpClient).releasePhoneNumbers(phoneNumbers);

assertNotNull(releaseResponse.getReleaseId());
}

@ParameterizedTest
@MethodSource("com.azure.core.test.TestBase#getHttpClients")
public void releasePhoneNumbersWithResponse(HttpClient httpClient) {
List<PhoneNumber> phoneNumbers = new ArrayList<>();
phoneNumbers.add(new PhoneNumber(PHONENUMBER_TO_RELEASE));

Response<ReleaseResponse> response =
this.getClient(httpClient).releasePhoneNumbersWithResponse(phoneNumbers, Context.NONE);

assertEquals(200, response.getStatusCode());
assertNotNull(response.getValue().getReleaseId());
}

private PhoneNumberClient getClient(HttpClient httpClient) {
return super.getClientBuilder(httpClient).buildClient();
}
Expand Down

0 comments on commit 5ec46e1

Please sign in to comment.