-
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.
Merge branch 'main' into readme-md-update
- Loading branch information
Showing
116 changed files
with
1,346 additions
and
213 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
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
28 changes: 28 additions & 0 deletions
28
client/src/main/com/sinch/sdk/domains/numbers/WebHooksService.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,28 @@ | ||
package com.sinch.sdk.domains.numbers; | ||
|
||
import com.sinch.sdk.core.exceptions.ApiMappingException; | ||
import com.sinch.sdk.domains.numbers.models.webhooks.EventNotification; | ||
|
||
/** | ||
* Webhooks service | ||
* | ||
* <p>Callback events are used to get notified about Numbers usage according to your configured | ||
* callback URL | ||
* | ||
* <p>see <a | ||
* href="https://developers.sinch.com/docs/numbers/api-reference/numbers/tag/Callbacks/#tag/Callbacks/operation/ImportedNumberService_EventsCallback">https://developers.sinch.com/docs/numbers/api-reference/numbers/tag/Callbacks/#tag/Callbacks/operation/ImportedNumberService_EventsCallback</a> | ||
* | ||
* @since 1.0 | ||
*/ | ||
public interface WebHooksService { | ||
|
||
/** | ||
* This function can be called to deserialize received payload onto callback. Function return Java | ||
* class instance from un-serialized payload | ||
* | ||
* @param jsonPayload Received payload to be un-serialized | ||
* @return The decoded event notification instance class | ||
* @since 1.0 | ||
*/ | ||
EventNotification unserializeEventNotification(String jsonPayload) throws ApiMappingException; | ||
} |
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
28 changes: 28 additions & 0 deletions
28
client/src/main/com/sinch/sdk/domains/numbers/adapters/WebHooksService.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,28 @@ | ||
package com.sinch.sdk.domains.numbers.adapters; | ||
|
||
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.adapters.converters.CallbackPayloadDtoConverter; | ||
import com.sinch.sdk.domains.numbers.models.dto.v1.CallbackPayloadDto; | ||
import com.sinch.sdk.domains.numbers.models.webhooks.EventNotification; | ||
|
||
public class WebHooksService implements com.sinch.sdk.domains.numbers.WebHooksService { | ||
|
||
@Override | ||
public EventNotification unserializeEventNotification(String jsonPayload) | ||
throws ApiMappingException { | ||
|
||
try { | ||
CallbackPayloadDto dto = | ||
Mapper.getInstance().readValue(jsonPayload, CallbackPayloadDto.class); | ||
if (null != dto) { | ||
return CallbackPayloadDtoConverter.convert(dto); | ||
} | ||
throw new ApiMappingException(jsonPayload, null); | ||
|
||
} catch (JsonProcessingException e) { | ||
throw new ApiMappingException(jsonPayload, e); | ||
} | ||
} | ||
} |
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
41 changes: 41 additions & 0 deletions
41
...c/main/com/sinch/sdk/domains/numbers/adapters/converters/CallbackPayloadDtoConverter.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,41 @@ | ||
package com.sinch.sdk.domains.numbers.adapters.converters; | ||
|
||
import com.sinch.sdk.domains.numbers.models.SmsErrorCode; | ||
import com.sinch.sdk.domains.numbers.models.dto.v1.CallbackPayloadDto; | ||
import com.sinch.sdk.domains.numbers.models.webhooks.EventNotification; | ||
import com.sinch.sdk.domains.numbers.models.webhooks.EventStatus; | ||
import com.sinch.sdk.domains.numbers.models.webhooks.EventType; | ||
import com.sinch.sdk.domains.numbers.models.webhooks.ResourceType; | ||
import java.time.Instant; | ||
import java.time.LocalDateTime; | ||
import java.time.ZoneOffset; | ||
import java.time.format.DateTimeParseException; | ||
|
||
public class CallbackPayloadDtoConverter { | ||
|
||
public static EventNotification convert(CallbackPayloadDto dto) { | ||
|
||
String eventId = dto.getEventId(); | ||
// FIXME: Currently Numbers API return a string without timezone | ||
// Workaround: | ||
// 1. try to parse as ISO8601 (with timezone) | ||
// 2. If failure: fallback to a local date time in UTC time zoe | ||
Instant timestamp = null; | ||
if (null != dto.getTimestamp()) { | ||
try { | ||
timestamp = Instant.parse(dto.getTimestamp()); | ||
} catch (DateTimeParseException e) { | ||
timestamp = LocalDateTime.parse(dto.getTimestamp()).toInstant(ZoneOffset.UTC); | ||
} | ||
} | ||
String projectId = dto.getProjectId(); | ||
String resourceId = dto.getResourceId(); | ||
ResourceType resourceType = ResourceType.from(dto.getResourceType()); | ||
EventType eventType = EventType.from(dto.getEventType()); | ||
EventStatus status = EventStatus.from(dto.getStatus()); | ||
SmsErrorCode failureCode = SmsErrorCode.from(dto.getFailureCode()); | ||
|
||
return new EventNotification( | ||
eventId, timestamp, projectId, resourceId, resourceType, eventType, status, failureCode); | ||
} | ||
} |
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
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
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
Oops, something went wrong.