-
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.
- Loading branch information
Showing
44 changed files
with
2,442 additions
and
30 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
9 changes: 9 additions & 0 deletions
9
client/src/main/com/sinch/sdk/auth/adapters/VoiceApplicationAuthManager.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,9 @@ | ||
package com.sinch.sdk.auth.adapters; | ||
|
||
// Voice and Verification are sharing same authentication mechanism | ||
public class VoiceApplicationAuthManager extends VerificationApplicationAuthManager { | ||
|
||
public VoiceApplicationAuthManager(String key, String base64Secret) { | ||
super(key, base64Secret); | ||
} | ||
} |
6 changes: 6 additions & 0 deletions
6
client/src/main/com/sinch/sdk/domains/sms/models/package-info.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,6 @@ | ||
/** | ||
* SMS API related models | ||
* | ||
* @since 1.0 | ||
*/ | ||
package com.sinch.sdk.domains.sms.models; |
24 changes: 24 additions & 0 deletions
24
client/src/main/com/sinch/sdk/domains/voice/CalloutsService.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,24 @@ | ||
package com.sinch.sdk.domains.voice; | ||
|
||
import com.sinch.sdk.domains.voice.models.requests.CalloutRequestParameters; | ||
|
||
/** | ||
* A callout is a call made to a phone number or app using the API. | ||
* | ||
* @see <a | ||
* href="https://developers.sinch.com/docs/voice/api-reference/voice/tag/Callouts">https://developers.sinch.com/docs/voice/api-reference/voice/tag/Callouts</a> | ||
* @since 1.0 | ||
*/ | ||
public interface CalloutsService { | ||
|
||
/** | ||
* Makes a call out to a phone number. The types of callouts currently supported are conference | ||
* callouts, text-to-speech callouts, and custom callouts. The custom callout is the most | ||
* flexible, but text-to-speech and conference callouts are more convenient. | ||
* | ||
* @param parameters Callout type to be performed | ||
* @return The returned call identifier | ||
* @since 1.0 | ||
*/ | ||
String call(CalloutRequestParameters parameters); | ||
} |
19 changes: 19 additions & 0 deletions
19
client/src/main/com/sinch/sdk/domains/voice/VoiceService.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,19 @@ | ||
package com.sinch.sdk.domains.voice; | ||
|
||
/** | ||
* Voice service | ||
* | ||
* @see <a | ||
* href="https://developers.sinch.com/docs/voice/">https://developers.sinch.com/docs/voice/</a> | ||
* @since 1.0 | ||
*/ | ||
public interface VoiceService { | ||
|
||
/** | ||
* Callouts Service instance | ||
* | ||
* @return service instance for project | ||
* @since 1.0 | ||
*/ | ||
CalloutsService callouts(); | ||
} |
31 changes: 31 additions & 0 deletions
31
client/src/main/com/sinch/sdk/domains/voice/adapters/CalloutsService.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,31 @@ | ||
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.CalloutsApi; | ||
import com.sinch.sdk.domains.voice.adapters.converters.CalloutsDtoConverter; | ||
import com.sinch.sdk.domains.voice.models.requests.CalloutRequestParameters; | ||
import com.sinch.sdk.models.Configuration; | ||
import java.util.Map; | ||
|
||
public class CalloutsService implements com.sinch.sdk.domains.voice.CalloutsService { | ||
|
||
private final CalloutsApi api; | ||
|
||
public CalloutsService( | ||
Configuration configuration, HttpClient httpClient, Map<String, AuthManager> authManagers) { | ||
this.api = | ||
new CalloutsApi(httpClient, configuration.getVoiceServer(), authManagers, new HttpMapper()); | ||
} | ||
|
||
protected CalloutsApi getApi() { | ||
return this.api; | ||
} | ||
|
||
public String call(CalloutRequestParameters parameters) { | ||
|
||
return CalloutsDtoConverter.convert( | ||
getApi().callouts(CalloutsDtoConverter.convert(parameters))); | ||
} | ||
} |
63 changes: 63 additions & 0 deletions
63
client/src/main/com/sinch/sdk/domains/voice/adapters/VoiceService.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.auth.adapters.VoiceApplicationAuthManager; | ||
import com.sinch.sdk.core.exceptions.ApiAuthException; | ||
import com.sinch.sdk.core.http.AuthManager; | ||
import com.sinch.sdk.core.http.HttpClient; | ||
import com.sinch.sdk.domains.voice.CalloutsService; | ||
import com.sinch.sdk.models.Configuration; | ||
import java.util.Map; | ||
import java.util.Objects; | ||
import java.util.TreeMap; | ||
|
||
public class VoiceService implements com.sinch.sdk.domains.voice.VoiceService { | ||
|
||
private static final String SECURITY_SCHEME_KEYWORD = "Signed"; | ||
|
||
private final Configuration configuration; | ||
private final HttpClient httpClient; | ||
private CalloutsService callouts; | ||
|
||
private Map<String, AuthManager> clientAuthManagers; | ||
|
||
public VoiceService(Configuration configuration, HttpClient httpClient) { | ||
|
||
// Currently, we are not supporting unified credentials: ensure application credentials are | ||
// defined | ||
Objects.requireNonNull(configuration.getApplicationKey(), "'applicationKey' cannot be null"); | ||
Objects.requireNonNull( | ||
configuration.getApplicationSecret(), "'applicationSecret' cannot be null"); | ||
|
||
this.configuration = configuration; | ||
this.httpClient = httpClient; | ||
setApplicationCredentials( | ||
configuration.getApplicationKey(), configuration.getApplicationSecret()); | ||
} | ||
|
||
private void setApplicationCredentials(String key, String secret) { | ||
|
||
AuthManager applicationAuthManager = new VoiceApplicationAuthManager(key, secret); | ||
|
||
clientAuthManagers = new TreeMap<>(String.CASE_INSENSITIVE_ORDER); | ||
clientAuthManagers.put(SECURITY_SCHEME_KEYWORD, applicationAuthManager); | ||
} | ||
|
||
public CalloutsService callouts() { | ||
if (null == this.callouts) { | ||
checkCredentials(); | ||
this.callouts = | ||
new com.sinch.sdk.domains.voice.adapters.CalloutsService( | ||
configuration, httpClient, clientAuthManagers); | ||
} | ||
return this.callouts; | ||
} | ||
|
||
private void checkCredentials() throws ApiAuthException { | ||
if (null == clientAuthManagers || clientAuthManagers.isEmpty()) { | ||
throw new ApiAuthException( | ||
String.format( | ||
"Service '%s' cannot be called without defined credentials", | ||
this.getClass().getSimpleName())); | ||
} | ||
} | ||
} |
Oops, something went wrong.