Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,9 @@ private Request buildRequest(Lookup lookup) {
}
request.putParameter("include_only_locality", lookup.getLocality());
request.putParameter("include_only_postal_code", lookup.getPostalCode());
if (lookup.getLanguage() != null) {
request.putParameter("language", lookup.getLanguage().getName());
}

return request;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
package com.smartystreets.api.international_autocomplete;

/**
* When not set, the output language will match the default for the country. When set to <b>NATIVE</b> the<br>
* results will always be in the language of the output country whenever possible. When set to <b>LATIN</b><br>
* the results will always be provided using the Latin character set, with accents and other diacritics removed.
* <p><b>Note: </b><i>For French diacritics in Canada, you must specify NATIVE.</i></p>
*/
public enum LanguageMode {
NATIVE("native"), LATIN("latin");

private final String name;

LanguageMode(String name){
this.name = name;
}

public String getName(){
return name;
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.smartystreets.api.international_autocomplete;


/**
* 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 @@ -22,6 +23,7 @@ public class Lookup {
private boolean geolocation;
private String locality;
private String postalCode;
private LanguageMode language;

//endregion

Expand Down Expand Up @@ -87,6 +89,10 @@ public String getPostalCode() {
return this.postalCode;
}

public LanguageMode getLanguage() {
return this.language;
}

//endregion

//region [ Setters ]
Expand Down Expand Up @@ -126,5 +132,9 @@ public void setPostalCode(String postalCode) {
this.postalCode = postalCode;
}

public void setLanguage(LanguageMode language) {
this.language = language;
}

//endregion
}
2 changes: 2 additions & 0 deletions src/main/java/examples/InternationalAutocompleteExample.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import com.smartystreets.api.international_autocomplete.Client;
import com.smartystreets.api.international_autocomplete.Lookup;
import com.smartystreets.api.international_autocomplete.Candidate;
import com.smartystreets.api.international_autocomplete.LanguageMode;

import java.io.IOException;

Expand All @@ -26,6 +27,7 @@ public static void main(String[] args) {
lookup.setLocality("Paris");
lookup.setMaxGroupResults(50);
lookup.setGeolocation(true);
lookup.setLanguage(LanguageMode.NATIVE);

client.send(lookup);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,13 +52,14 @@ public void testSendingSingleFullyPopulatedLookup() throws Exception {
URLPrefixSender sender = new URLPrefixSender("http://localhost/", capturingSender);
FakeSerializer serializer = new FakeSerializer(new Result());
Client client = new Client(sender, serializer);
String expectedURL = "http://localhost/?country=1&search=2&max_results=10&max_group_results=100&include_only_locality=4&include_only_postal_code=5";
String expectedURL = "http://localhost/?country=1&search=2&max_results=10&max_group_results=100&include_only_locality=4&include_only_postal_code=5&language=native";
Lookup lookup = new Lookup();
lookup.setCountry("1");
lookup.setSearch("2");
lookup.setMaxResults(10);
lookup.setLocality("4");
lookup.setPostalCode("5");
lookup.setLanguage(LanguageMode.NATIVE);

client.send(lookup);

Expand Down Expand Up @@ -93,6 +94,47 @@ public void testSendingLookupWithCustomMaxGroupResults() throws Exception {
assertTrue(capturingSender.getRequest().getUrl().contains("max_group_results=50"));
}

@Test
public void testSendingLookupWithNativeLanguage() throws Exception {
RequestCapturingSender capturingSender = new RequestCapturingSender();
URLPrefixSender sender = new URLPrefixSender("http://localhost/", capturingSender);
FakeSerializer serializer = new FakeSerializer(new Result());
Client client = new Client(sender, serializer);
Lookup lookup = new Lookup("1");
lookup.setLanguage(LanguageMode.NATIVE);

client.send(lookup);

assertTrue(capturingSender.getRequest().getUrl().contains("language=native"));
}

@Test
public void testSendingLookupWithLatinLanguage() throws Exception {
RequestCapturingSender capturingSender = new RequestCapturingSender();
URLPrefixSender sender = new URLPrefixSender("http://localhost/", capturingSender);
FakeSerializer serializer = new FakeSerializer(new Result());
Client client = new Client(sender, serializer);
Lookup lookup = new Lookup("1");
lookup.setLanguage(LanguageMode.LATIN);

client.send(lookup);

assertTrue(capturingSender.getRequest().getUrl().contains("language=latin"));
}

@Test
public void testSendingLookupWithUnsetLanguageOmitsParameter() throws Exception {
RequestCapturingSender capturingSender = new RequestCapturingSender();
URLPrefixSender sender = new URLPrefixSender("http://localhost/", capturingSender);
FakeSerializer serializer = new FakeSerializer(new Result());
Client client = new Client(sender, serializer);
Lookup lookup = new Lookup("1");

client.send(lookup);

assertFalse(capturingSender.getRequest().getUrl().contains("language"));
}

@Test
public void testDefaultValues() {
Lookup lookup = new Lookup();
Expand Down
Loading