Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
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
134 changes: 71 additions & 63 deletions MIGRATION-GUIDE.md

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ public interface ConversationService {
ProjectSettingsService projectSettings();

/**
* WebHooksService Service instance
* SinchEventsService Service instance
*
* @return service instance for project
* @since 1.3
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,18 +31,18 @@ public interface NumbersService extends ActiveNumberService, AvailableNumberServ
AvailableRegionsService regions();

/**
* Callbacks Configuration Service instance
* Event Destinations Configuration Service instance
*
* @return service instance for project
* @since 2.0
*/
CallbackConfigurationService callbackConfiguration();
EventDestinationsService eventDestinations();

/**
* Webhooks helpers instance
* Sinch Events helpers instance
*
* @return instance service related to webhooks helpers
* @since 1.2
* @return instance service related to Sinch Events helpers
* @since 2.0
*/
WebHooksService webhooks();
SinchEventsService sinchEvents();
}
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
package com.sinch.sdk.domains.numbers.api.v1;

import com.sinch.sdk.core.exceptions.ApiMappingException;
import com.sinch.sdk.domains.numbers.models.v1.webhooks.NumberEvent;
import com.sinch.sdk.domains.numbers.models.v1.sinchevents.NumberSinchEvent;
import java.util.Map;

/**
* Webhooks service
* Sinch Events service
*
* <p>Callback events are used to get notified about Numbers usage according to your configured
* callback URL
Expand All @@ -16,7 +16,7 @@
*
* @since 1.2
*/
public interface WebHooksService {
public interface SinchEventsService {

/**
* The Sinch Platform can initiate callback requests to a URL you define (Callback URL) on request
Expand Down Expand Up @@ -47,5 +47,5 @@ boolean validateAuthenticationHeader(
* @return The decoded event notification instance class
* @since 1.2
*/
NumberEvent parseEvent(String jsonPayload) throws ApiMappingException;
NumberSinchEvent parseEvent(String jsonPayload) throws ApiMappingException;
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
import com.sinch.sdk.core.models.ServerConfiguration;
import com.sinch.sdk.core.utils.StringUtil;
import com.sinch.sdk.domains.numbers.api.v1.AvailableRegionsService;
import com.sinch.sdk.domains.numbers.api.v1.CallbackConfigurationService;
import com.sinch.sdk.domains.numbers.api.v1.EventDestinationsService;
import com.sinch.sdk.domains.numbers.models.v1.ActiveNumber;
import com.sinch.sdk.domains.numbers.models.v1.EmergencyAddress;
import com.sinch.sdk.domains.numbers.models.v1.request.ActiveNumberUpdateRequest;
Expand Down Expand Up @@ -46,8 +46,8 @@ public class NumbersService implements com.sinch.sdk.domains.numbers.api.v1.Numb
private volatile AvailableNumberServiceFacade available;
private volatile ActiveNumberServiceFacade active;
private volatile AvailableRegionsService regions;
private volatile CallbackConfigurationService callbackConfiguration;
private volatile WebHooksService webhooks;
private volatile EventDestinationsService eventDestinations;
private volatile SinchEventsService sinchEvents;

static {
LocalLazyInit.init();
Expand Down Expand Up @@ -96,26 +96,26 @@ ActiveNumberServiceFacade active() {
return this.active;
}

public CallbackConfigurationService callbackConfiguration() {
if (null == this.callbackConfiguration) {
public EventDestinationsService eventDestinations() {
if (null == this.eventDestinations) {
instanceLazyInit();
this.callbackConfiguration =
new CallbackConfigurationServiceImpl(
this.eventDestinations =
new EventDestinationsServiceImpl(
httpClientSupplier.get(),
context.getNumbersServer(),
authManagers,
HttpMapper.getInstance(),
uriUUID);
}
return this.callbackConfiguration;
return this.eventDestinations;
}

public WebHooksService webhooks() {
public SinchEventsService sinchEvents() {

if (null == this.webhooks) {
this.webhooks = new WebHooksService(new NumbersWebhooksAuthenticationValidation());
if (null == this.sinchEvents) {
this.sinchEvents = new SinchEventsService(new SinchEventsAuthenticationValidation());
}
return this.webhooks;
return this.sinchEvents;
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
import javax.crypto.Mac;
import javax.crypto.spec.SecretKeySpec;

public class NumbersWebhooksAuthenticationValidation {
public class SinchEventsAuthenticationValidation {

public static final String SIGNATURE_HEADER = "X-Sinch-Signature";
static final String HMAC_SHA1_ALGORITHM = "HmacSHA1";
Expand Down Expand Up @@ -39,7 +39,7 @@ private String encode(String secret, String stringToSign) {
Mac mac = Mac.getInstance(HMAC_SHA1_ALGORITHM);
mac.init(secretKeySpec);
byte[] hmacSha256 = mac.doFinal(stringToSign.getBytes(StandardCharsets.UTF_8));
return NumbersWebhooksAuthenticationValidation.bytesToHex(hmacSha256);
return SinchEventsAuthenticationValidation.bytesToHex(hmacSha256);
} catch (NoSuchAlgorithmException | InvalidKeyException e) {
throw new ApiAuthException(e);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,13 @@
import com.fasterxml.jackson.core.JsonProcessingException;
import com.sinch.sdk.core.exceptions.ApiMappingException;
import com.sinch.sdk.core.utils.databind.Mapper;
import com.sinch.sdk.domains.numbers.models.v1.webhooks.NumberEvent;
import com.sinch.sdk.domains.numbers.models.v1.sinchevents.NumberSinchEvent;
import java.util.Map;

public class WebHooksService implements com.sinch.sdk.domains.numbers.api.v1.WebHooksService {
private final NumbersWebhooksAuthenticationValidation authenticationChecker;
public class SinchEventsService implements com.sinch.sdk.domains.numbers.api.v1.SinchEventsService {
private final SinchEventsAuthenticationValidation authenticationChecker;

public WebHooksService(NumbersWebhooksAuthenticationValidation authenticationChecker) {
public SinchEventsService(SinchEventsAuthenticationValidation authenticationChecker) {
this.authenticationChecker = authenticationChecker;
}

Expand All @@ -20,10 +20,10 @@ public boolean validateAuthenticationHeader(
}

@Override
public NumberEvent parseEvent(String jsonPayload) throws ApiMappingException {
public NumberSinchEvent parseEvent(String jsonPayload) throws ApiMappingException {

try {
return Mapper.getInstance().readValue(jsonPayload, NumberEvent.class);
return Mapper.getInstance().readValue(jsonPayload, NumberSinchEvent.class);
} catch (JsonProcessingException e) {
throw new ApiMappingException(jsonPayload, e);
}
Expand Down

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
/**
* Numbers API Event Destinations related models
*
* @since 1.2
*/
package com.sinch.sdk.domains.numbers.models.v1.eventdestinations;
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
/**
* Numbers Event Destinations API requests related models
*
* @since 1.2
*/
package com.sinch.sdk.domains.numbers.models.v1.eventdestinations.request;
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
/**
* Numbers Event Destinations API responses related models
*
* @since 1.2
*/
package com.sinch.sdk.domains.numbers.models.v1.eventdestinations.response;
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
/**
* Models related to Numbers Sinch Events
*
* @since 1.2
*/
package com.sinch.sdk.domains.numbers.models.v1.sinchevents;

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -319,7 +319,7 @@ void update() {
.setDisplayName("my display name")
.setSmsConfiguration(smsConfiguration)
.setVoiceConfiguration(voiceConfiguration)
.setCallbackUrl("foo callback")
.setEventDestinationTarget("foo callback")
.build();

HttpRequest httpRequest =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -227,7 +227,7 @@ void rent() {
.setSmsConfiguration(
SmsConfiguration.builder().setServicePlanId("").setCampaignId("").build())
.setVoiceConfiguration(VoiceConfigurationRTC.builder().setAppId("").build())
.setCallbackUrl("foo")
.setEventDestinationTarget("foo")
.build();

HttpRequest httpRequest =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,9 @@
import com.sinch.sdk.core.http.HttpResponse;
import com.sinch.sdk.core.http.URLPathUtils;
import com.sinch.sdk.core.models.ServerConfiguration;
import com.sinch.sdk.domains.numbers.api.v1.CallbackConfigurationService;
import com.sinch.sdk.domains.numbers.models.v1.CallbackConfigurationDtoTest;
import com.sinch.sdk.domains.numbers.models.v1.callbacks.response.CallbackConfigurationResponse;
import com.sinch.sdk.domains.numbers.api.v1.EventDestinationsService;
import com.sinch.sdk.domains.numbers.models.v1.EventDestinationsDtoTest;
import com.sinch.sdk.domains.numbers.models.v1.eventdestinations.response.EventDestinationResponse;
import java.util.Arrays;
import java.util.Collection;
import java.util.Collections;
Expand All @@ -31,15 +31,15 @@
import org.mockito.Mock;

@TestWithResources
class CallbackConfigurationServiceTest extends BaseTest {
class EventDestinationsServiceTest extends BaseTest {

@GivenTextResource("/domains/numbers/v1/callbacks/callback-get-response.json")
@GivenTextResource("/domains/numbers/v1/eventdestinations/event-destination-response.json")
String jsonGetResponse;

@Mock HttpClient httpClient;
@Mock ServerConfiguration serverConfiguration;
@Mock Map<String, AuthManager> authManagers;
CallbackConfigurationService service;
EventDestinationsService service;

static final String uriUUID = "foo";

Expand All @@ -48,7 +48,7 @@ class CallbackConfigurationServiceTest extends BaseTest {
@BeforeEach
public void initMocks() {
service =
new CallbackConfigurationServiceImpl(
new EventDestinationsServiceImpl(
httpClient, serverConfiguration, authManagers, HttpMapper.getInstance(), uriUUID);
}

Expand All @@ -74,9 +74,9 @@ void get() throws ApiException {
argThat(new HttpRequestMatcher(httpRequest))))
.thenReturn(httpResponse);

CallbackConfigurationResponse response = service.get();
EventDestinationResponse response = service.get();

TestHelpers.recursiveEquals(response, CallbackConfigurationDtoTest.getResponse);
TestHelpers.recursiveEquals(response, EventDestinationsDtoTest.getResponse);
}

@Test
Expand All @@ -90,7 +90,7 @@ void update() {
HttpMapper.getInstance()
.serialize(
Collections.singletonList(HttpContentType.APPLICATION_JSON),
CallbackConfigurationDtoTest.updateRequest),
EventDestinationsDtoTest.updateRequest),
Collections.emptyMap(),
Collections.singletonList(HttpContentType.APPLICATION_JSON),
Collections.singletonList(HttpContentType.APPLICATION_JSON),
Expand All @@ -104,9 +104,8 @@ void update() {
argThat(new HttpRequestMatcher(httpRequest))))
.thenReturn(httpResponse);

CallbackConfigurationResponse response =
service.update(CallbackConfigurationDtoTest.updateRequest);
EventDestinationResponse response = service.update(EventDestinationsDtoTest.updateRequest);

TestHelpers.recursiveEquals(response, CallbackConfigurationDtoTest.getResponse);
TestHelpers.recursiveEquals(response, EventDestinationsDtoTest.getResponse);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -26,13 +26,14 @@ void checkCredentialsRegions() {
}

@Test
void checkCredentialsCallback() {
void checkCredentialsEventDestinations() {
CredentialsValidationHelper.checkCredentials(
() -> httpClient, NumbersService::callbackConfiguration);
() -> httpClient, NumbersService::eventDestinations);
}

@Test
void checkCredentialsWebhooks() {
assertDoesNotThrow(() -> new NumbersService(null, null, null, null).webhooks(), "Init passed");
void checkCredentialsSinchEvents() {
assertDoesNotThrow(
() -> new NumbersService(null, null, null, null).sinchEvents(), "Init passed");
}
}
Loading
Loading