-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feature (DEVEXP-214): Support Voice/Applications
- Loading branch information
Showing
51 changed files
with
1,862 additions
and
507 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
56 changes: 56 additions & 0 deletions
56
client/src/main/com/sinch/sdk/domains/voice/ApplicationsService.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
package com.sinch.sdk.domains.voice; | ||
|
||
import com.sinch.sdk.domains.voice.models.CallbackUrls; | ||
import com.sinch.sdk.domains.voice.models.NumberInformation; | ||
import com.sinch.sdk.domains.voice.models.requests.ApplicationsUpdateNumbersRequestParameters; | ||
import com.sinch.sdk.domains.voice.models.response.AssignedNumbers; | ||
import com.sinch.sdk.models.E164PhoneNumber; | ||
|
||
/** You can use the API to manage features of applications in your project. */ | ||
public interface ApplicationsService { | ||
|
||
/** | ||
* Get information about your numbers. | ||
* | ||
* <p>It returns a list of numbers that you own, as well as their capability (voice or SMS). For | ||
* the ones that are assigned to an app, it returns the application key of the app. | ||
* | ||
* @return Your numbers | ||
* @since 1.0 | ||
*/ | ||
AssignedNumbers getNumbers(); | ||
|
||
/** | ||
* Returns any callback URLs configured for the specified application | ||
* | ||
* @param applicationKey The unique identifying key of the application | ||
* @return Assigned callback to application | ||
* @since 1.0 | ||
*/ | ||
CallbackUrls getCallbackUrls(String applicationKey); | ||
|
||
/** | ||
* @since 1.0 | ||
*/ | ||
void updateCallbackUrls(String applicationKey, CallbackUrls parameters); | ||
|
||
NumberInformation queryNumber(E164PhoneNumber number); | ||
|
||
/** | ||
* Update or assign a list of numbers to an application. | ||
* | ||
* @param parameters Request parameters | ||
* @since 1.0 | ||
*/ | ||
void updateNumbers(ApplicationsUpdateNumbersRequestParameters parameters); | ||
|
||
/** | ||
* Un-assign a number from an application. | ||
* | ||
* @param phoneNumber The phone number | ||
* @param applicationKey Indicates the application where the number was assigned. | ||
* <p>If empty, the application key that is used to authenticate | ||
* @since 1.0 | ||
*/ | ||
public void unassignNumber(E164PhoneNumber phoneNumber, String applicationKey); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
63 changes: 63 additions & 0 deletions
63
client/src/main/com/sinch/sdk/domains/voice/adapters/ApplicationsService.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
package com.sinch.sdk.domains.voice.adapters; | ||
|
||
import com.sinch.sdk.core.http.AuthManager; | ||
import com.sinch.sdk.core.http.HttpClient; | ||
import com.sinch.sdk.core.http.HttpMapper; | ||
import com.sinch.sdk.domains.voice.adapters.api.v1.ApplicationsApi; | ||
import com.sinch.sdk.domains.voice.adapters.converters.ApplicationsDtoConverter; | ||
import com.sinch.sdk.domains.voice.models.CallbackUrls; | ||
import com.sinch.sdk.domains.voice.models.NumberInformation; | ||
import com.sinch.sdk.domains.voice.models.requests.ApplicationsUpdateNumbersRequestParameters; | ||
import com.sinch.sdk.domains.voice.models.response.AssignedNumbers; | ||
import com.sinch.sdk.models.Configuration; | ||
import com.sinch.sdk.models.E164PhoneNumber; | ||
import java.util.Map; | ||
|
||
public class ApplicationsService implements com.sinch.sdk.domains.voice.ApplicationsService { | ||
|
||
private final ApplicationsApi api; | ||
|
||
public ApplicationsService( | ||
Configuration configuration, HttpClient httpClient, Map<String, AuthManager> authManagers) { | ||
this.api = | ||
new ApplicationsApi( | ||
httpClient, | ||
configuration.getVoiceApplicationMngmtServer(), | ||
authManagers, | ||
new HttpMapper()); | ||
} | ||
|
||
protected ApplicationsApi getApi() { | ||
return this.api; | ||
} | ||
|
||
public AssignedNumbers getNumbers() { | ||
|
||
return ApplicationsDtoConverter.convert(getApi().configurationGetNumbers()); | ||
} | ||
|
||
public CallbackUrls getCallbackUrls(String applicationKey) { | ||
|
||
return ApplicationsDtoConverter.convert(getApi().configurationGetCallbackURLs(applicationKey)); | ||
} | ||
|
||
public void updateCallbackUrls(String applicationKey, CallbackUrls parameters) { | ||
getApi() | ||
.configurationUpdateCallbackURLs( | ||
applicationKey, ApplicationsDtoConverter.convert(parameters)); | ||
} | ||
|
||
public NumberInformation queryNumber(E164PhoneNumber number) { | ||
return ApplicationsDtoConverter.convert(getApi().callingQueryNumber(number.stringValue())); | ||
} | ||
|
||
public void updateNumbers(ApplicationsUpdateNumbersRequestParameters parameters) { | ||
getApi().configurationUpdateNumbers(ApplicationsDtoConverter.convert(parameters)); | ||
} | ||
|
||
public void unassignNumber(E164PhoneNumber phoneNumber, String applicationKey) { | ||
|
||
getApi() | ||
.configurationUnassignNumber(ApplicationsDtoConverter.convert(phoneNumber, applicationKey)); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
120 changes: 120 additions & 0 deletions
120
...nt/src/main/com/sinch/sdk/domains/voice/adapters/converters/ApplicationsDtoConverter.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,120 @@ | ||
package com.sinch.sdk.domains.voice.adapters.converters; | ||
|
||
import com.sinch.sdk.domains.common.adapters.converters.EnumDynamicConverter; | ||
import com.sinch.sdk.domains.voice.models.ApplicationAssignedNumber; | ||
import com.sinch.sdk.domains.voice.models.ApplicationURL; | ||
import com.sinch.sdk.domains.voice.models.CallbackUrls; | ||
import com.sinch.sdk.domains.voice.models.NumberInformation; | ||
import com.sinch.sdk.domains.voice.models.dto.v1.CallbacksDto; | ||
import com.sinch.sdk.domains.voice.models.dto.v1.CallbacksUrlDto; | ||
import com.sinch.sdk.domains.voice.models.dto.v1.GetNumbersResponseObjDto; | ||
import com.sinch.sdk.domains.voice.models.dto.v1.GetNumbersResponseObjNumbersInnerDto; | ||
import com.sinch.sdk.domains.voice.models.dto.v1.GetQueryNumberDto; | ||
import com.sinch.sdk.domains.voice.models.dto.v1.GetQueryNumberNumberDto; | ||
import com.sinch.sdk.domains.voice.models.dto.v1.UnassignNumbersDto; | ||
import com.sinch.sdk.domains.voice.models.dto.v1.UpdateNumbersDto; | ||
import com.sinch.sdk.domains.voice.models.requests.ApplicationsUpdateNumbersRequestParameters; | ||
import com.sinch.sdk.domains.voice.models.response.AssignedNumbers; | ||
import com.sinch.sdk.models.E164PhoneNumber; | ||
import java.util.List; | ||
import java.util.stream.Collectors; | ||
|
||
public class ApplicationsDtoConverter { | ||
|
||
public static AssignedNumbers convert(GetNumbersResponseObjDto dto) { | ||
if (null == dto) { | ||
return null; | ||
} | ||
List<GetNumbersResponseObjNumbersInnerDto> list = dto.getNumbers(); | ||
if (null == list) { | ||
return null; | ||
} | ||
return AssignedNumbers.builder() | ||
.setNumbers( | ||
list.stream().map(ApplicationsDtoConverter::convert).collect(Collectors.toList())) | ||
.build(); | ||
} | ||
|
||
public static CallbackUrls convert(CallbacksDto dto) { | ||
if (null == dto) { | ||
return null; | ||
} | ||
|
||
return CallbackUrls.builder().setUrl(convert(dto.getUrl())).build(); | ||
} | ||
|
||
public static CallbacksDto convert(CallbackUrls client) { | ||
if (null == client || null == client.getUrl()) { | ||
return null; | ||
} | ||
CallbacksDto dto = new CallbacksDto(); | ||
dto.url( | ||
new CallbacksUrlDto() | ||
.primary(client.getUrl().getPrimary()) | ||
.fallback(client.getUrl().getFallback())); | ||
return dto; | ||
} | ||
|
||
public static NumberInformation convert(GetQueryNumberDto dto) { | ||
if (null == dto || !dto.getNumberDefined()) { | ||
return null; | ||
} | ||
GetQueryNumberNumberDto item = dto.getNumber(); | ||
return NumberInformation.builder() | ||
.setCountryId(item.getCountryId()) | ||
.setNumberType(NumberTypeDtoConverter.convert(item.getNumberType())) | ||
.setNormalizedNumber(E164PhoneNumberDtoConverter.convert(item.getNormalizedNumber())) | ||
.setRestricted(item.getRestricted()) | ||
.setRate(PriceDtoConverter.convert(item.getRate())) | ||
.build(); | ||
} | ||
|
||
public static UpdateNumbersDto convert(ApplicationsUpdateNumbersRequestParameters client) { | ||
if (null == client) { | ||
return null; | ||
} | ||
UpdateNumbersDto dto = new UpdateNumbersDto(); | ||
client | ||
.getNumbers() | ||
.ifPresent( | ||
f -> | ||
dto.numbers( | ||
f.stream().map(E164PhoneNumber::stringValue).collect(Collectors.toList()))); | ||
client.getApplicationKey().ifPresent(dto::applicationkey); | ||
client.getCapability().ifPresent(f -> dto.capability(EnumDynamicConverter.convert(f))); | ||
return dto; | ||
} | ||
|
||
public static UnassignNumbersDto convert(E164PhoneNumber phoneNumber, String applicationKey) { | ||
|
||
UnassignNumbersDto dto = new UnassignNumbersDto(); | ||
if (null != phoneNumber) { | ||
dto.number(phoneNumber.stringValue()); | ||
} | ||
dto.applicationkey(applicationKey); | ||
return dto; | ||
} | ||
|
||
private static ApplicationURL convert(CallbacksUrlDto dto) { | ||
if (null == dto) { | ||
return null; | ||
} | ||
|
||
return ApplicationURL.builder() | ||
.setPrimary(dto.getPrimary()) | ||
.setFallback(dto.getFallback()) | ||
.build(); | ||
} | ||
|
||
private static ApplicationAssignedNumber convert(GetNumbersResponseObjNumbersInnerDto dto) { | ||
if (null == dto) { | ||
return null; | ||
} | ||
|
||
return ApplicationAssignedNumber.builder() | ||
.setNumber(E164PhoneNumberDtoConverter.convert(dto.getNumber())) | ||
.setApplicationKey(dto.getApplicationkey()) | ||
.setCapability(CapabilityDtoConverter.convert(dto.getCapability())) | ||
.build(); | ||
} | ||
} |
13 changes: 13 additions & 0 deletions
13
client/src/main/com/sinch/sdk/domains/voice/adapters/converters/CapabilityDtoConverter.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
package com.sinch.sdk.domains.voice.adapters.converters; | ||
|
||
import com.sinch.sdk.domains.voice.models.CapabilityType; | ||
|
||
public class CapabilityDtoConverter { | ||
|
||
public static CapabilityType convert(String dto) { | ||
if (null == dto) { | ||
return null; | ||
} | ||
return CapabilityType.from(dto); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
13 changes: 13 additions & 0 deletions
13
client/src/main/com/sinch/sdk/domains/voice/adapters/converters/NumberTypeDtoConverter.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
package com.sinch.sdk.domains.voice.adapters.converters; | ||
|
||
import com.sinch.sdk.domains.voice.models.NumberType; | ||
|
||
public class NumberTypeDtoConverter { | ||
|
||
public static NumberType convert(String dto) { | ||
if (null == dto) { | ||
return null; | ||
} | ||
return NumberType.from(dto); | ||
} | ||
} |
Oops, something went wrong.