Skip to content

Commit

Permalink
Merge branch 'main' into readme-md-update
Browse files Browse the repository at this point in the history
  • Loading branch information
JPPortier authored Dec 15, 2023
2 parents 1bf9ef8 + 2eb3189 commit ec3370a
Show file tree
Hide file tree
Showing 116 changed files with 1,346 additions and 213 deletions.
3 changes: 1 addition & 2 deletions client/src/main/com/sinch/sdk/SinchClient.java
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
public class SinchClient {

private static final String DEFAULT_PROPERTIES_FILE_NAME = "/config-default.properties";
private static final String VERSION_PROPERTIES_FILE_NAME = "/version.properties";
private static final String VERSION_PROPERTIES_FILE_NAME = "/version.properties";

private static final String OAUTH_URL_KEY = "oauth-url";
private static final String NUMBERS_SERVER_KEY = "numbers-server";
Expand Down Expand Up @@ -224,5 +224,4 @@ private String formatAuxiliaryFlag(String auxiliaryFlag) {
}
return String.join(",", values);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,9 @@ public String getAccessToken() {
return accessToken;
}

/** @return Integer Token period expiration in seconds */
/**
* @return Integer Token period expiration in seconds
*/
public Integer getExpiresIn() {
return expiresIn;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
* Callback Configuration Service
*
* @see <a
* href="https://developers.sinch.com/docs/numbers/api-reference/callbacks-numbers/tag/Callback-Configuration/">https://developers.sinch.com/docs/numbers/api-reference/callbacks-numbers/tag/Callback-Configuration/</a>
* href="https://developers.sinch.com/docs/numbers/api-reference/numbers/tag/Callbacks/">https://developers.sinch.com/docs/numbers/api-reference/numbers/tag/Callbacks/</a>
*/
public interface CallbackConfigurationService {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,4 +40,12 @@ public interface NumbersService {
* @since 1.0
*/
CallbackConfigurationService callback();

/**
* Webhooks helpers instance
*
* @return instance service related to webhooks helpers
* @since 1.0
*/
WebHooksService webhooks();
}
28 changes: 28 additions & 0 deletions client/src/main/com/sinch/sdk/domains/numbers/WebHooksService.java
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;
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
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.numbers.adapters.api.v1.CallbackConfigurationApi;
import com.sinch.sdk.domains.numbers.adapters.api.v1.CallbacksApi;
import com.sinch.sdk.domains.numbers.adapters.converters.CallbackConfigurationDtoConverter;
import com.sinch.sdk.domains.numbers.adapters.converters.CallbackConfigurationUpdateRequestParametersDtoConverter;
import com.sinch.sdk.domains.numbers.models.CallbackConfiguration;
Expand All @@ -17,19 +17,19 @@ public class CallbackConfigurationService
implements com.sinch.sdk.domains.numbers.CallbackConfigurationService {

private Configuration configuration;
private CallbackConfigurationApi api;
private CallbacksApi api;

public CallbackConfigurationService() {}

public CallbackConfigurationService(
Configuration configuration, HttpClient httpClient, Map<String, AuthManager> authManagers) {
this.configuration = configuration;
this.api =
new CallbackConfigurationApi(
new CallbacksApi(
httpClient, configuration.getNumbersServer(), authManagers, new HttpMapper());
}

private CallbackConfigurationApi getApi() {
private CallbacksApi getApi() {
return this.api;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ public class NumbersService implements com.sinch.sdk.domains.numbers.NumbersServ
private ActiveNumberService active;
private AvailableRegionService regions;
private CallbackConfigurationService callback;
private WebHooksService webhooks;

private final Map<String, AuthManager> authManagers;

public NumbersService(Configuration configuration, HttpClient httpClient) {
Expand Down Expand Up @@ -57,4 +59,12 @@ public CallbackConfigurationService callback() {
}
return this.callback;
}

public WebHooksService webhooks() {

if (null == this.webhooks) {
this.webhooks = new WebHooksService();
}
return this.webhooks;
}
}
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);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,7 @@ public static ActiveNumberRequestDto convert(ActiveNumberUpdateRequestParameters
.getVoiceConfiguration()
.ifPresent(
value -> dto.setVoiceConfiguration(VoiceConfigurationDtoConverter.convert(value)));
// TODO: OAS file do not yet contains callback field
// parameters.getCallback()
// .ifPresent(value -> dto.setCallback.convert(value)));
parameters.getCallback().ifPresent(dto::setCallbackUrl);
return dto;
}
}
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);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ public final class NumberType extends EnumDynamic<String, NumberType> {

/** Numbers that belong to a specific range. */
public static final NumberType MOBILE = new NumberType("MOBILE");

/** Numbers that are assigned to a specific geographic region. */
public static final NumberType LOCAL = new NumberType("LOCAL");

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
public final class OrderBy extends EnumDynamic<String, OrderBy> {
/** Ordering by phoneNumber */
public static final OrderBy PHONE_NUMBER = new OrderBy("phoneNumber");

/** Ordering by displayName */
public static final OrderBy DISPLAY_NAME = new OrderBy("displayName");

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,12 @@ public final class SearchPattern extends EnumDynamic<String, SearchPattern> {
* <p>For example, to search for area code 206 in the US, you would enter, %2b1206
*/
public static final SearchPattern START = new SearchPattern("START");

/**
* The number pattern entered is contained somewhere in the number, the location being undefined.
*/
public static final SearchPattern CONTAINS = new SearchPattern("CONTAINS");

/** The number ends with the number pattern entered. */
public static final SearchPattern END = new SearchPattern("END");

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,10 @@ public class ActiveNumberUpdateRequestParameters {
private final String callback;

/**
* @param displayName User supplied name for the phone number
* @param smsConfiguration The current SMS configuration for this number
* @param voiceConfiguration The current voice configuration for this number
* @param callback The callback URL to be called for a rented number's provisioning /
* deprovisioning operations
* @param displayName see {@link #getDisplayName() getDisplayName getter}
* @param smsConfiguration see {@link #getSmsConfiguration() getSmsConfiguration getter}
* @param voiceConfiguration see {@link #getVoiceConfiguration() getVoiceConfiguration getter}
* @param callback see {@link #getCallback() getCallback getter}
*/
public ActiveNumberUpdateRequestParameters(
String displayName,
Expand All @@ -33,18 +32,31 @@ public ActiveNumberUpdateRequestParameters(
this.callback = callback;
}

/**
* @return User supplied name for the phone number
*/
public Optional<String> getDisplayName() {
return Optional.ofNullable(displayName);
}

/**
* @return The current SMS configuration for this number
*/
public Optional<ActiveNumberUpdateSMSConfigurationRequestParameters> getSmsConfiguration() {
return Optional.ofNullable(smsConfiguration);
}

/**
* @return The current voice configuration for this number
*/
public Optional<ActiveNumberUpdateVoiceConfigurationRequestParameters> getVoiceConfiguration() {
return Optional.ofNullable(voiceConfiguration);
}

/**
* @return The callback URL to be called for a rented number's provisioning / deprovisioning
* operations ({@link com.sinch.sdk.domains.numbers.WebHooksService see WebHooksService})
*/
public Optional<String> getCallback() {
return Optional.ofNullable(callback);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,9 @@ public class AvailableRegionListAllRequestParameters {

private final Collection<NumberType> types;

/** @param types Only return regions for which numbers are provided with the given types */
/**
* @param types Only return regions for which numbers are provided with the given types
*/
public AvailableRegionListAllRequestParameters(Collection<NumberType> types) {
this.types = types;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,9 @@ public class CallbackConfigurationUpdateRequestParameters {
/** */
private final String hmacSecret;

/** @param hmacSecret The HMAC secret to be updated for the specified project */
/**
* @param hmacSecret The HMAC secret to be updated for the specified project
*/
public CallbackConfigurationUpdateRequestParameters(String hmacSecret) {
this.hmacSecret = hmacSecret;
}
Expand Down
Loading

0 comments on commit ec3370a

Please sign in to comment.