Skip to content

Commit

Permalink
Adding match type and example to us extract api.
Browse files Browse the repository at this point in the history
  • Loading branch information
RyanLCox1 committed Feb 14, 2023
1 parent f9d1806 commit 35781cc
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 2 deletions.
1 change: 1 addition & 0 deletions src/main/java/com/smartystreets/api/us_extract/Client.java
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ private Request buildRequest(Lookup lookup) {
request.putParameter("aggressive", String.valueOf(lookup.isAggressive()));
request.putParameter("addr_line_breaks", String.valueOf(lookup.addressesHaveLineBreaks()));
request.putParameter("addr_per_line", String.valueOf(lookup.getAddressesPerLine()));
request.putParameter("match", lookup.getMatch());

return request;
}
Expand Down
24 changes: 24 additions & 0 deletions src/main/java/com/smartystreets/api/us_extract/Lookup.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
package com.smartystreets.api.us_extract;

import com.fasterxml.jackson.annotation.JsonProperty;
import com.smartystreets.api.us_street.MatchType;

/**
* In addition to holding all of the input data for this lookup, this class also<br>
* will contain the result of the lookup after it comes back from the API.
Expand All @@ -15,6 +18,8 @@ public class Lookup {
private int addressesPerLine;
private String text;

private String match;

//endregion

public Lookup() {
Expand Down Expand Up @@ -56,6 +61,21 @@ public String getText() {
return text;
}

@JsonProperty("match")
public String getMatch() {
if (this.match == null)
return null;
if (this.match.equals("strict") )
return "strict";
if (this.match.equals("range") )
return "range";
if (this.match.equals("invalid") )
return "invalid";
if (this.match.equals("enhanced") )
return "enhanced";
return null;
}

//endregion

//region [ Setters ]
Expand Down Expand Up @@ -84,5 +104,9 @@ public void setText(String text) {
this.text = text;
}

public void setMatch(MatchType match) {
this.match = match.getName();
}

//endregion
}
9 changes: 7 additions & 2 deletions src/main/java/examples/UsExtractExample.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,10 @@
import com.smartystreets.api.exceptions.SmartyException;
import com.smartystreets.api.us_extract.*;
import com.smartystreets.api.us_street.Candidate;
import com.smartystreets.api.us_street.MatchType;

import java.io.IOException;
import java.util.Arrays;

public class UsExtractExample {
public static void main(String[] args) {
Expand All @@ -18,10 +20,11 @@ public static void main(String[] args) {
// for client-side requests (browser/mobile), use this code:
SharedCredentials credentials = new SharedCredentials(System.getenv("SMARTY_AUTH_WEB"), System.getenv("SMARTY_AUTH_REFERER"));

Client client = new ClientBuilder(credentials).buildUsExtractApiClient();
Client client = new ClientBuilder(credentials).withLicenses(Arrays.asList("us-core-cloud")).buildUsExtractApiClient();
String text = "Here is some text.\r\nMy address is 3785 Las Vegs Av." +
"\r\nLos Vegas, Nevada." +
"\r\nMeet me at 1 Rosedale Baltimore Maryland, not at 123 Phony Street, Boise Idaho.";
"\r\nMeet me at 1 Rosedale Baltimore Maryland, not at 123 Phony Street, Boise Idaho." +
"\r\n808 County Road 408 Brady, Tx.";

// Documentation for input fields can be found at:
// https://smartystreets.com/docs/cloud/us-extract-api#http-request-input-fields
Expand All @@ -30,6 +33,7 @@ public static void main(String[] args) {
lookup.isAggressive(true);
lookup.addressesHaveLineBreaks();
lookup.getAddressesPerLine();
lookup.setMatch(MatchType.ENHANCED);

try {
Result result = client.send(lookup);
Expand All @@ -51,6 +55,7 @@ public static void main(String[] args) {
for (Candidate candidate : address.getCandidates()) {
System.out.println(candidate.getDeliveryLine1());
System.out.println(candidate.getLastLine());
System.out.println(candidate.getAnalysis().getEnhancedMatch());
System.out.println();
}
} else System.out.println();
Expand Down

0 comments on commit 35781cc

Please sign in to comment.