Skip to content

Commit 961601e

Browse files
committed
Add max group results and geolocation to international autocomplete api.
1 parent 3e8bfe8 commit 961601e

4 files changed

Lines changed: 68 additions & 3 deletions

File tree

src/main/java/com/smartystreets/api/international_autocomplete/Client.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,10 @@ private Request buildRequest(Lookup lookup) {
4545
request.putParameter("country", lookup.getCountry());
4646
request.putParameter("search", lookup.getSearch());
4747
request.putParameter("max_results", String.valueOf(lookup.getMaxResults()));
48+
request.putParameter("max_group_results", String.valueOf(lookup.getMaxGroupResults()));
49+
if (lookup.isGeolocation()) {
50+
request.putParameter("geolocation", "on");
51+
}
4852
request.putParameter("include_only_locality", lookup.getLocality());
4953
request.putParameter("include_only_postal_code", lookup.getPostalCode());
5054

src/main/java/com/smartystreets/api/international_autocomplete/Lookup.java

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
public class Lookup {
1010
static final int MAX_RESULTS_DEFAULT = 5;
1111
static final int DISTANCE_DEFAULT = 5;
12+
static final int MAX_GROUP_RESULTS_DEFAULT = 100;
1213

1314
//region [ Fields ]
1415

@@ -17,6 +18,8 @@ public class Lookup {
1718
private String search;
1819
private String addressID;
1920
private int maxResults;
21+
private int maxGroupResults;
22+
private boolean geolocation;
2023
private String locality;
2124
private String postalCode;
2225

@@ -29,6 +32,7 @@ public class Lookup {
2932
*/
3033
public Lookup() {
3134
this.maxResults = MAX_RESULTS_DEFAULT;
35+
this.maxGroupResults = MAX_GROUP_RESULTS_DEFAULT;
3236
}
3337

3438
/**
@@ -67,6 +71,14 @@ public int getMaxResults() {
6771
return this.maxResults;
6872
}
6973

74+
public int getMaxGroupResults() {
75+
return this.maxGroupResults;
76+
}
77+
78+
public boolean isGeolocation() {
79+
return this.geolocation;
80+
}
81+
7082
public String getLocality() {
7183
return this.locality;
7284
}
@@ -98,6 +110,14 @@ public void setMaxResults(int maxResults) {
98110
this.maxResults = maxResults;
99111
}
100112

113+
public void setMaxGroupResults(int maxGroupResults) {
114+
this.maxGroupResults = maxGroupResults;
115+
}
116+
117+
public void setGeolocation(boolean geolocation) {
118+
this.geolocation = geolocation;
119+
}
120+
101121
public void setLocality(String locality) {
102122
this.locality = locality;
103123
}

src/main/java/examples/InternationalAutocompleteExample.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,8 @@ public static void main(String[] args) {
2424

2525
lookup.setCountry("FRA");
2626
lookup.setLocality("Paris");
27+
lookup.setMaxGroupResults(50);
28+
lookup.setGeolocation(true);
2729

2830
client.send(lookup);
2931

src/test/java/com/smartystreets/api/international_autocomplete/ClientTest.java

Lines changed: 42 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@
1010

1111
import static org.junit.Assert.assertArrayEquals;
1212
import static org.junit.Assert.assertEquals;
13+
import static org.junit.Assert.assertTrue;
14+
import static org.junit.Assert.assertFalse;
1315

1416
public class ClientTest {
1517
//region [ Single Lookup ]
@@ -23,7 +25,7 @@ public void testSendingSinglePrefixOnlyLookup() throws Exception {
2325

2426
client.send(new Lookup("1"));
2527

26-
assertEquals("http://localhost/?search=1&max_results=5", capturingSender.getRequest().getUrl());
28+
assertEquals("http://localhost/?search=1&max_results=5&max_group_results=100", capturingSender.getRequest().getUrl());
2729
}
2830

2931
@Test
@@ -32,7 +34,7 @@ public void testSendingSinglePartiallyPopulatedLookup() throws Exception {
3234
URLPrefixSender sender = new URLPrefixSender("http://localhost/", capturingSender);
3335
FakeSerializer serializer = new FakeSerializer(new Result());
3436
Client client = new Client(sender, serializer);
35-
String expectedURL = "http://localhost/?country=1&search=2&max_results=5&include_only_locality=4&include_only_postal_code=5";
37+
String expectedURL = "http://localhost/?country=1&search=2&max_results=5&max_group_results=100&include_only_locality=4&include_only_postal_code=5";
3638
Lookup lookup = new Lookup();
3739
lookup.setCountry("1");
3840
lookup.setSearch("2");
@@ -50,7 +52,7 @@ public void testSendingSingleFullyPopulatedLookup() throws Exception {
5052
URLPrefixSender sender = new URLPrefixSender("http://localhost/", capturingSender);
5153
FakeSerializer serializer = new FakeSerializer(new Result());
5254
Client client = new Client(sender, serializer);
53-
String expectedURL = "http://localhost/?country=1&search=2&max_results=10&include_only_locality=4&include_only_postal_code=5";
55+
String expectedURL = "http://localhost/?country=1&search=2&max_results=10&max_group_results=100&include_only_locality=4&include_only_postal_code=5";
5456
Lookup lookup = new Lookup();
5557
lookup.setCountry("1");
5658
lookup.setSearch("2");
@@ -63,6 +65,43 @@ public void testSendingSingleFullyPopulatedLookup() throws Exception {
6365
assertEquals(expectedURL, capturingSender.getRequest().getUrl());
6466
}
6567

68+
@Test
69+
public void testSendingLookupWithGeolocation() throws Exception {
70+
RequestCapturingSender capturingSender = new RequestCapturingSender();
71+
URLPrefixSender sender = new URLPrefixSender("http://localhost/", capturingSender);
72+
FakeSerializer serializer = new FakeSerializer(new Result());
73+
Client client = new Client(sender, serializer);
74+
Lookup lookup = new Lookup("1");
75+
lookup.setGeolocation(true);
76+
77+
client.send(lookup);
78+
79+
assertTrue(capturingSender.getRequest().getUrl().contains("geolocation=on"));
80+
}
81+
82+
@Test
83+
public void testSendingLookupWithCustomMaxGroupResults() throws Exception {
84+
RequestCapturingSender capturingSender = new RequestCapturingSender();
85+
URLPrefixSender sender = new URLPrefixSender("http://localhost/", capturingSender);
86+
FakeSerializer serializer = new FakeSerializer(new Result());
87+
Client client = new Client(sender, serializer);
88+
Lookup lookup = new Lookup("1");
89+
lookup.setMaxGroupResults(50);
90+
91+
client.send(lookup);
92+
93+
assertTrue(capturingSender.getRequest().getUrl().contains("max_group_results=50"));
94+
}
95+
96+
@Test
97+
public void testDefaultValues() {
98+
Lookup lookup = new Lookup();
99+
100+
assertEquals(5, lookup.getMaxResults());
101+
assertEquals(100, lookup.getMaxGroupResults());
102+
assertFalse(lookup.isGeolocation());
103+
}
104+
66105
//endregion
67106

68107
//region [ Response Handling ]

0 commit comments

Comments
 (0)