Skip to content

Commit

Permalink
feat: Add toString, equals and hashCode to public domain objects (#508)
Browse files Browse the repository at this point in the history
* Add base POJO class

* Use JsonableBaseObject & testing

* Fix failing tests

* Implemented for users, subaccounts & ni2

* Update Account tests

* JsonableBaseObject for Numbers

* JsonableBaseObject for Verify v2

* JsonableBaseObject for Verify v1

* JsonableBaseObject for Bulk

* JsonableBaseObject for Video

* JsonableBaseObject for Voice

* Update changelog
  • Loading branch information
SMadani authored Jan 15, 2024
1 parent a50c7bb commit 1b1caa5
Show file tree
Hide file tree
Showing 244 changed files with 1,152 additions and 848 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,11 @@ All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](http://keepachangelog.com/)
and this project adheres to [Semantic Versioning](http://semver.org/).

# [8.2.0] - 2024-01-??
- Added Number Insight v2 API implementation
- New webhook deserialisation POJOs for Voice: `AnswerWebhook` and `EventWebhook`
- `toString`, `equals` and `hashCode` implemented for all domain response objects

# [8.1.0] - 2024-01-04
- Added various missing fields in Messages API:
- `webhook_version` and `webhook_url` for all outbound messages
Expand Down
1 change: 1 addition & 0 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ dependencies {
def junitVersion = '5.10.1'

implementation "commons-codec:commons-codec:1.16.0"
implementation 'org.apache.commons:commons-lang3:3.14.0'
implementation "org.apache.httpcomponents:httpclient:$httpclientVersion"
implementation "org.apache.httpcomponents:httpmime:$httpclientVersion"
implementation "com.fasterxml.jackson.core:jackson-databind:$jacksonVersion"
Expand Down
44 changes: 44 additions & 0 deletions src/main/java/com/vonage/client/JsonableBaseObject.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
/*
* Copyright 2024 Vonage
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.vonage.client;

import org.apache.commons.lang3.builder.EqualsBuilder;
import org.apache.commons.lang3.builder.HashCodeBuilder;

/**
* Base class for requests and responses which are serialised and parsed to and from JSON.
* In addition to the {@link Jsonable} interface, this class provides reflective implementations
* of {@code equals}, {@code hashCode} and {@code toString} methods based on the class's fields.
*
* @since 8.2.0
*/
public abstract class JsonableBaseObject implements Jsonable {

@Override
public int hashCode() {
return HashCodeBuilder.reflectionHashCode(this);
}

@Override
public boolean equals(Object obj) {
return EqualsBuilder.reflectionEquals(this, obj);
}

@Override
public String toString() {
return getClass().getSimpleName()+' '+toJson();
}
}
5 changes: 4 additions & 1 deletion src/main/java/com/vonage/client/account/BalanceResponse.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,14 @@
package com.vonage.client.account;

import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import com.fasterxml.jackson.annotation.JsonInclude;
import com.fasterxml.jackson.annotation.JsonProperty;
import com.vonage.client.Jsonable;
import com.vonage.client.JsonableBaseObject;

@JsonInclude(value = JsonInclude.Include.NON_NULL)
@JsonIgnoreProperties(ignoreUnknown = true)
public class BalanceResponse implements Jsonable {
public class BalanceResponse extends JsonableBaseObject {
private double value;
private boolean autoReload;

Expand Down
5 changes: 4 additions & 1 deletion src/main/java/com/vonage/client/account/Country.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,13 @@
package com.vonage.client.account;

import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import com.fasterxml.jackson.annotation.JsonInclude;
import com.fasterxml.jackson.annotation.JsonProperty;
import com.vonage.client.JsonableBaseObject;

@JsonInclude(value = JsonInclude.Include.NON_NULL)
@JsonIgnoreProperties(ignoreUnknown = true)
public class Country {
public class Country extends JsonableBaseObject {
private String code, displayName, name;

@JsonProperty("countryCode")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,9 @@

import com.fasterxml.jackson.annotation.JsonIgnore;
import com.fasterxml.jackson.annotation.JsonProperty;
import com.vonage.client.Jsonable;
import com.vonage.client.JsonableBaseObject;

class CreateSecretRequest implements Jsonable {
class CreateSecretRequest extends JsonableBaseObject {
@JsonIgnore private final String apiKey;
private final String secret;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,17 +16,20 @@
package com.vonage.client.account;

import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import com.fasterxml.jackson.annotation.JsonInclude;
import com.fasterxml.jackson.annotation.JsonProperty;
import com.vonage.client.Jsonable;
import com.vonage.client.JsonableBaseObject;
import java.util.List;

/**
* Pricing data for all countries.
*
* @since 7.9.0
*/
@JsonInclude(value = JsonInclude.Include.NON_NULL)

@JsonIgnoreProperties(ignoreUnknown = true)
class FullPricingResponse implements Jsonable {
class FullPricingResponse extends JsonableBaseObject {
private Integer count;
private List<PricingResponse> countries;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,20 +17,25 @@

import com.fasterxml.jackson.annotation.JsonIgnore;
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import com.fasterxml.jackson.annotation.JsonInclude;
import com.fasterxml.jackson.annotation.JsonProperty;
import com.vonage.client.Jsonable;
import com.vonage.client.JsonableBaseObject;
import com.vonage.client.common.HalPageResponse;
import java.util.List;

/**
* HAL response for {@link AccountClient#listSecrets(String)}.
*/
@JsonInclude(value = JsonInclude.Include.NON_NULL)
@JsonIgnoreProperties(ignoreUnknown = true)
public class ListSecretsResponse extends HalPageResponse {
@JsonProperty("_embedded") private Embedded _embedded;

@JsonInclude(value = JsonInclude.Include.NON_NULL)

@JsonIgnoreProperties(ignoreUnknown = true)
static final class Embedded {
static final class Embedded extends JsonableBaseObject {
@JsonProperty("secrets") private List<SecretResponse> secrets;
}

Expand Down
9 changes: 4 additions & 5 deletions src/main/java/com/vonage/client/account/Network.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,13 @@
*/
package com.vonage.client.account;

import com.fasterxml.jackson.annotation.JsonCreator;
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import com.fasterxml.jackson.annotation.JsonProperty;
import com.fasterxml.jackson.annotation.JsonValue;
import com.fasterxml.jackson.annotation.*;
import com.vonage.client.JsonableBaseObject;
import java.math.BigDecimal;

@JsonInclude(value = JsonInclude.Include.NON_NULL)
@JsonIgnoreProperties(ignoreUnknown = true)
public class Network {
public class Network extends JsonableBaseObject {
private Type type;
private BigDecimal price;
private String currency, mcc, mnc, code, name;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,15 @@
package com.vonage.client.account;

import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import com.fasterxml.jackson.annotation.JsonInclude;
import com.fasterxml.jackson.annotation.JsonProperty;
import com.vonage.client.Jsonable;
import com.vonage.client.JsonableBaseObject;
import java.util.List;

@JsonInclude(value = JsonInclude.Include.NON_NULL)
@JsonIgnoreProperties(ignoreUnknown = true)
public class PrefixPricingResponse implements Jsonable {
public class PrefixPricingResponse extends JsonableBaseObject {
private int count;
private List<PricingResponse> countries;

Expand Down
14 changes: 11 additions & 3 deletions src/main/java/com/vonage/client/account/PricingResponse.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,36 +16,44 @@
package com.vonage.client.account;

import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import com.fasterxml.jackson.annotation.JsonInclude;
import com.fasterxml.jackson.annotation.JsonProperty;
import com.fasterxml.jackson.annotation.JsonUnwrapped;
import com.vonage.client.Jsonable;
import com.vonage.client.JsonableBaseObject;
import java.math.BigDecimal;
import java.util.List;

@JsonInclude(value = JsonInclude.Include.NON_NULL)
@JsonIgnoreProperties(ignoreUnknown = true)
public class PricingResponse implements Jsonable {
public class PricingResponse extends JsonableBaseObject {
private String dialingPrefix;
private BigDecimal defaultPrice;
private String currency;
@JsonUnwrapped
private Country country;
@JsonUnwrapped private Country country;
private List<Network> networks;

@JsonProperty("dialingPrefix")
public String getDialingPrefix() {
return dialingPrefix;
}

@JsonProperty("defaultPrice")
public BigDecimal getDefaultPrice() {
return defaultPrice;
}

@JsonProperty("currency")
public String getCurrency() {
return currency;
}

@JsonProperty("country")
public Country getCountry() {
return country;
}

@JsonProperty("networks")
public List<Network> getNetworks() {
return networks;
}
Expand Down
5 changes: 4 additions & 1 deletion src/main/java/com/vonage/client/account/SecretResponse.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,15 +16,18 @@
package com.vonage.client.account;

import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import com.fasterxml.jackson.annotation.JsonInclude;
import com.fasterxml.jackson.annotation.JsonProperty;
import com.vonage.client.Jsonable;
import com.vonage.client.JsonableBaseObject;
import java.time.Instant;

/**
* Represents metadata about an API account secret.
*/
@JsonInclude(value = JsonInclude.Include.NON_NULL)
@JsonIgnoreProperties(ignoreUnknown = true)
public class SecretResponse implements Jsonable {
public class SecretResponse extends JsonableBaseObject {
private String id;
private Instant created;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
import com.vonage.client.QueryParamsRequest;
import java.util.LinkedHashMap;
import java.util.Map;

public class SettingsRequest implements QueryParamsRequest {
private final String incomingSmsUrl, deliveryReceiptUrl;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,11 @@
import com.fasterxml.jackson.annotation.JsonInclude;
import com.fasterxml.jackson.annotation.JsonProperty;
import com.vonage.client.Jsonable;
import com.vonage.client.JsonableBaseObject;

@JsonInclude(JsonInclude.Include.NON_NULL)
@JsonIgnoreProperties(ignoreUnknown = true)
public class SettingsResponse implements Jsonable {
public class SettingsResponse extends JsonableBaseObject {
private String incomingSmsUrl,deliveryReceiptUrl;
private Integer maxOutboundMessagesPerSecond, maxInboundMessagesPerSecond, maxApiCallsPerSecond;

Expand Down
9 changes: 5 additions & 4 deletions src/main/java/com/vonage/client/application/Application.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,14 +19,15 @@
import com.fasterxml.jackson.annotation.JsonInclude;
import com.fasterxml.jackson.annotation.JsonProperty;
import com.vonage.client.Jsonable;
import com.vonage.client.JsonableBaseObject;
import com.vonage.client.application.capabilities.*;

/**
* Represents a Vonage Application (both request and response).
*/
@JsonIgnoreProperties(ignoreUnknown = true)
@JsonInclude(JsonInclude.Include.NON_NULL)
public class Application implements Jsonable {
public class Application extends JsonableBaseObject {
private String id, name;
private Keys keys;
private Capabilities capabilities;
Expand Down Expand Up @@ -230,7 +231,7 @@ public Application build() {
*/
@JsonIgnoreProperties(ignoreUnknown = true)
@JsonInclude(JsonInclude.Include.NON_NULL)
public static class Privacy {
public static class Privacy extends JsonableBaseObject {
private Boolean improveAi;

/**
Expand All @@ -251,7 +252,7 @@ public Boolean getImproveAi() {
*/
@JsonIgnoreProperties(ignoreUnknown = true)
@JsonInclude(JsonInclude.Include.NON_NULL)
public static class Keys {
public static class Keys extends JsonableBaseObject {
private String publicKey, privateKey;

/**
Expand All @@ -277,7 +278,7 @@ public String getPrivateKey() {

@JsonIgnoreProperties(ignoreUnknown = true)
@JsonInclude(JsonInclude.Include.NON_NULL)
public static class Capabilities {
public static class Capabilities extends JsonableBaseObject {
private Voice voice;
private Messages messages;
private Rtc rtc;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import com.fasterxml.jackson.annotation.JsonInclude;
import com.fasterxml.jackson.annotation.JsonProperty;
import com.vonage.client.JsonableBaseObject;
import com.vonage.client.common.HttpMethod;
import com.vonage.client.common.Webhook;
import java.util.LinkedHashMap;
Expand All @@ -29,7 +30,7 @@
*/
@JsonIgnoreProperties(ignoreUnknown = true)
@JsonInclude(JsonInclude.Include.NON_NULL)
public abstract class Capability {
public abstract class Capability extends JsonableBaseObject {
protected Map<Webhook.Type, Webhook> webhooks;

protected Capability() {
Expand Down
3 changes: 2 additions & 1 deletion src/main/java/com/vonage/client/common/HalLinks.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,14 @@

import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import com.fasterxml.jackson.annotation.JsonProperty;
import com.vonage.client.JsonableBaseObject;
import java.net.URI;

/**
* Represents the {@code _links} section of a HAL response.
*/
@JsonIgnoreProperties(ignoreUnknown = true)
public class HalLinks {
public class HalLinks extends JsonableBaseObject {
@JsonProperty("first") UrlContainer first;
@JsonProperty("self") UrlContainer self;
@JsonProperty("prev") UrlContainer prev;
Expand Down
4 changes: 2 additions & 2 deletions src/main/java/com/vonage/client/common/HalPageResponse.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,14 @@

import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import com.fasterxml.jackson.annotation.JsonProperty;
import com.vonage.client.Jsonable;
import com.vonage.client.JsonableBaseObject;

/**
* Abstract base class for responses that conform to the
* <a href=https://datatracker.ietf.org/doc/html/draft-kelly-json-hal-07>HAL specification</a>.
*/
@JsonIgnoreProperties(ignoreUnknown = true)
public abstract class HalPageResponse implements Jsonable {
public abstract class HalPageResponse extends JsonableBaseObject {
protected Integer page, pageSize, totalItems, totalPages;
private HalLinks links;

Expand Down
5 changes: 3 additions & 2 deletions src/main/java/com/vonage/client/common/UrlContainer.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,15 @@

import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import com.fasterxml.jackson.annotation.JsonProperty;
import com.vonage.client.JsonableBaseObject;
import java.net.URI;

/**
* Represents a link under the {@code _links} section of a HAL response.
*/
@JsonIgnoreProperties(ignoreUnknown = true)
class UrlContainer {
URI href;
public class UrlContainer extends JsonableBaseObject {
protected URI href;

protected UrlContainer() {
}
Expand Down
Loading

0 comments on commit 1b1caa5

Please sign in to comment.