Skip to content

Commit

Permalink
Eliminating dependency on google http-client.
Browse files Browse the repository at this point in the history
  • Loading branch information
DuncanBeutler committed Apr 5, 2022
1 parent 0aceed3 commit c841388
Show file tree
Hide file tree
Showing 47 changed files with 326 additions and 537 deletions.
15 changes: 5 additions & 10 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -56,19 +56,14 @@
<scope>test</scope>
</dependency>
<dependency>
<groupId>com.google.http-client</groupId>
<artifactId>google-http-client</artifactId>
<version>1.21.0</version>
</dependency>
<dependency>
<groupId>com.google.http-client</groupId>
<artifactId>google-http-client-jackson2</artifactId>
<version>1.21.0</version>
<groupId>org.apache.commons</groupId>
<artifactId>commons-lang3</artifactId>
<version>3.5</version>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-core</artifactId>
<version>2.1.3</version>
<artifactId>jackson-databind</artifactId>
<version>2.13.0</version>
</dependency>
</dependencies>

Expand Down
10 changes: 5 additions & 5 deletions src/main/java/com/smartystreets/api/ClientBuilder.java
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ public class ClientBuilder {
private final String US_REVERSE_GEO_API_URL = "https://us-reverse-geo.api.smartystreets.com/lookup";

private ClientBuilder() {
this.serializer = new GoogleSerializer();
this.serializer = new SmartySerializer();
this.maxRetries = 5;
this.maxTimeout = 10000;
}
Expand Down Expand Up @@ -75,7 +75,7 @@ public ClientBuilder withSender(Sender sender) {
}

/**
* Changes the <b>Serializer</b> from the default <b>GoogleSerializer</b>.
* Changes the <b>Serializer</b> from the default <b>SmartySerializer</b>.
* @param serializer An object that implements the <b>Serializer</b> interface.
* @return Returns <b>this</b> to accommodate method chaining.
*/
Expand Down Expand Up @@ -121,7 +121,7 @@ public ClientBuilder withProxy(Proxy.Type proxyType, String proxyHost, int proxy
* @return Returns <b>this</b> to accommodate method chaining.
*/
public ClientBuilder withDebug() {
GoogleSender.enableLogging();
SmartySender.enableLogging();
return this;
}

Expand Down Expand Up @@ -180,9 +180,9 @@ private Sender buildSender() {

Sender sender;
if (this.proxy != null)
sender = new GoogleSender(this.maxTimeout, this.proxy);
sender = new SmartySender(this.maxTimeout, this.proxy);
else
sender = new GoogleSender(this.maxTimeout);
sender = new SmartySender(this.maxTimeout);

sender = new StatusCodeSender(sender);

Expand Down
24 changes: 0 additions & 24 deletions src/main/java/com/smartystreets/api/GoogleSerializer.java

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -15,26 +15,26 @@
import java.util.logging.LogRecord;
import java.util.logging.Logger;

public class GoogleSender implements Sender {
public class SmartySender implements Sender {
private int maxTimeOut;
private HttpClient client;

public GoogleSender() {
public SmartySender() {
this.maxTimeOut = 10000;
this.client = HttpClient.newHttpClient();
}

public GoogleSender(int maxTimeout) {
public SmartySender(int maxTimeout) {
this();
this.maxTimeOut = maxTimeout;
}

GoogleSender(int maxTimeOut, ProxySelector proxy) {
SmartySender(int maxTimeOut, ProxySelector proxy) {
this.maxTimeOut = maxTimeOut;
this.client = HttpClient.newBuilder().proxy(proxy).build();
}

GoogleSender(HttpClient client) {
SmartySender(HttpClient client) {
this();
this.client = client;
}
Expand Down
23 changes: 23 additions & 0 deletions src/main/java/com/smartystreets/api/SmartySerializer.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
package com.smartystreets.api;

import com.fasterxml.jackson.annotation.JsonInclude;
import com.fasterxml.jackson.databind.ObjectMapper;

import java.io.*;

public class SmartySerializer implements Serializer {

public SmartySerializer() {}

public byte[] serialize(Object obj) throws IOException {
ObjectMapper mapper = new ObjectMapper();
mapper.setSerializationInclusion(JsonInclude.Include.NON_NULL);
return mapper.writeValueAsBytes(obj);
}

public <T> T deserialize(byte[] payload, Class<T> type) throws IOException {
ObjectMapper mapper = new ObjectMapper();
mapper.setSerializationInclusion(JsonInclude.Include.NON_NULL);
return mapper.readValue(payload, type);
}
}
Original file line number Diff line number Diff line change
@@ -1,26 +1,19 @@
package com.smartystreets.api.international_autocomplete;

import com.google.api.client.util.Key;
import com.fasterxml.jackson.annotation.JsonProperty;

import java.io.Serializable;

/**
* @see "https://smartystreets.com/docs/cloud/international-address-autocomplete-api#http-response"
*/
public class Candidate {
public class Candidate implements Serializable {
//region [ Fields ]

@Key("street")
private String street;

@Key("locality")
private String locality;

@Key("administrative_area")
private String administrativeArea;

@Key("postal_code")
private String postalCode;

@Key("country_iso3")
private String countryISO3;

//region [ Fields ]
Expand All @@ -31,10 +24,13 @@ public class Candidate {

public String getLocality() { return locality; }

@JsonProperty("administrative_area")
public String getAdministrativeArea() { return administrativeArea; }

@JsonProperty("postal_code")
public String getPostalCode() { return postalCode; }

@JsonProperty("country_iso3")
public String getCountryISO3() { return countryISO3; }

//endregion
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
package com.smartystreets.api.international_autocomplete;

import com.google.api.client.util.Key;
import java.io.Serializable;

public class Result {
@Key("candidates")
public class Result implements Serializable {
private Candidate[] candidates;

public Candidate[] getCandidates() {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,32 +1,30 @@
package com.smartystreets.api.international_street;

import com.google.api.client.util.Key;
import com.fasterxml.jackson.annotation.JsonProperty;

import java.io.Serializable;

/**
* @see "https://smartystreets.com/docs/cloud/international-street-api#analysis"
*/
public class Analysis {
@Key("verification_status")
public class Analysis implements Serializable {
private String verificationStatus;

@Key("address_precision")
private String addressPrecision;

@Key("max_address_precision")
private String maxAddressPrecision;

@Key("changes")
private Changes changes;


@JsonProperty("verification_status")
public String getVerificationStatus() {
return verificationStatus;
}

@JsonProperty("address_precision")
public String getAddressPrecision() {
return addressPrecision;
}

@JsonProperty("max_address_precision")
public String getMaxAddressPrecision() {
return maxAddressPrecision;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,23 +1,18 @@
package com.smartystreets.api.international_street;

import com.google.api.client.util.Key;
import java.io.Serializable;

/**
* A candidate is a possible match for an address that was submitted.<br>
* A lookup can have multiple candidates if the address was ambiguous.
*
* @see "https://smartystreets.com/docs/cloud/international-street-api#root"
*/
public class Candidate extends RootLevel {
public class Candidate extends RootLevel implements Serializable {
//region [ Fields ]

@Key("components")
private Components components;

@Key("metadata")
private Metadata metadata;

@Key("analysis")
private Analysis analysis;

//endregion
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
package com.smartystreets.api.international_street;

import com.google.api.client.util.Key;
import java.io.Serializable;

public class Changes extends RootLevel {
public class Changes extends RootLevel implements Serializable {

//region [ Fields ]

@Key("components")
private Components components;

//endregion
Expand Down
Loading

0 comments on commit c841388

Please sign in to comment.